summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@gmail.com>2018-04-03 05:51:18 -0700
committerLennart Poettering <lennart@poettering.net>2018-04-03 14:51:18 +0200
commitcde942f61bf231ea4a0d50780cdb4e744458daeb (patch)
tree8e2bbc8e20c728143b624dce7ce9f7eb30281868 /src
parentbd6ae7e6f05964200cd51e7942a3fb5a2b6994e7 (diff)
downloadsystemd-cde942f61bf231ea4a0d50780cdb4e744458daeb.tar.gz
dissect: Don't count RPMB and boot partitions (#8609)
Filter-out RPMB partitions and boot partitions from MMC devices when counting partitions enumerated by the kernel. Also factor out the now duplicated code into a separate function. This complement the previous fixes to the problem reported in https://github.com/systemd/systemd/issues/5806
Diffstat (limited to 'src')
-rw-r--r--src/shared/dissect-image.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 7af59422b2..0f8d89ffb6 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -108,6 +108,14 @@ not_found:
#endif
}
+/* Detect RPMB and Boot partitions, which are not listed by blkid.
+ * See https://github.com/systemd/systemd/issues/5806. */
+static bool device_is_mmc_special_partition(struct udev_device *d) {
+ const char *sysname = udev_device_get_sysname(d);
+ return (sysname && startswith(sysname, "mmcblk") &&
+ (endswith(sysname, "rpmb") || endswith(sysname, "boot0") || endswith(sysname, "boot1")));
+}
+
int dissect_image(
int fd,
const void *root_hash,
@@ -282,8 +290,17 @@ int dissect_image(
/* Count the partitions enumerated by the kernel */
n = 0;
first = udev_enumerate_get_list_entry(e);
- udev_list_entry_foreach(item, first)
+ udev_list_entry_foreach(item, first) {
+ _cleanup_udev_device_unref_ struct udev_device *q;
+
+ q = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
+ if (!q)
+ return -errno;
+
+ if (device_is_mmc_special_partition(q))
+ continue;
n++;
+ }
/* Count the partitions enumerated by blkid */
z = blkid_partlist_numof_partitions(pl);
@@ -342,7 +359,7 @@ int dissect_image(
_cleanup_udev_device_unref_ struct udev_device *q;
unsigned long long pflags;
blkid_partition pp;
- const char *node, *sysname;
+ const char *node;
dev_t qn;
int nr;
@@ -357,11 +374,7 @@ int dissect_image(
if (st.st_rdev == qn)
continue;
- /* Filter out weird MMC RPMB partitions, which cannot reasonably be read, see
- * https://github.com/systemd/systemd/issues/5806 */
- sysname = udev_device_get_sysname(q);
- if (sysname && startswith(sysname, "mmcblk") &&
- (endswith(sysname, "rpmb") || endswith(sysname, "boot0" ) || endswith(sysname, "boot1")))
+ if (device_is_mmc_special_partition(q))
continue;
node = udev_device_get_devnode(q);