Commit Graph

1022 Commits

Author SHA1 Message Date
Simon Glass
20652517c8 fat: Use standard types for fixed-size values
Convert all __u8, __u16, and __u32 types to their u8, u16, u32
equivalents throughout the FAT filesystem code.

Series-to: u-boot
Series-cc: heinrich
Cover-letter:
fat: Some code improvements
This is an attempt to improve the structure of the FAT code, since it
doesn't fully follow the U-Boot conventions:

- fat_write.c includes fat.c which is odd
- use of __u32 and its ilk
- use of typedef
- old-style struct comments

This series resolves these problems, making it easier to take on other
improvements in future.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-13 19:59:03 -07:00
Simon Glass
aa6f5484e6 fat: Remove typedefs in fat.h
Convert all typedefs in fat.h to normal struct declarations.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 18:39:22 -07:00
Simon Glass
ffb7d606ff fat: Update struct fat_itr to kernel-doc style
Convert the struct fat_itr documentation from the older style with
separate @field comments to the standard kernel-doc style where field
descriptions are listed in the header comment block.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 18:39:13 -07:00
Simon Glass
cb30dcb8b6 fat: Separate fat.c from fat_write.c
Currently fat_write.c includes fat.c directly, which is unusual and
makes the code harder to maintain. Use the internal header file to hold
shared functions, to avoid this.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 18:39:11 -07:00
Simon Glass
b92ee1a12f fat: Create an internal header file
As a first step towards separating fat.c from fat_write.c, create a
header file for the definitions.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 18:28:57 -07:00
Simon Glass
7bd184c0c5 lib: Plumb in argon2 library
Add a Kconfig optiion to enable this library and add it to the lib/
Makefile, being careful to avoid a conflict with the existing blake2b
implementation.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:09:41 -07:00
Simon Glass
ef2d6ec193 fs: Avoid calling efi_set_bootdev() from the app
This function is used by the EFI loader but we want to avoid it for the
app, since it records global state.

We don't intend to support running arbitrary EFI apps outside of a
bootstd context, so drop this call for the EFI app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 17:01:22 -06:00
Simon Glass
2b66e2f9d3 fs: Reuse a directory device when accessing the same dir
At present a new directory device is created for every access to a
directory. This means that a new device is always created when 'ls' is
used.

Where the directory being accessed matches an existing device, this is
not necessary.

Check that path against existing directories and reuse the device if
possible.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 15:14:47 +02:00
Simon Glass
878f27e552 fs: Use an empty string for the root directory
It is easier to use an empty string when the root directory is intended.
Adjust the code to drop use of "/" and NULL and just use and empty
string.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 14:29:06 +02:00
Simon Glass
cd93381ec5 emulation: x86: Rename VENDOR_EMULATION to ARCH_QEMU_X86
This name matches the ARM name and 'emulation' is not really a vendor.
Use ARCH_QEMU_X86 instead, moving that option from its existing location.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 05:21:59 +02:00
Simon Glass
ab3b9d1d88 emulation: Rename ARCH_QEMU to ARCH_QEMU_ARM
This option looks generic but in fact is specific to ARM. Rename it to
reflect this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-05 05:48:28 -06:00
Simon Glass
5ab90a9307 virtio: Plumb virtio-fs into the legacy filesystem code
Add compatibility function to support a single virtio-fs via the normal
'ls' and 'load' commands. Other commands are not supported for now.

Add a workaround for the fact that virtiofs does not use a block device.
The existing filesystem layer does not support non-block filesystems -
sandbox's hostfs mostly bypasses this code.

Make sure that sandbox does not try to mount a virtio-fs as this does
not work at present. It will require either a fake driver for virtio-fs
which connects to host files, or possibly something involving FUSE.

Series-to: concept
Cover-letter:
virtio: Support virtio-fs
This series introduces support for virtio-fs, a filesystem which
provides access to host files from within a QEMU guest OS.

A new filesystem driver is created with support for the three uclasses
(FS, DIR, FILE). A compatibility layer is added as well, so that the
existing cmdline work as expected.

Only listing directories and reading files are supported so far.

Since sandbox works by using a NULL blk_desc, a workaround is added for
now. Once we switch commands (and bootstd!) over to the new filesystem
approach, this will go away.

It is possible to test this using something like:

   ./scripts/build-qemu -a x86  -rs -D .

