Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 207737 | Differences between
and this patch

Collapse All | Expand All

(-)squashfs3.3/squashfs-tools/Makefile (-9 / +32 lines)
Lines 1-19 Link Here
1
INCLUDEDIR = .
2
1
3
CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2
2
ifndef Sqlzma
3
$(error Sqlzma is not defined)
4
endif
4
5
5
all: mksquashfs unsquashfs
6
INCLUDEDIR = .
6
7
7
mksquashfs: mksquashfs.o read_fs.o sort.o
8
CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2
8
	$(CC) mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o $@
9
ifdef UseDebugFlags
10
DebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG
11
endif
12
CFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}
13
LDLIBS += -lz -L${LzmaAlone} -L${LzmaC}
14
Tgt = mksquashfs unsquashfs
9
15
10
mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h
16
all: ${Tgt}
11
17
12
read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h
18
read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \
19
	${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h
13
20
14
sort.o: sort.c squashfs_fs.h global.h sort.h
21
sort.o: sort.c squashfs_fs.h global.h sort.h
15
22
23
mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \
24
	${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \
25
	${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a
26
mksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++
27
mksquashfs: mksquashfs.o read_fs.o sort.o
28
29
unsquashfs.o: CFLAGS += -U_REENTRANT
30
unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \
31
	${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a
32
unsquashfs: LDLIBS += -lunlzma
16
unsquashfs: unsquashfs.o
33
unsquashfs: unsquashfs.o
17
	$(CC) unsquashfs.o -lz -o $@
18
34
19
unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h
35
clean:
36
	${RM} *~ *.o ${Tgt}
37
38
-include test.mk
39
40
# Local variables: ;
41
# compile-command: (concat "make Sqlzma=../.. -f " (file-name-nondirectory (buffer-file-name)));
42
# End: ;
(-)squashfs3.3/squashfs-tools/mksquashfs.c (-46 / +84 lines)
Lines 61-66 Link Here
61
#include "mksquashfs.h"
61
#include "mksquashfs.h"
62
#include "global.h"
62
#include "global.h"
63
#include "sort.h"
63
#include "sort.h"
64
#include "sqlzma.h"
65
#include "sqmagic.h"
64
66
65
#ifdef SQUASHFS_TRACE
67
#ifdef SQUASHFS_TRACE
66
#define TRACE(s, args...)	do { \
68
#define TRACE(s, args...)	do { \
Lines 112-117 unsigned short uid_count = 0, guid_count Link Here
112
squashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];
114
squashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];
113
int block_offset;
115
int block_offset;
114
int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;
116
int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;
117
struct sqlzma_un un;
118
struct sqlzma_opts sqlzma_opts = {
119
	.try_lzma	= 1,
120
	.dicsize	= SQUASHFS_FILE_SIZE
121
};
115
122
116
/* write position within data section */
123
/* write position within data section */
117
long long bytes = 0, total_bytes = 0;
124
long long bytes = 0, total_bytes = 0;
Lines 626-646 unsigned int mangle2(z_stream **strm, ch Link Here
626
			BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
633
			BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
627
	}
634
	}
628
635
629
	stream->next_in = (unsigned char *) s;
636
	res = sqlzma_cm(&sqlzma_opts, stream, (void *)s, size, (void *)d,
630
	stream->avail_in = size;
637
			block_size);
631
	stream->next_out = (unsigned char *) d;
632
	stream->avail_out = block_size;
633
634
	res = deflate(stream, Z_FINISH);
635
	if(res != Z_STREAM_END && res != Z_OK) {
636
		if(res == Z_STREAM_ERROR)
637
			BAD_ERROR("zlib::compress failed, stream state inconsistent\n");
638
		else if(res == Z_BUF_ERROR)
639
			BAD_ERROR("zlib::compress failed, no progress possible\n");
640
		else
641
			BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
642
	}
643
644
	c_byte = stream->total_out;
638
	c_byte = stream->total_out;
645
639
646
	if(res != Z_STREAM_END || c_byte >= size) {
640
	if(res != Z_STREAM_END || c_byte >= size) {
Lines 739-744 void write_bytes(int fd, long long byte, Link Here
739
		EXIT_MKSQUASHFS();
733
		EXIT_MKSQUASHFS();
740
	}
734
	}
741
735
736
	//printf("%d bytes at %Ld\n", bytes, off);
742
	if(write(fd, buff, bytes) == -1) {
737
	if(write(fd, buff, bytes) == -1) {
743
		perror("Write on destination failed");
738
		perror("Write on destination failed");
744
		EXIT_MKSQUASHFS();
739
		EXIT_MKSQUASHFS();
Lines 991-1002 int create_inode(squashfs_inode *i_no, s Link Here
991
		char buff[65536];
986
		char buff[65536];
992
987
993
		if((byte = readlink(filename, buff, 65536)) == -1) {
988
		if((byte = readlink(filename, buff, 65536)) == -1) {
994
			ERROR("Failed to read symlink %d, creating empty symlink\n", filename);
989
			ERROR("Failed to read symlink %s, creating empty symlink\n", filename);
995
			byte = 0;
990
			byte = 0;
996
		}
991
		}
997
992
998
		if(byte == 65536) {
993
		if(byte == 65536) {
999
			ERROR("Symlink %d is greater than 65536 bytes! Creating empty symlink\n", filename);
994
			ERROR("Symlink %s is greater than 65536 bytes! Creating empty symlink\n", filename);
1000
			byte = 0;
995
			byte = 0;
1001
		}
996
		}
1002
997
Lines 1022-1028 int create_inode(squashfs_inode *i_no, s Link Here
1022
			SQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);
1017
			SQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);
1023
		TRACE("ipc inode, type %s, nlink %d\n", type == SQUASHFS_FIFO_TYPE ? "fifo" : "socket", nlink);
1018
		TRACE("ipc inode, type %s, nlink %d\n", type == SQUASHFS_FIFO_TYPE ? "fifo" : "socket", nlink);
1024
	} else
1019
	} else
1025
		BAD_ERROR("Unrecognised inode %d in create_inode\n");
1020
		BAD_ERROR("Unrecognised inode %d in create_inode\n", type);
1026
1021
1027
	*i_no = MKINODE(inode);
1022
	*i_no = MKINODE(inode);
1028
	inode_count ++;
1023
	inode_count ++;
Lines 1250-1266 char *get_fragment(char *buffer, struct Link Here
1250
		int res;
1245
		int res;
1251
		unsigned long bytes = block_size;
1246
		unsigned long bytes = block_size;
1252
		char cbuffer[block_size];
1247
		char cbuffer[block_size];
1248
		enum {Src, Dst};
1249
		struct sized_buf sbuf[] = {
1250
			{.buf = (void *)cbuffer, .sz = size},
1251
			{.buf = (void *)buffer, .sz = bytes}
1252
		};
1253
1253
1254
		read_bytes(fd, disk_fragment->start_block, size, cbuffer);
1254
		read_bytes(fd, disk_fragment->start_block, size, cbuffer);
1255
1255
1256
		if((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {
1256
		res = sqlzma_un(&un, sbuf + Src, sbuf + Dst);
1257
			if(res == Z_MEM_ERROR)
1257
		if (res)
1258
				BAD_ERROR("zlib::uncompress failed, not enough memory\n");
1258
			BAD_ERROR("%s:%d: res %d\n", __func__, __LINE__, res);
1259
			else if(res == Z_BUF_ERROR)
1260
				BAD_ERROR("zlib::uncompress failed, not enough room in output buffer\n");
1261
			else
1262
				BAD_ERROR("zlib::uncompress failed, unknown error %d\n", res);
1263
		}
1264
	} else
1259
	} else
1265
		read_bytes(fd, disk_fragment->start_block, size, buffer);
1260
		read_bytes(fd, disk_fragment->start_block, size, buffer);
1266
1261
Lines 1687-1693 again: Link Here
1687
			goto restat;
1682
			goto restat;
1688
	}
1683
	}
1689
1684
1690
	if(file_buffer->fragment = file_buffer->block == frag_block)
1685
	file_buffer->fragment = (file_buffer->block == frag_block);
1686
	if(file_buffer->fragment)
1691
		queue_put(from_deflate, file_buffer);
1687
		queue_put(from_deflate, file_buffer);
1692
	else
1688
	else
1693
		queue_put(from_reader, file_buffer);
1689
		queue_put(from_reader, file_buffer);
Lines 1755-1760 void *reader(void *arg) Link Here
1755
			for(entry = priority_list[i]; entry; entry = entry->next)
1751
			for(entry = priority_list[i]; entry; entry = entry->next)
1756
				reader_read_file(entry->dir);
1752
				reader_read_file(entry->dir);
1757
	}
