forked from devttys0/sasquatch
-
Notifications
You must be signed in to change notification settings - Fork 10
/
unsquashfs.h
278 lines (249 loc) · 6.52 KB
/
unsquashfs.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
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
#ifndef UNSQUASHFS_H
#define UNSQUASHFS_H
/*
* Unsquash a squashfs filesystem. This is a highly compressed read only
* filesystem.
*
* Copyright (c) 2009, 2010, 2013, 2014
* Phillip Lougher <[email protected]>
*
* 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.
*
* unsquashfs.h
*/
#define TRUE 1
#define FALSE 0
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <utime.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <regex.h>
#include <fnmatch.h>
#include <signal.h>
#include <pthread.h>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#else
#include <endian.h>
#endif
#include "squashfs_fs.h"
#include "error.h"
#define CALCULATE_HASH(start) (start & 0xffff)
/*
* Unified superblock containing fields for all superblocks
*/
struct super_block {
struct squashfs_super_block s;
/* fields only used by squashfs 3 and earlier layouts */
unsigned int no_uids;
unsigned int no_guids;
long long uid_start;
long long guid_start;
};
struct hash_table_entry {
long long start;
int bytes;
struct hash_table_entry *next;
};
struct inode {
int blocks;
char *block_ptr;
long long data;
int fragment;
int frag_bytes;
gid_t gid;
int inode_number;
int mode;
int offset;
long long start;
char *symlink;
time_t time;
int type;
uid_t uid;
char sparse;
unsigned int xattr;
};
typedef struct squashfs_operations {
struct dir *(*squashfs_opendir)(unsigned int block_start,
unsigned int offset, struct inode **i);
void (*read_fragment)(unsigned int fragment, long long *start_block,
int *size);
int (*read_fragment_table)(long long *);
void (*read_block_list)(unsigned int *block_list, char *block_ptr,
int blocks);
struct inode *(*read_inode)(unsigned int start_block,
unsigned int offset);
int (*read_uids_guids)();
} squashfs_operations;
struct test {
int mask;
int value;
int position;
char mode;
};
/* Cache status struct. Caches are used to keep
track of memory buffers passed between different threads */
struct cache {
int max_buffers;
int count;
int used;
int buffer_size;
int wait_free;
int wait_pending;
pthread_mutex_t mutex;
pthread_cond_t wait_for_free;
pthread_cond_t wait_for_pending;
struct cache_entry *free_list;
struct cache_entry *hash_table[65536];
};
/* struct describing a cache entry passed between threads */
struct cache_entry {
struct cache *cache;
long long block;
int size;
int used;
int error;
int pending;
struct cache_entry *hash_next;
struct cache_entry *hash_prev;
struct cache_entry *free_next;
struct cache_entry *free_prev;
char *data;
};
/* struct describing queues used to pass data between threads */
struct queue {
int size;
int readp;
int writep;
pthread_mutex_t mutex;
pthread_cond_t empty;
pthread_cond_t full;
void **data;
};
/* default size of fragment buffer in Mbytes */
#define FRAGMENT_BUFFER_DEFAULT 256
/* default size of data buffer in Mbytes */
#define DATA_BUFFER_DEFAULT 256
#define DIR_ENT_SIZE 16
struct dir_ent {
char name[SQUASHFS_NAME_LEN + 1];
unsigned int start_block;
unsigned int offset;
unsigned int type;
};
struct dir {
int dir_count;
int cur_entry;
unsigned int mode;
uid_t uid;
gid_t guid;
unsigned int mtime;
unsigned int xattr;
struct dir_ent *dirs;
};
struct file_entry {
int offset;
int size;
struct cache_entry *buffer;
};
struct squashfs_file {
int fd;
int blocks;
long long file_size;
int mode;
uid_t uid;
gid_t gid;
time_t time;
char *pathname;
char sparse;
unsigned int xattr;
};
struct path_entry {
char *name;
regex_t *preg;
struct pathname *paths;
};
struct pathname {
int names;
struct path_entry *name;
};
struct pathnames {
int count;
struct pathname *path[0];
};
#define PATHS_ALLOC_SIZE 10
/* globals */
extern struct super_block sBlk;
extern squashfs_operations s_ops;
extern int swap;
extern char *inode_table, *directory_table;
extern struct hash_table_entry *inode_table_hash[65536],
*directory_table_hash[65536];
extern unsigned int *uid_table, *guid_table;
extern pthread_mutex_t screen_mutex;
extern int progress_enabled;
extern int inode_number;
extern int lookup_type[];
extern int fd;
extern struct queue *to_reader, *to_inflate, *to_writer;
extern struct cache *fragment_cache, *data_cache;
/* unsquashfs.c */
extern int lookup_entry(struct hash_table_entry **, long long);
extern int read_fs_bytes(int fd, long long, int, void *);
extern int read_block(int, long long, long long *, int, void *);
extern void enable_progress_bar();
extern void disable_progress_bar();
extern void dump_queue(struct queue *);
extern void dump_cache(struct cache *);
/* unsquash-1.c */
extern void read_block_list_1(unsigned int *, char *, int);
extern int read_fragment_table_1(long long *);
extern struct inode *read_inode_1(unsigned int, unsigned int);
extern struct dir *squashfs_opendir_1(unsigned int, unsigned int,
struct inode **);
extern int read_uids_guids_1();
/* unsquash-2.c */
extern void read_block_list_2(unsigned int *, char *, int);
extern int read_fragment_table_2(long long *);
extern void read_fragment_2(unsigned int, long long *, int *);
extern struct inode *read_inode_2(unsigned int, unsigned int);
/* unsquash-3.c */
extern int read_fragment_table_3(long long *);
extern void read_fragment_3(unsigned int, long long *, int *);
extern struct inode *read_inode_3(unsigned int, unsigned int);
extern struct dir *squashfs_opendir_3(unsigned int, unsigned int,
struct inode **);
/* unsquash-4.c */
extern int read_fragment_table_4(long long *);
extern void read_fragment_4(unsigned int, long long *, int *);
extern struct inode *read_inode_4(unsigned int, unsigned int);
extern struct dir *squashfs_opendir_4(unsigned int, unsigned int,
struct inode **);
extern int read_uids_guids_4();
#endif