then within U-Boot:

   ls virtio 0
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 11:57:41 -06:00
Simon Glass
595a5fb008 sandbox: Use DM_DRIVER_REF() to obtain driver
Using DM_DRIVER_GET() forces alignment which in the case of the
tools-only board results in an invalid linker list. It is not actually
used in this case (since only the tools are ever executed), but does
cause a build failure.

Fix it by switching to DM_DRIVER_REF()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-29 06:53:35 -06:00
Simon Glass
a84eefb95c fs: Add a sandbox test for the file uclass
Create a test which looks for a file reads from it.

Series-to: concept
Cover-letter:
Introduce a filesystem layer
U-Boot's filesystems work reasonably well but could be improved:

- There is no equivalent of Linux's VFS, meaning that the device type
  must be provided with filesystem commands like 'ls' and 'load'
- There is no caching, nor really anything to hang caching on to, so
  each access causes the filesystem to be remounted
- There is no real 'driver model' access to filesystems, in the sense
  of opening a file, reading it and then later closing it
- It is quite hard to support non-block filesystems, since many
  functions pass around a struct blk_desc for want of a better
  structure.

As a first step towards improving things, this series provides a simple
filesystem uclass, which can be implemented to provide access to
filesystems via driver model. Only one filesystem is currently
supported: sandbox's hostfs

The existing filesystem layer is renamed to 'legacy', to indicate that
it is on the way out. New filesystems should try to build on this new
series. The rename is only partial, since there is no attempt here to
replace the existing filesystem commands.

Basic versions of a directory and file are also added. The directory
uclass only supports listing directories. The file uclass only supports
reading files. There is a small test.

From this small start, we can perhaps build on more features.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
ab25244811 fs: Add support for a file
Directories can have a number of files within them. U-Boot only needs to
create a file object for those that have been opened for read/write. Add
the concept of a file, with its directory as parent.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
dd58526971 fs: Add a sandbox test for the directory uclass
Create a test which looks for a file and a directory in the U-Boot
source tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
4ae46c7db4 fs: Add support for a directory
Filesystems can have a number of directories within them. U-Boot only
worries about directories that have been accessed. Add the concept of
a directory, with the filesystem as parent.

Note that this is not a hierarchical device structure, so UCLASS_DIR
devices always have a UCLASS_FS as the parent.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
d347548467 fs: Add simple sandbox test
Add a simple test of a filesystem on sandbox.
2025-06-28 12:30:56 -06:00
Simon Glass
48655e4aa9 fs: Add support for a filesystem
The existing filesystem support is fairly basic. It supports access to
only one filesystem at a time, does not allow caching, does not have an
equivalent of Linux's VFS and uses global variables to keep track of
which one is in use.

As a starting point to improving this, provide a filesystem uclass. For
now it only includes operations to mount and unmount.

Provide a bootdev so that it is possible to locate bootflows on a
filesystem.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
b3cbdc4951 fs: Provide information about non-block filesystems
The existing disk and partition code assumes a block device.

Sandbox provides access to host files and does not operate through a
block device. This is currently handled with special-case logic.

We want to add virtio-fs support, which is also not a block device. It
is not easy to have these two co-exist, so add a new type field to
struct disk_partition to indicate the type.

This is a work-around to deal with the fact that the type needs to be
set by blk_get_device_part_str() in such a way that it is visible to
fs_readdir()

There is a global fs_type in disk/part.c but this is not available in
the fs/ code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
8630e568b2 fs: Rename fs_read() to fs_legacy_read()
This existing function does not have any context associated with it.
Rename it so that fs_read() can be used for the new FS uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
fba734be3c fs: Provide an SPL Kconfig for legacy-filesystem support
Add a new SPL_FS_LEGACY which mirrors the recently added FS_LEGACY
option.

Select this new option when filesystems are required, either due to
SPL_FS_LOADER or one of the filesystems.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:55 -06:00
Simon Glass
14d2361c95 fs: Provide a Kconfig option for legacy-filesystem support
There is currently no Kconfig used and the filesystem code is always
included in U-Boot proper. Add an option to control this. For now it is
always on.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 10:16:25 -06:00
Simon Glass
4acf3a243b fs: Rename fs.c to fs_legacy.c
A new filesystem interface is coming, so rename the main fs.c file to
indicate that it is the old one.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 07:53:25 -06:00
Simon Glass
8a698cf850 fs: Rename fs.h to fs_legacy.h
A new filesystem interface is coming, so rename the current header to
indicate that it is the old one.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 07:53:25 -06:00
Simon Glass
847d15cada boot: sandbox: Rename host_bootdev.c
This filename is confusing since it is actually for the sandbox hostfs,
i.e. access to files on the host filesystem, not the host device which
can be used to bind disk images.

