stat-util: also introduce stat_verify_block() and use it everywhere

This commit is contained in:
Lennart Poettering
2026-04-13 13:20:43 +02:00
parent 7f2410deb1
commit bda7e91337
12 changed files with 68 additions and 37 deletions
+22
View File
@@ -203,6 +203,28 @@ int fd_verify_linked(int fd) {
return verify_stat_at(fd, NULL, false, stat_verify_linked, true);
}
int stat_verify_block(const struct stat *st) {
assert(st);
if (S_ISDIR(st->st_mode))
return -EISDIR;
if (S_ISLNK(st->st_mode))
return -ELOOP;
if (!S_ISBLK(st->st_mode))
return -ENOTBLK;
return 0;
}
int fd_verify_block(int fd) {
if (IN_SET(fd, AT_FDCWD, XAT_FDROOT))
return -EISDIR;
return verify_stat_at(fd, /* path= */ NULL, /* follow= */ false, stat_verify_block, /* verify= */ true);
}
int stat_verify_device_node(const struct stat *st) {
assert(st);
+3
View File
@@ -28,6 +28,9 @@ int is_socket(const char *path);
int stat_verify_linked(const struct stat *st);
int fd_verify_linked(int fd);
int stat_verify_block(const struct stat *st);
int fd_verify_block(int fd);
int stat_verify_device_node(const struct stat *st);
int is_device_node(const char *path);