[PATCH] lsblk: improve error reporting for invalid device paths

sina-abroshan <[email protected]> Sun, 15 Feb 2026 12:04:17 +0330
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
From: Sina Abroshan <[email protected]>

Differentiate stat() failures from non-block-device cases,
so users get accurate errno-based error messages.

Signed-off-by: Sina Abroshan <[email protected]>

---
v2:
 - Use tabs instead of spaces
 - Drop unnecessary _() around "%s"
---
 misc-utils/lsblk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 3d2bc21a6..6a8769bc7 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1797,7 +1797,12 @@ static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t d
 
 		DBG(DEV, ul_debug("%s: reading alone device", devname));
 
-		if (stat(devname, &st) || !S_ISBLK(st.st_mode)) {
+		if (stat(devname, &st) != 0) {
+			warn("%s", devname);
+			goto leave;
+		}
+
+		if (!S_ISBLK(st.st_mode)) {
 			warnx(_("%s: not a block device"), devname);
 			goto leave;
 		}
-- 
2.34.1