From 86a9064a686624549a3a48994301daf201e416e2 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 10 Aug 2026 13:10:58 +0200 Subject: [PATCH] Add S_ISBLK checks to devdereference_btrfs and devdereference_bcachefs --- cmdline/unixapp.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmdline/unixapp.c b/cmdline/unixapp.c index 1b7e7652..0f206cbf 100644 --- a/cmdline/unixapp.c +++ b/cmdline/unixapp.c @@ -682,7 +682,7 @@ static int devdereference_btrfs(uint64_t device, const char* dir, int fd, tommy_ /* btrfs device IDs (devid) are not guaranteed to be contiguous */ if (errno == ENODEV || errno == ENOENT) continue; /* this is the expected error on missing id */ - log_error(errno, "Ioctl BTRFS_IOC_DEV_INFO failed. %s.", strerror(errno)); + log_error(errno, "Failed ioctl BTRFS_IOC_DEV_INFO. %s.", strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -691,6 +691,14 @@ static int devdereference_btrfs(uint64_t device, const char* dir, int fd, tommy_ struct stat st; if (stat((char*)dev_info.path, &st) != 0) { /* LCOV_EXCL_START */ + log_error(errno, "Failed stat %s. %s.", dev_info.path, strerror(errno)); + goto bail; + /* LCOV_EXCL_STOP */ + } + + if (!S_ISBLK(st.st_mode)) { + /* LCOV_EXCL_START */ + log_error(errno, "Device %s is not a block device.", dev_info.path); goto bail; /* LCOV_EXCL_STOP */ } @@ -811,6 +819,14 @@ static int devdereference_bcachefs(uint64_t device, const char* dir, tommy_list* struct stat st; if (stat(dev_map[i], &st) != 0) { /* LCOV_EXCL_START */ + log_error(errno, "Failed stat %s. %s.", dev_map[i], strerror(errno)); + goto bail; + /* LCOV_EXCL_STOP */ + } + + if (!S_ISBLK(st.st_mode)) { + /* LCOV_EXCL_START */ + log_error(errno, "Device %s is not a block device.", dev_map[i]); goto bail; /* LCOV_EXCL_STOP */ } @@ -972,6 +988,7 @@ static int devdereference_zfs(uint64_t device, const char* dir, tommy_list* devl struct stat st; if (stat(file, &st) != 0) { /* LCOV_EXCL_START */ + log_error(errno, "Failed stat %s. %s.", file, strerror(errno)); os_pclose(fp); goto bail; /* LCOV_EXCL_STOP */ @@ -979,6 +996,7 @@ static int devdereference_zfs(uint64_t device, const char* dir, tommy_list* devl if (!S_ISBLK(st.st_mode)) { /* LCOV_EXCL_START */ + log_error(errno, "Device %s is not a block device.", file); os_pclose(fp); goto bail; /* LCOV_EXCL_STOP */