mirror of
https://github.com/systemd/systemd.git
synced 2025-09-06 05:44:41 +03:00
repart: Extend squashfs logic to all read-only filesystems
The same logic will apply to every read-only filesystem that we might add support for in the future, so let's make this a bit more future proof.
This commit is contained in:
@@ -3306,12 +3306,12 @@ static int partition_populate_directory(Partition *p, char **ret_root, char **re
|
|||||||
assert(ret_root);
|
assert(ret_root);
|
||||||
assert(ret_tmp_root);
|
assert(ret_tmp_root);
|
||||||
|
|
||||||
/* When generating squashfs, we need the source tree to be available when we generate the squashfs
|
/* When generating read-only filesystems, we need the source tree to be available when we generate
|
||||||
* filesystem. Because we might have multiple source trees, we build a temporary source tree
|
* the read-only filesystem. Because we might have multiple source trees, we build a temporary source
|
||||||
* beforehand where we merge all our inputs. We then use this merged source tree to create the
|
* tree beforehand where we merge all our inputs. We then use this merged source tree to create the
|
||||||
* squashfs filesystem. */
|
* read-only filesystem. */
|
||||||
|
|
||||||
if (!streq(p->format, "squashfs")) {
|
if (!fstype_is_ro(p->format)) {
|
||||||
*ret_root = NULL;
|
*ret_root = NULL;
|
||||||
*ret_tmp_root = NULL;
|
*ret_tmp_root = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -3357,7 +3357,7 @@ static int partition_populate_filesystem(Partition *p, const char *node) {
|
|||||||
assert(p);
|
assert(p);
|
||||||
assert(node);
|
assert(node);
|
||||||
|
|
||||||
if (streq(p->format, "squashfs"))
|
if (fstype_is_ro(p->format))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (strv_isempty(p->copy_files) && strv_isempty(p->make_directories))
|
if (strv_isempty(p->copy_files) && strv_isempty(p->make_directories))
|
||||||
@@ -3464,9 +3464,9 @@ static int context_mkfs(Context *context) {
|
|||||||
|
|
||||||
/* Ideally, we populate filesystems using our own code after creating the filesystem to
|
/* Ideally, we populate filesystems using our own code after creating the filesystem to
|
||||||
* ensure consistent handling of chattrs, xattrs and other similar things. However, when
|
* ensure consistent handling of chattrs, xattrs and other similar things. However, when
|
||||||
* using squashfs, we can't populate after creating the filesystem because it's read-only, so
|
* using read-only filesystems such as squashfs, we can't populate after creating the
|
||||||
* instead we create a temporary root to use as the source tree when generating the squashfs
|
* filesystem because it's read-only, so instead we create a temporary root to use as the
|
||||||
* filesystem. */
|
* source tree when generating the read-only filesystem. */
|
||||||
r = partition_populate_directory(p, &root, &tmp_root);
|
r = partition_populate_directory(p, &root, &tmp_root);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
@@ -3485,7 +3485,7 @@ static int context_mkfs(Context *context) {
|
|||||||
if (flock(encrypted_dev_fd, LOCK_UN) < 0)
|
if (flock(encrypted_dev_fd, LOCK_UN) < 0)
|
||||||
return log_error_errno(errno, "Failed to unlock LUKS device: %m");
|
return log_error_errno(errno, "Failed to unlock LUKS device: %m");
|
||||||
|
|
||||||
/* Now, we can populate all the other filesystems that aren't squashfs. */
|
/* Now, we can populate all the other filesystems that aren't read-only. */
|
||||||
r = partition_populate_filesystem(p, fsdev);
|
r = partition_populate_filesystem(p, fsdev);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
encrypted_dev_fd = safe_close(encrypted_dev_fd);
|
encrypted_dev_fd = safe_close(encrypted_dev_fd);
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "id128-util.h"
|
#include "id128-util.h"
|
||||||
#include "mkfs-util.h"
|
#include "mkfs-util.h"
|
||||||
|
#include "mountpoint-util.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
#include "stdio-util.h"
|
#include "stdio-util.h"
|
||||||
@@ -102,6 +103,11 @@ int make_filesystem(
|
|||||||
assert(fstype);
|
assert(fstype);
|
||||||
assert(label);
|
assert(label);
|
||||||
|
|
||||||
|
if (fstype_is_ro(fstype) && !root)
|
||||||
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
|
"Cannot generate read-only filesystem %s without a source tree.",
|
||||||
|
fstype);
|
||||||
|
|
||||||
if (streq(fstype, "swap")) {
|
if (streq(fstype, "swap")) {
|
||||||
if (root)
|
if (root)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
@@ -112,10 +118,6 @@ int make_filesystem(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to determine whether mkswap binary exists: %m");
|
return log_error_errno(r, "Failed to determine whether mkswap binary exists: %m");
|
||||||
} else if (streq(fstype, "squashfs")) {
|
} 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);
|
r = find_executable("mksquashfs", &mkfs);
|
||||||
if (r == -ENOENT)
|
if (r == -ENOENT)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mksquashfs binary not available.");
|
return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mksquashfs binary not available.");
|
||||||
@@ -124,7 +126,7 @@ int make_filesystem(
|
|||||||
} else {
|
} else {
|
||||||
if (root)
|
if (root)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||||
"Populating with source tree is only supported for squashfs");
|
"Populating with source tree is only supported for read-only filesystems");
|
||||||
r = mkfs_exists(fstype);
|
r = mkfs_exists(fstype);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to determine whether mkfs binary for %s exists: %m", fstype);
|
return log_error_errno(r, "Failed to determine whether mkfs binary for %s exists: %m", fstype);
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "sd-id128.h"
|
#include "sd-id128.h"
|
||||||
|
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
int mkfs_exists(const char *fstype);
|
int mkfs_exists(const char *fstype);
|
||||||
|
|
||||||
int make_filesystem(const char *node, const char *fstype, const char *label, const char *root, 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);
|
||||||
|
Reference in New Issue
Block a user