From patchwork Thu Aug 30 09:08:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10581377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A174E14BD for ; Thu, 30 Aug 2018 09:01:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93466295F5 for ; Thu, 30 Aug 2018 09:01:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 878822B7FE; Thu, 30 Aug 2018 09:01:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40B84295F5 for ; Thu, 30 Aug 2018 09:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728064AbeH3NC2 (ORCPT ); Thu, 30 Aug 2018 09:02:28 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:56865 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727170AbeH3NC2 (ORCPT ); Thu, 30 Aug 2018 09:02:28 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="44185687" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Aug 2018 17:01:18 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 934EC4B6ED50 for ; Thu, 30 Aug 2018 17:01:19 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.31) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 30 Aug 2018 17:01:26 +0800 From: Su Yue To: CC: Subject: [PATCH] btrfs-progs: dump-tree: print invalid argument and strerror Date: Thu, 30 Aug 2018 17:08:04 +0800 Message-ID: <20180830090804.13264-1-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] X-yoursite-MailScanner-ID: 934EC4B6ED50.AC304 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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) &&