From: Simon Glass <simon.glass@canonical.com> The filesystem uuid method is not implemented. Add ext4l_uuid() which returns the filesystem UUID as a string and wire it into the filesystem operations table. Add a test. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/interface.c | 20 ++++++++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 8 ++++++++ test/fs/ext4l.c | 32 +++++++++++++++++++++++++++++ test/py/tests/test_fs/test_ext4l.py | 7 +++++++ 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 34e659cd28b..f25664369e6 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -15,6 +15,7 @@ #include <membuf.h> #include <part.h> #include <malloc.h> +#include <u-boot/uuid.h> #include <linux/errno.h> #include <linux/jbd2.h> #include <linux/types.h> @@ -80,6 +81,25 @@ int ext4l_get_uuid(u8 *uuid) return 0; } +/** + * ext4l_uuid() - Get the filesystem UUID as a string + * + * @uuid_str: Buffer to receive the UUID string (must be at least 37 bytes) + * Return: 0 on success, -ENODEV if not mounted + */ +int ext4l_uuid(char *uuid_str) +{ + u8 uuid[16]; + int ret; + + ret = ext4l_get_uuid(uuid); + if (ret) + return ret; + uuid_bin_to_str(uuid, uuid_str, UUID_STR_FORMAT_STD); + + return 0; +} + /** * ext4l_set_blk_dev() - Set the block device for ext4l operations * diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 27a2d7be220..71f8e56715f 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -270,7 +270,7 @@ static struct fstype_info fstypes[] = { .size = ext4l_size, .read = ext4l_read, .write = fs_write_unsupported, - .uuid = fs_uuid_unsupported, + .uuid = ext4l_uuid, .opendir = ext4l_opendir, .readdir = ext4l_readdir, .closedir = ext4l_closedir, diff --git a/include/ext4l.h b/include/ext4l.h index 643060ee44c..9d9e79b7695 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -76,6 +76,14 @@ int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, */ int ext4l_get_uuid(u8 *uuid); +/** + * ext4l_uuid() - Get the filesystem UUID as a string + * + * @uuid_str: Buffer to receive the UUID string (must be at least 37 bytes) + * Return: 0 on success, -ENODEV if not mounted + */ +int ext4l_uuid(char *uuid_str); + /** * ext4l_opendir() - Open a directory for iteration * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 1bea9186d5a..02ad13ec71d 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -295,3 +295,35 @@ static int fs_test_ext4l_read_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_read_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_uuid_norun() - Test ext4l_uuid function + * + * Verifies that ext4l can return the filesystem UUID. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_uuid_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + char uuid_str[UUID_STR_LEN + 1]; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Get the UUID string */ + ut_assertok(ext4l_uuid(uuid_str)); + + /* Verify it's a valid UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) */ + ut_asserteq(UUID_STR_LEN, strlen(uuid_str)); + ut_asserteq('-', uuid_str[8]); + ut_asserteq('-', uuid_str[13]); + ut_asserteq('-', uuid_str[18]); + ut_asserteq('-', uuid_str[23]); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_uuid_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_fs/test_ext4l.py b/test/py/tests/test_fs/test_ext4l.py index 4064a6c53ff..2bbbe766e6a 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -117,3 +117,10 @@ class TestExt4l: output = ubman.run_command( f'ut -f fs fs_test_ext4l_read_norun fs_image={ext4_image}') assert 'failures: 0' in output + + def test_uuid(self, ubman, ext4_image): + """Test that ext4l can return the filesystem UUID.""" + with ubman.log.section('Test ext4l uuid'): + output = ubman.run_command( + f'ut -f fs fs_test_ext4l_uuid_norun fs_image={ext4_image}') + assert 'failures: 0' in output -- 2.43.0