1 diff -u squashfs3.0old/squashfs-tools/mksquashfs.c squashfs3.0/squashfs-tools/mksquashfs.c
2 --- squashfs3.0old/squashfs-tools/mksquashfs.c 2006-03-15 21:36:20.000000000 +0000
3 +++ squashfs3.0/squashfs-tools/mksquashfs.c 2006-04-17 10:58:49.000000000 +0100
5 #define EXIT_MKSQUASHFS() do {\
8 - if(delete && destination_file && !block_device)\
9 + if(deletesquash && destination_file && !block_device)\
10 unlink(destination_file);\
18 +int deletesquash = FALSE;
19 long long total_compressed = 0, total_uncompressed = 0;
23 squashfs_fragment_entry **fragment_table);
24 int get_sorted_inode(squashfs_inode *inode, struct stat *buf);
25 int read_sort_file(char *filename, int source, char *source_path[]);
26 +int dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);
27 void sort_files_and_write(struct dir_info *dir);
28 struct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);
29 struct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));
35 +void sighandler(int signal)
44 +void sighandler2(int signal)
50 void scan2_init_dir(struct directory *dir)
52 - if((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {
53 + if((dir->buff = (unsigned char *)malloc(SQUASHFS_METADATA_SIZE)) == NULL) {
54 BAD_ERROR("Out of memory allocating directory buffer\n");
60 if(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {
61 - if((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL) {
62 + if((buff = (unsigned char *)realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL) {
63 BAD_ERROR("Out of memory reallocating directory buffer\n");
68 if((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {
69 if(dir->i_count % I_COUNT_SIZE == 0)
70 - if((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)
71 + if((dir->index = (struct cached_dir_index *)realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)
72 BAD_ERROR("Out of memory in directory index table reallocation!\n");
73 dir->index[dir->i_count].index.index = dir->p - dir->buff;
74 dir->index[dir->i_count].index.size = size - 1;
76 int blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;
77 unsigned int *block_list, *block_listp;
79 - if((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)
80 + if((block_list = (unsigned int *)malloc(blocks * sizeof(unsigned int))) == NULL)
81 BAD_ERROR("Out of memory allocating block_list\n");
82 block_listp = block_list;
88 - if((inode = malloc(sizeof(struct inode_info))) == NULL)
89 + if((inode = (struct inode_info *)malloc(sizeof(struct inode_info))) == NULL)
90 BAD_ERROR("Out of memory in inode hash table entry allocation\n");
92 memcpy(&inode->buf, buf, sizeof(struct stat));
93 @@ -1350,10 +1351,10 @@
94 inline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)
96 if((dir->count % DIR_ENTRIES) == 0)
97 - if((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)
98 + if((dir->list = (struct dir_ent **)realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)
99 BAD_ERROR("Out of memory in add_dir_entry\n");
101 - if((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)
102 + if((dir->list[dir->count] = (struct dir_ent *)malloc(sizeof(struct dir_ent))) == NULL)
103 BAD_ERROR("Out of memory in linux_opendir\n");
106 @@ -1363,7 +1364,7 @@
107 dir->list[dir->count]->inode = inode_info;
108 dir->list[dir->count]->dir = sub_dir;
109 dir->list[dir->count]->our_dir = dir;
110 - dir->list[dir->count++]->data = data;
111 + dir->list[dir->count++]->data = (struct old_root_entry_info *)data;
112 dir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);
115 @@ -1392,7 +1393,7 @@
116 struct dirent *d_name;
117 struct dir_info *dir;
119 - if((dir = malloc(sizeof(struct dir_info))) == NULL)
120 + if((dir = (struct dir_info *)malloc(sizeof(struct dir_info))) == NULL)
123 if(pathname[0] != '\0' && (dir->linuxdir = opendir(pathname)) == NULL) {
124 @@ -1527,10 +1528,10 @@
128 - if((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)
129 + if((dir_ent = (struct dir_ent *)malloc(sizeof(struct dir_ent))) == NULL)
130 BAD_ERROR("Out of memory in dir_scan\n");
132 - if((inode_info = malloc(sizeof(struct inode_info))) == NULL)
133 + if((inode_info = (struct inode_info *)malloc(sizeof(struct inode_info))) == NULL)
134 BAD_ERROR("Out of memory in dir_scan\n");
136 dir_ent->name = dir_ent->pathname = strdup(pathname);
137 @@ -1929,7 +1930,7 @@
140 else if(strcmp(argv[i], "-noappend") == 0)
142 + deletesquash = TRUE;
144 else if(strcmp(argv[i], "-keep-as-directory") == 0)
145 keep_as_directory = TRUE;
146 @@ -1996,7 +1997,7 @@
147 perror("Could not create destination file");
151 + deletesquash = TRUE;
153 perror("Could not stat destination file");
155 @@ -2011,7 +2012,7 @@
158 } else if(S_ISREG(buf.st_mode)) {
159 - if((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {
160 + if((fd = open(argv[source + 1], (deletesquash ? O_TRUNC : 0) | O_RDWR)) == -1) {
161 perror("Could not open regular file for writing as destination");
164 @@ -2023,7 +2024,7 @@
169 + if(!deletesquash) {
170 if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {
171 ERROR("Failed to read existing filesystem - will not overwrite - ABORTING!\n");
173 @@ -2068,7 +2069,7 @@
174 else if(strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "-root-becomes") == 0 || strcmp(argv[i], "-ef") == 0)
179 printf("Creating %s %d.%d filesystem on %s, block size %d.\n",
180 be ? "big endian" : "little endian", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);
181 bytes = sizeof(squashfs_super_block);
182 @@ -2176,7 +2177,7 @@
184 block_offset = check_data ? 3 : 2;
186 - if(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))
187 + if(deletesquash && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))
188 dir_scan(&inode, source_path[0], scan1_readdir);
189 else if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))
190 dir_scan(&inode, source_path[0], scan1_single_readdir);
191 diff -u squashfs3.0old/squashfs-tools/read_fs.c squashfs3.0/squashfs-tools/read_fs.c
192 --- squashfs3.0old/squashfs-tools/read_fs.c 2006-03-15 21:36:21.000000000 +0000
193 +++ squashfs3.0/squashfs-tools/read_fs.c 2006-04-17 11:01:56.000000000 +0100
195 fprintf(stderr, s, ## args); \
201 int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)
203 unsigned short c_byte;
208 read_bytes(fd, start, 2, (char *) block);
209 ((unsigned char *) &c_byte)[1] = block[0];
210 ((unsigned char *) &c_byte)[0] = block[1];
212 *root_inode_block = bytes;
214 if((size - bytes < SQUASHFS_METADATA_SIZE) &&
215 - ((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))
216 + ((*inode_table = (unsigned char *)realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))
218 TRACE("scan_inode_table: reading block 0x%llx\n", start);
219 if((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {
220 @@ -145,14 +145,14 @@
222 *root_inode_size = bytes - (*root_inode_block + root_inode_offset);
223 bytes = *root_inode_block + root_inode_offset;
226 squashfs_base_inode_header sinode;
227 memcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));
228 SQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));
230 memcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));
231 if(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {
234 squashfs_dir_inode_header sinode;
235 memcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));
236 SQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);
238 memcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));
239 directory_start_block = dir_inode->dir.start_block;
243 squashfs_ldir_inode_header sinode;
244 memcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));
245 SQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);
249 for(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {
252 squashfs_reg_inode_header sinode;
253 memcpy(&sinode, cur_ptr, sizeof(inode));
254 SQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);
255 @@ -191,13 +191,13 @@
257 TRACE("scan_inode_table: regular file, file_size %lld, blocks %d\n", inode.file_size, blocks);
259 - if((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {
260 + if((block_list = (unsigned int *)malloc(blocks * sizeof(unsigned int))) == NULL) {
261 ERROR("Out of memory in block list malloc\n");
265 cur_ptr += sizeof(inode);
268 unsigned int sblock_list[blocks];
269 memcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));
270 SQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);
273 unsigned int *block_list;
277 squashfs_lreg_inode_header sinodep;
278 memcpy(&sinodep, cur_ptr, sizeof(sinodep));
279 SQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);
280 @@ -238,12 +238,12 @@
282 start = inode.start_block;
284 - if((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {
285 + if((block_list = (unsigned int *)malloc(blocks * sizeof(unsigned int))) == NULL) {
286 ERROR("Out of memory in block list malloc\n");
292 unsigned int sblock_list[blocks];
293 memcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));
294 SQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);
296 case SQUASHFS_SYMLINK_TYPE: {
297 squashfs_symlink_inode_header inodep;
301 squashfs_symlink_inode_header sinodep;
302 memcpy(&sinodep, cur_ptr, sizeof(sinodep));
303 SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
305 case SQUASHFS_DIR_TYPE: {
306 squashfs_dir_inode_header dir_inode;
310 squashfs_dir_inode_header sinode;
311 memcpy(&sinode, cur_ptr, sizeof(dir_inode));
312 SQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);
314 squashfs_ldir_inode_header dir_inode;
319 squashfs_ldir_inode_header sinode;
320 memcpy(&sinode, cur_ptr, sizeof(dir_inode));
321 SQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);
323 cur_ptr += sizeof(squashfs_ldir_inode_header);
324 for(i = 0; i < dir_inode.i_count; i++) {
325 squashfs_dir_index index;
328 squashfs_dir_index sindex;
329 memcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));
330 SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
331 @@ -348,14 +348,14 @@
332 read_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);
334 /* Check it is a SQUASHFS superblock */
337 if(sBlk->s_magic != SQUASHFS_MAGIC) {
338 if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
339 squashfs_super_block sblk;
340 ERROR("Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\n", source);
341 SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
342 memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
346 ERROR("Can't find a SQUASHFS superblock on %s\n", source);
351 #if __BYTE_ORDER == __BIG_ENDIAN
359 printf("Found a valid SQUASHFS superblock on %s.\n", source);
361 long long start = sBlk->directory_table_start + directory_start_block, last_start_block;
364 - if((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)
365 + if((directory_table = (unsigned char *)malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)
367 while(bytes < size) {
368 TRACE("squashfs_readdir: reading block 0x%llx, bytes read so far %d\n", start, bytes);
372 while(bytes < size) {
375 squashfs_dir_header sdirh;
376 memcpy(&sdirh, directory_table + bytes, sizeof(sdirh));
377 SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
379 bytes += sizeof(dirh);
384 squashfs_dir_entry sdire;
385 memcpy(&sdire, directory_table + bytes, sizeof(sdire));
386 SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
393 squashfs_fragment_index sfragment_table_index[indexes];
395 read_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);
397 TRACE("Read fragment table block %d, from 0x%llx, length %d\n", i, fragment_table_index[i], length);
402 squashfs_fragment_entry sfragment;
403 for(i = 0; i < sBlk->fragments; i++) {
404 SQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));
407 memcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);
411 read_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);
413 squashfs_uid uids_copy[sBlk->no_uids];
415 SQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);
420 read_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);
422 squashfs_uid guids_copy[sBlk->no_guids];
423 diff -u squashfs3.0old/squashfs-tools/sort.c squashfs3.0/squashfs-tools/sort.c
424 --- squashfs3.0old/squashfs-tools/sort.c 2006-03-15 21:36:21.000000000 +0000
425 +++ squashfs3.0/squashfs-tools/sort.c 2006-04-17 11:01:33.000000000 +0100
427 struct priority_entry *new_priority_entry;
430 - if((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {
431 + if((new_priority_entry = (struct priority_entry *)malloc(sizeof(struct priority_entry))) == NULL) {
432 ERROR("Out of memory allocating priority entry\n");
436 #define ADD_ENTRY(buf, priority) {\
437 int hash = buf.st_ino & 0xffff;\
438 struct sort_info *s;\
439 - if((s = malloc(sizeof(struct sort_info))) == NULL) {\
440 + if((s = (struct sort_info *)malloc(sizeof(struct sort_info))) == NULL) {\
441 ERROR("Out of memory allocating sort list entry\n");\