]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: move 'norecovery' detection into its own helper call
authorLennart Poettering <lennart@poettering.net>
Tue, 7 Mar 2023 10:24:00 +0000 (11:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 9 Mar 2023 20:56:42 +0000 (21:56 +0100)
And let's also ask the kernel explicitly for support.

src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/shared/dissect-image.c
src/test/test-mountpoint-util.c

index 4e0994c881c9de82b7d51828c798f3debfd9f46a..27d20f5fe3e2ee13daef70e9a782baed43b7b816 100644 (file)
@@ -478,6 +478,23 @@ bool fstype_can_discard(const char *fstype) {
                           "xfs");
 }
 
+bool fstype_can_norecovery(const char *fstype) {
+        int r;
+
+        assert(fstype);
+
+        /* On new kernels we can just ask the kernel */
+        r = mount_option_supported(fstype, "norecovery", NULL);
+        if (r >= 0)
+                return r;
+
+        return STR_IN_SET(fstype,
+                          "ext3",
+                          "ext4",
+                          "xfs",
+                          "btrfs");
+}
+
 bool fstype_can_uid_gid(const char *fstype) {
 
         /* All file systems that have a uid=/gid= mount option that fixates the owners of all files and directories,
index e68fdf668523d85e8d916ff85c9b04c02aab71e1..e0c8f6b3564f2fdbd48254ed5003377174d461cf 100644 (file)
@@ -49,6 +49,7 @@ bool fstype_is_blockdev_backed(const char *fstype);
 bool fstype_is_ro(const char *fsype);
 bool fstype_can_discard(const char *fstype);
 bool fstype_can_uid_gid(const char *fstype);
+bool fstype_can_norecovery(const char *fstype);
 
 int dev_is_devtmpfs(void);
 
index fc27c50d448bdffdfc4799181314a3683a6c5ca2..59adb324266e5a471fa9cd5f353de9a9c3ad1694 100644 (file)
@@ -1567,7 +1567,7 @@ int partition_pick_mount_options(
          * access that actually modifies stuff work on such image files. Or to say this differently: if
          * people want their file systems to be fixed up they should just open them in writable mode, where
          * all these problems don't exist. */
-        if (!rw && STRPTR_IN_SET(fstype, "ext3", "ext4", "xfs", "btrfs"))
+        if (!rw && fstype && fstype_can_norecovery(fstype))
                 if (!strextend_with_separator(&options, ",", "norecovery"))
                         return -ENOMEM;
 
index 8fdfa4d96050c05b58adb2620c0f150da3abb2e4..d6aa2c7b94964398490c2fadc08a8999f8bba261 100644 (file)
@@ -355,6 +355,12 @@ TEST(fstype_can_discard) {
         assert_se(!fstype_can_discard("iso9660"));
 }
 
+TEST(fstype_can_norecovery) {
+        assert_se(fstype_can_norecovery("ext4"));
+        assert_se(!fstype_can_norecovery("vfat"));
+        assert_se(!fstype_can_norecovery("tmpfs"));
+}
+
 static int intro(void) {
         /* let's move into our own mount namespace with all propagation from the host turned off, so
          * that /proc/self/mountinfo is static and constant for the whole time our test runs. */