From: sina-abroshan <sina.abroshan@gmail.com>
To: util-linux@vger.kernel.org
Cc: kzak@redhat.com, sina-abroshan <sina.abroshan@gmail.com>
Subject: [PATCH] lsblk: improve error reporting for invalid device paths
Date: Thu, 12 Feb 2026 14:54:23 +0330 [thread overview]
Message-ID: <20260212112423.2400888-1-sina.abroshan@gmail.com> (raw)
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
next reply other threads:[~2026-02-12 11:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 11:24 sina-abroshan [this message]
2026-02-14 15:24 ` [PATCH] lsblk: improve error reporting for invalid device paths Benno Schulenberg
2026-02-15 8:34 ` sina-abroshan
2026-02-18 10:01 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260212112423.2400888-1-sina.abroshan@gmail.com \
--to=sina.abroshan@gmail.com \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox