File util-linux-blockdev-report-dm.patch of Package util-linux.31381

From 0a0b01c117fa8da8e3ac3d39256dfb5e5d0a0976 Mon Sep 17 00:00:00 2001
From: Stanislav Brabec <sbrabec@suse.cz>
Date: Tue, 26 May 2020 02:46:30 +0200
Subject: [PATCH] blockdev: Don't fail on missing start sector

Device mapper devices don't provide start sector. Don't fail
"blockdev --report" in this case, report N/A instead.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
 disk-utils/blockdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Index: util-linux-2.31.1/disk-utils/blockdev.c
===================================================================
--- util-linux-2.31.1.orig/disk-utils/blockdev.c
+++ util-linux-2.31.1/disk-utils/blockdev.c
@@ -457,6 +457,7 @@ static void report_device(char *device,
 	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,18 +477,20 @@ static void report_device(char *device,
 				_("%s: failed to initialize sysfs handler"),
 				device);
 		if (sysfs_read_u64(&cxt, "start", &start))
-			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"));
 		sysfs_deinit(&cxt);
 	}
+	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);
openSUSE Build Service is sponsored by