4 * Unsquash a squashfs filesystem. This is a highly compressed read only
7 * Copyright (c) 2009, 2010, 2013, 2014, 2019
8 * Phillip Lougher <phillip@squashfs.org.uk>
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.
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.
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.
30 #include <sys/types.h>
46 #include <sys/ioctl.h>
50 #define __BYTE_ORDER BYTE_ORDER
51 #define __BIG_ENDIAN BIG_ENDIAN
52 #define __LITTLE_ENDIAN LITTLE_ENDIAN
57 #include "squashfs_fs.h"
60 #define CALCULATE_HASH(start) (start & 0xffff)
63 * Unified superblock containing fields for all superblocks
66 struct squashfs_super_block s
;
67 /* fields only used by squashfs 3 and earlier layouts */
69 unsigned int no_guids
;
74 struct hash_table_entry
{
77 struct hash_table_entry
*next
;
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
,
104 void (*read_block_list
)(unsigned int *block_list
, char *block_ptr
,
106 struct inode
*(*read_inode
)(unsigned int start_block
,
107 unsigned int offset
);
108 } squashfs_operations
;
118 /* Cache status struct. Caches are used to keep
119 track of memory buffers passed between different threads */
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];
134 /* struct describing a cache entry passed between threads */
142 struct cache_entry
*hash_next
;
143 struct cache_entry
*hash_prev
;
144 struct cache_entry
*free_next
;
145 struct cache_entry
*free_prev
;
149 /* struct describing queues used to pass data between threads */
154 pthread_mutex_t mutex
;
155 pthread_cond_t empty
;
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
165 #define DIR_ENT_SIZE 16
168 char name
[SQUASHFS_NAME_LEN
+ 1];
169 unsigned int start_block
;
182 struct dir_ent
*dirs
;
188 struct cache_entry
*buffer
;
192 struct squashfs_file
{
208 struct pathname
*paths
;
213 struct path_entry
*name
;
218 struct pathname
*path
[0];
220 #define PATHS_ALLOC_SIZE 10
223 extern struct super_block sBlk
;
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
[];
232 extern int no_xattrs
;
233 extern struct queue
*to_reader
, *to_inflate
, *to_writer
;
234 extern struct cache
*fragment_cache
, *data_cache
;
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
*);
248 extern squashfs_operations
*read_filesystem_tables_1();
251 extern squashfs_operations
*read_filesystem_tables_2();
254 extern squashfs_operations
*read_filesystem_tables_3();
257 extern squashfs_operations
*read_filesystem_tables_4();
260 extern int read_ids(int, long long, long long, unsigned int **);
263 extern long long *alloc_index_table(int);