summaryrefslogtreecommitdiffstats
path: root/squashfs-tools/mksquashfs.h
blob: 10d31ffb9d5200c23679ae4053921022969a2638 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#ifndef MKSQUASHFS_H
#define MKSQUASHFS_H
/*
 * Squashfs
 *
 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 * 2012, 2013, 2014, 2019, 2021, 2022, 2023
 * Phillip Lougher <phillip@squashfs.org.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * mksquashfs.h
 *
 */

struct dir_info {
	char			*pathname;
	char			*subpath;
	unsigned int		count;
	unsigned int		directory_count;
	unsigned int		depth;
	unsigned int		excluded;
	char			dir_is_ldir;
	struct dir_ent		*dir_ent;
	struct dir_ent		*list;
	DIR			*linuxdir;
};

struct dir_ent {
	char			*name;
	char			*source_name;
	char			*nonstandard_pathname;
	struct inode_info	*inode;
	struct dir_info		*dir;
	struct dir_info		*our_dir;
	struct dir_ent		*next;
};

struct inode_info {
	struct stat		buf;
	struct inode_info	*next;
	struct pseudo_dev	*pseudo;
	struct tar_file		*tar_file;
	struct pseudo_xattr	*xattr;
	squashfs_inode		inode;
	unsigned int		inode_number;
	unsigned int		nlink;
	char			dummy_root_dir;
	char			type;
	char			read;
	char			root_entry;
	char			no_fragments;
	char			always_use_fragments;
	char			noD;
	char			noF;
	char			tarfile;
	char			symlink[0];
};


/* in memory file info */
struct file_info {
	long long		file_size;
	long long		bytes;
	long long		start;
	long long		sparse;
	unsigned int		*block_list;
	struct file_info	*frag_next;
	struct file_info	*block_next;
	struct fragment		*fragment;
	struct dup_info		*dup;
	unsigned int		blocks;
	unsigned short		checksum;
	unsigned short		fragment_checksum;
	char			have_frag_checksum;
	char			have_checksum;
};


struct dup_info {
	struct file_info	*file;
	struct file_info	*frag;
	struct dup_info		*next;
};


/* fragment block data structures */
struct fragment {
	unsigned int		index;
	int			offset;
	int			size;
};

/* in memory uid tables */
#define ID_ENTRIES 256
#define ID_HASH(id) (id & (ID_ENTRIES - 1))
#define ISA_UID 1
#define ISA_GID 2

struct id {
	unsigned int id;
	int	index;
	char	flags;
	struct id *next;
};

/* fragment to file mapping used when appending */
struct append_file {
	struct file_info *file;
	struct append_file *next;
};

/*
 * Amount of physical memory to use by default, and the default queue
 * ratios
 */
#define SQUASHFS_TAKE 4
#define SQUASHFS_READQ_MEM 4
#define SQUASHFS_BWRITEQ_MEM 4
#define SQUASHFS_FWRITEQ_MEM 4

/*
 * Lowest amount of physical memory considered viable for Mksquashfs
 * to run in Mbytes
 */
#define SQUASHFS_LOWMEM 64

/* offset of data in compressed metadata blocks (allowing room for
 * compressed size */
#define BLOCK_OFFSET 2

#ifdef REPRODUCIBLE_DEFAULT
#define NOREP_STR
#define REP_STR " (default)"
#define REP_DEF 1
#else
#define NOREP_STR " (default)"
#define REP_STR
#define REP_DEF 0
#endif

/* in memory directory data */
#define I_COUNT_SIZE		128
#define DIR_ENTRIES		32
#define INODE_HASH_SIZE		65536
#define INODE_HASH_MASK		(INODE_HASH_SIZE - 1)
#define INODE_HASH(dev, ino)	(ino & INODE_HASH_MASK)

struct cached_dir_index {
	struct squashfs_dir_index	index;
	char				*name;
};

struct directory {
	unsigned int		start_block;
	unsigned int		size;
	unsigned char		*buff;
	unsigned char		*p;
	unsigned int		entry_count;
	unsigned char		*entry_count_p;
	unsigned int		i_count;
	unsigned int		i_size;
	struct cached_dir_index	*index;
	unsigned char		*index_count_p;
	unsigned int		inode_number;
};

