From patchwork Mon Mar 21 07:21:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 8629831 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 E0101C0553 for ; Mon, 21 Mar 2016 07:21:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0DCCE20270 for ; Mon, 21 Mar 2016 07:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1056C20274 for ; Mon, 21 Mar 2016 07:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752306AbcCUHVY (ORCPT ); Mon, 21 Mar 2016 03:21:24 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:20274 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752124AbcCUHVW (ORCPT ); Mon, 21 Mar 2016 03:21:22 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2L7LJ79031805 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Mar 2016 07:21:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u2L7LIi8004169 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 21 Mar 2016 07:21:19 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u2L7LGIL025991; Mon, 21 Mar 2016 07:21:18 GMT Received: from arch2.sg.oracle.com (/10.186.101.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 21 Mar 2016 00:21:16 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 2/6] btrfs-progs: move test_issubvolume() to utils.c Date: Mon, 21 Mar 2016 15:21:01 +0800 Message-Id: <1458544865-16467-3-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1458544865-16467-1-git-send-email-anand.jain@oracle.com> References: <1458137673-464-1-git-send-email-anand.jain@oracle.com> <1458544865-16467-1-git-send-email-anand.jain@oracle.com> 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=-6.9 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 Signed-off-by: Anand Jain --- cmds-subvolume.c | 27 --------------------------- utils.c | 27 +++++++++++++++++++++++++++ utils.h | 1 + 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 3953d7c060a2..f62ab9584ce7 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -224,33 +224,6 @@ out: return retval; } -/* - * Test if path is a subvolume - * Returns: - * 0 - path exists but it is not a subvolume - * 1 - path exists and it is a subvolume - * < 0 - error - */ -int test_issubvolume(const char *path) -{ - struct stat st; - struct statfs stfs; - int res; - - res = stat(path, &st); - if (res < 0) - return -errno; - - if (st.st_ino != BTRFS_FIRST_FREE_OBJECTID || !S_ISDIR(st.st_mode)) - return 0; - - res = statfs(path, &stfs); - if (res < 0) - return -errno; - - return (int)stfs.f_type == BTRFS_SUPER_MAGIC; -} - static int wait_for_commit(int fd) { int ret; diff --git a/utils.c b/utils.c index fb549ee923c7..046ddf8eef19 100644 --- a/utils.c +++ b/utils.c @@ -3148,3 +3148,30 @@ int test_issubvolname(const char *name) return name[0] != '\0' && !strchr(name, '/') && strcmp(name, ".") && strcmp(name, ".."); } + +/* + * Test if path is a subvolume + * Returns: + * 0 - path exists but it is not a subvolume + * 1 - path exists and it is a subvolume + * < 0 - error + */ +int test_issubvolume(const char *path) +{ + struct stat st; + struct statfs stfs; + int res; + + res = stat(path, &st); + if (res < 0) + return -errno; + + if (st.st_ino != BTRFS_FIRST_FREE_OBJECTID || !S_ISDIR(st.st_mode)) + return 0; + + res = statfs(path, &stfs); + if (res < 0) + return -errno; + + return (int)stfs.f_type == BTRFS_SUPER_MAGIC; +} diff --git a/utils.h b/utils.h index a4e55bf58914..32bb02005719 100644 --- a/utils.h +++ b/utils.h @@ -194,6 +194,7 @@ const char* group_profile_str(u64 flags); int test_minimum_size(const char *file, u32 leafsize); int test_issubvolname(const char *name); +int test_issubvolume(const char *path); int test_isdir(const char *path); /*