summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index cb69b2b3..d2410444 100644
--- a/utils.c
+++ b/utils.c
@@ -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)