summaryrefslogtreecommitdiff
path: root/fs
AgeCommit message (Collapse)Author
2017-04-30fs: Kconfig: Add a separate option for FS_CRAMFSSimon Glass
Rather than using CMD_CRAMFS for both the filesystem and its command, we should have a separate option for each. This allows us to enable CRAMFS support without the command, if desired, which reduces U-Boot's size slightly. Signed-off-by: Simon Glass <sjg@chromium.org> [trini: imply FS_CRAMFS for keymile] Signed-off-by: Tom Rini <trini@konsulko.com>
2017-04-30fs: Kconfig: Add a separate config for FS_CBFSSimon Glass
Rather than using CMD_CBFS for both the filesystem and its command, we should have a separate option for each. This allows us to enable CBFS support without the command, if desired, which reduces U-Boot's size slightly. Signed-off-by: Simon Glass <sjg@chromium.org> [trini: imply FS_CBFS on SYS_COREBOOT] Signed-off-by: Tom Rini <trini@konsulko.com>
2017-04-27ext4: Fix comparision of unsigned expression with < 0Lokesh Vutla
In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below lbaint_t blknr; blknr = read_allocated_block(&(node->inode), i); if (blknr < 0) return -1; blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int. Similarly ext4/dev.c does a similar comparison. Drop the redundant comparison. Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2017-04-18yaffs2: remove redundant conditionxypron.glpk@gmx.de
If !parent, the changed line is not reached. So there is no need to check the value again. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com>
2017-04-18cramfs: basic symlink supportTyler Hall
Handle symlinks to files in the current directory. Other cases could be handled with additional code, but this is a start. Add explicit errors for absolute paths and links found in the middle of a path (directories). Other cases like '..' or '.' will result with the file not being found as when those path components are explicitly provided. Add a helper to decompress a null-terminated link name which is shared with cramfs_list_inode. Signed-off-by: Tyler Hall <tylerwhall@gmail.com>
2017-04-18cramfs: block pointers are 32 bitsTyler Hall
Using a variably-sized type is incorrect here since we're reading a fixed file format. Fixes cramfs on 64-bit platforms. Signed-off-by: Tyler Hall <tylerwhall@gmail.com>
2017-02-12flash: complete CONFIG_SYS_NO_FLASH move with renamingMasahiro Yamada
We repeated partial moves for CONFIG_SYS_NO_FLASH, but this is not completed. Finish this work by the tool. During this move, let's rename it to CONFIG_MTD_NOR_FLASH. Actually, we have more instances of "#ifndef CONFIG_SYS_NO_FLASH" than those of "#ifdef CONFIG_SYS_NO_FLASH". Flipping the logic will make the code more readable. Besides, negative meaning symbols do not fit in obj-$(CONFIG_...) style Makefiles. This commit was created as follows: [1] Edit "default n" to "default y" in the config entry in common/Kconfig. [2] Run "tools/moveconfig.py -y -r HEAD SYS_NO_FLASH" [3] Rename the instances in defconfigs by the following: find . -path './configs/*_defconfig' | xargs sed -i \ -e '/CONFIG_SYS_NO_FLASH=y/d' \ -e 's/# CONFIG_SYS_NO_FLASH is not set/CONFIG_MTD_NOR_FLASH=y/' [4] Change the conditionals by the following: find . -name '*.[ch]' | xargs sed -i \ -e 's/ifndef CONFIG_SYS_NO_FLASH/ifdef CONFIG_MTD_NOR_FLASH/' \ -e 's/ifdef CONFIG_SYS_NO_FLASH/ifndef CONFIG_MTD_NOR_FLASH/' \ -e 's/!defined(CONFIG_SYS_NO_FLASH)/defined(CONFIG_MTD_NOR_FLASH)/' \ -e 's/defined(CONFIG_SYS_NO_FLASH)/!defined(CONFIG_MTD_NOR_FLASH)/' [5] Modify the following manually - Rename the rest of instances - Remove the description from README - Create the new Kconfig entry in drivers/mtd/Kconfig - Remove the old Kconfig entry from common/Kconfig - Remove the garbage comments from include/configs/*.h Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
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/ext4: Initialize group descriptor size for revision level 0 filesystemsStefan Brüns
genext2fs creates revision level 0 filesystems, which are not readable by u-boot due to the initialized group descriptor size field. f798b1dda1c5de818b806189e523d1b75db7e72d Reported-by: Kever Yang <kever.yang@rock-chips.com> Reported-by: FrostyBytes@protonmail.com Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Tested-by: Kever Yang <kever.yang@rock-chips.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>
2016-12-27fs/fat: Avoid corruption of sectors following the FATStefan Brüns
The FAT is read/flushed in segments of 6 (FATBUFBLOCKS) disk sectors. The last segment may be less than 6 sectors, cap the length. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2016-12-27fat: fatwrite: fix the command for FAT12Philipp Skadorov
The u-boot command fatwrite empties FAT clusters from the beginning till the end of the file. Specifically for FAT12 it fails to detect the end of the file and goes beyond the file bounds thus corrupting the file system. Additionally, FAT entry chaining-up into a file is not implemented for FAT12. The users normally workaround this by re-formatting the partition as FAT16/FAT32, like here: https://github.com/FEDEVEL/openrex-uboot-v2015.10/issues/1 The patch fixes the bounds of a file and FAT12 entries chaining into a file, including EOF markup. Signed-off-by: Philipp Skadorov <philipp.skadorov@savoirfairelinux.com>
2016-12-02sandboxfs: Fix resource leakTom Rini
Now that we free resources in sandbox_fs_ls Coverity is letting us know that in some cases we might leak. So in case of error we should still let os_dirent_free free anything that was allocated. Fixes: 86167089b71c ("sandbox/fs: Free memory allocated by os_dirent_ls") Reported-by: Coverity (CID: 153450) Cc: Stefan Brüns <stefan.bruens@rwth-aachen.de> Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-11-29fs/fat/fatwrite: Local variable as buffer to store dir_slot entriesTien Fong Chee
fill_dir_slot use get_contents_vfatname_block as a temporary buffer for constructing a list of dir_slot entries. To save the memory and providing correct type of memory for above usage, a local buffer with accurate size declaration is introduced. The local array size 640 is used because for long file name entry, each entry use 32 bytes, one entry can store up to 13 characters. The maximum number of entry possible is 20. So, total size is 32*20=640bytes. Signed-off-by: Genevieve Chan <ccheauya@altera.com> Signed-off-by: Tien Fong Chee <tfchee@altera.com>
2016-11-21ext4: Allow reading files with non-zero offset, clamp read lenStefan Brüns
Support was already implemented, but not hooked up. This fixes several fails in the test cases. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Stephen Warren <swarren@wwwdotorg.org>
2016-11-21ext4: Fix handling of sparse filesStefan Brüns
A sparse file may have regions not mapped by any extents, at the start or at the end of the file, or anywhere between, thus not finding a matching extent region is never an error. Found by python filesystem tests. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-10-31Fix spelling of "multiple".Vagrant Cascadian
Signed-off-by: Vagrant Cascadian <vagrant@debian.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-10-24ext4: Only write journal entries for modified blocks in unlink_filenameStefan Brüns
Instead of creating a journal entry for each directory block, even if the block is unmodified, only log the modified block. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-10-24ext4: Fix handling of direntlen in unlink_filenameStefan Brüns
The direntlen checks were quite bogus, i.e. the loop termination used "len + offset == blocksize" (exact match only), and checked for a direntlen less than 0. The latter can never happen as the len is unsigned, this has been reported by Coverity, CID 153384. Use the same code as in search_dir for directory traversal. This code has the correct checks for direntlen >= sizeof(struct dirent), and offset < blocksize. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reported-by: Coverity (CID: 153383, 153384) Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-10-24ext4: cleanup unlink_filename functionStefan Brüns
Use the same variable names as in search_dir, to make purpose of variables more obvious. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-10-11sandbox/fs: Free memory allocated by os_dirent_lsStefan Brüns
Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Simon Glass <sjg@chromium.org>
2016-09-23treewide: replace #include <asm/errno.h> with <linux/errno.h>Masahiro Yamada
Now, arch/${ARCH}/include/asm/errno.h and include/linux/errno.h have the same content. (both just wrap <asm-generic/errno.h>) Replace all include directives for <asm/errno.h> with <linux/errno.h>. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> [trini: Fixup include/clk.] Signed-off-by: Tom Rini <trini@konsulko.com>
2016-09-23treewide: use #include <...> to include public headersMasahiro Yamada
We are supposed to use #include <...> to include headers in the public include paths. We should use #include "..." only for headers in local directories. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-09-23ext4: Revert rejection of 64bit enabled ext4 fsStefan Brüns
Enable mounting of ext4 fs with 64bit feature, as it is supported now. These had been disabled in 6f94ab6656ceffb3f2a972c8de4c554502b6f2b7. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Respect group descriptor size when adjusting free countsStefan Brüns
Also adjust high 16/32 bits when free inode/block counts are modified. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Use helper function to access group descriptor and its fieldsStefan Brüns
The descriptor size is variable, thus array indices are not generically applicable. The larger group descriptors also contain e.g. high parts of block numbers, which have to be read and written. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Use correct descriptor size when reading the block group descriptorStefan Brüns
The correct descriptor size must be used when calculating offsets, and also to read the correct amount of data. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Add helper functions for block group descriptor field accessStefan Brüns
The helper functions encapsulate access of the block group descriptors, independent of group descriptor size. The helpers also deal with the endianess of the fields, and with split fields like free_blocks/ free_blocks_high. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: determine group descriptor size for 64bit featureStefan Brüns
If EXT4_FEATURE_INCOMPAT_64BIT is set, the descriptor can be read from the superblocks, otherwise it defaults to 32. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Fix memory leak of journal buffer if block is updated multiple timesStefan Brüns
If the same block is updated multiple times in a row during a single file system operation, gd_index is decremented to use the same journal entry again. Avoid loosing the already allocated buffer. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: Correct block number handling, empty block vs. error codeStefan Brüns
read_allocated block may return block number 0, which is just an indicator a chunk of the file is not backed by a block, i.e. it is sparse. During file deletions, just continue with the next logical block, for other operations treat blocknumber <= 0 as an error. For writes, blocknumber 0 should never happen, as U-Boot always allocates blocks for the whole file. Reading already handles this correctly, i.e. the read buffer is 0-fillled. Not treating block 0 as sparse block leads to FS corruption, e.g. ./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ; ext4write host 0 0 /2.5GB.file 1 ' The 2.5GB.file from the fs test is actually a sparse file. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: remove duplicated block release code for extentsStefan Brüns
The data blocks are identical for files using traditional direct/indirect block allocation scheme and extent trees, thus this code part can be common. Only the code to deallocate the indirect blocks to record the used blocks has to be seperate, respectively the code to release extent tree index blocks. Actually the code to release the extent tree index blocks is still missing, but at least add a FIXME at the appropriate place. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2016-09-23ext4: initialize full inode for inodes bigger than 128 bytesStefan Brüns
Make sure the the extra_isize field (offset 128) is initialized to 0, to mark any extra data as invalid. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Use correct value for inode size even on revision 0 filesystemsStefan Brüns
fs->inodesz is already correctly (i.e. dependent on fs revision) initialized in ext4fs_mount. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Fix memory leak in case of failureStefan Brüns
temp_ptr should always be freed, even if the function is left via goto fail. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Avoid out-of-bounds access of block bitmapStefan Brüns
If the blocksize is 1024, count is initialized with 1. Incrementing count by 8 will never match (count == fs->blksz * 8), and ptr may be incremented beyond the buffer end if the bitmap is filled. Add the startblock offset after the loop. Remove the second loop, as only the first iteration will be done. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: After completely filled group, scan next group from the beginningStefan Brüns
The last free block of a block group may be in its middle. After it has been allocated, the next block group should be scanned from its beginning. The following command triggers the bad behaviour (on a blocksize 1024 fs): ./sandbox/u-boot -c 'i=0; host bind 0 ./disk.raw ; while test $i -lt 260 ; do echo $i; setexpr i $i + 1; ext4write host 0:2 0 /X${i} 0x1450; done ; ext4write host 0:2 0 /X240 0x2000 ; ' When 'X240' is extended from 5200 byte to 8192 byte, the new blocks should start from the first free block (8811), but it uses the blocks 8098-8103 and 16296-16297 -- 8103 + 1 + 8192 = 16296. This can be shown with debugfs, commands 'ffb' and 'stat X240'. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Do not clear zalloc'ed buffers a second timeStefan Brüns
zero_buffer is never written, thus clearing it is pointless. journal_buffer is completely initialized by ext4fs_devread (or in case of failure, not used). Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Only update number of of unused inodes if GDT_CSUM feature is setStefan Brüns
e2fsck warns about "Group descriptor 0 marked uninitialized without feature set." The bg_itable_unused field is only defined if FEATURE_RO_COMPAT_GDT_CSUM is set, and should be set (kept) zero otherwise. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Scan all directory blocks when looking up an entryStefan Brüns
Scanning only the direct blocks of the directory file may falsely report an existing file as nonexisting, and worse can also lead to creation of a duplicate entry on file creation. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Avoid corruption of directories with hash tree indexesStefan Brüns
While directories can be read using the old linear scan method, adding a new file would require updating the index tree (alternatively, the whole tree could be removed). Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Scan all directory blocks for space when inserting a new entryStefan Brüns
Previously, only the last directory block was scanned for available space. Instead, scan all blocks back to front, and if no sufficient space is found, eventually append a new block. Blocks are only appended if the directory does not use extents or the new block would require insertion of indirect blocks, as the old code does. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: Do not crash when trying to grow a directory using extentsStefan Brüns
The following command crashes u-boot: ./sandbox/u-boot -c 'i=0; host bind 0 ./sandbox/test/fs/3GB.ext4.img ; while test $i -lt 200 ; do echo $i; setexpr i $i + 1; ext4write host 0 0 /foobar${i} 0; done' Previously, the code updated the direct_block even for extents, and fortunately crashed before pushing garbage to the disk. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: propagate error if creation of directory entry failsStefan Brüns
In case the dir entry creation failed, ext4fs_write would later overwrite a random inode, as inodeno was never initialized. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: fix possible crash on directory traversal, ignore deleted entriesStefan Brüns
The following command triggers a segfault in search_dir: ./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ; ext4write host 0 0 /./foo 0x10' The following command triggers a segfault in check_filename: ./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ; ext4write host 0 0 /. 0x10' "." is the first entry in the directory, thus previous_dir is NULL. The whole previous_dir block in search_dir seems to be a bad copy from check_filename(...). As the changed data is not written to disk, the statement is mostly harmless, save the possible NULL-ptr reference. Typically a file is unlinked by extending the direntlen of the previous entry. If the entry is the first entry in the directory block, it is invalidated by setting inode=0. The inode==0 case is hard to trigger without crafted filesystems. It only hits if the first entry in a directory block is deleted and later a lookup for the entry (by name) is done. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2016-09-23ext4: fix wrong usage of le32_to_cpu()Michael Walle
le32_to_cpu() must only convert the revision_level and not the boolean result. Signed-off-by: Michael Walle <michael@walle.cc>
2016-09-23ext4: fix endianess problems in ext4 write supportMichael Walle
All fields were accessed directly instead of using the proper byte swap functions. Thus, ext4 write support was only usable on little-endian architectures. Fix this. Signed-off-by: Michael Walle <michael@walle.cc>
2016-09-23ext4: use kernel names for byte swapsMichael Walle
Instead of __{be,le}{16,32}_to_cpu use {be,le}{16,32}_to_cpu. Signed-off-by: Michael Walle <michael@walle.cc>