summaryrefslogtreecommitdiffstats
path: root/src/shared/loop-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-22 21:22:22 +0100
committerLennart Poettering <lennart@poettering.net>2021-04-19 23:16:02 +0200
commitf3859d5f5591494c3022d6e9e4af1538174526fd (patch)
treef4c0c0bba4bf7a78386ac86e73ae1de1bac22e00 /src/shared/loop-util.c
parentrepart: add high-level setting for creating dirs in formatted file systems (diff)
downloadsystemd-f3859d5f5591494c3022d6e9e4af1538174526fd.tar.xz
systemd-f3859d5f5591494c3022d6e9e4af1538174526fd.zip
loop-util: store device major/minor in LoopDevice object
Let's store this away. It's useful when matching up mounts (i.e. struct stat's .st_dev field) with loopback devices.
Diffstat (limited to 'src/shared/loop-util.c')
-rw-r--r--src/shared/loop-util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c
index 84f415aa61..2aa4936965 100644
--- a/src/shared/loop-util.c
+++ b/src/shared/loop-util.c
@@ -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;