Rename it to hostfs_bootdev.c to make this clearer. Update the driver
name as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-05 14:42:47 -06:00
Simon Glass
be9b32b66e fs: boot: Update fs_load_alloc() to use abuf
Using an abuf for this function simplifies returning the size and also
makes it easier to free memory afterwards. Update the API and callers.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-02 09:45:32 -06:00
Simon Glass
0fa5b24f73 fs: boot: Update fs_read_alloc() to use abuf
Using an abuf for this function simplifies returning the size and also
makes it easier to free memory afterwards. Update the API and callers.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-02 09:45:32 -06:00
Tom Rini
2825b387b0 Kbuild: Always use $(PHASE_)
It is confusing to have both "$(PHASE_)" and "$(XPL_)" be used in our
Makefiles as part of the macros to determine when to do something in our
Makefiles based on what phase of the build we are in. For consistency,
bring this down to a single macro and use "$(PHASE_)" only.

Signed-off-by: Tom Rini <trini@konsulko.com>
2025-05-01 05:56:48 -06:00
Marek Vasut
b7bc01908a fs: exfat: Implement trivial 'rename' support
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: b86a651b64 ("fs: exfat: Add U-Boot porting layer")
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:48 -06:00
Marek Vasut
5aca9aa830 fs: exfat: Fix exfat_fs_exists() return value
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: b86a651b64 ("fs: exfat: Add U-Boot porting layer")
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:48 -06:00
Marek Vasut
a525201bd9 fs: exfat: Rework exfat_fs_readdir() to behave like exfat_fs_ls()
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: b86a651b64 ("fs: exfat: Add U-Boot porting layer")
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:48 -06:00
Marek Vasut
9762ff4f08 fs: exfat: Inhibit "impossible" print on write to bogus file
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: b86a651b64 ("fs: exfat: Add U-Boot porting layer")
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:48 -06:00
Marek Vasut
8b93c82c01 fs: exfat: Flush node before put in read() callback
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: b86a651b64 ("fs: exfat: Add U-Boot porting layer")
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:48 -06:00
Marek Vasut
7618495e80 fs: exfat: Demote filesystem detection failure message to debug()
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 <trini@konsulko.com>
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:47 -06:00
Marek Vasut
f6efa5fd11 fs: exfat: Fix conversion overflow errors
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 <marex@denx.de>
2025-05-01 05:56:47 -06:00
Marek Vasut
daa6d6a67d fs: exfat: Add U-Boot porting layer
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 <trini@konsulko.com>
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:47 -06:00
Marek Vasut
e0ff2d4bd9 fs: exfat: Import libexfat from fuse-exfat
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 <trini@konsulko.com>
Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:47 -06:00
Marek Vasut
89dbc9b6d0 fs: Add generic fs_devread() implementation
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().

Signed-off-by: Marek Vasut <marex@denx.de>
2025-05-01 05:56:47 -06:00
Gabriel Dalimonte
2a5b014de2 fs: fat: update parent dirs metadata on dentry create/delete
POSIX filesystem functions that create or remove directory entries contain
text along the lines of "[function] shall mark for update the last data
modification and last file status change timestamps of the parent
directory of each file." [1][2][3] The common theme is these timestamp
updates occur when a directory entry is added or removed. The
create_link() and delete_dentry_link() functions have been changed to
update the modification timestamp on the directory where the direntry
change occurs. This differs slightly from Linux in the case of rename(),
where Linux will not update `new_path`'s parent directory's timestamp if
it is replacing an existing file. (via `vfat_add_entry` [4])

The timestamps are not updated if the build configuration does not support
RTCs. This is an effort to minimize introducing erratic timestamps where
they would go from [current date] -> 2000-01-01 (error timestamp in the
FAT driver). I would assume an unchanged timestamp would be more valuable
than a default timestamp in these cases.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html
[2] https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlink.html
[3] https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html
[4] https://elixir.bootlin.com/linux/v6.12.6/source/fs/fat/namei_vfat.c#L682

Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
2025-05-01 05:56:47 -06:00
Gabriel Dalimonte
f12f27d2e0 fs: fat: add rename
The implementation roughly follows the POSIX specification for
rename() [1]. The ordering of operations attempting to minimize the chance
for data loss in unexpected circumstances.

