mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
With gcc-9.1.1-2.fc31.x86_64 and -Doptimization=2:
../src/shared/dm-util.c: In function ‘dm_deferred_remove’:
../src/shared/dm-util.c:35:9: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation]
35 | strncpy(dm.name, name, sizeof(dm.name));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc is plain wrong here, because we checked strlen(name) a few lines above, so
there can be no truncation and even the terminator always fits. But let's avoid
the warning.
43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
#include <fcntl.h>
|
|
#include <linux/dm-ioctl.h>
|
|
#include <string.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "dm-util.h"
|
|
#include "fd-util.h"
|
|
#include "string-util.h"
|
|
|
|
int dm_deferred_remove(const char *name) {
|
|
|
|
struct dm_ioctl dm = {
|
|
.version = {
|
|
DM_VERSION_MAJOR,
|
|
DM_VERSION_MINOR,
|
|
DM_VERSION_PATCHLEVEL
|
|
},
|
|
.data_size = sizeof(dm),
|
|
.flags = DM_DEFERRED_REMOVE,
|
|
};
|
|
|
|
_cleanup_close_ int fd = -1;
|
|
|
|
assert(name);
|
|
|
|
/* Unfortunately, libcryptsetup doesn't provide a proper API for this, hence call the ioctl()
|
|
* directly. */
|
|
|
|
if (strlen(name) >= sizeof(dm.name))
|
|
return -ENODEV; /* A device with a name longer than this cannot possibly exist */
|
|
|
|
fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
|
|
if (fd < 0)
|
|
return -errno;
|
|
|
|
strncpy_exact(dm.name, name, sizeof(dm.name));
|
|
|
|
if (ioctl(fd, DM_DEV_REMOVE, &dm))
|
|
return -errno;
|
|
|
|
return 0;
|
|
}
|