summaryrefslogtreecommitdiff
path: root/fs/exfat
AgeCommit message (Collapse)Author
2025-07-24fs: exfat: Remove unused label codeAndrew Goodbody
Smatch reported a possible buffer overflow in exfat_set_label but it turns out that this code is unused so just guard the function with '#ifndef __UBOOT__' as well as exfat_get_label that is also unused and the helper static find_label. Signed-off-by: Andrew Goodbody <[email protected]>
2025-07-15fs: exfat: Remove pointless variable uoffsetAndrew Goodbody
In exfat_generic_pread and exfat_generic_pwrite offset is passed in as a off_t type which is defined as 'unsigned long long' so there is no need to create the variable uoffset as a uint64_t as this is just a direct copy of offset. Also remove the impossible test of 'offset < 0' as this is always false due to offset being unsigned. This issue found by Smatch. Signed-off-by: Andrew Goodbody <[email protected]>
2025-07-15fs: exfat: Perform NULL check before dereferenceAndrew Goodbody
In the functions exfat_pread and exfat_pwrite there is a NULL check for ctxt.cur_dev but this has already been derefenced twice before this happens. Refactor the code a bit to put the NULL check first. This issue found by Smatch. Signed-off-by: Andrew Goodbody <[email protected]>
2025-05-05fs: exfat: Inhibit unused exfat_humanize_bytes() and exfat_print_info()Marek Vasut
Make sure unused exfat_humanize_bytes() and exfat_print_info() functions are not compiled into U-Boot code base. This also removes CID 550300: Integer handling issues (INTEGER_OVERFLOW) in exfat_humanize_bytes() , which is now surely unreachable. Signed-off-by: Marek Vasut <[email protected]>
2025-05-05fs: exfat: Use strncpy() and bail on too long filenamesMarek Vasut
In case the filename is too long, longer than PATH_MAX - 1, it would overflow dirs->dirname array. Add missing check and also use strncpy() to prevent the overflow in any case. Fixes CID 550305: Security best practices violations (STRING_OVERFLOW) Signed-off-by: Marek Vasut <[email protected]>
2025-04-21fs: exfat: Implement trivial 'rename' supportMarek Vasut
Implement exfat_fs_rename() to rename or move files. This is used by the 'mv' generic FS interface command. The rename implementation for other filesystems was added recently and was not part of exfat porting layer due to merge issue, which made 'mv' command crash, fix this by adding the missing implementation. Fixes: b86a651b646c ("fs: exfat: Add U-Boot porting layer") Signed-off-by: Marek Vasut <[email protected]>
2025-04-21fs: exfat: Fix exfat_fs_exists() return valueMarek Vasut
The exfat_fs_exists() should return 0 in case the path does not exist, and 1 in case the path does exist. Fix the inverted return value. This fixes 'test -e' command with exfat. Fixes: b86a651b646c ("fs: exfat: Add U-Boot porting layer") Signed-off-by: Marek Vasut <[email protected]>
2025-04-21fs: exfat: Rework exfat_fs_readdir() to behave like exfat_fs_ls()Marek Vasut
The exfat_fs_readdir() depends on state created in exfat_fs_opendir(), but that state may be disrupted by fs_close() called by the FS layer in fs_opendir(), because exfat porting layer unmounts the filesystem in ->close() callback. To avoid this disruption, avoid creating state in exfat_fs_opendir(), cache only the directory name to list there, and rework exfat_fs_readdir() to work in a similar way to exfat_fs_ls(). That is, make exfat_fs_readdir() open the directory, look up specific entry, extract its properties to be reported to FS layer, and close the directory. This is slow, but avoids the disruption. The slowness does not affect regular 'ls' command, which uses exfat_fs_ls() fast path. Fixes: b86a651b646c ("fs: exfat: Add U-Boot porting layer") Signed-off-by: Marek Vasut <[email protected]>
2025-04-21fs: exfat: Inhibit "impossible" print on write to bogus fileMarek Vasut
Write into a bogus file, like '/.', triggers an "impossible" print from the exfat core code. That should not be printed in U-Boot, because U-Boot prints its own error message sooner. Inhibit this error message. The following command triggers the bogus print: " => save host 0:0 1000008 /. 0x10 " Fixes: b86a651b646c ("fs: exfat: Add U-Boot porting layer") Signed-off-by: Marek Vasut <[email protected]>
2025-04-21fs: exfat: Flush node before put in read() callbackMarek Vasut
Make sure the node is never dirty before being released, flush the node first using exfat_flush_node() and only then release the node using exfat_put_node(). This now matches the behavior of exfat_fs_write() too. Fixes: b86a651b646c ("fs: exfat: Add U-Boot porting layer") Signed-off-by: Marek Vasut <[email protected]>
2025-04-02fs: exfat: Demote filesystem detection failure message to debug()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(). Reviewed-by: Tom Rini <[email protected]> Signed-off-by: Marek Vasut <[email protected]>
2025-04-02fs: exfat: Fix conversion overflow errorsMarek 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; | ^ " Signed-off-by: Marek Vasut <[email protected]>
2025-04-02fs: exfat: Add U-Boot porting layerMarek 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) Acked-by: Tom Rini <[email protected]> Signed-off-by: Marek Vasut <[email protected]>
2025-04-02fs: exfat: Import libexfat from fuse-exfatMarek 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.") Acked-by: Tom Rini <[email protected]> Signed-off-by: Marek Vasut <[email protected]>