Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2020 Bootlin |
| 4 | * |
| 5 | * Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef SQFS_UTILS_H |
| 9 | #define SQFS_UTILS_H |
| 10 | |
| 11 | #include <linux/bitops.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <stdbool.h> |
| 14 | |
| 15 | #define SQFS_FRAGMENT_INDEX_OFFSET(A) ((A) % SQFS_MAX_ENTRIES) |
| 16 | #define SQFS_FRAGMENT_INDEX(A) ((A) / SQFS_MAX_ENTRIES) |
| 17 | #define SQFS_BLOCK_SIZE(A) ((A) & GENMASK(23, 0)) |
| 18 | #define SQFS_CHECK_FLAG(flag, bit) (((flag) >> (bit)) & 1) |
| 19 | /* Useful for both fragment and data blocks */ |
| 20 | #define SQFS_COMPRESSED_BLOCK(A) (!((A) & BIT(24))) |
| 21 | /* SQFS_COMPRESSED_DATA strictly used with super block's 'flags' member */ |
| 22 | #define SQFS_COMPRESSED_DATA(A) (!((A) & 0x0002)) |
| 23 | #define SQFS_IS_FRAGMENTED(A) ((A) != 0xFFFFFFFF) |
| 24 | /* |
| 25 | * These two macros work as getters for a metada block header, retrieving the |
| 26 | * data size and if it is compressed/uncompressed |
| 27 | */ |
| 28 | #define SQFS_COMPRESSED_METADATA(A) (!((A) & BIT(15))) |
| 29 | #define SQFS_METADATA_SIZE(A) ((A) & GENMASK(14, 0)) |
| 30 | |
| 31 | struct squashfs_super_block_flags { |
| 32 | /* check: unused |
| 33 | * uncompressed_ids: not supported |
| 34 | */ |
| 35 | bool uncompressed_inodes; |
| 36 | bool uncompressed_data; |
| 37 | bool check; |
| 38 | bool uncompressed_frags; |
| 39 | bool no_frags; |
| 40 | bool always_frags; |
| 41 | bool duplicates; |
| 42 | bool exportable; |
| 43 | bool uncompressed_xattrs; |
| 44 | bool no_xattrs; |
| 45 | bool compressor_options; |
| 46 | bool uncompressed_ids; |
| 47 | }; |
| 48 | |
| 49 | #endif /* SQFS_UTILS_H */ |