summaryrefslogtreecommitdiff
path: root/fs/btrfs
AgeCommit message (Collapse)AuthorFilesLines
2020-05-19common: Drop log.h from common headerSimon Glass4-0/+4
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-19common: Drop part.h from common headerSimon Glass2-1/+4
Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-19part: Drop disk_partition_t typedefSimon Glass3-3/+4
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>
2020-05-18common: Drop uuid.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-04-20fs: btrfs: support sparse extentsMarek Behún1-0/+6
When logical address of a regular extent is 0, the extent is sparse and consists of all zeros. Without this when sparse extents are used in a file reading fails with Cannot map logical address 0 to physical Signed-off-by: Marek Behún <marek.behun@nic.cz>
2020-04-17fs: btrfs: Fix LZO false decompression error caused by pending zeroQu Wenruo1-1/+19
For certain btrfs files with compressed file extent, uboot will fail to load it: btrfs_read_extent_reg: disk_bytenr=14229504 disk_len=73728 offset=0 nr_bytes=131 072 decompress_lzo: tot_len=70770 decompress_lzo: in_len=1389 decompress_lzo: in_len=2400 decompress_lzo: in_len=3002 decompress_lzo: in_len=1379 decompress_lzo: in_len=88539136 decompress_lzo: header error, in_len=88539136 clen=65534 tot_len=62580 NOTE: except the last line, all other lines are debug output. Btrfs lzo compression uses its own format to record compressed size (segment header, LE32). However to make decompression easier, we never put such segment header across page boundary. In above case, the xxd dump of the lzo compressed data looks like this: 00001fe0: 4cdc 02fc 0bfd 02c0 dc02 0d13 0100 0001 L............... 00001ff0: 0000 0008 0300 0000 0000 0011 0000|0000 ................ 00002000: 4705 0000 0001 cc02 0000 0000 0000 1e01 G............... '|' is the "expected" segment header start position. But in that page, there are only 2 bytes left, can't contain the 4 bytes segment header. So btrfs compression will skip that 2 bytes, put the segment header in next page directly. Uboot doesn't have such check, and read the header with 2 bytes offset, result 0x05470000 (88539136), other than the expected result 0x00000547 (1351), resulting above error. Follow the btrfs-progs restore implementation, by introducing tot_in to record total processed bytes (including headers), and do proper page boundary skip to fix it. Please note that, current code base doesn't parse fs_info thus we can't grab sector size easily, so it uses PAGE_SIZE, and relying on fs open time check to exclude unsupported sector size. Signed-off-by: Qu Wenruo <wqu@suse.com> Cc: Marek Behun <marek.behun@nic.cz> Reviewed-by: Marek Behún <marek.behun@nic.cz>
2020-04-17fs: btrfs: Reject fs with sector size other than PAGE_SIZEQu Wenruo1-0/+8
Although in theory u-boot fs driver could easily support more sector sizes, current code base doesn't have good enough way to grab sector size yet. This would cause problem for later LZO fixes which rely on sector size. And considering that most u-boot boards are using 4K page size, which is also the most common sector size for btrfs, rejecting fs with non-page-sized sector size shouldn't cause much problem. This should only be a quick fix before we implement better sector size support. Signed-off-by: Qu Wenruo <wqu@suse.com> Cc: Marek Behun <marek.behun@nic.cz> Reviewed-by: Marek Behún <marek.behun@nic.cz>
2020-04-17fs: btrfs: Use LZO_LEN to replace immediate numberQu Wenruo1-10/+12
Just a cleanup. These immediate numbers make my eyes hurt. Signed-off-by: Qu Wenruo <wqu@suse.com> Cc: Marek Behun <marek.behun@nic.cz> Reviewed-by: Marek Behún <marek.behun@nic.cz>
2019-05-05fs: btrfs: add zstd decompression supportMarek Behún3-2/+63
This adds decompression support for Zstandard, which has been included in Linux btrfs driver for some time. Signed-off-by: Marek Behún <marek.behun@nic.cz>
2019-05-03fs: btrfs: fix btrfs methods return values on failureMarek Behún1-8/+8
The btrfs implementation methods .ls(), .size() and .read() returns 1 on failure, but the command handlers expect values <0 on failure. For example if given a nonexistent path, the load command currently returns success, and hush scripting does not work. Fix this by setting return values of these methods to -1 instead of 1 on failure. Signed-off-by: Marek Behún <marek.behun@nic.cz>
2019-05-03fs: btrfs: Do not print mount fail message when not btrfs filesystemMarek Behún1-6/+5
Other filesystem drivers don't do this. Signed-off-by: Marek Behún <marek.behun@nic.cz>
2019-04-27Revert "fs: btrfs: fix false negatives in ROOT_ITEM search"Tom Rini1-38/+6
Per Pierre this change shouldn't have been applied as it was superseded by "fs: btrfs: fix btrfs_search_tree invalid results" which is also applied now as 1627e5e5985d. This reverts commit 633967f9818cb6a0e87ffa8cba33148a5bcc6edb. Signed-off-by: Tom Rini <trini@konsulko.com>
2019-04-27fs: btrfs: fix btrfs_search_tree invalid resultsPierre Bourdon1-2/+12
btrfs_search_tree should return the first item in the tree that is greater or equal to the searched item. The search algorithm did not properly handle the edge case where the searched item is higher than the last item of the node but lower than the first item of the next node. Instead of properly returning the first item of the next node, it was returning an invalid path pointer (pointing to a non-existent item after the last item of the node + 1). This fixes two issues in the btrfs driver: - Looking for a ROOT_ITEM could fail if it was the first item of its leaf node. - Iterating through DIR_INDEX entries (for readdir) could fail if the first DIR_INDEX entry was the first item of a leaf node. Signed-off-by: Pierre Bourdon <delroth@gmail.com> Cc: Marek Behun <marek.behun@nic.cz>
2019-04-27fs: btrfs: fix false negatives in ROOT_ITEM searchPierre Bourdon1-6/+38
ROOT_ITEMs in btrfs are referenced without knowing their actual "offset" value. To perform these searches using only two items from the key, the btrfs driver uses a special "btrfs_search_tree_key_type" function. The algorithm used by that function to transform a 3-tuple search into a 2-tuple search was subtly broken, leading to items not being found if they were the first in their tree node. This commit fixes btrfs_search_tree_key_type to properly behave in these situations. Signed-off-by: Pierre Bourdon <delroth@gmail.com> Cc: Marek Behun <marek.behun@nic.cz>
2018-10-08fs: btrfs: Fix tree traversal with btrfs_next_slot()Yevgeny Popovych1-1/+1
When traversing slots in a btree (via btrfs_path) with btrfs_next_slot(), we didn't correctly identify that the last slot in the leaf was reached and we should jump to the next leaf. This could lead to any kind of runtime errors or corruptions, like: * file data not being read at all, or is read partially * file is read but is corrupted * (any) metadata being corrupted or not read at all, etc The easiest way to reproduce this is to read a large enough file that its EXTENT_DATA items don't fit into a single leaf. Signed-off-by: Yevgeny Popovych <yevgenyp@pointgrab.com> Cc: Marek Behun <marek.behun@nic.cz> Tested-by: Marek Behún <marek.behun@nic.cz>
2018-09-30fs: btrfs: Fix cache alignment bugsMarek Vasut3-13/+17
The btrfs implementation passes cache-unaligned buffers into the block layer, which triggers cache alignment problems down in the block device drivers. Align the buffers to prevent this. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Marek Behun <marek.behun@nic.cz>
2018-07-20fs: btrfs: Fix wrong comparison in logical to physical mappingMarek Behún1-1/+1
The comparison logical > item->logical + item->length in btrfs_map_logical_to_physical is wrong and should be instead logical >= item->logical + item->length For example, if item->logical = 4096 item->length = 4096 and we are looking for logical = 8192, it is not part of item (item is [4096, 8191]). But the comparison is false and we think we have found the correct item, although we should be searing in the right subtree. This fixes some bugs I encountered. Signed-off-by: Marek Behun <marek.behun@nic.cz>
2018-06-18fs: btrfs: Do not fail when all root_backups are emptyYevgeny Popovych2-9/+22
This is the case when reading freshly created filesystem. The error message is like the following: btrfs_read_superblock: No valid root_backup found! Since the data from super_roots/root_backups is not actually used - decided to rework btrfs_newest_root_backup() into btrfs_check_super_roots() that will only check if super_roots array is valid and correctly handle empty scenario. As a result: * btrfs_read_superblock() now only checks if super_roots array is valid; the case when it is empty is considered OK. * removed root_backup pointer from btrfs_info, which would be NULL in case of empty super_roots. * btrfs_read_superblock() verifies number of devices from the superblock itself, not newest root_backup. Signed-off-by: Yevgeny Popovych <yevgenyp@pointgrab.com> Cc: Marek Behun <marek.behun@nic.cz> Cc: Sergey Struzh <sergeys@pointgrab.com>
2018-06-13fs: btrfs: Fix not all CHUNK_ITEMs being read from CHUNK_TREEYevgeny Popovych1-1/+1
This causes errors when translating logical addresses to physical: btrfs_map_logical_to_physical: Cannot map logical address <addr> to physical btrfs_file_read: Error reading extent The behavior of btrfs_map_logical_to_physical() is to stop traversing CHUNK_TREE when it encounters first non-CHUNK_ITEM, which makes only some portion of CHUNK_ITEMs being read. Change it to skip over non-chunk items. Signed-off-by: Yevgeny Popovych <yevgenyp@pointgrab.com> Cc: Marek Behun <marek.behun@nic.cz> Cc: Sergey Struzh <sergeys@pointgrab.com> Reviewed-by: Marek Behun <marek.behun@nic.cz>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini17-35/+17
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-04-07fs: btrfs: Remove unused debug code left from developmentMarek Behún2-14/+0
Signed-off-by: Marek Behun <marek.behun@nic.cz>
2018-01-29fs: btrfs: Fix printf format character warningTom Rini1-2/+2
When printing a size_t value we need to use %zu for portability between 32bit and 64bit targets. Signed-off-by: Tom Rini <trini@konsulko.com> Reviewed-by: Marek Behun <marek.behun@nic.cz>
2018-01-28fs: btrfs: Fix unaligned memory accessesAlberto Sánchez Molero2-3/+5
Loading files stored with lzo compression from a btrfs filesystem was producing unaligned memory accesses, which were causing a data abort and a reset on an Orange Pi Zero. The change in hash.c is not triggered by any error but follows the same pattern. Please confirm. Fixed according to doc/README.unaligned-memory-access.txt Signed-off-by: Alberto Sánchez Molero <alsamolero@gmail.com> Tested-by: Robert Nelson <robertcnelson@gmail.com>
2017-10-16fs: btrfs: Remove a foreign language noteMarek Behún1-1/+0
I accidentaly left a foreign language note in the code from development. Signed-off-by: Marek Behun <marek.behun@nic.cz>
2017-10-16fs: btrfs: Fix usage of uninitialized variablesMarek Behún3-3/+3
The variable res should be initialized to 0 in these functions, because if the searched key is not found, the variable is used uninitialized. Reported-by: Coverity (CID: 167335) Reported-by: Coverity (CID: 167336) Reported-by: Coverity (CID: 167337) Signed-off-by: Marek Behun <marek.behun@nic.cz>
2017-10-03fs/btrfs: Fix warning in btrfs_check_super()Tom Rini1-1/+1
We specifically say that the last arg is u32, so use %lu. Signed-off-by: Tom Rini <trini@konsulko.com>
2017-10-03fs: btrfs: Add U-Boot fs handlers.Marek Behún3-0/+244
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-10-03fs: btrfs: Add single-device read-only BTRFS implementationMarek Behún12-0/+1841
This adds the proper implementation for the BTRFS filesystem. The implementation currently supports only read-only mode and the filesystem can be only on a single device. Checksums of data chunks is unimplemented. Compression is implemented (ZLIB + LZO). Signed-off-by: Marek Behun <marek.behun@nic.cz> create mode 100644 fs/btrfs/btrfs.h create mode 100644 fs/btrfs/chunk-map.c create mode 100644 fs/btrfs/compression.c create mode 100644 fs/btrfs/ctree.c create mode 100644 fs/btrfs/dev.c create mode 100644 fs/btrfs/dir-item.c create mode 100644 fs/btrfs/extent-io.c create mode 100644 fs/btrfs/hash.c create mode 100644 fs/btrfs/inode.c create mode 100644 fs/btrfs/root.c create mode 100644 fs/btrfs/subvolume.c create mode 100644 fs/btrfs/super.c
2017-10-03fs: btrfs: Add disk-to-cpu and cpu-to-disk conversion functionsMarek Behún1-0/+176
BTRFS on disk structures are stored in Little Endian. Add functions to convert this structures to cpu and to disk format. On Little Endian hosts, these functions do nothing. On Big Endian the CALL_MACRO_FROM_EACH from variadic-macro.h is used to define all the members for each structure on which cpu_to_le* or le*_to_cpu is to be called. Signed-off-by: Marek Behun <marek.behun@nic.cz> create mode 100644 fs/btrfs/conv-funcs.h
2017-10-03fs: btrfs: Add btrfs_tree.h and ctree.h from Linux (and modified)Marek Behún2-0/+1100
Add btrfs_tree.h and ctree.h from Linux which contains constants and structures for the BTRFS filesystem. Signed-off-by: Marek Behun <marek.behun@nic.cz> create mode 100644 fs/btrfs/btrfs_tree.h create mode 100644 fs/btrfs/ctree.h