]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Create loop device when populating filesystems if needed
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 13 Oct 2022 11:45:34 +0000 (13:45 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 11 Nov 2022 12:49:49 +0000 (13:49 +0100)
src/partition/repart.c

index 43b93eaa986f26c3b0edb1e9ebb26d7cb6b61b11..c917d5ded510ec511f8efd8ce5146089d08df270 100644 (file)
@@ -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