]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: Add squashfs support to make_filesystem()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 19 Sep 2022 18:24:55 +0000 (20:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 Sep 2022 08:50:16 +0000 (10:50 +0200)
The caveat is that the caller has to provide a source directory
to initialize the squashfs filesystem from.

src/home/homework-luks.c
src/partition/makefs.c
src/partition/repart.c
src/shared/mkfs-util.c
src/shared/mkfs-util.h
src/test/test-loop-block.c

index f2dcabd84a20c11a389d0aa97bcd8e69f7ec9020..c57621a6b1c5b9c29609a4fb1c97c4b308eb0510 100644 (file)
@@ -2333,7 +2333,7 @@ int home_create_luks(
 
         log_info("Setting up LUKS device %s completed.", setup->dm_node);
 
-        r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), fs_uuid, user_record_luks_discard(h));
+        r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), NULL, fs_uuid, user_record_luks_discard(h));
         if (r < 0)
                 return r;
 
index b6979b7e4f72824134a4541794c5bed83f77927f..e8aa813bda06c2a1f1298756a98a3987e983e2a4 100644 (file)
@@ -65,7 +65,7 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to generate UUID for file system: %m");
 
-        return make_filesystem(device, fstype, basename(device), uuid, true);
+        return make_filesystem(device, fstype, basename(device), NULL, uuid, true);
 }
 
 DEFINE_MAIN_FUNCTION(run);
index 1169eca40e310d750ccd0801b8d796c4c831c045..db37a3ee3a6af8d54a47cf33679d91c7fb462e1c 100644 (file)
@@ -3387,7 +3387,7 @@ static int context_mkfs(Context *context) {
                 if (r < 0)
                         return r;
 
-                r = make_filesystem(fsdev, p->format, strempty(p->new_label), fs_uuid, arg_discard);
+                r = make_filesystem(fsdev, p->format, strempty(p->new_label), NULL, fs_uuid, arg_discard);
                 if (r < 0) {
                         encrypted_dev_fd = safe_close(encrypted_dev_fd);
                         (void) deactivate_luks(cd, encrypted);
index accd64f9e89f9f6e008418f4f76fdb76960b57ab..4c31045a867fa9313a4f5fbf1b6df197e3967142 100644 (file)
@@ -90,6 +90,7 @@ int make_filesystem(
                 const char *node,
                 const char *fstype,
                 const char *label,
+                const char *root,
                 sd_id128_t uuid,
                 bool discard) {
 
@@ -102,12 +103,28 @@ int make_filesystem(
         assert(label);
 
         if (streq(fstype, "swap")) {
+                if (root)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "A swap filesystem can't be populated, refusing");
                 r = find_executable("mkswap", &mkfs);
                 if (r == -ENOENT)
                         return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkswap binary not available.");
                 if (r < 0)
                         return log_error_errno(r, "Failed to determine whether mkswap binary exists: %m");
+        } else if (streq(fstype, "squashfs")) {
+                if (!root)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Cannot generate squashfs filesystems without a source tree.");
+
+                r = find_executable("mksquashfs", &mkfs);
+                if (r == -ENOENT)
+                        return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mksquashfs binary not available.");
+                if (r < 0)
+                        return log_error_errno(r, "Failed to determine whether mksquashfs binary exists: %m");
         } else {
+                if (root)
+                        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                               "Populating with source tree is only supported for squashfs");
                 r = mkfs_exists(fstype);
                 if (r < 0)
                         return log_error_errno(r, "Failed to determine whether mkfs binary for %s exists: %m", fstype);
@@ -225,6 +242,13 @@ int make_filesystem(
                                       "-U", vol_id,
                                       node, NULL);
 
+                else if (streq(fstype, "squashfs"))
+
+                        (void) execlp(mkfs, mkfs,
+                                      root, node,
+                                      "-quiet",
+                                      "-noappend",
+                                      NULL);
                 else
                         /* Generic fallback for all other file systems */
                         (void) execlp(mkfs, mkfs, node, NULL);
index 7647afbfc70f1eba696364c154f1931d394ddaba..7cff11634955efaa761be4bab09f57974d7cc58f 100644 (file)
@@ -7,4 +7,4 @@
 
 int mkfs_exists(const char *fstype);
 
-int make_filesystem(const char *node, const char *fstype, const char *label, sd_id128_t uuid, bool discard);
+int make_filesystem(const char *node, const char *fstype, const char *label, const char *root, sd_id128_t uuid, bool discard);
index ee28ad4235fa278d519e168bc8def321c0eca4bc..83d158f470be4e271c9c1d97d1e43a710f348131 100644 (file)
@@ -234,16 +234,16 @@ static int run(int argc, char *argv[]) {
         assert_se(dissected->partitions[PARTITION_HOME].node);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", id, true) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", NULL, id, true) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", id, true) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", NULL, id, true) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", id, true) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", NULL, id, true) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", id, true) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", NULL, id, true) >= 0);
 
         dissected = dissected_image_unref(dissected);
         assert_se(dissect_loop_device(loop, NULL, NULL, 0, &dissected) >= 0);