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

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