From patchwork Wed Jul 23 05:47:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4608871 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2D58DC0515 for ; Wed, 23 Jul 2014 05:48:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F5BA201BF for ; Wed, 23 Jul 2014 05:48:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F4DE201CE for ; Wed, 23 Jul 2014 05:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754188AbaGWFrp (ORCPT ); Wed, 23 Jul 2014 01:47:45 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:26807 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751299AbaGWFro (ORCPT ); Wed, 23 Jul 2014 01:47:44 -0400 X-IronPort-AV: E=Sophos;i="5.00,931,1396972800"; d="scan'208";a="33667148" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Jul 2014 13:44:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6N5ldko029309 for ; Wed, 23 Jul 2014 13:47:39 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 23 Jul 2014 13:47:45 +0800 From: Qu Wenruo To: Subject: [PATCH v3 4/4] btrfs-progs: Add mount point output for 'btrfs fi df' Date: Wed, 23 Jul 2014 13:47:37 +0800 Message-ID: <1406094457-3100-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1406094457-3100-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1406094457-3100-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add mount point output for 'btrfs fi df'. Also since the patch uses find_mount_root() to find mount point, now 'btrfs fi df' can output more meaningful error message when given a non-btrfs path. Signed-off-by: Qu Wenruo --- changelog: v2: Call realpath() before find_mount_root() to deal with relative path v3: Only output mount point when get_df() successed. --- cmds-filesystem.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 108d9b7..ca6bcad 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -187,6 +187,8 @@ static int cmd_filesystem_df(int argc, char **argv) int ret; int fd; char *path; + char *real_path = NULL; + char *mount_point = NULL; DIR *dirstream = NULL; if (check_argc_exact(argc, 2)) @@ -194,6 +196,29 @@ static int cmd_filesystem_df(int argc, char **argv) path = argv[1]; + real_path = realpath(path, NULL); + if (!real_path) { + fprintf(stderr, + "ERROR: Failed to resolve real path for %s: %s\n", + path, strerror(errno)); + return 1; + } + ret = find_mount_root(real_path, &mount_point); + if (ret < 0) { + fprintf(stderr, + "ERROR: failed to determine mount point for %s: %s\n", + path, strerror(-ret)); + free(real_path); + return 1; + } + if (ret > 0) { + fprintf(stderr, + "ERROR: %s does not belong to a btrfs mount point\n", + path); + free(real_path); + return 1; + } + fd = open_file_or_dir(path, &dirstream); if (fd < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); @@ -201,12 +226,15 @@ static int cmd_filesystem_df(int argc, char **argv) } ret = get_df(fd, &sargs); if (!ret && sargs) { + printf("Mounted on: %s\n", mount_point); print_df(sargs); free(sargs); } else { fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret)); } + free(real_path); + free(mount_point); close_file_or_dir(fd, dirstream); return !!ret; }