Skip to contentSkip to conversation

fs: exfat: Add exfat port based on exfat-fuse

PATCH Superseded Marek Vasut 2 participants 15 messages Mar 13, 2025 – Mar 17, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover fs: exfat: Add exfat port based on exfat-fuse

Import exfat-fuse libexfat, add U-Boot filesystem layer porting glue code and wire exfat support into generic filesystem support code. This adds exfat support to U-Boot.

Fill in generic filesystem interface for mkdir and rm commands. Make filesystem tests test the generic interface as well as exfat, to make sure this code does not fall apart.

[1] https://github.com/relan/exfat

    0b41c6d3560d ("CI: bump FreeBSD to 13.1.")

Marek Vasut (11):
cmd: fs: Add generic mkdir implementation
cmd: fs: Add generic rm implementation
test_fs: Allow testing FS_GENERIC
linux: Add generic struct stat {}
fs: Add generic fs_devread() implementation
fs: exfat: Import libexfat from fuse-exfat
fs: exfat: Add U-Boot porting layer
fs: exfat: Fix conversion overflow errors
fs: exfat: Demote filesystem detection failure message to debug()
configs: sandbox: Enable exfat support
test_fs: Add exfat tests

 cmd/fs.c                                |   28 +
 configs/sandbox64_defconfig             |    1 +
 configs/sandbox_defconfig               |    1 +
 fs/Kconfig                              |    2 +
 fs/Makefile                             |    1 +
 fs/exfat/Kconfig                        |    5 +
 fs/exfat/Makefile                       |   13 +
 fs/exfat/byteorder.h                    |   68 ++
 fs/exfat/cluster.c                      |  496 +++++++++
 fs/exfat/compiler.h                     |   69 ++
 fs/exfat/exfat.h                        |  259 +++++
 fs/exfat/exfatfs.h                      |  200 ++++
 fs/exfat/io.c                           | 1000 ++++++++++++++++++
 fs/exfat/lookup.c                       |  225 ++++
 fs/exfat/mount.c                        |  380 +++++++
 fs/exfat/node.c                         | 1243 +++++++++++++++++++++++
 fs/exfat/platform.h                     |   75 ++
 fs/exfat/repair.c                       |  115 +++
 fs/exfat/time.c                         |  175 ++++
 fs/exfat/utf.c                          |  254 +++++
 fs/exfat/utils.c                        |  192 ++++
 fs/fs.c                                 |   22 +
 fs/fs_internal.c                        |  102 ++
 include/exfat.h                         |   24 +
 include/fs.h                            |    3 +-
 include/fs_internal.h                   |    2 +
 include/linux/stat.h                    |   45 +-
 test/py/requirements.txt                |    1 +
 test/py/tests/fs_helper.py              |    8 +-
 test/py/tests/test_fs/conftest.py       |   44 +-
 test/py/tests/test_fs/fstest_helpers.py |    2 +
 test/py/tests/test_fs/test_basic.py     |   71 +-
 test/py/tests/test_fs/test_ext.py       |  176 ++--
 test/py/tests/test_fs/test_mkdir.py     |   42 +-
 test/py/tests/test_fs/test_unlink.py    |   38 +-
 tools/docker/Dockerfile                 |    1 +
 36 files changed, 5202 insertions(+), 181 deletions(-)
 create mode 100644 fs/exfat/Kconfig
 create mode 100644 fs/exfat/Makefile
 create mode 100644 fs/exfat/byteorder.h
 create mode 100644 fs/exfat/cluster.c
 create mode 100644 fs/exfat/compiler.h
 create mode 100644 fs/exfat/exfat.h
 create mode 100644 fs/exfat/exfatfs.h
 create mode 100644 fs/exfat/io.c
 create mode 100644 fs/exfat/lookup.c
 create mode 100644 fs/exfat/mount.c
 create mode 100644 fs/exfat/node.c
 create mode 100644 fs/exfat/platform.h
 create mode 100644 fs/exfat/repair.c
 create mode 100644 fs/exfat/time.c
 create mode 100644 fs/exfat/utf.c
 create mode 100644 fs/exfat/utils.c
 create mode 100644 include/exfat.h

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]

Signature · 1 line
2.47.2
#1 lore raw

PATCH v2 1/11 cmd: fs: Add generic mkdir implementation

Add generic implementation of the 'mkdir' command to create directories in filesystems using the generic filesystem API.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Add RB from Tom

---
 cmd/fs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
cmd/fs.c +14 -0
index 3faf7627447..bccc3a129bd 100644
@@ -85,6 +85,20 @@ U_BOOT_CMD(
 	"      device type 'interface' instance 'dev'."
 );
 
+static int do_mkdir_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
+			    char *const argv[])
+{
+	return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+	mkdir,	4,	1,	do_mkdir_wrapper,
+	"create a directory",
+	"<interface> [<dev[:part]>] <directory>\n"
+	"    - Create a directory 'directory' of partition 'part' on\n"
+	"      device type 'interface' instance 'dev'."
+);
+
 static int do_fstype_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
 			     char *const argv[])
 {
Signature · 1 line
2.47.2
#2 lore raw

PATCH v2 2/11 cmd: fs: Add generic rm implementation

In reply to Marek Vasut

Add generic implementation of the 'rm' command to delete files from filesystems using the generic filesystem API.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Add RB from Tom

---
 cmd/fs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
cmd/fs.c +14 -0
index bccc3a129bd..7f1ab8f0fd2 100644
@@ -99,6 +99,20 @@ U_BOOT_CMD(
 	"      device type 'interface' instance 'dev'."
 );
 
+static int do_rm_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	return do_rm(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+	rm,	4,	1,	do_rm_wrapper,
+	"delete a file",
+	"<interface> [<dev[:part]>] <filename>\n"
+	"    - delete a file with the name 'filename' on\n"
+	"      device type 'interface' instance 'dev'."
+);
+
 static int do_fstype_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
 			     char *const argv[])
 {
Signature · 1 line
2.47.2
#3 lore raw

PATCH v2 3/11 test_fs: Allow testing FS_GENERIC

In reply to Marek Vasut

The generic filesystem interface was so far untested. The interface is similar to the FS specific interfaces with FS specific prefixes, like ext4ls, fatmkdir, ... but it does not have any prefixes, i.e. it provides plain ls, mkdir, ... commands.

Extend the test parameters to include 'fs_cmd_prefix' and optionally 'fs_cmd_write' parameters. The 'fs_cmd_prefix' allow specifying the filesystem specific command prefix, like 'ext4' in 'ext4ls'. The 'fs_cmd_write' allows selecting between 'write'/'save' command name for storing files into the filesystem, see last paragraph.

Introduce new 'fs_generic' fs_type which is used to parametrize existing tests and run them without any prefixes if detected, thus testing the generic filesystem interface. Use the fatfs as the backing store for the generic FS tests.

The check_ubconfig needs to be slightly adjusted to avoid test for CMD_FS_GENERIC_WRITE which does not exist separately from CMD_FS_GENERIC.

The CMD_FS_GENERIC does not provide generic 'write' command, instead the generic equivalent command is called 'save' . Add simple ternary oeprator to use 'save' command for CMD_FS_GENERIC tests and '..write' commands for filesystem specific tests.

Enable generic filesystem tests for basic/extended/mkdir/unlink tests.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: No change

---
 test/py/tests/fs_helper.py           |   2 +-
 test/py/tests/test_fs/conftest.py    |  40 +++++--
 test/py/tests/test_fs/test_basic.py  |  71 ++++++------
 test/py/tests/test_fs/test_ext.py    | 156 +++++++++++++--------------
 test/py/tests/test_fs/test_mkdir.py  |  42 ++++----
 test/py/tests/test_fs/test_unlink.py |  38 +++----
 6 files changed, 187 insertions(+), 162 deletions(-)
test/py/tests/fs_helper.py +1 -1
index ccfc0201a49..378d5ae0690 100644
@@ -35,7 +35,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
     else:
         mkfs_opt = ''
 
-    if re.match('fat', fs_type):
+    if re.match('fat', fs_type) or fs_type == 'fs_generic':
         fs_lnxtype = 'vfat'
     else:
         fs_lnxtype = fs_type
test/py/tests/test_fs/conftest.py +32 -8
index 7bfcf41ed6f..5baddb24545 100644
@@ -12,11 +12,11 @@ import u_boot_utils as util
 # pylint: disable=E0611
 from tests import fs_helper
 
-supported_fs_basic = ['fat16', 'fat32', 'ext4']
-supported_fs_ext = ['fat12', 'fat16', 'fat32']
+supported_fs_basic = ['fat16', 'fat32', 'ext4', 'fs_generic']
+supported_fs_ext = ['fat12', 'fat16', 'fat32', 'fs_generic']
 supported_fs_fat = ['fat12', 'fat16']
-supported_fs_mkdir = ['fat12', 'fat16', 'fat32']
-supported_fs_unlink = ['fat12', 'fat16', 'fat32']
+supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'fs_generic']
+supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'fs_generic']
 supported_fs_symlink = ['ext4']
 supported_fs_rename = ['fat12', 'fat16', 'fat32']
 
