diff options
author | Su Yue <suy.fnst@cn.fujitsu.com> | 2018-08-30 17:08:04 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-10-23 14:48:39 +0200 |
commit | ea18e30d6e4674f7b0c416c8311792d668149455 (patch) | |
tree | 710591140232a0d82f06814b31ed1977d229e3ea /cmds-inspect-dump-tree.c | |
parent | 5950bcd1214e91af3fdb618a65e34d7d5360a188 (diff) |
btrfs-progs: dump-tree: print invalid argument and strerror
Before this patch:
$ ls nothingness
ls: cannot access 'nothingness': No such file or directory
$ btrfs inspect-internal dump-tree nothingness
ERROR: not a block device or regular file: nothingness
The confusing error message makes users think that nonexistent file
exiss but is of a wrong type.
This patch lets check_arg_type return -errno if realpath failed. And
print strerror if check_arg_type failed and the returned code is
negative. Like:
$ btrfs inspect-internal dump-tree nothingness
ERROR: invalid argument: nothingness: No such file or directory
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-inspect-dump-tree.c')
-rw-r--r-- | cmds-inspect-dump-tree.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c index c8acd55a..d84d52dd 100644 --- a/cmds-inspect-dump-tree.c +++ b/cmds-inspect-dump-tree.c @@ -313,7 +313,12 @@ int cmd_inspect_dump_tree(int argc, char **argv) ret = check_arg_type(argv[optind]); if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) { - error("not a block device or regular file: %s", argv[optind]); + if (ret < 0) + error("invalid argument %s: %s", argv[optind], + strerror(-ret)); + else + error("not a block device or regular file: %s", + argv[optind]); goto out; } |