[klibc] [PATCH] kinit: Support specifying root with PARTLABEL

Ben Hutchings ben at decadent.org.uk
Sun Jul 23 14:03:26 PDT 2023


On Thu, 2023-07-20 at 14:08 +0200, Rob Vandermeulen wrote:
> Allow specifying the root device to be mounted as root=PARTLABEL=label.
> The label is the GPT partition label of the intended root partition, as
> presented by the kernel with the uevent entry PARTNAME.

It's unfortunate that this doesn't handle PARTUUID here as well.  But I
realise that's not yet possible because no-one thought to expose that
information to user-space when adding it to the kernel...

I spotted one bug, commented below:

> Signed-off-by: Rob Vandermeulen <rvandermeulen at google.com>
> ---
>  usr/kinit/name_to_dev.c | 71 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 71 insertions(+)
> 
> diff --git a/usr/kinit/name_to_dev.c b/usr/kinit/name_to_dev.c
> index d8c17363..76cc4f81 100644
> --- a/usr/kinit/name_to_dev.c
> +++ b/usr/kinit/name_to_dev.c
> @@ -1,4 +1,6 @@
>  #include <ctype.h>
> +#include <dirent.h>
> +#include <errno.h>
>  #include <fcntl.h>
>  #include <sys/stat.h>
>  #include <stdio.h>
> @@ -73,6 +75,71 @@ fail:
>  	return (dev_t) 0;
>  }
>  
> +/*
> + * Find dev_t for a block device based on the provided GPT partlabel.
> + * The partlabel to block device mapping is found by scanning all
> + * the entries in /sys/dev/block/, opening the uevent file and picking
> + * the device where the PARTNAME= entry matches partlabel.
> + */
> +static dev_t partlabel_to_dev_t(const char *plabel)
> +{
> +	char path[BUF_SZ];
> +	DIR *dir;
> +	FILE *fp;
> +	struct dirent *dent;
> +	char *ret;
> +	char line[BUF_SZ];
> +	int match_label = 0;
> +	int major = 0;
> +	int minor = 0;
[...]

These 3 variables need to be reinitialised for each file, not just
once.  Otherwise we could (in principle) match on a combination of
information from different files.

Ben.

-- 
Ben Hutchings
If you seem to know what you are doing, you'll be given more to do.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zytor.com/archives/klibc/attachments/20230723/1a51b3e7/attachment.sig>


More information about the klibc mailing list