public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lsblk: improve error reporting for invalid device paths
@ 2026-02-12 11:24 sina-abroshan
  2026-02-14 15:24 ` Benno Schulenberg
  2026-02-15  8:34 ` sina-abroshan
  0 siblings, 2 replies; 4+ messages in thread
From: sina-abroshan @ 2026-02-12 11:24 UTC (permalink / raw)
  To: util-linux; +Cc: kzak, sina-abroshan

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

Signed-off-by: sina-abroshan <sina.abroshan@gmail.com>
---
 misc-utils/lsblk.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 3d2bc21a6..4a0d7c70e 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1793,14 +1793,20 @@ static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t d
 	int real_part = 0, rc = -EINVAL;
 
 	if (devno == 0 && devname) {
-		struct stat st;
+    	struct stat st;
 
-		DBG(DEV, ul_debug("%s: reading alone device", devname));
+    	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;
 		}
+
 		devno = st.st_rdev;
 	} else if (devno) {
 		DBG(DEV, ul_debug("%d:%d: reading alone device", major(devno), minor(devno)));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-18 10:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 11:24 [PATCH] lsblk: improve error reporting for invalid device paths sina-abroshan
2026-02-14 15:24 ` Benno Schulenberg
2026-02-15  8:34 ` sina-abroshan
2026-02-18 10:01   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox