From b81dd800fccc62754d1801a6c118ec7f629b0355 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 28 Apr 2014 16:37:29 +0800 Subject: btrfs-progs: Improve the errno string about open_path_or_dev_mnt() open_path_or_dev_mnt() is used to on *mounted* btrfs device or mount point, when a unmounted btrfs device is passed, errno is set to EINVAL to info the caller. If ignore the errno and just print "ERROR: can't access '%s'", end users will get confused. This patch will add check for open_path_or_dev_mnt() caller and print more meaningful error message when a unmounted btrfs device path is given. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- cmds-scrub.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'cmds-scrub.c') diff --git a/cmds-scrub.c b/cmds-scrub.c index 3510f57d..5265a2b0 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -1172,7 +1172,13 @@ static int scrub_start(int argc, char **argv, int resume) fdmnt = open_path_or_dev_mnt(path, &dirstream); if (fdmnt < 0) { - ERR(!do_quiet, "ERROR: can't access '%s'\n", path); + if (errno == EINVAL) + ERR(!do_quiet, + "ERROR: '%s' is not a mounted btrfs device\n", + path); + else + ERR(!do_quiet, "ERROR: can't access '%s': %s\n", + path, strerror(errno)); return 1; } @@ -1560,8 +1566,13 @@ static int cmd_scrub_cancel(int argc, char **argv) fdmnt = open_path_or_dev_mnt(path, &dirstream); if (fdmnt < 0) { - fprintf(stderr, "ERROR: could not open %s: %s\n", - path, strerror(errno)); + if (errno == EINVAL) + fprintf(stderr, + "ERROR: '%s' is not a mounted btrfs device\n", + path); + else + fprintf(stderr, "ERROR: can't access '%s': %s\n", + path, strerror(errno)); ret = 1; goto out; } @@ -1658,7 +1669,13 @@ static int cmd_scrub_status(int argc, char **argv) fdmnt = open_path_or_dev_mnt(path, &dirstream); if (fdmnt < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", path); + if (errno == EINVAL) + fprintf(stderr, + "ERROR: '%s' is not a mounted btrfs device\n", + path); + else + fprintf(stderr, "ERROR: can't access '%s': %s\n", + path, strerror(errno)); return 1; } -- cgit v1.2.3