cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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