1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
|
Modify the source code to use the lzma {,de}compression routines.
Leon Woestenberg <leonw@mailcan.com>
diff -Nur squashfs-tools/mksquashfs.c squashfs-lzma-tools/mksquashfs.c
--- squashfs-tools/mksquashfs.c 2006-08-31 00:07:37.000000000 +0200
+++ squashfs-lzma-tools/mksquashfs.c 2006-08-22 09:35:14.000000000 +0200
@@ -40,16 +40,13 @@
#include <signal.h>
#include <setjmp.h>
#include <sys/mman.h>
-#include <pthread.h>
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#include <sys/sysctl.h>
#else
#include <endian.h>
-#include <sys/sysinfo.h>
#endif
#include <squashfs_fs.h>
@@ -149,7 +146,7 @@
struct inode_info *inode_info[INODE_HASH_SIZE];
/* hash tables used to do fast duplicate searches in duplicate check */
-struct file_info *dupl[65536];
+struct file_info *dupl[65536], *frag_dups[65536];
int dup_files = 0;
/* list of exclude dirs/files */
@@ -165,7 +162,7 @@
/* fragment block data structures */
int fragments = 0;
-struct file_buffer *fragment_data = NULL;
+char fragment_data[SQUASHFS_FILE_SIZE];
int fragment_size = 0;
struct fragment {
unsigned int index;
@@ -174,7 +171,6 @@
};
#define FRAG_SIZE 32768
squashfs_fragment_entry *fragment_table = NULL;
-int fragments_outstanding = 0;
/* current inode number for directories and non directories */
@@ -198,15 +194,13 @@
/* in memory file info */
struct file_info {
- long long file_size;
long long bytes;
unsigned short checksum;
- unsigned short fragment_checksum;
long long start;
unsigned int *block_list;
struct file_info *next;
struct fragment *fragment;
- char checksum_flag;
+ unsigned short fragment_checksum;
};
/* count of how many times SIGINT or SIGQUIT has been sent */
@@ -225,7 +219,6 @@
sdir_count, sfifo_count, ssock_count, sdup_files;
int sfragments;
int restore = 0;
-int threads;
/* flag whether destination file is a block device */
int block_device = 0;
@@ -236,67 +229,14 @@
/* save destination file name for deleting on error */
char *destination_file = NULL;
-/* data allocator status struct. Allocators are used to keep
- track of memory buffers passed between different threads */
-struct allocator {
- int max_buffers;
- int count;
- int buffer_size;
- pthread_mutex_t mutex;
- pthread_cond_t wait;
-};
-
-/* struct describing a memory buffer passed between threads */
-struct file_buffer {
- struct allocator *allocator;
- void (*release)(int);
- int release_data;
- long long block;
- int size;
- int c_byte;
- unsigned int block_order;
- int fragment;
- int error;
- struct file_buffer *next;
- char data[0];
-};
-
-/* struct describing queues used to pass data between threads */
-struct queue {
- int size;
- int readp;
- int writep;
- pthread_mutex_t mutex;
- pthread_cond_t empty;
- pthread_cond_t full;
- void **data;
-};
-
-/* describes the list of blocks in a file which is a possible
- duplicate. For each block, it indicates whether the block is
- in memory or on disk */
-struct buffer_list {
- long long start;
- int size;
- struct file_buffer *read_buffer;
+/* structure to used to pass in a pointer or an integer
+ * to duplicate buffer read helper functions.
+ */
+struct duplicate_buffer_handle {
+ char *ptr;
+ long long start;
};
-struct allocator *reader_buffer, *writer_buffer, *fragment_buffer;
-struct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;
-pthread_t *thread, *deflator_thread, *frag_deflator_thread;
-pthread_mutex_t fragment_mutex;
-pthread_cond_t fragment_waiting;
-pthread_mutex_t pos_mutex;
-
-/* user options that control parallelisation */
-int processors = -1;
-/* default size of output buffer in Mbytes */
-#define WRITER_BUFFER_DEFAULT 512
-/* default size of input buffer in Mbytes */
-#define READER_BUFFER_DEFAULT 64
-int writer_buffer_size;
-int reader_buffer_size;
-
void add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);
extern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);
extern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,
@@ -309,166 +249,18 @@
unsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,
void (push_directory_entry)(char *, squashfs_inode, int, int),
squashfs_fragment_entry **fragment_table);
-extern int read_sort_file(char *filename, int source, char *source_path[]);
-extern void sort_files_and_write(struct dir_info *dir);
-struct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);
+int get_sorted_inode(squashfs_inode *inode, struct stat *buf);
+int read_sort_file(char *filename, int source, char *source_path[]);
+void sort_files_and_write(struct dir_info *dir);
+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);
struct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));
-struct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);
-extern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);
-extern struct priority_entry *priority_list[65536];
-
-
-struct allocator *alloc_init(int buffer_size, int max_buffers)
-{
- struct allocator *allocator = malloc(sizeof(struct allocator));
-
- if(allocator == NULL)
- return NULL;
-
- allocator->max_buffers = max_buffers;
- allocator->buffer_size = buffer_size;
- allocator->count = 0;
- pthread_mutex_init(&allocator->mutex, NULL);
- pthread_cond_init(&allocator->wait, NULL);
-
- return allocator;
-}
-
-
-struct file_buffer *alloc_get(struct allocator *allocator)
-{
- struct file_buffer *file_buffer;
-
- pthread_mutex_lock(&allocator->mutex);
-
- while(allocator->count == allocator->max_buffers)
- pthread_cond_wait(&allocator->wait, &allocator->mutex);
-
- if((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)
- goto failed;
-
- file_buffer->release = NULL;
- file_buffer->allocator = allocator;
- allocator->count ++;
-
-failed:
- pthread_mutex_unlock(&allocator->mutex);
- return file_buffer;
-}
-
-
-struct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)
-{
- struct file_buffer *file_buffer = alloc_get(allocator);
-
- if(file_buffer) {
- file_buffer->release = release;
- file_buffer->release_data = release_data;
- }
- return file_buffer;
-}
-
-
-void alloc_free(struct file_buffer *file_buffer)
-{
- struct allocator *allocator;
-
- if(file_buffer == NULL)
- return;
-
- allocator = file_buffer->allocator;
-
- if(file_buffer->release)
- file_buffer->release(file_buffer->release_data);
-
- pthread_mutex_lock(&allocator->mutex);
- free(file_buffer);
- if(allocator->count == 0)
- ERROR("alloc_free: freeing buffer for empty allocator!\n");
- else
- allocator->count --;
- pthread_cond_signal(&allocator->wait);
- pthread_mutex_unlock(&allocator->mutex);
-}
-
-
-struct queue *queue_init(int size)
-{
- struct queue *queue = malloc(sizeof(struct queue));
-
- if(queue == NULL)
- return NULL;
-
- if((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {
- free(queue);
- return NULL;
- }
-
- queue->size = size + 1;
- queue->readp = queue->writep = 0;
- pthread_mutex_init(&queue->mutex, NULL);
- pthread_cond_init(&queue->empty, NULL);
- pthread_cond_init(&queue->full, NULL);
-
- return queue;
-}
-
-
-void queue_put(struct queue *queue, void *data)
-{
- int nextp;
-
- pthread_mutex_lock(&queue->mutex);
-
- while((nextp = (queue->writep + 1) % queue->size) == queue->readp)
- pthread_cond_wait(&queue->full, &queue->mutex);
-
- queue->data[queue->writep] = data;
- queue->writep = nextp;
- pthread_cond_signal(&queue->empty);
- pthread_mutex_unlock(&queue->mutex);
-}
-
-
-void *queue_get(struct queue *queue)
-{
- void *data;
- pthread_mutex_lock(&queue->mutex);
-
- while(queue->readp == queue->writep)
- pthread_cond_wait(&queue->empty, &queue->mutex);
-
- data = queue->data[queue->readp];
- queue->readp = (queue->readp + 1) % queue->size;
- pthread_cond_signal(&queue->full);
- pthread_mutex_unlock(&queue->mutex);
-
- return data;
-}
-
#define MKINODE(A) ((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))
-inline void waitforthread(int i)
-{
- TRACE("Waiting for thread %d\n", i);
- while(thread[i] != 0)
- sched_yield();
-}
-
-
void restorefs()
{
- int i;
-
ERROR("Exiting - restoring original filesystem!\n\n");
-
- for(i = 0; i < 2 + processors * 2; i++)
- pthread_kill(thread[i], SIGUSR1);
- for(i = 0; i < 2 + processors * 2; i++)
- waitforthread(i);
- TRACE("All threads in signal handler\n");
bytes = sbytes;
memcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);
memcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);
@@ -495,13 +287,12 @@
void sighandler()
{
- if(++interrupted > 2)
- return;
- if(interrupted == 2)
+ if(interrupted == 1)
restorefs();
else {
ERROR("Interrupting will restore original filesystem!\n");
ERROR("Interrupt again to quit\n");
+ interrupted ++;
}
}
@@ -512,81 +303,22 @@
}
-void sigusr1_handler()
-{
- int i;
- sigset_t sigmask;
- pthread_t thread_id = pthread_self();
-
- for(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);
- thread[i] = (pthread_t) 0;
-
- TRACE("Thread %d(%p) in sigusr1_handler\n", i, thread_id);
-
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGINT);
- sigaddset(&sigmask, SIGQUIT);
- sigaddset(&sigmask, SIGUSR1);
- while(1) {
- sigsuspend(&sigmask);
- TRACE("After wait in sigusr1_handler :(\n");
- }
-}
-
-
-unsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)
+unsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)
{
- unsigned long c_byte;
+ unsigned long c_byte = block_size << 1;
unsigned int res;
- z_stream *stream = *strm;
-
- if(uncompressed)
- goto notcompressed;
-
- if(stream == NULL) {
- if((stream = *strm = malloc(sizeof(z_stream))) == NULL)
- BAD_ERROR("mangle::compress failed, not enough memory\n");
-
- stream->zalloc = Z_NULL;
- stream->zfree = Z_NULL;
- stream->opaque = 0;
- if((res = deflateInit(stream, 9)) != Z_OK) {
- if(res == Z_MEM_ERROR)
- BAD_ERROR("zlib::compress failed, not enough memory\n");
- else if(res == Z_STREAM_ERROR)
- BAD_ERROR("zlib::compress failed, not a valid compression level\n");
- else if(res == Z_VERSION_ERROR)
- BAD_ERROR("zlib::compress failed, incorrect zlib version\n");
- else
- BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
- }
- } else if((res = deflateReset(stream)) != Z_OK) {
- if(res == Z_STREAM_ERROR)
- BAD_ERROR("zlib::compress failed, stream state inconsistent\n");
- else
- BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
- }
-
- stream->next_in = (unsigned char *) s;
- stream->avail_in = size;
- stream->next_out = (unsigned char *) d;
- stream->avail_out = block_size;
-
- res = deflate(stream, Z_FINISH);
- if(res != Z_STREAM_END && res != Z_OK) {
- if(res == Z_STREAM_ERROR)
- BAD_ERROR("zlib::compress failed, stream state inconsistent\n");
+ if(!uncompressed && (res = compress2((unsigned char *) d, &c_byte, (unsigned char *) s, size, 9)) != Z_OK) {
+ if(res == Z_MEM_ERROR)
+ BAD_ERROR("zlib::compress failed, not enough memory\n");
else if(res == Z_BUF_ERROR)
- BAD_ERROR("zlib::compress failed, no progress possible\n");
+ BAD_ERROR("zlib::compress failed, not enough room in output buffer\n");
else
BAD_ERROR("zlib::compress failed, unknown error %d\n", res);
+ return 0;
}
- c_byte = stream->total_out;
-
- if(res != Z_STREAM_END || c_byte >= size) {
-notcompressed:
+ if(uncompressed || c_byte >= size) {
memcpy(d, s, size);
return size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);
}
@@ -595,14 +327,6 @@
}
-unsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)
-{
- static z_stream *stream = NULL;
-
- return mangle2(&stream, d, s, size, block_size, uncompressed, data_block);
-}
-
-
squashfs_base_inode_header *get_inode(int req_size)
{
int data_space;
@@ -655,7 +379,6 @@
{
off_t off = byte;
- pthread_mutex_lock(&pos_mutex);
if(lseek(fd, off, SEEK_SET) == -1) {
perror("Lseek on destination failed");
EXIT_MKSQUASHFS();
@@ -665,7 +388,6 @@
perror("Read on destination failed");
EXIT_MKSQUASHFS();
}
- pthread_mutex_unlock(&pos_mutex);
}
@@ -673,9 +395,6 @@
{
off_t off = byte;
- if(interrupted < 2)
- pthread_mutex_lock(&pos_mutex);
-
if(lseek(fd, off, SEEK_SET) == -1) {
perror("Lseek on destination failed");
EXIT_MKSQUASHFS();
@@ -685,9 +404,6 @@
perror("Write on destination failed");
EXIT_MKSQUASHFS();
}
-
- if(interrupted < 2)
- pthread_mutex_unlock(&pos_mutex);
}
@@ -1173,23 +889,10 @@
}
-char *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)
+char *get_fragment(char *buffer, struct fragment *fragment)
{
- squashfs_fragment_entry *disk_fragment;
- int size;
-
- if(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)
- return buffer + fragment->offset;
-
- if(fragment_data && fragment->index == fragments)
- return fragment_data->data + fragment->offset;
-
- pthread_mutex_lock(&fragment_mutex);
- while(fragment_table[fragment->index].pending)
- pthread_cond_wait(&fragment_waiting, &fragment_mutex);
- pthread_mutex_unlock(&fragment_mutex);
- disk_fragment = &fragment_table[fragment->index];
- size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);
+ squashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];
+ int size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);
if(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {
int res;
@@ -1209,74 +912,53 @@
} else
read_bytes(fd, disk_fragment->start_block, size, buffer);
- *cached_fragment = fragment->index;
return buffer + fragment->offset;
}
-void ensure_fragments_flushed()
-{
- pthread_mutex_lock(&fragment_mutex);
- while(fragments_outstanding)
- pthread_cond_wait(&fragment_waiting, &fragment_mutex);
- pthread_mutex_unlock(&fragment_mutex);
-}
-
-
void write_fragment()
{
+ int compressed_size;
+ char buffer[block_size << 1];
+
if(fragment_size == 0)
return;
- pthread_mutex_lock(&fragment_mutex);
- if(fragments % FRAG_SIZE == 0) {
- if((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {
- pthread_mutex_unlock(&fragment_mutex);
+ if(fragments % FRAG_SIZE == 0)
+ if((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)
BAD_ERROR("Out of memory in fragment table\n");
- }
- }
- fragment_data->size = fragment_size;
- fragment_data->block = fragments;
- fragment_table[fragments].pending = TRUE;
- fragments_outstanding ++;
- queue_put(to_frag, fragment_data);
+ fragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);
+ fragment_table[fragments].start_block = bytes;
+ compressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);
+ write_bytes(fd, bytes, compressed_size, buffer);
+ bytes += compressed_size;
+ total_uncompressed += fragment_size;
+ total_compressed += compressed_size;
+ TRACE("Writing fragment %d, uncompressed size %d, compressed size %d\n",fragments, fragment_size, compressed_size);
fragments ++;
fragment_size = 0;
- pthread_mutex_unlock(&fragment_mutex);
-}
-
-void frag_release(int block)
-{
- pthread_mutex_lock(&fragment_mutex);
- fragment_table[block].pending = FALSE;
- pthread_cond_signal(&fragment_waiting);
- pthread_mutex_unlock(&fragment_mutex);
}
static struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};
-struct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)
+struct fragment *get_and_fill_fragment(char *buff, int size)
{
struct fragment *ffrg;
-
- if(file_buffer == NULL || file_buffer->size == 0)
+ if(size == 0)
return &empty_fragment;
- if(fragment_size + file_buffer->size > block_size)
+ if(fragment_size + size > block_size)
write_fragment();
if((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)
BAD_ERROR("Out of memory in fragment block allocation!\n");
- if(fragment_size == 0)
- fragment_data = alloc_get(fragment_buffer);
-
ffrg->index = fragments;
ffrg->offset = fragment_size;
- ffrg->size = file_buffer->size;
- memcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);
- fragment_size += file_buffer->size;
+ ffrg->size = size;
+ memcpy(fragment_data + fragment_size, buff, size);
+ fragment_size += size;
return ffrg;
}
@@ -1333,10 +1015,19 @@
}
+char *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)
+{
+ char *v = handle->ptr;
+ handle->ptr += avail_bytes;
+ return v;
+}
+
+
char read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];
-char *read_from_disk(long long start, unsigned int avail_bytes)
+char *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)
{
- read_bytes(fd, start, avail_bytes, read_from_file_buffer);
+ read_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);
+ handle->start += avail_bytes;
return read_from_file_buffer;
}
@@ -1344,205 +1035,99 @@
/*
* Compute 16 bit BSD checksum over the data
*/
-unsigned short get_checksum(char *buff, int bytes, unsigned short chksum)
-{
- unsigned char *b = (unsigned char *) buff;
-
- while(bytes --) {
- chksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;
- chksum += *b++;
- }
-
- return chksum;
-}
-
-
-unsigned short get_checksum_disk(long long start, long long l)
+unsigned short get_checksum(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, long long l)
{
unsigned short chksum = 0;
- unsigned int bytes;
+ unsigned int bytes = 0;
+ unsigned char *b;
+ struct duplicate_buffer_handle position = *handle;
while(l) {
bytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;
l -= bytes;
- chksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);
- start += bytes;
- }
-
- return chksum;
-}
-
-
-unsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)
-{
- unsigned short chksum = 0;
- int block;
-
- for(block = 0; block < blocks; block ++) {
- struct buffer_list *b = &buffer_list[block];
-
- if(b->read_buffer)
- chksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);
- else
- chksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);
+ b = (unsigned char *) get_next_file_block(&position, bytes);
+ while(bytes--) {
+ chksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;
+ chksum += *b++;
+ }
}
return chksum;
}
-unsigned short get_checksum_mem(char *buff, int bytes)
-{
- return get_checksum(buff, bytes, 0);
-}
-
-
-unsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)
-{
- if(file_buffer == NULL)
- return 0;
- else
- return get_checksum(file_buffer->data, file_buffer->size, 0);
-}
-
-
int cached_frag = -1;
-char fragdata[SQUASHFS_FILE_MAX_SIZE];
-#define DUP_HASH(a) (a & 0xffff)
-void add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)
+void add_file(long long start, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)
{
struct fragment *frg;
+ struct file_info *dupl_ptr;
char *datap;
+ struct duplicate_buffer_handle handle;
unsigned int *block_list = block_listp;
- struct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];
- if(!duplicate_checking || file_size == 0)
+ if(!duplicate_checking)
return;
- for(; dupl_ptr; dupl_ptr = dupl_ptr->next) {
- if(file_size != dupl_ptr->file_size)
- continue;
- if(blocks != 0 && start != dupl_ptr->start)
- continue;
- if(fragment != dupl_ptr->fragment->index)
- continue;
- if(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))
- continue;
- return;
- }
-
if((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)
BAD_ERROR("Out of memory in fragment block allocation!\n");
frg->index = fragment;
frg->offset = offset;
frg->size = bytes;
-
- add_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);
+ if(fragment == cached_frag || fragment == SQUASHFS_INVALID_FRAG)
+ datap = fragment_data + offset;
+ else
+ datap = get_fragment(fragment_data, frg);
+ handle.start = start;
+ if((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)
+ dupl_ptr->fragment = frg;
+ else
+ free(block_list);
+ cached_frag = fragment;
}
+
char cached_fragment[SQUASHFS_FILE_SIZE];
int cached_frag1 = -1;
-int pre_duplicate(long long file_size)
-{
- struct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];
-
- for(; dupl_ptr; dupl_ptr = dupl_ptr->next)
- if(dupl_ptr->file_size == file_size)
- return TRUE;
-
- return FALSE;
-}
-
-
-int pre_duplicate_frag(long long file_size, unsigned short checksum)
+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)
{
- struct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];
-
- for(; dupl_ptr; dupl_ptr = dupl_ptr->next)
- if(dupl_ptr->file_size == file_size) {
- if(dupl_ptr->checksum_flag == FALSE) {
- dupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);
- dupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);
- dupl_ptr->checksum_flag = TRUE;
- }
- if(dupl_ptr->fragment_checksum == checksum)
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-struct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)
-{
- struct file_info *dupl_ptr;
+ unsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);
+ struct duplicate_buffer_handle handle = { frag_data, 0 };
+ unsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);
+ struct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];
- if((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {
- BAD_ERROR("Out of memory in dup_files allocation!\n");
- }
-
- dupl_ptr->file_size = file_size;
- dupl_ptr->bytes = bytes;
- dupl_ptr->block_list = block_list;
- dupl_ptr->start = start;
- dupl_ptr->fragment = fragment;
- dupl_ptr->checksum = checksum;
- dupl_ptr->fragment_checksum = fragment_checksum;
- dupl_ptr->checksum_flag = checksum_flag;
- dupl_ptr->next = dupl[DUP_HASH(file_size)];
- dupl[DUP_HASH(file_size)] = dupl_ptr;
- dup_files ++;
-
- return dupl_ptr;
-}
-
-
-struct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)
-{
- struct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];
- int frag_bytes = file_buffer ? file_buffer->size : 0;
for(; dupl_ptr; dupl_ptr = dupl_ptr->next)
- if(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {
- char buffer2[SQUASHFS_FILE_MAX_SIZE];
+ if(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {
+ char buffer1[SQUASHFS_FILE_MAX_SIZE];
+ long long dup_bytes = dupl_ptr->bytes;
long long dup_start = dupl_ptr->start;
+ struct duplicate_buffer_handle position = *file_start;
char *buffer;
- int block;
+ while(dup_bytes) {
+ int avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;
- if(checksum_flag == FALSE) {
- checksum = get_checksum_buffer(buffer_list, blocks);
- fragment_checksum = get_checksum_mem_buffer(file_buffer);
- checksum_flag = TRUE;
- }
-
- if(dupl_ptr->checksum_flag == FALSE) {
- dupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);
- dupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);
- dupl_ptr->checksum_flag = TRUE;
- }
-
- if(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)
- continue;
-
- for(block = 0; block < blocks; block ++) {
- struct buffer_list *b = &buffer_list[block];
-
- if(b->read_buffer)
- buffer = b->read_buffer->data;
- else
- buffer = read_from_disk(b->start, b->size);
-
- read_bytes(fd, dup_start, b->size, buffer2);
- if(memcmp(buffer, buffer2, b->size) != 0)
+ buffer = get_next_file_block(&position, avail_bytes);
+ read_bytes(fd, dup_start, avail_bytes, buffer1);
+ if(memcmp(buffer, buffer1, avail_bytes) != 0)
break;
- dup_start += b->size;
+ dup_bytes -= avail_bytes;
+ dup_start += avail_bytes;
}
- if(block == blocks) {
- char *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);
+ if(dup_bytes == 0) {
+ char *fragment_buffer1;
+
+ if(dupl_ptr->fragment->index == fragments || dupl_ptr->fragment->index == SQUASHFS_INVALID_FRAG)
+ fragment_buffer1 = fragment_data + dupl_ptr->fragment->offset;
+ else if(dupl_ptr->fragment->index == cached_frag1)
+ fragment_buffer1 = cached_fragment + dupl_ptr->fragment->offset;
+ else {
+ fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment);
+ cached_frag1 = dupl_ptr->fragment->index;
+ }
- if(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {
+ if(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {
TRACE("Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\n", dupl_ptr->start,
dupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);
*block_list = dupl_ptr->block_list;
@@ -1554,520 +1139,135 @@
}
- return add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);
-}
-
-
-void reader_read_file(struct dir_ent *dir_ent)
-{
- struct stat *buf = &dir_ent->inode->buf;
- int count;
- int blocks = (buf->st_size + block_size - 1) >> block_log;
- int frag_block = !no_fragments && (always_use_fragments ||
- (buf->st_size < block_size)) ? buf->st_size >> block_log : -1;
- int file;
- static int block_order = 0;
- struct file_buffer *file_buffer;
-
- if(buf->st_size == 0 || dir_ent->inode->read)
- return;
-
- if((file = open(dir_ent->pathname, O_RDONLY)) == -1)
- goto read_err;
-
- for(count = 0; count < blocks; count ++) {
- file_buffer = alloc_get(reader_buffer);
-
- if((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {
- close(file);
- goto read_err2;
- }
- file_buffer->block = count;
- file_buffer->block_order = block_order ++;
- file_buffer->error = FALSE;
- if(file_buffer->fragment = count == frag_block)
- queue_put(from_deflate, file_buffer);
- else
- queue_put(from_reader, file_buffer);
- }
-
- close(file);
- dir_ent->inode->read = TRUE;
-
- return;
-
-read_err:
- file_buffer = alloc_get(reader_buffer);
-read_err2:
- file_buffer->block_order = block_order ++;
- file_buffer->error = TRUE;
- queue_put(from_deflate, file_buffer);
-}
-
-
-void reader_scan(struct dir_info *dir) {
- int i;
-
- for(i = 0; i < dir->count; i++) {
- struct dir_ent *dir_ent = dir->list[i];
- struct stat *buf = &dir_ent->inode->buf;
- if(dir_ent->data)
- continue;
-
- switch(buf->st_mode & S_IFMT) {
- case S_IFREG:
- reader_read_file(dir_ent);
- break;
- case S_IFDIR:
- reader_scan(dir_ent->dir);
- break;
- }
- }
-}
-
-
-void *reader(void *arg)
-{
- int oldstate;
-
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
-
- if(!sorted)
- reader_scan(queue_get(to_reader));
- else {
- int i;
- struct priority_entry *entry;
-
- queue_get(to_reader);
- for(i = 65535; i >= 0; i--)
- for(entry = priority_list[i]; entry; entry = entry->next)
- reader_read_file(entry->dir);
- }
-}
-
-
-void *writer(void *arg)
-{
- int write_error = FALSE;
- int oldstate;
-
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
-
- while(1) {
- struct file_buffer *file_buffer = queue_get(to_writer);
- off_t off;
-
- if(file_buffer == NULL) {
- queue_put(from_writer, write_error ? (void *) &write_error : NULL);
- continue;
- }
-
- off = file_buffer->block;
-
- pthread_mutex_lock(&pos_mutex);
-
- if(!write_error && lseek(fd, off, SEEK_SET) == -1) {
- perror("Lseek on destination failed");
- write_error = TRUE;
- }
-
- if(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {
- perror("Write on destination failed");
- write_error = TRUE;
- }
- pthread_mutex_unlock(&pos_mutex);
-
- alloc_free(file_buffer);
- }
-}
-
-
-void *deflator(void *arg)
-{
- z_stream *stream = NULL;
- int oldstate;
-
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
-
- while(1) {
- struct file_buffer *file_buffer = queue_get(from_reader);
- struct file_buffer *write_buffer = alloc_get(writer_buffer);
-
- write_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);
- write_buffer->block = file_buffer->block;
- write_buffer->block_order = file_buffer->block_order;
- write_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);
- write_buffer->fragment = FALSE;
- write_buffer->error = FALSE;
- alloc_free(file_buffer);
- queue_put(from_deflate, write_buffer);
- }
-}
-
-
-void *frag_deflator(void *arg)
-{
- z_stream *stream = NULL;
- int oldstate;
-
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
-
- while(1) {
- int c_byte, compressed_size;
- struct file_buffer *file_buffer = queue_get(to_frag);
- struct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);
-
- c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);
- compressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
- pthread_mutex_lock(&fragment_mutex);
- fragment_table[file_buffer->block].size = c_byte;
- fragment_table[file_buffer->block].start_block = bytes;
- write_buffer->size = compressed_size;
- write_buffer->block = bytes;
- queue_put(to_writer, write_buffer);
- bytes += compressed_size;
- total_uncompressed += file_buffer->size;
- total_compressed += compressed_size;
- TRACE("Writing fragment %d, uncompressed size %d, compressed size %d\n", file_buffer->block, file_buffer->size, compressed_size);
- fragments_outstanding --;
- pthread_cond_signal(&fragment_waiting);
- pthread_mutex_unlock(&fragment_mutex);
- alloc_free(file_buffer);
+ if((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {
+ BAD_ERROR("Out of memory in dup_files allocation!\n");
}
-}
-
-
-#define HASH_ENTRIES 256
-#define BLOCK_HASH(a) (a % HASH_ENTRIES)
-struct file_buffer *block_hash[HASH_ENTRIES];
-void push_buffer(struct file_buffer *file_buffer)
-{
- int hash = BLOCK_HASH(file_buffer->block_order);
-
- file_buffer->next = block_hash[hash];
- block_hash[hash] = file_buffer;
-}
-
-
-struct file_buffer *get_file_buffer(struct queue *queue)
-{
- static unsigned int block_order = 0;
- int hash = BLOCK_HASH(block_order);
- struct file_buffer *file_buffer = block_hash[hash], *prev = NULL;
-
- for(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)
- if(file_buffer->block_order == block_order)
- break;
+ dupl_ptr->bytes = bytes;
+ dupl_ptr->checksum = checksum;
+ dupl_ptr->start = *start;
+ dupl_ptr->fragment_checksum = fragment_checksum;
+ dupl_ptr->block_list = *block_list;
- if(file_buffer) {
- if(prev)
- prev->next = file_buffer->next;
- else
- block_hash[hash] = file_buffer->next;
+ dup_files ++;
+ if(bytes) {
+ dupl_ptr->next = dupl[checksum];
+ dupl[checksum] = dupl_ptr;
} else {
- while(1) {
- file_buffer = queue_get(queue);
- if(file_buffer->block_order == block_order)
- break;
- push_buffer(file_buffer);
- }
+ dupl_ptr->next = frag_dups[fragment_checksum];
+ frag_dups[fragment_checksum] = dupl_ptr;
}
- block_order ++;
-
- return file_buffer;
-}
-
-
-int write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)
-{
- file_count ++;
- *duplicate_file = FALSE;
- return dir_ent->inode->nlink == 1 ?
- create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :
- create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);
-}
-
-
-int write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)
-{
- int file;
- struct file_info *dupl_ptr;
- struct fragment *fragment;
- unsigned int *block_listp = NULL;
- long long start = 0;
-
- dupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);
-
- if(dupl_ptr) {
- *duplicate_file = FALSE;
- fragment = get_and_fill_fragment(file_buffer);
- dupl_ptr->fragment = fragment;
- } else
- *duplicate_file = TRUE;
-
- alloc_free(file_buffer);
-
- total_bytes += size;
- file_count ++;
-
- return dir_ent->inode->nlink == 1 ?
- create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :
- create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);
-}
-
-
-int write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)
-{
- struct fragment *fragment;
- unsigned short checksum;
- struct file_buffer *file_buffer = get_file_buffer(from_deflate);
-
- if(file_buffer->size != size)
- printf("bug\n");
-
- if(file_buffer->error) {
- alloc_free(file_buffer);
- return FALSE;
- }
-
- checksum = get_checksum_mem_buffer(file_buffer);
-
- if(pre_duplicate_frag(size, checksum))
- return write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);
-
- fragment = get_and_fill_fragment(file_buffer);
-
- alloc_free(file_buffer);
-
- if(duplicate_checking)
- add_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);
-
- total_bytes += size;
- file_count ++;
-
- *duplicate_file = FALSE;
-
- return dir_ent->inode->nlink == 1 ?
- create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :
- create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);
+ return dupl_ptr;
}
-int write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)
+#define MINALLOCBYTES (1024 * 1024)
+int write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)
{
- int block, status;
+ int block = 0, i, file, whole_file = 1, status;
unsigned int c_byte, frag_bytes;
- long long bbytes, file_bytes, start;
+ long long bbytes, file_bytes = 0, start;
+ char buff[block_size], *c_buffer = NULL, *filename = dir_ent->pathname;
struct fragment *fragment;
- struct file_info *dupl_ptr;
- int blocks = (read_size + block_size - 1) >> block_log;
- unsigned int *block_list;
- struct file_buffer *read_buffer;
-
- if(!no_fragments && always_use_fragments) {
- blocks = read_size >> block_log;
- frag_bytes = read_size % block_size;
- } else
- frag_bytes = 0;
+ struct file_info *dupl_ptr = NULL;
+ struct duplicate_buffer_handle handle;
+ long long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;
+ int blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;
+ unsigned int *block_list, *block_listp;
if((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)
BAD_ERROR("Out of memory allocating block_list\n");
+ block_listp = block_list;
- ensure_fragments_flushed();
-
- file_bytes = 0;
- start = bytes;
- for(block = 0; block < blocks; block ++) {
- read_buffer = get_file_buffer(from_deflate);
- if(read_buffer->error)
- goto read_err;
-
- block_list[block] = read_buffer->c_byte;
- read_buffer->block = bytes;
- bytes += read_buffer->size;
- file_bytes += read_buffer->size;
- queue_put(to_writer, read_buffer);
- }
-
- if(frag_bytes != 0) {
- read_buffer = get_file_buffer(from_deflate);
- if(read_buffer->size != frag_bytes)
- printf("bug\n");
- if(read_buffer->error)
- goto read_err;
- } else
- read_buffer = NULL;
-
- fragment = get_and_fill_fragment(read_buffer);
- alloc_free(read_buffer);
-
- if(duplicate_checking)
- add_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);
- file_count ++;
- total_bytes += read_size;
- if(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))
- status = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);
- else
- status = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);
- if(duplicate_checking == FALSE)
- free(block_list);
- return status;
-
-read_err:
- perror("Error in reading file, skipping...");
- if(block) {
- queue_put(to_writer, NULL);
- if(queue_get(from_writer) != 0)
- EXIT_MKSQUASHFS();
- bytes = start;
- if(!block_device)
- ftruncate(fd, bytes);
- }
- free(block_list);
- alloc_free(read_buffer);
- return FALSE;
-}
-
-
-int write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)
-{
- int block, status, thresh;
- unsigned int c_byte, frag_bytes;
- long long bbytes, file_bytes, start;
- struct fragment *fragment;
- struct file_info *dupl_ptr;
- int blocks = (read_size + block_size - 1) >> block_log;
- unsigned int *block_list, *block_listp;
- struct file_buffer *read_buffer;
- struct file_data *file_data;
- struct buffer_list *buffer_list;
-
- if(!no_fragments && always_use_fragments) {
- blocks = read_size >> block_log;
+ if(!no_fragments && (read_size < block_size || always_use_fragments)) {
+ allocated_blocks = blocks = read_size >> block_log;
frag_bytes = read_size % block_size;
} else
frag_bytes = 0;
- if((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)
- BAD_ERROR("Out of memory allocating block_list\n");
- block_listp = block_list;
-
- if((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)
- BAD_ERROR("Out of memory allocating file block list\n");
-
- ensure_fragments_flushed();
+ if(size > read_size)
+ ERROR("file %s truncated to %lld bytes\n", filename, SQUASHFS_MAX_FILE_SIZE);
- file_bytes = 0;
- start = bytes;
- thresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;
- for(block = 0; block < blocks; block ++) {
- read_buffer = get_file_buffer(from_deflate);
- if(read_buffer->error)
- goto read_err;
+ total_bytes += read_size;
+ if((file = open(filename, O_RDONLY)) == -1)
+ goto read_err;
- block_list[block] = read_buffer->c_byte;
- read_buffer->block = bytes;
- bytes += read_buffer->size;
- file_bytes += read_buffer->size;
-
- if(block < thresh) {
- buffer_list[block].read_buffer = NULL;
- queue_put(to_writer, read_buffer);
- } else
- buffer_list[block].read_buffer = read_buffer;
- buffer_list[block].start = read_buffer->block;
- buffer_list[block].size = read_buffer->size;
+ do {
+ long long bytes = (((long long) allocated_blocks) + 1) << block_log;
+ if(bytes != ((size_t) bytes) || (c_buffer = (char *) malloc(bytes)) == NULL) {
+ TRACE("Out of memory allocating write_file buffer, allocated_blocks %ld, blocks %d\n", allocated_blocks, blocks);
+ whole_file = 0;
+ if(bytes < MINALLOCBYTES)
+ BAD_ERROR("Out of memory allocating write_file buffer, could not allocate %ld blocks (%d Kbytes)\n", allocated_blocks, allocated_blocks << (block_log - 10));
+ allocated_blocks >>= 1;
+ }
+ } while(!c_buffer);
+
+ for(start = bytes; block < blocks; file_bytes += bbytes) {
+ for(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {
+ int available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);
+ if(read(file, buff, available_bytes) == -1)
+ goto read_err;
+ c_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);
+ block_list[block ++] = c_byte;
+ bbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
+ }
+ if(!whole_file) {
+ write_bytes(fd, bytes, bbytes, c_buffer);
+ bytes += bbytes;
+ }
}
- if(frag_bytes != 0) {
- read_buffer = get_file_buffer(from_deflate);
- if(read_buffer->size != frag_bytes)
- printf("bug\n");
- if(read_buffer->error)
+ if(frag_bytes != 0)
+ if(read(file, buff, frag_bytes) == -1)
goto read_err;
- } else
- read_buffer = NULL;
-
- queue_put(to_writer, NULL);
- if(queue_get(from_writer) != 0)
- EXIT_MKSQUASHFS();
-
- dupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);
- if(dupl_ptr) {
- *duplicate_file = FALSE;
- for(block = thresh; block < blocks; block ++)
- queue_put(to_writer, buffer_list[block].read_buffer);
- fragment = get_and_fill_fragment(read_buffer);
- dupl_ptr->fragment = fragment;
+ close(file);
+ if(whole_file) {
+ handle.ptr = c_buffer;
+ if(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {
+ *duplicate_file = TRUE;
+ goto wr_inode;
+ }
+ write_bytes(fd, bytes, file_bytes, c_buffer);
+ bytes += file_bytes;
} else {
- *duplicate_file = TRUE;
- for(block = thresh; block < blocks; block ++)
- alloc_free(buffer_list[block].read_buffer);
- bytes = buffer_list[0].start;
- if(thresh && !block_device)
- ftruncate(fd, bytes);
+ handle.start = start;
+ if(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {
+ bytes = start;
+ if(!block_device)
+ ftruncate(fd, bytes);
+ *duplicate_file = TRUE;
+ goto wr_inode;
+ }
}
- alloc_free(read_buffer);
- free(buffer_list);
- file_count ++;
- total_bytes += read_size;
+ fragment = get_and_fill_fragment(buff, frag_bytes);
+ if(duplicate_checking)
+ dupl_ptr->fragment = fragment;
+
+ *duplicate_file = FALSE;
+wr_inode:
+ free(c_buffer);
+ file_count ++;
if(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))
status = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);
else
status = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);
- if(*duplicate_file == TRUE)
+ if(duplicate_checking == FALSE || *duplicate_file == TRUE)
free(block_list);
return status;
read_err:
perror("Error in reading file, skipping...");
- if(block && thresh) {
- queue_put(to_writer, NULL);
- if(queue_get(from_writer) != 0)
- EXIT_MKSQUASHFS();
- bytes = start;
- if(!block_device)
- ftruncate(fd, bytes);
- }
- for(blocks = thresh; blocks < block; blocks ++)
- alloc_free(buffer_list[blocks].read_buffer);
- free(buffer_list);
+ free(c_buffer);
free(block_list);
- alloc_free(read_buffer);
return FALSE;
}
-int write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)
-{
- long long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;
-
- if(size > read_size)
- ERROR("file %s truncated to %lld bytes\n", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);
-
- if(read_size == 0)
- return write_file_empty(inode, dir_ent, duplicate_file);
-
- if(!no_fragments && (read_size < block_size))
- return write_file_frag(inode, dir_ent, read_size, duplicate_file);
-
- if(pre_duplicate(read_size))
- return write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);
-
- *duplicate_file = FALSE;
- return write_file_blocks(inode, dir_ent, read_size);
-}
-
-
char b_buffer[8192];
char *name;
char *basename_r();
@@ -2134,7 +1334,6 @@
BAD_ERROR("Out of memory in inode hash table entry allocation\n");
memcpy(&inode->buf, buf, sizeof(struct stat));
- inode->read = FALSE;
inode->inode = SQUASHFS_INVALID_BLK;
inode->nlink = 1;
if((buf->st_mode & S_IFMT) == S_IFDIR)
@@ -2357,9 +1556,6 @@
return;
}
if(sorted)
- generate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);
- queue_put(to_reader, dir_info);
- if(sorted)
sort_files_and_write(dir_info);
dir_scan2(inode, dir_info);
}
@@ -2495,7 +1691,7 @@
case SQUASHFS_CHRDEV_TYPE:
INFO("character device %s inode 0x%llx LINK\n", dir_name, *inode);
break;
- case SQUASHFS_BLKDEV_TYPE:
+ caseSQUASHFS_BLKDEV_TYPE:
INFO("block device %s inode 0x%llx LINK\n", dir_name, *inode);
break;
case SQUASHFS_FIFO_TYPE:
@@ -2595,76 +1791,8 @@
}
-void initialise_threads()
-{
- int i;
- sigset_t sigmask, old_mask;
-
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGINT);
- sigaddset(&sigmask, SIGQUIT);
- if(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)
- BAD_ERROR("Failed to set signal mask in intialise_threads\n");
-
- signal(SIGUSR1, sigusr1_handler);
-
- if(processors == -1) {
-#ifndef linux
- int mib[2];
- size_t len = sizeof(processors);
-
- mib[0] = CTL_HW;
-#ifdef HW_AVAILCPU
- mib[1] = HW_AVAILCPU;
-#else
- mib[1] = HW_NCPU;
-#endif
-
- if(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {
- ERROR("Failed to get number of available processors. Defaulting to 1\n");
- processors = 1;
- }
-#else
- processors = get_nprocs();
-#endif
- }
-
- if((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)
- BAD_ERROR("Out of memory allocating thread descriptors\n");
- deflator_thread = &thread[2];
- frag_deflator_thread = &deflator_thread[processors];
-
- to_reader = queue_init(1);
- from_reader = queue_init(reader_buffer_size);
- to_writer = queue_init(writer_buffer_size);
- from_writer = queue_init(1);
- from_deflate = queue_init(reader_buffer_size);
- to_frag = queue_init(processors * 2);
- reader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);
- writer_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);
- fragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);
- pthread_create(&thread[0], NULL, reader, NULL);
- pthread_create(&thread[1], NULL, writer, NULL);
- pthread_mutex_init(&fragment_mutex, NULL);
- pthread_cond_init(&fragment_waiting, NULL);
-
- for(i = 0; i < processors; i++) {
- if(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )
- BAD_ERROR("Failed to create thread\n");
- if(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)
- BAD_ERROR("Failed to create thread\n");
- }
-
- printf("Parallel mksquashfs: Using %d processor%s\n", processors,
- processors == 1 ? "" : "s");
-
- if(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)
- BAD_ERROR("Failed to set signal mask in intialise_threads\n");
-}
-
-
#define VERSION() \
- printf("mksquashfs version 3.1-r2 (2006/08/30)\n");\
+ printf("mksquashfs version 3.0 (2006/03/15)\n");\
printf("copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\n\n"); \
printf("This program is free software; you can redistribute it and/or\n");\
printf("modify it under the terms of the GNU General Public License\n");\
@@ -2682,7 +1810,6 @@
char *b, *root_name = NULL;
int be, nopad = FALSE, keep_as_directory = FALSE, orig_be;
squashfs_inode inode;
- int readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;
#if __BYTE_ORDER == __BIG_ENDIAN
be = TRUE;
@@ -2701,34 +1828,7 @@
source_path = argv + 1;
source = i - 2;
for(; i < argc; i++) {
- if(strcmp(argv[i], "-processors") == 0) {
- if((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\0')) {
- ERROR("%s: -processors missing or invalid processor number\n", argv[0]);
- exit(1);
- }
- if(processors < 1) {
- ERROR("%s: -processors should be 1 or larger\n", argv[0]);
- exit(1);
- }
- } else if(strcmp(argv[i], "-read_queue") == 0) {
- if((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\0')) {
- ERROR("%s: -read_queue missing or invalid queue size\n", argv[0]);
- exit(1);
- }
- if(readb_mbytes < 1) {
- ERROR("%s: -read_queue should be 1 megabyte or larger\n", argv[0]);
- exit(1);
- }
- } else if(strcmp(argv[i], "-write_queue") == 0) {
- if((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\0')) {
- ERROR("%s: -write_queue missing or invalid queue size\n", argv[0]);
- exit(1);
- }
- if(writeb_mbytes < 1) {
- ERROR("%s: -write_queue should be 1 megabyte or larger\n", argv[0]);
- exit(1);
- }
- } else if(strcmp(argv[i], "-b") == 0) {
+ if(strcmp(argv[i], "-b") == 0) {
if((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\0')) {
ERROR("%s: -b missing or invalid block size\n", argv[0]);
exit(1);
@@ -2851,9 +1951,6 @@
ERROR("-version\t\tprint version, licence and copyright message\n");
ERROR("-info\t\t\tprint files written to filesystem\n");
ERROR("-b <block_size>\t\tset data block to <block_size>. Default %d bytes\n", SQUASHFS_FILE_SIZE);
- ERROR("-processors <number>\tUse <number> processors. By default will use number of\n\t\t\tprocessors available\n");
- ERROR("-read-queue <size>\tSet input queue to <size> Mbytes. Default %d Mbytes\n", READER_BUFFER_DEFAULT);
- ERROR("-write-queue <size>\tSet output queue to <size> Mbytes. Default %d Mbytes\n", WRITER_BUFFER_DEFAULT);
ERROR("-noI\t\t\tdo not compress inode table\n");
ERROR("-noD\t\t\tdo not compress data blocks\n");
ERROR("-noF\t\t\tdo not compress fragment blocks\n");
@@ -2887,9 +1984,6 @@
}
}
- reader_buffer_size = readb_mbytes << (20 - block_log);
- writer_buffer_size = writeb_mbytes << (20 - block_log);
-
for(i = 0; i < source; i++)
if(stat(source_path[i], &source_buf) == -1) {
fprintf(stderr, "Cannot stat source directory \"%s\" because %s\n", source_path[i], strerror(errno));
@@ -2975,8 +2069,6 @@
else if(strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "-root-becomes") == 0 || strcmp(argv[i], "-ef") == 0)
i++;
- initialise_threads();
-
if(delete) {
printf("Creating %s %d.%d filesystem on %s, block size %d.\n",
be ? "big endian" : "little endian", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);
@@ -3104,13 +2196,6 @@
restore_filesystem:
write_fragment();
sBlk.fragments = fragments;
- if(interrupted < 2) {
- ensure_fragments_flushed();
- queue_put(to_writer, NULL);
- if(queue_get(from_writer) != 0)
- EXIT_MKSQUASHFS();
- }
-
sBlk.inode_table_start = write_inodes();
sBlk.directory_table_start = write_directories();
sBlk.fragment_table_start = write_fragment_table();
diff -Nur squashfs-tools/read_fs.c squashfs-lzma-tools/read_fs.c
--- squashfs-tools/read_fs.c 2006-08-21 01:40:35.000000000 +0200
+++ squashfs-lzma-tools/read_fs.c 2006-08-22 09:39:31.000000000 +0200
@@ -22,7 +22,7 @@
*/
extern void read_bytes(int, long long, int, char *);
-extern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);
+extern int add_file(long long, long long, unsigned int *, int, unsigned int, int, int);
#define TRUE 1
#define FALSE 0
@@ -186,8 +186,7 @@
+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>
sBlk->block_log;
long long file_bytes = 0;
- int i;
- long long start = inode.start_block;
+ int i, start = inode.start_block;
unsigned int *block_list;
TRACE("scan_inode_table: regular file, file_size %lld, blocks %d\n", inode.file_size, blocks);
@@ -211,7 +210,7 @@
for(i = 0; i < blocks; i++)
file_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);
- add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);
+ add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);
cur_ptr += blocks * sizeof(unsigned int);
break;
}
@@ -220,8 +219,7 @@
int frag_bytes;
int blocks;
long long file_bytes = 0;
- int i;
- long long start;
+ int i, start;
unsigned int *block_list;
if(swap) {
@@ -258,7 +256,7 @@
for(i = 0; i < blocks; i++)
file_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);
- add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);
+ add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);
cur_ptr += blocks * sizeof(unsigned int);
break;
}
diff -Nur squashfs-tools/README squashfs-lzma-tools/README
--- squashfs-tools/README 1970-01-01 01:00:00.000000000 +0100
+++ squashfs-lzma-tools/README 2006-08-22 09:36:18.000000000 +0200
@@ -0,0 +1,2 @@
+This is mksquashfs patched with LZMA support
+and with the patch for 'fragment_table rounding bug'
\ No newline at end of file
diff -Nur squashfs-tools/sort.c squashfs-lzma-tools/sort.c
--- squashfs-tools/sort.c 2006-08-21 01:40:35.000000000 +0200
+++ squashfs-lzma-tools/sort.c 2006-06-25 05:17:43.000000000 +0200
@@ -71,6 +71,11 @@
struct sort_info *sort_info_list[65536];
+struct priority_entry {
+ struct dir_ent *dir;
+ struct priority_entry *next;
+};
+
struct priority_entry *priority_list[65536];
extern int silent;
@@ -230,6 +235,8 @@
squashfs_inode inode;
int duplicate_file;
+ generate_file_priorities(dir, 0, &dir->dir_ent->inode->buf);
+
for(i = 65535; i >= 0; i--)
for(entry = priority_list[i]; entry; entry = entry->next) {
TRACE("%d: %s\n", i - 32768, entry->dir->pathname);
diff -Nur squashfs-tools/sort.h squashfs-lzma-tools/sort.h
--- squashfs-tools/sort.h 2006-08-21 01:40:35.000000000 +0200
+++ squashfs-lzma-tools/sort.h 2006-06-25 05:17:43.000000000 +0200
@@ -51,12 +51,6 @@
squashfs_inode inode;
unsigned int type;
unsigned int inode_number;
- char read;
struct inode_info *next;
};
-
-struct priority_entry {
- struct dir_ent *dir;
- struct priority_entry *next;
-};
#endif
diff -Nur squashfs-tools/squashfs_fs.h squashfs-lzma-tools/squashfs_fs.h
--- squashfs-tools/squashfs_fs.h 2006-08-21 02:00:22.000000000 +0200
+++ squashfs-lzma-tools/squashfs_fs.h 2006-06-25 05:17:43.000000000 +0200
@@ -308,7 +308,7 @@
struct squashfs_fragment_entry {
long long start_block;
unsigned int size;
- unsigned int pending;
+ unsigned int unused;
} __attribute__ ((packed));
extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
|