From: Daan De Meyer Date: Mon, 19 Sep 2022 18:24:55 +0000 (+0200) Subject: shared: Add squashfs support to make_filesystem() X-Git-Tag: v252-rc1~121^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f55ad775d214b879cbd76565d9198aab8ff3b7e;p=thirdparty%2Fsystemd.git shared: Add squashfs support to make_filesystem() The caveat is that the caller has to provide a source directory to initialize the squashfs filesystem from. --- diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index f2dcabd84a2..c57621a6b1c 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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; diff --git a/src/partition/makefs.c b/src/partition/makefs.c index b6979b7e4f7..e8aa813bda0 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -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); diff --git a/src/partition/repart.c b/src/partition/repart.c index 1169eca40e3..db37a3ee3a6 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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); diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index accd64f9e89..4c31045a867 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -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); diff --git a/src/shared/mkfs-util.h b/src/shared/mkfs-util.h index 7647afbfc70..7cff1163495 100644 --- a/src/shared/mkfs-util.h +++ b/src/shared/mkfs-util.h @@ -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); diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c index ee28ad4235f..83d158f470b 100644 --- a/src/test/test-loop-block.c +++ b/src/test/test-loop-block.c @@ -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);