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