diff options
author | Anand Jain <Anand.Jain@oracle.com> | 2013-10-22 13:53:22 +0800 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-10-24 05:57:44 -0400 |
commit | d33b2a48429563b3c777249ae03cfbecb13d9d07 (patch) | |
tree | ad1e58f2f53961c69f3644f3088f4758f1b5a60d /utils.c | |
parent | 811e993db4f447e577c87fb2a0539eb723798685 (diff) |
btrfs-progs: filesystem show of specified mounted disk should work
Originally, thinking was user will use mount point if the disk
is mounted. But thats not really true, actually user don't
(or shouldn't) care to check if disk mounted, so whether disk
is mounted/unmounted when disk path is specified it should work.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -677,7 +677,8 @@ error: * Returns negative errno on failure, otherwise * returns 1 for blockdev, 0 for not-blockdev */ -int is_block_device(const char *path) { +int is_block_device(const char *path) +{ struct stat statbuf; if (stat(path, &statbuf) < 0) @@ -687,6 +688,30 @@ 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 + */ +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; + + while ((mnt = getmntent(f)) != NULL) { + if (strcmp(mnt->mnt_dir, path)) + continue; + ret = 1; + break; + } + endmntent(f); + return ret; +} + +/* * Find the mount point for a mounted device. * On success, returns 0 with mountpoint in *mp. * On failure, returns -errno (not mounted yields -EINVAL) |