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

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