]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-util: add fstab_has_node
authorMike Yuan <me@yhndnzj.com>
Sat, 29 Jul 2023 12:00:55 +0000 (20:00 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 29 Jul 2023 12:00:55 +0000 (20:00 +0800)
src/shared/fstab-util.c
src/shared/fstab-util.h

index 4ffec25c75430e883f2adba925c4cb192147fff8..67e718b6eaa61d129233ee8bf81e472065e820d1 100644 (file)
@@ -63,7 +63,7 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) {
         return false;
 }
 
-static int fstab_is_mount_point_of(const char *what_fstab, const char *path) {
+static int fstab_is_same_node(const char *what_fstab, const char *path) {
         _cleanup_free_ char *node = NULL;
 
         assert(what_fstab);
@@ -86,7 +86,7 @@ int fstab_is_mount_point_full(const char *where, const char *path) {
         _cleanup_endmntent_ FILE *f = NULL;
         int r;
 
-        assert(where);
+        assert(where || path);
 
         f = setmntent(fstab_path(), "re");
         if (!f)
@@ -100,14 +100,15 @@ int fstab_is_mount_point_full(const char *where, const char *path) {
                 if (!me)
                         return errno != 0 ? -errno : false;
 
-                if (path_equal(where, me->mnt_dir)) {
-                        if (!path)
-                                return true;
+                if (where && !path_equal(where, me->mnt_dir))
+                        continue;
 
-                        r = fstab_is_mount_point_of(me->mnt_fsname, path);
-                        if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r)))
-                                return r;
-                }
+                if (!path)
+                        return true;
+
+                r = fstab_is_same_node(me->mnt_fsname, path);
+                if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r)))
+                        return r;
         }
 
         return false;
index cb3686bee3f24c93d6dc52886a38f0f84f739b22..a1c079fd41719a2619284af168618f896461e8db 100644 (file)
@@ -13,6 +13,9 @@ 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);
 }
+static inline int fstab_has_node(const char *path) {
+        return fstab_is_mount_point_full(NULL, path);
+}
 
 int fstab_filter_options(
                 const char *opts,