blob: 41f13e8a9ec32f072fbcba27d5f4e42d0061d028 [file] [log] [blame]
Joao Marcos Costac5100612020-07-30 15:33:47 +02001/* 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 Costac5100612020-07-30 15:33:47 +020018/* Useful for both fragment and data blocks */
19#define SQFS_COMPRESSED_BLOCK(A) (!((A) & BIT(24)))
Joao Marcos Costac5100612020-07-30 15:33:47 +020020#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 Costac5100612020-07-30 15:33:47 +020028#endif /* SQFS_UTILS_H */