From: Stanislav Brabec <sbrabec@suse.cz>
To: util-linux@vger.kernel.org
Cc: Martin Wilck <martin.wilck@suse.com>
Subject: [PATCH] blockdev: Don't fail on missing start sector
Date: Mon, 1 Jun 2020 01:35:44 +0200 [thread overview]
Message-ID: <a7a4f974-8a32-efb3-0ba3-a25e77145946@suse.cz> (raw)
Device mapper devices don't provide start sector.
It causes "blockdev --report" error:
blockdev: /dev/dm-9: failed to read partition start from sysfs: No such
file or directory
There is no reliable way to detect a geometry in this case.
Report N/A instead.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Martin Wilck <martin.wilck@suse.com>
---
disk-utils/blockdev.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index f1067c815..ab18cfa66 100644
--- a/disk-utils/blockdev.c
+++ b/disk-utils/blockdev.c
@@ -455,6 +455,7 @@ static void report_device(char *device, int quiet)
long ra;
unsigned long long bytes;
uint64_t start = 0;
+ char start_str[11] = "";
struct stat st;
fd = open(device, O_RDONLY | O_NONBLOCK);
@@ -476,19 +477,21 @@ static void report_device(char *device, int quiet)
disk != st.st_rdev) {
if (ul_path_read_u64(pc, &start, "start") != 0)
- err(EXIT_FAILURE,
- _("%s: failed to read partition start from sysfs"),
- device);
+ /* TRANSLATORS: Start sector not available. Max. 10
letters. */
+ sprintf(start_str, "%10s", _("N/A"));
}
ul_unref_path(pc);
}
+ if (start_str[0] == 0)
+ sprintf(start_str, "%10ju", start);
+
if (ioctl(fd, BLKROGET, &ro) == 0 &&
ioctl(fd, BLKRAGET, &ra) == 0 &&
ioctl(fd, BLKSSZGET, &ssz) == 0 &&
ioctl(fd, BLKBSZGET, &bsz) == 0 &&
blkdev_get_size(fd, &bytes) == 0) {
- printf("%s %5ld %5d %5d %10ju %15lld %s\n",
- ro ? "ro" : "rw", ra, ssz, bsz, start, bytes, device);
+ printf("%s %5ld %5d %5d %s %15lld %s\n",
+ ro ? "ro" : "rw", ra, ssz, bsz, start_str, bytes, device);
} else {
if (!quiet)
warnx(_("ioctl error on %s"), device);
--
2.25.1
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
next reply other threads:[~2020-05-31 23:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-31 23:35 Stanislav Brabec [this message]
2020-06-01 8:13 ` [PATCH] blockdev: Don't fail on missing start sector Karel Zak
2020-06-02 1:52 ` Stanislav Brabec
2020-06-03 15:16 ` Karel Zak
2020-06-05 8:06 ` Karel Zak
2020-06-13 20:52 ` Stanislav Brabec
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=a7a4f974-8a32-efb3-0ba3-a25e77145946@suse.cz \
--to=sbrabec@suse.cz \
--cc=martin.wilck@suse.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;
as well as URLs for NNTP newsgroup(s).