aboutsummaryrefslogtreecommitdiff
path: root/fs/fs.c
AgeCommit message (Collapse)AuthorFilesLines
2023-07-14fs: Create functions to load and allocate a fileSimon Glass1-0/+58
This functionality current sits in bootstd, but it is more generally useful. Add a function to load a file into memory, allocating it as needed. Adjust bootstd to use this version. Note: Tests are added in the subsequent patch which converts the 'cat' command to use this function. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-08-10common: Drop display_options.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-04-25fs: Add a function to set the filesystem typeSimon Glass1-0/+5
When sandbox is used with hostfs we won't have a block device, but still must set up the filesystem type before any filesystem operation, such as loading a file. Add a function to handle this. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-04-21fs: Allow to compile FS_SQUASHFS only for proper U-BootPali Rohár1-1/+1
CONFIG_SPL_FS_SQUASHFS cannot be disabled when CONFIG_FS_SQUASHFS is enabled. Fix it. Signed-off-by: Pali Rohár <pali@kernel.org>
2022-04-19fs: Allow to compile FS_BTRFS when SPL is enabledWIP/2022-04-19-assorted-udpatesPali Rohár1-0/+2
Currently there is no btrfs support in SPL. But macro CONFIG_FS_BTRFS is defined also when building SPL. When both FS_BTRFS and SPL are enabled then build process throw compile error. Fix check for btrfs code in fstypes[] to allow compiling FS_BTRFS only in proper U-Boot. Signed-off-by: Pali Rohár <pali@kernel.org>
2022-04-14fs: Allow to compile CMD_UBIFS when SPL is enabledPali Rohár1-0/+2
Currently there is no UBIFS support in SPL. But macro CONFIG_CMD_UBIFS is defined also when building SPL. when both CMD_UBIFS and SPL are enabled then build process throw compile error. Fix check for ubifs code in fstypes[] to allow compiling CMD_UBIFS only in proper U-Boot. Signed-off-by: Pali Rohár <pali@kernel.org>
2022-04-14fs: Allow to compile FS_FAT only for proper U-BootPali Rohár1-1/+1
CONFIG_SPL_FS_FAT cannot be disabled when CONFIG_FS_FAT is enabled. Fix it. Signed-off-by: Pali Rohár <pali@kernel.org>
2022-04-01fs: Add semihosting filesystemSean Anderson1-0/+20
This adds a filesystem which is backed by the host's filesystem. It is modeled off of sandboxfs, which has very similar aims. Semihosting doesn't support listing directories (except with SYS_SYSTEM), so neither do we. it's possible to optimize a bit for the common case of reading a whole file by omitting a call to smh_seek, but this is left as a future optimization. Signed-off-by: Sean Anderson <sean.anderson@seco.com>
2022-03-15fs/erofs: add erofs filesystem supportHuang Jianan1-0/+22
This patch mainly deals with uncompressed files. Signed-off-by: Huang Jianan <jnhuang95@gmail.com>
2021-09-24fs: avoid superfluous messagesHeinrich Schuchardt1-1/+1
Output like the following is quite irritating: => bootefi hello Scanning disk mmc2.blk... No valid Btrfs found Bad magic number for SquashFS image. ** Unrecognized filesystem type ** Scanning disk mmc1.blk... No valid Btrfs found Bad magic number for SquashFS image. ** Unrecognized filesystem type ** Scanning disk mmc0.blk... No valid Btrfs found Bad magic number for SquashFS image. ** Unrecognized filesystem type ** Albeit a whole disk may be formatted with a filesystem in most cases a partition table is used and the whole disk (partition number 0) doesn't contain a filesytem. Some partitions may only contain a blob. Not seeing a filesytem on the whole disk or on any partition is only worth a debug message. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-08-02global: Convert simple_strtoul() with hex to hextoul()Simon Glass1-7/+7
It is a pain to have to specify the value 16 in each call. Add a new hextoul() function and update the code to use it. Add a proper comment to simple_strtoul() while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-04-22cmd: fs: Use part_get_info_by_dev_and_name_or_num to parse partitionsSean Anderson1-2/+2
This allows using dev#partlabel syntax. Signed-off-by: Sean Anderson <sean.anderson@seco.com>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2021-02-01cmd: load, emit error message for invalid block deviceHeinrich Schuchardt1-1/+3
The load command should not silently return to the console prompt if an invalid block device is specified and no file is loaded. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-01-13efi_loader: setting boot deviceHeinrich Schuchardt1-1/+2
Up to now the bootefi command used the last file loaded to determine the boot partition. This has led to errors when the fdt had been loaded from another partition after the EFI binary. Before setting the boot device from a loaded file check if it is a PE-COFF image or a FIT image. For a PE-COFF image remember address and size, boot device and path. For a FIT image remember boot device and path. If the PE-COFF image is overwritten by loading another file, forget it. Do not allow to start an image via bootefi which is not the last loaded PE-COFF image. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-31fs/fat: implement fsuuid commandHeinrich Schuchardt1-1/+1
The FAT file system does not have a UUID but a 4 byte volume ID. Let the fsuuid command show it in XXXX-XXXX format. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-19fs/squashfs: implement exists() functionRichard Genoud1-1/+1
This permits to find a file and use the distro_bootcmd Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
2020-11-19fs/squashfs: fix board hang-up when calling .exists()Richard Genoud1-0/+7
add missing squashfs function to prevent dangling or null pointers. For exemple, when calling test [ -e somefile ], squashfs.exists may be called. Signed-off-by: Richard Genoud <richard.genoud@posteo.net> Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com>
2020-09-06fs: convert error and debug messages to logHeinrich Schuchardt1-7/+9
Use log functions for error and debug messages of the file-system. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-08-07fs/fs.c: add symbolic link case to fs_ls_generic()Joao Marcos Costa1-0/+3
Adds an 'else if' statement inside the loop to check for symbolic links. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
2020-08-07fs/squashfs: new filesystemJoao Marcos Costa1-0/+15
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
2020-07-17fs: error handling in do_load()Heinrich Schuchardt1-5/+7
If a file cannot be loaded, show an error message. Set the EFI boot device only after successfully loading a file. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-07cmd: fs: Add command to list supported fs typesNiel Fourie1-0/+20
Added command "fstypes" to list supported/included filesystems. Signed-off-by: Niel Fourie <lusus@denx.de> Cc: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> [trini: Limit to sandbox] Signed-off-by: Tom Rini <trini@konsulko.com>
2020-05-18common: Drop log.h from common headerSimon Glass1-0/+1
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18command: Remove the cmd_tbl_t typedefSimon Glass1-14/+15
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18common: Drop part.h from common headerSimon Glass1-0/+1
Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18part: Drop disk_partition_t typedefSimon Glass1-3/+3
We should not be using typedefs and these make it harder to use forward declarations (to reduce header file inclusions). Drop the typedef. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-10-17fs: add fs_get_type() for current filesystem typeAKASHI Takahiro1-0/+13
This function is a variant of fs_get_type_name() and returns a filesystem type with which the current device is associated. We don't want to export fs_type variable directly because we have to take care of it consistently within fs.c. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-17fs: clean up around fs_typeAKASHI Takahiro1-3/+0
fs_ls(), fs_mkdir() and fs_unlink() sets fs_type to FS_TYPE_ANY explicitly, but it is redundant as they call fs_close(). So just remove those lines. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-17fs: export fs_close()AKASHI Takahiro1-1/+1
fs_close() closes the connection to a file system which opened with either fs_set_blk_dev() or fs_set_dev_with_part(). Many file system functions implicitly call fs_close(), e.g. fs_closedir(), fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write() and fs_unlink(). So just export it. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-08-11env: Move env_set_hex() to env.hSimon Glass1-0/+1
Move env_set_hex() over to the new header file along with env_set_addr() which uses it. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-06-20fs: do_load: pass device path for efi payloadMian Yousaf Kaukab1-0/+5
fatload command can be used to load the EFI payload since EFI system partition is always a FAT partition. Call into EFI code from do_load() to set the device path from which the last binary was loaded. An EFI application like grub2 can’t find its configuration file without the device path set. Since device path is now set in do_load() there is no need to set it in do_load_wrapper() for the load command. Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-09fs: Add a new command to create symbolic linksJean-Jacques Hiblot1-0/+44
The command line is: ln <interface> <dev[:part]> target linkname Currently symbolic links are supported only in ext4 and only if the option CMD_EXT4_WRITE is enabled. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-02-09fs: ext4: Unmount FS in do_fs_type()Marek Vasut1-0/+2
Unlike other generic FS accessors, fs_get_info() does not call fs_close() at the end of it's operation. Thus, using fs_get_info() in do_fs_type() without calling fs_close() causes potential memory leak by creating new filesystem structures on each call of do_fs_type(). The test case to trigger this problem is as follows. It is required to have ext4 filesystem on the first partition of the SDMMC device, since ext4 requires stateful mount and causes memory allocation. => while true ; do mmc rescan ; fstype mmc 1 ; done Eventually, the mounting of ext4 will fail due to malloc failures and the filesystem will not be correctly detected. This patch fixes the problem by adding the missing fs_close(). Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com>
2019-02-02lmb: handle more than one DRAM BANKSimon Goldschmidt1-2/+1
This fixes the automatic lmb initialization and reservation for boards with more than one DRAM bank. This fixes the CVE-2018-18439 and -18440 fixes that only allowed to load files into the firs DRAM bank from fs and via tftp. Found-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-02-01spl: fat/fs: Add control to build FS EXT4 in SPLTien Fong Chee1-1/+2
CONFIG_SPL_FS_EXT4 can be used to include/exclude the FS EXT4 from SPL build. Excluding the FS EXT4 from SPL build can help to save 20KiB memory. Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-02-01spl: fat/fs: Add option to include/exclude FAT write build in SPLTien Fong Chee1-1/+1
Most of the time SPL only needs very simple FAT reading, so having CONFIG_IS_ENABLED(FAT_WRITE) to exclude it from SPL build would help to save 64KiB default max clustersize from memory. Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-01-16fs: prevent overwriting reserved memorySimon Goldschmidt1-3/+53
This fixes CVE-2018-18440 ("insufficient boundary checks in filesystem image load") by using lmb to check the load size of a file against reserved memory addresses. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-12-02fs: update fs_dev_part in fs_set_blk_dev_with_part()AKASHI Takahiro1-0/+1
As in the case of fs_set_blk_dev(), fs_set_blk_dev_with_part() should maintain and update fs_dev_part whenever called. Without this patch, a problem will come up when an efi binary associated with efi's BOOTxxxx variable is invoked via "bootefi bootmgr". Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: support unlinkAKASHI Takahiro1-1/+2
In this patch, unlink support is added to FAT file system. A directory can be deleted only if it is empty. In this implementation, only a directory entry for a short file name will be removed. So entries for a long file name can and should be reclaimed with fsck. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: add unlink interfaceAKASHI Takahiro1-0/+40
"unlink" interface is added to file operations. This is a preparatory change as unlink support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: support mkdirAKASHI Takahiro1-1/+2
In this patch, mkdir support is added to FAT file system. A newly created directory contains only "." and ".." entries. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: add mkdir interfaceAKASHI Takahiro1-0/+45
"mkdir" interface is added to file operations. This is a preparatory change as mkdir support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-08-13fs: fix typo 'dumm'Heinrich Schuchardt1-1/+1
%s/dumm /dummy / Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2018-05-30fs: Add fs_get_type_name to return current filesystem nameAlex Kiernan1-0/+13
Add fs_get_type_name so we can get the current filesystem type. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini1-2/+1
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-01-19fs: remove distractive message in fs_read()Heinrich Schuchardt1-1/+1
The message "** %s shorter than offset + len **\n" may be interesting when debugging but it does not indicate an error. So we should not write it if we are not in debug mode. Fixes: 7a3e70cfd88c fs/fs.c: read up to EOF when len would read past EOF Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-10-16fs: Set .opendir to fs_opendir_unsupported for btrfsMarek Behún1-0/+1
Otherwise fs_opendir will fault. Signed-off-by: Marek Behun <marek.behun@nic.cz>
2017-10-02fs: btrfs: Add U-Boot fs handlers.Marek Behún1-0/+16
Signed-off-by: Marek Behun <marek.behun@nic.cz> create mode 100644 fs/btrfs/Kconfig create mode 100644 fs/btrfs/Makefile create mode 100644 fs/btrfs/btrfs.c create mode 100644 include/btrfs.h
2017-09-15fat/fs: move ls to generic implementationRob Clark1-2/+33
Add a generic implementation of 'ls' using opendir/readdir/closedir, and replace fat's custom implementation. Other filesystems should move to the generic implementation after they add opendir/readdir/closedir support. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>