]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-util: add fstab_is_bind
authorMike Yuan <me@yhndnzj.com>
Thu, 13 Jul 2023 15:13:10 +0000 (23:13 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 13 Jul 2023 17:27:02 +0000 (01:27 +0800)
src/core/mount.c
src/shared/fstab-util.c
src/shared/fstab-util.h

index 765c9899ef6cd90512628b4714b1731348e6e56d..1e752aa44ffe744766bf35c3928fdcab887f6deb 100644 (file)
@@ -123,14 +123,7 @@ static bool mount_is_loop(const MountParameters *p) {
 
 static bool mount_is_bind(const MountParameters *p) {
         assert(p);
-
-        if (fstab_test_option(p->options, "bind\0" "rbind\0"))
-                return true;
-
-        if (p->fstype && STR_IN_SET(p->fstype, "bind", "rbind"))
-                return true;
-
-        return false;
+        return fstab_is_bind(p->options, p->fstype);
 }
 
 static bool mount_is_bound_to_device(Mount *m) {
index b0e274afccabfa43fdda8030495e27763d2a3642..6efdcd689656a3b68a451a749114ca69df3d6b43 100644 (file)
@@ -20,6 +20,8 @@ int fstab_has_fstype(const char *fstype) {
         _cleanup_endmntent_ FILE *f = NULL;
         struct mntent *m;
 
+        assert(fstype);
+
         f = setmntent(fstab_path(), "re");
         if (!f)
                 return errno == ENOENT ? false : -errno;
@@ -288,3 +290,14 @@ char *fstab_node_to_udev_node(const char *p) {
 
         return strdup(p);
 }
+
+bool fstab_is_bind(const char *options, const char *fstype) {
+
+        if (fstab_test_option(options, "bind\0" "rbind\0"))
+                return true;
+
+        if (fstype && STR_IN_SET(fstype, "bind", "rbind"))
+                return true;
+
+        return false;
+}
index 6b596baafa100c843d38c704ab56d27665255aaa..5979b476b673e3d2d691de436db2ca2a846a64cb 100644 (file)
@@ -40,3 +40,5 @@ char *fstab_node_to_udev_node(const char *p);
 static inline const char* fstab_path(void) {
         return secure_getenv("SYSTEMD_FSTAB") ?: "/etc/fstab";
 }
+
+bool fstab_is_bind(const char *options, const char *fstype);