Skip to contentSkip to conversation

lsblk: improve error reporting for invalid device paths

PATCH In review sina-abroshan 3 participants 4 messages Feb 12 – Feb 18 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lsblk: improve error reporting for invalid device paths

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

---
 misc-utils/lsblk.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
misc-utils/lsblk.c +9 -3
index 3d2bc21a6..4a0d7c70e 100644
@@ -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)));
Signature · 1 line
2.34.1
#1 lore raw

Op 12-02-2026 om 12:24 schreef sina-abroshan:

misc-utils/lsblk.c static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t d · line 1798

Quoted 5 lines
misc-utils/lsblk.c +2 -2
-		struct stat st;
+    	struct stat st;
 
-		DBG(DEV, ul_debug("%s: reading alone device", devname));
+    	DBG(DEV, ul_debug("%s: reading alone device", devname));

Why these whitespace changes? There should be tabs there, not spaces.

misc-utils/lsblk.c static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t d · line 1801

Quoted 3 lines
misc-utils/lsblk.c +2 -1
-		if (stat(devname, &st) || !S_ISBLK(st.st_mode)) {
+		if (stat(devname, &st) != 0) {
+			warn(_("%s"), devname);

Gettextizing a message that contains nothing translatable is pointless. In other words: drop the _() call.

Benno

#2 lore raw

PATCH 1/1 lsblk: improve error reporting for invalid device paths

In reply to sina-abroshan

From: Sina Abroshan <[email protected]>

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

---
v2:
- Use tabs instead of spaces
- Drop unnecessary _() around "%s"

---
 misc-utils/lsblk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
misc-utils/lsblk.c +6 -1
index 3d2bc21a6..6a8769bc7 100644
@@ -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;
 		}
Signature · 1 line
2.34.1
maintainer Applied
#3 lore raw
Quoted 2 lines · sina-abroshan
 misc-utils/lsblk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com