Blame 0007-sysfs-fallback-for-partitions-not-including-parent-n.patch

Karel Zak 3fbed7
From 9c45c4bf1a1a02ebaf9e24fd7d81d62c676eda7c Mon Sep 17 00:00:00 2001
Karel Zak 101ae8
From: Portisch <hugo.portisch@yahoo.de>
Karel Zak 101ae8
Date: Mon, 8 Nov 2021 12:31:39 +0100
Karel Zak 101ae8
Subject: sysfs: fallback for partitions not including parent name
Karel Zak 101ae8
Karel Zak 101ae8
Upstream: http://github.com/util-linux/util-linux/commit/9b59641bcec3df9c451eea4c7057751a153a3fcb
Karel Zak 101ae8
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2021462
Karel Zak 101ae8
Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak 101ae8
---
Karel Zak 101ae8
 lib/sysfs.c | 12 +++++++-----
Karel Zak 101ae8
 1 file changed, 7 insertions(+), 5 deletions(-)
Karel Zak 101ae8
Karel Zak 101ae8
diff --git a/lib/sysfs.c b/lib/sysfs.c
Karel Zak 101ae8
index bb7183319..191d870f6 100644
Karel Zak 101ae8
--- a/lib/sysfs.c
Karel Zak 101ae8
+++ b/lib/sysfs.c
Karel Zak 101ae8
@@ -210,9 +210,10 @@ int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *par
Karel Zak 101ae8
 	    d->d_type != DT_UNKNOWN)
Karel Zak 101ae8
 		return 0;
Karel Zak 101ae8
 #endif
Karel Zak 101ae8
+	size_t len = 0;
Karel Zak 101ae8
+
Karel Zak 101ae8
 	if (parent_name) {
Karel Zak 101ae8
 		const char *p = parent_name;
Karel Zak 101ae8
-		size_t len;
Karel Zak 101ae8
 
Karel Zak 101ae8
 		/* /dev/sda --> "sda" */
Karel Zak 101ae8
 		if (*parent_name == '/') {
Karel Zak 101ae8
@@ -223,14 +224,15 @@ int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *par
Karel Zak 101ae8
 		}
Karel Zak 101ae8
 
Karel Zak 101ae8
 		len = strlen(p);
Karel Zak 101ae8
-		if (strlen(d->d_name) <= len)
Karel Zak 101ae8
-			return 0;
Karel Zak 101ae8
+		if ((strlen(d->d_name) <= len) || (strncmp(p, d->d_name, len) != 0))
Karel Zak 101ae8
+			len = 0;
Karel Zak 101ae8
+	}
Karel Zak 101ae8
 
Karel Zak 101ae8
+	if (len > 0) {
Karel Zak 101ae8
 		/* partitions subdir name is
Karel Zak 101ae8
 		 *	"<parent>[:digit:]" or "<parent>p[:digit:]"
Karel Zak 101ae8
 		 */
Karel Zak 101ae8
-		return strncmp(p, d->d_name, len) == 0 &&
Karel Zak 101ae8
-		       ((*(d->d_name + len) == 'p' && isdigit(*(d->d_name + len + 1)))
Karel Zak 101ae8
+		return ((*(d->d_name + len) == 'p' && isdigit(*(d->d_name + len + 1)))
Karel Zak 101ae8
 			|| isdigit(*(d->d_name + len)));
Karel Zak 101ae8
 	}
Karel Zak 101ae8
 
Karel Zak 101ae8
-- 
Karel Zak 101ae8
2.34.1
Karel Zak 101ae8