]>
Commit | Line | Data |
---|---|---|
a709a315 LP |
1 | #include <fcntl.h> |
2 | #include <linux/dm-ioctl.h> | |
a709a315 LP |
3 | #include <sys/ioctl.h> |
4 | ||
5 | #include "dm-util.h" | |
6 | #include "fd-util.h" | |
706fb348 | 7 | #include "string-util.h" |
a709a315 LP |
8 | |
9 | int dm_deferred_remove(const char *name) { | |
10 | ||
11 | struct dm_ioctl dm = { | |
12 | .version = { | |
13 | DM_VERSION_MAJOR, | |
14 | DM_VERSION_MINOR, | |
15 | DM_VERSION_PATCHLEVEL | |
16 | }, | |
17 | .data_size = sizeof(dm), | |
18 | .flags = DM_DEFERRED_REMOVE, | |
19 | }; | |
20 | ||
21 | _cleanup_close_ int fd = -1; | |
22 | ||
23 | assert(name); | |
24 | ||
25 | /* Unfortunately, libcryptsetup doesn't provide a proper API for this, hence call the ioctl() | |
26 | * directly. */ | |
27 | ||
706fb348 | 28 | if (strlen(name) >= sizeof(dm.name)) |
a709a315 LP |
29 | return -ENODEV; /* A device with a name longer than this cannot possibly exist */ |
30 | ||
31 | fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC); | |
32 | if (fd < 0) | |
33 | return -errno; | |
34 | ||
706fb348 | 35 | strncpy_exact(dm.name, name, sizeof(dm.name)); |
a709a315 LP |
36 | |
37 | if (ioctl(fd, DM_DEV_REMOVE, &dm)) | |
38 | return -errno; | |
39 | ||
40 | return 0; | |
41 | } |