]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkfs-util: Set sector size for btrfs as well 33544/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 29 Jun 2024 13:27:02 +0000 (15:27 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 29 Jun 2024 14:11:34 +0000 (16:11 +0200)
btrfs used to default the sector size to the page size and didn't
support anything else. Since 6.7, it defaults to 4K and using 4K
makes the filesystem compatible with all page sizes. So let's make
sure we use minimum 4K as well (lower causes failures on systems with
a 4K page size) but still allow larger sector sizes if specified by
the user.

src/shared/mkfs-util.c

index 4d440127e57ff942a51d9a0b7cbcc6c9a47d0675..14bf82b56430f1860a010b2c7153028fd70f6374 100644 (file)
@@ -461,6 +461,15 @@ int make_filesystem(
                 if (quiet)
                         stdio_fds[1] = -EBADF;
 
+                if (sector_size > 0) {
+                        if (strv_extend(&argv, "--sectorsize") < 0)
+                                return log_oom();
+
+                        /* mkfs.btrfs expects a sector size of at least 4k bytes. */
+                        if (strv_extendf(&argv, "%"PRIu64, MAX(sector_size, 4 * U64_KB)) < 0)
+                                return log_oom();
+                }
+
         } else if (streq(fstype, "f2fs")) {
                 argv = strv_new(mkfs,
                                 "-g",  /* "default options" */