summaryrefslogtreecommitdiff
path: root/fs/fat
AgeCommit message (Collapse)Author
2019-01-11Revert "fs: fat: assign rootdir sector when accessing root directory"Tom Rini
This particular commit is causing a regression on stih410-b2260 and other platforms when reading from FAT16. Noting that I had rebased the original fix from Thomas onto then-current master, there is also question from Akashi-san if the change is still needed after other FAT fixes that have gone in. This reverts commit a68b0e11ea774492713a65d9fd5bb525fcaefff3. Reported-by: Patrice Chotard <patrice.chotard@st.com> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org> Cc: Thomas RIENOESSL <thomas.rienoessl@bachmann.info> Signed-off-by: Tom Rini <trini@konsulko.com>
2018-12-06fs: fix FAT name extractionPatrick Wildt
The long name apparently can be accumulated using multiple 13-byte slots. Unfortunately we never checked how many we can actually fit in the buffer we are reading to. Signed-off-by: Patrick Wildt <patrick@blueri.se>
2018-12-06fs: check FAT cluster sizePatrick Wildt
The cluster size specifies how many sectors make up a cluster. A cluster size of zero makes no sense, as it would mean that the cluster is made up of no sectors. This will later lead into a division by zero in sect_to_clust(), so better take care of that early. The MAX_CLUSTSIZE define can reduced using a define to make some room in low-memory system. Unfortunately if the code reads a filesystem with a bigger cluster size it will overflow the buffer. Signed-off-by: Patrick Wildt <patrick@blueri.se>
2018-11-20fs: fat: assign rootdir sector when accessing root directoryThomas RIENOESSL
This fixes problems accessing drives formated under Windows as FAT16. Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info> [trini: Rebase on top of f528c140c801] Signed-off-by: Tom Rini <trini@konsulko.com>
2018-10-16fs: fat: Fix warning in normalize_longname()Tom Rini
As observed with clang: fs/fat/fat_write.c:1024:13: warning: comparison of constant 128 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare] if ((0x80 <= c) && (c <= 0xff)) ~~~~ ^ ~ fs/fat/fat_write.c:1024:25: warning: comparison of constant 255 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare] if ((0x80 <= c) && (c <= 0xff)) ~ ^ ~~~~ Fixes: 25bb9dab14f4 ("fs: fat: check and normalize file name") Signed-off-by: Tom Rini <trini@konsulko.com> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-10-06fs: fat: fix set_cluster()Heinrich Schuchardt
Avoid CoverityScan warning SIGN_EXTENSION by changing the type of parameter size of set_cluster(). Avoid leaking stack content when writing an incomplete last sector. Reported-by: Coverity (CID: 184096) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2018-10-06fs: fat: memory leak in fat_unlink()Heinrich Schuchardt
Do not leak filename_copy in case of error. Catch out of memory when calling strdup. Reported-by: Coverity (CID: 184086) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2018-09-23fs: fat: unaligned buffers are not an errorHeinrich Schuchardt
The FAT driver supports unaligned reads and writes and EFI applications will make use of these. So a misaligned buffer is only worth a debug message. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: support unlinkAKASHI Takahiro
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: fat: support mkdirAKASHI Takahiro
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: fat: remember the starting cluster number of directoryAKASHI Takahiro
The starting cluster number of directory is needed to initialize ".." (parent directory) entry when creating a new directory. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: support write with non-zero offsetAKASHI Takahiro
In this patch, all the necessary code for allowing for a file offset at write is implemented. What plays a major roll here is get_set_cluster(), which, in contrast to its counterpart, set_cluster(), only operates on already-allocated clusters, overwriting with data. So, with a file offset specified, set_contents() seeks and writes data with set_get_cluster() until the end of a file, and, once it reaches there, continues writing with set_cluster() for the rest. Please note that a file will be trimmed as a result of write operation if write ends before reaching file's end. This is an intended behavior in order to maintain compatibility with the current interface. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: refactor write interface for a file offsetAKASHI Takahiro
The current write implementation is quite simple: remove existing clusters and then allocating new ones and filling them with data. This, inevitably, enforces always writing from the beginning of a file. As the first step to lift this restriction, fat_file_write() and set_contents() are modified to accept an additional parameter, file offset and further re-factored so that, in the next patch, all the necessary code will be put into set_contents(). Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: support write with sub-directory pathAKASHI Takahiro
In this patch, write implementation is overhauled and rewritten by making full use of directory iterator. The obvious bonus is that we are now able to write to a file with a directory path, like /A/B/C/FILE. Please note that, as there is no notion of "current directory" on u-boot, a file name specified must contain an absolute directory path. Otherwise, "/" (root directory) is assumed. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: write returns error code instead of -1AKASHI Takahiro
It would be good that FAT write function return error code instead of just returning -1 as fat_read_file() does. This patch attempts to address this issue although it is 'best effort (or estimate)' for now. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: check and normalize file nameAKASHI Takahiro
FAT file system's long file name support is a bit complicated and has some restrictions on its naming. We should be careful about it especially for write as it may easily end up with wrong file system. normalize_longname() check for the rules and normalize a file name if necessary. Please note, however, that this function is yet to be extended to fully comply with the standard. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23Revert "fs: fat: cannot write to subdirectories"AKASHI Takahiro
This reverts commit 0dc1bfb7302d220a48364263d5632d6d572b069b. The succeeding patch series will supersede it. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: assure iterator's ->dent belongs to ->clustAKASHI Takahiro
In my attempt to re-work write operation, it was revealed that iterator's "clust" does not always point to a cluster to which a current directory entry ("dent") belongs. This patch assures that it is always true by adding "next_clust" which is used solely for dereferencing a cluster chain. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve()AKASHI Takahiro
FAT's root directory does not have "." nor ".." So care must be taken when scanning root directory with fat_itr_resolve(). Without this patch, any file path starting with "." or ".." will not be resolved at all. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23fs: fat: extend get_fs_info() for write useAKASHI Takahiro
get_fs_info() was introduced in major re-work of read operation by Rob. We want to reuse this function in write operation by extending it with additional members in fsdata structure. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-08-20fs/fat: debug-print file read position during file_fat_read_at()Andreas Dannenberg
In order to make the debug print in file_fat_read_at() a tad more useful, show the offset the file is being read at alongside the filename. Suggested-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2018-07-25fs: fat: cannot write to subdirectoriesHeinrich Schuchardt
fs_fat_write() is not able to write to subdirectories. Currently if a filepath with a leading slash is passed, the slash is treated as part of the filename to be created in the root directory. Strip leading (back-)slashes. Check that the remaining filename does not contain any illegal characters (<>:"/\|?*). This way we will throw an error when trying to write to a subdirectory. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini
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-22fs: fat: Drop CONFIG_SUPPORT_VFATTuomas Tynkkynen
fat.h unconditionally defines CONFIG_SUPPORT_VFAT (and has done since 2003), so as a result VFAT support is always enabled regardless of whether a board config defines it or not. Drop this unnecessary option. Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
2018-01-22fs: FAT: Fix typo in FS_FAT_MAX_CLUSTSIZE descriptionTuomas Tynkkynen
Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
2018-01-19fs/fat: remove distractive message in file_fat_read_at()Heinrich Schuchardt
The message "reading %s\n" may be interesting when debugging but otherwise it is superfluous. Only output the message when debugging. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-01-10fat write: Fixed a problem with the case of file names when writing filesJean-Jacques Hiblot
commit 21a24c3bf35b ("fs/fat: fix case for FAT shortnames") made it possible that get_name() returns file names with some upper cases. find_directory_entry() must be updated to take this account, and use case-insensitive functions to compare file names. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
2017-11-29fat: Use cache aligned buffers for fat_opendirNeil Armstrong
Before this patch one could receive following errors when executing "fatls" command on machine with cache enabled (ex i.MX6Q) : => fatls mmc 0:1 CACHE: Misaligned operation at range [4f59dfc8, 4f59e7c8] CACHE: Misaligned operation at range [4f59dfc8, 4f59e7c8] ERROR: v7_outer_cache_inval_range - start address is not aligned - 0x4f59dfc8 ERROR: v7_outer_cache_inval_range - stop address is not aligned - 0x4f59e7c8 CACHE: Misaligned operation at range [4f59dfc8, 4f59e7c8] CACHE: Misaligned operation at range [4f59dfc8, 4f59e7c8] ERROR: v7_outer_cache_inval_range - start address is not aligned - 0x4f59dfc8 ERROR: v7_outer_cache_inval_range - stop address is not aligned - 0x4f59e7c8 To alleviate this problem - the calloc()s have been replaced with malloc_cache_aligned() and memset(). After those changes the buffers are properly aligned (with both start address and size) to SoC cache line. Fixes: 09fa964bba80 ("fs/fat: Fix 'CACHE: Misaligned operation at range' warnings") Suggested-by: Lukasz Majewski <lukma@denx.de> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> Reviewed-by: Lukasz Majewski <lukma@denx.de> Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>
2017-10-08fs/fat: Check malloc return values and fix memory leaksTuomas Tynkkynen
Check malloc() return values and properly unwind on errors so memory allocated for fat_itr structures get freed properly. Also fixes a leak of fsdata.fatbuf in fat_size(). Fixes: 2460098cffacd1 ("fs/fat: Reduce stack usage") Reported-by: Coverity (CID: 167225, 167233, 167234) Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi> Reviewed-by: Tom Rini <trini@konsulko.com>
2017-10-08fs/fat: Fix 'CACHE: Misaligned operation at range' warningsTuomas Tynkkynen
The 'block' field of fat_itr needs to be properly aligned for DMA and while it does have '__aligned(ARCH_DMA_MINALIGN)', the fat_itr structure itself needs to be properly aligned as well. While at it use malloc_cache_aligned() for the other aligned allocations in the file as well. Fixes: 2460098cffacd1 ("fs/fat: Reduce stack usage") Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi> Reviewed-by: Tom Rini <trini@konsulko.com>
2017-10-06fs/fat: Fix pathnames using '..' that lead to the root directoryTuomas Tynkkynen
If we end up back in the root directory via a '..' directory entry, set itr->is_root accordingly. Failing to do that gives spews like "Invalid FAT entry" and being unable to access directory entries located past the first cluster of the root directory. Fixes: 8eafae209c35 ("fat/fs: convert to directory iterators") Reviewed-by: Tom Rini <trini@konsulko.com> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
2017-09-22fs/fat: Reduce stack usageTom Rini
We have limited stack in SPL builds. Drop itrblock and move to malloc/free of itr to move this off of the stack. As part of this fix a double-free issue in fat_size(). Signed-off-by: Tom Rini <trini@konsulko.com> --- Rework to use malloc/free as moving this to a global overflows some SH targets.
2017-09-15fs/fat: fix fatbuf leakRob Clark
A new fatbuf was allocated by get_fs_info() (called by fat_itr_root()), but not freed, resulting in eventually running out of memory. Spotted by running 'ls -r' in a large FAT filesystem from Shell.efi. fatbuf is mainly used to cache FAT entry lookups (get_fatent()).. possibly once fat_write.c it can move into the iterator to simplify this. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Łukasz Majewski <lukma@denx.de>
2017-09-15fs/fat: Clean up open-coded sector <-> cluster conversionsRob Clark
Use the clust_to_sect() helper that was introduced earlier, and add an inverse sect_to_clust(), plus update the various spots that open-coded this conversion previously. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15fs/fat: fix case for FAT shortnamesRob Clark
Noticed when comparing our output to linux. There are some lcase bits which control whether filename and/or extension should be downcase'd. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15fat/fs: move ls to generic implementationRob Clark
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>
2017-09-15fat/fs: remove a bunch of dead codeRob Clark
Spotted by chance, when trying to remove file_fat_ls(), I noticed there were some dead users of the API. Signed-off-by: Rob Clark <robdclark@gmail.com> Acked-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15fs/fat: implement opendir/readdir/closedirRob Clark
Implement the readdir interface using the directory iterators. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15fat/fs: convert to directory iteratorsRob Clark
And drop a whole lot of ugly code! Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15fs/fat: introduce new director iteratorsRob Clark
Untangle directory traversal into a simple iterator, to replace the existing multi-purpose do_fat_read_at() + get_dentfromdir(). Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de>
2017-09-15fs/fat: split out helper to init fsdataRob Clark
Want to re-use this in fat dirent iterator in next patch. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-08-26fs: fat: fix fatwrite overflow calculationReno Farnesi
The overflow calculation was incorrect. Adding the start block of the partition is not needed because the sectors are already relative to the beginning of the partition. If you attempted to write a file smaller than cur_part_info.start blocks on a full partition the old calculation fails to catch the overflow. This would cause an infinite loop in the determine_fatent function. Old, incorrect calculation: ending sector of new file = start sector + file size (in sectors) last sector = partition start + total sectors on the partition Adding the partition start block number is not needed because sectors are already relative to the start of the partition. New calculation: ending sector of new file = start sector + file size (in sectors) last sector = total sectors on the partition Signed-off-by: Reno Farnesi <nfarnesi4@gmail.com>
2017-08-20fs/fat: Correct blk_dread() return value checkTom Rini
The function blk_dread will return -ENOSYS on failure or on success the number of blocks read, which must be the number asked to read (otherwise it failed somewhere). Correct this check. Signed-off-by: Tom Rini <trini@konsulko.com>
2017-07-11Kconfig: Add CONFIG_SATA to enable SATASimon Glass
At present CONFIG_CMD_SATA enables the 'sata' command which also brings in SATA support. Some boards may wish to enable SATA without the command. Add a separate CONFIG to permit this. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2017-06-03fs: fat: add kbuild configuration supportSekhar Nori
Add Kconfig symbols for various configurations supported by FAT filesystem support code. CONFIG_SUPPORT_VFAT has been left out since its force enabled in include/fat.h and probably should get removed at some point. Signed-off-by: Sekhar Nori <nsekhar@ti.com> [trini: add select FS_FAT for CMD_FAT and SPL_FAT_SUPPORT] Signed-off-by: Tom Rini <trini@konsulko.com>
2017-05-22Kconfig: Add a CONFIG_IDE optionSimon Glass
At present IDE support is controlled by CONFIG_CMD_IDE. Add a separate CONFIG_IDE option so that IDE support can be enabled without requiring the 'ide' command. Update existing users and move the ide driver into drivers/block since it should not be in common/. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-01-28fs/fat: Fix unaligned __u16 reads for FAT12 accessStefan Brüns
Doing unaligned reads is not supported on all architectures, use byte sized reads of the little endian buffer. Rename off16 to off8, as it reflects the buffer offset in byte granularity (offset is in entry, i.e. 12 bit, granularity). Fix a regression introduced in 8d48c92b45aea91e2a2be90f2ed93677e85526f1 Reported-by: Oleksandr Tymoshenko <gonzo@bluezbox.com> Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Tested-by: Oleksandr Tymoshenko <gonzo@bluezbox.com>
2017-01-28cmd, disk: convert CONFIG_PARTITION_UUIDS, CMD_PART and CMD_GPTPatrick Delaunay
We convert CONFIG_PARTITION_UUIDS to Kconfig first. But in order to cleanly update all of the config files we must also update CMD_PART and CMD_GPT to also be in Kconfig in order to avoid complex logic elsewhere to update all of the config files. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com> Signed-off-by: Tom Rini <trini@konsulko.com>
2016-12-27fs/fat: simplify get_fatent for FAT12Stefan Brüns
Instead of shuffling bits from two adjacent 16 bit words, use one 16 bit word with the appropriate byte offset in the buffer. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-12-27fs/fat: merge readwrite get_fatent_value() with readonly get_fatent()Stefan Brüns
get_fatent_value(...) flushes changed FAT entries to disk when fetching the next FAT blocks, in every other aspect it is identical to get_fatent(...). Provide a stub implementation for flush_dirty_fat_buffer if CONFIG_FAT_WRITE is not set. Calling flush_dirty_fat_buffer during read only operation is fine as it checks if any buffers needs flushing. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>