@@ -109,6 +109,22 @@ def pytest_generate_tests(metafunc):
 #
 # Helper functions
 #
+def fstype_to_prefix(fs_type):
+    """Convert a file system type to an U-Boot command prefix
+
+    Args:
+        fs_type: File system type.
+
+    Return:
+        A corresponding command prefix for file system type.
+    """
+    if fs_type == 'fs_generic':
+        return ''
+    elif re.match('fat', fs_type):
+        return 'fat'
+    else:
+        return fs_type
+
 def fstype_to_ubname(fs_type):
     """Convert a file system type to an U-Boot specific string
 
@@ -142,6 +158,8 @@ def check_ubconfig(config, fs_type):
     """
     if not config.buildconfig.get('config_cmd_%s' % fs_type, None):
         pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper())
+    if fs_type == 'fs_generic':
+        return
     if not config.buildconfig.get('config_%s_write' % fs_type, None):
         pytest.skip('.config feature "%s_WRITE" not enabled'
         % fs_type.upper())
@@ -179,6 +197,8 @@ def fs_obj_basic(request, u_boot_config):
         volume file name and  a list of MD5 hashes.
     """
     fs_type = request.param
+    fs_cmd_prefix = fstype_to_prefix(fs_type)
+    fs_cmd_write = 'save' if fs_type == 'fs_generic' else 'write'
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
@@ -268,7 +288,7 @@ def fs_obj_basic(request, u_boot_config):
         pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err))
         return
     else:
-        yield [fs_ubtype, fs_img, md5val]
+        yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val]
     finally:
         call('rm -rf %s' % scratch_dir, shell=True)
         call('rm -f %s' % fs_img, shell=True)
@@ -289,6 +309,8 @@ def fs_obj_ext(request, u_boot_config):
         volume file name and  a list of MD5 hashes.
     """
     fs_type = request.param
+    fs_cmd_prefix = fstype_to_prefix(fs_type)
+    fs_cmd_write = 'save' if fs_type == 'fs_generic' else 'write'
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
@@ -358,7 +380,7 @@ def fs_obj_ext(request, u_boot_config):
         pytest.skip('Setup failed for filesystem: ' + fs_type)
         return
     else:
-        yield [fs_ubtype, fs_img, md5val]
+        yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val]
     finally:
         call('rm -rf %s' % scratch_dir, shell=True)
         call('rm -f %s' % fs_img, shell=True)
@@ -379,6 +401,7 @@ def fs_obj_mkdir(request, u_boot_config):
         volume file name.
     """
     fs_type = request.param
+    fs_cmd_prefix = fstype_to_prefix(fs_type)
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
@@ -391,7 +414,7 @@ def fs_obj_mkdir(request, u_boot_config):
         pytest.skip('Setup failed for filesystem: ' + fs_type)
         return
     else:
-        yield [fs_ubtype, fs_img]
+        yield [fs_ubtype, fs_cmd_prefix, fs_img]
     call('rm -f %s' % fs_img, shell=True)
 
 #
@@ -410,6 +433,7 @@ def fs_obj_unlink(request, u_boot_config):
         volume file name.
     """
     fs_type = request.param
+    fs_cmd_prefix = fstype_to_prefix(fs_type)
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
@@ -457,7 +481,7 @@ def fs_obj_unlink(request, u_boot_config):
         pytest.skip('Setup failed for filesystem: ' + fs_type)
         return
     else:
-        yield [fs_ubtype, fs_img]
+        yield [fs_ubtype, fs_cmd_prefix, fs_img]
     finally:
         call('rm -rf %s' % scratch_dir, shell=True)
         call('rm -f %s' % fs_img, shell=True)
test/py/tests/test_fs/test_basic.py +36 -35

248 lines not on this page · raw message

test/py/tests/test_fs/test_ext.py +78 -78

353 lines not on this page · raw message

test/py/tests/test_fs/test_mkdir.py +21 -21

115 lines not on this page · raw message

test/py/tests/test_fs/test_unlink.py +19 -19
index 97aafc63bb5..4795ddbe940 100644
@@ -19,16 +19,16 @@ class TestUnlink(object):
         """
         Test Case 1 - delete a file
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 1 - unlink (file)'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir1/file1' % fs_type,
-                '%sls host 0:0 dir1/file1' % fs_type])
+                '%srm host 0:0 dir1/file1' % fs_cmd_prefix,
+                '%sls host 0:0 dir1/file1' % fs_cmd_prefix])
             assert('' == ''.join(output))
 
             output = u_boot_console.run_command(
-                '%sls host 0:0 dir1/' % fs_type)
+                '%sls host 0:0 dir1/' % fs_cmd_prefix)
             assert(not 'file1' in output)
             assert('file2' in output)
             assert_fs_integrity(fs_type, fs_img)
@@ -37,18 +37,18 @@ class TestUnlink(object):
         """
         Test Case 2 - delete many files
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 2 - unlink (many)'):
             output = u_boot_console.run_command('host bind 0 %s' % fs_img)
 
             for i in range(0, 20):
                 output = u_boot_console.run_command_list([
-                    '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
-                    '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
+                    '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i),
+                    '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i)])
                 assert('' == ''.join(output))
 
             output = u_boot_console.run_command(
-                '%sls host 0:0 dir2' % fs_type)
+                '%sls host 0:0 dir2' % fs_cmd_prefix)
             assert('0 file(s), 2 dir(s)' in output)
             assert_fs_integrity(fs_type, fs_img)
 
@@ -56,11 +56,11 @@ class TestUnlink(object):
         """
         Test Case 3 - trying to delete a non-existing file should fail
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir1/nofile' % fs_type])
+                '%srm host 0:0 dir1/nofile' % fs_cmd_prefix])
             assert('nofile: doesn\'t exist' in ''.join(output))
             assert_fs_integrity(fs_type, fs_img)
 
@@ -68,15 +68,15 @@ class TestUnlink(object):
         """
         Test Case 4 - delete an empty directory
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir4' % fs_type])
+                '%srm host 0:0 dir4' % fs_cmd_prefix])
             assert('' == ''.join(output))
 
             output = u_boot_console.run_command(
-                '%sls host 0:0 /' % fs_type)
+                '%sls host 0:0 /' % fs_cmd_prefix)
             assert(not 'dir4' in output)
             assert_fs_integrity(fs_type, fs_img)
 
@@ -85,11 +85,11 @@ class TestUnlink(object):
         Test Case 5 - trying to deleting a non-empty directory ".."
         should fail
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir5' % fs_type])
+                '%srm host 0:0 dir5' % fs_cmd_prefix])
             assert('directory is not empty' in ''.join(output))
             assert_fs_integrity(fs_type, fs_img)
 
