From patchwork Mon Feb 10 07:28:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3615621 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 343149F2F6 for ; Mon, 10 Feb 2014 07:27:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E2EF20171 for ; Mon, 10 Feb 2014 07:27:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 81254201C8 for ; Mon, 10 Feb 2014 07:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751712AbaBJH1r (ORCPT ); Mon, 10 Feb 2014 02:27:47 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:29722 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750948AbaBJH1l (ORCPT ); Mon, 10 Feb 2014 02:27:41 -0500 X-IronPort-AV: E=Sophos;i="4.95,816,1384272000"; d="scan'208";a="9496203" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Feb 2014 15:23:48 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s1A7RXJA020167 for ; Mon, 10 Feb 2014 15:27:34 +0800 Received: from adam-work.lan ([10.167.226.24]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014021015253859-1689684 ; Mon, 10 Feb 2014 15:25:38 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/3] btrfs-progs: reuse find_mount_root to determine arg type and so on. Date: Mon, 10 Feb 2014 15:28:30 +0800 Message-Id: <1392017310-19951-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.4 In-Reply-To: <1392017310-19951-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1392017310-19951-1-git-send-email-quwenruo@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/10 15:25:38, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/10 15:25:39, Serialize complete at 2014/02/10 15:25:39 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 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 Since find_mount_root now can check mount point quiet good, reuse it to determing arg type and get real mount point Signed-off-by: Qu Wenruo --- cmds-filesystem.c | 7 +++++++ utils.c | 24 +++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 43e1cf3..bc62d51 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -532,6 +532,7 @@ static int cmd_show(int argc, char **argv) struct btrfs_fs_devices *fs_devices; struct list_head *cur_uuid; char *search = NULL; + char *real_mp = NULL; int ret; int where = BTRFS_SCAN_LBLKID; int type = 0; @@ -607,6 +608,11 @@ static int cmd_show(int argc, char **argv) } } } + + if (type == BTRFS_ARG_MNTPOINT) { + find_mount_root(search, &real_mp, 1); + search = real_mp; + } } if (where == BTRFS_SCAN_DEV) @@ -646,6 +652,7 @@ devs_only: out: printf("%s\n", BTRFS_BUILD_VERSION); + free(real_mp); free_seen_fsid(); return ret; } diff --git a/utils.c b/utils.c index e39ad79..297f18d 100644 --- a/utils.c +++ b/utils.c @@ -700,26 +700,20 @@ int is_block_device(const char *path) /* * check if given path is a mount point - * return 1 if yes. 0 if no. -1 for error + * return 1 if yes. 0 if no. <0 for error */ int is_mount_point(const char *path) { - FILE *f; - struct mntent *mnt; - int ret = 0; - - f = setmntent("/proc/self/mounts", "r"); - if (f == NULL) - return -1; + int ret; - while ((mnt = getmntent(f)) != NULL) { - if (strcmp(mnt->mnt_dir, path)) - continue; - ret = 1; - break; + ret = find_mount_root(path, NULL, 1); + if (ret < 0) { + if (ret != -ENOENT) + return 0; + else + return ret; } - endmntent(f); - return ret; + return 1; } /*