diff options
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/Kconfig | 1 | ||||
-rw-r--r-- | fs/btrfs/btrfs.c | 16 | ||||
-rw-r--r-- | fs/btrfs/btrfs_tree.h | 5 | ||||
-rw-r--r-- | fs/btrfs/compression.c | 59 | ||||
-rw-r--r-- | fs/btrfs/super.c | 11 |
5 files changed, 76 insertions, 16 deletions
diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig index 22909d9fccc..f302b1fbef5 100644 --- a/fs/btrfs/Kconfig +++ b/fs/btrfs/Kconfig @@ -2,6 +2,7 @@ config FS_BTRFS bool "Enable BTRFS filesystem support" select CRC32C select LZO + select ZSTD select RBTREE help This provides a single-device read-only BTRFS support. BTRFS is a diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 6f35854823e..cb7e1827422 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -119,17 +119,17 @@ int btrfs_ls(const char *path) if (inr == -1ULL) { printf("Cannot lookup path %s\n", path); - return 1; + return -1; } if (type != BTRFS_FT_DIR) { printf("Not a directory: %s\n", path); - return 1; + return -1; } if (btrfs_readdir(&root, inr, readdir_callback)) { printf("An error occured while listing directory %s\n", path); - return 1; + return -1; } return 0; @@ -158,12 +158,12 @@ int btrfs_size(const char *file, loff_t *size) if (inr == -1ULL) { printf("Cannot lookup file %s\n", file); - return 1; + return -1; } if (type != BTRFS_FT_REG_FILE) { printf("Not a regular file: %s\n", file); - return 1; + return -1; } *size = inode.size; @@ -183,12 +183,12 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, if (inr == -1ULL) { printf("Cannot lookup file %s\n", file); - return 1; + return -1; } if (type != BTRFS_FT_REG_FILE) { printf("Not a regular file: %s\n", file); - return 1; + return -1; } if (!len) @@ -200,7 +200,7 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, rd = btrfs_file_read(&root, inr, offset, len, buf); if (rd == -1ULL) { printf("An error occured while reading file %s\n", file); - return 1; + return -1; } *actread = rd; diff --git a/fs/btrfs/btrfs_tree.h b/fs/btrfs/btrfs_tree.h index f90fbb29514..aa0f3d6c86d 100644 --- a/fs/btrfs/btrfs_tree.h +++ b/fs/btrfs/btrfs_tree.h @@ -647,8 +647,9 @@ enum btrfs_compression_type { BTRFS_COMPRESS_NONE = 0, BTRFS_COMPRESS_ZLIB = 1, BTRFS_COMPRESS_LZO = 2, - BTRFS_COMPRESS_TYPES = 2, - BTRFS_COMPRESS_LAST = 3, + BTRFS_COMPRESS_ZSTD = 3, + BTRFS_COMPRESS_TYPES = 3, + BTRFS_COMPRESS_LAST = 4, }; struct btrfs_file_extent_item { diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index e5601b8f2bf..346875d45a1 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -6,7 +6,9 @@ */ #include "btrfs.h" +#include <malloc.h> #include <linux/lzo.h> +#include <linux/zstd.h> #include <u-boot/zlib.h> #include <asm/unaligned.h> @@ -108,6 +110,61 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 *dbuf, u32 dlen) return res; } +#define ZSTD_BTRFS_MAX_WINDOWLOG 17 +#define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG) + +static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen) +{ + ZSTD_DStream *dstream; + ZSTD_inBuffer in_buf; + ZSTD_outBuffer out_buf; + void *workspace; + size_t wsize; + u32 res = -1; + + wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT); + workspace = malloc(wsize); + if (!workspace) { + debug("%s: cannot allocate workspace of size %zu\n", __func__, + wsize); + return -1; + } + + dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize); + if (!dstream) { + printf("%s: ZSTD_initDStream failed\n", __func__); + goto err_free; + } + + in_buf.src = cbuf; + in_buf.pos = 0; + in_buf.size = clen; + + out_buf.dst = dbuf; + out_buf.pos = 0; + out_buf.size = dlen; + + while (1) { + size_t ret; + + ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf); + if (ZSTD_isError(ret)) { + printf("%s: ZSTD_decompressStream error %d\n", __func__, + ZSTD_getErrorCode(ret)); + goto err_free; + } + + if (in_buf.pos >= clen || !ret) + break; + } + + res = out_buf.pos; + +err_free: + free(workspace); + return res; +} + u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen) { u32 res; @@ -126,6 +183,8 @@ u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen) return decompress_zlib(cbuf, clen, dbuf, dlen); case BTRFS_COMPRESS_LZO: return decompress_lzo(cbuf, clen, dbuf, dlen); + case BTRFS_COMPRESS_ZSTD: + return decompress_zstd(cbuf, clen, dbuf, dlen); default: printf("%s: Unsupported compression in extent: %i\n", __func__, type); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 7aaf8f9b0d8..2dc4a6fcd7a 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -198,17 +198,16 @@ int btrfs_read_superblock(void) break; if (btrfs_check_super_csum(raw_sb)) { - printf("%s: invalid checksum at superblock mirror %i\n", - __func__, i); + debug("%s: invalid checksum at superblock mirror %i\n", + __func__, i); continue; } btrfs_super_block_to_cpu(sb); if (sb->magic != BTRFS_MAGIC) { - printf("%s: invalid BTRFS magic 0x%016llX at " - "superblock mirror %i\n", __func__, sb->magic, - i); + debug("%s: invalid BTRFS magic 0x%016llX at " + "superblock mirror %i\n", __func__, sb->magic, i); } else if (sb->bytenr != superblock_offsets[i]) { printf("%s: invalid bytenr 0x%016llX (expected " "0x%016llX) at superblock mirror %i\n", @@ -224,7 +223,7 @@ int btrfs_read_superblock(void) } if (!btrfs_info.sb.generation) { - printf("%s: No valid BTRFS superblock found!\n", __func__); + debug("%s: No valid BTRFS superblock found!\n", __func__); return -1; } |