From: Qu Wenruo <quwenruo@cn.fujitsu.com>
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 [thread overview]
Message-ID: <1392017310-19951-4-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1392017310-19951-1-git-send-email-quwenruo@cn.fujitsu.com>
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 <quwenruo@cn.fujitsu.com>
---
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;
}
/*
--
1.8.5.4
next prev parent reply other threads:[~2014-02-10 7:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 7:28 [PATCH 0/3] make 'btrfs fi show /mnt/point/' works with ending '/' character Qu Wenruo
2014-02-10 7:28 ` [PATCH 1/3] btrfs-progs: move find_mount_root to utils.[ch] Qu Wenruo
2014-02-10 7:28 ` [PATCH 2/3] btrfs-progs: Add path_is_mp option for find_mount_root Qu Wenruo
2014-02-10 7:28 ` Qu Wenruo [this message]
2014-02-12 2:18 ` [PATCH 0/3] make 'btrfs fi show /mnt/point/' works with ending '/' character Qu Wenruo
2014-02-12 14:31 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392017310-19951-4-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).