The 'mv' command was implemented as a front end for the rename operation
as that is what most users are likely familiar with in terms of behavior.

The 'FAT_RENAME' Kconfig option was added to prevent code size increase on
size-oriented builds like SPL.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html

Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
2025-05-01 05:56:47 -06:00
Gabriel Dalimonte
fa10e79519 fs: add rename infrastructure
The selection for *rename as the name for the rename/move operation
derives from the POSIX specification where they name the function
rename/renameat. [1] This aligns with Linux where the syscalls for
renaming/moving also use the rename/renameat naming.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html

Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-05-01 05:56:47 -06:00
Gabriel Dalimonte
ac6cb92467 fs: fat: factor out dentry link create/delete
The create_link() code was previously duplicated in two existing functions.
The two functions will be used in a future commit to achieve renaming.

Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
2025-05-01 05:56:47 -06:00
Simon Glass
9820ce9a2f fs: Record loaded files in an ad-hoc bootflow
This makes a start on dealing with images loaded outside the context of
bootstd. For now, it just records these images. They can be listed using
the 'bootstd images' command.

Often, very little is known about these images, but future work could
perhaps use the filename or contents to detect the type.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-05 11:00:23 -07:00
Nam Cao
6ea8dc661b fs: Use ARCH_DMA_MINALIGN as default alignment for fs_read_alloc()
The comment above fs_read_alloc() explains:

    @align: Alignment to use for memory allocation (0 for default)

However, in the actual implementation, there is no alignment when @align is
zero.

This current default is probably fine for most cases. But for some block
devices which transfer data via DMA, ARCH_DMA_MINALIGN is needed.

Change the default alignment to ARCH_DMA_MINALIGN.

Fixes: de7b5a8a1a ("fs: Create functions to load and allocate a file")
Signed-off-by: Nam Cao <namcao@linutronix.de>
Tested-by: Javier Fernandez Pastrana <javier.pastrana@linutronix.de>
2024-11-18 08:23:56 -06:00
Dominique Martinet
6e988fde65 fs: btrfs: hide duplicate 'Cannot lookup file' error on 'load'
Running commands such as 'load mmc 2:1 $addr $path' when path does not
exists will print an error twice if the file does not exist, e.g.:
```
Cannot lookup file boot/boot.scr
Failed to load 'boot/boot.scr'
```
(where the first line is printed by btrfs and the second by common fs
code)

Historically other filesystems such as ext4 or fat have not been
printing a message here, so do the same here to avoid duplicate.

The other error messages in this function are also somewhat redundant,
but bring useful diagnostics if they happen somewhere, so have been left
as printf.

Note that if a user wants no message to be printed for optional file
loads, they have to check for file existence first with other commands
such as 'size'.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
2024-11-15 13:11:47 -06:00
Heinrich Schuchardt
9084e1b1b9 fs: ext4: correct error handling
After calling strdup() check the returned pointer.

Avoid a memory leak if the directory is not found.

Reported-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com>
Fixes: 22fdac381f ("fs: ext4: implement opendir, readdir, closedir")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-11-13 08:18:50 -06:00
Heinrich Schuchardt
29e5a2e959 fs: ext4: use fs_ls_generic
Now that opendir, readir, closedir are implemented for ext4 we can use
fs_ls_generic() for implementing the ls command.

Adjust the unit tests:

* fs_ls_generic() produces more spaces between file size and name.
* The ext4 specific message "** Can not find directory. **\n" is not
  written anymore.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-11-01 13:37:58 -06:00
Heinrich Schuchardt
22fdac381f fs: ext4: implement opendir, readdir, closedir
For accessing directories from the EFI sub-system a file system must
implement opendir, readdir, closedir. Provide the missing implementation.

With this patch the eficonfig command can be used to define load options
for the ext4 file system.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-11-01 13:37:58 -06:00
Heinrich Schuchardt
2d94480c02 fs: ext4: free directory node in ext4fs_exists()
The directory retrieved in ext4fs_exists() should be freed to avoid a
memory leak.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-11-01 13:37:58 -06:00