@@ -97,11 +97,11 @@ class TestUnlink(object):
         """
         Test Case 6 - trying to deleting a "." should fail
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 6 - unlink (".")'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir5/.' % fs_type])
+                '%srm host 0:0 dir5/.' % fs_cmd_prefix])
             assert('directory is not empty' in ''.join(output))
             assert_fs_integrity(fs_type, fs_img)
 
@@ -109,10 +109,10 @@ class TestUnlink(object):
         """
         Test Case 7 - trying to deleting a ".." should fail
         """
-        fs_type,fs_img = fs_obj_unlink
+        fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
         with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
             output = u_boot_console.run_command_list([
                 'host bind 0 %s' % fs_img,
-                '%srm host 0:0 dir5/..' % fs_type])
+                '%srm host 0:0 dir5/..' % fs_cmd_prefix])
             assert('directory is not empty' in ''.join(output))
             assert_fs_integrity(fs_type, fs_img)
Signature · 1 line
2.47.2
#4 lore raw

PATCH v2 4/11 linux: Add generic struct stat {}

In reply to Marek Vasut

Add generic implementation of struct stat {} imported from Linux 6.13.y commit 27560b371ab8 ("fs: pack struct kstat better"). This can be used by filesystem code imported from elsewhere. Now struct stat {} becomes available on all supported architectures.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: No change

---
 include/linux/stat.h | 45 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)
include/linux/stat.h +35 -10
index 5eba6334e60..b65bff7e97d 100644
@@ -65,9 +65,7 @@ struct stat {
 	unsigned long	__unused5;
 };
 
-#endif	/* __PPC__ */
-
-#if defined (__ARM__) || defined (__I386__) || defined (__M68K__) || defined (__bfin__) ||\
+#elif defined (__ARM__) || defined (__I386__) || defined (__M68K__) || defined (__bfin__) ||\
 	defined (__microblaze__) || defined (__nios2__)
 
 struct stat {
@@ -93,9 +91,7 @@ struct stat {
 	unsigned long  __unused5;
 };
 
-#endif	/* __ARM__ */
-
-#if defined (__MIPS__)
+#elif defined (__MIPS__)
 
 struct stat {
 	dev_t		st_dev;
@@ -124,9 +120,7 @@ struct stat {
 	long		st_pad4[14];
 };
 
-#endif	/* __MIPS__ */
-
-#if defined(__SH__) || defined(__XTENSA__)
+#elif defined(__SH__) || defined(__XTENSA__)
 
 struct stat {
 	unsigned long st_dev;
@@ -149,7 +143,38 @@ struct stat {
 	unsigned long  __unused5;
 };
 
-#endif /* __SH__  || __XTENSA__ */
+#else
+
+/*
+ * Everybody gets this wrong and has to stick with it for all
+ * eternity. Hopefully, this version gets used by new architectures
+ * so they don't fall into the same traps.
+ *
+ */
+struct stat {
+	unsigned long	st_dev;		/* Device.  */
+	unsigned long	st_ino;		/* File serial number.  */
+	unsigned int	st_mode;	/* File mode.  */
+	unsigned int	st_nlink;	/* Link count.  */
+	unsigned int	st_uid;		/* User ID of the file's owner.  */
+	unsigned int	st_gid;		/* Group ID of the file's group. */
+	unsigned long	st_rdev;	/* Device number, if device.  */
+	unsigned long	__pad1;
+	long		st_size;	/* Size of file, in bytes.  */
+	int		st_blksize;	/* Optimal block size for I/O.  */
+	int		__pad2;
+	long		st_blocks;	/* Number 512-byte blocks allocated. */
+	long		st_atime;	/* Time of last access.  */
+	unsigned long	st_atime_nsec;
+	long		st_mtime;	/* Time of last modification.  */
+	unsigned long	st_mtime_nsec;
+	long		st_ctime;	/* Time of last status change.  */
+	unsigned long	st_ctime_nsec;
+	unsigned int	__unused4;
+	unsigned int	__unused5;
+};
+
+#endif
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.47.2
#5 lore raw

PATCH v2 5/11 fs: Add generic fs_devread() implementation

In reply to Marek Vasut

Add generic implementation of write into a block device to be used by filesystem implementations. This is a pair function for already existing fs_devread().

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: No change

---
 fs/fs_internal.c      | 102 ++++++++++++++++++++++++++++++++++++++++++
 include/fs_internal.h |   2 +
 2 files changed, 104 insertions(+)
fs/fs_internal.c +102 -0
index 51c1719361b..ab4847ac257 100644
@@ -92,3 +92,105 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition,
 	}
 	return 1;
 }
+
+int fs_devwrite(struct blk_desc *blk, struct disk_partition *partition,
+	        lbaint_t sector, int byte_offset, int byte_len, const char *buf)
+{
+	unsigned block_len;
+	int log2blksz;
+	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (blk ? blk->blksz : 0));
+	if (blk == NULL) {
+		log_err("** Invalid Block Device Descriptor (NULL)\n");
+		return 0;
+	}
+	log2blksz = blk->log2blksz;
+
+	/* Check partition boundaries */
+	if ((sector + ((byte_offset + byte_len - 1) >> log2blksz))
+	    >= partition->size) {
+		log_debug("read outside partition " LBAFU "\n", sector);
+		return 0;
+	}
+
+	/* Get the read to the beginning of a partition */
+	sector += byte_offset >> log2blksz;
+	byte_offset &= blk->blksz - 1;
+
+	log_debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len);
+
+	if (byte_offset != 0) {
+		int readlen;
+		/* read first part which isn't aligned with start of sector */
+		if (blk_dread(blk, partition->start + sector, 1,
+			      (void *)sec_buf) != 1) {
+			log_err(" ** %s read error **\n", __func__);
+			return 0;
+		}
+
+		readlen = min((int)blk->blksz - byte_offset,
+			      byte_len);
+		memcpy(sec_buf + byte_offset, buf, readlen);
+
+		if (blk_dwrite(blk, partition->start + sector, 1,
+			      (void *)sec_buf) != 1) {
+			log_err(" ** %s write error **\n", __func__);
+			return 0;
+		}
+		buf += readlen;
+		byte_len -= readlen;
+		sector++;
+	}
+
+	if (byte_len == 0)
+		return 1;
+
+	/* write sector aligned part */
+	block_len = byte_len & ~(blk->blksz - 1);
+
+	if (block_len == 0) {
+		if (blk_dread(blk, partition->start + sector, 1,
+			  (void *)sec_buf) != 1) {
+			log_err(" ** %s read error **\n", __func__);
+			return 0;
+		}
+
+		memcpy(sec_buf, buf, byte_len);
+
+		if (blk_dwrite(blk, partition->start + sector, 1,
+			      (void *)sec_buf) != 1) {
+			log_err(" ** %s write error **\n", __func__);
+			return 0;
+		}
+
+		return 1;
+	}
+
+	if (blk_dwrite(blk, partition->start + sector,
+		       block_len >> log2blksz, (void *)buf) !=
+			block_len >> log2blksz) {
+		log_err(" ** %s write error - block\n", __func__);
+		return 0;
+	}
+	block_len = byte_len & ~(blk->blksz - 1);
+	buf += block_len;
+	byte_len -= block_len;
+	sector += block_len / blk->blksz;
+
+	if (byte_len != 0) {
+		/* read rest of data which are not in whole sector */
+		if (blk_dread(blk, partition->start + sector, 1,
+			      (void *)sec_buf) != 1) {
+			log_err("* %s read error - last part **\n", __func__);
+			return 0;
+		}
+
+		memcpy(sec_buf, buf, byte_len);
+
+		if (blk_dwrite(blk, partition->start + sector, 1,
+			      (void *)sec_buf) != 1) {
+			log_err(" ** %s write error - last part **\n", __func__);
+			return 0;
+		}
+	}
+	return 1;
+}
include/fs_internal.h +2 -0
index 07f6bc5ea40..351582db61a 100644
@@ -12,5 +12,7 @@
 
 int fs_devread(struct blk_desc *, struct disk_partition *, lbaint_t, int, int,
 	       char *);
+int fs_devwrite(struct blk_desc *, struct disk_partition *, lbaint_t, int, int,
+	        const char *);
 
 #endif /* __U_BOOT_FS_INTERNAL_H__ */
Signature · 1 line
2.47.2
#6 lore raw

PATCH v2 6/11 fs: exfat: Import libexfat from fuse-exfat

In reply to Marek Vasut

Import most of libexfat from [1] except for log.c verbatim. The code does not even compile and further adjustments and integration into U-Boot filesystem code is in the next patch.

[1] https://github.com/relan/exfat

    0b41c6d3560d ("CI: bump FreeBSD to 13.1.")

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Add AB from Tom

---
 fs/exfat/byteorder.h |   68 +++
 fs/exfat/cluster.c   |  496 +++++++++++++++++
 fs/exfat/compiler.h  |   69 +++
 fs/exfat/exfat.h     |  248 +++++++++
 fs/exfat/exfatfs.h   |  181 ++++++
 fs/exfat/io.c        |  514 +++++++++++++++++
 fs/exfat/lookup.c    |  222 ++++++++
 fs/exfat/mount.c     |  373 +++++++++++++
 fs/exfat/node.c      | 1243 ++++++++++++++++++++++++++++++++++++++++++
 fs/exfat/platform.h  |   73 +++
 fs/exfat/repair.c    |  102 ++++
 fs/exfat/time.c      |  173 ++++++
 fs/exfat/utf.c       |  254 +++++++++
 fs/exfat/utils.c     |  192 +++++++
 14 files changed, 4208 insertions(+)
 create mode 100644 fs/exfat/byteorder.h
 create mode 100644 fs/exfat/cluster.c
 create mode 100644 fs/exfat/compiler.h
 create mode 100644 fs/exfat/exfat.h
 create mode 100644 fs/exfat/exfatfs.h
 create mode 100644 fs/exfat/io.c
 create mode 100644 fs/exfat/lookup.c
 create mode 100644 fs/exfat/mount.c
 create mode 100644 fs/exfat/node.c
 create mode 100644 fs/exfat/platform.h
 create mode 100644 fs/exfat/repair.c
 create mode 100644 fs/exfat/time.c
 create mode 100644 fs/exfat/utf.c
 create mode 100644 fs/exfat/utils.c
fs/exfat/byteorder.h new file +68 -0
new file mode 100644
index 00000000000..98b93c700c3
@@ -0,0 +1,68 @@
+/*
+	byteorder.h (12.01.10)
+	Endianness stuff. exFAT uses little-endian byte order.
+
+	Free exFAT implementation.
+	Copyright (C) 2010-2023  Andrew Nayenko
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License along
+	with this program; if not, write to the Free Software Foundation, Inc.,
+	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef BYTEORDER_H_INCLUDED
+#define BYTEORDER_H_INCLUDED
+
+#include "platform.h"
+#include <stdint.h>
+#include <stddef.h>
+
+typedef struct { uint16_t __u16; } le16_t;
+typedef struct { uint32_t __u32; } le32_t;
+typedef struct { uint64_t __u64; } le64_t;
+
+#if EXFAT_BYTE_ORDER == EXFAT_LITTLE_ENDIAN
+
+static inline uint16_t le16_to_cpu(le16_t v) { return v.__u16; }
+static inline uint32_t le32_to_cpu(le32_t v) { return v.__u32; }
+static inline uint64_t le64_to_cpu(le64_t v) { return v.__u64; }
+
+static inline le16_t cpu_to_le16(uint16_t v) { le16_t t = {v}; return t; }
+static inline le32_t cpu_to_le32(uint32_t v) { le32_t t = {v}; return t; }
+static inline le64_t cpu_to_le64(uint64_t v) { le64_t t = {v}; return t; }
+
+typedef size_t bitmap_t;
+
+#elif EXFAT_BYTE_ORDER == EXFAT_BIG_ENDIAN
+
+static inline uint16_t le16_to_cpu(le16_t v)
+	{ return exfat_bswap16(v.__u16); }
+static inline uint32_t le32_to_cpu(le32_t v)
+	{ return exfat_bswap32(v.__u32); }
+static inline uint64_t le64_to_cpu(le64_t v)
+	{ return exfat_bswap64(v.__u64); }
+
+static inline le16_t cpu_to_le16(uint16_t v)
+	{ le16_t t = {exfat_bswap16(v)}; return t; }
+static inline le32_t cpu_to_le32(uint32_t v)
+	{ le32_t t = {exfat_bswap32(v)}; return t; }
+static inline le64_t cpu_to_le64(uint64_t v)
+	{ le64_t t = {exfat_bswap64(v)}; return t; }
+
+typedef unsigned char bitmap_t;
+
+#else
+#error Wow! You have a PDP machine?!
+#endif
+
+#endif /* ifndef BYTEORDER_H_INCLUDED */
fs/exfat/cluster.c new file +496 -0

496 lines not on this page · raw message

fs/exfat/compiler.h new file +69 -0

69 lines not on this page · raw message

fs/exfat/exfat.h new file +248 -0

248 lines not on this page · raw message

fs/exfat/exfatfs.h new file +181 -0

181 lines not on this page · raw message

fs/exfat/io.c new file +514 -0

514 lines not on this page · raw message

fs/exfat/lookup.c new file +222 -0

222 lines not on this page · raw message

fs/exfat/mount.c new file +373 -0

373 lines not on this page · raw message

fs/exfat/node.c new file +1243 -0

829 lines not on this page · raw message

fs/exfat/platform.h new file +73 -0

73 lines not on this page · raw message

fs/exfat/repair.c new file +102 -0

102 lines not on this page · raw message

fs/exfat/time.c new file +173 -0

173 lines not on this page · raw message

fs/exfat/utf.c new file +254 -0

254 lines not on this page · raw message

fs/exfat/utils.c new file +192 -0

192 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.47.2

Part of the diff is not shown here. View the raw message.

#7 lore raw

PATCH v2 7/11 fs: exfat: Add U-Boot porting layer

In reply to Marek Vasut

Add U-Boot adjustments to the libexfat code and integrate the result into U-Boot filesystem layer. This provides full read-write exfat support for U-Boot available via generic filesystem interface.

FS_DIRENT_NAME_LEN is increased to 1024 in case exfat is enabled, because EXFAT can use UTF16 names, which do not fit into current FS_DIRENT_NAME_LEN. To avoid affecting every configuration, increase FS_DIRENT_NAME_LEN only in case EXFAT is enabled.

Example usage via sandbox, assuming disk.img with one exfat partition:

Drive info:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; host info 0'
dev       blocks  blksz label           path
  0       262144    512 0               ../disk.img

List files:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; ls host 0:1 /api'
      475   Kconfig
      230   Makefile
     1873   README
     ...
10 file(s), 0 dir(s)

Load and checksum a file:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; load host 0:1 $loadaddr .config ; \
                crc32 $loadaddr $filesize'
56724 bytes read in 1 ms (54.1 MiB/s)
crc32 for 00000000 ... 0000dd93 ==> b2e847c9
$ crc32 .config
b2e847c9

Load .config file to RAM, store the file into FS as /newconfig, load the /newconfig into RAM and checksum the file:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; load host 0:1 $loadaddr .config ; \
		save host 0:1 $loadaddr /newconfig $filesize ; \
		load host 0:1 0x10000 /newconfig ; \
		crc32 0x10000 $filesize'
56724 bytes read in 1 ms (54.1 MiB/s)
56724 bytes written in 0 ms
56724 bytes read in 0 ms
crc32 for 00010000 ... 0001dd93 ==> b2e847c9

Remove file 3.txt and create new directory /newdir:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; ls host 0:1 / ; \
                rm host 0:1 3.txt ; mkdir host 0:1 /newdir ; \
		ls host 0:1 /'
...
        0   1.txt
        0   2.txt
        0   3.txt
        0   4.txt
        0   5.txt

7 file(s), 4 dir(s)
...

        0   1.txt
        0   2.txt
            newdir/
        0   4.txt
        0   5.txt

6 file(s), 5 dir(s)

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: - Update Kconfig, imply CMD_FS_GENERIC if CMDLINE
- Update Makefile to use obj .. +=

---
 fs/Kconfig          |   2 +
 fs/Makefile         |   1 +
 fs/exfat/Kconfig    |   5 +
 fs/exfat/Makefile   |  13 ++
 fs/exfat/exfat.h    |  11 +
 fs/exfat/exfatfs.h  |  19 ++
 fs/exfat/io.c       | 486 ++++++++++++++++++++++++++++++++++++++++++++
 fs/exfat/lookup.c   |   3 +
 fs/exfat/mount.c    |   2 +
 fs/exfat/platform.h |   2 +
 fs/exfat/repair.c   |  13 ++
 fs/exfat/time.c     |   2 +
 fs/fs.c             |  22 ++
 include/exfat.h     |  24 +++
 include/fs.h        |   3 +-
 15 files changed, 607 insertions(+), 1 deletion(-)
 create mode 100644 fs/exfat/Kconfig
 create mode 100644 fs/exfat/Makefile
 create mode 100644 include/exfat.h
fs/Kconfig +2 -0
index 5e83cb27059..e0b0b901e1d 100644
@@ -8,6 +8,8 @@ source "fs/btrfs/Kconfig"
 
 source "fs/cbfs/Kconfig"
 
+source "fs/exfat/Kconfig"
+
 source "fs/ext4/Kconfig"
 
 source "fs/fat/Kconfig"
fs/Makefile +1 -0
index 1c2ff180bda..ce5e74257a0 100644
@@ -16,6 +16,7 @@ obj-y				+= fs.o
 obj-$(CONFIG_FS_BTRFS) += btrfs/
 obj-$(CONFIG_FS_CBFS) += cbfs/
 obj-$(CONFIG_CMD_CRAMFS) += cramfs/
+obj-$(CONFIG_FS_EXFAT) += exfat/
 obj-$(CONFIG_FS_EXT4) += ext4/
 obj-$(CONFIG_FS_FAT) += fat/
 obj-$(CONFIG_FS_JFFS2) += jffs2/
fs/exfat/Kconfig new file +5 -0
new file mode 100644
index 00000000000..bce61e8fcc7
@@ -0,0 +1,5 @@
+config FS_EXFAT
+	bool "Enable EXFAT filesystem support"
+	imply CMD_FS_GENERIC if CMDLINE
+	help
+	  This provides read/write support for EXFAT filesystem.
fs/exfat/Makefile new file +13 -0
new file mode 100644
index 00000000000..550c0683d65
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+obj-$(CONFIG_FS_EXFAT) += \
+	cluster.o \
+	io.o \
+	lookup.o \
+	mount.o \
+	node.o \
+	repair.o \
+	time.o \
+	utf.o \
+	utils.o
fs/exfat/exfat.h +11 -0
index 0e146e8f4d9..cce3e3021ca 100644
@@ -34,8 +34,10 @@
 #include <stdlib.h>
 #include <time.h>
 #include <stdbool.h>
+#ifndef __UBOOT__
 #include <sys/stat.h>
 #include <sys/types.h>
+#endif
 
 #define EXFAT_NAME_MAX 255
 /* UTF-16 encodes code points up to U+FFFF as single 16-bit code units.
@@ -51,7 +53,9 @@
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
+#ifndef __UBOOT__
 #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d))
+#endif
 #define ROUND_UP(x, d) (DIV_ROUND_UP(x, d) * (d))
 
 #define BMAP_SIZE(count) (ROUND_UP(count, sizeof(bitmap_t) * 8) / 8)
@@ -145,10 +149,17 @@ struct exfat_human_bytes
 extern int exfat_errors;
 extern int exfat_errors_fixed;
 
+#ifdef __UBOOT__
+#define exfat_bug(fmt, args...)		log_crit(fmt, ##args)
+#define exfat_error(fmt, args...)	log_err(fmt, ##args)
+#define exfat_warn(fmt, args...)	log_warning(fmt, ##args)
+#define exfat_debug(fmt, args...)	log_debug(fmt, ##args)
+#else
 void exfat_bug(const char* format, ...) PRINTF NORETURN;
 void exfat_error(const char* format, ...) PRINTF;
 void exfat_warn(const char* format, ...) PRINTF;
 void exfat_debug(const char* format, ...) PRINTF;
+#endif
 
 struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode);
 int exfat_close(struct exfat_dev* dev);
fs/exfat/exfatfs.h +19 -0
index 3618d4d3024..fa59aab47b6 100644
@@ -23,6 +23,25 @@
 #ifndef EXFATFS_H_INCLUDED
 #define EXFATFS_H_INCLUDED
 
+#ifdef __UBOOT__
+#include <linux/stat.h>
+#include <linux/types.h>
+#include <log.h>
+#include <stdint.h>
+#include <vsprintf.h>
+
+struct timespec {
+	time_t	tv_sec;		/* seconds */
+	long	tv_nsec;	/* nanoseconds */
+};
+
+#define time(t)		1741234567	/* Thu Mar  6 05:16:07 CET 2025 */
+#define geteuid(n)	1000
+#define getegid(n)	1000
+#define strtol(n, e, b)	simple_strtol(n, e, b)
+#define off_t		unsigned long long
+#endif
+
 #include "byteorder.h"
 #include "compiler.h"
 
fs/exfat/io.c +486 -0

515 lines not on this page · raw message

fs/exfat/lookup.c +3 -0
index bb7b1243632..9867aab95f3 100644
@@ -219,4 +219,7 @@ int exfat_split(struct exfat* ef, struct exfat_node** parent,
 		*parent = *node;
 	}
 	exfat_bug("impossible");
+#ifdef __UBOOT__
+	return 0;
+#endif
 }
fs/exfat/mount.c +2 -0
index 86fb84db244..c17a84735fc 100644
@@ -25,8 +25,10 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <inttypes.h>
+#ifndef __UBOOT__
 #include <unistd.h>
 #include <sys/types.h>
+#endif
 
 static uint64_t rootdir_size(const struct exfat* ef)
 {
fs/exfat/platform.h +2 -0
index 9bd125a100a..668857607bf 100644
@@ -26,8 +26,10 @@
 
 #if defined(__linux__) || defined(__GLIBC__) || defined(__GNU__)
 
+#ifndef __UBOOT__
 #include <endian.h>
 #include <byteswap.h>
+#endif
 #define exfat_bswap16(x) bswap_16(x)
 #define exfat_bswap32(x) bswap_32(x)
 #define exfat_bswap64(x) bswap_64(x)
fs/exfat/repair.c +13 -0
index 615b8d11f3c..9c91239b899 100644
@@ -21,15 +21,19 @@
 */
 
 #include "exfat.h"
+#ifndef __UBOOT__
 #include <strings.h>
+#endif
 
 int exfat_errors_fixed;
 
 bool exfat_ask_to_fix(const struct exfat* ef)
 {
 	const char* question = "Fix (Y/N)?";
+#ifndef __UBOOT__
 	char answer[8];
 	bool yeah, nope;
+#endif
 
 	switch (ef->repair)
 	{
@@ -39,6 +43,7 @@ bool exfat_ask_to_fix(const struct exfat* ef)
 		printf("%s %s", question, "Y\n");
 		return true;
 	case EXFAT_REPAIR_ASK:
+#ifndef __UBOOT__
 		do
 		{
 			printf("%s ", question);
@@ -56,8 +61,16 @@ bool exfat_ask_to_fix(const struct exfat* ef)
 		}
 		while (!yeah && !nope);
 		return yeah;
+#else
+	default:
+		/* Do not attempt to repair FS in U-Boot. */
+		return false;
+#endif
 	}
 	exfat_bug("invalid repair option value: %d", ef->repair);
+#ifdef __UBOOT__
+	return false;
+#endif
 }
 
 bool exfat_fix_invalid_vbr_checksum(const struct exfat* ef, void* sector,
fs/exfat/time.c +2 -0
index 3ab2a1561b8..f2217dd7986 100644
@@ -159,6 +159,7 @@ void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time,
 
 void exfat_tzset(void)
 {
+#ifndef __UBOOT__
 	time_t now;
 	struct tm* utc;
 
@@ -170,4 +171,5 @@ void exfat_tzset(void)
 	   summer time is in effect. */
 	utc->tm_isdst = -1;
 	exfat_timezone = mktime(utc) - now;
+#endif
 }
fs/fs.c +22 -0
index 30a8e5010f2..01d69483e84 100644
@@ -32,6 +32,7 @@
 #include <efi_loader.h>
 #include <squashfs.h>
 #include <erofs.h>
+#include <exfat.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -380,6 +381,27 @@ static struct fstype_info fstypes[] = {
 		.mkdir = fs_mkdir_unsupported,
 		.rename = fs_rename_unsupported,
 	},
+#endif
+#if IS_ENABLED(CONFIG_FS_EXFAT)
+	{
+		.fstype = FS_TYPE_EXFAT,
+		.name = "exfat",
+		.null_dev_desc_ok = false,
+		.probe = exfat_fs_probe,
+		.opendir = exfat_fs_opendir,
+		.readdir = exfat_fs_readdir,
+		.ls = exfat_fs_ls,
+		.read = exfat_fs_read,
+		.size = exfat_fs_size,
+		.close = exfat_fs_close,
+		.closedir = exfat_fs_closedir,
+		.exists = exfat_fs_exists,
+		.uuid = fs_uuid_unsupported,
+		.write = exfat_fs_write,
+		.ln = fs_ln_unsupported,
+		.unlink = exfat_fs_unlink,
+		.mkdir = exfat_fs_mkdir,
+	},
 #endif
 	{
 		.fstype = FS_TYPE_ANY,
include/exfat.h new file +24 -0
new file mode 100644
index 00000000000..7e43beeb348
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _EXFAT_H_
+#define _EXFAT_H_
+
+struct disk_partition;
+
+int exfat_fs_opendir(const char *filename, struct fs_dir_stream **dirsp);
+int exfat_fs_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
+int exfat_fs_ls(const char *dirname);
+int exfat_fs_probe(struct blk_desc *fs_dev_desc,
+		struct disk_partition *fs_partition);
+int exfat_fs_read(const char *filename, void *buf, loff_t offset,
+	       loff_t len, loff_t *actread);
+int exfat_fs_size(const char *filename, loff_t *size);
+int exfat_fs_exists(const char *filename);
+void exfat_fs_close(void);
+void exfat_fs_closedir(struct fs_dir_stream *dirs);
+
+int exfat_fs_unlink(const char *filename);
+int exfat_fs_mkdir(const char *dirname);
+int exfat_fs_write(const char *filename, void *buf, loff_t offset,
+		   loff_t len, loff_t *actwrite);
+
+#endif /* _EXFAT_H */
include/fs.h +2 -1
index 54449faf2e5..731aaa02637 100644
@@ -18,6 +18,7 @@ struct cmd_tbl;
 #define FS_TYPE_SQUASHFS 6
 #define FS_TYPE_EROFS   7
 #define FS_TYPE_SEMIHOSTING 8
+#define FS_TYPE_EXFAT   9
 
 struct blk_desc;
 
@@ -173,7 +174,7 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
 #define FS_DT_REG  8         /* regular file */
 #define FS_DT_LNK  10        /* symbolic link */
 
-#define FS_DIRENT_NAME_LEN 256
+#define FS_DIRENT_NAME_LEN	CONFIG_IS_ENABLED(FS_EXFAT, (1024), (256))
 
 /**
  * struct fs_dirent - directory entry
Signature · 1 line
2.47.2
Acked-by on v2 7/11
#8 lore raw

Re: [PATCH v2 07/11] fs: exfat: Add U-Boot porting layer

Quoted 65 lines · Marek Vasut

Add U-Boot adjustments to the libexfat code and integrate the result into U-Boot filesystem layer. This provides full read-write exfat support for U-Boot available via generic filesystem interface.

FS_DIRENT_NAME_LEN is increased to 1024 in case exfat is enabled, because EXFAT can use UTF16 names, which do not fit into current FS_DIRENT_NAME_LEN. To avoid affecting every configuration, increase FS_DIRENT_NAME_LEN only in case EXFAT is enabled.

Example usage via sandbox, assuming disk.img with one exfat partition:

Drive info:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; host info 0'
dev       blocks  blksz label           path
  0       262144    512 0               ../disk.img

List files:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; ls host 0:1 /api'
      475   Kconfig
      230   Makefile
     1873   README
     ...
10 file(s), 0 dir(s)

Load and checksum a file:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; load host 0:1 $loadaddr .config ; \
                crc32 $loadaddr $filesize'
56724 bytes read in 1 ms (54.1 MiB/s)
crc32 for 00000000 ... 0000dd93 ==> b2e847c9
$ crc32 .config
b2e847c9

Load .config file to RAM, store the file into FS as /newconfig, load the /newconfig into RAM and checksum the file:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; load host 0:1 $loadaddr .config ; \
		save host 0:1 $loadaddr /newconfig $filesize ; \
		load host 0:1 0x10000 /newconfig ; \
		crc32 0x10000 $filesize'
56724 bytes read in 1 ms (54.1 MiB/s)
56724 bytes written in 0 ms
56724 bytes read in 0 ms
crc32 for 00010000 ... 0001dd93 ==> b2e847c9

Remove file 3.txt and create new directory /newdir:

$ ./u-boot -Tc 'host bind 0 ../disk.img ; ls host 0:1 / ; \
                rm host 0:1 3.txt ; mkdir host 0:1 /newdir ; \
		ls host 0:1 /'
...
        0   1.txt
        0   2.txt
        0   3.txt
        0   4.txt
        0   5.txt

7 file(s), 4 dir(s)
...

        0   1.txt
        0   2.txt
            newdir/
        0   4.txt
        0   5.txt
Quoted 3 lines

6 file(s), 5 dir(s)

Signature · 1 line
Tom
#9 lore raw

PATCH v2 8/11 fs: exfat: Fix conversion overflow errors

In reply to Marek Vasut

Fix the following conversion overflow errors. The UTF8-to-UTF16 conversion is done through 32bit wchar_t, but U-Boot codebase is built with -fshort-wchar which limits wchar_t to 16bit. Replace the built-in wchar_t with u32 to assure the intermediate type is 32bit.

"
fs/exfat/utf.c: In function ‘utf8_to_wchar’:
fs/exfat/utf.c:165:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 18 & 1835008’ to ‘0’ [-Woverflow]
165 | *wc = ((wchar_t) input[0] & 0x07) << 18;
| ^
fs/exfat/utf.c:170:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 24 & 50331648’ to ‘0’ [-Woverflow]
170 | *wc = ((wchar_t) input[0] & 0x03) << 24;
| ^
fs/exfat/utf.c:175:23: warning: overflow in conversion from ‘int’ to ‘wchar_t’ {aka ‘short unsigned int’} changes value from ‘(int)(short unsigned int)*input << 30 & 1073741824’ to ‘0’ [-Woverflow]
175 | *wc = ((wchar_t) input[0] & 0x01) << 30;
| ^
"

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Rework the patch, replace wchar_t with u32

---
 fs/exfat/utf.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
fs/exfat/utf.c +13 -13
index b1d09e76478..8a28e7621ca 100644
@@ -23,7 +23,7 @@
 #include "exfat.h"
 #include <errno.h>
 
-static char* wchar_to_utf8(char* output, wchar_t wc, size_t outsize)
+static char* wchar_to_utf8(char* output, u32 wc, size_t outsize)
 {
 	if (wc <= 0x7f)
 	{
@@ -82,14 +82,14 @@ static char* wchar_to_utf8(char* output, wchar_t wc, size_t outsize)
 	return output;
 }
 
-static const le16_t* utf16_to_wchar(const le16_t* input, wchar_t* wc,
+static const le16_t* utf16_to_wchar(const le16_t* input, u32* wc,
 		size_t insize)
 {
 	if ((le16_to_cpu(input[0]) & 0xfc00) == 0xd800)
 	{
 		if (insize < 2 || (le16_to_cpu(input[1]) & 0xfc00) != 0xdc00)
 			return NULL;
-		*wc = ((wchar_t) (le16_to_cpu(input[0]) & 0x3ff) << 10);
+		*wc = ((u32) (le16_to_cpu(input[0]) & 0x3ff) << 10);
 		*wc |= (le16_to_cpu(input[1]) & 0x3ff);
 		*wc += 0x10000;
 		return input + 2;
@@ -108,7 +108,7 @@ int exfat_utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
 	const le16_t* iend = input + insize;
 	char* optr = output;
 	const char* oend = output + outsize;
-	wchar_t wc;
+	u32 wc;
 
 	while (iptr < iend)
 	{
@@ -136,7 +136,7 @@ int exfat_utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
 	return 0;
 }
 
-static const char* utf8_to_wchar(const char* input, wchar_t* wc,
+static const char* utf8_to_wchar(const char* input, u32* wc,
 		size_t insize)
 {
 	size_t size;
@@ -147,32 +147,32 @@ static const char* utf8_to_wchar(const char* input, wchar_t* wc,
 
 	if ((input[0] & 0x80) == 0)
 	{
-		*wc = (wchar_t) input[0];
+		*wc = (u32) input[0];
 		return input + 1;
 	}
 	else if ((input[0] & 0xe0) == 0xc0)
 	{
-		*wc = ((wchar_t) input[0] & 0x1f) << 6;
+		*wc = ((u32) input[0] & 0x1f) << 6;
 		size = 2;
 	}
 	else if ((input[0] & 0xf0) == 0xe0)
 	{
-		*wc = ((wchar_t) input[0] & 0x0f) << 12;
+		*wc = ((u32) input[0] & 0x0f) << 12;
 		size = 3;
 	}
 	else if ((input[0] & 0xf8) == 0xf0)
 	{
-		*wc = ((wchar_t) input[0] & 0x07) << 18;
+		*wc = ((u32) input[0] & 0x07) << 18;
 		size = 4;
 	}
 	else if ((input[0] & 0xfc) == 0xf8)
 	{
-		*wc = ((wchar_t) input[0] & 0x03) << 24;
+		*wc = ((u32) input[0] & 0x03) << 24;
 		size = 5;
 	}
 	else if ((input[0] & 0xfe) == 0xfc)
 	{
-		*wc = ((wchar_t) input[0] & 0x01) << 30;
+		*wc = ((u32) input[0] & 0x01) << 30;
 		size = 6;
 	}
 	else
@@ -192,7 +192,7 @@ static const char* utf8_to_wchar(const char* input, wchar_t* wc,
 	return input + size;
 }
 
-static le16_t* wchar_to_utf16(le16_t* output, wchar_t wc, size_t outsize)
+static le16_t* wchar_to_utf16(le16_t* output, u32 wc, size_t outsize)
 {
 	if (wc <= 0xffff) /* if character is from BMP */
 	{
@@ -216,7 +216,7 @@ int exfat_utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
 	const char* iend = input + insize;
 	le16_t* optr = output;
 	const le16_t* oend = output + outsize;
-	wchar_t wc;
+	u32 wc;
 
 	while (iptr < iend)
 	{
Signature · 1 line
2.47.2
#10 lore raw

PATCH v2 9/11 fs: exfat: Demote filesystem detection failure message to debug()

In reply to Marek Vasut

Demote "exFAT file system is not found" message to debug(). This is printed when U-Boot attempts to auto-detect the filesystem via generic filesystem API by attempting to mount the device, and fails to do so because there is another filesystem in place. The libexfat-fuse code prints this an error, which interferes with 'test_gpt' test. Demote the message to debug().

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Add RB from Tom

---
 fs/exfat/mount.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/exfat/mount.c +6 -1
index c17a84735fc..0ff297af67b 100644
@@ -226,7 +226,12 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
 	}
 	if (memcmp(ef->sb->oem_name, "EXFAT   ", 8) != 0)
 	{
-		exfat_error("exFAT file system is not found");
+#ifndef __UBOOT__
+		exfat_error(
+#else
+		exfat_debug(
+#endif
+		"exFAT file system is not found");
 		exfat_free(ef);
 		return -EIO;
 	}
Signature · 1 line
2.47.2
#11 lore raw

PATCH v2 10/11 configs: sandbox: Enable exfat support

In reply to Marek Vasut

Enable exfat support in sandbox and sandbox64 to assure build and test coverage of this filesystem on both 32bit and 64bit builds.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: No change

---
 configs/sandbox64_defconfig | 1 +
 configs/sandbox_defconfig   | 1 +
 2 files changed, 2 insertions(+)
configs/sandbox64_defconfig +1 -0
index 7960b2ef42e..1236ce474a6 100644
@@ -267,6 +267,7 @@ CONFIG_WDT_SANDBOX=y
 CONFIG_WDT_ALARM_SANDBOX=y
 CONFIG_FS_CBFS=y
 CONFIG_FS_CRAMFS=y
+CONFIG_FS_EXFAT=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_ERRNO_STR=y
configs/sandbox_defconfig +1 -0
index 0b3c765389c..87f21fdbd12 100644
@@ -352,6 +352,7 @@ CONFIG_WDT_ALARM_SANDBOX=y
 CONFIG_WDT_FTWDT010=y
 CONFIG_FS_CBFS=y
 CONFIG_FS_CRAMFS=y
+CONFIG_FS_EXFAT=y
 CONFIG_ADDR_MAP=y
 CONFIG_PANIC_HANG=y
 CONFIG_CMD_DHRYSTONE=y
Signature · 1 line
2.47.2
#12 lore raw

PATCH v2 11/11 test_fs: Add exfat tests

In reply to Marek Vasut

Add tests for the exfat filesystem. These tests are largely an extension of the FS_GENERIC tests with the following notable exceptions.

The filesystem image for exfat tests is generated using combination of exfatprogs mkfs.exfat and python fattools. The fattols are capable of generating exfat filesystem images too, but this is not used, the fattools are only used as a replacement for dosfstools 'mcopy' and 'mdir', which are used to insert files and directories into existing fatfs images and list existing fatfs images respectively, without the need for superuser access to mount such images.

The exfat filesystem has no filesystem specific command, there is only the generic filesystem command interface, therefore check_ubconfig() has to special case exfat and skip check for CONFIG_CMD_EXFAT and instead check for CONFIG_FS_EXFAT.

---
Cc: Baruch Siach <[email protected]>
Cc: Francesco Dolcini <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Hiago De Franco <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: - s@exfatutils@exfatprogs@
- Fill in fsck.exfat into fstest_helpers.py
- Fill in exfatprogs into CI docker container template

---
 test/py/requirements.txt                |  1 +
 test/py/tests/fs_helper.py              |  8 ++++++--
 test/py/tests/test_fs/conftest.py       | 20 +++++++++++---------
 test/py/tests/test_fs/fstest_helpers.py |  2 ++
 test/py/tests/test_fs/test_ext.py       | 20 ++++++++++++++------
 tools/docker/Dockerfile                 |  1 +
 6 files changed, 35 insertions(+), 17 deletions(-)
test/py/requirements.txt +1 -0
index acfe17dce9f..804a427b351 100644
@@ -2,3 +2,4 @@ filelock==3.0.12
 pycryptodomex==3.21.0
 pytest==6.2.5
 pytest-xdist==2.5.0
+FATtools==1.0.42
test/py/tests/fs_helper.py +6 -2
index 378d5ae0690..94a5b94f479 100644
@@ -35,7 +35,9 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
     else:
         mkfs_opt = ''
 
-    if re.match('fat', fs_type) or fs_type == 'fs_generic':
+    if fs_type == 'exfat':
+        fs_lnxtype = 'exfat'
+    elif re.match('fat', fs_type) or fs_type == 'fs_generic':
         fs_lnxtype = 'vfat'
     else:
         fs_lnxtype = fs_type
@@ -43,7 +45,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
     if src_dir:
         if fs_lnxtype == 'ext4':
             mkfs_opt = mkfs_opt + ' -d ' + src_dir
-        elif fs_lnxtype != 'vfat':
+        elif fs_lnxtype != 'vfat' and fs_lnxtype != 'exfat':
             raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}')
 
     count = (size + size_gran - 1) // size_gran
@@ -64,6 +66,8 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
                 check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
         elif fs_lnxtype == 'vfat' and src_dir:
             check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
+        elif fs_lnxtype == 'exfat' and src_dir:
+            check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True)
         return fs_img
     except CalledProcessError:
         call(f'rm -f {fs_img}', shell=True)
test/py/tests/test_fs/conftest.py +11 -9
index 5baddb24545..d26718cbe48 100644
@@ -12,11 +12,11 @@ import u_boot_utils as util
 # pylint: disable=E0611
 from tests import fs_helper
 
-supported_fs_basic = ['fat16', 'fat32', 'ext4', 'fs_generic']
-supported_fs_ext = ['fat12', 'fat16', 'fat32', 'fs_generic']
+supported_fs_basic = ['fat16', 'fat32', 'exfat', 'ext4', 'fs_generic']
+supported_fs_ext = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
 supported_fs_fat = ['fat12', 'fat16']
-supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'fs_generic']
-supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'fs_generic']
+supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
+supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
 supported_fs_symlink = ['ext4']
 supported_fs_rename = ['fat12', 'fat16', 'fat32']
 
@@ -118,7 +118,7 @@ def fstype_to_prefix(fs_type):
     Return:
         A corresponding command prefix for file system type.
     """
