071607c57d74121d9113200d112374b335aaf090
[ipfire-2.x.git] / src / patches / squashfstools-3.0.patch
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
4 @@ -72,7 +72,7 @@
5  #define EXIT_MKSQUASHFS()      do {\
6                                         if(restore)\
7                                                 restorefs();\
8 -                                       if(delete && destination_file && !block_device)\
9 +                                       if(deletesquash && destination_file && !block_device)\
10                                                 unlink(destination_file);\
11                                         exit(1);\
12                                 } while(0)
13 @@ -81,7 +81,7 @@
14                                         EXIT_MKSQUASHFS();\
15                                 } while(0)
16  
17 -int delete = FALSE;
18 +int deletesquash = FALSE;
19  long long total_compressed = 0, total_uncompressed = 0;
20  int fd;
21  
22 @@ -251,6 +251,7 @@
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 *));
30 @@ -285,7 +286,7 @@
31  }
32  
33  
34 -void sighandler()
35 +void sighandler(int signal)
36  {
37         if(interrupted == 1)
38                 restorefs();
39 @@ -297,7 +298,7 @@
40  }
41  
42  
43 -void sighandler2()
44 +void sighandler2(int signal)
45  {
46         EXIT_MKSQUASHFS();
47  }
48 @@ -693,7 +694,7 @@
49  
50  void scan2_init_dir(struct directory *dir)
51  {
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");
55         }
56  
57 @@ -720,7 +721,7 @@
58         }
59  
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");
64                 }
65  
66 @@ -737,7 +738,7 @@
67  
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;
75 @@ -1175,7 +1176,7 @@
76         int blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;
77         unsigned int *block_list, *block_listp;
78  
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;
83  
84 @@ -1329,7 +1330,7 @@
85                 inode = inode->next;
86         }
87  
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");
91  
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)
95  {
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");
100  
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");
104  
105         if(sub_dir)
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);
113  }
114  
115 @@ -1392,7 +1393,7 @@
116         struct dirent *d_name;
117         struct dir_info *dir;
118  
119 -       if((dir = malloc(sizeof(struct dir_info))) == NULL)
120 +       if((dir = (struct dir_info *)malloc(sizeof(struct dir_info))) == NULL)
121                 return NULL;
122  
123         if(pathname[0] != '\0' && (dir->linuxdir = opendir(pathname)) == NULL) {
124 @@ -1527,10 +1528,10 @@
125         if(dir_info == NULL)
126                 return;
127  
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");
131  
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");
135  
136         dir_ent->name = dir_ent->pathname = strdup(pathname);
137 @@ -1929,7 +1930,7 @@
138                         break;
139  
140                 else if(strcmp(argv[i], "-noappend") == 0)
141 -                       delete = TRUE;
142 +                       deletesquash = TRUE;
143  
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");
148                                 exit(1);
149                         }
150 -                       delete = TRUE;
151 +                       deletesquash = TRUE;
152                 } else {
153                         perror("Could not stat destination file");
154                         exit(1);
155 @@ -2011,7 +2012,7 @@
156                         block_device = 1;
157  
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");
162                                 exit(1);
163                         }
164 @@ -2023,7 +2024,7 @@
165  
166         }
167  
168 -       if(!delete) {
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");
172                         EXIT_MKSQUASHFS();
173 @@ -2068,7 +2069,7 @@
174                 else if(strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "-root-becomes") == 0 || strcmp(argv[i], "-ef") == 0)
175                         i++;
176  
177 -       if(delete) {
178 +       if(deletesquash) {
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 @@
183  
184         block_offset = check_data ? 3 : 2;
185  
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
194 @@ -61,14 +61,14 @@
195                                                 fprintf(stderr, s, ## args); \
196                                         } while(0)
197  
198 -int swap;
199 +int swapsquash;
200  
201  int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)
202  {
203         unsigned short c_byte;
204         int offset = 2;
205         
206 -       if(swap) {
207 +       if(swapsquash) {
208                 read_bytes(fd, start, 2, (char *) block);
209                 ((unsigned char *) &c_byte)[1] = block[0];
210                 ((unsigned char *) &c_byte)[0] = block[1]; 
211 @@ -125,7 +125,7 @@
212                         *root_inode_block = bytes;
213                 }
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))
217                         return FALSE;
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 @@
221          */
222         *root_inode_size = bytes - (*root_inode_block + root_inode_offset);
223         bytes = *root_inode_block + root_inode_offset;
224 -       if(swap) {
225 +       if(swapsquash) {
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));
229         } else
230                 memcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));
231         if(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {
232 -               if(swap) {
233 +               if(swapsquash) {
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);
237 @@ -160,7 +160,7 @@
238                         memcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));
239                 directory_start_block = dir_inode->dir.start_block;
240         } else {
241 -               if(swap) {
242 +               if(swapsquash) {
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);
246 @@ -170,7 +170,7 @@
247         }
248  
249         for(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {
250 -               if(swap) {
251 +               if(swapsquash) {
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 @@
256  
257                                 TRACE("scan_inode_table: regular file, file_size %lld, blocks %d\n", inode.file_size, blocks);
258  
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");
262                                         goto failed;
263                                 }
264  
265                                 cur_ptr += sizeof(inode);
266 -                               if(swap) {
267 +                               if(swapsquash) {
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);
271 @@ -222,7 +222,7 @@
272                                 int i, start;
273                                 unsigned int *block_list;
274  
275 -                               if(swap) {
276 +                               if(swapsquash) {
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 @@
281                                         sBlk->block_log;
282                                 start = inode.start_block;
283  
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");
287                                         goto failed;
288                                 }
289  
290 -                               if(swap) {
291 +                               if(swapsquash) {
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);
295 @@ -263,7 +263,7 @@
296                         case SQUASHFS_SYMLINK_TYPE: {
297                                 squashfs_symlink_inode_header inodep;
298         
299 -                               if(swap) {
300 +                               if(swapsquash) {
301                                         squashfs_symlink_inode_header sinodep;
302                                         memcpy(&sinodep, cur_ptr, sizeof(sinodep));
303                                         SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
304 @@ -276,7 +276,7 @@
305                         case SQUASHFS_DIR_TYPE: {
306                                 squashfs_dir_inode_header dir_inode;
307  
308 -                               if(swap) {
309 +                               if(swapsquash) {
310                                         squashfs_dir_inode_header sinode;
311                                         memcpy(&sinode, cur_ptr, sizeof(dir_inode));
312                                         SQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);
313 @@ -292,7 +292,7 @@
314                                 squashfs_ldir_inode_header dir_inode;
315                                 int i;
316  
317 -                               if(swap) {
318 +                               if(swapsquash) {
319                                         squashfs_ldir_inode_header sinode;
320                                         memcpy(&sinode, cur_ptr, sizeof(dir_inode));
321                                         SQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);
322 @@ -304,7 +304,7 @@
323                                 cur_ptr += sizeof(squashfs_ldir_inode_header);
324                                 for(i = 0; i < dir_inode.i_count; i++) {
325                                         squashfs_dir_index index;
326 -                                       if(swap) {
327 +                                       if(swapsquash) {
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);
333  
334         /* Check it is a SQUASHFS superblock */
335 -       swap = 0;
336 +       swapsquash = 0;
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));
343 -                       swap = 1;
344 +                       swapsquash = 1;
345                 } else  {
346                         ERROR("Can't find a SQUASHFS superblock on %s\n", source);
347                         goto failed_mount;
348 @@ -373,9 +373,9 @@
349         }
350  
351  #if __BYTE_ORDER == __BIG_ENDIAN
352 -       *be = !swap;
353 +       *be = !swapsquash;
354  #else
355 -       *be = swap;
356 +       *be = swapsquash;
357  #endif
358  
359         printf("Found a valid SQUASHFS superblock on %s.\n", source);
360 @@ -416,7 +416,7 @@
361         long long start = sBlk->directory_table_start + directory_start_block, last_start_block; 
362  
363         size += offset;
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)
366                 return NULL;
367         while(bytes < size) {
368                 TRACE("squashfs_readdir: reading block 0x%llx, bytes read so far %d\n", start, bytes);
369 @@ -433,7 +433,7 @@
370  
371         bytes = offset;
372         while(bytes < size) {                   
373 -               if(swap) {
374 +               if(swapsquash) {
375                         squashfs_dir_header sdirh;
376                         memcpy(&sdirh, directory_table + bytes, sizeof(sdirh));
377                         SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
378 @@ -445,7 +445,7 @@
379                 bytes += sizeof(dirh);
380  
381                 while(dir_count--) {
382 -                       if(swap) {
383 +                       if(swapsquash) {
384                                 squashfs_dir_entry sdire;
385                                 memcpy(&sdire, directory_table + bytes, sizeof(sdire));
386                                 SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
387 @@ -481,7 +481,7 @@
388                 return 0;
389         }
390  
391 -       if(swap) {
392 +       if(swapsquash) {
393                 squashfs_fragment_index sfragment_table_index[indexes];
394  
395                 read_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);
396 @@ -494,7 +494,7 @@
397                 TRACE("Read fragment table block %d, from 0x%llx, length %d\n", i, fragment_table_index[i], length);
398         }
399  
400 -       if(swap) {
401 +       if(swapsquash) {
402                 squashfs_fragment_entry sfragment;
403                 for(i = 0; i < sBlk->fragments; i++) {
404                         SQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));
405 @@ -584,7 +584,7 @@
406                 }
407                 memcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);
408  
409 -               if(!swap)
410 +               if(!swapsquash)
411                         read_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);
412                 else {
413                         squashfs_uid uids_copy[sBlk->no_uids];
414 @@ -593,7 +593,7 @@
415                         SQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);
416                 }
417  
418 -               if(!swap)
419 +               if(!swapsquash)
420                         read_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);
421                 else {
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
426 @@ -87,7 +87,7 @@
427         struct priority_entry *new_priority_entry;
428  
429         priority += 32768;
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");
433                 return FALSE;
434         }
435 @@ -117,7 +117,7 @@
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");\
442                 return FALSE;\
443         }\