From: Daan De Meyer Date: Thu, 13 Oct 2022 11:45:34 +0000 (+0200) Subject: repart: Create loop device when populating filesystems if needed X-Git-Tag: v253-rc1~527^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c17515203b28ab7b4f946bf072de6fe98b50881;p=thirdparty%2Fsystemd.git repart: Create loop device when populating filesystems if needed --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 43b93eaa986..c917d5ded51 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