]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: store device major/minor in LoopDevice object
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Mar 2021 20:22:22 +0000 (21:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 19 Apr 2021 21:16:02 +0000 (23:16 +0200)
Let's store this away. It's useful when matching up mounts (i.e.  struct
stat's .st_dev field) with loopback devices.

src/shared/loop-util.c
src/shared/loop-util.h

index 84f415aa61c1eb33af8adda898bdad419672a879..2aa4936965429bc25155d3f2fbf5192da43b48d7 100644 (file)
@@ -353,6 +353,7 @@ int loop_device_make(
                                 .nr = nr,
                                 .node = TAKE_PTR(loopdev),
                                 .relinquished = true, /* It's not allocated by us, don't destroy it when this object is freed */
+                                .devno = st.st_rdev,
                         };
 
                         *ret = d;
@@ -425,6 +426,10 @@ int loop_device_make(
                                               UINT64_C(240) * USEC_PER_MSEC * n_attempts/64));
         }
 
+        if (fstat(loop_with_fd, &st) < 0)
+                return -errno;
+        assert(S_ISBLK(st.st_mode));
+
         d = new(LoopDevice, 1);
         if (!d)
                 return -ENOMEM;
@@ -432,6 +437,7 @@ int loop_device_make(
                 .fd = TAKE_FD(loop_with_fd),
                 .node = TAKE_PTR(loopdev),
                 .nr = nr,
+                .devno = st.st_rdev,
         };
 
         *ret = d;
index 9538daea3116cc48cdf6e58df94e654303657fd9..619b34716bf26b4aa890cdcf8a40c3b211e3996c 100644 (file)
@@ -10,6 +10,7 @@ typedef struct LoopDevice LoopDevice;
 struct LoopDevice {
         int fd;
         int nr;
+        dev_t devno;
         char *node;
         bool relinquished;
 };