1753
	}
1754
	return NULL;
1758
}
1755
}
1759
1756
1760
1757
Lines 1784-1789 void *writer(void *arg) Link Here
1784
			write_error = TRUE;
1781
			write_error = TRUE;
1785
		}
1782
		}
1786
1783
1784
		//printf("%d bytes at %Ld\n", file_buffer->size, off);
1787
		if(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {
1785
		if(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {
1788
			perror("Write on destination failed");
1786
			perror("Write on destination failed");
1789
			write_error = TRUE;
1787
			write_error = TRUE;
Lines 1926-1932 int progress_bar(long long current, long Link Here
1926
	int spaces = columns - used - hashes;
1924
	int spaces = columns - used - hashes;
1927
1925
1928
	if(!progress || columns - used < 0)
1926
	if(!progress || columns - used < 0)
1929
		return;
1927
		return 0;
1930
1928
1931
	printf("\r[");
1929
	printf("\r[");
1932
1930
Lines 1939-1944 int progress_bar(long long current, long Link Here
1939
	printf("] %*lld/%*lld", max_digits, current, max_digits, max);
1937
	printf("] %*lld/%*lld", max_digits, current, max_digits, max);
1940
	printf(" %3lld%%", current * 100 / max);
1938
	printf(" %3lld%%", current * 100 / max);
1941
	fflush(stdout);
1939
	fflush(stdout);
1940
	return 0;
1942
}
1941
}
1943
1942
1944
1943
Lines 2243-2249 void write_file(squashfs_inode *inode, s Link Here
2243
2242
2244
again:
2243
again:
2245
	read_buffer = get_file_buffer(from_deflate);
2244
	read_buffer = get_file_buffer(from_deflate);
2246
	if(status = read_buffer->error) {
2245
	status = read_buffer->error;
2246
	if(status) {
2247
		alloc_free(read_buffer);
2247
		alloc_free(read_buffer);
2248
		goto file_err;
2248
		goto file_err;
2249
	}
2249
	}
Lines 2635-2641 error: Link Here
2635
2635
2636
void dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)
2636
void dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)
2637
{
2637
{
2638
	int squashfs_type;
2638
	int squashfs_type = -1;
2639
	int duplicate_file;
2639
	int duplicate_file;
2640
	char *pathname = dir_info->pathname;
2640
	char *pathname = dir_info->pathname;
2641
	struct directory dir;
2641
	struct directory dir;
Lines 2918-2924 skip_inode_hash_table: Link Here
2918
char *get_component(char *target, char *targname)
2918
char *get_component(char *target, char *targname)
2919
{
2919
{
2920
	while(*target == '/')
2920
	while(*target == '/')
2921
		*target ++;
2921
		target ++;
2922
2922
2923
	while(*target != '/' && *target!= '\0')
2923
	while(*target != '/' && *target!= '\0')
2924
		*targname ++ = *target ++;
2924
		*targname ++ = *target ++;
Lines 2974-2980 struct pathname *add_path(struct pathnam Link Here
2974
		paths->name[i].paths = NULL;
2974
		paths->name[i].paths = NULL;
2975
		if(use_regex) {
2975
		if(use_regex) {
2976
			paths->name[i].preg = malloc(sizeof(regex_t));
2976
			paths->name[i].preg = malloc(sizeof(regex_t));
2977
			if(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {
2977
			error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);
2978
			if(error) {
2978
				char str[1024];
2979
				char str[1024];
2979
2980
2980
				regerror(error, paths->name[i].preg, str, 1024);
2981
				regerror(error, paths->name[i].preg, str, 1024);
Lines 3242-3248 void read_recovery_data(char *recovery_f Link Here
3242
	printf("This program is distributed in the hope that it will be useful,\n");\
3243
	printf("This program is distributed in the hope that it will be useful,\n");\
3243
	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");\
3244
	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");\
3244
	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");\
3245
	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");\
3245
	printf("GNU General Public License for more details.\n");
3246
	printf("GNU General Public License for more details.\n");\
3247
	printf("and LZMA support for slax.org by jro.\n");
3246
int main(int argc, char *argv[])
3248
int main(int argc, char *argv[])
3247
{
3249
{
3248
	struct winsize winsize;
3250
	struct winsize winsize;
Lines 3261-3266 int main(int argc, char *argv[]) Link Here
3261
	be = FALSE;
3263
	be = FALSE;
3262
#endif
3264
#endif
3263
3265
3266
	un.un_lzma = 1;
3264
	block_log = slog(block_size);
3267
	block_log = slog(block_size);
3265
	if(argc > 1 && strcmp(argv[1], "-version") == 0) {
3268
	if(argc > 1 && strcmp(argv[1], "-version") == 0) {
3266
		VERSION();
3269
		VERSION();
Lines 3319-3342 int main(int argc, char *argv[]) Link Here
3319
				ERROR("%s: -write-queue should be 1 megabyte or larger\n", argv[0]);
3322
				ERROR("%s: -write-queue should be 1 megabyte or larger\n", argv[0]);
3320
				exit(1);
3323
				exit(1);
3321
			}
3324
			}
3322
		} else if(strcmp(argv[i], "-b") == 0) {
3325
		} else if(strcmp(argv[i], "-b") == 0
3326
			|| strcmp(argv[i], "-lzmadic") == 0) {
3327
			long bs;
3328
			unsigned int bl;
3323
			if(++i == argc) {
3329
			if(++i == argc) {
3324
				ERROR("%s: -b missing block size\n", argv[0]);
3330
				ERROR("%s: -b|-lzmadic missing block size\n", argv[0]);
3325
				exit(1);
3331
				exit(1);
3326
			}
3332
			}
3327
			block_size = strtol(argv[i], &b, 10);
3333
			bs = strtol(argv[i], &b, 10);
3328
			if(*b == 'm' || *b == 'M')
3334
			if(*b == 'm' || *b == 'M')
3329
				block_size *= 1048576;
3335
				bs *= 1048576;
3330
			else if(*b == 'k' || *b == 'K')
3336
			else if(*b == 'k' || *b == 'K')
3331
				block_size *= 1024;
3337
				bs *= 1024;
3332
			else if(*b != '\0') {
3338
			else if(*b != '\0') {
3333
				ERROR("%s: -b invalid block size\n", argv[0]);
3339
				ERROR("%s: -b|-lzmadic invalid size\n", argv[0]);
3334
				exit(1);
3340
				exit(1);
3335
			}
3341
			}
3336
			if((block_log = slog(block_size)) == 0) {
3342
			bl = slog(bs);
3337
				ERROR("%s: -b block size not power of two or not between 4096 and 1Mbyte\n", argv[0]);
3343
			if(bl == 0) {
3344
				ERROR("%s: -b|-lzmadic size not power of two or not between 4096 and 1Mbyte\n", argv[0]);
3338
				exit(1);
3345
				exit(1);
3339
			}
3346
			}
3347
			if (!strcmp(argv[i - 1], "-b")) {
3348
				block_size = bs;
3349
				block_log = bl;
3350
			}
3351
			sqlzma_opts.dicsize = bs;
3340
		} else if(strcmp(argv[i], "-ef") == 0) {
3352
		} else if(strcmp(argv[i], "-ef") == 0) {
3341
			if(++i == argc) {
3353
			if(++i == argc) {
3342
				ERROR("%s: -ef missing filename\n", argv[0]);
3354
				ERROR("%s: -ef missing filename\n", argv[0]);
Lines 3440-3445 int main(int argc, char *argv[]) Link Here
3440
				exit(1);
3452
				exit(1);
3441
			}	
3453
			}	
3442
			root_name = argv[i];
3454
			root_name = argv[i];
3455
		} else if(strcmp(argv[i], "-nolzma") == 0) {
3456
			un.un_lzma = 0;
3457
			sqlzma_opts.try_lzma = 0;
3443
		} else if(strcmp(argv[i], "-version") == 0) {
3458
		} else if(strcmp(argv[i], "-version") == 0) {
3444
			VERSION();
3459
			VERSION();
3445
		} else {
3460
		} else {
Lines 3489-3494 printOptions: Link Here
3489
			ERROR("-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n");
3504
			ERROR("-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n");
3490
			ERROR("-wildcards\t\tAllow extended shell wildcards (globbing) to be used in\n\t\t\texclude dirs/files\n");
3505
			ERROR("-wildcards\t\tAllow extended shell wildcards (globbing) to be used in\n\t\t\texclude dirs/files\n");
3491
			ERROR("-regex\t\t\tAllow POSIX regular expressions to be used in exclude\n\t\t\tdirs/files\n");
3506
			ERROR("-regex\t\t\tAllow POSIX regular expressions to be used in exclude\n\t\t\tdirs/files\n");
3507
			ERROR("-lzmadic <dic_size>\tset the LZMA dictionary"
3508
			      " size to <dic_size>\n"
3509
			      "\t\t\tDefault value always follow the block"
3510
			      " size\n"
3511
			      "\t\t\tUse this alone or AFTER -b option\n");
3512
			ERROR("-nolzma\t\t\tnever try LZMA compression\n");
3492
			exit(1);
3513
			exit(1);
3493
		}
3514
		}
3494
	}
3515
	}
Lines 3595-3600 printOptions: Link Here
3595
3616
3596
		be = orig_be;
3617
		be = orig_be;
3597
		block_log = slog(block_size = sBlk.block_size);
3618
		block_log = slog(block_size = sBlk.block_size);
3619
		//sqlzma_opts.dicsize = block_size;
3598
		s_minor = sBlk.s_minor;
3620
		s_minor = sBlk.s_minor;
3599
		noI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);
3621
		noI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);
3600
		noD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);
3622
		noD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);
Lines 3608-3617 printOptions: Link Here
3608
3630
3609
	initialise_threads();
3631
	initialise_threads();
3610
3632
3633
	i = sqlzma_init(&un, un.un_lzma, 0);
3634
	if (i != Z_OK) {
3635
		ERROR("%s:%d: %d\n", __func__, __LINE__, i);
3636
		EXIT_MKSQUASHFS();
3637
	}
3638
3611
	if(delete) {
3639
	if(delete) {
3612
		printf("Creating %s %d.%d filesystem on %s, block size %d.\n",
3640
		printf("Creating %s %d.%d filesystem on %s, block size %d.\n",
3613
				be ? "big endian" : "little endian", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);
3641
				be ? "big endian" : "little endian", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);
3614
		bytes = sizeof(squashfs_super_block);
3642
		bytes = sizeof(squashfs_super_block);
3643
		if (sqlzma_opts.try_lzma)
3644
			printf("lzmadic %u\n", sqlzma_opts.dicsize);
3615
	} else {
3645
	} else {
3616
		unsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,
3646
		unsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,
3617
		inode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,
3647
		inode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,
Lines 3635-3645 printOptions: Link Here
3635
3665
3636
		printf("Appending to existing %s %d.%d filesystem on %s, block size %d\n", be ? "big endian" :
3666
		printf("Appending to existing %s %d.%d filesystem on %s, block size %d\n", be ? "big endian" :
3637
			"little endian", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);
3667
			"little endian", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);
3668
		if (sqlzma_opts.try_lzma)
3669
			printf("lzmadic %u\n", sqlzma_opts.dicsize);
3638
		printf("All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\n");
3670
		printf("All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\n");
3639
		printf("\nIf appending is not wanted, please re-run with -noappend specified!\n\n");
3671
		printf("\nIf appending is not wanted, please re-run with -noappend specified!\n\n");
3640
3672
3641
		compressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);
3673
		compressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1)); //??
3642
		uncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);
3674
		uncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1)); //??
3643
		
3675
		
3644
		/* save original filesystem state for restoring ... */
3676
		/* save original filesystem state for restoring ... */
3645
		sfragments = fragments;
3677
		sfragments = fragments;
Lines 3733-3739 printOptions: Link Here
3733
		dir_scan(&inode, "", scan1_encomp_readdir);
3765
		dir_scan(&inode, "", scan1_encomp_readdir);
3734
	sBlk.root_inode = inode;
3766
	sBlk.root_inode = inode;
3735
	sBlk.inodes = inode_count;
3767
	sBlk.inodes = inode_count;
3736
	sBlk.s_magic = SQUASHFS_MAGIC;
3768
	sBlk.s_magic = SQUASHFS_MAGIC_LZMA;
3769
	if (!un.un_lzma)
3770
		sBlk.s_magic = SQUASHFS_MAGIC;
3737
	sBlk.s_major = SQUASHFS_MAJOR;
3771
	sBlk.s_major = SQUASHFS_MAJOR;
3738
	sBlk.s_minor = s_minor;
3772
	sBlk.s_minor = s_minor;
3739
	sBlk.block_size = block_size;
3773
	sBlk.block_size = block_size;
Lines 3762-3768 restore_filesystem: Link Here
3762
	if(exportable)
3796
	if(exportable)
3763
		TRACE("sBlk->lookup_table_start 0x%llx\n", sBlk.lookup_table_start);
3797
		TRACE("sBlk->lookup_table_start 0x%llx\n", sBlk.lookup_table_start);
3764
3798
3765
	if(sBlk.no_uids = uid_count) {
3799
	sBlk.no_uids = uid_count;
3800
	if(sBlk.no_uids) {
3766
		if(!swap)
3801
		if(!swap)
3767
			write_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);
3802
			write_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);
3768
		else {
3803
		else {
Lines 3776-3782 restore_filesystem: Link Here
3776
	} else
3811
	} else
3777
		sBlk.uid_start = 0;
3812
		sBlk.uid_start = 0;
3778
3813
3779
	if(sBlk.no_guids = guid_count) {
3814
	sBlk.no_guids = guid_count;
3815
	if(sBlk.no_guids) {
3780
		if(!swap)
3816
		if(!swap)
3781
			write_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);
3817
			write_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);
3782
		else {
3818
		else {
Lines 3819-3824 restore_filesystem: Link Here
3819
		exportable ? "Exportable " : "", be ?  "Big endian" : "Little endian", block_size,
3855
		exportable ? "Exportable " : "", be ?  "Big endian" : "Little endian", block_size,
3820
		noD ? "uncompressed" : "compressed", noI ?  "uncompressed" : "compressed",
3856
		noD ? "uncompressed" : "compressed", noI ?  "uncompressed" : "compressed",
3821
		no_fragments ? "no" : noF ? "uncompressed" : "compressed", duplicate_checking ? "" : "not ");
3857
		no_fragments ? "no" : noF ? "uncompressed" : "compressed", duplicate_checking ? "" : "not ");
3858
	if (sqlzma_opts.try_lzma)
3859
		printf("lzmadic %u\n", sqlzma_opts.dicsize);
3822
	printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n", bytes / 1024.0, bytes / (1024.0 * 1024.0));
3860
	printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n", bytes / 1024.0, bytes / (1024.0 * 1024.0));
3823
	printf("\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\n",
3861
	printf("\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\n",
3824
		((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);
3862
		((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);
(-)squashfs3.3/squashfs-tools/read_fs.c (-22 / +38 lines)
Lines 46-51 extern int add_file(long long, long long Link Here
46
#include <squashfs_fs.h>
46
#include <squashfs_fs.h>
47
#include "read_fs.h"
47
#include "read_fs.h"
48
#include "global.h"
48
#include "global.h"
49
#include "sqlzma.h"
50
#include "sqmagic.h"
49
51
50
#include <stdlib.h>
52
#include <stdlib.h>
51
53
Lines 62-67 extern int add_file(long long, long long Link Here
62
					} while(0)
64
					} while(0)
63
65
64
int swap;
66
int swap;
67
extern struct sqlzma_un un;
65
68
66
int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)
69
int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)
67
{
70
{
Lines 81-99 int read_block(int fd, long long start, Link Here
81
		char buffer[SQUASHFS_METADATA_SIZE];
84
		char buffer[SQUASHFS_METADATA_SIZE];
82
		int res;
85
		int res;
83
		unsigned long bytes = SQUASHFS_METADATA_SIZE;
86
		unsigned long bytes = SQUASHFS_METADATA_SIZE;
87
		enum {Src, Dst};
88
		struct sized_buf sbuf[] = {
89
			{.buf = (void *)buffer},
90
			{.buf = (void *)block, .sz = bytes}
91
		};
84
92
85
		c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
93
		c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
86
		read_bytes(fd, start + offset, c_byte, buffer);
94
		read_bytes(fd, start + offset, c_byte, buffer);
87
95
88
		if((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {
96
		sbuf[Src].sz = c_byte;
89
			if(res == Z_MEM_ERROR)
97
		res = sqlzma_un(&un, sbuf + Src, sbuf + Dst);
90
				ERROR("zlib::uncompress failed, not enough memory\n");
98
		if (res)
91
			else if(res == Z_BUF_ERROR)
99
			abort();
92
				ERROR("zlib::uncompress failed, not enough room in output buffer\n");
100
		bytes = un.un_reslen;
93
			else
94
				ERROR("zlib::uncompress failed, unknown error %d\n", res);
95
			return 0;
96
		}
97
		if(next)
101
		if(next)
98
			*next = start + offset + c_byte;
102
			*next = start + offset + c_byte;
99
		return bytes;
103
		return bytes;
Lines 351-368 int read_super(int fd, squashfs_super_bl Link Here
351
355
352
	/* Check it is a SQUASHFS superblock */
356
	/* Check it is a SQUASHFS superblock */
353
	swap = 0;
357
	swap = 0;
354
	if(sBlk->s_magic != SQUASHFS_MAGIC) {
358
	switch (sBlk->s_magic) {
355
		if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
359
		squashfs_super_block sblk;
356
			squashfs_super_block sblk;
360
357
			ERROR("Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\n", source);
361
	case SQUASHFS_MAGIC_LZMA:
358
			SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
362
		if (!un.un_lzma)
359
			memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
363
			goto bad;
360
			swap = 1;
364
		break;
361
		} else  {
365
	case SQUASHFS_MAGIC:
362
			ERROR("Can't find a SQUASHFS superblock on %s\n", source);
366
		break;
363
			goto failed_mount;
367
	case SQUASHFS_MAGIC_LZMA_SWAP:
364
		}
368
		if (!un.un_lzma)
365
	}
369
			goto bad;
370
		/*FALLTHROUGH*/
371
	case SQUASHFS_MAGIC_SWAP:
372
		ERROR("Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\n", source);
373
		SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
374
		memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
375
		swap = 1;
376
		break;
377
	bad:
378
	default:
379
		ERROR("Can't find a SQUASHFS superblock on %s\n", source);
380
		goto failed_mount;
381
 	}
366
382
367
	/* Check the MAJOR & MINOR versions */
383
	/* Check the MAJOR & MINOR versions */
368
	if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
384
	if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
Lines 416-422 unsigned char *squashfs_readdir(int fd, Link Here
416
	squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
432
	squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
417
	unsigned char *directory_table = NULL;
433
	unsigned char *directory_table = NULL;
418
	int byte, bytes = 0, dir_count;
434
	int byte, bytes = 0, dir_count;
419
	long long start = sBlk->directory_table_start + directory_start_block, last_start_block; 
435
	long long start = sBlk->directory_table_start + directory_start_block, last_start_block = -1; 
420
436
421
	size += offset;
437
	size += offset;
422
	if((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)
438
	if((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)
(-)squashfs3.3/squashfs-tools/sort.c (-1 / +1 lines)
Lines 74-80 struct sort_info *sort_info_list[65536]; Link Here
74
struct priority_entry *priority_list[65536];
74
struct priority_entry *priority_list[65536];
75
75
76
extern int silent;
76
extern int silent;
77
extern write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);
77
extern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);
78
78
79
79
80
int add_priority_list(struct dir_ent *dir, int priority)
80
int add_priority_list(struct dir_ent *dir, int priority)
(-)squashfs3.3/squashfs-tools/unsquashfs.c (-40 / +60 lines)
Lines 52-57 Link Here
52
#include <squashfs_fs.h>
52
#include <squashfs_fs.h>
53
#include "read_fs.h"
53
#include "read_fs.h"
54
#include "global.h"
54
#include "global.h"
55
#include "sqlzma.h"
56
#include "sqmagic.h"
55
57
56
#include <stdlib.h>
58
#include <stdlib.h>
57
#include <time.h>
59
#include <time.h>
Lines 131-136 unsigned int block_size; Link Here
131
int lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;
133
int lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;
132
char **created_inode;
134
char **created_inode;
133
int root_process;
135
int root_process;
136
struct sqlzma_un un;
134
137
135
int lookup_type[] = {
138
int lookup_type[] = {
136
	0,
139
	0,
Lines 287-292 int read_bytes(long long byte, int bytes Link Here
287
		return FALSE;
290
		return FALSE;
288
	}
291
	}
289
292
293
	/* printf("%d bytes at %Ld\n", bytes, off); */
290
	if(read(fd, buff, bytes) == -1) {
294
	if(read(fd, buff, bytes) == -1) {
291
		ERROR("Read on destination failed because %s\n", strerror(errno));
295
		ERROR("Read on destination failed because %s\n", strerror(errno));
292
		return FALSE;
296
		return FALSE;
Lines 318-338 int read_block(long long start, long lon Link Here
318
		char buffer[SQUASHFS_METADATA_SIZE];
322
		char buffer[SQUASHFS_METADATA_SIZE];
319
		int res;
323
		int res;
320
		unsigned long bytes = SQUASHFS_METADATA_SIZE;
324
		unsigned long bytes = SQUASHFS_METADATA_SIZE;
325
		enum {Src, Dst};
326
		struct sized_buf sbuf[] = {
327
			{.buf = (void *)buffer},
328
			{.buf = (void *)block, .sz = bytes}
329
		};
321
330
322
		c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
331
		c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
323
		if(read_bytes(start + offset, c_byte, buffer) == FALSE)
332
		if(read_bytes(start + offset, c_byte, buffer) == FALSE)
324
			goto failed;
333
			goto failed;
325
334
326
		if((res = uncompress((unsigned char *) block, &bytes,
335
		sbuf[Src].sz = c_byte;
327
		(const unsigned char *) buffer, c_byte)) != Z_OK) {
336
		res = sqlzma_un(&un, sbuf + Src, sbuf + Dst);
328
			if(res == Z_MEM_ERROR)
337
		if (res)
329
				ERROR("zlib::uncompress failed, not enough memory\n");
338
			abort();
330
			else if(res == Z_BUF_ERROR)
339
		bytes = un.un_reslen;
331
				ERROR("zlib::uncompress failed, not enough room in output buffer\n");
332
			else
333
				ERROR("zlib::uncompress failed, unknown error %d\n", res);
334
			goto failed;
335
		}
336
		if(next)
340
		if(next)
337
			*next = start + offset + c_byte;
341
			*next = start + offset + c_byte;
338
		return bytes;
342
		return bytes;
Lines 359-378 int read_data_block(long long start, uns Link Here
359
	TRACE("read_data_block: block @0x%llx, %d %s bytes\n", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? "compressed" : "uncompressed");
363
	TRACE("read_data_block: block @0x%llx, %d %s bytes\n", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? "compressed" : "uncompressed");
360
364
361
	if(SQUASHFS_COMPRESSED_BLOCK(size)) {
365
	if(SQUASHFS_COMPRESSED_BLOCK(size)) {
362
		if(read_bytes(start, c_byte, data) == FALSE)
366
		enum {Src, Dst};
363
			return 0;
367
		struct sized_buf sbuf[] = {
368
			{.buf = (void *)data, .sz = c_byte},
369
			{.buf = (void *)block, .sz = bytes}
370
		};
364
371
365
		if((res = uncompress((unsigned char *) block, &bytes,
372
		if(read_bytes(start, c_byte, data) == FALSE)
366
		(const unsigned char *) data, c_byte)) != Z_OK) {
367
			if(res == Z_MEM_ERROR)
368
				ERROR("zlib::uncompress failed, not enough memory\n");
369
			else if(res == Z_BUF_ERROR)
370
				ERROR("zlib::uncompress failed, not enough room in output buffer\n");
371
			else
372
				ERROR("zlib::uncompress failed, unknown error %d\n", res);
373
			return 0;
373
			return 0;
374
		}
375
374
375
		res = sqlzma_un(&un, sbuf + Src, sbuf + Dst);
376
		if (res)
377
			abort();
378
		bytes = un.un_reslen;
376
		return bytes;
379
		return bytes;
377
	} else {
380
	} else {
378
		if(read_bytes(start, c_byte, block) == FALSE)
381
		if(read_bytes(start, c_byte, block) == FALSE)
Lines 653-659 unsigned int mode) Link Here
653
		return FALSE;
656
		return FALSE;
654
	}
657
	}
655
658
656
	s_ops.read_block_list(block_list, block_ptr, blocks);
659
	s_ops.read_block_list(block_list, (void *)block_ptr, blocks);
657
660
658
	if((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {
661
	if((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {
659
		ERROR("write_file: failed to create file %s, because %s\n", pathname,
662
		ERROR("write_file: failed to create file %s, because %s\n", pathname,
Lines 921-927 int create_inode(char *pathname, struct Link Here
921
				set_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);
924
				set_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);
922
				dev_count ++;
925
				dev_count ++;
923
			} else
926
			} else
924
				ERROR("create_inode: could not create %s device %s, because you're not superuser!\n",
927
				ERROR("create_inode: could not create %s device %s, because you're not superuser! %s\n",
925
					chrdev ? "character" : "block", pathname, strerror(errno));
928
					chrdev ? "character" : "block", pathname, strerror(errno));
926
			break;
929
			break;
927
		}
930
		}
Lines 1456-1462 void squashfs_closedir(struct dir *dir) Link Here
1456
char *get_component(char *target, char *targname)
1459
char *get_component(char *target, char *targname)
1457
{
1460
{
1458
	while(*target == '/')
1461
	while(*target == '/')
1459
		*target ++;
1462
		target ++;
1460
1463
1461
	while(*target != '/' && *target!= '\0')
1464
	while(*target != '/' && *target!= '\0')
1462
		*targname ++ = *target ++;
1465
		*targname ++ = *target ++;
Lines 1529-1535 struct pathname *add_path(struct pathnam Link Here
1529
		paths->name[i].paths = NULL;
1532
		paths->name[i].paths = NULL;
1530
		if(use_regex) {
1533
		if(use_regex) {
1531
			paths->name[i].preg = malloc(sizeof(regex_t));
1534
			paths->name[i].preg = malloc(sizeof(regex_t));
1532
			if(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {
1535
			error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);
1536
			if(error) {
1533
				char str[1024];
1537
				char str[1024];
1534
1538
1535
				regerror(error, paths->name[i].preg, str, 1024);
1539
				regerror(error, paths->name[i].preg, str, 1024);
Lines 1717-1723 int dir_scan(char *parent_name, unsigned Link Here
1717
		free_subdir(new);
1721
		free_subdir(new);
1718
	}
1722
	}
1719
1723
1720
	!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);
1724
	if (!lsonly) //??
1725
		set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);
1721
1726
1722
	squashfs_closedir(dir);
1727
	squashfs_closedir(dir);
1723
	dir_count ++;
1728
	dir_count ++;
Lines 1775-1793 int read_super(char *source) Link Here
1775
	read_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);
1780
	read_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);
1776
1781
1777
	/* Check it is a SQUASHFS superblock */
1782
	/* Check it is a SQUASHFS superblock */
1783
	un.un_lzma = 1;
1778
	swap = 0;
1784
	swap = 0;
1779
	if(sBlk.s_magic != SQUASHFS_MAGIC) {
1785
	switch (sBlk.s_magic) {
1780
		if(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {
1786
		squashfs_super_block sblk;
1781
			squashfs_super_block sblk;
1787
	case SQUASHFS_MAGIC:
1782
			ERROR("Reading a different endian SQUASHFS filesystem on %s\n", source);
1788
		un.un_lzma = 0;
1783
			SQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);
1789
		/*FALLTHROUGH*/
1784
			memcpy(&sBlk, &sblk, sizeof(squashfs_super_block));
1790
	case SQUASHFS_MAGIC_LZMA:
1785
			swap = 1;
1791
		break;
1786
		} else  {
1792
	case SQUASHFS_MAGIC_SWAP:
1787
			ERROR("Can't find a SQUASHFS superblock on %s\n", source);
1793
		un.un_lzma = 0;
1788
			goto failed_mount;
1794
		/*FALLTHROUGH*/
1789
		}
1795
	case SQUASHFS_MAGIC_LZMA_SWAP:
1790
	}
1796
		ERROR("Reading a different endian SQUASHFS filesystem on %s\n", source);
1797
		SQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);
1798
		memcpy(&sBlk, &sblk, sizeof(squashfs_super_block));
1799
		swap = 1;
1800
	default:
1801
		ERROR("Can't find a SQUASHFS superblock on %s\n", source);
1802
		goto failed_mount;
1803
 	}
1791
1804
1792
	/* Check the MAJOR & MINOR versions */
1805
	/* Check the MAJOR & MINOR versions */
1793
	if(sBlk.s_major == 1 || sBlk.s_major == 2) {
1806
	if(sBlk.s_major == 1 || sBlk.s_major == 2) {
Lines 1857-1863 struct pathname *process_extract_files(s Link Here
1857
	printf("This program is distributed in the hope that it will be useful,\n");\
1870
	printf("This program is distributed in the hope that it will be useful,\n");\
1858
	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");\
1871
	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");\
1859
	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");\
1872
	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");\
1860
	printf("GNU General Public License for more details.\n");
1873
	printf("GNU General Public License for more details.\n");\
1874
	printf("and LZMA support for slax.org by jro.\n");
1861
int main(int argc, char *argv[])
1875
int main(int argc, char *argv[])
1862
{
1876
{
1863
	char *dest = "squashfs-root";
1877
	char *dest = "squashfs-root";
Lines 1867-1873 int main(int argc, char *argv[]) Link Here
1867
	struct pathnames *paths = NULL;
1881
	struct pathnames *paths = NULL;
1868
	struct pathname *path = NULL;
1882
	struct pathname *path = NULL;
1869
1883
1870
	if(root_process = geteuid() == 0)
1884
	root_process = geteuid() == 0;
1885
	if(root_process)
1871
		umask(0);
1886
		umask(0);
1872
	
1887
	
1873
	for(i = 1; i < argc; i++) {
1888
	for(i = 1; i < argc; i++) {
Lines 1957-1962 options: Link Here
1957
		EXIT_UNSQUASH("failed to allocate created_inode\n");
1972
		EXIT_UNSQUASH("failed to allocate created_inode\n");
1958
1973
1959
	memset(created_inode, 0, sBlk.inodes * sizeof(char *));
1974
	memset(created_inode, 0, sBlk.inodes * sizeof(char *));
1975
	i = sqlzma_init(&un, un.un_lzma, 0);
1976
	if (i != Z_OK) {
1977
		fputs("sqlzma_init failed", stderr);
1978
		abort();
1979
	}
1960
1980
1961
	read_uids_guids();
1981
	read_uids_guids();
1962
1982

Return to bug 207737