[U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Simon Glass
sjg at chromium.org
Sat Nov 1 16:13:12 CET 2014
Hi Christian,
On 31 October 2014 09:08, Christian Gmeiner <christian.gmeiner at gmail.com> wrote:
> 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.
>
> Hit any key to stop autoboot: 0
> => fsuuid
> fsuuid - Look up a filesystem UUID
>
> Usage:
> fsuuid <interface> <dev>:<part>
> - print filesystem UUID
> fsuuid <interface> <dev>:<part> <varname>
> - set environment variable to filesystem UUID
>
> => fsuuid mmc 0:1
> d9f9fc05-45ae-4a36-a616-fccce0e4f887
> => fsuuid mmc 0:2
> eb3db83c-7b28-499f-95ce-9e0bb21cda81
> => fsuuid mmc 0:1 uuid1
> => fsuuid mmc 0:2 uuid2
> => printenv uuid1
> uuid1=d9f9fc05-45ae-4a36-a616-fccce0e4f887
> => printenv uuid2
> uuid2=eb3db83c-7b28-499f-95ce-9e0bb21cda81
> =>
>
> Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
If this is version 2 you should have a change list. You can use patman
(tools/patman/patman) to automate this.
> ---
> README | 1 +
> common/Makefile | 1 +
> fs/ext4/ext4fs.c | 15 +++++++++++++++
> fs/fs.c | 39 +++++++++++++++++++++++++++++++++++++++
> include/ext4fs.h | 1 +
> include/fs.h | 2 ++
> 6 files changed, 59 insertions(+)
>
> diff --git a/README b/README
> index 7b5538e..53b84a6 100644
> --- a/README
> +++ b/README
> @@ -989,6 +989,7 @@ The following options need to be configured:
> CONFIG_CMD_EXT4 * ext4 command support
> CONFIG_CMD_FS_GENERIC * filesystem commands (e.g. load, ls)
> that work for multiple fs types
> + CONFIG_CMD_FS_UUID * Look up a filesystem UUID
> CONFIG_CMD_SAVEENV saveenv
> CONFIG_CMD_FDC * Floppy Disk Support
> CONFIG_CMD_FAT * FAT command support
> diff --git a/common/Makefile b/common/Makefile
> index 6cc4de8..508a0b2 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
> index cbdc220..61b6dc2 100644
> --- a/fs/ext4/ext4fs.c
> +++ b/fs/ext4/ext4fs.c
> @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename)
> return ext4fs_open(filename);
> }
>
> +int ext4fs_uuid(char *uuid_str)
> +{
> + if (ext4fs_root == NULL)
> + return -1;
> +
> +#ifdef CONFIG_LIB_UUID
> + uuid_bin_to_str((unsigned char *)ext4fs_root->sblock.unique_id,
> + uuid_str, UUID_STR_FORMAT_STD);
> +
> + return 0;
> +#endif
> +
> + return -ENOSYS;
> +}
> +
> int ext4fs_read(char *buf, unsigned len)
> {
> if (ext4fs_root == NULL || ext4fs_file == NULL)
> diff --git a/fs/fs.c b/fs/fs.c
> index dd680f3..492d8b1 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -15,6 +15,7 @@
> */
>
> #include <config.h>
> +#include <errno.h>
> #include <common.h>
> #include <part.h>
> #include <ext4fs.h>
> @@ -86,6 +87,7 @@ struct fstype_info {
> int (*read)(const char *filename, void *buf, int offset, int len);
> int (*write)(const char *filename, void *buf, int offset, int len);
> void (*close)(void);
> + int (*uuid)(char *uuid_str);
> };
>
> static struct fstype_info fstypes[] = {
> @@ -113,6 +115,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 +209,17 @@ static void fs_close(void)
> fs_type = FS_TYPE_ANY;
> }
>
> +int fs_uuid(char *uuid_str)
> +{
> + struct fstype_info *info = fs_get_info(fs_type);
> + int ret = -ENOSYS;
> +
> + if (info->uuid)
> + ret = info->uuid(uuid_str);
> +
> + return ret;
> +}
> +
> int fs_ls(const char *dirname)
> {
> int ret;
> @@ -443,3 +457,28 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
>
> return 0;
> }
> +
> +int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
> + int fstype)
> +{
> + int ret;
> + char uuid[37];
> + memset(uuid, 0, sizeof(uuid));
> +
> + if (argc < 3 || argc > 4)
> + return CMD_RET_USAGE;
> +
> + if (fs_set_blk_dev(argv[1], argv[2], fstype))
> + return 1;
> +
> + ret = fs_uuid(uuid);
> + if (ret)
> + return ret;
Here you should return CMD_RET_SUCCESS or CMD_RET_FAILURE. You should
not return raw errors since they are not the same thing.
> +
> + if (argc == 4)
> + setenv(argv[3], uuid);
> + else
> + printf("%s\n", uuid);
> +
> + return 0;
> +}
> diff --git a/include/ext4fs.h b/include/ext4fs.h
> index 6c419f3..19816de 100644
> --- a/include/ext4fs.h
> +++ b/include/ext4fs.h
> @@ -137,6 +137,7 @@ void ext4fs_reinit_global(void);
> int ext4fs_ls(const char *dirname);
> int ext4fs_exists(const char *filename);
> int ext4fs_size(const char *filename);
> +int ext4fs_uuid(char *uuid_str);
> void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
> int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
> void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
> diff --git a/include/fs.h b/include/fs.h
> index 06a45f2..41082b3 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -92,5 +92,7 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file,
> int fstype);
> int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
> int fstype);
> +int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
> + int fstype);
Can you please add a function comment for this?
>
> #endif /* _FS_H */
> --
> 1.9.3
>
Regards,
Simon
More information about the U-Boot
mailing list