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 <[email protected]> --- 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; } -- 2.0.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
