From patchwork Fri Aug 28 14:11:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 7091961 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 438CD9F22E for ; Fri, 28 Aug 2015 14:11:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 523392083F for ; Fri, 28 Aug 2015 14:11:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCBFC2083E for ; Fri, 28 Aug 2015 14:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752350AbbH1OLt (ORCPT ); Fri, 28 Aug 2015 10:11:49 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:30397 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751841AbbH1OLs (ORCPT ); Fri, 28 Aug 2015 10:11:48 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7SEBh5x019362 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Aug 2015 14:11:43 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t7SEBgUj006766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 28 Aug 2015 14:11:43 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t7SEBgpu020685; Fri, 28 Aug 2015 14:11:42 GMT Received: from localhost.localdomain (/42.60.17.47) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 28 Aug 2015 07:11:42 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, kreijack@inwind.it Subject: [PATCH] btrfs-progs: fix is_block_device() return checks Date: Fri, 28 Aug 2015 22:11:30 +0800 Message-Id: <1440771090-338-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.4.1 X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 it was highlighted to me is_block_device(), returns 1 if the file is a block device, < 0 in case of an error (eg: file not found) 0 otherwise This patch makes proper return checks at all the places where is_block_device() is used. Thanks to Goffredo. Signed-off-by: Anand Jain Suggested-by: Goffredo Baroncelli --- cmds-device.c | 6 +++--- mkfs.c | 6 +++--- utils.c | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index eb4358d..e9f17bd 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -170,7 +170,7 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) if (is_numerical(argv[i])) { argv3.devid = arg_strtou64(argv[i]); its_num = true; - } else if (is_block_device(argv[i])) { + } else if (is_block_device(argv[i]) == 1) { strncpy_null(argv3.name, argv[i]); } else { fprintf(stderr, @@ -290,7 +290,7 @@ static int cmd_scan_dev(int argc, char **argv) for( i = devstart ; i < argc ; i++ ){ char *path; - if (!is_block_device(argv[i])) { + if (is_block_device(argv[i]) != 1) { fprintf(stderr, "ERROR: %s is not a block device\n", argv[i]); ret = 1; @@ -348,7 +348,7 @@ static int cmd_ready_dev(int argc, char **argv) goto out; } - if (!is_block_device(path)) { + if (is_block_device(path) != 1) { fprintf(stderr, "ERROR: %s is not a block device\n", path); ret = 1; diff --git a/mkfs.c b/mkfs.c index b60fc5a..faef748 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1357,7 +1357,7 @@ int main(int ac, char **av) while (dev_cnt-- > 0) { file = av[optind++]; - if (is_block_device(file)) + if (is_block_device(file) == 1) if (test_dev_for_mkfs(file, force_overwrite)) exit(1); } @@ -1592,7 +1592,7 @@ int main(int ac, char **av) trans = btrfs_start_transaction(root, 1); - if (is_block_device(file)) + if (is_block_device(file) == 1) btrfs_register_one_device(file); if (dev_cnt == 0) @@ -1642,7 +1642,7 @@ int main(int ac, char **av) (unsigned long long)device->devid); } - if (is_block_device(file)) + if (is_block_device(file) == 1) btrfs_register_one_device(file); } diff --git a/utils.c b/utils.c index 39b295a..479b97a 100644 --- a/utils.c +++ b/utils.c @@ -1063,7 +1063,8 @@ int open_path_or_dev_mnt(const char *path, DIR **dirstream) char mp[PATH_MAX]; int fdmnt; - if (is_block_device(path)) { + fdmnt = is_block_device(path); + if (fdmnt == 1) { int ret; ret = get_btrfs_mount(path, mp, sizeof(mp)); @@ -1073,7 +1074,7 @@ int open_path_or_dev_mnt(const char *path, DIR **dirstream) return -1; } fdmnt = open_file_or_dir(mp, dirstream); - } else { + } else if (fdmnt == 0) { fdmnt = open_file_or_dir(path, dirstream); } @@ -2061,7 +2062,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, memset(fi_args, 0, sizeof(*fi_args)); - if (is_block_device(path)) { + if (is_block_device(path) == 1) { struct btrfs_super_block *disk_super; char buf[BTRFS_SUPER_INFO_SIZE]; u64 devid;