/* exclude file handling */
/* list of exclude dirs/files */
struct exclude_info {
	dev_t			st_dev;
	ino_t			st_ino;
};

#define EXCLUDE_SIZE 8192

struct pathname {
	int names;
	struct path_entry *name;
};

struct pathnames {
	int count;
	struct pathname *path[0];
};
#define PATHS_ALLOC_SIZE 10

#define FRAG_SIZE 32768

struct old_root_entry_info {
	char			*name;
	struct inode_info	inode;
};

#define ALLOC_SIZE 128

/* Maximum transfer size for Linux read() call on both 32-bit and 64-bit systems.
 * See READ(2) */
#define MAXIMUM_READ_SIZE 0x7ffff000

extern int sleep_time;
extern struct cache *reader_buffer, *fragment_buffer, *reserve_cache;
extern struct cache *bwriter_buffer, *fwriter_buffer;
extern struct queue *to_reader, *to_deflate, *to_writer, *from_writer,
	*to_frag, *locked_fragment, *to_process_frag;
extern struct append_file **file_mapping;
extern struct seq_queue *to_main, *to_order;
extern pthread_mutex_t fragment_mutex, dup_mutex;
extern struct squashfs_fragment_entry *fragment_table;
extern struct compressor *comp;
extern int block_size;
extern int block_log;
extern int sorted;
extern int noF;
extern int noD;
extern int old_exclude;
extern int no_fragments;
extern int always_use_fragments;
extern struct file_info **dupl_frag;
extern int duplicate_checking;
extern int no_hardlinks;
extern struct dir_info *root_dir;
extern struct pathnames *paths;
extern int tarfile;
extern int root_mode_opt;
extern mode_t root_mode;
extern int root_time_opt;
extern unsigned int root_time;
extern int root_uid_opt;
extern unsigned int root_uid;
extern int root_gid_opt;
extern unsigned int root_gid;
extern struct inode_info *inode_info[INODE_HASH_SIZE];
extern int quiet;
extern int sequence_count;
extern int pseudo_override;
extern int global_uid_opt;
extern unsigned int global_uid;
extern int global_gid_opt;
extern unsigned int global_gid;
extern int sleep_time;

extern int read_fs_bytes(int, long long, long long, void *);
extern void add_file(long long, long long, long long, unsigned int *, int,
	unsigned int, int, int);
extern struct id *create_id(unsigned int);
extern unsigned int get_uid(unsigned int);
extern unsigned int get_guid(unsigned int);
extern long long read_bytes(int, void *, long long);
extern unsigned short get_checksum_mem(char *, int);
extern int reproducible;
extern void *reader(void *arg);
extern squashfs_inode create_inode(struct dir_info *dir_info,
	struct dir_ent *dir_ent, int type, long long byte_size,
	long long start_block, unsigned int offset, unsigned int *block_list,
	struct fragment *fragment, struct directory *dir_in, long long sparse);
extern void free_fragment(struct fragment *fragment);
extern struct file_info *write_file(struct dir_ent *dir_ent, int *dup);
extern int excluded(char *name, struct pathnames *paths, struct pathnames **new);
extern struct dir_ent *lookup_name(struct dir_info *dir, char *name);
extern struct dir_ent *create_dir_entry(char *name, char *source_name,
	char *nonstandard_pathname, struct dir_info *dir);
extern void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
	struct inode_info *inode_info);
extern void free_dir_entry(struct dir_ent *dir_ent);
extern void free_dir(struct dir_info *dir);
extern struct dir_info *create_dir(char *pathname, char *subpath, unsigned int depth);
extern char *subpathname(struct dir_ent *dir_ent);
extern struct dir_info *scan1_opendir(char *pathname, char *subpath, unsigned int depth);
extern squashfs_inode do_directory_scans(struct dir_ent *dir_ent, int progress);
extern struct inode_info *lookup_inode(struct stat *buf);
extern int exec_date(char *, unsigned int *);
#endif