From patchwork Mon Jan 5 06:24:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5565031 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 338F8BF6C3 for ; Mon, 5 Jan 2015 06:26:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29CF120165 for ; Mon, 5 Jan 2015 06:26:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F1D12015A for ; Mon, 5 Jan 2015 06:26:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751124AbbAEG02 (ORCPT ); Mon, 5 Jan 2015 01:26:28 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:2375 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750959AbbAEG02 (ORCPT ); Mon, 5 Jan 2015 01:26:28 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="55534349" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 05 Jan 2015 14:23:02 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t056Psj3007432 for ; Mon, 5 Jan 2015 14:25:54 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 5 Jan 2015 14:26:30 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: Allow debug-tree to be executed on regular file. Date: Mon, 5 Jan 2015 14:24:27 +0800 Message-ID: <1420439067-27380-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The commit 1bad43fbe002 ("btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given") add judgement on btrfs-debug-tree to restrict only block device to be executed on, but the command can also be used on regular file, so add regular file support for the judgement. Signed-off-by: Qu Wenruo --- btrfs-debug-tree.c | 5 +++-- utils.c | 21 +++++++++++++++++---- utils.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c index 9cdb35f..0815fe1 100644 --- a/btrfs-debug-tree.c +++ b/btrfs-debug-tree.c @@ -180,8 +180,9 @@ int main(int ac, char **av) print_usage(); ret = check_arg_type(av[optind]); - if (ret != BTRFS_ARG_BLKDEV) { - fprintf(stderr, "'%s' is not a block device\n", av[optind]); + if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) { + fprintf(stderr, "'%s' is not a block device or regular file\n", + av[optind]); exit(1); } diff --git a/utils.c b/utils.c index af0a8fe..3ca8229 100644 --- a/utils.c +++ b/utils.c @@ -854,13 +854,23 @@ int is_mount_point(const char *path) return ret; } +static int is_reg_file(const char *path) +{ + struct stat statbuf; + + if (stat(path, &statbuf) < 0) + return -errno; + return S_ISREG(statbuf.st_mode); +} + /* * This function checks if the given input parameter is * an uuid or a path - * return -1: some error in the given input - * return 0: unknow input - * return 1: given input is uuid - * return 2: given input is path + * return <0 : some error in the given input + * return BTRFS_ARG_UNKNOWN: unknown input + * return BTRFS_ARG_UUID: given input is uuid + * return BTRFS_ARG_MNTPOINT: given input is path + * return BTRFS_ARG_REG: given input is regular file */ int check_arg_type(const char *input) { @@ -877,6 +887,9 @@ int check_arg_type(const char *input) if (is_mount_point(path) == 1) return BTRFS_ARG_MNTPOINT; + if (is_reg_file(path)) + return BTRFS_ARG_REG; + return BTRFS_ARG_UNKNOWN; } diff --git a/utils.h b/utils.h index 3950491..142f3f9 100644 --- a/utils.h +++ b/utils.h @@ -35,6 +35,7 @@ #define BTRFS_ARG_MNTPOINT 1 #define BTRFS_ARG_UUID 2 #define BTRFS_ARG_BLKDEV 3 +#define BTRFS_ARG_REG 4 #define BTRFS_UUID_UNPARSED_SIZE 37