]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/unsquashfs.h
1.1.07 release
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / unsquashfs.h
1 #ifndef UNSQUASHFS_H
2 #define UNSQUASHFS_H
3 /*
4 * Unsquash a squashfs filesystem. This is a highly compressed read only
5 * filesystem.
6 *
7 * Copyright (c) 2009, 2010, 2013, 2014, 2019
8 * Phillip Lougher <phillip@squashfs.org.uk>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2,
13 * or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 * unsquashfs.h
25 */
26
27 #define TRUE 1
28 #define FALSE 0
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <sys/mman.h>
38 #include <utime.h>
39 #include <pwd.h>
40 #include <grp.h>
41 #include <time.h>
42 #include <regex.h>
43 #include <signal.h>
44 #include <pthread.h>
45 #include <math.h>
46 #include <sys/ioctl.h>
47 #include <sys/time.h>
48
49 #ifndef linux
50 #define __BYTE_ORDER BYTE_ORDER
51 #define __BIG_ENDIAN BIG_ENDIAN
52 #define __LITTLE_ENDIAN LITTLE_ENDIAN
53 #else
54 #include <endian.h>
55 #endif
56
57 #include "squashfs_fs.h"
58 #include "error.h"
59
60 #define CALCULATE_HASH(start) (start & 0xffff)
61
62 /*
63 * Unified superblock containing fields for all superblocks
64 */
65 struct super_block {
66 struct squashfs_super_block s;
67 /* fields only used by squashfs 3 and earlier layouts */
68 unsigned int no_uids;
69 unsigned int no_guids;
70 long long uid_start;
71 long long guid_start;
72 };
73
74 struct hash_table_entry {
75 long long start;
76 long long bytes;
77 struct hash_table_entry *next;
78 };
79
80 struct inode {
81 int blocks;
82 char *block_ptr;
83 long long data;
84 int fragment;
85 int frag_bytes;
86 gid_t gid;
87 int inode_number;
88 int mode;
89 int offset;
90 long long start;
91 char *symlink;
92 time_t time;
93 int type;
94 uid_t uid;
95 char sparse;
96 unsigned int xattr;
97 };
98
99 typedef struct squashfs_operations {
100 struct dir *(*opendir)(unsigned int block_start,
101 unsigned int offset, struct inode **i);
102 void (*read_fragment)(unsigned int fragment, long long *start_block,
103 int *size);
104 void (*read_block_list)(unsigned int *block_list, char *block_ptr,
105 int blocks);
106 struct inode *(*read_inode)(unsigned int start_block,
107 unsigned int offset);
108 } squashfs_operations;
109
110 struct test {
111 int mask;
112 int value;
113 int position;
114 char mode;
115 };
116
117
118 /* Cache status struct. Caches are used to keep
119 track of memory buffers passed between different threads */
120 struct cache {
121 int max_buffers;
122 int count;
123 int used;
124 int buffer_size;
125 int wait_free;
126 int wait_pending;
127 pthread_mutex_t mutex;
128 pthread_cond_t wait_for_free;
129 pthread_cond_t wait_for_pending;
130 struct cache_entry *free_list;
131 struct cache_entry *hash_table[65536];
132 };
133
134 /* struct describing a cache entry passed between threads */
135 struct cache_entry {
136 struct cache *cache;
137 long long block;
138 int size;
139 int used;
140 int error;
141 int pending;
142 struct cache_entry *hash_next;
143 struct cache_entry *hash_prev;
144 struct cache_entry *free_next;
145 struct cache_entry *free_prev;
146 char *data;
147 };
148
149 /* struct describing queues used to pass data between threads */
150 struct queue {
151 int size;
152 int readp;
153 int writep;
154 pthread_mutex_t mutex;
155 pthread_cond_t empty;
156 pthread_cond_t full;
157 void **data;
158 };
159
160 /* default size of fragment buffer in Mbytes */
161 #define FRAGMENT_BUFFER_DEFAULT 256
162 /* default size of data buffer in Mbytes */
163 #define DATA_BUFFER_DEFAULT 256
164
165 #define DIR_ENT_SIZE 16
166
167 struct dir_ent {
168 char name[SQUASHFS_NAME_LEN + 1];
169 unsigned int start_block;
170 unsigned int offset;
171 unsigned int type;
172 };
173
174 struct dir {
175 int dir_count;
176 int cur_entry;
177 unsigned int mode;
178 uid_t uid;
179 gid_t guid;
180 unsigned int mtime;
181 unsigned int xattr;
182 struct dir_ent *dirs;
183 };
184
185 struct file_entry {
186 int offset;
187 int size;
188 struct cache_entry *buffer;
189 };
190
191
192 struct squashfs_file {
193 int fd;
194 int blocks;
195 long long file_size;
196 int mode;
197 uid_t uid;
198 gid_t gid;
199 time_t time;
200 char *pathname;
201 char sparse;
202 unsigned int xattr;
203 };
204
205 struct path_entry {
206 char *name;
207 regex_t *preg;
208 struct pathname *paths;
209 };
210
211 struct pathname {
212 int names;
213 struct path_entry *name;
214 };
215
216 struct pathnames {
217 int count;
218 struct pathname *path[0];
219 };
220 #define PATHS_ALLOC_SIZE 10
221
222 /* globals */
223 extern struct super_block sBlk;
224 extern int swap;
225 extern struct hash_table_entry *inode_table_hash[65536],
226 *directory_table_hash[65536];
227 extern pthread_mutex_t screen_mutex;
228 extern int progress_enabled;
229 extern int inode_number;
230 extern int lookup_type[];
231 extern int fd;
232 extern int no_xattrs;
233 extern struct queue *to_reader, *to_inflate, *to_writer;
234 extern struct cache *fragment_cache, *data_cache;
235
236 /* unsquashfs.c */
237 extern void *read_inode_table(long long, long long);
238 extern void *read_directory_table(long long, long long);
239 extern long long lookup_entry(struct hash_table_entry **, long long);
240 extern int read_fs_bytes(int fd, long long, int, void *);
241 extern int read_block(int, long long, long long *, int, void *);
242 extern void enable_progress_bar();
243 extern void disable_progress_bar();
244 extern void dump_queue(struct queue *);
245 extern void dump_cache(struct cache *);
246
247 /* unsquash-1.c */
248 extern squashfs_operations *read_filesystem_tables_1();
249
250 /* unsquash-2.c */
251 extern squashfs_operations *read_filesystem_tables_2();
252
253 /* unsquash-3.c */
254 extern squashfs_operations *read_filesystem_tables_3();
255
256 /* unsquash-4.c */
257 extern squashfs_operations *read_filesystem_tables_4();
258
259 /* unsquash-123.c */
260 extern int read_ids(int, long long, long long, unsigned int **);
261
262 /* unsquash-34.c */
263 extern long long *alloc_index_table(int);
264 #endif