summaryrefslogtreecommitdiffstats
path: root/src/partition/repart.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-10-13 13:45:34 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-11-11 13:49:49 +0100
commit7c17515203b28ab7b4f946bf072de6fe98b50881 (patch)
treebe9397076414197184289e27ac69b5b9bc8adfe5 /src/partition/repart.c
parentrepart: Move fstype_is_ro() checks out of the populate functions (diff)
downloadsystemd-7c17515203b28ab7b4f946bf072de6fe98b50881.tar.xz
systemd-7c17515203b28ab7b4f946bf072de6fe98b50881.zip
repart: Create loop device when populating filesystems if needed
Diffstat (limited to '')
-rw-r--r--src/partition/repart.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 43b93eaa98..c917d5ded5 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -3383,6 +3383,8 @@ static int partition_populate_directory(Partition *p, const Set *denylist, char
}
static int partition_populate_filesystem(Partition *p, const char *node, const Set *denylist) {
+ _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
+ struct stat st;
int r;
assert(p);
@@ -3391,6 +3393,17 @@ static int partition_populate_filesystem(Partition *p, const char *node, const S
if (strv_isempty(p->copy_files) && strv_isempty(p->make_directories))
return 0;
+ if (stat(node, &st) < 0)
+ return log_error_errno(errno, "Failed to stat %s: %m", node);
+
+ if (!S_ISBLK(st.st_mode)) {
+ r = loop_device_make_by_path(node, O_RDWR, 0, LOCK_EX, &d);
+ if (r < 0)
+ return log_error_errno(r, "Failed to make loopback device of %s: %m", node);
+
+ node = d->node;
+ }
+
log_info("Populating partition %" PRIu64 " with files.", p->partno);
/* We copy in a child process, since we have to mount the fs for that, and we don't want that fs to