blockdev-util: Remove dependency on string-util.h

Let's insist on a string literal in SYS_BLOCK_PATH_MAX() so that
we don't accidentally allocate VLAs and let's inline strempty() in
xsprintf_sys_block_path() so we don't need to include string-util.h
in blockdev-util.h

We'll remove the actual string-util.h include as part of #37344.
This commit is contained in:
Daan De Meyer
2025-05-14 16:56:05 +02:00
parent 5f3b558b99
commit bdcd47a269
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -542,7 +542,7 @@ static int blockdev_is_encrypted(const char *sysfs_path, unsigned depth_left) {
}
int fd_is_encrypted(int fd) {
char p[SYS_BLOCK_PATH_MAX(NULL)];
char p[SYS_BLOCK_PATH_MAX("")];
dev_t devt;
int r;
@@ -558,7 +558,7 @@ int fd_is_encrypted(int fd) {
}
int path_is_encrypted(const char *path) {
char p[SYS_BLOCK_PATH_MAX(NULL)];
char p[SYS_BLOCK_PATH_MAX("")];
dev_t devt;
int r;
+2 -2
View File
@@ -10,9 +10,9 @@
#include "string-util.h"
#define SYS_BLOCK_PATH_MAX(suffix) \
(STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + strlen_ptr(suffix))
(STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + STRLEN(suffix))
#define xsprintf_sys_block_path(buf, suffix, devno) \
xsprintf(buf, "/sys/dev/block/%u:%u%s", major(devno), minor(devno), strempty(suffix))
xsprintf(buf, "/sys/dev/block/%u:%u%s", major(devno), minor(devno), suffix ?: "")
typedef enum BlockDeviceLookupFlag {
BLOCK_DEVICE_LOOKUP_WHOLE_DISK = 1 << 0, /* whole block device, e.g. sda, nvme0n1, or loop0. */