wok-stable view squashfs/stuff/lzma.u @ rev 4755

flex: update depends
author Paul Issott <paul@slitaz.org>
date Sun Jan 10 12:41:44 2010 +0000 (2010-01-10)
parents 7b34aa2dd3aa
children
line source
1 --- squashfs-4.0/squashfs-tools/Makefile
2 +++ squashfs-4.0/squashfs-tools/Makefile
3 @@ -1,40 +1,76 @@
4 +#
5 +# Building LZMA support
6 +# Download LZMA sdk (4.65 used in development, other versions may work),
7 +# set LZMA_DIR to unpacked source, and uncomment next line
8 +LZMA_SUPPORT = 1
9 +LZMA_DIR = ../LZMA/lzma465
10 +
11 +#Compression default.
12 +COMP_DEFAULT = gzip
13 +
14 +INCLUDEDIR = -I.
15 INSTALL_DIR = /usr/local/bin
17 -INCLUDEDIR = .
18 +MKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o \
19 + gzip_wrapper.o
21 -CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2
22 +UNSQUASHFS_OBJS = unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o \
23 + unsquash-4.o swap.o compressor.o gzip_wrapper.o
25 +CFLAGS = $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
26 + -D_GNU_SOURCE -DCOMP_DEFAULT=\"$(COMP_DEFAULT)\" -O2 -Wall
27 +
28 +ifdef LZMA_SUPPORT
29 +LZMA_OBJS = $(LZMA_DIR)/C/Alloc.o $(LZMA_DIR)/C/LzFind.o \
30 + $(LZMA_DIR)/C/LzmaDec.o $(LZMA_DIR)/C/LzmaEnc.o $(LZMA_DIR)/C/LzmaLib.o
31 +INCLUDEDIR += -I$(LZMA_DIR)/C
32 +CFLAGS += -DLZMA_SUPPORT
33 +MKSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)
34 +UNSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)
35 +endif
36 +
37 +.PHONY: all
38 all: mksquashfs unsquashfs
40 -mksquashfs: mksquashfs.o read_fs.o sort.o swap.o pseudo.o
41 - $(CC) mksquashfs.o read_fs.o sort.o swap.o pseudo.o -lz -lpthread -lm -o $@
42 +mksquashfs: $(MKSQUASHFS_OBJS)
43 + $(CC) $(MKSQUASHFS_OBJS) -lz -lpthread -lm -o $@
45 -mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h squashfs_swap.h Makefile
46 +mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \
47 + squashfs_swap.h
49 -read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h squashfs_swap.h Makefile
50 +read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h squashfs_swap.h
52 -sort.o: sort.c squashfs_fs.h global.h sort.h Makefile
53 +sort.o: sort.c squashfs_fs.h global.h sort.h
55 -swap.o: swap.c Makefile
56 +swap.o: swap.c
58 -pseudo.o: pseudo.c pseudo.h Makefile
59 +pseudo.o: pseudo.c pseudo.h
61 -unsquashfs: unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o unsquash-4.o swap.o
62 - $(CC) unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o unsquash-4.o swap.o -lz -lpthread -lm -o $@
63 +compressor.o: compressor.c compressor.h
65 -unsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h squashfs_compat.h global.h Makefile
66 +unsquashfs: $(UNSQUASHFS_OBJS)
67 + $(CC) $(UNSQUASHFS_OBJS) -lz -lpthread -lm -o $@
69 -unsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h global.h Makefile
70 +unsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h \
71 + squashfs_compat.h global.h
73 -unsquash-2.o: unsquashfs.h unsquash-2.c unsquashfs.h squashfs_fs.h squashfs_compat.h global.h Makefile
74 +unsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h \
75 + global.h
77 -unsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h global.h Makefile
78 +unsquash-2.o: unsquashfs.h unsquash-2.c unsquashfs.h squashfs_fs.h \
79 + squashfs_compat.h global.h
81 -unsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h global.h Makefile
82 +unsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h \
83 + global.h
85 +unsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h \
86 + global.h
87 +
88 +.PHONY: clean
89 clean:
90 -rm -f *.o mksquashfs unsquashfs
92 +.PHONY: install
93 install: mksquashfs unsquashfs
94 mkdir -p $(INSTALL_DIR)
95 cp mksquashfs $(INSTALL_DIR)
97 --- squashfs-4.0/squashfs-tools/compressor.c Thu Jan 1 01:00:00 1970
98 +++ squashfs-4.0/squashfs-tools/compressor.c Sat Aug 29 03:05:34 2009
99 @@ -0,0 +1,78 @@
100 +/*
101 + *
102 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
103 + * Phillip Lougher <phillip@lougher.demon.co.uk>
104 + *
105 + * This program is free software; you can redistribute it and/or
106 + * modify it under the terms of the GNU General Public License
107 + * as published by the Free Software Foundation; either version 2,
108 + * or (at your option) any later version.
109 + *
110 + * This program is distributed in the hope that it will be useful,
111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 + * GNU General Public License for more details.
114 + *
115 + * You should have received a copy of the GNU General Public License
116 + * along with this program; if not, write to the Free Software
117 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
118 + *
119 + * compressor.c
120 + */
121 +
122 +#include <stdio.h>
123 +#include <string.h>
124 +#include "compressor.h"
125 +#include "squashfs_fs.h"
126 +
127 +extern int gzip_compress(void **, char *, char *, int, int, int *);
128 +extern int gzip_uncompress(char *, char *, int, int, int *);
129 +extern int lzma_compress(void **, char *, char *, int, int, int *);
130 +extern int lzma_uncompress(char *, char *, int, int, int *);
131 +
132 +struct compressor compressor[] = {
133 + { gzip_compress, gzip_uncompress, ZLIB_COMPRESSION, "gzip", 1 },
134 +#ifdef LZMA_SUPPORT
135 + { lzma_compress, lzma_uncompress, LZMA_COMPRESSION, "lzma", 1 },
136 +#else
137 + { NULL, NULL, LZMA_COMPRESSION, "lzma", 0 },
138 +#endif
139 + { NULL, NULL , 0, "unknown", 0}
140 +};
141 +
142 +
143 +struct compressor *lookup_compressor(char *name)
144 +{
145 + int i;
146 +
147 + for(i = 0; compressor[i].id; i++)
148 + if(strcmp(compressor[i].name, name) == 0)
149 + break;
150 +
151 + return &compressor[i];
152 +}
153 +
154 +
155 +struct compressor *lookup_compressor_id(int id)
156 +{
157 + int i;
158 +
159 + for(i = 0; compressor[i].id; i++)
160 + if(id == compressor[i].id)
161 + break;
162 +
163 + return &compressor[i];
164 +}
165 +
166 +
167 +void display_compressors(char *indent, char *def_comp)
168 +{
169 + int i;
170 +
171 + for(i = 0; compressor[i].id; i++)
172 + if(compressor[i].supported)
173 + fprintf(stderr, "%s\t%s%s\n", indent,
174 + compressor[i].name,
175 + strcmp(compressor[i].name, def_comp) == 0 ?
176 + " (default)" : "");
177 +}
179 --- squashfs-4.0/squashfs-tools/compressor.h Thu Jan 1 01:00:00 1970
180 +++ squashfs-4.0/squashfs-tools/compressor.h Mon Aug 24 20:28:04 2009
181 @@ -0,0 +1,33 @@
182 +/*
183 + *
184 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
185 + * Phillip Lougher <phillip@lougher.demon.co.uk>
186 + *
187 + * This program is free software; you can redistribute it and/or
188 + * modify it under the terms of the GNU General Public License
189 + * as published by the Free Software Foundation; either version 2,
190 + * or (at your option) any later version.
191 + *
192 + * This program is distributed in the hope that it will be useful,
193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195 + * GNU General Public License for more details.
196 + *
197 + * You should have received a copy of the GNU General Public License
198 + * along with this program; if not, write to the Free Software
199 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
200 + *
201 + * compressor.h
202 + */
203 +
204 +struct compressor {
205 + int (*compress)(void **, char *, char *, int, int, int *);
206 + int (*uncompress)(char *, char *, int, int, int *);
207 + int id;
208 + char *name;
209 + int supported;
210 +};
211 +
212 +extern struct compressor *lookup_compressor(char *);
213 +extern struct compressor *lookup_compressor_id(int);
214 +extern void display_compressors(char *, char *);
216 --- squashfs-4.0/squashfs-tools/gzip_wrapper.c Thu Jan 1 01:00:00 1970
217 +++ squashfs-4.0/squashfs-tools/gzip_wrapper.c Fri Aug 7 22:12:53 2009
218 @@ -0,0 +1,80 @@
219 +/*
220 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
221 + * Phillip Lougher <phillip@lougher.demon.co.uk>
222 + *
223 + * This program is free software; you can redistribute it and/or
224 + * modify it under the terms of the GNU General Public License
225 + * as published by the Free Software Foundation; either version 2,
226 + * or (at your option) any later version.
227 + *
228 + * This program is distributed in the hope that it will be useful,
229 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
230 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231 + * GNU General Public License for more details.
232 + *
233 + * You should have received a copy of the GNU General Public License
234 + * along with this program; if not, write to the Free Software
235 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
236 + *
237 + * gzip_wrapper.c
238 + */
239 +
240 +#include <stdlib.h>
241 +#include <zlib.h>
242 +
243 +int gzip_compress(void **strm, char *d, char *s, int size, int block_size,
244 + int *error)
245 +{
246 + int res = 0;
247 + z_stream *stream = *strm;
248 +
249 + if(stream == NULL) {
250 + if((stream = *strm = malloc(sizeof(z_stream))) == NULL)
251 + goto failed;
252 +
253 + stream->zalloc = Z_NULL;
254 + stream->zfree = Z_NULL;
255 + stream->opaque = 0;
256 +
257 + if((res = deflateInit(stream, 9)) != Z_OK)
258 + goto failed;
259 + } else if((res = deflateReset(stream)) != Z_OK)
260 + goto failed;
261 +
262 + stream->next_in = (unsigned char *) s;
263 + stream->avail_in = size;
264 + stream->next_out = (unsigned char *) d;
265 + stream->avail_out = block_size;
266 +
267 + res = deflate(stream, Z_FINISH);
268 + if(res == Z_STREAM_END)
269 + /*
270 + * Success, return the compressed size.
271 + */
272 + return (int) stream->total_out;
273 + if(res == Z_OK)
274 + /*
275 + * Output buffer overflow. Return out of buffer space
276 + */
277 + return 0;
278 +failed:
279 + /*
280 + * All other errors return failure, with the compressor
281 + * specific error code in *error
282 + */
283 + *error = res;
284 + return -1;
285 +}
286 +
287 +
288 +int gzip_uncompress(char *d, char *s, int size, int block_size, int *error)
289 +{
290 + int res;
291 + unsigned long bytes = block_size;
292 +
293 + res = uncompress((unsigned char *) d, &bytes,
294 + (const unsigned char *) s, size);
295 +
296 + *error = res;
297 + return res == Z_OK ? (int) bytes : -1;
298 +}
300 --- squashfs-4.0/squashfs-tools/lzma_wrapper.c Thu Jan 1 01:00:00 1970
301 +++ squashfs-4.0/squashfs-tools/lzma_wrapper.c Wed Oct 14 05:32:57 2009
302 @@ -0,0 +1,93 @@
303 +/*
304 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
305 + * Phillip Lougher <phillip@lougher.demon.co.uk>
306 + *
307 + * This program is free software; you can redistribute it and/or
308 + * modify it under the terms of the GNU General Public License
309 + * as published by the Free Software Foundation; either version 2,
310 + * or (at your option) any later version.
311 + *
312 + * This program is distributed in the hope that it will be useful,
313 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
314 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
315 + * GNU General Public License for more details.
316 + *
317 + * You should have received a copy of the GNU General Public License
318 + * along with this program; if not, write to the Free Software
319 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
320 + *
321 + * lzma_wrapper.c
322 + */
323 +
324 +#include <LzmaLib.h>
325 +
326 +#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
327 +
328 +int lzma_compress(void **strm, char *dest, char *src, int size,int block_size,
329 + int *error)
330 +{
331 + unsigned char *d = (unsigned char *) dest, *s = (unsigned char *) src;
332 + size_t props_size = LZMA_PROPS_SIZE,
333 + outlen = block_size - LZMA_HEADER_SIZE;
334 + int res;
335 +
336 + res = LzmaCompress(d + LZMA_HEADER_SIZE, &outlen, s, size, d,
337 + &props_size, 5, block_size, 3, 0, 2, 32, 1);
338 +
339 + if(res == SZ_ERROR_OUTPUT_EOF) {
340 + /*
341 + * Output buffer overflow. Return out of buffer space error
342 + */
343 + return 0;
344 + }
345 +
346 + if(res != SZ_OK) {
347 + /*
348 + * All other errors return failure, with the compressor
349 + * specific error code in *error
350 + */
351 + *error = res;
352 + return -1;
353 + }
354 +
355 + /*
356 + * Fill in the 8 byte little endian uncompressed size field in the
357 + * LZMA header. 8 bytes is excessively large for squashfs but
358 + * this is the standard LZMA header and which is expected by the kernel
359 + * code
360 + */
361 + d[LZMA_PROPS_SIZE] = size & 255;
362 + d[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;
363 + d[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;
364 + d[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;
365 + d[LZMA_PROPS_SIZE + 4] = 0;
366 + d[LZMA_PROPS_SIZE + 5] = 0;
367 + d[LZMA_PROPS_SIZE + 6] = 0;
368 + d[LZMA_PROPS_SIZE + 7] = 0;
369 +
370 + /*
371 + * Success, return the compressed size. Outlen returned by the LZMA
372 + * compressor does not include the LZMA header space
373 + */
374 + return outlen + LZMA_HEADER_SIZE;
375 +}
376 +
377 +
378 +int lzma_uncompress(char *dest, char *src, int size, int block_size,
379 + int *error)
380 +{
381 + unsigned char *d = (unsigned char *) dest, *s = (unsigned char *) src;
382 + size_t outlen, inlen = size - LZMA_HEADER_SIZE;
383 + int res;
384 +
385 + outlen = s[LZMA_PROPS_SIZE] |
386 + (s[LZMA_PROPS_SIZE + 1] << 8) |
387 + (s[LZMA_PROPS_SIZE + 2] << 16) |
388 + (s[LZMA_PROPS_SIZE + 3] << 24);
389 +
390 + res = LzmaUncompress(d, &outlen, s + LZMA_HEADER_SIZE, &inlen,
391 + s, LZMA_PROPS_SIZE);
392 +
393 + *error = res;
394 + return res == SZ_OK ? outlen : -1;
395 +}
397 --- squashfs-4.0/squashfs-tools/mksquashfs.c Sun Apr 5 23:22:48 2009
398 +++ squashfs-4.0/squashfs-tools/mksquashfs.c Tue Dec 8 19:02:54 2009
399 @@ -36,7 +36,6 @@
400 #include <errno.h>
401 #include <dirent.h>
402 #include <string.h>
403 -#include <zlib.h>
404 #include <stdlib.h>
405 #include <signal.h>
406 #include <setjmp.h>
407 @@ -47,6 +46,7 @@
408 #include <math.h>
409 #include <regex.h>
410 #include <fnmatch.h>
411 +#include <sys/wait.h>
413 #ifndef linux
414 #define __BYTE_ORDER BYTE_ORDER
415 @@ -64,6 +64,7 @@
416 #include "global.h"
417 #include "sort.h"
418 #include "pseudo.h"
419 +#include "compressor.h"
421 #ifdef SQUASHFS_TRACE
422 #define TRACE(s, args...) do { \
423 @@ -245,10 +246,8 @@
424 /* list of root directory entries read from original filesystem */
425 int old_root_entries = 0;
426 struct old_root_entry_info {
427 - char name[SQUASHFS_NAME_LEN + 1];
428 - squashfs_inode inode;
429 - int type;
430 - int inode_number;
431 + char *name;
432 + struct inode_info inode;
433 };
434 struct old_root_entry_info *old_root_entry;
436 @@ -371,10 +370,15 @@
437 int reader_buffer_size;
438 int fragment_buffer_size;
440 +/* compression operations structure */
441 +static struct compressor *comp;
442 +char *comp_name = COMP_DEFAULT;
443 +
444 char *read_from_disk(long long start, unsigned int avail_bytes);
445 void add_old_root_entry(char *name, squashfs_inode inode, int inode_number,
446 int type);
447 -extern int read_super(int fd, squashfs_super_block *sBlk, char *source);
448 +extern struct compressor *read_super(int fd, squashfs_super_block *sBlk,
449 + char *source);
450 extern long long read_filesystem(char *root_name, int fd,
451 squashfs_super_block *sBlk, char **cinode_table, char **data_cache,
452 char **cdirectory_table, char **directory_data_cache,
453 @@ -831,83 +835,32 @@
454 }
457 -unsigned int mangle2(z_stream **strm, char *d, char *s, int size,
458 +int mangle2(void **strm, char *d, char *s, int size,
459 int block_size, int uncompressed, int data_block)
460 {
461 - unsigned long c_byte;
462 - unsigned int res;
463 - z_stream *stream = *strm;
464 + int error, c_byte = 0;
466 - if(uncompressed)
467 - goto notcompressed;
468 -
469 - if(stream == NULL) {
470 - if((stream = *strm = malloc(sizeof(z_stream))) == NULL)
471 - BAD_ERROR("mangle::compress failed, not enough "
472 - "memory\n");
473 -
474 - stream->zalloc = Z_NULL;
475 - stream->zfree = Z_NULL;
476 - stream->opaque = 0;
477 -
478 - if((res = deflateInit(stream, 9)) != Z_OK) {
479 - if(res == Z_MEM_ERROR)
480 - BAD_ERROR("zlib::compress failed, not enough "
481 - "memory\n");
482 - else if(res == Z_STREAM_ERROR)
483 - BAD_ERROR("zlib::compress failed, not a valid "
484 - "compression level\n");
485 - else if(res == Z_VERSION_ERROR)
486 - BAD_ERROR("zlib::compress failed, incorrect "
487 - "zlib version\n");
488 - else
489 - BAD_ERROR("zlib::compress failed, unknown "
490 - "error %d\n", res);
491 - }
492 - } else if((res = deflateReset(stream)) != Z_OK) {
493 - if(res == Z_STREAM_ERROR)
494 - BAD_ERROR("zlib::compress failed, stream state "
495 - "inconsistent\n");
496 - else
497 - BAD_ERROR("zlib::compress failed, unknown error %d\n",
498 - res);
499 + if(!uncompressed) {
500 + c_byte = comp->compress(strm, d, s, size, block_size, &error);
501 + if(c_byte == -1)
502 + BAD_ERROR("mangle2:: %s compress failed with error "
503 + "code %d\n", comp->name, error);
504 }
506 - stream->next_in = (unsigned char *) s;
507 - stream->avail_in = size;
508 - stream->next_out = (unsigned char *) d;
509 - stream->avail_out = block_size;
510 -
511 - res = deflate(stream, Z_FINISH);
512 - if(res != Z_STREAM_END && res != Z_OK) {
513 - if(res == Z_STREAM_ERROR)
514 - BAD_ERROR("zlib::compress failed, stream state "
515 - "inconsistent\n");
516 - else if(res == Z_BUF_ERROR)
517 - BAD_ERROR("zlib::compress failed, no progress possible"
518 - "\n");
519 - else
520 - BAD_ERROR("zlib::compress failed, unknown error %d\n",
521 - res);
522 - }
523 -
524 - c_byte = stream->total_out;
525 -
526 - if(res != Z_STREAM_END || c_byte >= size) {
527 -notcompressed:
528 + if(c_byte == 0 || c_byte >= size) {
529 memcpy(d, s, size);
530 return size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :
531 SQUASHFS_COMPRESSED_BIT);
532 }
534 - return (unsigned int) c_byte;
535 + return c_byte;
536 }
539 -unsigned int mangle(char *d, char *s, int size, int block_size,
540 +int mangle(char *d, char *s, int size, int block_size,
541 int uncompressed, int data_block)
542 {
543 - static z_stream *stream = NULL;
544 + static void *stream = NULL;
546 return mangle2(&stream, d, s, size, block_size, uncompressed,
547 data_block);
548 @@ -1660,8 +1613,7 @@
549 pthread_mutex_unlock(&fragment_mutex);
551 if(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {
552 - int res;
553 - unsigned long bytes = block_size;
554 + int error, res;
555 char *data;
557 if(compressed_buffer)
558 @@ -1669,19 +1621,11 @@
559 else
560 data = read_from_disk(start_block, size);
562 - res = uncompress((unsigned char *) buffer->data, &bytes,
563 - (const unsigned char *) data, size);
564 - if(res != Z_OK) {
565 - if(res == Z_MEM_ERROR)
566 - BAD_ERROR("zlib::uncompress failed, not enough "
567 - "memory\n");
568 - else if(res == Z_BUF_ERROR)
569 - BAD_ERROR("zlib::uncompress failed, not enough "
570 - "room in output buffer\n");
571 - else
572 - BAD_ERROR("zlib::uncompress failed,"
573 - " unknown error %d\n", res);
574 - }
575 + res = comp->uncompress(buffer->data, data, size, block_size,
576 + &error);
577 + if(res == -1)
578 + BAD_ERROR("%s uncompress failed with error code %d\n",
579 + comp->name, error);
580 } else if(compressed_buffer)
581 memcpy(buffer->data, compressed_buffer->data, size);
582 else
583 @@ -1733,9 +1677,7 @@
584 entry->buffer->block = bytes;
585 bytes += compressed_size;
586 fragments_outstanding --;
587 - pthread_mutex_unlock(&fragment_mutex);
588 queue_put(to_writer, entry->buffer);
589 - pthread_mutex_lock(&fragment_mutex);
590 TRACE("fragment_locked writing fragment %d, compressed size %d"
591 "\n", entry->fragment, compressed_size);
592 free(entry);
593 @@ -1758,6 +1700,8 @@
594 pthread_mutex_lock(&fragment_mutex);
595 insert_fragment_list(&frag_locked_list, entry);
596 pthread_mutex_unlock(&fragment_mutex);
597 +
598 + return TRUE;
599 }
602 @@ -1824,7 +1768,9 @@
603 unsigned short c_byte;
604 char cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];
606 +#ifdef SQUASHFS_TRACE
607 long long obytes = bytes;
608 +#endif
610 for(i = 0; i < meta_blocks; i++) {
611 int avail_bytes = length > SQUASHFS_METADATA_SIZE ?
612 @@ -2170,11 +2116,85 @@
613 }
616 +static int seq = 0;
617 +void reader_read_process(struct dir_ent *dir_ent)
618 +{
619 + struct file_buffer *prev_buffer = NULL, *file_buffer;
620 + int status, res, byte, count = 0;
621 + int file = get_pseudo_file(dir_ent->inode->pseudo_id)->fd;
622 + int child = get_pseudo_file(dir_ent->inode->pseudo_id)->child;
623 + long long bytes = 0;
624 +
625 + while(1) {
626 + file_buffer = cache_get(reader_buffer, 0, 0);
627 + file_buffer->sequence = seq ++;
628 +
629 + byte = read_bytes(file, file_buffer->data, block_size);
630 + if(byte == -1)
631 + goto read_err;
632 +
633 + file_buffer->size = byte;
634 + file_buffer->file_size = -1;
635 + file_buffer->block = count ++;
636 + file_buffer->error = FALSE;
637 + file_buffer->fragment = FALSE;
638 + bytes += byte;
639 +
640 + if(byte == 0)
641 + break;
642 +
643 + /*
644 + * Update estimated_uncompressed block count. This is done
645 + * on every block rather than waiting for all blocks to be
646 + * read incase write_file_process() is running in parallel
647 + * with this. Otherwise cur uncompressed block count may
648 + * get ahead of the total uncompressed block count.
649 + */
650 + estimated_uncompressed ++;
651 +
652 + if(prev_buffer)
653 + queue_put(from_reader, prev_buffer);
654 + prev_buffer = file_buffer;
655 + }
656 +
657 + /*
658 + * Update inode file size now that the size of the dynamic pseudo file
659 + * is known. This is needed for the -info option.
660 + */
661 + dir_ent->inode->buf.st_size = bytes;
662 +
663 + res = waitpid(child, &status, 0);
664 + if(res == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
665 + goto read_err;
666 +
667 + if(prev_buffer == NULL)
668 + prev_buffer = file_buffer;
669 + else {
670 + cache_block_put(file_buffer);
671 + seq --;
672 + }
673 + prev_buffer->file_size = bytes;
674 + prev_buffer->fragment = !no_fragments &&
675 + (count == 2 || always_use_fragments) && (byte < block_size);
676 + queue_put(from_reader, prev_buffer);
677 +
678 + return;
679 +
680 +read_err:
681 + if(prev_buffer) {
682 + cache_block_put(file_buffer);
683 + seq --;
684 + file_buffer = prev_buffer;
685 + }
686 + file_buffer->error = TRUE;
687 + queue_put(from_deflate, file_buffer);
688 +}
689 +
690 +
691 void reader_read_file(struct dir_ent *dir_ent)
692 {
693 struct stat *buf = &dir_ent->inode->buf, buf2;
694 struct file_buffer *file_buffer;
695 - static int index = 0;
696 int blocks, byte, count, expected, file, frag_block;
697 long long bytes, read_size;
699 @@ -2202,7 +2222,7 @@
700 if(file_buffer)
701 queue_put(from_reader, file_buffer);
702 file_buffer = cache_get(reader_buffer, 0, 0);
703 - file_buffer->sequence = index ++;
704 + file_buffer->sequence = seq ++;
706 byte = file_buffer->size = read_bytes(file, file_buffer->data,
707 block_size);
708 @@ -2238,7 +2258,7 @@
710 read_err:
711 file_buffer = cache_get(reader_buffer, 0, 0);
712 - file_buffer->sequence = index ++;
713 + file_buffer->sequence = seq ++;
714 read_err2:
715 file_buffer->error = TRUE;
716 queue_put(from_deflate, file_buffer);
717 @@ -2262,9 +2282,14 @@
718 for(i = 0; i < dir->count; i++) {
719 struct dir_ent *dir_ent = dir->list[i];
720 struct stat *buf = &dir_ent->inode->buf;
721 - if(dir_ent->data)
722 + if(dir_ent->inode->root_entry)
723 continue;
725 + if(dir_ent->inode->pseudo_file) {
726 + reader_read_process(dir_ent);
727 + continue;
728 + }
729 +
730 switch(buf->st_mode & S_IFMT) {
731 case S_IFREG:
732 reader_read_file(dir_ent);
733 @@ -2365,7 +2390,7 @@
735 void *deflator(void *arg)
736 {
737 - z_stream *stream = NULL;
738 + void *stream = NULL;
739 int oldstate;
741 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
742 @@ -2402,7 +2427,7 @@
744 void *frag_deflator(void *arg)
745 {
746 - z_stream *stream = NULL;
747 + void *stream = NULL;
748 int oldstate;
750 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
751 @@ -2426,8 +2451,8 @@
752 write_buffer->block = bytes;
753 bytes += compressed_size;
754 fragments_outstanding --;
755 - pthread_mutex_unlock(&fragment_mutex);
756 queue_put(to_writer, write_buffer);
757 + pthread_mutex_unlock(&fragment_mutex);
758 TRACE("Writing fragment %lld, uncompressed size %d, "
759 "compressed size %d\n", file_buffer->block,
760 file_buffer->size, compressed_size);
761 @@ -2674,6 +2699,98 @@
762 }
765 +int write_file_process(squashfs_inode *inode, struct dir_ent *dir_ent,
766 + struct file_buffer *read_buffer, int *duplicate_file)
767 +{
768 + long long read_size, file_bytes, start;
769 + struct fragment *fragment;
770 + unsigned int *block_list = NULL;
771 + int block = 0, status;
772 + long long sparse = 0;
773 + struct file_buffer *fragment_buffer = NULL;
774 +
775 + *duplicate_file = FALSE;
776 +
777 + lock_fragments();
778 +
779 + file_bytes = 0;
780 + start = bytes;
781 + while (1) {
782 + read_size = read_buffer->file_size;
783 + if(read_buffer->fragment && read_buffer->c_byte)
784 + fragment_buffer = read_buffer;
785 + else {
786 + block_list = realloc(block_list, (block + 1) *
787 + sizeof(unsigned int));
788 + if(block_list == NULL)
789 + BAD_ERROR("Out of memory allocating block_list"
790 + "\n");
791 + block_list[block ++] = read_buffer->c_byte;
792 + if(read_buffer->c_byte) {
793 + read_buffer->block = bytes;
794 + bytes += read_buffer->size;
795 + cache_rehash(read_buffer, read_buffer->block);
796 + file_bytes += read_buffer->size;
797 + queue_put(to_writer, read_buffer);
798 + } else {
799 + sparse += read_buffer->size;
800 + cache_block_put(read_buffer);
801 + }
802 + }
803 + inc_progress_bar();
804 +
805 + if(read_size != -1)
806 + break;
807 +
808 + read_buffer = get_file_buffer(from_deflate);
809 + if(read_buffer->error)
810 + goto read_err;
811 + }
812 +
813 + unlock_fragments();
814 + fragment = get_and_fill_fragment(fragment_buffer);
815 + cache_block_put(fragment_buffer);
816 +
817 + if(duplicate_checking)
818 + add_non_dup(read_size, file_bytes, block_list, start, fragment,
819 + 0, 0, FALSE);
820 + file_count ++;
821 + total_bytes += read_size;
822 +
823 + if(read_size < (1LL << 32) && start < (1LL << 32) && sparse == 0)
824 + create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,
825 + start, block, block_list, fragment, NULL, 0);
826 + else
827 + create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,
828 + start, block, block_list, fragment, NULL, sparse);
829 +
830 + if(duplicate_checking == FALSE)
831 + free(block_list);
832 +
833 + return 0;
834 +
835 +read_err:
836 + cur_uncompressed -= block;
837 + status = read_buffer->error;
838 + bytes = start;
839 + if(!block_device) {
840 + int res;
841 +
842 + queue_put(to_writer, NULL);
843 + if(queue_get(from_writer) != 0)
844 + EXIT_MKSQUASHFS();
845 + res = ftruncate(fd, bytes);
846 + if(res != 0)
847 + BAD_ERROR("Failed to truncate dest file because %s\n",
848 + strerror(errno));
849 + }
850 + unlock_fragments();
851 + free(block_list);
852 + cache_block_put(read_buffer);
853 + return status;
854 +}
855 +
856 +
857 int write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,
858 long long read_size, struct file_buffer *read_buffer,
859 int *duplicate_file)
860 @@ -2941,7 +3058,10 @@
862 read_size = read_buffer->file_size;
864 - if(read_size == 0) {
865 + if(read_size == -1)
866 + status = write_file_process(inode, dir_ent, read_buffer,
867 + duplicate_file);
868 + else if(read_size == 0) {
869 write_file_empty(inode, dir_ent, duplicate_file);
870 cache_block_put(read_buffer);
871 } else if(read_buffer->fragment && read_buffer->c_byte)
872 @@ -3036,6 +3156,8 @@
874 memcpy(&inode->buf, buf, sizeof(struct stat));
875 inode->read = FALSE;
876 + inode->root_entry = FALSE;
877 + inode->pseudo_file = FALSE;
878 inode->inode = SQUASHFS_INVALID_BLK;
879 inode->nlink = 1;
881 @@ -3056,7 +3178,7 @@
884 inline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,
885 - struct inode_info *inode_info, void *data, struct dir_info *dir)
886 + struct inode_info *inode_info, struct dir_info *dir)
887 {
888 if((dir->count % DIR_ENTRIES) == 0) {
889 dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *
890 @@ -3075,8 +3197,7 @@
891 NULL;
892 dir->list[dir->count]->inode = inode_info;
893 dir->list[dir->count]->dir = sub_dir;
894 - dir->list[dir->count]->our_dir = dir;
895 - dir->list[dir->count++]->data = data;
896 + dir->list[dir->count++]->our_dir = dir;
897 dir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);
898 }
900 @@ -3128,10 +3249,10 @@
902 if(dir->count < old_root_entries)
903 for(i = 0; i < old_root_entries; i++) {
904 - if(old_root_entry[i].type == SQUASHFS_DIR_TYPE)
905 + if(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)
906 dir->directory_count ++;
907 - add_dir_entry(old_root_entry[i].name, "", NULL, NULL,
908 - &old_root_entry[i], dir);
909 + add_dir_entry(old_root_entry[i].name, "", NULL,
910 + &old_root_entry[i].inode, dir);
911 }
913 while(index < source) {
914 @@ -3167,10 +3288,10 @@
916 if(dir->count < old_root_entries)
917 for(i = 0; i < old_root_entries; i++) {
918 - if(old_root_entry[i].type == SQUASHFS_DIR_TYPE)
919 + if(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)
920 dir->directory_count ++;
921 - add_dir_entry(old_root_entry[i].name, "", NULL, NULL,
922 - &old_root_entry[i], dir);
923 + add_dir_entry(old_root_entry[i].name, "", NULL,
924 + &old_root_entry[i].inode, dir);
925 }
927 if((d_name = readdir(dir->linuxdir)) != NULL) {
928 @@ -3215,7 +3336,7 @@
929 int current_count;
931 while((current_count = dir_info->current_count++) < dir_info->count)
932 - if(dir_info->list[current_count]->data)
933 + if(dir_info->list[current_count]->inode->root_entry)
934 continue;
935 else
936 return dir_info->list[current_count];
937 @@ -3240,11 +3361,11 @@
938 int current_count;
940 while((current_count = dir_info->current_count++) < dir_info->count)
941 - if(dir_info->list[current_count]->data)
942 - add_dir(dir_info->list[current_count]->data->inode,
943 - dir_info->list[current_count]->data->inode_number,
944 + if(dir_info->list[current_count]->inode->root_entry)
945 + add_dir(dir_info->list[current_count]->inode->inode,
946 + dir_info->list[current_count]->inode->inode_number,
947 dir_info->list[current_count]->name,
948 - dir_info->list[current_count]->data->type, dir);
949 + dir_info->list[current_count]->inode->type, dir);
950 else
951 return dir_info->list[current_count];
952 return NULL;
953 @@ -3313,7 +3434,6 @@
954 dir_ent->name = dir_ent->pathname = strdup(pathname);
955 dir_ent->dir = dir_info;
956 dir_ent->our_dir = NULL;
957 - dir_ent->data = NULL;
958 dir_info->dir_ent = dir_ent;
960 if(sorted)
961 @@ -3383,7 +3503,7 @@
962 sub_dir = NULL;
964 add_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),
965 - NULL, dir);
966 + dir);
967 }
969 scan1_freedir(dir);
970 @@ -3399,7 +3519,7 @@
971 struct dir_ent *dir_ent;
972 struct pseudo_entry *pseudo_ent;
973 struct stat buf;
974 - static pseudo_ino = 1;
975 + static int pseudo_ino = 1;
977 if(dir == NULL && (dir = scan1_opendir("")) == NULL)
978 return NULL;
979 @@ -3415,6 +3535,29 @@
981 while((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {
982 dir_ent = scan2_lookup(dir, pseudo_ent->name);
983 + if(pseudo_ent->dev->type == 's') {
984 + struct stat *buf;
985 + if(dir_ent == NULL) {
986 + ERROR("Pseudo set file \"%s\" does not exist "
987 + "in source filesystem. Ignoring\n",
988 + pseudo_ent->pathname);
989 + continue;
990 + }
991 + if(dir_ent->inode->root_entry) {
992 + ERROR("Pseudo set file \"%s\" is a pre-existing"
993 + " file in the filesystem being appended"
994 + " to. It cannot be modified. "
995 + "Ignoring!\n", pseudo_ent->pathname);
996 + continue;
997 + }
998 + buf = &dir_ent->inode->buf;
999 + buf->st_mode = (buf->st_mode & S_IFMT) |
1000 + pseudo_ent->dev->mode;
1001 + buf->st_uid = pseudo_ent->dev->uid;
1002 + buf->st_gid = pseudo_ent->dev->gid;
1003 + continue;
1004 + }
1006 if(dir_ent) {
1007 ERROR("Pseudo file \"%s\" exists in source filesystem "
1008 "\"%s\"\n", pseudo_ent->pathname,
1009 @@ -3444,8 +3587,29 @@
1010 buf.st_mtime = time(NULL);
1011 buf.st_ino = pseudo_ino ++;
1013 - add_dir_entry(pseudo_ent->name, pseudo_ent->pathname, sub_dir,
1014 - lookup_inode(&buf), NULL, dir);
1015 + if(pseudo_ent->dev->type == 'f') {
1016 +#ifdef USE_TMP_FILE
1017 + struct stat buf2;
1018 + int res = stat(pseudo_ent->dev->filename, &buf2);
1019 + if(res == -1) {
1020 + ERROR("Stat on pseudo file \"%s\" failed, "
1021 + "skipping...", pseudo_ent->pathname);
1022 + continue;
1023 + }
1024 + buf.st_size = buf2.st_size;
1025 + add_dir_entry(pseudo_ent->name,
1026 + pseudo_ent->dev->filename, sub_dir,
1027 + lookup_inode(&buf), dir);
1028 +#else
1029 + struct inode_info *inode = lookup_inode(&buf);
1030 + inode->pseudo_id = pseudo_ent->dev->pseudo_id;
1031 + inode->pseudo_file = TRUE;
1032 + add_dir_entry(pseudo_ent->name, pseudo_ent->pathname,
1033 + sub_dir, inode, dir);
1034 +#endif
1035 + } else
1036 + add_dir_entry(pseudo_ent->name, pseudo_ent->pathname,
1037 + sub_dir, lookup_inode(&buf), dir);
1040 scan2_freedir(dir);
1041 @@ -3482,8 +3646,9 @@
1042 &duplicate_file);
1043 INFO("file %s, uncompressed size %lld "
1044 "bytes %s\n", filename,
1045 - buf->st_size, duplicate_file ?
1046 - "DUPLICATE" : "");
1047 + (long long) buf->st_size,
1048 + duplicate_file ? "DUPLICATE" :
1049 + "");
1050 break;
1052 case S_IFDIR:
1053 @@ -3557,6 +3722,7 @@
1054 INFO("file %s, uncompressed "
1055 "size %lld bytes LINK"
1056 "\n", filename,
1057 + (long long)
1058 buf->st_size);
1059 break;
1060 case SQUASHFS_SYMLINK_TYPE:
1061 @@ -3667,10 +3833,11 @@
1062 BAD_ERROR("Out of memory in old root directory entries "
1063 "reallocation\n");
1065 - strcpy(old_root_entry[old_root_entries].name, name);
1066 - old_root_entry[old_root_entries].inode = inode;
1067 - old_root_entry[old_root_entries].inode_number = inode_number;
1068 - old_root_entry[old_root_entries++].type = type;
1069 + old_root_entry[old_root_entries].name = strdup(name);
1070 + old_root_entry[old_root_entries].inode.inode = inode;
1071 + old_root_entry[old_root_entries].inode.inode_number = inode_number;
1072 + old_root_entry[old_root_entries].inode.type = type;
1073 + old_root_entry[old_root_entries++].inode.root_entry = TRUE;
1077 @@ -4137,7 +4304,7 @@
1080 #define VERSION() \
1081 - printf("mksquashfs version 4.0 (2009/04/05)\n");\
1082 + printf("mksquashfs version 4.1-CVS (2009/12/08)\n");\
1083 printf("copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n"); \
1084 printf("This program is free software; you can redistribute it and/or\n");\
1085 printf("modify it under the terms of the GNU General Public License\n");\
1086 @@ -4172,26 +4339,28 @@
1087 source_path = argv + 1;
1088 source = i - 2;
1089 for(; i < argc; i++) {
1090 - if(strcmp(argv[i], "-pf") == 0) {
1091 + if(strcmp(argv[i], "-comp") == 0) {
1092 if(++i == argc) {
1093 - ERROR("%s: -pf missing filename\n", argv[0]);
1094 + ERROR("%s: -comp missing compression type\n",
1095 + argv[0]);
1096 exit(1);
1098 - if(read_pseudo_file(&pseudo, argv[i]) == FALSE) {
1099 - ERROR("Failed to parse pseudo file \"%s\"\n",
1100 - argv[i]);
1101 + comp_name = argv[i];
1102 + } else if(strcmp(argv[i], "-pf") == 0) {
1103 + if(++i == argc) {
1104 + ERROR("%s: -pf missing filename\n", argv[0]);
1105 exit(1);
1107 + if(read_pseudo_file(&pseudo, argv[i]) == FALSE)
1108 + exit(1);
1109 } else if(strcmp(argv[i], "-p") == 0) {
1110 if(++i == argc) {
1111 ERROR("%s: -p missing pseudo file definition\n",
1112 argv[0]);
1113 exit(1);
1115 - if(read_pseudo_def(&pseudo, argv[i]) == FALSE) {
1116 - ERROR("Failed to parse pseudo definition\n");
1117 + if(read_pseudo_def(&pseudo, argv[i]) == FALSE)
1118 exit(1);
1119 - }
1120 } else if(strcmp(argv[i], "-recover") == 0) {
1121 if(++i == argc) {
1122 ERROR("%s: -recover missing recovery file\n",
1123 @@ -4394,34 +4563,16 @@
1124 printOptions:
1125 ERROR("SYNTAX:%s source1 source2 ... dest [options] "
1126 "[-e list of exclude\ndirs/files]\n", argv[0]);
1127 - ERROR("\nOptions are\n");
1128 - ERROR("-version\t\tprint version, licence and "
1129 - "copyright message\n");
1130 - ERROR("-recover <name>\t\trecover filesystem data "
1131 - "using recovery file <name>\n");
1132 - ERROR("-no-recovery\t\tdon't generate a recovery "
1133 - "file\n");
1134 - ERROR("-info\t\t\tprint files written to filesystem\n");
1135 - ERROR("-no-exports\t\tdon't make the filesystem "
1136 - "exportable via NFS\n");
1137 - ERROR("-no-progress\t\tdon't display the progress "
1138 - "bar\n");
1139 - ERROR("-no-sparse\t\tdon't detect sparse files\n");
1140 + ERROR("\nFilesystem build options:\n");
1141 + ERROR("-comp <comp>\t\tselect <comp> compression\n");
1142 + ERROR("\t\t\tCompressors available:\n");
1143 + display_compressors("\t\t\t", COMP_DEFAULT);
1144 ERROR("-b <block_size>\t\tset data block to "
1145 "<block_size>. Default %d bytes\n",
1146 SQUASHFS_FILE_SIZE);
1147 - ERROR("-processors <number>\tUse <number> processors."
1148 - " By default will use number of\n");
1149 - ERROR("\t\t\tprocessors available\n");
1150 - ERROR("-read-queue <size>\tSet input queue to <size> "
1151 - "Mbytes. Default %d Mbytes\n",
1152 - READER_BUFFER_DEFAULT);
1153 - ERROR("-write-queue <size>\tSet output queue to <size> "
1154 - "Mbytes. Default %d Mbytes\n",
1155 - WRITER_BUFFER_DEFAULT);
1156 - ERROR("-fragment-queue <size>\tSet fagment queue to "
1157 - "<size> Mbytes. Default %d Mbytes\n",
1158 - FRAGMENT_BUFFER_DEFAULT);
1159 + ERROR("-no-exports\t\tdon't make the filesystem "
1160 + "exportable via NFS\n");
1161 + ERROR("-no-sparse\t\tdon't detect sparse files\n");
1162 ERROR("-noI\t\t\tdo not compress inode table\n");
1163 ERROR("-noD\t\t\tdo not compress data blocks\n");
1164 ERROR("-noF\t\t\tdo not compress fragment blocks\n");
1165 @@ -4430,13 +4581,34 @@
1166 "files larger than block size\n");
1167 ERROR("-no-duplicates\t\tdo not perform duplicate "
1168 "checking\n");
1169 - ERROR("-noappend\t\tdo not append to existing "
1170 - "filesystem\n");
1171 + ERROR("-all-root\t\tmake all files owned by root\n");
1172 + ERROR("-force-uid uid\t\tset all file uids to uid\n");
1173 + ERROR("-force-gid gid\t\tset all file gids to gid\n");
1174 + ERROR("-nopad\t\t\tdo not pad filesystem to a multiple "
1175 + "of 4K\n");
1176 ERROR("-keep-as-directory\tif one source directory is "
1177 "specified, create a root\n");
1178 ERROR("\t\t\tdirectory containing that directory, "
1179 "rather than the\n");
1180 ERROR("\t\t\tcontents of the directory\n");
1181 + ERROR("\nFilesystem filter options:\n");
1182 + ERROR("-p <pseudo-definition>\tAdd pseudo file definition\n");
1183 + ERROR("-pf <pseudo-file>\tAdd list of pseudo file definitions\n");
1184 + ERROR("-sort <sort_file>\tsort files according to "
1185 + "priorities in <sort_file>. One\n");
1186 + ERROR("\t\t\tfile or dir with priority per line. "
1187 + "Priority -32768 to\n");
1188 + ERROR("\t\t\t32767, default priority 0\n");
1189 + ERROR("-ef <exclude_file>\tlist of exclude dirs/files."
1190 + " One per line\n");
1191 + ERROR("-wildcards\t\tAllow extended shell wildcards "
1192 + "(globbing) to be used in\n\t\t\texclude "
1193 + "dirs/files\n");
1194 + ERROR("-regex\t\t\tAllow POSIX regular expressions to "
1195 + "be used in exclude\n\t\t\tdirs/files\n");
1196 + ERROR("\nFilesystem append options:\n");
1197 + ERROR("-noappend\t\tdo not append to existing "
1198 + "filesystem\n");
1199 ERROR("-root-becomes <name>\twhen appending source "
1200 "files/directories, make the\n");
1201 ERROR("\t\t\toriginal root become a subdirectory in "
1202 @@ -4444,11 +4616,29 @@
1203 ERROR("\t\t\tcalled <name>, rather than adding the new "
1204 "source items\n");
1205 ERROR("\t\t\tto the original root\n");
1206 - ERROR("-all-root\t\tmake all files owned by root\n");
1207 - ERROR("-force-uid uid\t\tset all file uids to uid\n");
1208 - ERROR("-force-gid gid\t\tset all file gids to gid\n");
1209 - ERROR("-nopad\t\t\tdo not pad filesystem to a multiple "
1210 - "of 4K\n");
1211 + ERROR("\nMksquashfs runtime options:\n");
1212 + ERROR("-version\t\tprint version, licence and "
1213 + "copyright message\n");
1214 + ERROR("-recover <name>\t\trecover filesystem data "
1215 + "using recovery file <name>\n");
1216 + ERROR("-no-recovery\t\tdon't generate a recovery "
1217 + "file\n");
1218 + ERROR("-info\t\t\tprint files written to filesystem\n");
1219 + ERROR("-no-progress\t\tdon't display the progress "
1220 + "bar\n");
1221 + ERROR("-processors <number>\tUse <number> processors."
1222 + " By default will use number of\n");
1223 + ERROR("\t\t\tprocessors available\n");
1224 + ERROR("-read-queue <size>\tSet input queue to <size> "
1225 + "Mbytes. Default %d Mbytes\n",
1226 + READER_BUFFER_DEFAULT);
1227 + ERROR("-write-queue <size>\tSet output queue to <size> "
1228 + "Mbytes. Default %d Mbytes\n",
1229 + WRITER_BUFFER_DEFAULT);
1230 + ERROR("-fragment-queue <size>\tSet fagment queue to "
1231 + "<size> Mbytes. Default %d Mbytes\n",
1232 + FRAGMENT_BUFFER_DEFAULT);
1233 + ERROR("\nMiscellaneous options:\n");
1234 ERROR("-root-owned\t\talternative name for -all-root"
1235 "\n");
1236 ERROR("-noInodeCompression\talternative name for -noI"
1237 @@ -4457,20 +4647,8 @@
1238 "\n");
1239 ERROR("-noFragmentCompression\talternative name for "
1240 "-noF\n");
1241 - ERROR("-sort <sort_file>\tsort files according to "
1242 - "priorities in <sort_file>. One\n");
1243 - ERROR("\t\t\tfile or dir with priority per line. "
1244 - "Priority -32768 to\n");
1245 - ERROR("\t\t\t32767, default priority 0\n");
1246 - ERROR("-ef <exclude_file>\tlist of exclude dirs/files."
1247 - " One per line\n");
1248 - ERROR("-wildcards\t\tAllow extended shell wildcards "
1249 - "(globbing) to be used in\n\t\t\texclude "
1250 - "dirs/files\n");
1251 - ERROR("-regex\t\t\tAllow POSIX regular expressions to "
1252 - "be used in exclude\n\t\t\tdirs/files\n");
1253 - ERROR("-p <pseudo-definition>\tAdd pseudo file definition\n");
1254 - ERROR("-pf <pseudo-file>\tAdd list of pseudo file definitions\n");
1255 + ERROR("\nCompressors available:\n");
1256 + display_compressors("", COMP_DEFAULT);
1257 exit(1);
1260 @@ -4548,11 +4726,10 @@
1261 fclose(fd);
1262 } else if(strcmp(argv[i], "-e") == 0)
1263 break;
1264 - else if(strcmp(argv[i], "-b") == 0 ||
1265 - strcmp(argv[i], "-root-becomes") == 0 ||
1266 + else if(strcmp(argv[i], "-root-becomes") == 0 ||
1267 strcmp(argv[i], "-sort") == 0 ||
1268 strcmp(argv[i], "-pf") == 0 ||
1269 - strcmp(argv[i], "-p") == 0)
1270 + strcmp(argv[i], "-comp") == 0)
1271 i++;
1273 if(i != argc) {
1274 @@ -4574,11 +4751,10 @@
1275 sorted ++;
1276 } else if(strcmp(argv[i], "-e") == 0)
1277 break;
1278 - else if(strcmp(argv[i], "-b") == 0 ||
1279 - strcmp(argv[i], "-root-becomes") == 0 ||
1280 + else if(strcmp(argv[i], "-root-becomes") == 0 ||
1281 strcmp(argv[i], "-ef") == 0 ||
1282 strcmp(argv[i], "-pf") == 0 ||
1283 - strcmp(argv[i], "-p") == 0)
1284 + strcmp(argv[i], "-comp") == 0)
1285 i++;
1287 #ifdef SQUASHFS_TRACE
1288 @@ -4586,7 +4762,8 @@
1289 #endif
1291 if(!delete) {
1292 - if(read_super(fd, &sBlk, argv[source + 1]) == 0) {
1293 + comp = read_super(fd, &sBlk, argv[source + 1]);
1294 + if(comp == NULL) {
1295 ERROR("Failed to read existing filesystem - will not "
1296 "overwrite - ABORTING!\n");
1297 ERROR("To force Mksquashfs to write to this block "
1298 @@ -4603,6 +4780,15 @@
1299 always_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);
1300 duplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);
1301 exportable = SQUASHFS_EXPORTABLE(sBlk.flags);
1302 + } else {
1303 + comp = lookup_compressor(comp_name);
1304 + if(!comp->supported) {
1305 + ERROR("FATAL_ERROR: Compressor \"%s\" is not "
1306 + "supported!\n", comp_name);
1307 + ERROR("Compressors available:\n");
1308 + display_compressors("", COMP_DEFAULT);
1309 + EXIT_MKSQUASHFS();
1310 + }
1313 initialise_threads();
1314 @@ -4648,8 +4834,8 @@
1315 "size %d\n", SQUASHFS_MAJOR, s_minor, argv[source + 1],
1316 block_size);
1317 printf("All -b, -noI, -noD, -noF, no-duplicates, no-fragments, "
1318 - "-always-use-fragments and -exportable options ignored"
1319 - "\n");
1320 + "-always-use-fragments,\n-exportable and -comp options "
1321 + "ignored\n");
1322 printf("\nIf appending is not wanted, please re-run with "
1323 "-noappend specified!\n\n");
1325 @@ -4803,8 +4989,7 @@
1327 sBlk.bytes_used = bytes;
1329 - /* Only compression supported */
1330 - sBlk.compression = ZLIB_COMPRESSION;
1331 + sBlk.compression = comp->id;
1333 /* Xattrs are not currently supported */
1334 sBlk.xattr_table_start = SQUASHFS_INVALID_BLK;
1335 @@ -4820,6 +5005,8 @@
1337 close(fd);
1339 + delete_pseudo_files();
1341 if(recovery_file[0] != '\0')
1342 unlink(recovery_file);
1344 @@ -4827,9 +5014,9 @@
1345 * sizeof(unsigned short) + guid_count * sizeof(unsigned short) +
1346 sizeof(squashfs_super_block);
1348 - printf("\n%sSquashfs %d.%d filesystem, data block size %d\n",
1349 - exportable ? "Exportable " : "", SQUASHFS_MAJOR, SQUASHFS_MINOR,
1350 - block_size);
1351 + printf("\n%sSquashfs %d.%d filesystem, %s compressed, data block size"
1352 + " %d\n", exportable ? "Exportable " : "", SQUASHFS_MAJOR,
1353 + SQUASHFS_MINOR, comp->name, block_size);
1354 printf("\t%s data, %s metadata, %s fragments\n",
1355 noD ? "uncompressed" : "compressed", noI ? "uncompressed" :
1356 "compressed", no_fragments ? "no" : noF ? "uncompressed" :
1358 --- squashfs-4.0/squashfs-tools/par_mksquashfs/README Thu Jan 1 01:00:00 1970
1359 +++ squashfs-4.0/squashfs-tools/par_mksquashfs/README Mon Nov 6 01:27:32 2006
1360 @@ -0,0 +1,2 @@
1361 +par_mksquashfs is now the standard mksquashfs, and so this directory is now empty.
1364 --- squashfs-4.0/squashfs-tools/pseudo.c Sun Apr 5 04:01:58 2009
1365 +++ squashfs-4.0/squashfs-tools/pseudo.c Thu Sep 10 06:17:48 2009
1366 @@ -30,6 +30,7 @@
1367 #include <string.h>
1368 #include <stdlib.h>
1369 #include <sys/types.h>
1370 +#include <sys/wait.h>
1372 #include "pseudo.h"
1374 @@ -55,6 +56,9 @@
1375 #define TRUE 1
1376 #define FALSE 0
1378 +struct pseudo_dev **pseudo_file = NULL;
1379 +int pseudo_count = 0;
1381 static void dump_pseudo(struct pseudo *pseudo, char *string)
1383 int i;
1384 @@ -99,7 +103,7 @@
1385 char *target, char *alltarget)
1387 char targname[1024];
1388 - int i, error;
1389 + int i;
1391 target = get_component(target, targname);
1393 @@ -128,12 +132,8 @@
1394 if(target[0] == '\0') {
1395 /* at leaf pathname component */
1396 pseudo->name[i].pseudo = NULL;
1397 - pseudo->name[i].dev = malloc(sizeof(struct pseudo_dev));
1398 - if(pseudo->name[i].dev == NULL)
1399 - BAD_ERROR("failed to allocate pseudo file\n");
1400 pseudo->name[i].pathname = strdup(alltarget);
1401 - memcpy(pseudo->name[i].dev, pseudo_dev,
1402 - sizeof(struct pseudo_dev));
1403 + pseudo->name[i].dev = pseudo_dev;
1404 } else {
1405 /* recurse adding child components */
1406 pseudo->name[i].dev = NULL;
1407 @@ -169,15 +169,9 @@
1408 if(target[0] == '\0') {
1409 if(pseudo->name[i].dev == NULL &&
1410 pseudo_dev->type == 'd') {
1411 - pseudo->name[i].dev =
1412 - malloc(sizeof(struct pseudo_dev));
1413 - if(pseudo->name[i].dev == NULL)
1414 - BAD_ERROR("failed to allocate "
1415 - "pseudo file\n");
1416 pseudo->name[i].pathname =
1417 strdup(alltarget);
1418 - memcpy(pseudo->name[i].dev, pseudo_dev,
1419 - sizeof(struct pseudo_dev));
1420 + pseudo->name[i].dev = pseudo_dev;
1421 } else
1422 ERROR("%s already exists as a "
1423 "directory. Ignoring %s!\n",
1424 @@ -229,16 +223,113 @@
1428 +int exec_file(char *command, struct pseudo_dev *dev)
1429 +{
1430 + int child, res;
1431 + static pid_t pid = -1;
1432 + int pipefd[2];
1433 +#ifdef USE_TMP_FILE
1434 + char filename[1024];
1435 + int status;
1436 + static int number = 0;
1437 +#endif
1439 + if(pid == -1)
1440 + pid = getpid();
1442 +#ifdef USE_TMP_FILE
1443 + sprintf(filename, "/tmp/squashfs_pseudo_%d_%d", pid, number ++);
1444 + pipefd[1] = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
1445 + if(pipefd[1] == -1) {
1446 + printf("open failed\n");
1447 + return -1;
1448 + }
1449 +#else
1450 + res = pipe(pipefd);
1451 + if(res == -1) {
1452 + printf("pipe failed\n");
1453 + return -1;
1454 + }
1455 +#endif
1457 + child = fork();
1458 + if(child == -1) {
1459 + printf("fork failed\n");
1460 + goto failed;
1461 + }
1463 + if(child == 0) {
1464 + close(STDOUT_FILENO);
1465 + res = dup(pipefd[1]);
1466 + if(res == -1) {
1467 + printf("dup failed\n");
1468 + exit(EXIT_FAILURE);
1469 + }
1470 + execl("/bin/sh", "sh", "-c", command, (char *) NULL);
1471 + printf("execl failed\n");
1472 + exit(EXIT_FAILURE);
1473 + }
1475 +#ifdef USE_TMP_FILE
1476 + res = waitpid(child, &status, 0);
1477 + close(pipefd[1]);
1478 + if(res != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
1479 + dev->filename = strdup(filename);
1480 + return 0;
1481 + }
1482 +failed:
1483 + unlink(filename);
1484 + return -1;
1485 +#else
1486 + close(pipefd[1]);
1487 + dev->fd = pipefd[0];
1488 + dev->child = child;
1489 + return 0;
1490 +failed:
1491 + return -1;
1492 +#endif
1493 +}
1496 +void add_pseudo_file(struct pseudo_dev *dev)
1497 +{
1498 + pseudo_file = realloc(pseudo_file, (pseudo_count + 1) *
1499 + sizeof(struct pseudo_dev *));
1500 + if(pseudo_file == NULL)
1501 + BAD_ERROR("Failed to realloc pseudo_file\n");
1503 + dev->pseudo_id = pseudo_count;
1504 + pseudo_file[pseudo_count ++] = dev;
1505 +}
1508 +void delete_pseudo_files()
1509 +{
1510 +#ifdef USE_TMP_FILE
1511 + int i;
1513 + for(i = 0; i < pseudo_count; i++)
1514 + unlink(pseudo_file[i]->filename);
1515 +#endif
1516 +}
1519 +struct pseudo_dev *get_pseudo_file(int pseudo_id)
1520 +{
1521 + return pseudo_file[pseudo_id];
1522 +}
1525 int read_pseudo_def(struct pseudo **pseudo, char *def)
1527 - int n;
1528 + int n, bytes;
1529 unsigned int major = 0, minor = 0, mode;
1530 char filename[2048], type, suid[100], sgid[100], *ptr;
1531 long long uid, gid;
1532 - struct pseudo_dev dev;
1533 + struct pseudo_dev *dev;
1535 - n = sscanf(def, "%s %c %o %s %s %u %u", filename, &type, &mode, suid, sgid,
1536 - &major, &minor);
1537 + n = sscanf(def, "%s %c %o %s %s %n", filename, &type, &mode, suid,
1538 + sgid, &bytes);
1540 if(n < 5) {
1541 ERROR("Not enough or invalid arguments in pseudo file "
1542 @@ -249,7 +340,9 @@
1543 switch(type) {
1544 case 'b':
1545 case 'c':
1546 - if(n < 7) {
1547 + n = sscanf(def + bytes, "%u %u", &major, &minor);
1549 + if(n < 2) {
1550 ERROR("Not enough or invalid arguments in pseudo file "
1551 "definition\n");
1552 goto error;
1553 @@ -265,54 +358,59 @@
1554 goto error;
1557 - /* fall through */
1558 - case 'd':
1559 - if(mode > 0777) {
1560 - ERROR("Mode %o out of range\n", mode);
1561 + case 'f':
1562 + if(def[bytes] == '\0') {
1563 + ERROR("Not enough arguments in pseudo file "
1564 + "definition\n");
1565 goto error;
1566 - }
1568 - uid = strtoll(suid, &ptr, 10);
1569 - if(*ptr == '\0') {
1570 - if(uid < 0 || uid > ((1LL << 32) - 1)) {
1571 - ERROR("Uid %s out of range\n", suid);
1572 - goto error;
1573 - }
1574 - } else {
1575 - struct passwd *pwuid = getpwnam(suid);
1576 - if(pwuid)
1577 - uid = pwuid->pw_uid;
1578 - else {
1579 - ERROR("Uid %s invalid uid or unknown user\n",
1580 - suid);
1581 - goto error;
1582 - }
1583 - }
1585 - gid = strtoll(sgid, &ptr, 10);
1586 - if(*ptr == '\0') {
1587 - if(gid < 0 || gid > ((1LL << 32) - 1)) {
1588 - ERROR("Gid %s out of range\n", sgid);
1589 - goto error;
1590 - }
1591 - } else {
1592 - struct group *grgid = getgrnam(sgid);
1593 - if(grgid)
1594 - gid = grgid->gr_gid;
1595 - else {
1596 - ERROR("Gid %s invalid uid or unknown user\n",
1597 - sgid);
1598 - goto error;
1599 - }
1600 - }
1602 + }
1603 break;
1604 + case 'd':
1605 + case 'm':
1606 + break;
1607 default:
1608 ERROR("Unsupported type %c\n", type);
1609 goto error;
1613 + if(mode > 0777) {
1614 + ERROR("Mode %o out of range\n", mode);
1615 + goto error;
1616 + }
1618 + uid = strtoll(suid, &ptr, 10);
1619 + if(*ptr == '\0') {
1620 + if(uid < 0 || uid > ((1LL << 32) - 1)) {
1621 + ERROR("Uid %s out of range\n", suid);
1622 + goto error;
1623 + }
1624 + } else {
1625 + struct passwd *pwuid = getpwnam(suid);
1626 + if(pwuid)
1627 + uid = pwuid->pw_uid;
1628 + else {
1629 + ERROR("Uid %s invalid uid or unknown user\n", suid);
1630 + goto error;
1631 + }
1632 + }
1634 + gid = strtoll(sgid, &ptr, 10);
1635 + if(*ptr == '\0') {
1636 + if(gid < 0 || gid > ((1LL << 32) - 1)) {
1637 + ERROR("Gid %s out of range\n", sgid);
1638 + goto error;
1639 + }
1640 + } else {
1641 + struct group *grgid = getgrnam(sgid);
1642 + if(grgid)
1643 + gid = grgid->gr_gid;
1644 + else {
1645 + ERROR("Gid %s invalid uid or unknown user\n", sgid);
1646 + goto error;
1647 + }
1648 + }
1650 switch(type) {
1651 case 'b':
1652 mode |= S_IFBLK;
1653 @@ -323,16 +421,37 @@
1654 case 'd':
1655 mode |= S_IFDIR;
1656 break;
1657 + case 'f':
1658 + mode |= S_IFREG;
1659 + break;
1662 - dev.type = type;
1663 - dev.mode = mode;
1664 - dev.uid = uid;
1665 - dev.gid = gid;
1666 - dev.major = major;
1667 - dev.minor = minor;
1668 + dev = malloc(sizeof(struct pseudo_dev));
1669 + if(dev == NULL)
1670 + BAD_ERROR("Failed to create pseudo_dev\n");
1672 - *pseudo = add_pseudo(*pseudo, &dev, filename, filename);
1673 + dev->type = type;
1674 + dev->mode = mode;
1675 + dev->uid = uid;
1676 + dev->gid = gid;
1677 + dev->major = major;
1678 + dev->minor = minor;
1680 + if(type == 'f') {
1681 + int res;
1683 + printf("Executing dynamic pseudo file\n");
1684 + printf("\t\"%s\"\n", def);
1685 + res = exec_file(def + bytes, dev);
1686 + if(res == -1) {
1687 + ERROR("Failed to execute dynamic pseudo file definition"
1688 + " \"%s\"\n", def);
1689 + return FALSE;
1690 + }
1691 + add_pseudo_file(dev);
1692 + }
1694 + *pseudo = add_pseudo(*pseudo, dev, filename, filename);
1696 return TRUE;
1699 --- squashfs-4.0/squashfs-tools/pseudo.h Sat Apr 4 03:44:24 2009
1700 +++ squashfs-4.0/squashfs-tools/pseudo.h Fri Sep 11 14:10:58 2009
1701 @@ -27,6 +27,12 @@
1702 unsigned int gid;
1703 unsigned int major;
1704 unsigned int minor;
1705 + int pseudo_id;
1706 + int fd;
1707 + int child;
1708 +#ifdef USE_TMP_FILE
1709 + char *filename;
1710 +#endif
1711 };
1713 struct pseudo_entry {
1714 @@ -46,3 +52,5 @@
1715 extern int read_pseudo_file(struct pseudo **, char *);
1716 extern struct pseudo *pseudo_subdir(char *, struct pseudo *);
1717 extern struct pseudo_entry *pseudo_readdir(struct pseudo *);
1718 +extern struct pseudo_dev *get_pseudo_file(int);
1719 +extern void delete_pseudo_files();
1721 --- squashfs-4.0/squashfs-tools/read_fs.c Tue Mar 31 06:23:14 2009
1722 +++ squashfs-4.0/squashfs-tools/read_fs.c Mon Aug 24 20:28:04 2009
1723 @@ -36,7 +36,6 @@
1724 #include <fcntl.h>
1725 #include <errno.h>
1726 #include <string.h>
1727 -#include <zlib.h>
1728 #include <sys/mman.h>
1730 #ifndef linux
1731 @@ -51,6 +50,7 @@
1732 #include "squashfs_swap.h"
1733 #include "read_fs.h"
1734 #include "global.h"
1735 +#include "compressor.h"
1737 #include <stdlib.h>
1739 @@ -66,7 +66,9 @@
1740 fprintf(stderr, s, ## args); \
1741 } while(0)
1743 -int read_block(int fd, long long start, long long *next, unsigned char *block,
1744 +static struct compressor *comp;
1746 +int read_block(int fd, long long start, long long *next, void *block,
1747 squashfs_super_block *sBlk)
1749 unsigned short c_byte;
1750 @@ -77,32 +79,24 @@
1752 if(SQUASHFS_COMPRESSED(c_byte)) {
1753 char buffer[SQUASHFS_METADATA_SIZE];
1754 - int res;
1755 - unsigned long bytes = SQUASHFS_METADATA_SIZE;
1756 + int error, res;
1758 c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
1759 read_destination(fd, start + offset, c_byte, buffer);
1761 - res = uncompress(block, &bytes, (const unsigned char *) buffer,
1762 - c_byte);
1763 - if(res != Z_OK) {
1764 - if(res == Z_MEM_ERROR)
1765 - ERROR("zlib::uncompress failed, not enough "
1766 - "memory\n");
1767 - else if(res == Z_BUF_ERROR)
1768 - ERROR("zlib::uncompress failed, not enough "
1769 - "room in output buffer\n");
1770 - else
1771 - ERROR("zlib::uncompress failed, unknown error "
1772 - "%d\n", res);
1773 + res = comp->uncompress(block, buffer, c_byte,
1774 + SQUASHFS_METADATA_SIZE, &error);
1775 + if(res == -1) {
1776 + ERROR("%s uncompress failed with error code %d\n",
1777 + comp->name, error);
1778 return 0;
1780 if(next)
1781 *next = start + offset + c_byte;
1782 - return bytes;
1783 + return res;
1784 } else {
1785 c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
1786 - read_destination(fd, start + offset, c_byte, (char *) block);
1787 + read_destination(fd, start + offset, c_byte, block);
1788 if(next)
1789 *next = start + offset + c_byte;
1790 return c_byte;
1791 @@ -356,7 +350,7 @@
1795 -int read_super(int fd, squashfs_super_block *sBlk, char *source)
1796 +struct compressor *read_super(int fd, squashfs_super_block *sBlk, char *source)
1798 read_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),
1799 (char *) sBlk);
1800 @@ -388,8 +382,18 @@
1801 goto failed_mount;
1804 + /* Check the compression type */
1805 + comp = lookup_compressor_id(sBlk->compression);
1806 + if(!comp->supported) {
1807 + ERROR("Filesystem on %s uses %s compression, this is"
1808 + "unsupported by this version\n", source, comp->name);
1809 + display_compressors("", "");
1810 + goto failed_mount;
1811 + }
1813 printf("Found a valid %sSQUASHFS superblock on %s.\n",
1814 SQUASHFS_EXPORTABLE(sBlk->flags) ? "exportable " : "", source);
1815 + printf("\tCompression used %s\n", comp->name);
1816 printf("\tInodes are %scompressed\n",
1817 SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
1818 printf("\tData is %scompressed\n",
1819 @@ -417,10 +421,10 @@
1820 TRACE("sBlk->lookup_table_start %llx\n", sBlk->lookup_table_start);
1821 printf("\n");
1823 - return TRUE;
1824 + return comp;
1826 failed_mount:
1827 - return FALSE;
1828 + return NULL;
1832 @@ -514,12 +518,17 @@
1833 SQUASHFS_INSWAP_ID_BLOCKS(index, indexes);
1835 for(i = 0; i < indexes; i++) {
1836 - int length;
1837 - length = read_block(fd, index[i], NULL,
1838 + int length = read_block(fd, index[i], NULL,
1839 ((unsigned char *) id_table) +
1840 (i * SQUASHFS_METADATA_SIZE), sBlk);
1841 TRACE("Read id table block %d, from 0x%llx, length %d\n", i,
1842 index[i], length);
1843 + if(length == 0) {
1844 + ERROR("Failed to read id table block %d, from 0x%llx, "
1845 + "length %d\n", i, index[i], length);
1846 + free(id_table);
1847 + return NULL;
1848 + }
1851 SQUASHFS_INSWAP_INTS(id_table, sBlk->no_ids);
1852 @@ -563,6 +572,13 @@
1853 (i * SQUASHFS_METADATA_SIZE), sBlk);
1854 TRACE("Read fragment table block %d, from 0x%llx, length %d\n",
1855 i, fragment_table_index[i], length);
1856 + if(length == 0) {
1857 + ERROR("Failed to read fragment table block %d, from "
1858 + "0x%llx, length %d\n", i,
1859 + fragment_table_index[i], length);
1860 + free(*fragment_table);
1861 + return 0;
1862 + }
1865 for(i = 0; i < sBlk->fragments; i++)
1866 @@ -599,6 +615,13 @@
1867 (i * SQUASHFS_METADATA_SIZE), sBlk);
1868 TRACE("Read inode lookup table block %d, from 0x%llx, length "
1869 "%d\n", i, index[i], length);
1870 + if(length == 0) {
1871 + ERROR("Failed to read inode lookup table block %d, "
1872 + "from 0x%llx, length %d\n", i, index[i],
1873 + length);
1874 + free(*inode_lookup_table);
1875 + return 0;
1876 + }
1879 SQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);
1881 --- squashfs-4.0/squashfs-tools/sort.c Tue Mar 31 06:25:53 2009
1882 +++ squashfs-4.0/squashfs-tools/sort.c Sat Aug 29 07:41:45 2009
1883 @@ -198,7 +198,7 @@
1884 while(dir->current_count < dir->count) {
1885 struct dir_ent *dir_ent = dir->list[dir->current_count++];
1886 struct stat *buf = &dir_ent->inode->buf;
1887 - if(dir_ent->data)
1888 + if(dir_ent->inode->root_entry)
1889 continue;
1891 switch(buf->st_mode & S_IFMT) {
1892 @@ -254,6 +254,7 @@
1893 write_file(&inode, entry->dir, &duplicate_file);
1894 INFO("file %s, uncompressed size %lld bytes %s"
1895 "\n", entry->dir->pathname,
1896 + (long long)
1897 entry->dir->inode->buf.st_size,
1898 duplicate_file ? "DUPLICATE" : "");
1899 entry->dir->inode->inode = inode;
1900 @@ -261,6 +262,7 @@
1901 } else
1902 INFO("file %s, uncompressed size %lld bytes "
1903 "LINK\n", entry->dir->pathname,
1904 + (long long)
1905 entry->dir->inode->buf.st_size);
1909 --- squashfs-4.0/squashfs-tools/sort.h Sun Feb 8 13:02:53 2009
1910 +++ squashfs-4.0/squashfs-tools/sort.h Thu Sep 10 05:50:01 2009
1911 @@ -42,17 +42,19 @@
1912 struct inode_info *inode;
1913 struct dir_info *dir;
1914 struct dir_info *our_dir;
1915 - struct old_root_entry_info *data;
1916 };
1918 struct inode_info {
1919 - unsigned int nlink;
1920 struct stat buf;
1921 + struct inode_info *next;
1922 squashfs_inode inode;
1923 - unsigned int type;
1924 unsigned int inode_number;
1925 + unsigned int nlink;
1926 + int pseudo_id;
1927 + char type;
1928 char read;
1929 - struct inode_info *next;
1930 + char root_entry;
1931 + char pseudo_file;
1932 };
1934 struct priority_entry {
1936 --- squashfs-4.0/squashfs-tools/squashfs_compat.h Mon Mar 16 05:27:27 2009
1937 +++ squashfs-4.0/squashfs-tools/squashfs_compat.h Tue Apr 21 02:52:24 2009
1938 @@ -777,11 +777,10 @@
1939 #endif
1941 #define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1942 - int bits;\
1943 - int b_pos = pos % 8;\
1944 - unsigned long long val = 0;\
1945 - unsigned char *s = (unsigned char *)p + (pos / 8);\
1946 - unsigned char *d = ((unsigned char *) &val) + 7;\
1947 + b_pos = pos % 8;\
1948 + val = 0;\
1949 + s = (unsigned char *)p + (pos / 8);\
1950 + d = ((unsigned char *) &val) + 7;\
1951 for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1952 *d-- = *s++;\
1953 value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
1955 --- squashfs-4.0/squashfs-tools/squashfs_fs.h Wed Mar 18 03:50:20 2009
1956 +++ squashfs-4.0/squashfs-tools/squashfs_fs.h Thu Jul 30 06:45:38 2009
1957 @@ -229,6 +229,7 @@
1958 typedef long long squashfs_inode_t;
1960 #define ZLIB_COMPRESSION 1
1961 +#define LZMA_COMPRESSION 2
1963 struct squashfs_super_block {
1964 unsigned int s_magic;
1966 --- squashfs-4.0/squashfs-tools/unsquash-3.c Tue Mar 31 06:35:10 2009
1967 +++ squashfs-4.0/squashfs-tools/unsquash-3.c Tue Apr 21 02:58:22 2009
1968 @@ -36,7 +36,7 @@
1969 sBlk.fragment_table_start);
1971 if(sBlk.fragments == 0)
1972 - return;
1973 + return TRUE;
1975 if((fragment_table = malloc(sBlk.fragments *
1976 sizeof(squashfs_fragment_entry_3))) == NULL)
1978 --- squashfs-4.0/squashfs-tools/unsquash-4.c Tue Mar 31 06:38:31 2009
1979 +++ squashfs-4.0/squashfs-tools/unsquash-4.c Tue Apr 21 02:59:16 2009
1980 @@ -38,7 +38,7 @@
1981 sBlk.fragment_table_start);
1983 if(sBlk.fragments == 0)
1984 - return;
1985 + return TRUE;
1987 if((fragment_table = malloc(sBlk.fragments *
1988 sizeof(squashfs_fragment_entry))) == NULL)
1990 --- squashfs-4.0/squashfs-tools/unsquashfs.c Sun Apr 5 23:23:06 2009
1991 +++ squashfs-4.0/squashfs-tools/unsquashfs.c Sun Aug 30 16:10:31 2009
1992 @@ -25,7 +25,10 @@
1993 #include "squashfs_swap.h"
1994 #include "squashfs_compat.h"
1995 #include "read_fs.h"
1996 +#include "compressor.h"
1998 +#include <sys/sysinfo.h>
2000 struct cache *fragment_cache, *data_cache;
2001 struct queue *to_reader, *to_deflate, *to_writer, *from_writer;
2002 pthread_t *thread, *deflator_thread;
2003 @@ -36,6 +39,7 @@
2005 struct super_block sBlk;
2006 squashfs_operations s_ops;
2007 +struct compressor *comp;
2009 int bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,
2010 dev_count = 0, fifo_count = 0;
2011 @@ -590,31 +594,23 @@
2012 offset = 3;
2013 if(SQUASHFS_COMPRESSED(c_byte)) {
2014 char buffer[SQUASHFS_METADATA_SIZE];
2015 - int res;
2016 - unsigned long bytes = SQUASHFS_METADATA_SIZE;
2017 + int error, res;
2019 c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
2020 if(read_bytes(start + offset, c_byte, buffer) == FALSE)
2021 goto failed;
2023 - res = uncompress((unsigned char *) block, &bytes,
2024 - (const unsigned char *) buffer, c_byte);
2025 + res = comp->uncompress(block, buffer, c_byte,
2026 + SQUASHFS_METADATA_SIZE, &error);
2028 - if(res != Z_OK) {
2029 - if(res == Z_MEM_ERROR)
2030 - ERROR("zlib::uncompress failed, not enough "
2031 - "memory\n");
2032 - else if(res == Z_BUF_ERROR)
2033 - ERROR("zlib::uncompress failed, not enough "
2034 - "room in output buffer\n");
2035 - else
2036 - ERROR("zlib::uncompress failed, unknown error "
2037 - "%d\n", res);
2038 + if(res == -1) {
2039 + ERROR("%s uncompress failed with error code %d\n",
2040 + comp->name, error);
2041 goto failed;
2043 if(next)
2044 *next = start + offset + c_byte;
2045 - return bytes;
2046 + return res;
2047 } else {
2048 c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
2049 if(read_bytes(start + offset, c_byte, block) == FALSE)
2050 @@ -632,36 +628,26 @@
2052 int read_data_block(long long start, unsigned int size, char *block)
2054 - int res;
2055 - unsigned long bytes = block_size;
2056 + int error, res;
2057 int c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);
2059 TRACE("read_data_block: block @0x%llx, %d %s bytes\n", start,
2060 - SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte),
2061 - SQUASHFS_COMPRESSED_BLOCK(c_byte) ? "compressed" :
2062 + c_byte, SQUASHFS_COMPRESSED_BLOCK(size) ? "compressed" :
2063 "uncompressed");
2065 if(SQUASHFS_COMPRESSED_BLOCK(size)) {
2066 if(read_bytes(start, c_byte, data) == FALSE)
2067 goto failed;
2069 - res = uncompress((unsigned char *) block, &bytes,
2070 - (const unsigned char *) data, c_byte);
2071 + res = comp->uncompress(block, data, c_byte, block_size, &error);
2073 - if(res != Z_OK) {
2074 - if(res == Z_MEM_ERROR)
2075 - ERROR("zlib::uncompress failed, not enough "
2076 - "memory\n");
2077 - else if(res == Z_BUF_ERROR)
2078 - ERROR("zlib::uncompress failed, not enough "
2079 - "room in output buffer\n");
2080 - else
2081 - ERROR("zlib::uncompress failed, unknown error "
2082 - "%d\n", res);
2083 + if(res == -1) {
2084 + ERROR("%s uncompress failed with error code %d\n",
2085 + comp->name, error);
2086 goto failed;
2089 - return bytes;
2090 + return res;
2091 } else {
2092 if(read_bytes(start, c_byte, block) == FALSE)
2093 goto failed;
2094 @@ -671,7 +657,7 @@
2096 failed:
2097 ERROR("read_data_block: failed to read block @0x%llx, size %d\n", start,
2098 - size);
2099 + c_byte);
2100 return FALSE;
2103 @@ -1383,6 +1369,11 @@
2104 #endif
2105 printf("Creation or last append time %s", mkfs_str ? mkfs_str :
2106 "failed to get time\n");
2107 + printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n",
2108 + sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));
2109 + if(sBlk.s_major == 4)
2110 + printf("Compression %s\n", comp->name);
2111 + printf("Block size %d\n", sBlk.block_size);
2112 printf("Filesystem is %sexportable via NFS\n",
2113 SQUASHFS_EXPORTABLE(sBlk.flags) ? "" : "not ");
2115 @@ -1409,9 +1400,6 @@
2116 SQUASHFS_DUPLICATES(sBlk.flags) ? "" : "not ");
2117 else
2118 printf("Duplicates are removed\n");
2119 - printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n",
2120 - sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));
2121 - printf("Block size %d\n", sBlk.block_size);
2122 if(sBlk.s_major > 1)
2123 printf("Number of fragments %d\n", sBlk.fragments);
2124 printf("Number of inodes %d\n", sBlk.inodes);
2125 @@ -1459,6 +1447,18 @@
2126 s_ops.read_inode = read_inode_4;
2127 s_ops.read_uids_guids = read_uids_guids_4;
2128 memcpy(&sBlk, &sBlk_4, sizeof(sBlk_4));
2130 + /*
2131 + * Check the compression type
2132 + */
2133 + comp = lookup_compressor_id(sBlk.compression);
2134 + if(!comp->supported) {
2135 + ERROR("Filesystem uses %s compression, this is "
2136 + "unsupported by this version\n", comp->name);
2137 + ERROR("Decompressors available:\n");
2138 + display_compressors("", "");
2139 + goto failed_mount;
2140 + }
2141 return TRUE;
2144 @@ -1548,6 +1548,11 @@
2145 goto failed_mount;
2148 + /*
2149 + * 1.x, 2.x and 3.x filesystems use gzip compression. Gzip is always
2150 + * suppported.
2151 + */
2152 + comp = lookup_compressor("gzip");
2153 return TRUE;
2155 failed_mount:
2156 @@ -1707,32 +1712,24 @@
2158 while(1) {
2159 struct cache_entry *entry = queue_get(to_deflate);
2160 - int res;
2161 - unsigned long bytes = block_size;
2162 + int error, res;
2164 - res = uncompress((unsigned char *) tmp, &bytes,
2165 - (const unsigned char *) entry->data,
2166 - SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size));
2167 + res = comp->uncompress(tmp, entry->data,
2168 + SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size), block_size,
2169 + &error);
2171 - if(res != Z_OK) {
2172 - if(res == Z_MEM_ERROR)
2173 - ERROR("zlib::uncompress failed, not enough"
2174 - "memory\n");
2175 - else if(res == Z_BUF_ERROR)
2176 - ERROR("zlib::uncompress failed, not enough "
2177 - "room in output buffer\n");
2178 - else
2179 - ERROR("zlib::uncompress failed, unknown error "
2180 - "%d\n", res);
2181 - } else
2182 - memcpy(entry->data, tmp, bytes);
2183 + if(res == -1)
2184 + ERROR("%s uncompress failed with error code %d\n",
2185 + comp->name, error);
2186 + else
2187 + memcpy(entry->data, tmp, res);
2189 /*
2190 * block has been either successfully decompressed, or an error
2191 * occurred, clear pending flag, set error appropriately and
2192 * wake up any threads waiting on this block
2193 */
2194 - cache_block_ready(entry, res != Z_OK);
2195 + cache_block_ready(entry, res == -1);
2199 @@ -1913,7 +1910,7 @@
2202 #define VERSION() \
2203 - printf("unsquashfs version 4.0 (2009/04/05)\n");\
2204 + printf("unsquashfs version 4.0 (CVS 2009/08/30)\n");\
2205 printf("copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>"\
2206 "\n\n");\
2207 printf("This program is free software; you can redistribute it and/or\n");\
2208 @@ -1938,7 +1935,6 @@
2209 int fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;
2210 int data_buffer_size = DATA_BUFFER_DEFAULT;
2211 char *b;
2212 - struct winsize winsize;
2214 pthread_mutex_init(&screen_mutex, NULL);
2215 root_process = geteuid() == 0;
2216 @@ -2087,6 +2083,8 @@
2217 "regular expressions\n");
2218 ERROR("\t\t\t\trather than use the default shell "
2219 "wildcard\n\t\t\t\texpansion (globbing)\n");
2220 + ERROR("\nDecompressors available:\n");
2221 + display_compressors("", "");
2223 exit(1);
2226 --- squashfs-4.0/squashfs-tools/unsquashfs.h Sun Mar 29 04:29:02 2009
2227 +++ squashfs-4.0/squashfs-tools/unsquashfs.h Fri Jul 31 19:24:38 2009
2228 @@ -31,7 +31,6 @@
2229 #include <fcntl.h>
2230 #include <errno.h>
2231 #include <string.h>
2232 -#include <zlib.h>
2233 #include <sys/mman.h>
2234 #include <utime.h>
2235 #include <pwd.h>
2237 --- squashfs-4.0/squashfs-tools/squashfs_fs.h
2238 +++ squashfs-4.0/squashfs-tools/squashfs_fs.h
2239 @@ -28,6 +28,8 @@
2240 #define SQUASHFS_MINOR 0
2241 #define SQUASHFS_MAGIC 0x73717368
2242 #define SQUASHFS_MAGIC_SWAP 0x68737173
2243 +#define SQUASHFS_MAGIC_OLD_LZMA 0x71736873
2244 +#define SQUASHFS_MAGIC_OLD_LZMA_SWAP 0x73687371
2245 #define SQUASHFS_START 0
2247 /* size of metadata (inode and directory) blocks */
2249 --- squashfs-4.0/squashfs-tools/unsquashfs.c
2250 +++ squashfs-4.0/squashfs-tools/unsquashfs.c
2251 @@ -1473,8 +1473,10 @@
2252 * Check it is a SQUASHFS superblock
2253 */
2254 swap = 0;
2255 - if(sBlk_3.s_magic != SQUASHFS_MAGIC) {
2256 - if(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP) {
2257 + if(sBlk_3.s_magic != SQUASHFS_MAGIC &&
2258 + sBlk_3.s_magic != SQUASHFS_MAGIC_OLD_LZMA) {
2259 + if(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP ||
2260 + sBlk_3.s_magic == SQUASHFS_MAGIC_OLD_LZMA_SWAP) {
2261 squashfs_super_block_3 sblk;
2262 ERROR("Reading a different endian SQUASHFS filesystem "
2263 "on %s\n", source);
2264 @@ -1552,7 +1554,10 @@
2265 * 1.x, 2.x and 3.x filesystems use gzip compression. Gzip is always
2266 * suppported.
2267 */
2268 - comp = lookup_compressor("gzip");
2269 + if (sBlk_3.s_magic == SQUASHFS_MAGIC_OLD_LZMA ||
2270 + sBlk_3.s_magic == SQUASHFS_MAGIC_OLD_LZMA_SWAP)
2271 + comp = lookup_compressor("lzma");
2272 + else comp = lookup_compressor("gzip");
2273 return TRUE;
2275 failed_mount: