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:
Daan De Meyer
2022-09-21 10:50:16 +02:00
parent 92cd7e7ccb
commit 7f55ad775d
6 changed files with 32 additions and 8 deletions
+24
View 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);
+1 -1
View 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);