-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqfs_utils.h
121 lines (106 loc) · 2.68 KB
/
sqfs_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2020 Bootlin
*
* Author: Joao Marcos Costa <[email protected]>
*
* sqfs_utils.h: function prototypes and struct definitions, included at main.c
*/
#ifndef SQFS_UTILS_H
#define SQFS_UTILS_H
#include <stdbool.h>
#define __bitwise
#define CHECK_FLAG(flag, bit) (((flag) >> (bit)) & 1)
#define __aligned_u64 __u64 __aligned(8)
#define __aligned_be64 __be64 __aligned(8)
#define __aligned_le64 __le64 __aligned(8)
#define BIT(x) (1 << (x))
#define BITS_PER_LONG 64
#define GENMASK(h, l) \
(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
/* Metadata blocks start by a 2-byte length header */
#define HEADER_SIZE 2
/*
* These two macros work as getters for a metada block header, retrieving the
* data size and if it is compressed/uncompressed
*/
#define IS_COMPRESSED(A) (!((A) & BIT(15)))
#define DATA_SIZE(A) ((A) & GENMASK(14, 0))
#define SUPER_BLOCK_SIZE 96
//#define DEBUG
#ifdef DEBUG
#define DEBUG_TEST 1
#else
#define DEBUG_TEST 0
#endif
#define printd(...) \
do { if (DEBUG_TEST) {\
fprintf(stderr, "\n%s:%d:%s()", __FILE__, __LINE__, __func__);\
fprintf(stderr, "\n\t" __VA_ARGS__);\
} \
} while (0)\
#define METADATA_BLOCK_SIZE 8192
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
typedef __signed__ long __s64;
typedef unsigned long __u64;
typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
typedef __u32 __bitwise __be32;
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;
struct squashfs_super_block {
__le32 s_magic;
__le32 inodes;
__le32 mkfs_time;
__le32 block_size;
__le32 fragments;
__le16 compression;
__le16 block_log;
__le16 flags;
__le16 no_ids;
__le16 s_major;
__le16 s_minor;
__le64 root_inode;
__le64 bytes_used;
__le64 id_table_start;
__le64 xattr_id_table_start;
__le64 inode_table_start;
__le64 directory_table_start;
__le64 fragment_table_start;
__le64 lookup_table_start;
};
struct super_block_flags {
/* check: unused
* uncompressed_ids: not supported
*/
bool uncompressed_inodes;
bool uncompressed_data;
bool check;
bool uncompressed_frags;
bool no_frags;
bool always_frags;
bool duplicates;
bool exportable;
bool uncompressed_xattrs;
bool no_xattrs;
bool compressor_options;
bool uncompressed_ids;
};
enum squashfs_compression_type {
ZLIB = 1,
LZMA,
LZO,
XZ,
LZ4,
ZSTD,
};
int sqfs_dump_sblk(void *file_mapping);
int sqfs_fill_sblk_flags(struct super_block_flags *sblkf, unsigned short flags);
int sqfs_dump_sblk_flags(struct super_block_flags *sblkf);
#endif /* SQFS_UTILS_H */