-    if fs_type == 'fs_generic':
+    if fs_type == 'fs_generic' or fs_type == 'exfat':
         return ''
     elif re.match('fat', fs_type):
         return 'fat'
@@ -156,9 +156,11 @@ def check_ubconfig(config, fs_type):
     Return:
         Nothing.
     """
-    if not config.buildconfig.get('config_cmd_%s' % fs_type, None):
+    if fs_type == 'exfat' and not config.buildconfig.get('config_fs_%s' % fs_type, None):
+        pytest.skip('.config feature "FS_%s" not enabled' % fs_type.upper())
+    if fs_type != 'exfat' and not config.buildconfig.get('config_cmd_%s' % fs_type, None):
         pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper())
-    if fs_type == 'fs_generic':
+    if fs_type == 'fs_generic' or fs_type == 'exfat':
         return
     if not config.buildconfig.get('config_%s_write' % fs_type, None):
         pytest.skip('.config feature "%s_WRITE" not enabled'
@@ -198,7 +200,7 @@ def fs_obj_basic(request, u_boot_config):
     """
     fs_type = request.param
     fs_cmd_prefix = fstype_to_prefix(fs_type)
-    fs_cmd_write = 'save' if fs_type == 'fs_generic' else 'write'
+    fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write'
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
@@ -310,7 +312,7 @@ def fs_obj_ext(request, u_boot_config):
     """
     fs_type = request.param
     fs_cmd_prefix = fstype_to_prefix(fs_type)
-    fs_cmd_write = 'save' if fs_type == 'fs_generic' else 'write'
+    fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write'
     fs_img = ''
 
     fs_ubtype = fstype_to_ubname(fs_type)
test/py/tests/test_fs/fstest_helpers.py +2 -0
index c1447b4d43e..8f2e1fcf47d 100644
@@ -9,6 +9,8 @@ def assert_fs_integrity(fs_type, fs_img):
     try:
         if fs_type == 'ext4':
             check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
+        if fs_type == 'exfat':
+            check_call('fsck.exfat -n %s' % fs_img, shell=True)
         elif fs_type in ['fat12', 'fat16', 'fat32']:
             check_call('fsck.fat -n %s' % fs_img, shell=True)
     except CalledProcessError:
test/py/tests/test_fs/test_ext.py +14 -6
index 4e79135f824..47228be83c5 100644
@@ -345,11 +345,19 @@ class TestFsExt(object):
                 '%s%s host 0:0 %x /%s 0'
                     % (fs_cmd_prefix, fs_cmd_write, ADDR, MANGLE_FILE)])
             assert('0 bytes written' in ''.join(output))
-            # Test Case 12b - Read file system content
-            output = check_output('mdir -i %s' % fs_img, shell=True).decode()
-            # Test Case 12c - Check if short filename is not mangled
-            assert(str2fat(PLAIN_FILE) in ''.join(output))
-            # Test Case 12d - Check if long filename is mangled
-            assert(str2fat(MANGLE_FILE) in ''.join(output))
+            if fs_type == 'exfat':
+                # Test Case 12b - Read file system content
+                output = check_output('fattools ls %s' % fs_img, shell=True).decode()
+                # Test Case 12c - Check if short filename is not mangled
+                assert(PLAIN_FILE in ''.join(output))
+                # Test Case 12d - Check if long filename is mangled
+                assert(MANGLE_FILE in ''.join(output))
+            else:
+                # Test Case 12b - Read file system content
+                output = check_output('mdir -i %s' % fs_img, shell=True).decode()
+                # Test Case 12c - Check if short filename is not mangled
+                assert(str2fat(PLAIN_FILE) in ''.join(output))
+                # Test Case 12d - Check if long filename is mangled
+                assert(str2fat(MANGLE_FILE) in ''.join(output))
 
             assert_fs_integrity(fs_type, fs_img)
tools/docker/Dockerfile +1 -0
index 85d67848327..ad0200ad686 100644
@@ -74,6 +74,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
 	e2fsprogs \
 	efitools \
 	erofs-utils \
+	exfatprogs \
 	expect \
 	fakeroot \
 	flex \
Signature · 1 line
2.47.2
#13 lore raw

Re: [PATCH v2 11/11] test_fs: Add exfat tests

Quoted 19 lines · Marek Vasut

Add tests for the exfat filesystem. These tests are largely an extension of the FS_GENERIC tests with the following notable exceptions.

The filesystem image for exfat tests is generated using combination of exfatprogs mkfs.exfat and python fattools. The fattols are capable of generating exfat filesystem images too, but this is not used, the fattools are only used as a replacement for dosfstools 'mcopy' and 'mdir', which are used to insert files and directories into existing fatfs images and list existing fatfs images respectively, without the need for superuser access to mount such images.

The exfat filesystem has no filesystem specific command, there is only the generic filesystem command interface, therefore check_ubconfig() has to special case exfat and skip check for CONFIG_CMD_EXFAT and instead check for CONFIG_FS_EXFAT.

---

[snip]

test/py/tests/test_fs/fstest_helpers.py def assert_fs_integrity(fs_type, fs_img): · line 16

Quoted 13 lines
test/py/tests/test_fs/fstest_helpers.py +2 -0
index c1447b4d43e..8f2e1fcf47d 100644
@@ -9,6 +9,8 @@ def assert_fs_integrity(fs_type, fs_img):
     try:
         if fs_type == 'ext4':
             check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
+        if fs_type == 'exfat':
+            check_call('fsck.exfat -n %s' % fs_img, shell=True)
         elif fs_type in ['fat12', 'fat16', 'fat32']:
             check_call('fsck.fat -n %s' % fs_img, shell=True)
     except CalledProcessError:

This should be elif not if? Not a big deal if there's nothing else needing a v3 however. Everything else looks good, thanks.

Signature · 1 line
Tom
#14 lore raw

Re: [PATCH v2 11/11] test_fs: Add exfat tests

Quoted 22 lines · Tom Rini
Quoted 19 lines · Marek Vasut

Add tests for the exfat filesystem. These tests are largely an extension of the FS_GENERIC tests with the following notable exceptions.

The filesystem image for exfat tests is generated using combination of exfatprogs mkfs.exfat and python fattools. The fattols are capable of generating exfat filesystem images too, but this is not used, the fattools are only used as a replacement for dosfstools 'mcopy' and 'mdir', which are used to insert files and directories into existing fatfs images and list existing fatfs images respectively, without the need for superuser access to mount such images.

The exfat filesystem has no filesystem specific command, there is only the generic filesystem command interface, therefore check_ubconfig() has to special case exfat and skip check for CONFIG_CMD_EXFAT and instead check for CONFIG_FS_EXFAT.

---

[snip]

Quoted 16 lines

test/py/tests/test_fs/fstest_helpers.py def assert_fs_integrity(fs_type, fs_img): · line 16

Quoted 13 lines
test/py/tests/test_fs/fstest_helpers.py +2 -0
index c1447b4d43e..8f2e1fcf47d 100644
@@ -9,6 +9,8 @@ def assert_fs_integrity(fs_type, fs_img):
      try:
          if fs_type == 'ext4':
              check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
+        if fs_type == 'exfat':
+            check_call('fsck.exfat -n %s' % fs_img, shell=True)
          elif fs_type in ['fat12', 'fat16', 'fat32']:
              check_call('fsck.fat -n %s' % fs_img, shell=True)
      except CalledProcessError:

This should be elif not if? Not a big deal if there's nothing else needing a v3 however. Everything else looks good, thanks.

Yes, it should be elif . Unfortunately, there is now a clean up change in next which modifies test/py/tests/test_fs/test_basic.py and conflicts badly with 3/11 in this series, so I need to carefully rebase that patch on top of current next. I'll send V3 once it is done.