All of lore.kernel.org
 help / color / mirror / Atom feed
From: Su Yue <suy.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <suy.fnst@cn.fujitsu.com>
Subject: [PATCH] btrfs-progs: dump-tree: print invalid argument and strerror
Date: Thu, 30 Aug 2018 17:08:04 +0800	[thread overview]
Message-ID: <20180830090804.13264-1-suy.fnst@cn.fujitsu.com> (raw)

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 thinks that nonexistent
file is existed but in wrong type.

This patch let 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>
---
 cmds-inspect-dump-tree.c | 7 ++++++-
 utils.c                  | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c
index c8acd55a0c3a..f70a1c47d145 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;
 	}
 
diff --git a/utils.c b/utils.c
index 1e275c668cd5..80eca77b1b20 100644
--- a/utils.c
+++ b/utils.c
@@ -502,6 +502,8 @@ int check_arg_type(const char *input)
 			return BTRFS_ARG_REG;
 
 		return BTRFS_ARG_UNKNOWN;
+	} else {
+		return -errno;
 	}
 
 	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
-- 
2.17.1

             reply	other threads:[~2018-08-30 13:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30  9:08 Su Yue [this message]
2018-09-11 14:44 ` [PATCH] btrfs-progs: dump-tree: print invalid argument and strerror David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180830090804.13264-1-suy.fnst@cn.fujitsu.com \
    --to=suy.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.