]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-util: add fstab_is_mount_point_full which takes a source path to compare
authorMike Yuan <me@yhndnzj.com>
Wed, 26 Jul 2023 04:04:07 +0000 (12:04 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 26 Jul 2023 07:00:06 +0000 (15:00 +0800)
src/shared/fstab-util.c
src/shared/fstab-util.h

index 6efdcd689656a3b68a451a749114ca69df3d6b43..4ffec25c75430e883f2adba925c4cb192147fff8 100644 (file)
@@ -63,23 +63,53 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) {
         return false;
 }
 
-int fstab_is_mount_point(const char *mount) {
+static int fstab_is_mount_point_of(const char *what_fstab, const char *path) {
+        _cleanup_free_ char *node = NULL;
+
+        assert(what_fstab);
+        assert(path);
+
+        node = fstab_node_to_udev_node(what_fstab);
+        if (!node)
+                return -ENOMEM;
+
+        if (path_equal(node, path))
+                return true;
+
+        if (is_device_node(path) && is_device_node(node))
+                return devnode_same(node, path);
+
+        return false;
+}
+
+int fstab_is_mount_point_full(const char *where, const char *path) {
         _cleanup_endmntent_ FILE *f = NULL;
-        struct mntent *m;
+        int r;
+
+        assert(where);
 
         f = setmntent(fstab_path(), "re");
         if (!f)
                 return errno == ENOENT ? false : -errno;
 
         for (;;) {
+                struct mntent *me;
+
                 errno = 0;
-                m = getmntent(f);
-                if (!m)
+                me = getmntent(f);
+                if (!me)
                         return errno != 0 ? -errno : false;
 
-                if (path_equal(m->mnt_dir, mount))
-                        return true;
+                if (path_equal(where, me->mnt_dir)) {
+                        if (!path)
+                                return true;
+
+                        r = fstab_is_mount_point_of(me->mnt_fsname, path);
+                        if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r)))
+                                return r;
+                }
         }
+
         return false;
 }
 
index 5979b476b673e3d2d691de436db2ca2a846a64cb..cb3686bee3f24c93d6dc52886a38f0f84f739b22 100644 (file)
@@ -7,9 +7,13 @@
 #include "macro.h"
 
 bool fstab_is_extrinsic(const char *mount, const char *opts);
-int fstab_is_mount_point(const char *mount);
 int fstab_has_fstype(const char *fstype);
 
+int fstab_is_mount_point_full(const char *where, const char *path);
+static inline int fstab_is_mount_point(const char *where) {
+        return fstab_is_mount_point_full(where, NULL);
+}
+
 int fstab_filter_options(
                 const char *opts,
                 const char *names,