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)) |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 18 | /* Useful for both fragment and data blocks */ |
| 19 | #define SQFS_COMPRESSED_BLOCK(A) (!((A) & BIT(24))) |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 20 | #define SQFS_IS_FRAGMENTED(A) ((A) != 0xFFFFFFFF) |
| 21 | /* |
| 22 | * These two macros work as getters for a metada block header, retrieving the |
| 23 | * data size and if it is compressed/uncompressed |
| 24 | */ |
| 25 | #define SQFS_COMPRESSED_METADATA(A) (!((A) & BIT(15))) |
| 26 | #define SQFS_METADATA_SIZE(A) ((A) & GENMASK(14, 0)) |
| 27 | |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 28 | #endif /* SQFS_UTILS_H */ |