diff mbox

[v2] btrfs-progs: Add mount point output for 'btrfs fi df' command.

Message ID 1404889017-31426-1-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Qu Wenruo July 9, 2014, 6:56 a.m. UTC
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 <quwenruo@cn.fujitsu.com>
---
v2:
  Call realpath() before find_mount_root() to deal with relative path
---
 cmds-filesystem.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

David Sterba July 22, 2014, 5:56 p.m. UTC | #1
On Wed, Jul 09, 2014 at 02:56:57PM +0800, Qu Wenruo wrote:
> 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.

If a non-btrfs path is passed, the "Mounted on" line is printed,
followed by 2 ERROR: lines. I suggest to print it only if get_df
succeeds, ie. right before print_df.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo July 23, 2014, 1:26 a.m. UTC | #2
-------- Original Message --------
Subject: Re: [PATCH v2] btrfs-progs: Add mount point output for 'btrfs 
fi df' command.
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Date: 2014?07?23? 01:56
> On Wed, Jul 09, 2014 at 02:56:57PM +0800, Qu Wenruo wrote:
>> 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.
> If a non-btrfs path is passed, the "Mounted on" line is printed,
> followed by 2 ERROR: lines. I suggest to print it only if get_df
> succeeds, ie. right before print_df.
Thanks for mentioning, I'll update the patchset soon.

Thanks,
Qu
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 4b2d27e..77e1db0 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -187,12 +187,31 @@  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))
                usage(cmd_filesystem_df_usage);
 
        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) {
+	       free(real_path);
+	       if (ret != -ENOENT)
+		       fprintf(stderr, "ERROR: Failed to find mount root for path %s: %s\n",
+			       path, strerror(-ret));
+		return 1;
+       }
+       free(real_path);
+       printf("Mounted on: %s\n", mount_point);
+       free(mount_point);
 
        fd = open_file_or_dir(path, &dirstream);
        if (fd < 0) {