/src/systemd/src/shared/dm-util.c
Line | Count | Source |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | |
3 | | #include <fcntl.h> |
4 | | #include <linux/dm-ioctl.h> |
5 | | #include <sys/ioctl.h> |
6 | | |
7 | | #include "dm-util.h" |
8 | | #include "fd-util.h" |
9 | | #include "string-util.h" |
10 | | |
11 | 0 | int dm_deferred_remove_cancel(const char *name) { |
12 | 0 | _cleanup_close_ int fd = -EBADF; |
13 | |
|
14 | 0 | struct combined { |
15 | 0 | struct dm_ioctl dm_ioctl; |
16 | 0 | struct dm_target_msg dm_target_msg; |
17 | 0 | } _packed_; |
18 | |
|
19 | 0 | union message { |
20 | 0 | struct combined combined; |
21 | 0 | struct { |
22 | 0 | uint8_t space[offsetof(struct combined, dm_target_msg.message)]; |
23 | 0 | char text[STRLEN("@cancel_deferred_remove") + 1]; |
24 | 0 | } _packed_; |
25 | 0 | } message = { |
26 | 0 | .combined.dm_ioctl = { |
27 | 0 | .version = { |
28 | 0 | DM_VERSION_MAJOR, |
29 | 0 | DM_VERSION_MINOR, |
30 | 0 | DM_VERSION_PATCHLEVEL |
31 | 0 | }, |
32 | 0 | .data_size = sizeof(union message), |
33 | 0 | .data_start = offsetof(union message, combined.dm_target_msg), |
34 | 0 | }, |
35 | 0 | }; |
36 | |
|
37 | 0 | assert(name); |
38 | |
|
39 | 0 | if (strlen(name) >= sizeof(message.combined.dm_ioctl.name)) |
40 | 0 | return -ENODEV; /* A device with a name longer than this cannot possibly exist */ |
41 | | |
42 | 0 | strncpy_exact(message.combined.dm_ioctl.name, name, sizeof(message.combined.dm_ioctl.name)); |
43 | 0 | strncpy_exact(message.text, "@cancel_deferred_remove", sizeof(message.text)); |
44 | |
|
45 | 0 | fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC); |
46 | 0 | if (fd < 0) |
47 | 0 | return -errno; |
48 | | |
49 | 0 | if (ioctl(fd, DM_TARGET_MSG, &message)) |
50 | 0 | return -errno; |
51 | | |
52 | 0 | return 0; |
53 | 0 | } |