Skip to content

Commit

Permalink
dissect: Don't count RPMB and boot partitions
Browse files Browse the repository at this point in the history
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
systemd/systemd#5806

https://phabricator.endlessm.com/T21744
  • Loading branch information
jprvita committed Apr 2, 2018
1 parent f08ebe1 commit 8c03387
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/shared/dissect-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ int probe_filesystem(const char *node, char **ret_fstype) {
#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, size_t root_hash_size, DissectImageFlags flags, DissectedImage **ret) {

#if HAVE_BLKID
Expand Down Expand Up @@ -277,8 +285,17 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
/* 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);
Expand Down Expand Up @@ -337,7 +354,7 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
_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;

Expand All @@ -352,11 +369,7 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
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);
Expand Down

0 comments on commit 8c03387

Please sign in to comment.