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.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user