lsblk: improve error reporting for invalid device paths
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
@@ -1793,14 +1793,20 @@ static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t dint 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
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
PATCH 1/1 lsblk: improve error reporting for invalid device paths
In reply to sina-abroshanFrom: 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
@@ -1797,7 +1797,12 @@ static int __process_one_device(struct lsblk_devtree *tr, char *devname, dev_t dDBG (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
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