aboutsummaryrefslogtreecommitdiff
path: root/include/sqfs/block.h
blob: 2a765e0a99f04fb2a6142164e40ecf389b8af414 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
 * block.h - This file is part of libsquashfs
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#ifndef SQFS_BLOCK_H
#define SQFS_BLOCK_H

#include "sqfs/predef.h"

/**
 * @file block.h
 *
 * @brief Contains on-disk data structures for data block management,
 *        helper macros and the higher level @ref sqfs_block_t structure.
 */

#define SQFS_META_BLOCK_SIZE 8192

#define SQFS_IS_BLOCK_COMPRESSED(size) (((size) & (1 << 24)) == 0)
#define SQFS_ON_DISK_BLOCK_SIZE(size) ((size) & ((1 << 24) - 1))
#define SQFS_IS_SPARSE_BLOCK(size) (SQFS_ON_DISK_BLOCK_SIZE(size) == 0)

/**
 * @struct sqfs_fragment_t
 *
 * @brief Data structure that makes up the fragment table entries.
 */
struct sqfs_fragment_t {
	/**
	 * @brief Location of the fragment block on-disk.
	 */
	uint64_t start_offset;

	/**
	 * @brief Size of the fragment block in bytes.
	 */
	uint32_t size;

	/**
	 * @brief Unused. Always initialize this to 0.
	 */
	uint32_t pad0;
};

/**
 * @enum E_SQFS_BLK_FLAGS
 *
 * @brief Generic flags that tell the processor what to do with a block and
 *        flags that the processor sets when it is done with a block.
 */
typedef enum {
	/**
	 * @brief Only calculate checksum, do NOT compress the data.
	 *
	 * If set, the blocks of a file will not be compressed by the
	 * @ref sqfs_data_writer_t.
	 */
	SQFS_BLK_DONT_COMPRESS = 0x0001,

	/**
	 * @brief Allign the block on disk to device block size.
	 *
	 * If set, the @ref sqfs_data_writer_t will add padding before the
	 * first block of the affected file and after the last block.
	 */
	SQFS_BLK_ALLIGN = 0x0002,

	/**
	 * @brief Set by the @ref sqfs_data_writer_t on the first
	 *        block of a file.
	 */
	SQFS_BLK_FIRST_BLOCK = 0x0800,

	/**
	 * @brief Set by the @ref sqfs_data_writer_t on the last
	 *        block of a file.
	 */
	SQFS_BLK_LAST_BLOCK = 0x1000,

	/**
	 * @brief Set by the @ref sqfs_data_writer_t to indicate that a block
	 *        is a tail end of a file and the block.
	 */
	SQFS_BLK_IS_FRAGMENT = 0x2000,

	/**
	 * @brief Set by the @ref sqfs_data_writer_t on fragment blocks that
	 *        it generates.
	 */
	SQFS_BLK_FRAGMENT_BLOCK = 0x4000,

	/**
	 * @brief Set by @ref sqfs_data_writer_t if the block was
	 *        actually compressed.
	 */
	SQFS_BLK_IS_COMPRESSED = 0x8000,

	/**
	 * @brief The combination of all flags that are user settable.
	 */
	SQFS_BLK_USER_SETTABLE_FLAGS = 0x0003,
} E_SQFS_BLK_FLAGS;

/**
 * @struct sqfs_block_t
 *
 * @brief Encapsulates a chunk of data to be processed by the block processor.
 */
struct sqfs_block_t {
	/**
	 * @brief Used internally, existing value is ignored and overwritten
	 *        when enqueueing a block.
	 */
	sqfs_block_t *next;

	/**
	 * @brief Used internally, existing value is ignored and overwritten
	 *        when enqueueing a block.
	 */
	uint32_t sequence_number;

	/**
	 * @brief Size of the data area.
	 */
	uint32_t size;

	/**
	 * @brief Checksum of the input data.
	 */
	uint32_t checksum;

	/**
	 * @brief Data block index within the inode.
	 */
	uint32_t index;

	/**
	 * @brief The squashfs inode related to this block.
	 */
	sqfs_inode_generic_t *inode;

	/**
	 * @brief User settable flag field.
	 *
	 * A combination of @ref E_SQFS_BLK_FLAGS and custom, user
	 * settable flags.
	 */
	uint32_t flags;

	/**
	 * @brief Raw data to be processed.
	 */
	uint8_t data[];
};

#endif /* SQFS_BLOCK_H */