[U-Boot] [RFC] fs: make it possible to read the filesystem UUID

Simon Glass sjg at chromium.org
Thu Oct 30 02:42:56 CET 2014


Hi,

On 29 October 2014 13:57, Pavel Machek <pavel at denx.de> wrote:
> Hi!
>
>> Adding Stephen Warren, Simon Glass and Pavel Machek to CC list
>> (./scripts/get_maintainer.pl -f fs/fs.c).
>
> I'm not really fs maintainer, I added people that might be interested.
>>
>> 2014-10-22 15:29 GMT+02:00 Christian Gmeiner <christian.gmeiner at gmail.com>:
>> > Some filesystems have a UUID stored in its superblock. To
>> > allow using root=UUID=... for the kernel command line we
>> > need a way to read-out the filesystem UUID. This is what this
>> > patch tries to do.
>> >
>> > Keep in mind that this patch is an RFC and I hope to get some
>> > feedback on this patch.
>> >
>> > This is what blkid under linux gives me:
>> > /dev/sdh1: LABEL="data" UUID="b6995cec-97e2-48b8-94dc-8ba7afc92bac" TYPE="ext4" PARTUUID="43f21f0e-01"
>> > /dev/sdh2: LABEL="rfs" UUID="8d020de7-c75e-4674-948e-f7838a931b02" TYPE="ext4" PARTUUID="43f21f0e-02"
>> >
>> > And here is the output from u-boot:
>> > => sata init
>> > AHCI 0001.0300 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
>> > flags: ncq stag pm led clo only pmp pio slum part
>> > SATA Device Info:
>> > S/N: 000060059798A1000014
>> > Product model number: SFCA4096H1BR4TO-I-MS-236-STD
>> > Firmware version: 20111021
>> > Capacity: 7793856 sectors
>> > => fs_uuid sata 0:1 ; print fs_uuid; fs_uuid sata 0:2 ; print fs_uuid
>> > fs_uuid=b6995cec-97e2-48b8-94dc-8ba7afc92bac
>> > fs_uuid=8d020de7-c75e-4674-948e-f7838a931b02
>> >
>>
>> Really no feedback?
>
> I see nothing obviously wrong... But I'm not a fs/ maintainer. We
> don't have one, AFICT.
>
>> > Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
>> > ---
>> >  common/Makefile       |  1 +
>> >  common/cmd_fs_uuid.c  | 23 +++++++++++++++++++++++
>> >  fs/ext4/ext4_common.c |  9 +++++++++
>> >  fs/fs.c               | 28 ++++++++++++++++++++++++++++
>> >  include/ext4fs.h      |  1 +
>> >  include/fs.h          |  2 ++
>> >  6 files changed, 64 insertions(+)
>> >  create mode 100644 common/cmd_fs_uuid.c
>> >
>> > diff --git a/common/Makefile b/common/Makefile
>> > index b19d379..d5d3315 100644
>> > --- a/common/Makefile
>> > +++ b/common/Makefile
>> > @@ -188,6 +188,7 @@ obj-y += usb.o usb_hub.o
>> >  obj-$(CONFIG_USB_STORAGE) += usb_storage.o
>> >  endif
>> >  obj-$(CONFIG_CMD_FASTBOOT) += cmd_fastboot.o
>> > +obj-$(CONFIG_CMD_FS_UUID) += cmd_fs_uuid.o
>> >
>> >  obj-$(CONFIG_CMD_USB_MASS_STORAGE) += cmd_usb_mass_storage.o
>> >  obj-$(CONFIG_CMD_THOR_DOWNLOAD) += cmd_thordown.o
>> > diff --git a/common/cmd_fs_uuid.c b/common/cmd_fs_uuid.c
>> > new file mode 100644
>> > index 0000000..3af9518
>> > --- /dev/null
>> > +++ b/common/cmd_fs_uuid.c
>> > @@ -0,0 +1,23 @@
>> > +/*
>> > + * cmd_fs_uuid.c -- fs_uuid command
>> > + *
>> > + * Copyright (C) 2014, Bachmann electronic GmbH
>> > + *
>> > + * SPDX-License-Identifier:    GPL-2.0+
>> > + */
>> > +
>> > +#include <common.h>
>> > +#include <command.h>
>> > +#include <fs.h>
>> > +
>> > +static int do_fs_uuid_wrapper(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>> > +{
>> > +       return do_fs_uuid(cmdtp, flag, argc, argv, FS_TYPE_ANY);
>> > +}
>> > +
>> > +U_BOOT_CMD(
>> > +       fs_uuid,        3,      0,      do_fs_uuid_wrapper,
>> > +       "filesystem UUDI related commands",
>> > +       "<interface> <dev>:<part>\n"
>> > +       "    - print filesystem UUID\n"
>> > +);
>> > diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
>> > index 33d69c9..926b6c6 100644
>> > --- a/fs/ext4/ext4_common.c
>> > +++ b/fs/ext4/ext4_common.c
>> > @@ -2246,3 +2246,12 @@ fail:
>> >
>> >         return 0;
>> >  }
>> > +
>> > +void ext4fs_uuid(char *uuid_str)
>> > +{
>> > +       if (ext4fs_root == NULL)
>> > +               return;
>> > +
>> > +       uuid_bin_to_str((unsigned char *)ext4fs_root->sblock.unique_id, uuid_str,
>> > +                       UUID_STR_FORMAT_STD);
>> > +}
>> > diff --git a/fs/fs.c b/fs/fs.c
>> > index dd680f3..f8c6d64 100644
>> > --- a/fs/fs.c
>> > +++ b/fs/fs.c
>> > @@ -85,6 +85,7 @@ struct fstype_info {
>> >         int (*size)(const char *filename);
>> >         int (*read)(const char *filename, void *buf, int offset, int len);
>> >         int (*write)(const char *filename, void *buf, int offset, int len);
>> > +       void (*uuid)(char *uuid_str);
>> >         void (*close)(void);
>> >  };
>> >
>> > @@ -113,6 +114,7 @@ static struct fstype_info fstypes[] = {
>> >                 .size = ext4fs_size,
>> >                 .read = ext4_read_file,
>> >                 .write = fs_write_unsupported,
>> > +               .uuid = ext4fs_uuid,
>> >         },
>> >  #endif
>> >  #ifdef CONFIG_SANDBOX
>> > @@ -206,6 +208,14 @@ static void fs_close(void)
>> >         fs_type = FS_TYPE_ANY;
>> >  }
>> >
>>
>> Should I do add an #ifdef CONFIG_CMD_FS_UUID around .uuid = ext4fs_uuid?
>> Or speaking more general: At which places should I add this ifdef to
>> opt-in the FS_UUID
>> feature?
>
> I guess so. And I guess it is worth it to remove ext4fs_uuid function
> when !defined(CONFIG_CMD_FS_UUID)...

You add very little new code so I doubt it is worth it?

Regards,
Simon


More information about the U-Boot mailing list