python-pyrex: Rework DEPENDS updates
[openembedded.git] / recipes / linux / linux-rt-2.6.24 / squashfs-lzma-2.6.24.patch
blobfb92cbf7c57bc0f210af10be77fbac419680e5f5
1 diff -urN linux-2.6.23/fs/Kconfig linux-2.6.23.sqlzma/fs/Kconfig
2 --- linux-2.6.23/fs/Kconfig 2007-10-09 16:31:38.000000000 -0400
3 +++ linux-2.6.23.sqlzma/fs/Kconfig 2007-10-14 13:19:21.000000000 -0400
4 @@ -1364,6 +1364,72 @@
6 If unsure, say N.
8 +config SQUASHFS
9 + tristate "SquashFS 3.2 - Squashed file system support"
10 + select ZLIB_INFLATE
11 + help
12 + Saying Y here includes support for SquashFS 3.2 (a Compressed Read-
13 + Only File System). Squashfs is a highly compressed read-only
14 + filesystem for Linux. It uses zlib and/or LZMA compression to compress
15 + both files, inodes and directories. Inodes in the system are very
16 + small and all blocks are packed to minimise data overhead. Block sizes
17 + greater than 4K are supported up to a maximum of 64K. SquashFS 3.2
18 + supports 64 bit filesystems and files (larger than 4GB), full uid/gid
19 + information, hard links and timestamps.
21 + Squashfs is intended for general read-only filesystem use, for archival
22 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
23 + systems where low overhead is needed. Further information and
24 + filesystem tools are available from http://squashfs.sourceforge.net.
26 + If you want to compile this as a module ( = code which can be
27 + inserted in and removed from the running kernel whenever you want),
28 + say M here and read <file:Documentation/modules.txt>. The module
29 + will be called squashfs. Note that the root file system (the one
30 + containing the directory /) cannot be compiled as a module.
32 + If unsure, say N.
34 +config SQUASHFS_EMBEDDED
36 + bool "Additional options for memory-constrained systems"
37 + depends on SQUASHFS
38 + default n
39 + help
40 + Saying Y here allows you to specify cache sizes and how Squashfs
41 + allocates memory. This is only intended for memory constrained
42 + systems.
44 + If unsure, say N.
46 +config SQUASHFS_FRAGMENT_CACHE_SIZE
47 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
48 + depends on SQUASHFS
49 + default "3"
50 + help
51 + By default SquashFS caches the last 3 fragments read from
52 + the filesystem. Increasing this amount may mean SquashFS
53 + has to re-read fragments less often from disk, at the expense
54 + of extra system memory. Decreasing this amount will mean
55 + SquashFS uses less memory at the expense of extra reads from disk.
57 + Note there must be at least one cached fragment. Anything
58 + much more than three will probably not make much difference.
60 +config SQUASHFS_VMALLOC
61 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
62 + depends on SQUASHFS
63 + default n
64 + help
65 + By default SquashFS uses kmalloc to obtain fragment cache memory.
66 + Kmalloc memory is the standard kernel allocator, but it can fail
67 + on memory constrained systems. Because of the way Vmalloc works,
68 + Vmalloc can succeed when kmalloc fails. Specifying this option
69 + will make SquashFS always use Vmalloc to allocate the
70 + fragment cache memory.
72 + If unsure, say N.
74 config VXFS_FS
75 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
76 depends on BLOCK
77 diff -urN linux-2.6.23/fs/Makefile linux-2.6.23.sqlzma/fs/Makefile
78 --- linux-2.6.23/fs/Makefile 2007-10-09 16:31:38.000000000 -0400
79 +++ linux-2.6.23.sqlzma/fs/Makefile 2007-10-14 10:24:31.000000000 -0400
80 @@ -72,6 +72,7 @@
81 obj-$(CONFIG_JBD2) += jbd2/
82 obj-$(CONFIG_EXT2_FS) += ext2/
83 obj-$(CONFIG_CRAMFS) += cramfs/
84 +obj-$(CONFIG_SQUASHFS) += squashfs/
85 obj-y += ramfs/
86 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
87 obj-$(CONFIG_CODA_FS) += coda/
88 diff -urN linux-2.6.23/fs/squashfs/LzmaDecode.c linux-2.6.23.sqlzma/fs/squashfs/LzmaDecode.c
89 --- linux-2.6.23/fs/squashfs/LzmaDecode.c 1969-12-31 19:00:00.000000000 -0500
90 +++ linux-2.6.23.sqlzma/fs/squashfs/LzmaDecode.c 2007-10-14 12:44:42.000000000 -0400
91 @@ -0,0 +1,584 @@
92 +/*
93 + LzmaDecode.c
94 + LZMA Decoder (optimized for Speed version)
96 + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
97 + http://www.7-zip.org/
99 + LZMA SDK is licensed under two licenses:
100 + 1) GNU Lesser General Public License (GNU LGPL)
101 + 2) Common Public License (CPL)
102 + It means that you can select one of these two licenses and
103 + follow rules of that license.
105 + SPECIAL EXCEPTION:
106 + Igor Pavlov, as the author of this Code, expressly permits you to
107 + statically or dynamically link your Code (or bind by name) to the
108 + interfaces of this file without subjecting your linked Code to the
109 + terms of the CPL or GNU LGPL. Any modifications or additions
110 + to this file, however, are subject to the LGPL or CPL terms.
113 +#include "LzmaDecode.h"
115 +#define kNumTopBits 24
116 +#define kTopValue ((UInt32)1 << kNumTopBits)
118 +#define kNumBitModelTotalBits 11
119 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
120 +#define kNumMoveBits 5
122 +#define RC_READ_BYTE (*Buffer++)
124 +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
125 + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
127 +#ifdef _LZMA_IN_CB
129 +#define RC_TEST { if (Buffer == BufferLim) \
130 + { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
131 + BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
133 +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
135 +#else
137 +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
139 +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
141 +#endif
143 +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
145 +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
146 +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
147 +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
149 +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
150 + { UpdateBit0(p); mi <<= 1; A0; } else \
151 + { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
153 +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
155 +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
156 + { int i = numLevels; res = 1; \
157 + do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
158 + res -= (1 << numLevels); }
161 +#define kNumPosBitsMax 4
162 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
164 +#define kLenNumLowBits 3
165 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
166 +#define kLenNumMidBits 3
167 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
168 +#define kLenNumHighBits 8
169 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
171 +#define LenChoice 0
172 +#define LenChoice2 (LenChoice + 1)
173 +#define LenLow (LenChoice2 + 1)
174 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
175 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
176 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
179 +#define kNumStates 12
180 +#define kNumLitStates 7
182 +#define kStartPosModelIndex 4
183 +#define kEndPosModelIndex 14
184 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
186 +#define kNumPosSlotBits 6
187 +#define kNumLenToPosStates 4
189 +#define kNumAlignBits 4
190 +#define kAlignTableSize (1 << kNumAlignBits)
192 +#define kMatchMinLen 2
194 +#define IsMatch 0
195 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
196 +#define IsRepG0 (IsRep + kNumStates)
197 +#define IsRepG1 (IsRepG0 + kNumStates)
198 +#define IsRepG2 (IsRepG1 + kNumStates)
199 +#define IsRep0Long (IsRepG2 + kNumStates)
200 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
201 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
202 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
203 +#define LenCoder (Align + kAlignTableSize)
204 +#define RepLenCoder (LenCoder + kNumLenProbs)
205 +#define Literal (RepLenCoder + kNumLenProbs)
207 +#if Literal != LZMA_BASE_SIZE
208 +StopCompilingDueBUG
209 +#endif
211 +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
213 + unsigned char prop0;
214 + if (size < LZMA_PROPERTIES_SIZE)
215 + return LZMA_RESULT_DATA_ERROR;
216 + prop0 = propsData[0];
217 + if (prop0 >= (9 * 5 * 5))
218 + return LZMA_RESULT_DATA_ERROR;
220 + for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
221 + for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
222 + propsRes->lc = prop0;
223 + /*
224 + unsigned char remainder = (unsigned char)(prop0 / 9);
225 + propsRes->lc = prop0 % 9;
226 + propsRes->pb = remainder / 5;
227 + propsRes->lp = remainder % 5;
228 + */
231 + #ifdef _LZMA_OUT_READ
233 + int i;
234 + propsRes->DictionarySize = 0;
235 + for (i = 0; i < 4; i++)
236 + propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
237 + if (propsRes->DictionarySize == 0)
238 + propsRes->DictionarySize = 1;
240 + #endif
241 + return LZMA_RESULT_OK;
244 +#define kLzmaStreamWasFinishedId (-1)
246 +int LzmaDecode(CLzmaDecoderState *vs,
247 + #ifdef _LZMA_IN_CB
248 + ILzmaInCallback *InCallback,
249 + #else
250 + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
251 + #endif
252 + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
254 + CProb *p = vs->Probs;
255 + SizeT nowPos = 0;
256 + Byte previousByte = 0;
257 + UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
258 + UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
259 + int lc = vs->Properties.lc;
261 + #ifdef _LZMA_OUT_READ
263 + UInt32 Range = vs->Range;
264 + UInt32 Code = vs->Code;
265 + #ifdef _LZMA_IN_CB
266 + const Byte *Buffer = vs->Buffer;
267 + const Byte *BufferLim = vs->BufferLim;
268 + #else
269 + const Byte *Buffer = inStream;
270 + const Byte *BufferLim = inStream + inSize;
271 + #endif
272 + int state = vs->State;
273 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
274 + int len = vs->RemainLen;
275 + UInt32 globalPos = vs->GlobalPos;
276 + UInt32 distanceLimit = vs->DistanceLimit;
278 + Byte *dictionary = vs->Dictionary;
279 + UInt32 dictionarySize = vs->Properties.DictionarySize;
280 + UInt32 dictionaryPos = vs->DictionaryPos;
282 + Byte tempDictionary[4];
284 + #ifndef _LZMA_IN_CB
285 + *inSizeProcessed = 0;
286 + #endif
287 + *outSizeProcessed = 0;
288 + if (len == kLzmaStreamWasFinishedId)
289 + return LZMA_RESULT_OK;
291 + if (dictionarySize == 0)
293 + dictionary = tempDictionary;
294 + dictionarySize = 1;
295 + tempDictionary[0] = vs->TempDictionary[0];
298 + if (len == kLzmaNeedInitId)
301 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
302 + UInt32 i;
303 + for (i = 0; i < numProbs; i++)
304 + p[i] = kBitModelTotal >> 1;
305 + rep0 = rep1 = rep2 = rep3 = 1;
306 + state = 0;
307 + globalPos = 0;
308 + distanceLimit = 0;
309 + dictionaryPos = 0;
310 + dictionary[dictionarySize - 1] = 0;
311 + #ifdef _LZMA_IN_CB
312 + RC_INIT;
313 + #else
314 + RC_INIT(inStream, inSize);
315 + #endif
317 + len = 0;
319 + while(len != 0 && nowPos < outSize)
321 + UInt32 pos = dictionaryPos - rep0;
322 + if (pos >= dictionarySize)
323 + pos += dictionarySize;
324 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
325 + if (++dictionaryPos == dictionarySize)
326 + dictionaryPos = 0;
327 + len--;
329 + if (dictionaryPos == 0)
330 + previousByte = dictionary[dictionarySize - 1];
331 + else
332 + previousByte = dictionary[dictionaryPos - 1];
334 + #else /* if !_LZMA_OUT_READ */
336 + int state = 0;
337 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
338 + int len = 0;
339 + const Byte *Buffer;
340 + const Byte *BufferLim;
341 + UInt32 Range;
342 + UInt32 Code;
344 + #ifndef _LZMA_IN_CB
345 + *inSizeProcessed = 0;
346 + #endif
347 + *outSizeProcessed = 0;
350 + UInt32 i;
351 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
352 + for (i = 0; i < numProbs; i++)
353 + p[i] = kBitModelTotal >> 1;
356 + #ifdef _LZMA_IN_CB
357 + RC_INIT;
358 + #else
359 + RC_INIT(inStream, inSize);
360 + #endif
362 + #endif /* _LZMA_OUT_READ */
364 + while(nowPos < outSize)
366 + CProb *prob;
367 + UInt32 bound;
368 + int posState = (int)(
369 + (nowPos
370 + #ifdef _LZMA_OUT_READ
371 + + globalPos
372 + #endif
374 + & posStateMask);
376 + prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
377 + IfBit0(prob)
379 + int symbol = 1;
380 + UpdateBit0(prob)
381 + prob = p + Literal + (LZMA_LIT_SIZE *
382 + (((
383 + (nowPos
384 + #ifdef _LZMA_OUT_READ
385 + + globalPos
386 + #endif
388 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
390 + if (state >= kNumLitStates)
392 + int matchByte;
393 + #ifdef _LZMA_OUT_READ
394 + UInt32 pos = dictionaryPos - rep0;
395 + if (pos >= dictionarySize)
396 + pos += dictionarySize;
397 + matchByte = dictionary[pos];
398 + #else
399 + matchByte = outStream[nowPos - rep0];
400 + #endif
401 + do
403 + int bit;
404 + CProb *probLit;
405 + matchByte <<= 1;
406 + bit = (matchByte & 0x100);
407 + probLit = prob + 0x100 + bit + symbol;
408 + RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
410 + while (symbol < 0x100);
412 + while (symbol < 0x100)
414 + CProb *probLit = prob + symbol;
415 + RC_GET_BIT(probLit, symbol)
417 + previousByte = (Byte)symbol;
419 + outStream[nowPos++] = previousByte;
420 + #ifdef _LZMA_OUT_READ
421 + if (distanceLimit < dictionarySize)
422 + distanceLimit++;
424 + dictionary[dictionaryPos] = previousByte;
425 + if (++dictionaryPos == dictionarySize)
426 + dictionaryPos = 0;
427 + #endif
428 + if (state < 4) state = 0;
429 + else if (state < 10) state -= 3;
430 + else state -= 6;
432 + else
434 + UpdateBit1(prob);
435 + prob = p + IsRep + state;
436 + IfBit0(prob)
438 + UpdateBit0(prob);
439 + rep3 = rep2;
440 + rep2 = rep1;
441 + rep1 = rep0;
442 + state = state < kNumLitStates ? 0 : 3;
443 + prob = p + LenCoder;
445 + else
447 + UpdateBit1(prob);
448 + prob = p + IsRepG0 + state;
449 + IfBit0(prob)
451 + UpdateBit0(prob);
452 + prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
453 + IfBit0(prob)
455 + #ifdef _LZMA_OUT_READ
456 + UInt32 pos;
457 + #endif
458 + UpdateBit0(prob);
460 + #ifdef _LZMA_OUT_READ
461 + if (distanceLimit == 0)
462 + #else
463 + if (nowPos == 0)
464 + #endif
465 + return LZMA_RESULT_DATA_ERROR;
467 + state = state < kNumLitStates ? 9 : 11;
468 + #ifdef _LZMA_OUT_READ
469 + pos = dictionaryPos - rep0;
470 + if (pos >= dictionarySize)
471 + pos += dictionarySize;
472 + previousByte = dictionary[pos];
473 + dictionary[dictionaryPos] = previousByte;
474 + if (++dictionaryPos == dictionarySize)
475 + dictionaryPos = 0;
476 + #else
477 + previousByte = outStream[nowPos - rep0];
478 + #endif
479 + outStream[nowPos++] = previousByte;
480 + #ifdef _LZMA_OUT_READ
481 + if (distanceLimit < dictionarySize)
482 + distanceLimit++;
483 + #endif
485 + continue;
487 + else
489 + UpdateBit1(prob);
492 + else
494 + UInt32 distance;
495 + UpdateBit1(prob);
496 + prob = p + IsRepG1 + state;
497 + IfBit0(prob)
499 + UpdateBit0(prob);
500 + distance = rep1;
502 + else
504 + UpdateBit1(prob);
505 + prob = p + IsRepG2 + state;
506 + IfBit0(prob)
508 + UpdateBit0(prob);
509 + distance = rep2;
511 + else
513 + UpdateBit1(prob);
514 + distance = rep3;
515 + rep3 = rep2;
517 + rep2 = rep1;
519 + rep1 = rep0;
520 + rep0 = distance;
522 + state = state < kNumLitStates ? 8 : 11;
523 + prob = p + RepLenCoder;
526 + int numBits, offset;
527 + CProb *probLen = prob + LenChoice;
528 + IfBit0(probLen)
530 + UpdateBit0(probLen);
531 + probLen = prob + LenLow + (posState << kLenNumLowBits);
532 + offset = 0;
533 + numBits = kLenNumLowBits;
535 + else
537 + UpdateBit1(probLen);
538 + probLen = prob + LenChoice2;
539 + IfBit0(probLen)
541 + UpdateBit0(probLen);
542 + probLen = prob + LenMid + (posState << kLenNumMidBits);
543 + offset = kLenNumLowSymbols;
544 + numBits = kLenNumMidBits;
546 + else
548 + UpdateBit1(probLen);
549 + probLen = prob + LenHigh;
550 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
551 + numBits = kLenNumHighBits;
554 + RangeDecoderBitTreeDecode(probLen, numBits, len);
555 + len += offset;
558 + if (state < 4)
560 + int posSlot;
561 + state += kNumLitStates;
562 + prob = p + PosSlot +
563 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
564 + kNumPosSlotBits);
565 + RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
566 + if (posSlot >= kStartPosModelIndex)
568 + int numDirectBits = ((posSlot >> 1) - 1);
569 + rep0 = (2 | ((UInt32)posSlot & 1));
570 + if (posSlot < kEndPosModelIndex)
572 + rep0 <<= numDirectBits;
573 + prob = p + SpecPos + rep0 - posSlot - 1;
575 + else
577 + numDirectBits -= kNumAlignBits;
578 + do
580 + RC_NORMALIZE
581 + Range >>= 1;
582 + rep0 <<= 1;
583 + if (Code >= Range)
585 + Code -= Range;
586 + rep0 |= 1;
589 + while (--numDirectBits != 0);
590 + prob = p + Align;
591 + rep0 <<= kNumAlignBits;
592 + numDirectBits = kNumAlignBits;
595 + int i = 1;
596 + int mi = 1;
597 + do
599 + CProb *prob3 = prob + mi;
600 + RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
601 + i <<= 1;
603 + while(--numDirectBits != 0);
606 + else
607 + rep0 = posSlot;
608 + if (++rep0 == (UInt32)(0))
610 + /* it's for stream version */
611 + len = kLzmaStreamWasFinishedId;
612 + break;
616 + len += kMatchMinLen;
617 + #ifdef _LZMA_OUT_READ
618 + if (rep0 > distanceLimit)
619 + #else
620 + if (rep0 > nowPos)
621 + #endif
622 + return LZMA_RESULT_DATA_ERROR;
624 + #ifdef _LZMA_OUT_READ
625 + if (dictionarySize - distanceLimit > (UInt32)len)
626 + distanceLimit += len;
627 + else
628 + distanceLimit = dictionarySize;
629 + #endif
631 + do
633 + #ifdef _LZMA_OUT_READ
634 + UInt32 pos = dictionaryPos - rep0;
635 + if (pos >= dictionarySize)
636 + pos += dictionarySize;
637 + previousByte = dictionary[pos];
638 + dictionary[dictionaryPos] = previousByte;
639 + if (++dictionaryPos == dictionarySize)
640 + dictionaryPos = 0;
641 + #else
642 + previousByte = outStream[nowPos - rep0];
643 + #endif
644 + len--;
645 + outStream[nowPos++] = previousByte;
647 + while(len != 0 && nowPos < outSize);
650 + RC_NORMALIZE;
652 + #ifdef _LZMA_OUT_READ
653 + vs->Range = Range;
654 + vs->Code = Code;
655 + vs->DictionaryPos = dictionaryPos;
656 + vs->GlobalPos = globalPos + (UInt32)nowPos;
657 + vs->DistanceLimit = distanceLimit;
658 + vs->Reps[0] = rep0;
659 + vs->Reps[1] = rep1;
660 + vs->Reps[2] = rep2;
661 + vs->Reps[3] = rep3;
662 + vs->State = state;
663 + vs->RemainLen = len;
664 + vs->TempDictionary[0] = tempDictionary[0];
665 + #endif
667 + #ifdef _LZMA_IN_CB
668 + vs->Buffer = Buffer;
669 + vs->BufferLim = BufferLim;
670 + #else
671 + *inSizeProcessed = (SizeT)(Buffer - inStream);
672 + #endif
673 + *outSizeProcessed = nowPos;
674 + return LZMA_RESULT_OK;
676 diff -urN linux-2.6.23/fs/squashfs/LzmaDecode.h linux-2.6.23.sqlzma/fs/squashfs/LzmaDecode.h
677 --- linux-2.6.23/fs/squashfs/LzmaDecode.h 1969-12-31 19:00:00.000000000 -0500
678 +++ linux-2.6.23.sqlzma/fs/squashfs/LzmaDecode.h 2007-10-14 12:44:42.000000000 -0400
679 @@ -0,0 +1,113 @@
680 +/*
681 + LzmaDecode.h
682 + LZMA Decoder interface
684 + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
685 + http://www.7-zip.org/
687 + LZMA SDK is licensed under two licenses:
688 + 1) GNU Lesser General Public License (GNU LGPL)
689 + 2) Common Public License (CPL)
690 + It means that you can select one of these two licenses and
691 + follow rules of that license.
693 + SPECIAL EXCEPTION:
694 + Igor Pavlov, as the author of this code, expressly permits you to
695 + statically or dynamically link your code (or bind by name) to the
696 + interfaces of this file without subjecting your linked code to the
697 + terms of the CPL or GNU LGPL. Any modifications or additions
698 + to this file, however, are subject to the LGPL or CPL terms.
701 +#ifndef __LZMADECODE_H
702 +#define __LZMADECODE_H
704 +#include "LzmaTypes.h"
706 +/* #define _LZMA_IN_CB */
707 +/* Use callback for input data */
709 +/* #define _LZMA_OUT_READ */
710 +/* Use read function for output data */
712 +/* #define _LZMA_PROB32 */
713 +/* It can increase speed on some 32-bit CPUs,
714 + but memory usage will be doubled in that case */
716 +/* #define _LZMA_LOC_OPT */
717 +/* Enable local speed optimizations inside code */
719 +#ifdef _LZMA_PROB32
720 +#define CProb UInt32
721 +#else
722 +#define CProb UInt16
723 +#endif
725 +#define LZMA_RESULT_OK 0
726 +#define LZMA_RESULT_DATA_ERROR 1
728 +#ifdef _LZMA_IN_CB
729 +typedef struct _ILzmaInCallback
731 + int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
732 +} ILzmaInCallback;
733 +#endif
735 +#define LZMA_BASE_SIZE 1846
736 +#define LZMA_LIT_SIZE 768
738 +#define LZMA_PROPERTIES_SIZE 5
740 +typedef struct _CLzmaProperties
742 + int lc;
743 + int lp;
744 + int pb;
745 + #ifdef _LZMA_OUT_READ
746 + UInt32 DictionarySize;
747 + #endif
748 +}CLzmaProperties;
750 +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
752 +#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
754 +#define kLzmaNeedInitId (-2)
756 +typedef struct _CLzmaDecoderState
758 + CLzmaProperties Properties;
759 + CProb *Probs;
761 + #ifdef _LZMA_IN_CB
762 + const unsigned char *Buffer;
763 + const unsigned char *BufferLim;
764 + #endif
766 + #ifdef _LZMA_OUT_READ
767 + unsigned char *Dictionary;
768 + UInt32 Range;
769 + UInt32 Code;
770 + UInt32 DictionaryPos;
771 + UInt32 GlobalPos;
772 + UInt32 DistanceLimit;
773 + UInt32 Reps[4];
774 + int State;
775 + int RemainLen;
776 + unsigned char TempDictionary[4];
777 + #endif
778 +} CLzmaDecoderState;
780 +#ifdef _LZMA_OUT_READ
781 +#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
782 +#endif
784 +int LzmaDecode(CLzmaDecoderState *vs,
785 + #ifdef _LZMA_IN_CB
786 + ILzmaInCallback *inCallback,
787 + #else
788 + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
789 + #endif
790 + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
792 +#endif
793 diff -urN linux-2.6.23/fs/squashfs/LzmaTypes.h linux-2.6.23.sqlzma/fs/squashfs/LzmaTypes.h
794 --- linux-2.6.23/fs/squashfs/LzmaTypes.h 1969-12-31 19:00:00.000000000 -0500
795 +++ linux-2.6.23.sqlzma/fs/squashfs/LzmaTypes.h 2007-10-14 13:00:30.000000000 -0400
796 @@ -0,0 +1,45 @@
797 +/*
798 +LzmaTypes.h
800 +Types for LZMA Decoder
802 +This file written and distributed to public domain by Igor Pavlov.
803 +This file is part of LZMA SDK 4.40 (2006-05-01)
806 +#ifndef __LZMATYPES_H
807 +#define __LZMATYPES_H
809 +#ifndef _7ZIP_BYTE_DEFINED
810 +#define _7ZIP_BYTE_DEFINED
811 +typedef unsigned char Byte;
812 +#endif
814 +#ifndef _7ZIP_UINT16_DEFINED
815 +#define _7ZIP_UINT16_DEFINED
816 +typedef unsigned short UInt16;
817 +#endif
819 +#ifndef _7ZIP_UINT32_DEFINED
820 +#define _7ZIP_UINT32_DEFINED
821 +#ifdef _LZMA_UINT32_IS_ULONG
822 +typedef unsigned long UInt32;
823 +#else
824 +typedef unsigned int UInt32;
825 +#endif
826 +#endif
828 +/* #define _LZMA_SYSTEM_SIZE_T */
829 +/* Use system's size_t. You can use it to enable 64-bit sizes supporting */
831 +#ifndef _7ZIP_SIZET_DEFINED
832 +#define _7ZIP_SIZET_DEFINED
833 +#ifdef _LZMA_SYSTEM_SIZE_T
834 +#include <stddef.h>
835 +typedef size_t SizeT;
836 +#else
837 +typedef UInt32 SizeT;
838 +#endif
839 +#endif
841 +#endif
842 diff -urN linux-2.6.23/fs/squashfs/Makefile linux-2.6.23.sqlzma/fs/squashfs/Makefile
843 --- linux-2.6.23/fs/squashfs/Makefile 1969-12-31 19:00:00.000000000 -0500
844 +++ linux-2.6.23.sqlzma/fs/squashfs/Makefile 2007-10-14 12:56:24.000000000 -0400
845 @@ -0,0 +1,18 @@
847 +# Copyright (C) 2006 Junjiro Okajima
848 +# Copyright (C) 2006 Tomas Matejicek, slax.org
850 +# LICENSE follows the described one in lzma.txt.
852 +# $Id: Makefile,v 1.3 2006/11/27 03:54:58 jro Exp $
855 +# Makefile for the linux squashfs routines.
858 +obj-$(CONFIG_SQUASHFS) += unlzma.o sqlzma.o squashfs.o
859 +unlzma-y += module.o
860 +sqlzma-y += uncomp.o
861 +squashfs-y += inode.o
862 +squashfs-y += squashfs2_0.o
864 diff -urN linux-2.6.23/fs/squashfs/inode.c linux-2.6.23.sqlzma/fs/squashfs/inode.c
865 --- linux-2.6.23/fs/squashfs/inode.c 1969-12-31 19:00:00.000000000 -0500
866 +++ linux-2.6.23.sqlzma/fs/squashfs/inode.c 2007-10-14 10:29:23.000000000 -0400
867 @@ -0,0 +1,2430 @@
869 + * Squashfs - a compressed read only filesystem for Linux
871 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
872 + * Phillip Lougher <phillip@lougher.org.uk>
874 + * This program is free software; you can redistribute it and/or
875 + * modify it under the terms of the GNU General Public License
876 + * as published by the Free Software Foundation; either version 2,
877 + * or (at your option) any later version.
879 + * This program is distributed in the hope that it will be useful,
880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
882 + * GNU General Public License for more details.
884 + * You should have received a copy of the GNU General Public License
885 + * along with this program; if not, write to the Free Software
886 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
888 + * inode.c
889 + */
891 +#include <linux/squashfs_fs.h>
892 +#include <linux/module.h>
893 +#include <linux/zlib.h>
894 +#include <linux/fs.h>
895 +#include <linux/squashfs_fs_sb.h>
896 +#include <linux/squashfs_fs_i.h>
897 +#include <linux/buffer_head.h>
898 +#include <linux/vfs.h>
899 +#include <linux/vmalloc.h>
900 +#include <linux/smp_lock.h>
901 +#include <linux/sched.h>
902 +#include <linux/exportfs.h>
904 +#include "squashfs.h"
905 +#include "sqlzma.h"
906 +#include "sqmagic.h"
908 +#undef KeepPreemptive
909 +#if defined(CONFIG_PREEMPT) && !defined(UnsquashNoPreempt)
910 +#define KeepPreemptive
911 +#endif
913 +struct sqlzma {
914 +#ifdef KeepPreemptive
915 + struct mutex mtx;
916 +#endif
917 + unsigned char read_data[SQUASHFS_FILE_MAX_SIZE];
918 + struct sqlzma_un un;
920 +static DEFINE_PER_CPU(struct sqlzma *, sqlzma);
922 +#define dpri(fmt, args...) /* printk("%s:%d: " fmt, __func__, __LINE__, ##args) */
923 +#define dpri_un(un) dpri("un{%d, {%d %p}, {%d %p}, {%d %p}}\n", \
924 + (un)->un_lzma, (un)->un_a[0].sz, (un)->un_a[0].buf, \
925 + (un)->un_a[1].sz, (un)->un_a[1].buf, \
926 + (un)->un_a[2].sz, (un)->un_a[2].buf)
928 +static void vfs_read_inode(struct inode *i);
929 +static struct dentry *squashfs_get_parent(struct dentry *child);
930 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
931 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
932 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
933 +static long long read_blocklist(struct inode *inode, int index,
934 + int readahead_blks, char *block_list,
935 + unsigned short **block_p, unsigned int *bsize);
936 +static int squashfs_readpage(struct file *file, struct page *page);
937 +static int squashfs_readpage4K(struct file *file, struct page *page);
938 +static int squashfs_readdir(struct file *, void *, filldir_t);
939 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
940 + struct nameidata *);
941 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
942 +static void squashfs_put_super(struct super_block *);
943 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
944 + struct vfsmount *);
945 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
946 +static void squashfs_destroy_inode(struct inode *inode);
947 +static int init_inodecache(void);
948 +static void destroy_inodecache(void);
950 +static struct file_system_type squashfs_fs_type = {
951 + .owner = THIS_MODULE,
952 + .name = "squashfs",
953 + .get_sb = squashfs_get_sb,
954 + .kill_sb = kill_block_super,
955 + .fs_flags = FS_REQUIRES_DEV
958 +static const unsigned char squashfs_filetype_table[] = {
959 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
962 +static struct super_operations squashfs_super_ops = {
963 + .alloc_inode = squashfs_alloc_inode,
964 + .destroy_inode = squashfs_destroy_inode,
965 + .statfs = squashfs_statfs,
966 + .put_super = squashfs_put_super,
967 + .remount_fs = squashfs_remount
970 +static struct super_operations squashfs_export_super_ops = {
971 + .alloc_inode = squashfs_alloc_inode,
972 + .destroy_inode = squashfs_destroy_inode,
973 + .statfs = squashfs_statfs,
974 + .put_super = squashfs_put_super,
975 + .read_inode = vfs_read_inode
978 +static struct export_operations squashfs_export_ops = {
979 + .get_parent = squashfs_get_parent
982 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
983 + .readpage = squashfs_symlink_readpage
986 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
987 + .readpage = squashfs_readpage
990 +SQSH_EXTERN const struct address_space_operations squashfs_aops_4K = {
991 + .readpage = squashfs_readpage4K
994 +static const struct file_operations squashfs_dir_ops = {
995 + .read = generic_read_dir,
996 + .readdir = squashfs_readdir
999 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
1000 + .lookup = squashfs_lookup
1004 +static struct buffer_head *get_block_length(struct super_block *s,
1005 + int *cur_index, int *offset, int *c_byte)
1007 + struct squashfs_sb_info *msblk = s->s_fs_info;
1008 + unsigned short temp;
1009 + struct buffer_head *bh;
1011 + if (!(bh = sb_bread(s, *cur_index)))
1012 + goto out;
1014 + if (msblk->devblksize - *offset == 1) {
1015 + if (msblk->swap)
1016 + ((unsigned char *) &temp)[1] = *((unsigned char *)
1017 + (bh->b_data + *offset));
1018 + else
1019 + ((unsigned char *) &temp)[0] = *((unsigned char *)
1020 + (bh->b_data + *offset));
1021 + brelse(bh);
1022 + if (!(bh = sb_bread(s, ++(*cur_index))))
1023 + goto out;
1024 + if (msblk->swap)
1025 + ((unsigned char *) &temp)[0] = *((unsigned char *)
1026 + bh->b_data);
1027 + else
1028 + ((unsigned char *) &temp)[1] = *((unsigned char *)
1029 + bh->b_data);
1030 + *c_byte = temp;
1031 + *offset = 1;
1032 + } else {
1033 + if (msblk->swap) {
1034 + ((unsigned char *) &temp)[1] = *((unsigned char *)
1035 + (bh->b_data + *offset));
1036 + ((unsigned char *) &temp)[0] = *((unsigned char *)
1037 + (bh->b_data + *offset + 1));
1038 + } else {
1039 + ((unsigned char *) &temp)[0] = *((unsigned char *)
1040 + (bh->b_data + *offset));
1041 + ((unsigned char *) &temp)[1] = *((unsigned char *)
1042 + (bh->b_data + *offset + 1));
1044 + *c_byte = temp;
1045 + *offset += 2;
1048 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
1049 + if (*offset == msblk->devblksize) {
1050 + brelse(bh);
1051 + if (!(bh = sb_bread(s, ++(*cur_index))))
1052 + goto out;
1053 + *offset = 0;
1055 + if (*((unsigned char *) (bh->b_data + *offset)) !=
1056 + SQUASHFS_MARKER_BYTE) {
1057 + ERROR("Metadata block marker corrupt @ %x\n",
1058 + *cur_index);
1059 + brelse(bh);
1060 + goto out;
1062 + (*offset)++;
1064 + return bh;
1066 +out:
1067 + return NULL;
1071 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
1072 + long long index, unsigned int length,
1073 + long long *next_index, int srclength)
1075 + struct squashfs_sb_info *msblk = s->s_fs_info;
1076 + struct squashfs_super_block *sblk = &msblk->sblk;
1077 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
1078 + msblk->devblksize_log2) + 2];
1079 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
1080 + unsigned int cur_index = index >> msblk->devblksize_log2;
1081 + int bytes, avail_bytes, b = 0, k = 0;
1082 + unsigned int compressed;
1083 + unsigned int c_byte = length;
1085 + if (c_byte) {
1086 + bytes = msblk->devblksize - offset;
1087 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
1088 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
1090 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index, compressed
1091 + ? "" : "un", (unsigned int) c_byte, srclength);
1093 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
1094 + goto read_failure;
1096 + if (!(bh[0] = sb_getblk(s, cur_index)))
1097 + goto block_release;
1099 + for (b = 1; bytes < c_byte; b++) {
1100 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
1101 + goto block_release;
1102 + bytes += msblk->devblksize;
1104 + ll_rw_block(READ, b, bh);
1105 + } else {
1106 + if (index < 0 || (index + 2) > sblk->bytes_used)
1107 + goto read_failure;
1109 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
1110 + &c_byte)))
1111 + goto read_failure;
1113 + bytes = msblk->devblksize - offset;
1114 + compressed = SQUASHFS_COMPRESSED(c_byte);
1115 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
1117 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
1118 + ? "" : "un", (unsigned int) c_byte);
1120 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
1121 + goto read_failure;
1123 + for (b = 1; bytes < c_byte; b++) {
1124 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
1125 + goto block_release;
1126 + bytes += msblk->devblksize;
1128 + ll_rw_block(READ, b - 1, bh + 1);
1131 + if (compressed) {
1132 + int zlib_err = Z_STREAM_END;
1133 + int rest, start;
1134 + enum {Src, Dst};
1135 + struct sized_buf sbuf[2];
1136 + struct sqlzma *percpu;
1138 + /*
1139 + * uncompress block
1140 + */
1141 + for (k = 0; k < b; k++) {
1142 + wait_on_buffer(bh[k]);
1143 + if (!buffer_uptodate(bh[k]))
1144 + goto block_release;
1147 + avail_bytes = 0;
1148 + for (k = 0; !avail_bytes && k < b; k++) {
1149 + avail_bytes = msblk->devblksize - offset;
1150 + if (c_byte < avail_bytes)
1151 + avail_bytes = c_byte;
1152 + if (avail_bytes)
1153 + break;
1154 + offset = 0;
1155 + brelse(bh[k]);
1157 + bytes = 0;
1158 + if (!avail_bytes)
1159 + goto block_release; // nothing to be process
1161 + start = k;
1162 + /* it disables preemption */
1163 + percpu = get_cpu_var(sqlzma);
1164 +#ifdef KeepPreemptive
1165 + put_cpu_var(sqlzma);
1166 + mutex_lock(&percpu->mtx);
1167 +#endif
1169 + for (; k < b; k++) {
1170 + memcpy(percpu->read_data + bytes, bh[k]->b_data + offset,
1171 + avail_bytes);
1172 + bytes += avail_bytes;
1173 + offset = 0;
1174 + brelse(bh[k]);
1175 + avail_bytes = msblk->devblksize - offset;
1176 + rest = c_byte - bytes;
1177 + if (rest < avail_bytes)
1178 + avail_bytes = rest;
1181 + sbuf[Src].buf = percpu->read_data;
1182 + sbuf[Src].sz = bytes;
1183 + sbuf[Dst].buf = buffer;
1184 + sbuf[Dst].sz = srclength;
1185 + dpri_un(&percpu->un);
1186 + dpri("src %d %p, dst %d %p\n", sbuf[Src].sz, sbuf[Src].buf,
1187 + sbuf[Dst].sz, sbuf[Dst].buf);
1188 + zlib_err = sqlzma_un(&percpu->un, sbuf + Src, sbuf + Dst);
1189 + bytes = percpu->un.un_reslen;
1191 +#ifdef KeepPreemptive
1192 + mutex_unlock(&percpu->mtx);
1193 +#else
1194 + put_cpu_var(sqlzma);
1195 +#endif
1196 + if (unlikely(zlib_err)) {
1197 + dpri("zlib_err %d\n", zlib_err);
1198 + goto release_mutex;
1200 + } else {
1201 + int i;
1203 + for(i = 0; i < b; i++) {
1204 + wait_on_buffer(bh[i]);
1205 + if(!buffer_uptodate(bh[i]))
1206 + goto block_release;
1209 + for (bytes = 0; k < b; k++) {
1210 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
1211 + msblk->devblksize - offset :
1212 + c_byte - bytes;
1213 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
1214 + bytes += avail_bytes;
1215 + offset = 0;
1216 + brelse(bh[k]);
1220 + if (next_index)
1221 + *next_index = index + c_byte + (length ? 0 :
1222 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
1223 + ? 3 : 2));
1224 + return bytes;
1226 +release_mutex:
1227 + //mutex_unlock(&msblk->read_data_mutex);
1229 +block_release:
1230 + for (; k < b; k++)
1231 + brelse(bh[k]);
1233 +read_failure:
1234 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
1235 + return 0;
1239 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
1240 + long long block, unsigned int offset,
1241 + int length, long long *next_block,
1242 + unsigned int *next_offset)
1244 + struct squashfs_sb_info *msblk = s->s_fs_info;
1245 + int n, i, bytes, return_length = length;
1246 + long long next_index;
1248 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
1250 + while ( 1 ) {
1251 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1252 + if (msblk->block_cache[i].block == block)
1253 + break;
1255 + mutex_lock(&msblk->block_cache_mutex);
1257 + if (i == SQUASHFS_CACHED_BLKS) {
1258 + /* read inode header block */
1259 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
1260 + n ; n --, i = (i + 1) %
1261 + SQUASHFS_CACHED_BLKS)
1262 + if (msblk->block_cache[i].block !=
1263 + SQUASHFS_USED_BLK)
1264 + break;
1266 + if (n == 0) {
1267 + wait_queue_t wait;
1269 + init_waitqueue_entry(&wait, current);
1270 + add_wait_queue(&msblk->waitq, &wait);
1271 + set_current_state(TASK_UNINTERRUPTIBLE);
1272 + mutex_unlock(&msblk->block_cache_mutex);
1273 + schedule();
1274 + set_current_state(TASK_RUNNING);
1275 + remove_wait_queue(&msblk->waitq, &wait);
1276 + continue;
1278 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
1280 + if (msblk->block_cache[i].block ==
1281 + SQUASHFS_INVALID_BLK) {
1282 + if (!(msblk->block_cache[i].data =
1283 + kmalloc(SQUASHFS_METADATA_SIZE,
1284 + GFP_KERNEL))) {
1285 + ERROR("Failed to allocate cache"
1286 + "block\n");
1287 + mutex_unlock(&msblk->block_cache_mutex);
1288 + goto out;
1292 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
1293 + mutex_unlock(&msblk->block_cache_mutex);
1295 + msblk->block_cache[i].length = squashfs_read_data(s,
1296 + msblk->block_cache[i].data, block, 0, &next_index, SQUASHFS_METADATA_SIZE);
1297 + if (msblk->block_cache[i].length == 0) {
1298 + ERROR("Unable to read cache block [%llx:%x]\n",
1299 + block, offset);
1300 + mutex_lock(&msblk->block_cache_mutex);
1301 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1302 + kfree(msblk->block_cache[i].data);
1303 + wake_up(&msblk->waitq);
1304 + mutex_unlock(&msblk->block_cache_mutex);
1305 + goto out;
1308 + mutex_lock(&msblk->block_cache_mutex);
1309 + wake_up(&msblk->waitq);
1310 + msblk->block_cache[i].block = block;
1311 + msblk->block_cache[i].next_index = next_index;
1312 + TRACE("Read cache block [%llx:%x]\n", block, offset);
1315 + if (msblk->block_cache[i].block != block) {
1316 + mutex_unlock(&msblk->block_cache_mutex);
1317 + continue;
1320 + bytes = msblk->block_cache[i].length - offset;
1322 + if (bytes < 1) {
1323 + mutex_unlock(&msblk->block_cache_mutex);
1324 + goto out;
1325 + } else if (bytes >= length) {
1326 + if (buffer)
1327 + memcpy(buffer, msblk->block_cache[i].data +
1328 + offset, length);
1329 + if (msblk->block_cache[i].length - offset == length) {
1330 + *next_block = msblk->block_cache[i].next_index;
1331 + *next_offset = 0;
1332 + } else {
1333 + *next_block = block;
1334 + *next_offset = offset + length;
1336 + mutex_unlock(&msblk->block_cache_mutex);
1337 + goto finish;
1338 + } else {
1339 + if (buffer) {
1340 + memcpy(buffer, msblk->block_cache[i].data +
1341 + offset, bytes);
1342 + buffer += bytes;
1344 + block = msblk->block_cache[i].next_index;
1345 + mutex_unlock(&msblk->block_cache_mutex);
1346 + length -= bytes;
1347 + offset = 0;
1351 +finish:
1352 + return return_length;
1353 +out:
1354 + return 0;
1358 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
1359 + long long *fragment_start_block,
1360 + unsigned int *fragment_size)
1362 + struct squashfs_sb_info *msblk = s->s_fs_info;
1363 + long long start_block =
1364 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
1365 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
1366 + struct squashfs_fragment_entry fragment_entry;
1368 + if (msblk->swap) {
1369 + struct squashfs_fragment_entry sfragment_entry;
1371 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
1372 + start_block, offset,
1373 + sizeof(sfragment_entry), &start_block,
1374 + &offset))
1375 + goto out;
1376 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
1377 + } else
1378 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
1379 + start_block, offset,
1380 + sizeof(fragment_entry), &start_block,
1381 + &offset))
1382 + goto out;
1384 + *fragment_start_block = fragment_entry.start_block;
1385 + *fragment_size = fragment_entry.size;
1387 + return 1;
1389 +out:
1390 + return 0;
1394 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
1395 + squashfs_fragment_cache *fragment)
1397 + mutex_lock(&msblk->fragment_mutex);
1398 + fragment->locked --;
1399 + wake_up(&msblk->fragment_wait_queue);
1400 + mutex_unlock(&msblk->fragment_mutex);
1404 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
1405 + *s, long long start_block,
1406 + int length)
1408 + int i, n;
1409 + struct squashfs_sb_info *msblk = s->s_fs_info;
1410 + struct squashfs_super_block *sblk = &msblk->sblk;
1412 + while ( 1 ) {
1413 + mutex_lock(&msblk->fragment_mutex);
1415 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
1416 + msblk->fragment[i].block != start_block; i++);
1418 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
1419 + for (i = msblk->next_fragment, n =
1420 + SQUASHFS_CACHED_FRAGMENTS; n &&
1421 + msblk->fragment[i].locked; n--, i = (i + 1) %
1422 + SQUASHFS_CACHED_FRAGMENTS);
1424 + if (n == 0) {
1425 + wait_queue_t wait;
1427 + init_waitqueue_entry(&wait, current);
1428 + add_wait_queue(&msblk->fragment_wait_queue,
1429 + &wait);
1430 + set_current_state(TASK_UNINTERRUPTIBLE);
1431 + mutex_unlock(&msblk->fragment_mutex);
1432 + schedule();
1433 + set_current_state(TASK_RUNNING);
1434 + remove_wait_queue(&msblk->fragment_wait_queue,
1435 + &wait);
1436 + continue;
1438 + msblk->next_fragment = (msblk->next_fragment + 1) %
1439 + SQUASHFS_CACHED_FRAGMENTS;
1441 + if (msblk->fragment[i].data == NULL)
1442 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
1443 + (SQUASHFS_FILE_MAX_SIZE))) {
1444 + ERROR("Failed to allocate fragment "
1445 + "cache block\n");
1446 + mutex_unlock(&msblk->fragment_mutex);
1447 + goto out;
1450 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1451 + msblk->fragment[i].locked = 1;
1452 + mutex_unlock(&msblk->fragment_mutex);
1454 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
1455 + msblk->fragment[i].data,
1456 + start_block, length, NULL, sblk->block_size))) {
1457 + ERROR("Unable to read fragment cache block "
1458 + "[%llx]\n", start_block);
1459 + msblk->fragment[i].locked = 0;
1460 + smp_mb();
1461 + goto out;
1464 + mutex_lock(&msblk->fragment_mutex);
1465 + msblk->fragment[i].block = start_block;
1466 + TRACE("New fragment %d, start block %lld, locked %d\n",
1467 + i, msblk->fragment[i].block,
1468 + msblk->fragment[i].locked);
1469 + mutex_unlock(&msblk->fragment_mutex);
1470 + break;
1473 + msblk->fragment[i].locked++;
1474 + mutex_unlock(&msblk->fragment_mutex);
1475 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
1476 + msblk->fragment[i].block,
1477 + msblk->fragment[i].locked);
1478 + break;
1481 + return &msblk->fragment[i];
1483 +out:
1484 + return NULL;
1488 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
1489 + struct squashfs_base_inode_header *inodeb)
1491 + i->i_ino = inodeb->inode_number;
1492 + i->i_mtime.tv_sec = inodeb->mtime;
1493 + i->i_atime.tv_sec = inodeb->mtime;
1494 + i->i_ctime.tv_sec = inodeb->mtime;
1495 + i->i_uid = msblk->uid[inodeb->uid];
1496 + i->i_mode = inodeb->mode;
1497 + i->i_size = 0;
1498 + if (inodeb->guid == SQUASHFS_GUIDS)
1499 + i->i_gid = i->i_uid;
1500 + else
1501 + i->i_gid = msblk->guid[inodeb->guid];
1505 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
1507 + struct squashfs_sb_info *msblk = s->s_fs_info;
1508 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
1509 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
1510 + squashfs_inode_t inode;
1512 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
1514 + if (msblk->swap) {
1515 + squashfs_inode_t sinode;
1517 + if (!squashfs_get_cached_block(s, (char *) &sinode, start, offset,
1518 + sizeof(sinode), &start, &offset))
1519 + goto out;
1520 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
1521 + } else if (!squashfs_get_cached_block(s, (char *) &inode, start, offset,
1522 + sizeof(inode), &start, &offset))
1523 + goto out;
1525 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
1527 + return inode;
1529 +out:
1530 + return SQUASHFS_INVALID_BLK;
1534 +static void vfs_read_inode(struct inode *i)
1536 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1537 + squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);
1539 + TRACE("Entered vfs_read_inode\n");
1541 + if(inode != SQUASHFS_INVALID_BLK)
1542 + (msblk->read_inode)(i, inode);
1546 +static struct dentry *squashfs_get_parent(struct dentry *child)
1548 + struct inode *i = child->d_inode;
1549 + struct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
1550 + struct dentry *rv;
1552 + TRACE("Entered squashfs_get_parent\n");
1554 + if(parent == NULL) {
1555 + rv = ERR_PTR(-EACCES);
1556 + goto out;
1559 + rv = d_alloc_anon(parent);
1560 + if(rv == NULL)
1561 + rv = ERR_PTR(-ENOMEM);
1563 +out:
1564 + return rv;
1568 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number)
1570 + struct squashfs_sb_info *msblk = s->s_fs_info;
1571 + struct inode *i = iget_locked(s, inode_number);
1573 + TRACE("Entered squashfs_iget\n");
1575 + if(i && (i->i_state & I_NEW)) {
1576 + (msblk->read_inode)(i, inode);
1577 + unlock_new_inode(i);
1580 + return i;
1584 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
1586 + struct super_block *s = i->i_sb;
1587 + struct squashfs_sb_info *msblk = s->s_fs_info;
1588 + struct squashfs_super_block *sblk = &msblk->sblk;
1589 + long long block = SQUASHFS_INODE_BLK(inode) +
1590 + sblk->inode_table_start;
1591 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
1592 + long long next_block;
1593 + unsigned int next_offset;
1594 + union squashfs_inode_header id, sid;
1595 + struct squashfs_base_inode_header *inodeb = &id.base,
1596 + *sinodeb = &sid.base;
1598 + TRACE("Entered squashfs_read_inode\n");
1600 + if (msblk->swap) {
1601 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
1602 + offset, sizeof(*sinodeb), &next_block,
1603 + &next_offset))
1604 + goto failed_read;
1605 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
1606 + sizeof(*sinodeb));
1607 + } else
1608 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
1609 + offset, sizeof(*inodeb), &next_block,
1610 + &next_offset))
1611 + goto failed_read;
1613 + squashfs_new_inode(msblk, i, inodeb);
1615 + switch(inodeb->inode_type) {
1616 + case SQUASHFS_FILE_TYPE: {
1617 + unsigned int frag_size;
1618 + long long frag_blk;
1619 + struct squashfs_reg_inode_header *inodep = &id.reg;
1620 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
1622 + if (msblk->swap) {
1623 + if (!squashfs_get_cached_block(s, (char *)
1624 + sinodep, block, offset,
1625 + sizeof(*sinodep), &next_block,
1626 + &next_offset))
1627 + goto failed_read;
1628 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
1629 + } else
1630 + if (!squashfs_get_cached_block(s, (char *)
1631 + inodep, block, offset,
1632 + sizeof(*inodep), &next_block,
1633 + &next_offset))
1634 + goto failed_read;
1636 + frag_blk = SQUASHFS_INVALID_BLK;
1637 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
1638 + !get_fragment_location(s,
1639 + inodep->fragment, &frag_blk, &frag_size))
1640 + goto failed_read;
1642 + i->i_nlink = 1;
1643 + i->i_size = inodep->file_size;
1644 + i->i_fop = &generic_ro_fops;
1645 + i->i_mode |= S_IFREG;
1646 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
1647 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
1648 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
1649 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
1650 + SQUASHFS_I(i)->start_block = inodep->start_block;
1651 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
1652 + SQUASHFS_I(i)->offset = next_offset;
1653 + if (sblk->block_size > 4096)
1654 + i->i_data.a_ops = &squashfs_aops;
1655 + else
1656 + i->i_data.a_ops = &squashfs_aops_4K;
1658 + TRACE("File inode %x:%x, start_block %llx, "
1659 + "block_list_start %llx, offset %x\n",
1660 + SQUASHFS_INODE_BLK(inode), offset,
1661 + inodep->start_block, next_block,
1662 + next_offset);
1663 + break;
1665 + case SQUASHFS_LREG_TYPE: {
1666 + unsigned int frag_size;
1667 + long long frag_blk;
1668 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
1669 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
1671 + if (msblk->swap) {
1672 + if (!squashfs_get_cached_block(s, (char *)
1673 + sinodep, block, offset,
1674 + sizeof(*sinodep), &next_block,
1675 + &next_offset))
1676 + goto failed_read;
1677 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
1678 + } else
1679 + if (!squashfs_get_cached_block(s, (char *)
1680 + inodep, block, offset,
1681 + sizeof(*inodep), &next_block,
1682 + &next_offset))
1683 + goto failed_read;
1685 + frag_blk = SQUASHFS_INVALID_BLK;
1686 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
1687 + !get_fragment_location(s,
1688 + inodep->fragment, &frag_blk, &frag_size))
1689 + goto failed_read;
1691 + i->i_nlink = inodep->nlink;
1692 + i->i_size = inodep->file_size;
1693 + i->i_fop = &generic_ro_fops;
1694 + i->i_mode |= S_IFREG;
1695 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
1696 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
1697 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
1698 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
1699 + SQUASHFS_I(i)->start_block = inodep->start_block;
1700 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
1701 + SQUASHFS_I(i)->offset = next_offset;
1702 + if (sblk->block_size > 4096)
1703 + i->i_data.a_ops = &squashfs_aops;
1704 + else
1705 + i->i_data.a_ops = &squashfs_aops_4K;
1707 + TRACE("File inode %x:%x, start_block %llx, "
1708 + "block_list_start %llx, offset %x\n",
1709 + SQUASHFS_INODE_BLK(inode), offset,
1710 + inodep->start_block, next_block,
1711 + next_offset);
1712 + break;
1714 + case SQUASHFS_DIR_TYPE: {
1715 + struct squashfs_dir_inode_header *inodep = &id.dir;
1716 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
1718 + if (msblk->swap) {
1719 + if (!squashfs_get_cached_block(s, (char *)
1720 + sinodep, block, offset,
1721 + sizeof(*sinodep), &next_block,
1722 + &next_offset))
1723 + goto failed_read;
1724 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
1725 + } else
1726 + if (!squashfs_get_cached_block(s, (char *)
1727 + inodep, block, offset,
1728 + sizeof(*inodep), &next_block,
1729 + &next_offset))
1730 + goto failed_read;
1732 + i->i_nlink = inodep->nlink;
1733 + i->i_size = inodep->file_size;
1734 + i->i_op = &squashfs_dir_inode_ops;
1735 + i->i_fop = &squashfs_dir_ops;
1736 + i->i_mode |= S_IFDIR;
1737 + SQUASHFS_I(i)->start_block = inodep->start_block;
1738 + SQUASHFS_I(i)->offset = inodep->offset;
1739 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
1740 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
1742 + TRACE("Directory inode %x:%x, start_block %x, offset "
1743 + "%x\n", SQUASHFS_INODE_BLK(inode),
1744 + offset, inodep->start_block,
1745 + inodep->offset);
1746 + break;
1748 + case SQUASHFS_LDIR_TYPE: {
1749 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
1750 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
1752 + if (msblk->swap) {
1753 + if (!squashfs_get_cached_block(s, (char *)
1754 + sinodep, block, offset,
1755 + sizeof(*sinodep), &next_block,
1756 + &next_offset))
1757 + goto failed_read;
1758 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
1759 + sinodep);
1760 + } else
1761 + if (!squashfs_get_cached_block(s, (char *)
1762 + inodep, block, offset,
1763 + sizeof(*inodep), &next_block,
1764 + &next_offset))
1765 + goto failed_read;
1767 + i->i_nlink = inodep->nlink;
1768 + i->i_size = inodep->file_size;
1769 + i->i_op = &squashfs_dir_inode_ops;
1770 + i->i_fop = &squashfs_dir_ops;
1771 + i->i_mode |= S_IFDIR;
1772 + SQUASHFS_I(i)->start_block = inodep->start_block;
1773 + SQUASHFS_I(i)->offset = inodep->offset;
1774 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
1775 + SQUASHFS_I(i)->u.s2.directory_index_offset =
1776 + next_offset;
1777 + SQUASHFS_I(i)->u.s2.directory_index_count =
1778 + inodep->i_count;
1779 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
1781 + TRACE("Long directory inode %x:%x, start_block %x, "
1782 + "offset %x\n",
1783 + SQUASHFS_INODE_BLK(inode), offset,
1784 + inodep->start_block, inodep->offset);
1785 + break;
1787 + case SQUASHFS_SYMLINK_TYPE: {
1788 + struct squashfs_symlink_inode_header *inodep =
1789 + &id.symlink;
1790 + struct squashfs_symlink_inode_header *sinodep =
1791 + &sid.symlink;
1793 + if (msblk->swap) {
1794 + if (!squashfs_get_cached_block(s, (char *)
1795 + sinodep, block, offset,
1796 + sizeof(*sinodep), &next_block,
1797 + &next_offset))
1798 + goto failed_read;
1799 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
1800 + sinodep);
1801 + } else
1802 + if (!squashfs_get_cached_block(s, (char *)
1803 + inodep, block, offset,
1804 + sizeof(*inodep), &next_block,
1805 + &next_offset))
1806 + goto failed_read;
1808 + i->i_nlink = inodep->nlink;
1809 + i->i_size = inodep->symlink_size;
1810 + i->i_op = &page_symlink_inode_operations;
1811 + i->i_data.a_ops = &squashfs_symlink_aops;
1812 + i->i_mode |= S_IFLNK;
1813 + SQUASHFS_I(i)->start_block = next_block;
1814 + SQUASHFS_I(i)->offset = next_offset;
1816 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
1817 + "offset %x\n",
1818 + SQUASHFS_INODE_BLK(inode), offset,
1819 + next_block, next_offset);
1820 + break;
1822 + case SQUASHFS_BLKDEV_TYPE:
1823 + case SQUASHFS_CHRDEV_TYPE: {
1824 + struct squashfs_dev_inode_header *inodep = &id.dev;
1825 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
1827 + if (msblk->swap) {
1828 + if (!squashfs_get_cached_block(s, (char *)
1829 + sinodep, block, offset,
1830 + sizeof(*sinodep), &next_block,
1831 + &next_offset))
1832 + goto failed_read;
1833 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
1834 + } else
1835 + if (!squashfs_get_cached_block(s, (char *)
1836 + inodep, block, offset,
1837 + sizeof(*inodep), &next_block,
1838 + &next_offset))
1839 + goto failed_read;
1841 + i->i_nlink = inodep->nlink;
1842 + i->i_mode |= (inodeb->inode_type ==
1843 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
1844 + S_IFBLK;
1845 + init_special_inode(i, i->i_mode,
1846 + old_decode_dev(inodep->rdev));
1848 + TRACE("Device inode %x:%x, rdev %x\n",
1849 + SQUASHFS_INODE_BLK(inode), offset,
1850 + inodep->rdev);
1851 + break;
1853 + case SQUASHFS_FIFO_TYPE:
1854 + case SQUASHFS_SOCKET_TYPE: {
1855 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
1856 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
1858 + if (msblk->swap) {
1859 + if (!squashfs_get_cached_block(s, (char *)
1860 + sinodep, block, offset,
1861 + sizeof(*sinodep), &next_block,
1862 + &next_offset))
1863 + goto failed_read;
1864 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
1865 + } else
1866 + if (!squashfs_get_cached_block(s, (char *)
1867 + inodep, block, offset,
1868 + sizeof(*inodep), &next_block,
1869 + &next_offset))
1870 + goto failed_read;
1872 + i->i_nlink = inodep->nlink;
1873 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
1874 + ? S_IFIFO : S_IFSOCK;
1875 + init_special_inode(i, i->i_mode, 0);
1876 + break;
1878 + default:
1879 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1880 + inodeb->inode_type);
1881 + goto failed_read1;
1884 + return 1;
1886 +failed_read:
1887 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1889 +failed_read1:
1890 + make_bad_inode(i);
1891 + return 0;
1895 +static int read_inode_lookup_table(struct super_block *s)
1897 + struct squashfs_sb_info *msblk = s->s_fs_info;
1898 + struct squashfs_super_block *sblk = &msblk->sblk;
1899 + unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1901 + TRACE("In read_inode_lookup_table, length %d\n", length);
1903 + /* Allocate inode lookup table */
1904 + if (!(msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL))) {
1905 + ERROR("Failed to allocate inode lookup table\n");
1906 + return 0;
1909 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1910 + sblk->lookup_table_start, length |
1911 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1912 + ERROR("unable to read inode lookup table\n");
1913 + return 0;
1916 + if (msblk->swap) {
1917 + int i;
1918 + long long block;
1920 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1921 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1922 + &msblk->inode_lookup_table[i], 1);
1923 + msblk->inode_lookup_table[i] = block;
1927 + return 1;
1931 +static int read_fragment_index_table(struct super_block *s)
1933 + struct squashfs_sb_info *msblk = s->s_fs_info;
1934 + struct squashfs_super_block *sblk = &msblk->sblk;
1935 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1937 + if(length == 0)
1938 + return 1;
1940 + /* Allocate fragment index table */
1941 + if (!(msblk->fragment_index = kmalloc(length, GFP_KERNEL))) {
1942 + ERROR("Failed to allocate fragment index table\n");
1943 + return 0;
1946 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1947 + sblk->fragment_table_start, length |
1948 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1949 + ERROR("unable to read fragment index table\n");
1950 + return 0;
1953 + if (msblk->swap) {
1954 + int i;
1955 + long long fragment;
1957 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1958 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1959 + &msblk->fragment_index[i], 1);
1960 + msblk->fragment_index[i] = fragment;
1964 + return 1;
1968 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1970 + struct squashfs_super_block *sblk = &msblk->sblk;
1972 + msblk->read_inode = squashfs_read_inode;
1973 + msblk->read_blocklist = read_blocklist;
1974 + msblk->read_fragment_index_table = read_fragment_index_table;
1976 + if (sblk->s_major == 1) {
1977 + if (!squashfs_1_0_supported(msblk)) {
1978 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1979 + "are unsupported\n");
1980 + SERROR("Please recompile with "
1981 + "Squashfs 1.0 support enabled\n");
1982 + return 0;
1984 + } else if (sblk->s_major == 2) {
1985 + if (!squashfs_2_0_supported(msblk)) {
1986 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1987 + "are unsupported\n");
1988 + SERROR("Please recompile with "
1989 + "Squashfs 2.0 support enabled\n");
1990 + return 0;
1992 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1993 + SQUASHFS_MINOR) {
1994 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1995 + "filesystem\n", sblk->s_major, sblk->s_minor);
1996 + SERROR("Please update your kernel\n");
1997 + return 0;
2000 + return 1;
2004 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
2006 + struct squashfs_sb_info *msblk;
2007 + struct squashfs_super_block *sblk;
2008 + int i, err;
2009 + char b[BDEVNAME_SIZE];
2010 + struct inode *root;
2011 + void *label;
2013 + TRACE("Entered squashfs_read_superblock\n");
2015 + err = -ENOMEM;
2016 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
2017 + GFP_KERNEL))) {
2018 + ERROR("Failed to allocate superblock\n");
2019 + goto failure;
2021 + label = &&out_fsinfo;
2022 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
2023 + msblk = s->s_fs_info;
2024 + sblk = &msblk->sblk;
2026 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
2027 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
2029 + //mutex_init(&msblk->read_data_mutex);
2030 + mutex_init(&msblk->read_page_mutex);
2031 + mutex_init(&msblk->block_cache_mutex);
2032 + mutex_init(&msblk->fragment_mutex);
2033 + mutex_init(&msblk->meta_index_mutex);
2035 + init_waitqueue_head(&msblk->waitq);
2036 + init_waitqueue_head(&msblk->fragment_wait_queue);
2038 + err = -EINVAL;
2039 + sblk->bytes_used = sizeof(struct squashfs_super_block);
2040 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
2041 + sizeof(struct squashfs_super_block) |
2042 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
2043 + SERROR("unable to read superblock\n");
2044 + goto *label;
2047 + /* Check it is a SQUASHFS superblock */
2048 + s->s_magic = sblk->s_magic;
2049 + msblk->swap = 0;
2050 + dpri("magic 0x%x\n", sblk->s_magic);
2051 + switch (sblk->s_magic) {
2052 + struct squashfs_super_block ssblk;
2054 + case SQUASHFS_MAGIC_SWAP:
2055 + /*FALLTHROUGH*/
2056 + case SQUASHFS_MAGIC_LZMA_SWAP:
2057 + WARNING("Mounting a different endian SQUASHFS "
2058 + "filesystem on %s\n", bdevname(s->s_bdev, b));
2060 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
2061 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
2062 + msblk->swap = 1;
2063 + /*FALLTHROUGH*/
2064 + case SQUASHFS_MAGIC:
2065 + case SQUASHFS_MAGIC_LZMA:
2066 + break;
2067 + default:
2068 + SERROR("Can't find a SQUASHFS superblock on %s\n",
2069 + bdevname(s->s_bdev, b));
2070 + goto *label;
2074 + struct sqlzma *p;
2075 + dpri("block_size %d\n", sblk->block_size);
2076 + BUG_ON(sblk->block_size > sizeof(p->read_data));
2079 + /* Check the MAJOR & MINOR versions */
2080 + err = -EINVAL;
2081 + if(!supported_squashfs_filesystem(msblk, silent))
2082 + goto *label;
2084 + /* Check the filesystem does not extend beyond the end of the
2085 + block device */
2086 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
2087 + goto *label;
2089 + /* Check the root inode for sanity */
2090 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
2091 + goto *label;
2093 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
2094 + TRACE("Inodes are %scompressed\n",
2095 + SQUASHFS_UNCOMPRESSED_INODES
2096 + (sblk->flags) ? "un" : "");
2097 + TRACE("Data is %scompressed\n",
2098 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
2099 + ? "un" : "");
2100 + TRACE("Check data is %s present in the filesystem\n",
2101 + SQUASHFS_CHECK_DATA(sblk->flags) ?
2102 + "" : "not");
2103 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
2104 + TRACE("Block size %d\n", sblk->block_size);
2105 + TRACE("Number of inodes %d\n", sblk->inodes);
2106 + if (sblk->s_major > 1)
2107 + TRACE("Number of fragments %d\n", sblk->fragments);
2108 + TRACE("Number of uids %d\n", sblk->no_uids);
2109 + TRACE("Number of gids %d\n", sblk->no_guids);
2110 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
2111 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
2112 + if (sblk->s_major > 1)
2113 + TRACE("sblk->fragment_table_start %llx\n",
2114 + sblk->fragment_table_start);
2115 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
2117 + s->s_flags |= MS_RDONLY;
2118 + s->s_op = &squashfs_super_ops;
2120 + /* Init inode_table block pointer array */
2121 + err = -ENOMEM;
2122 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
2123 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
2124 + ERROR("Failed to allocate block cache\n");
2125 + goto *label;
2127 + label = &&out_block_cache;
2129 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2130 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
2132 + msblk->next_cache = 0;
2134 + /* Allocate read_page block */
2135 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
2136 + ERROR("Failed to allocate read_page block\n");
2137 + goto *label;
2139 + label = &&out_read_page;
2141 + /* Allocate uid and gid tables */
2142 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
2143 + sizeof(unsigned int), GFP_KERNEL))) {
2144 + ERROR("Failed to allocate uid/gid table\n");
2145 + goto *label;
2147 + label = &&out_uid;
2148 + msblk->guid = msblk->uid + sblk->no_uids;
2150 + dpri("swap %d\n", msblk->swap);
2151 + err = -EINVAL;
2152 + if (msblk->swap) {
2153 + unsigned int suid[sblk->no_uids + sblk->no_guids];
2155 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
2156 + ((sblk->no_uids + sblk->no_guids) *
2157 + sizeof(unsigned int)) |
2158 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
2159 + ERROR("unable to read uid/gid table\n");
2160 + goto *label;
2163 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
2164 + sblk->no_guids), (sizeof(unsigned int) * 8));
2165 + } else
2166 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
2167 + ((sblk->no_uids + sblk->no_guids) *
2168 + sizeof(unsigned int)) |
2169 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
2170 + ERROR("unable to read uid/gid table\n");
2171 + goto *label;
2175 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
2176 + goto allocate_root;
2178 + err = -ENOMEM;
2179 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
2180 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
2181 + ERROR("Failed to allocate fragment block cache\n");
2182 + goto *label;
2184 + label = &&out_fragment;
2186 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
2187 + msblk->fragment[i].locked = 0;
2188 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
2189 + msblk->fragment[i].data = NULL;
2192 + msblk->next_fragment = 0;
2194 + /* Allocate and read fragment index table */
2195 + if (msblk->read_fragment_index_table(s) == 0)
2196 + goto *label;
2198 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
2199 + goto allocate_root;
2201 + /* Allocate and read inode lookup table */
2202 + if (read_inode_lookup_table(s) == 0)
2203 + goto failed_mount;
2205 + s->s_op = &squashfs_export_super_ops;
2206 + s->s_export_op = &squashfs_export_ops;
2208 +allocate_root:
2209 + dpri("alloate_root\n");
2210 + root = new_inode(s);
2211 + if ((msblk->read_inode)(root, sblk->root_inode) == 0) {
2212 + iput(root);
2213 + goto failed_mount;
2215 + insert_inode_hash(root);
2217 + if ((s->s_root = d_alloc_root(root)) == NULL) {
2218 + ERROR("Root inode create failed\n");
2219 + iput(root);
2220 + goto failed_mount;
2223 + TRACE("Leaving squashfs_read_super\n");
2224 + return 0;
2226 +failed_mount:
2227 + kfree(msblk->inode_lookup_table);
2228 + kfree(msblk->fragment_index);
2229 + kfree(msblk->fragment_index_2);
2230 + out_fragment:
2231 + kfree(msblk->fragment);
2232 + out_uid:
2233 + kfree(msblk->uid);
2234 + out_read_page:
2235 + kfree(msblk->read_page);
2236 + out_block_cache:
2237 + kfree(msblk->block_cache);
2238 + out_fsinfo:
2239 + kfree(s->s_fs_info);
2240 + s->s_fs_info = NULL;
2241 + failure:
2242 + return err;
2246 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
2248 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
2249 + struct squashfs_super_block *sblk = &msblk->sblk;
2251 + TRACE("Entered squashfs_statfs\n");
2253 + buf->f_type = sblk->s_magic;
2254 + buf->f_bsize = sblk->block_size;
2255 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
2256 + buf->f_bfree = buf->f_bavail = 0;
2257 + buf->f_files = sblk->inodes;
2258 + buf->f_ffree = 0;
2259 + buf->f_namelen = SQUASHFS_NAME_LEN;
2261 + return 0;
2265 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
2267 + struct inode *inode = page->mapping->host;
2268 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
2269 + long long block = SQUASHFS_I(inode)->start_block;
2270 + int offset = SQUASHFS_I(inode)->offset;
2271 + void *pageaddr = kmap(page);
2273 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
2274 + "%llx, offset %x\n", page->index,
2275 + SQUASHFS_I(inode)->start_block,
2276 + SQUASHFS_I(inode)->offset);
2278 + for (length = 0; length < index; length += bytes) {
2279 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
2280 + block, offset, PAGE_CACHE_SIZE, &block,
2281 + &offset))) {
2282 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
2283 + offset);
2284 + goto skip_read;
2288 + if (length != index) {
2289 + ERROR("(squashfs_symlink_readpage) length != index\n");
2290 + bytes = 0;
2291 + goto skip_read;
2294 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
2295 + i_size_read(inode) - length;
2297 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
2298 + offset, bytes, &block, &offset)))
2299 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
2301 +skip_read:
2302 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
2303 + kunmap(page);
2304 + flush_dcache_page(page);
2305 + SetPageUptodate(page);
2306 + unlock_page(page);
2308 + return 0;
2312 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
2314 + struct meta_index *meta = NULL;
2315 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
2316 + int i;
2318 + mutex_lock(&msblk->meta_index_mutex);
2320 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
2322 + if(msblk->meta_index == NULL)
2323 + goto not_allocated;
2325 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
2326 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
2327 + msblk->meta_index[i].offset >= offset &&
2328 + msblk->meta_index[i].offset <= index &&
2329 + msblk->meta_index[i].locked == 0) {
2330 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
2331 + msblk->meta_index[i].offset);
2332 + meta = &msblk->meta_index[i];
2333 + offset = meta->offset;
2336 + if (meta)
2337 + meta->locked = 1;
2339 +not_allocated:
2340 + mutex_unlock(&msblk->meta_index_mutex);
2342 + return meta;
2346 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
2348 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
2349 + struct meta_index *meta = NULL;
2350 + int i;
2352 + mutex_lock(&msblk->meta_index_mutex);
2354 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
2356 + if(msblk->meta_index == NULL) {
2357 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
2358 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
2359 + ERROR("Failed to allocate meta_index\n");
2360 + goto failed;
2362 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
2363 + msblk->meta_index[i].inode_number = 0;
2364 + msblk->meta_index[i].locked = 0;
2366 + msblk->next_meta_index = 0;
2369 + for(i = SQUASHFS_META_NUMBER; i &&
2370 + msblk->meta_index[msblk->next_meta_index].locked; i --)
2371 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
2372 + SQUASHFS_META_NUMBER;
2374 + if(i == 0) {
2375 + TRACE("empty_meta_index: failed!\n");
2376 + goto failed;
2379 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
2380 + msblk->next_meta_index,
2381 + &msblk->meta_index[msblk->next_meta_index]);
2383 + meta = &msblk->meta_index[msblk->next_meta_index];
2384 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
2385 + SQUASHFS_META_NUMBER;
2387 + meta->inode_number = inode->i_ino;
2388 + meta->offset = offset;
2389 + meta->skip = skip;
2390 + meta->entries = 0;
2391 + meta->locked = 1;
2393 +failed:
2394 + mutex_unlock(&msblk->meta_index_mutex);
2395 + return meta;
2399 +void release_meta_index(struct inode *inode, struct meta_index *meta)
2401 + meta->locked = 0;
2402 + smp_mb();
2406 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
2407 + long long *start_block, int *offset)
2409 + struct squashfs_sb_info *msblk = s->s_fs_info;
2410 + unsigned int *block_listp;
2411 + int block = 0;
2413 + if (msblk->swap) {
2414 + char sblock_list[blocks << 2];
2416 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
2417 + *offset, blocks << 2, start_block, offset)) {
2418 + ERROR("Unable to read block list [%llx:%x]\n",
2419 + *start_block, *offset);
2420 + goto failure;
2422 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
2423 + ((unsigned int *)sblock_list), blocks);
2424 + } else
2425 + if (!squashfs_get_cached_block(s, block_list, *start_block,
2426 + *offset, blocks << 2, start_block, offset)) {
2427 + ERROR("Unable to read block list [%llx:%x]\n",
2428 + *start_block, *offset);
2429 + goto failure;
2432 + for (block_listp = (unsigned int *) block_list; blocks;
2433 + block_listp++, blocks --)
2434 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
2436 + return block;
2438 +failure:
2439 + return -1;
2443 +#define SIZE 256
2445 +static inline int calculate_skip(int blocks) {
2446 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
2447 + return skip >= 7 ? 7 : skip + 1;
2451 +static int get_meta_index(struct inode *inode, int index,
2452 + long long *index_block, int *index_offset,
2453 + long long *data_block, char *block_list)
2455 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
2456 + struct squashfs_super_block *sblk = &msblk->sblk;
2457 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
2458 + int offset = 0;
2459 + struct meta_index *meta;
2460 + struct meta_entry *meta_entry;
2461 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
2462 + int cur_offset = SQUASHFS_I(inode)->offset;
2463 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
2464 + int i;
2466 + index /= SQUASHFS_META_INDEXES * skip;
2468 + while ( offset < index ) {
2469 + meta = locate_meta_index(inode, index, offset + 1);
2471 + if (meta == NULL) {
2472 + if ((meta = empty_meta_index(inode, offset + 1,
2473 + skip)) == NULL)
2474 + goto all_done;
2475 + } else {
2476 + if(meta->entries == 0)
2477 + goto failed;
2478 + offset = index < meta->offset + meta->entries ? index :
2479 + meta->offset + meta->entries - 1;
2480 + meta_entry = &meta->meta_entry[offset - meta->offset];
2481 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
2482 + cur_offset = meta_entry->offset;
2483 + cur_data_block = meta_entry->data_block;
2484 + TRACE("get_meta_index: offset %d, meta->offset %d, "
2485 + "meta->entries %d\n", offset, meta->offset,
2486 + meta->entries);
2487 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
2488 + " data_block 0x%llx\n", cur_index_block,
2489 + cur_offset, cur_data_block);
2492 + for (i = meta->offset + meta->entries; i <= index &&
2493 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
2494 + int blocks = skip * SQUASHFS_META_INDEXES;
2496 + while (blocks) {
2497 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
2498 + blocks;
2499 + int res = read_block_index(inode->i_sb, block,
2500 + block_list, &cur_index_block,
2501 + &cur_offset);
2503 + if (res == -1)
2504 + goto failed;
2506 + cur_data_block += res;
2507 + blocks -= block;
2510 + meta_entry = &meta->meta_entry[i - meta->offset];
2511 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
2512 + meta_entry->offset = cur_offset;
2513 + meta_entry->data_block = cur_data_block;
2514 + meta->entries ++;
2515 + offset ++;
2518 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
2519 + meta->offset, meta->entries);
2521 + release_meta_index(inode, meta);
2524 +all_done:
2525 + *index_block = cur_index_block;
2526 + *index_offset = cur_offset;
2527 + *data_block = cur_data_block;
2529 + return offset * SQUASHFS_META_INDEXES * skip;
2531 +failed:
2532 + release_meta_index(inode, meta);
2533 + return -1;
2537 +static long long read_blocklist(struct inode *inode, int index,
2538 + int readahead_blks, char *block_list,
2539 + unsigned short **block_p, unsigned int *bsize)
2541 + long long block_ptr;
2542 + int offset;
2543 + long long block;
2544 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
2545 + block_list);
2547 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
2548 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
2549 + block);
2551 + if(res == -1)
2552 + goto failure;
2554 + index -= res;
2556 + while ( index ) {
2557 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
2558 + int res = read_block_index(inode->i_sb, blocks, block_list,
2559 + &block_ptr, &offset);
2560 + if (res == -1)
2561 + goto failure;
2562 + block += res;
2563 + index -= blocks;
2566 + if (read_block_index(inode->i_sb, 1, block_list,
2567 + &block_ptr, &offset) == -1)
2568 + goto failure;
2569 + *bsize = *((unsigned int *) block_list);
2571 + return block;
2573 +failure:
2574 + return 0;
2578 +static int squashfs_readpage(struct file *file, struct page *page)
2580 + struct inode *inode = page->mapping->host;
2581 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
2582 + struct squashfs_super_block *sblk = &msblk->sblk;
2583 + unsigned char *block_list;
2584 + long long block;
2585 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
2586 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
2587 + void *pageaddr;
2588 + struct squashfs_fragment_cache *fragment = NULL;
2589 + char *data_ptr = msblk->read_page;
2591 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
2592 + int start_index = page->index & ~mask;
2593 + int end_index = start_index | mask;
2595 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
2596 + page->index,
2597 + SQUASHFS_I(inode)->start_block);
2599 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
2600 + ERROR("Failed to allocate block_list\n");
2601 + goto skip_read;
2604 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
2605 + PAGE_CACHE_SHIFT))
2606 + goto skip_read;
2608 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
2609 + || index < (i_size_read(inode) >>
2610 + sblk->block_log)) {
2611 + if ((block = (msblk->read_blocklist)(inode, index, 1,
2612 + block_list, NULL, &bsize)) == 0)
2613 + goto skip_read;
2615 + mutex_lock(&msblk->read_page_mutex);
2617 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
2618 + block, bsize, NULL, sblk->block_size))) {
2619 + ERROR("Unable to read page, block %llx, size %x\n", block,
2620 + bsize);
2621 + mutex_unlock(&msblk->read_page_mutex);
2622 + goto skip_read;
2624 + } else {
2625 + if ((fragment = get_cached_fragment(inode->i_sb,
2626 + SQUASHFS_I(inode)->
2627 + u.s1.fragment_start_block,
2628 + SQUASHFS_I(inode)->u.s1.fragment_size))
2629 + == NULL) {
2630 + ERROR("Unable to read page, block %llx, size %x\n",
2631 + SQUASHFS_I(inode)->
2632 + u.s1.fragment_start_block,
2633 + (int) SQUASHFS_I(inode)->
2634 + u.s1.fragment_size);
2635 + goto skip_read;
2637 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
2638 + (i_size_read(inode) & (sblk->block_size
2639 + - 1));
2640 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
2641 + data_ptr = fragment->data;
2644 + for (i = start_index; i <= end_index && byte_offset < bytes;
2645 + i++, byte_offset += PAGE_CACHE_SIZE) {
2646 + struct page *push_page;
2647 + int avail = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
2648 + PAGE_CACHE_SIZE : bytes - byte_offset;
2650 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
2651 + bytes, i, byte_offset, avail);
2653 + push_page = (i == page->index) ? page :
2654 + grab_cache_page_nowait(page->mapping, i);
2656 + if (!push_page)
2657 + continue;
2659 + if (PageUptodate(push_page))
2660 + goto skip_page;
2662 + pageaddr = kmap_atomic(push_page, KM_USER0);
2663 + memcpy(pageaddr, data_ptr + byte_offset, avail);
2664 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
2665 + kunmap_atomic(pageaddr, KM_USER0);
2666 + flush_dcache_page(push_page);
2667 + SetPageUptodate(push_page);
2668 +skip_page:
2669 + unlock_page(push_page);
2670 + if(i != page->index)
2671 + page_cache_release(push_page);
2674 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
2675 + || index < (i_size_read(inode) >>
2676 + sblk->block_log))
2677 + mutex_unlock(&msblk->read_page_mutex);
2678 + else
2679 + release_cached_fragment(msblk, fragment);
2681 + kfree(block_list);
2682 + return 0;
2684 +skip_read:
2685 + pageaddr = kmap_atomic(page, KM_USER0);
2686 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
2687 + kunmap_atomic(pageaddr, KM_USER0);
2688 + flush_dcache_page(page);
2689 + SetPageUptodate(page);
2690 + unlock_page(page);
2692 + kfree(block_list);
2693 + return 0;
2697 +static int squashfs_readpage4K(struct file *file, struct page *page)
2699 + struct inode *inode = page->mapping->host;
2700 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
2701 + struct squashfs_super_block *sblk = &msblk->sblk;
2702 + unsigned char *block_list;
2703 + long long block;
2704 + unsigned int bsize, bytes = 0;
2705 + void *pageaddr;
2707 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
2708 + page->index,
2709 + SQUASHFS_I(inode)->start_block);
2711 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
2712 + PAGE_CACHE_SHIFT)) {
2713 + block_list = NULL;
2714 + goto skip_read;
2717 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
2718 + ERROR("Failed to allocate block_list\n");
2719 + goto skip_read;
2722 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
2723 + || page->index < (i_size_read(inode) >>
2724 + sblk->block_log)) {
2725 + block = (msblk->read_blocklist)(inode, page->index, 1,
2726 + block_list, NULL, &bsize);
2727 + if(block == 0)
2728 + goto skip_read;
2730 + mutex_lock(&msblk->read_page_mutex);
2731 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
2732 + bsize, NULL, sblk->block_size);
2733 + if (bytes) {
2734 + pageaddr = kmap_atomic(page, KM_USER0);
2735 + memcpy(pageaddr, msblk->read_page, bytes);
2736 + kunmap_atomic(pageaddr, KM_USER0);
2737 + } else
2738 + ERROR("Unable to read page, block %llx, size %x\n",
2739 + block, bsize);
2740 + mutex_unlock(&msblk->read_page_mutex);
2741 + } else {
2742 + struct squashfs_fragment_cache *fragment =
2743 + get_cached_fragment(inode->i_sb,
2744 + SQUASHFS_I(inode)->
2745 + u.s1.fragment_start_block,
2746 + SQUASHFS_I(inode)-> u.s1.fragment_size);
2747 + if (fragment) {
2748 + bytes = i_size_read(inode) & (sblk->block_size - 1);
2749 + pageaddr = kmap_atomic(page, KM_USER0);
2750 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
2751 + u.s1.fragment_offset, bytes);
2752 + kunmap_atomic(pageaddr, KM_USER0);
2753 + release_cached_fragment(msblk, fragment);
2754 + } else
2755 + ERROR("Unable to read page, block %llx, size %x\n",
2756 + SQUASHFS_I(inode)->
2757 + u.s1.fragment_start_block, (int)
2758 + SQUASHFS_I(inode)-> u.s1.fragment_size);
2761 +skip_read:
2762 + pageaddr = kmap_atomic(page, KM_USER0);
2763 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
2764 + kunmap_atomic(pageaddr, KM_USER0);
2765 + flush_dcache_page(page);
2766 + SetPageUptodate(page);
2767 + unlock_page(page);
2769 + kfree(block_list);
2770 + return 0;
2774 +static int get_dir_index_using_offset(struct super_block *s, long long
2775 + *next_block, unsigned int *next_offset,
2776 + long long index_start,
2777 + unsigned int index_offset, int i_count,
2778 + long long f_pos)
2780 + struct squashfs_sb_info *msblk = s->s_fs_info;
2781 + struct squashfs_super_block *sblk = &msblk->sblk;
2782 + int i, length = 0;
2783 + struct squashfs_dir_index index;
2785 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2786 + i_count, (unsigned int) f_pos);
2788 + f_pos =- 3;
2789 + if (f_pos == 0)
2790 + goto finish;
2792 + for (i = 0; i < i_count; i++) {
2793 + if (msblk->swap) {
2794 + struct squashfs_dir_index sindex;
2795 + squashfs_get_cached_block(s, (char *) &sindex,
2796 + index_start, index_offset,
2797 + sizeof(sindex), &index_start,
2798 + &index_offset);
2799 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
2800 + } else
2801 + squashfs_get_cached_block(s, (char *) &index,
2802 + index_start, index_offset,
2803 + sizeof(index), &index_start,
2804 + &index_offset);
2806 + if (index.index > f_pos)
2807 + break;
2809 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2810 + index.size + 1, &index_start,
2811 + &index_offset);
2813 + length = index.index;
2814 + *next_block = index.start_block + sblk->directory_table_start;
2817 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2819 +finish:
2820 + return length + 3;
2824 +static int get_dir_index_using_name(struct super_block *s, long long
2825 + *next_block, unsigned int *next_offset,
2826 + long long index_start,
2827 + unsigned int index_offset, int i_count,
2828 + const char *name, int size)
2830 + struct squashfs_sb_info *msblk = s->s_fs_info;
2831 + struct squashfs_super_block *sblk = &msblk->sblk;
2832 + int i, length = 0;
2833 + struct squashfs_dir_index *index;
2834 + char *str;
2836 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2838 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2839 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2840 + ERROR("Failed to allocate squashfs_dir_index\n");
2841 + goto failure;
2844 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
2845 + strncpy(str, name, size);
2846 + str[size] = '\0';
2848 + for (i = 0; i < i_count; i++) {
2849 + if (msblk->swap) {
2850 + struct squashfs_dir_index sindex;
2851 + squashfs_get_cached_block(s, (char *) &sindex,
2852 + index_start, index_offset,
2853 + sizeof(sindex), &index_start,
2854 + &index_offset);
2855 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
2856 + } else
2857 + squashfs_get_cached_block(s, (char *) index,
2858 + index_start, index_offset,
2859 + sizeof(struct squashfs_dir_index),
2860 + &index_start, &index_offset);
2862 + squashfs_get_cached_block(s, index->name, index_start,
2863 + index_offset, index->size + 1,
2864 + &index_start, &index_offset);
2866 + index->name[index->size + 1] = '\0';
2868 + if (strcmp(index->name, str) > 0)
2869 + break;
2871 + length = index->index;
2872 + *next_block = index->start_block + sblk->directory_table_start;
2875 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2876 + kfree(str);
2877 +failure:
2878 + return length + 3;
2882 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
2884 + struct inode *i = file->f_dentry->d_inode;
2885 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2886 + struct squashfs_super_block *sblk = &msblk->sblk;
2887 + long long next_block = SQUASHFS_I(i)->start_block +
2888 + sblk->directory_table_start;
2889 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2890 + dir_count;
2891 + struct squashfs_dir_header dirh;
2892 + struct squashfs_dir_entry *dire;
2894 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
2896 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2897 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2898 + ERROR("Failed to allocate squashfs_dir_entry\n");
2899 + goto finish;
2902 + while(file->f_pos < 3) {
2903 + char *name;
2904 + int size, i_ino;
2906 + if(file->f_pos == 0) {
2907 + name = ".";
2908 + size = 1;
2909 + i_ino = i->i_ino;
2910 + } else {
2911 + name = "..";
2912 + size = 2;
2913 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
2915 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
2916 + (unsigned int) dirent, name, size, (int)
2917 + file->f_pos, i_ino,
2918 + squashfs_filetype_table[1]);
2920 + if (filldir(dirent, name, size,
2921 + file->f_pos, i_ino,
2922 + squashfs_filetype_table[1]) < 0) {
2923 + TRACE("Filldir returned less than 0\n");
2924 + goto finish;
2926 + file->f_pos += size;
2929 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2930 + SQUASHFS_I(i)->u.s2.directory_index_start,
2931 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2932 + SQUASHFS_I(i)->u.s2.directory_index_count,
2933 + file->f_pos);
2935 + while (length < i_size_read(i)) {
2936 + /* read directory header */
2937 + if (msblk->swap) {
2938 + struct squashfs_dir_header sdirh;
2940 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2941 + next_block, next_offset, sizeof(sdirh),
2942 + &next_block, &next_offset))
2943 + goto failed_read;
2945 + length += sizeof(sdirh);
2946 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2947 + } else {
2948 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2949 + next_block, next_offset, sizeof(dirh),
2950 + &next_block, &next_offset))
2951 + goto failed_read;
2953 + length += sizeof(dirh);
2956 + dir_count = dirh.count + 1;
2957 + while (dir_count--) {
2958 + if (msblk->swap) {
2959 + struct squashfs_dir_entry sdire;
2960 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2961 + &sdire, next_block, next_offset,
2962 + sizeof(sdire), &next_block,
2963 + &next_offset))
2964 + goto failed_read;
2966 + length += sizeof(sdire);
2967 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2968 + } else {
2969 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2970 + dire, next_block, next_offset,
2971 + sizeof(*dire), &next_block,
2972 + &next_offset))
2973 + goto failed_read;
2975 + length += sizeof(*dire);
2978 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2979 + next_block, next_offset,
2980 + dire->size + 1, &next_block,
2981 + &next_offset))
2982 + goto failed_read;
2984 + length += dire->size + 1;
2986 + if (file->f_pos >= length)
2987 + continue;
2989 + dire->name[dire->size + 1] = '\0';
2991 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2992 + (unsigned int) dirent, dire->name,
2993 + dire->size + 1, (int) file->f_pos,
2994 + dirh.start_block, dire->offset,
2995 + dirh.inode_number + dire->inode_number,
2996 + squashfs_filetype_table[dire->type]);
2998 + if (filldir(dirent, dire->name, dire->size + 1,
2999 + file->f_pos,
3000 + dirh.inode_number + dire->inode_number,
3001 + squashfs_filetype_table[dire->type])
3002 + < 0) {
3003 + TRACE("Filldir returned less than 0\n");
3004 + goto finish;
3006 + file->f_pos = length;
3010 +finish:
3011 + kfree(dire);
3012 + return 0;
3014 +failed_read:
3015 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3016 + next_offset);
3017 + kfree(dire);
3018 + return 0;
3022 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
3023 + struct nameidata *nd)
3025 + const unsigned char *name = dentry->d_name.name;
3026 + int len = dentry->d_name.len;
3027 + struct inode *inode = NULL;
3028 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
3029 + struct squashfs_super_block *sblk = &msblk->sblk;
3030 + long long next_block = SQUASHFS_I(i)->start_block +
3031 + sblk->directory_table_start;
3032 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
3033 + dir_count;
3034 + struct squashfs_dir_header dirh;
3035 + struct squashfs_dir_entry *dire;
3037 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
3039 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
3040 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
3041 + ERROR("Failed to allocate squashfs_dir_entry\n");
3042 + goto exit_lookup;
3045 + if (len > SQUASHFS_NAME_LEN)
3046 + goto exit_lookup;
3048 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
3049 + SQUASHFS_I(i)->u.s2.directory_index_start,
3050 + SQUASHFS_I(i)->u.s2.directory_index_offset,
3051 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
3052 + len);
3054 + while (length < i_size_read(i)) {
3055 + /* read directory header */
3056 + if (msblk->swap) {
3057 + struct squashfs_dir_header sdirh;
3058 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
3059 + next_block, next_offset, sizeof(sdirh),
3060 + &next_block, &next_offset))
3061 + goto failed_read;
3063 + length += sizeof(sdirh);
3064 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
3065 + } else {
3066 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
3067 + next_block, next_offset, sizeof(dirh),
3068 + &next_block, &next_offset))
3069 + goto failed_read;
3071 + length += sizeof(dirh);
3074 + dir_count = dirh.count + 1;
3075 + while (dir_count--) {
3076 + if (msblk->swap) {
3077 + struct squashfs_dir_entry sdire;
3078 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3079 + &sdire, next_block,next_offset,
3080 + sizeof(sdire), &next_block,
3081 + &next_offset))
3082 + goto failed_read;
3084 + length += sizeof(sdire);
3085 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
3086 + } else {
3087 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3088 + dire, next_block,next_offset,
3089 + sizeof(*dire), &next_block,
3090 + &next_offset))
3091 + goto failed_read;
3093 + length += sizeof(*dire);
3096 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
3097 + next_block, next_offset, dire->size + 1,
3098 + &next_block, &next_offset))
3099 + goto failed_read;
3101 + length += dire->size + 1;
3103 + if (name[0] < dire->name[0])
3104 + goto exit_lookup;
3106 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
3107 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
3108 + dire->offset);
3110 + TRACE("calling squashfs_iget for directory "
3111 + "entry %s, inode %x:%x, %d\n", name,
3112 + dirh.start_block, dire->offset,
3113 + dirh.inode_number + dire->inode_number);
3115 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
3117 + goto exit_lookup;
3122 +exit_lookup:
3123 + kfree(dire);
3124 + if (inode)
3125 + return d_splice_alias(inode, dentry);
3126 + d_add(dentry, inode);
3127 + return ERR_PTR(0);
3129 +failed_read:
3130 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3131 + next_offset);
3132 + goto exit_lookup;
3136 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
3138 + *flags |= MS_RDONLY;
3139 + return 0;
3143 +static void squashfs_put_super(struct super_block *s)
3145 + int i;
3147 + if (s->s_fs_info) {
3148 + struct squashfs_sb_info *sbi = s->s_fs_info;
3149 + if (sbi->block_cache)
3150 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
3151 + if (sbi->block_cache[i].block !=
3152 + SQUASHFS_INVALID_BLK)
3153 + kfree(sbi->block_cache[i].data);
3154 + if (sbi->fragment)
3155 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
3156 + SQUASHFS_FREE(sbi->fragment[i].data);
3157 + kfree(sbi->fragment);
3158 + kfree(sbi->block_cache);
3159 + kfree(sbi->read_page);
3160 + kfree(sbi->uid);
3161 + kfree(sbi->fragment_index);
3162 + kfree(sbi->fragment_index_2);
3163 + kfree(sbi->meta_index);
3164 + kfree(s->s_fs_info);
3165 + s->s_fs_info = NULL;
3170 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
3171 + const char *dev_name, void *data,
3172 + struct vfsmount *mnt)
3174 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
3175 + mnt);
3179 +static void free_sqlzma(void)
3181 + int cpu;
3182 + struct sqlzma *p;
3184 + for_each_online_cpu(cpu) {
3185 + p = per_cpu(sqlzma, cpu);
3186 + if (p) {
3187 +#ifdef KeepPreemptive
3188 + mutex_destroy(&p->mtx);
3189 +#endif
3190 + sqlzma_fin(&p->un);
3191 + kfree(p);
3196 +static int __init init_squashfs_fs(void)
3198 + struct sqlzma *p;
3199 + int cpu;
3200 + int err = init_inodecache();
3201 + if (err)
3202 + goto out;
3204 + for_each_online_cpu(cpu) {
3205 + dpri("%d: %p\n", cpu, per_cpu(sqlzma, cpu));
3206 + err = -ENOMEM;
3207 + p = kmalloc(sizeof(struct sqlzma), GFP_KERNEL);
3208 + if (p) {
3209 +#ifdef KeepPreemptive
3210 + mutex_init(&p->mtx);
3211 +#endif
3212 + err = sqlzma_init(&p->un, 1, 0);
3213 + if (unlikely(err)) {
3214 + ERROR("Failed to intialize uncompress workspace\n");
3215 + break;
3217 + per_cpu(sqlzma, cpu) = p;
3218 + err = 0;
3219 + } else
3220 + break;
3222 + if (unlikely(err)) {
3223 + free_sqlzma();
3224 + goto out;
3227 + printk(KERN_INFO "squashfs: version 3.2-r2 (2007/01/15) "
3228 + "Phillip Lougher\n"
3229 + "squashfs: LZMA suppport for slax.org by jro\n");
3231 + if ((err = register_filesystem(&squashfs_fs_type))) {
3232 + free_sqlzma();
3233 + destroy_inodecache();
3236 +out:
3237 + return err;
3241 +static void __exit exit_squashfs_fs(void)
3243 + unregister_filesystem(&squashfs_fs_type);
3244 + free_sqlzma();
3245 + destroy_inodecache();
3249 +static struct kmem_cache * squashfs_inode_cachep;
3252 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
3254 + struct squashfs_inode_info *ei;
3255 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
3256 + if (!ei)
3257 + return NULL;
3258 + return &ei->vfs_inode;
3262 +static void squashfs_destroy_inode(struct inode *inode)
3264 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
3268 +static void init_once(struct kmem_cache * cachep, void * foo)
3270 + struct squashfs_inode_info *ei = foo;
3271 + inode_init_once(&ei->vfs_inode);
3275 +static int __init init_inodecache(void)
3277 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
3278 + sizeof(struct squashfs_inode_info),
3279 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
3280 + init_once);
3281 + if (squashfs_inode_cachep == NULL)
3282 + return -ENOMEM;
3283 + return 0;
3287 +static void destroy_inodecache(void)
3289 + kmem_cache_destroy(squashfs_inode_cachep);
3293 +module_init(init_squashfs_fs);
3294 +module_exit(exit_squashfs_fs);
3295 +MODULE_DESCRIPTION("squashfs 3.2-r2, a compressed read-only filesystem, and LZMA suppport for slax.org");
3296 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>, and LZMA suppport for slax.org by jro");
3297 +MODULE_LICENSE("GPL");
3298 diff -urN linux-2.6.23/fs/squashfs/module.c linux-2.6.23.sqlzma/fs/squashfs/module.c
3299 --- linux-2.6.23/fs/squashfs/module.c 1969-12-31 19:00:00.000000000 -0500
3300 +++ linux-2.6.23.sqlzma/fs/squashfs/module.c 2007-10-14 12:58:25.000000000 -0400
3301 @@ -0,0 +1,36 @@
3304 + * Copyright (C) 2006 Junjiro Okajima
3305 + * Copyright (C) 2006 Tomas Matejicek, slax.org
3307 + * LICENSE follows the described one in lzma.txt.
3308 + */
3310 +/* $Id: module.c,v 1.5 2006/11/27 03:54:58 jro Exp $ */
3312 +#include <linux/init.h>
3313 +#include <linux/module.h>
3315 +#include "LzmaDecode.c"
3317 +EXPORT_SYMBOL(LzmaDecodeProperties);
3318 +EXPORT_SYMBOL(LzmaDecode);
3320 +#if 0
3321 +static int __init unlzma_init(void)
3323 + return 0;
3326 +static void __exit unlzma_exit(void)
3330 +module_init(unlzma_init);
3331 +module_exit(unlzma_exit);
3332 +#endif
3334 +MODULE_LICENSE("GPL");
3335 +MODULE_VERSION("$Id: module.c,v 1.5 2006/11/27 03:54:58 jro Exp $");
3336 +MODULE_DESCRIPTION("LZMA uncompress. "
3337 + "A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.");
3338 diff -urN linux-2.6.23/fs/squashfs/sqlzma.h linux-2.6.23.sqlzma/fs/squashfs/sqlzma.h
3339 --- linux-2.6.23/fs/squashfs/sqlzma.h 1969-12-31 19:00:00.000000000 -0500
3340 +++ linux-2.6.23.sqlzma/fs/squashfs/sqlzma.h 2007-10-14 13:07:12.000000000 -0400
3341 @@ -0,0 +1,79 @@
3343 + * Copyright (C) 2006 Junjiro Okajima
3344 + * Copyright (C) 2006 Tomas Matejicek, slax.org
3346 + * LICENSE follows the described one in lzma.
3347 + */
3349 +/* $Id: sqlzma.h,v 1.13 2007/01/07 15:12:48 jro Exp $ */
3351 +#ifndef __sqlzma_h__
3352 +#define __sqlzma_h__
3354 +#ifndef __KERNEL__
3355 +#include <stdlib.h>
3356 +#include <string.h>
3357 +#include <zlib.h>
3358 +#ifdef _REENTRANT
3359 +#include <pthread.h>
3360 +#endif
3361 +#else
3362 +#include <linux/zlib.h>
3363 +#endif
3364 +#define _7ZIP_BYTE_DEFINED
3367 + * detect the compression method automatically by the first byte of compressed
3368 + * data.
3369 + * according to rfc1950, the first byte of zlib compression must be 0x?8.
3370 + */
3371 +#define is_lzma(c) (c == 0x5d)
3373 +/* ---------------------------------------------------------------------- */
3375 +#ifdef __cplusplus
3376 +extern "C" {
3377 +#endif
3379 +#ifndef __KERNEL__
3380 +/* for mksquashfs only */
3381 +int sqlzma_cm(int lzma, z_stream *stream, Bytef *next_in, uInt avail_in,
3382 + Bytef *next_out, uInt avail_out);
3383 +#endif
3385 +/* ---------------------------------------------------------------------- */
3387 + * Three patterns for sqlzma uncompression. very dirty code.
3388 + * - kernel space (squashfs kernel module)
3389 + * - user space with pthread (mksquashfs)
3390 + * - user space without pthread (unsquashfs)
3391 + */
3393 +struct sized_buf {
3394 + unsigned int sz;
3395 + unsigned char *buf;
3398 +enum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};
3399 +struct sqlzma_un {
3400 + int un_lzma;
3401 + struct sized_buf un_a[SQUN_LAST];
3402 + unsigned char un_prob[31960]; /* unlzma 64KB */
3403 + z_stream un_stream;
3404 +#define un_cmbuf un_stream.next_in
3405 +#define un_cmlen un_stream.avail_in
3406 +#define un_resbuf un_stream.next_out
3407 +#define un_resroom un_stream.avail_out
3408 +#define un_reslen un_stream.total_out
3411 +int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);
3412 +int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, struct sized_buf *dst);
3413 +void sqlzma_fin(struct sqlzma_un *un);
3415 +/* ---------------------------------------------------------------------- */
3417 +#ifdef __cplusplus
3419 +#endif
3420 +#endif
3421 diff -urN linux-2.6.23/fs/squashfs/sqmagic.h linux-2.6.23.sqlzma/fs/squashfs/sqmagic.h
3422 --- linux-2.6.23/fs/squashfs/sqmagic.h 1969-12-31 19:00:00.000000000 -0500
3423 +++ linux-2.6.23.sqlzma/fs/squashfs/sqmagic.h 2007-10-14 14:32:24.000000000 -0400
3424 @@ -0,0 +1,17 @@
3426 + * Copyright (C) 2006 Junjiro Okajima
3427 + * Copyright (C) 2006 Tomas Matejicek, slax.org
3429 + * LICENSE must follow the one in squashfs.
3430 + */
3432 +/* $Id: sqmagic.h,v 1.2 2006/11/27 03:54:58 jro Exp $ */
3434 +#ifndef __sqmagic_h__
3435 +#define __sqmagic_h__
3437 +/* see SQUASHFS_MAGIC in squashfs_fs.h */
3438 +#define SQUASHFS_MAGIC_LZMA 0x71736873
3439 +#define SQUASHFS_MAGIC_LZMA_SWAP 0x73687371
3441 +#endif
3442 diff -urN linux-2.6.23/fs/squashfs/squashfs.h linux-2.6.23.sqlzma/fs/squashfs/squashfs.h
3443 --- linux-2.6.23/fs/squashfs/squashfs.h 1969-12-31 19:00:00.000000000 -0500
3444 +++ linux-2.6.23.sqlzma/fs/squashfs/squashfs.h 2007-10-14 10:24:31.000000000 -0400
3445 @@ -0,0 +1,87 @@
3447 + * Squashfs - a compressed read only filesystem for Linux
3449 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3450 + * Phillip Lougher <phillip@lougher.org.uk>
3452 + * This program is free software; you can redistribute it and/or
3453 + * modify it under the terms of the GNU General Public License
3454 + * as published by the Free Software Foundation; either version 2,
3455 + * or (at your option) any later version.
3457 + * This program is distributed in the hope that it will be useful,
3458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3460 + * GNU General Public License for more details.
3462 + * You should have received a copy of the GNU General Public License
3463 + * along with this program; if not, write to the Free Software
3464 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3466 + * squashfs.h
3467 + */
3469 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3470 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3471 +#endif
3473 +#ifdef SQUASHFS_TRACE
3474 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3475 +#else
3476 +#define TRACE(s, args...) {}
3477 +#endif
3479 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3481 +#define SERROR(s, args...) do { \
3482 + if (!silent) \
3483 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3484 + } while(0)
3486 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3488 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3490 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3493 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3494 +#define SQSH_EXTERN
3495 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3496 + long long index, unsigned int length,
3497 + long long *next_index, int srclength);
3498 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3499 + long long block, unsigned int offset,
3500 + int length, long long *next_block,
3501 + unsigned int *next_offset);
3502 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3503 + squashfs_fragment_cache *fragment);
3504 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3505 + *s, long long start_block,
3506 + int length);
3507 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
3508 +extern const struct address_space_operations squashfs_symlink_aops;
3509 +extern const struct address_space_operations squashfs_aops;
3510 +extern const struct address_space_operations squashfs_aops_4K;
3511 +extern struct inode_operations squashfs_dir_inode_ops;
3512 +#else
3513 +#define SQSH_EXTERN static
3514 +#endif
3516 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3517 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3518 +#else
3519 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3521 + return 0;
3523 +#endif
3525 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3526 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3527 +#else
3528 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3530 + return 0;
3532 +#endif
3533 diff -urN linux-2.6.23/fs/squashfs/squashfs2_0.c linux-2.6.23.sqlzma/fs/squashfs/squashfs2_0.c
3534 --- linux-2.6.23/fs/squashfs/squashfs2_0.c 1969-12-31 19:00:00.000000000 -0500
3535 +++ linux-2.6.23.sqlzma/fs/squashfs/squashfs2_0.c 2007-10-14 10:24:31.000000000 -0400
3536 @@ -0,0 +1,742 @@
3538 + * Squashfs - a compressed read only filesystem for Linux
3540 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3541 + * Phillip Lougher <phillip@lougher.org.uk>
3543 + * This program is free software; you can redistribute it and/or
3544 + * modify it under the terms of the GNU General Public License
3545 + * as published by the Free Software Foundation; either version 2,
3546 + * or (at your option) any later version.
3548 + * This program is distributed in the hope that it will be useful,
3549 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3550 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3551 + * GNU General Public License for more details.
3553 + * You should have received a copy of the GNU General Public License
3554 + * along with this program; if not, write to the Free Software
3555 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3557 + * squashfs2_0.c
3558 + */
3560 +#include <linux/squashfs_fs.h>
3561 +#include <linux/module.h>
3562 +#include <linux/zlib.h>
3563 +#include <linux/fs.h>
3564 +#include <linux/squashfs_fs_sb.h>
3565 +#include <linux/squashfs_fs_i.h>
3567 +#include "squashfs.h"
3568 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
3569 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
3570 + struct nameidata *);
3572 +static struct file_operations squashfs_dir_ops_2 = {
3573 + .read = generic_read_dir,
3574 + .readdir = squashfs_readdir_2
3577 +static struct inode_operations squashfs_dir_inode_ops_2 = {
3578 + .lookup = squashfs_lookup_2
3581 +static unsigned char squashfs_filetype_table[] = {
3582 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
3585 +static int read_fragment_index_table_2(struct super_block *s)
3587 + struct squashfs_sb_info *msblk = s->s_fs_info;
3588 + struct squashfs_super_block *sblk = &msblk->sblk;
3590 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
3591 + (sblk->fragments), GFP_KERNEL))) {
3592 + ERROR("Failed to allocate uid/gid table\n");
3593 + return 0;
3596 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
3597 + !squashfs_read_data(s, (char *)
3598 + msblk->fragment_index_2,
3599 + sblk->fragment_table_start,
3600 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
3601 + (sblk->fragments) |
3602 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
3603 + ERROR("unable to read fragment index table\n");
3604 + return 0;
3607 + if (msblk->swap) {
3608 + int i;
3609 + unsigned int fragment;
3611 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
3612 + i++) {
3613 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
3614 + &msblk->fragment_index_2[i], 1);
3615 + msblk->fragment_index_2[i] = fragment;
3619 + return 1;
3623 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
3624 + long long *fragment_start_block,
3625 + unsigned int *fragment_size)
3627 + struct squashfs_sb_info *msblk = s->s_fs_info;
3628 + long long start_block =
3629 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
3630 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
3631 + struct squashfs_fragment_entry_2 fragment_entry;
3633 + if (msblk->swap) {
3634 + struct squashfs_fragment_entry_2 sfragment_entry;
3636 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
3637 + start_block, offset,
3638 + sizeof(sfragment_entry), &start_block,
3639 + &offset))
3640 + goto out;
3641 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
3642 + } else
3643 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
3644 + start_block, offset,
3645 + sizeof(fragment_entry), &start_block,
3646 + &offset))
3647 + goto out;
3649 + *fragment_start_block = fragment_entry.start_block;
3650 + *fragment_size = fragment_entry.size;
3652 + return 1;
3654 +out:
3655 + return 0;
3659 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
3660 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
3662 + struct squashfs_super_block *sblk = &msblk->sblk;
3664 + i->i_ino = ino;
3665 + i->i_mtime.tv_sec = sblk->mkfs_time;
3666 + i->i_atime.tv_sec = sblk->mkfs_time;
3667 + i->i_ctime.tv_sec = sblk->mkfs_time;
3668 + i->i_uid = msblk->uid[inodeb->uid];
3669 + i->i_mode = inodeb->mode;
3670 + i->i_nlink = 1;
3671 + i->i_size = 0;
3672 + if (inodeb->guid == SQUASHFS_GUIDS)
3673 + i->i_gid = i->i_uid;
3674 + else
3675 + i->i_gid = msblk->guid[inodeb->guid];
3679 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
3681 + struct super_block *s = i->i_sb;
3682 + struct squashfs_sb_info *msblk = s->s_fs_info;
3683 + struct squashfs_super_block *sblk = &msblk->sblk;
3684 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
3685 + sblk->inode_table_start;
3686 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
3687 + unsigned int ino = i->i_ino;
3688 + long long next_block;
3689 + unsigned int next_offset;
3690 + union squashfs_inode_header_2 id, sid;
3691 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
3692 + *sinodeb = &sid.base;
3694 + TRACE("Entered squashfs_iget\n");
3696 + if (msblk->swap) {
3697 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
3698 + offset, sizeof(*sinodeb), &next_block,
3699 + &next_offset))
3700 + goto failed_read;
3701 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
3702 + sizeof(*sinodeb));
3703 + } else
3704 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
3705 + offset, sizeof(*inodeb), &next_block,
3706 + &next_offset))
3707 + goto failed_read;
3709 + squashfs_new_inode(msblk, i, inodeb, ino);
3711 + switch(inodeb->inode_type) {
3712 + case SQUASHFS_FILE_TYPE: {
3713 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
3714 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
3715 + long long frag_blk;
3716 + unsigned int frag_size = 0;
3718 + if (msblk->swap) {
3719 + if (!squashfs_get_cached_block(s, (char *)
3720 + sinodep, block, offset,
3721 + sizeof(*sinodep), &next_block,
3722 + &next_offset))
3723 + goto failed_read;
3724 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
3725 + } else
3726 + if (!squashfs_get_cached_block(s, (char *)
3727 + inodep, block, offset,
3728 + sizeof(*inodep), &next_block,
3729 + &next_offset))
3730 + goto failed_read;
3732 + frag_blk = SQUASHFS_INVALID_BLK;
3733 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
3734 + !get_fragment_location_2(s,
3735 + inodep->fragment, &frag_blk, &frag_size))
3736 + goto failed_read;
3738 + i->i_size = inodep->file_size;
3739 + i->i_fop = &generic_ro_fops;
3740 + i->i_mode |= S_IFREG;
3741 + i->i_mtime.tv_sec = inodep->mtime;
3742 + i->i_atime.tv_sec = inodep->mtime;
3743 + i->i_ctime.tv_sec = inodep->mtime;
3744 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
3745 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
3746 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
3747 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
3748 + SQUASHFS_I(i)->start_block = inodep->start_block;
3749 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
3750 + SQUASHFS_I(i)->offset = next_offset;
3751 + if (sblk->block_size > 4096)
3752 + i->i_data.a_ops = &squashfs_aops;
3753 + else
3754 + i->i_data.a_ops = &squashfs_aops_4K;
3756 + TRACE("File inode %x:%x, start_block %x, "
3757 + "block_list_start %llx, offset %x\n",
3758 + SQUASHFS_INODE_BLK(inode), offset,
3759 + inodep->start_block, next_block,
3760 + next_offset);
3761 + break;
3763 + case SQUASHFS_DIR_TYPE: {
3764 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
3765 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
3767 + if (msblk->swap) {
3768 + if (!squashfs_get_cached_block(s, (char *)
3769 + sinodep, block, offset,
3770 + sizeof(*sinodep), &next_block,
3771 + &next_offset))
3772 + goto failed_read;
3773 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
3774 + } else
3775 + if (!squashfs_get_cached_block(s, (char *)
3776 + inodep, block, offset,
3777 + sizeof(*inodep), &next_block,
3778 + &next_offset))
3779 + goto failed_read;
3781 + i->i_size = inodep->file_size;
3782 + i->i_op = &squashfs_dir_inode_ops_2;
3783 + i->i_fop = &squashfs_dir_ops_2;
3784 + i->i_mode |= S_IFDIR;
3785 + i->i_mtime.tv_sec = inodep->mtime;
3786 + i->i_atime.tv_sec = inodep->mtime;
3787 + i->i_ctime.tv_sec = inodep->mtime;
3788 + SQUASHFS_I(i)->start_block = inodep->start_block;
3789 + SQUASHFS_I(i)->offset = inodep->offset;
3790 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
3791 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
3793 + TRACE("Directory inode %x:%x, start_block %x, offset "
3794 + "%x\n", SQUASHFS_INODE_BLK(inode),
3795 + offset, inodep->start_block,
3796 + inodep->offset);
3797 + break;
3799 + case SQUASHFS_LDIR_TYPE: {
3800 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
3801 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
3803 + if (msblk->swap) {
3804 + if (!squashfs_get_cached_block(s, (char *)
3805 + sinodep, block, offset,
3806 + sizeof(*sinodep), &next_block,
3807 + &next_offset))
3808 + goto failed_read;
3809 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
3810 + sinodep);
3811 + } else
3812 + if (!squashfs_get_cached_block(s, (char *)
3813 + inodep, block, offset,
3814 + sizeof(*inodep), &next_block,
3815 + &next_offset))
3816 + goto failed_read;
3818 + i->i_size = inodep->file_size;
3819 + i->i_op = &squashfs_dir_inode_ops_2;
3820 + i->i_fop = &squashfs_dir_ops_2;
3821 + i->i_mode |= S_IFDIR;
3822 + i->i_mtime.tv_sec = inodep->mtime;
3823 + i->i_atime.tv_sec = inodep->mtime;
3824 + i->i_ctime.tv_sec = inodep->mtime;
3825 + SQUASHFS_I(i)->start_block = inodep->start_block;
3826 + SQUASHFS_I(i)->offset = inodep->offset;
3827 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
3828 + SQUASHFS_I(i)->u.s2.directory_index_offset =
3829 + next_offset;
3830 + SQUASHFS_I(i)->u.s2.directory_index_count =
3831 + inodep->i_count;
3832 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
3834 + TRACE("Long directory inode %x:%x, start_block %x, "
3835 + "offset %x\n",
3836 + SQUASHFS_INODE_BLK(inode), offset,
3837 + inodep->start_block, inodep->offset);
3838 + break;
3840 + case SQUASHFS_SYMLINK_TYPE: {
3841 + struct squashfs_symlink_inode_header_2 *inodep =
3842 + &id.symlink;
3843 + struct squashfs_symlink_inode_header_2 *sinodep =
3844 + &sid.symlink;
3846 + if (msblk->swap) {
3847 + if (!squashfs_get_cached_block(s, (char *)
3848 + sinodep, block, offset,
3849 + sizeof(*sinodep), &next_block,
3850 + &next_offset))
3851 + goto failed_read;
3852 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
3853 + sinodep);
3854 + } else
3855 + if (!squashfs_get_cached_block(s, (char *)
3856 + inodep, block, offset,
3857 + sizeof(*inodep), &next_block,
3858 + &next_offset))
3859 + goto failed_read;
3861 + i->i_size = inodep->symlink_size;
3862 + i->i_op = &page_symlink_inode_operations;
3863 + i->i_data.a_ops = &squashfs_symlink_aops;
3864 + i->i_mode |= S_IFLNK;
3865 + SQUASHFS_I(i)->start_block = next_block;
3866 + SQUASHFS_I(i)->offset = next_offset;
3868 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
3869 + "offset %x\n",
3870 + SQUASHFS_INODE_BLK(inode), offset,
3871 + next_block, next_offset);
3872 + break;
3874 + case SQUASHFS_BLKDEV_TYPE:
3875 + case SQUASHFS_CHRDEV_TYPE: {
3876 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
3877 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
3879 + if (msblk->swap) {
3880 + if (!squashfs_get_cached_block(s, (char *)
3881 + sinodep, block, offset,
3882 + sizeof(*sinodep), &next_block,
3883 + &next_offset))
3884 + goto failed_read;
3885 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
3886 + } else
3887 + if (!squashfs_get_cached_block(s, (char *)
3888 + inodep, block, offset,
3889 + sizeof(*inodep), &next_block,
3890 + &next_offset))
3891 + goto failed_read;
3893 + i->i_mode |= (inodeb->inode_type ==
3894 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
3895 + S_IFBLK;
3896 + init_special_inode(i, i->i_mode,
3897 + old_decode_dev(inodep->rdev));
3899 + TRACE("Device inode %x:%x, rdev %x\n",
3900 + SQUASHFS_INODE_BLK(inode), offset,
3901 + inodep->rdev);
3902 + break;
3904 + case SQUASHFS_FIFO_TYPE:
3905 + case SQUASHFS_SOCKET_TYPE: {
3907 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
3908 + ? S_IFIFO : S_IFSOCK;
3909 + init_special_inode(i, i->i_mode, 0);
3910 + break;
3912 + default:
3913 + ERROR("Unknown inode type %d in squashfs_iget!\n",
3914 + inodeb->inode_type);
3915 + goto failed_read1;
3918 + return 1;
3920 +failed_read:
3921 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
3923 +failed_read1:
3924 + return 0;
3928 +static int get_dir_index_using_offset(struct super_block *s, long long
3929 + *next_block, unsigned int *next_offset,
3930 + long long index_start,
3931 + unsigned int index_offset, int i_count,
3932 + long long f_pos)
3934 + struct squashfs_sb_info *msblk = s->s_fs_info;
3935 + struct squashfs_super_block *sblk = &msblk->sblk;
3936 + int i, length = 0;
3937 + struct squashfs_dir_index_2 index;
3939 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
3940 + i_count, (unsigned int) f_pos);
3942 + if (f_pos == 0)
3943 + goto finish;
3945 + for (i = 0; i < i_count; i++) {
3946 + if (msblk->swap) {
3947 + struct squashfs_dir_index_2 sindex;
3948 + squashfs_get_cached_block(s, (char *) &sindex,
3949 + index_start, index_offset,
3950 + sizeof(sindex), &index_start,
3951 + &index_offset);
3952 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
3953 + } else
3954 + squashfs_get_cached_block(s, (char *) &index,
3955 + index_start, index_offset,
3956 + sizeof(index), &index_start,
3957 + &index_offset);
3959 + if (index.index > f_pos)
3960 + break;
3962 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
3963 + index.size + 1, &index_start,
3964 + &index_offset);
3966 + length = index.index;
3967 + *next_block = index.start_block + sblk->directory_table_start;
3970 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
3972 +finish:
3973 + return length;
3977 +static int get_dir_index_using_name(struct super_block *s, long long
3978 + *next_block, unsigned int *next_offset,
3979 + long long index_start,
3980 + unsigned int index_offset, int i_count,
3981 + const char *name, int size)
3983 + struct squashfs_sb_info *msblk = s->s_fs_info;
3984 + struct squashfs_super_block *sblk = &msblk->sblk;
3985 + int i, length = 0;
3986 + struct squashfs_dir_index_2 *index;
3987 + char *str;
3989 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
3991 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
3992 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
3993 + ERROR("Failed to allocate squashfs_dir_index\n");
3994 + goto failure;
3997 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
3998 + strncpy(str, name, size);
3999 + str[size] = '\0';
4001 + for (i = 0; i < i_count; i++) {
4002 + if (msblk->swap) {
4003 + struct squashfs_dir_index_2 sindex;
4004 + squashfs_get_cached_block(s, (char *) &sindex,
4005 + index_start, index_offset,
4006 + sizeof(sindex), &index_start,
4007 + &index_offset);
4008 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
4009 + } else
4010 + squashfs_get_cached_block(s, (char *) index,
4011 + index_start, index_offset,
4012 + sizeof(struct squashfs_dir_index_2),
4013 + &index_start, &index_offset);
4015 + squashfs_get_cached_block(s, index->name, index_start,
4016 + index_offset, index->size + 1,
4017 + &index_start, &index_offset);
4019 + index->name[index->size + 1] = '\0';
4021 + if (strcmp(index->name, str) > 0)
4022 + break;
4024 + length = index->index;
4025 + *next_block = index->start_block + sblk->directory_table_start;
4028 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
4029 + kfree(str);
4030 +failure:
4031 + return length;
4035 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
4037 + struct inode *i = file->f_dentry->d_inode;
4038 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
4039 + struct squashfs_super_block *sblk = &msblk->sblk;
4040 + long long next_block = SQUASHFS_I(i)->start_block +
4041 + sblk->directory_table_start;
4042 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
4043 + dir_count;
4044 + struct squashfs_dir_header_2 dirh;
4045 + struct squashfs_dir_entry_2 *dire;
4047 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
4049 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
4050 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
4051 + ERROR("Failed to allocate squashfs_dir_entry\n");
4052 + goto finish;
4055 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
4056 + SQUASHFS_I(i)->u.s2.directory_index_start,
4057 + SQUASHFS_I(i)->u.s2.directory_index_offset,
4058 + SQUASHFS_I(i)->u.s2.directory_index_count,
4059 + file->f_pos);
4061 + while (length < i_size_read(i)) {
4062 + /* read directory header */
4063 + if (msblk->swap) {
4064 + struct squashfs_dir_header_2 sdirh;
4066 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
4067 + next_block, next_offset, sizeof(sdirh),
4068 + &next_block, &next_offset))
4069 + goto failed_read;
4071 + length += sizeof(sdirh);
4072 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
4073 + } else {
4074 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
4075 + next_block, next_offset, sizeof(dirh),
4076 + &next_block, &next_offset))
4077 + goto failed_read;
4079 + length += sizeof(dirh);
4082 + dir_count = dirh.count + 1;
4083 + while (dir_count--) {
4084 + if (msblk->swap) {
4085 + struct squashfs_dir_entry_2 sdire;
4086 + if (!squashfs_get_cached_block(i->i_sb, (char *)
4087 + &sdire, next_block, next_offset,
4088 + sizeof(sdire), &next_block,
4089 + &next_offset))
4090 + goto failed_read;
4092 + length += sizeof(sdire);
4093 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
4094 + } else {
4095 + if (!squashfs_get_cached_block(i->i_sb, (char *)
4096 + dire, next_block, next_offset,
4097 + sizeof(*dire), &next_block,
4098 + &next_offset))
4099 + goto failed_read;
4101 + length += sizeof(*dire);
4104 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
4105 + next_block, next_offset,
4106 + dire->size + 1, &next_block,
4107 + &next_offset))
4108 + goto failed_read;
4110 + length += dire->size + 1;
4112 + if (file->f_pos >= length)
4113 + continue;
4115 + dire->name[dire->size + 1] = '\0';
4117 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
4118 + (unsigned int) dirent, dire->name,
4119 + dire->size + 1, (int) file->f_pos,
4120 + dirh.start_block, dire->offset,
4121 + squashfs_filetype_table[dire->type]);
4123 + if (filldir(dirent, dire->name, dire->size + 1,
4124 + file->f_pos, SQUASHFS_MK_VFS_INODE(
4125 + dirh.start_block, dire->offset),
4126 + squashfs_filetype_table[dire->type])
4127 + < 0) {
4128 + TRACE("Filldir returned less than 0\n");
4129 + goto finish;
4131 + file->f_pos = length;
4135 +finish:
4136 + kfree(dire);
4137 + return 0;
4139 +failed_read:
4140 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
4141 + next_offset);
4142 + kfree(dire);
4143 + return 0;
4147 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
4148 + struct nameidata *nd)
4150 + const unsigned char *name = dentry->d_name.name;
4151 + int len = dentry->d_name.len;
4152 + struct inode *inode = NULL;
4153 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
4154 + struct squashfs_super_block *sblk = &msblk->sblk;
4155 + long long next_block = SQUASHFS_I(i)->start_block +
4156 + sblk->directory_table_start;
4157 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
4158 + dir_count;
4159 + struct squashfs_dir_header_2 dirh;
4160 + struct squashfs_dir_entry_2 *dire;
4161 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
4163 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
4165 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
4166 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
4167 + ERROR("Failed to allocate squashfs_dir_entry\n");
4168 + goto exit_loop;
4171 + if (len > SQUASHFS_NAME_LEN)
4172 + goto exit_loop;
4174 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
4175 + SQUASHFS_I(i)->u.s2.directory_index_start,
4176 + SQUASHFS_I(i)->u.s2.directory_index_offset,
4177 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
4178 + len);
4180 + while (length < i_size_read(i)) {
4181 + /* read directory header */
4182 + if (msblk->swap) {
4183 + struct squashfs_dir_header_2 sdirh;
4184 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
4185 + next_block, next_offset, sizeof(sdirh),
4186 + &next_block, &next_offset))
4187 + goto failed_read;
4189 + length += sizeof(sdirh);
4190 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
4191 + } else {
4192 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
4193 + next_block, next_offset, sizeof(dirh),
4194 + &next_block, &next_offset))
4195 + goto failed_read;
4197 + length += sizeof(dirh);
4200 + dir_count = dirh.count + 1;
4201 + while (dir_count--) {
4202 + if (msblk->swap) {
4203 + struct squashfs_dir_entry_2 sdire;
4204 + if (!squashfs_get_cached_block(i->i_sb, (char *)
4205 + &sdire, next_block,next_offset,
4206 + sizeof(sdire), &next_block,
4207 + &next_offset))
4208 + goto failed_read;
4210 + length += sizeof(sdire);
4211 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
4212 + } else {
4213 + if (!squashfs_get_cached_block(i->i_sb, (char *)
4214 + dire, next_block,next_offset,
4215 + sizeof(*dire), &next_block,
4216 + &next_offset))
4217 + goto failed_read;
4219 + length += sizeof(*dire);
4222 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
4223 + next_block, next_offset, dire->size + 1,
4224 + &next_block, &next_offset))
4225 + goto failed_read;
4227 + length += dire->size + 1;
4229 + if (sorted && name[0] < dire->name[0])
4230 + goto exit_loop;
4232 + if ((len == dire->size + 1) && !strncmp(name,
4233 + dire->name, len)) {
4234 + squashfs_inode_t ino =
4235 + SQUASHFS_MKINODE(dirh.start_block,
4236 + dire->offset);
4237 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
4238 + dire->offset);
4240 + TRACE("calling squashfs_iget for directory "
4241 + "entry %s, inode %x:%x, %lld\n", name,
4242 + dirh.start_block, dire->offset, ino);
4244 + inode = squashfs_iget(i->i_sb, ino, inode_number);
4246 + goto exit_loop;
4251 +exit_loop:
4252 + kfree(dire);
4253 + d_add(dentry, inode);
4254 + return ERR_PTR(0);
4256 +failed_read:
4257 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
4258 + next_offset);
4259 + goto exit_loop;
4263 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
4265 + struct squashfs_super_block *sblk = &msblk->sblk;
4267 + msblk->read_inode = squashfs_read_inode_2;
4268 + msblk->read_fragment_index_table = read_fragment_index_table_2;
4270 + sblk->bytes_used = sblk->bytes_used_2;
4271 + sblk->uid_start = sblk->uid_start_2;
4272 + sblk->guid_start = sblk->guid_start_2;
4273 + sblk->inode_table_start = sblk->inode_table_start_2;
4274 + sblk->directory_table_start = sblk->directory_table_start_2;
4275 + sblk->fragment_table_start = sblk->fragment_table_start_2;
4277 + return 1;
4279 diff -urN linux-2.6.23/fs/squashfs/uncomp.c linux-2.6.23.sqlzma/fs/squashfs/uncomp.c
4280 --- linux-2.6.23/fs/squashfs/uncomp.c 1969-12-31 19:00:00.000000000 -0500
4281 +++ linux-2.6.23.sqlzma/fs/squashfs/uncomp.c 2007-10-14 12:43:55.000000000 -0400
4282 @@ -0,0 +1,221 @@
4284 + * Copyright (C) 2006, 2007 Junjiro Okajima
4285 + * Copyright (C) 2006, 2007 Tomas Matejicek, slax.org
4287 + * LICENSE follows the described one in lzma.txt.
4288 + */
4290 +/* $Id: uncomp.c,v 1.30 2007/03/04 12:45:53 jro Exp $ */
4292 +/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */
4294 +#ifndef __KERNEL__
4295 +#include <stdio.h>
4296 +#include <stdlib.h>
4297 +#include <string.h>
4298 +#include <errno.h>
4299 +#include <assert.h>
4300 +#include <pthread.h>
4301 +#define unlikely(x) __builtin_expect(!!(x), 0)
4302 +#define BUG_ON(x) assert(!(x))
4303 +/* sqlzma buffers are always larger than a page. true? */
4304 +#define kmalloc(sz,gfp) malloc(sz)
4305 +#define kfree(p) free(p)
4306 +#define zlib_inflate(s, f) inflate(s, f)
4307 +#define zlib_inflateInit(s) inflateInit(s)
4308 +#define zlib_inflateReset(s) inflateReset(s)
4309 +#define zlib_inflateEnd(s) inflateEnd(s)
4310 +#else
4311 +#include <linux/init.h>
4312 +#include <linux/module.h>
4313 +#include <linux/kernel.h>
4314 +#include <linux/vmalloc.h>
4315 +#ifndef WARN_ON_ONCE
4316 +#define WARN_ON_ONCE(b) WARN_ON(b)
4317 +#endif
4318 +#endif /* __KERNEL__ */
4320 +#include "sqlzma.h"
4321 +#include "LzmaDecode.h"
4323 +static int LzmaUncompress(struct sqlzma_un *un)
4325 + int err, i, ret;
4326 + SizeT outSize, inProcessed, outProcessed, srclen;
4327 + /* it's about 24-80 bytes structure, if int is 32-bit */
4328 + CLzmaDecoderState state;
4329 + unsigned char *dst, *src, a[8];
4330 + struct sized_buf *sbuf;
4332 + /* Decode LZMA properties and allocate memory */
4333 + err = -EINVAL;
4334 + src = (unsigned char *)un->un_cmbuf;
4335 + ret = LzmaDecodeProperties(&state.Properties, src, LZMA_PROPERTIES_SIZE);
4336 + src += LZMA_PROPERTIES_SIZE;
4337 + if (unlikely(ret != LZMA_RESULT_OK))
4338 + goto out;
4339 + i = LzmaGetNumProbs(&state.Properties);
4340 + if (unlikely(i <= 0))
4341 + i = 1;
4342 + i *= sizeof(CProb);
4343 + sbuf = un->un_a + SQUN_PROB;
4344 + if (unlikely(sbuf->sz < i)) {
4345 + if (sbuf->buf && sbuf->buf != un->un_prob)
4346 + kfree(sbuf->buf);
4347 +#ifdef __KERNEL__
4348 + printk("%s:%d: %d --> %d\n", __func__, __LINE__, sbuf->sz, i);
4349 +#else
4350 + printf("%d --> %d\n", sbuf->sz, i);
4351 +#endif
4352 + err = -ENOMEM;
4353 + sbuf->sz = 0;
4354 + sbuf->buf = kmalloc(i, GFP_ATOMIC);
4355 + if (unlikely(!sbuf->buf))
4356 + goto out;
4357 + sbuf->sz = i;
4359 + state.Probs = (void*)sbuf->buf;
4361 + /* Read uncompressed size */
4362 + memcpy(a, src, sizeof(a));
4363 + src += sizeof(a);
4364 + outSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
4366 + err = -EINVAL;
4367 + dst = un->un_resbuf;
4368 + if (unlikely(!dst || outSize > un->un_reslen))
4369 + goto out;
4370 + un->un_reslen = outSize;
4371 + srclen = un->un_cmlen - (src - un->un_cmbuf);
4373 + /* Decompress */
4374 + err = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,
4375 + &outProcessed);
4376 + if (err)
4377 + err = -EINVAL;
4379 + out:
4380 +#ifndef __KERNEL__
4381 + if (err)
4382 + fprintf(stderr, "err %d\n", err);
4383 +#endif
4384 + return err;
4387 +int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
4388 + struct sized_buf *dst)
4390 + int err, by_lzma = 0;
4391 + if (un->un_lzma && is_lzma(*src->buf)) {
4392 + by_lzma = 1;
4393 + un->un_cmbuf = src->buf;
4394 + un->un_cmlen = src->sz;
4395 + un->un_resbuf = dst->buf;
4396 + un->un_reslen = dst->sz;
4398 + /* this library is thread-safe */
4399 + err = LzmaUncompress(un);
4400 + goto out;
4403 + err = zlib_inflateReset(&un->un_stream);
4404 + if (unlikely(err != Z_OK))
4405 + goto out;
4406 + un->un_stream.next_in = src->buf;
4407 + un->un_stream.avail_in = src->sz;
4408 + un->un_stream.next_out = dst->buf;
4409 + un->un_stream.avail_out = dst->sz;
4410 + err = zlib_inflate(&un->un_stream, Z_FINISH);
4411 + if (err == Z_STREAM_END)
4412 + err = 0;
4414 + out:
4415 + if (err) {
4416 +#ifdef __KERNEL__
4417 + WARN_ON_ONCE(1);
4418 +#else
4419 + char a[64] = "ZLIB ";
4420 + if (by_lzma) {
4421 + strcpy(a, "LZMA ");
4422 +#ifdef _REENTRANT
4423 + strerror_r(err, a + 5, sizeof(a) - 5);
4424 +#else
4425 + strncat(a, strerror(err), sizeof(a) - 5);
4426 +#endif
4427 + } else
4428 + strncat(a, zError(err), sizeof(a) - 5);
4429 + fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
4430 +#endif
4432 + return err;
4435 +int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)
4437 + int err;
4439 + err = -ENOMEM;
4440 + un->un_lzma = do_lzma;
4441 + memset(un->un_a, 0, sizeof(un->un_a));
4442 + un->un_a[SQUN_PROB].buf = un->un_prob;
4443 + un->un_a[SQUN_PROB].sz = sizeof(un->un_prob);
4444 + if (res_sz) {
4445 + un->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);
4446 + if (unlikely(!un->un_a[SQUN_RESULT].buf))
4447 + return err;
4448 + un->un_a[SQUN_RESULT].sz = res_sz;
4451 + un->un_stream.next_in = NULL;
4452 + un->un_stream.avail_in = 0;
4453 +#ifdef __KERNEL__
4454 + un->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
4455 + if (unlikely(!un->un_stream.workspace))
4456 + return err;
4457 +#else
4458 + un->un_stream.opaque = NULL;
4459 + un->un_stream.zalloc = Z_NULL;
4460 + un->un_stream.zfree = Z_NULL;
4461 +#endif
4462 + err = zlib_inflateInit(&un->un_stream);
4463 + if (unlikely(err == Z_MEM_ERROR))
4464 + return -ENOMEM;
4465 + BUG_ON(err);
4466 + return err;
4469 +void sqlzma_fin(struct sqlzma_un *un)
4471 + int i;
4472 + for (i = 0; i < SQUN_LAST; i++)
4473 + if (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)
4474 + kfree(un->un_a[i].buf);
4475 + BUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);
4478 +#ifdef __KERNEL__
4479 +EXPORT_SYMBOL(sqlzma_un);
4480 +EXPORT_SYMBOL(sqlzma_init);
4481 +EXPORT_SYMBOL(sqlzma_fin);
4483 +#if 0
4484 +static int __init sqlzma_init(void)
4486 + return 0;
4489 +static void __exit sqlzma_exit(void)
4493 +module_init(sqlzma_init);
4494 +module_exit(sqlzma_exit);
4495 +#endif
4497 +MODULE_LICENSE("GPL");
4498 +MODULE_AUTHOR("Junjiro Okajima <hooanon05 at yahoo dot co dot jp>");
4499 +MODULE_VERSION("$Id: uncomp.c,v 1.30 2007/03/04 12:45:53 jro Exp $");
4500 +MODULE_DESCRIPTION("LZMA uncompress for squashfs. "
4501 + "Some functions for squashfs to support LZMA and "
4502 + "a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.");
4503 +#endif
4504 diff -urN linux-2.6.23/include/linux/squashfs_fs.h linux-2.6.23.sqlzma/include/linux/squashfs_fs.h
4505 --- linux-2.6.23/include/linux/squashfs_fs.h 1969-12-31 19:00:00.000000000 -0500
4506 +++ linux-2.6.23.sqlzma/include/linux/squashfs_fs.h 2007-10-14 10:24:31.000000000 -0400
4507 @@ -0,0 +1,934 @@
4508 +#ifndef SQUASHFS_FS
4509 +#define SQUASHFS_FS
4512 + * Squashfs
4514 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4515 + * Phillip Lougher <phillip@lougher.org.uk>
4517 + * This program is free software; you can redistribute it and/or
4518 + * modify it under the terms of the GNU General Public License
4519 + * as published by the Free Software Foundation; either version 2,
4520 + * or (at your option) any later version.
4522 + * This program is distributed in the hope that it will be useful,
4523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4525 + * GNU General Public License for more details.
4527 + * You should have received a copy of the GNU General Public License
4528 + * along with this program; if not, write to the Free Software
4529 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4531 + * squashfs_fs.h
4532 + */
4534 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
4535 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
4536 +#endif
4538 +#ifdef CONFIG_SQUASHFS_VMALLOC
4539 +#define SQUASHFS_ALLOC(a) vmalloc(a)
4540 +#define SQUASHFS_FREE(a) vfree(a)
4541 +#else
4542 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
4543 +#define SQUASHFS_FREE(a) kfree(a)
4544 +#endif
4545 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
4546 +#define SQUASHFS_MAJOR 3
4547 +#define SQUASHFS_MINOR 0
4548 +#define SQUASHFS_MAGIC 0x73717368
4549 +#define SQUASHFS_MAGIC_SWAP 0x68737173
4550 +#define SQUASHFS_START 0
4552 +/* size of metadata (inode and directory) blocks */
4553 +#define SQUASHFS_METADATA_SIZE 8192
4554 +#define SQUASHFS_METADATA_LOG 13
4556 +/* default size of data blocks */
4557 +#define SQUASHFS_FILE_SIZE 65536
4558 +#define SQUASHFS_FILE_LOG 16
4560 +#define SQUASHFS_FILE_MAX_SIZE 65536
4562 +/* Max number of uids and gids */
4563 +#define SQUASHFS_UIDS 256
4564 +#define SQUASHFS_GUIDS 255
4566 +/* Max length of filename (not 255) */
4567 +#define SQUASHFS_NAME_LEN 256
4569 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
4570 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
4571 +#define SQUASHFS_INVALID_BLK ((long long) -1)
4572 +#define SQUASHFS_USED_BLK ((long long) -2)
4574 +/* Filesystem flags */
4575 +#define SQUASHFS_NOI 0
4576 +#define SQUASHFS_NOD 1
4577 +#define SQUASHFS_CHECK 2
4578 +#define SQUASHFS_NOF 3
4579 +#define SQUASHFS_NO_FRAG 4
4580 +#define SQUASHFS_ALWAYS_FRAG 5
4581 +#define SQUASHFS_DUPLICATE 6
4582 +#define SQUASHFS_EXPORT 7
4584 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
4586 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
4587 + SQUASHFS_NOI)
4589 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
4590 + SQUASHFS_NOD)
4592 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
4593 + SQUASHFS_NOF)
4595 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
4596 + SQUASHFS_NO_FRAG)
4598 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
4599 + SQUASHFS_ALWAYS_FRAG)
4601 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
4602 + SQUASHFS_DUPLICATE)
4604 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
4605 + SQUASHFS_EXPORT)
4607 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
4608 + SQUASHFS_CHECK)
4610 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
4611 + duplicate_checking, exortable) (noi | (nod << 1) | (check_data << 2) \
4612 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
4613 + (duplicate_checking << 6) | (exportable << 7))
4615 +/* Max number of types and file types */
4616 +#define SQUASHFS_DIR_TYPE 1
4617 +#define SQUASHFS_FILE_TYPE 2
4618 +#define SQUASHFS_SYMLINK_TYPE 3
4619 +#define SQUASHFS_BLKDEV_TYPE 4
4620 +#define SQUASHFS_CHRDEV_TYPE 5
4621 +#define SQUASHFS_FIFO_TYPE 6
4622 +#define SQUASHFS_SOCKET_TYPE 7
4623 +#define SQUASHFS_LDIR_TYPE 8
4624 +#define SQUASHFS_LREG_TYPE 9
4626 +/* 1.0 filesystem type definitions */
4627 +#define SQUASHFS_TYPES 5
4628 +#define SQUASHFS_IPC_TYPE 0
4630 +/* Flag whether block is compressed or uncompressed, bit is set if block is
4631 + * uncompressed */
4632 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
4634 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
4635 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
4637 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
4639 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
4641 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
4642 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
4643 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
4645 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
4648 + * Inode number ops. Inodes consist of a compressed block number, and an
4649 + * uncompressed offset within that block
4650 + */
4651 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
4653 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
4655 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
4656 + << 16) + (B)))
4658 +/* Compute 32 bit VFS inode number from squashfs inode number */
4659 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
4660 + ((b) >> 2) + 1))
4661 +/* XXX */
4663 +/* Translate between VFS mode and squashfs mode */
4664 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
4666 +/* fragment and fragment table defines */
4667 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
4669 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
4670 + SQUASHFS_METADATA_SIZE)
4672 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
4673 + SQUASHFS_METADATA_SIZE)
4675 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
4676 + SQUASHFS_METADATA_SIZE - 1) / \
4677 + SQUASHFS_METADATA_SIZE)
4679 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
4680 + sizeof(long long))
4682 +/* inode lookup table defines */
4683 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
4685 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
4686 + SQUASHFS_METADATA_SIZE)
4688 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
4689 + SQUASHFS_METADATA_SIZE)
4691 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
4692 + SQUASHFS_METADATA_SIZE - 1) / \
4693 + SQUASHFS_METADATA_SIZE)
4695 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
4696 + sizeof(long long))
4698 +/* cached data constants for filesystem */
4699 +#define SQUASHFS_CACHED_BLKS 8
4701 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
4703 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
4704 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
4706 +#define SQUASHFS_MARKER_BYTE 0xff
4708 +/* meta index cache */
4709 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
4710 +#define SQUASHFS_META_ENTRIES 31
4711 +#define SQUASHFS_META_NUMBER 8
4712 +#define SQUASHFS_SLOTS 4
4714 +struct meta_entry {
4715 + long long data_block;
4716 + unsigned int index_block;
4717 + unsigned short offset;
4718 + unsigned short pad;
4721 +struct meta_index {
4722 + unsigned int inode_number;
4723 + unsigned int offset;
4724 + unsigned short entries;
4725 + unsigned short skip;
4726 + unsigned short locked;
4727 + unsigned short pad;
4728 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
4733 + * definitions for structures on disk
4734 + */
4736 +typedef long long squashfs_block_t;
4737 +typedef long long squashfs_inode_t;
4739 +struct squashfs_super_block {
4740 + unsigned int s_magic;
4741 + unsigned int inodes;
4742 + unsigned int bytes_used_2;
4743 + unsigned int uid_start_2;
4744 + unsigned int guid_start_2;
4745 + unsigned int inode_table_start_2;
4746 + unsigned int directory_table_start_2;
4747 + unsigned int s_major:16;
4748 + unsigned int s_minor:16;
4749 + unsigned int block_size_1:16;
4750 + unsigned int block_log:16;
4751 + unsigned int flags:8;
4752 + unsigned int no_uids:8;
4753 + unsigned int no_guids:8;
4754 + unsigned int mkfs_time /* time of filesystem creation */;
4755 + squashfs_inode_t root_inode;
4756 + unsigned int block_size;
4757 + unsigned int fragments;
4758 + unsigned int fragment_table_start_2;
4759 + long long bytes_used;
4760 + long long uid_start;
4761 + long long guid_start;
4762 + long long inode_table_start;
4763 + long long directory_table_start;
4764 + long long fragment_table_start;
4765 + long long lookup_table_start;
4766 +} __attribute__ ((packed));
4768 +struct squashfs_dir_index {
4769 + unsigned int index;
4770 + unsigned int start_block;
4771 + unsigned char size;
4772 + unsigned char name[0];
4773 +} __attribute__ ((packed));
4775 +#define SQUASHFS_BASE_INODE_HEADER \
4776 + unsigned int inode_type:4; \
4777 + unsigned int mode:12; \
4778 + unsigned int uid:8; \
4779 + unsigned int guid:8; \
4780 + unsigned int mtime; \
4781 + unsigned int inode_number;
4783 +struct squashfs_base_inode_header {
4784 + SQUASHFS_BASE_INODE_HEADER;
4785 +} __attribute__ ((packed));
4787 +struct squashfs_ipc_inode_header {
4788 + SQUASHFS_BASE_INODE_HEADER;
4789 + unsigned int nlink;
4790 +} __attribute__ ((packed));
4792 +struct squashfs_dev_inode_header {
4793 + SQUASHFS_BASE_INODE_HEADER;
4794 + unsigned int nlink;
4795 + unsigned short rdev;
4796 +} __attribute__ ((packed));
4798 +struct squashfs_symlink_inode_header {
4799 + SQUASHFS_BASE_INODE_HEADER;
4800 + unsigned int nlink;
4801 + unsigned short symlink_size;
4802 + char symlink[0];
4803 +} __attribute__ ((packed));
4805 +struct squashfs_reg_inode_header {
4806 + SQUASHFS_BASE_INODE_HEADER;
4807 + squashfs_block_t start_block;
4808 + unsigned int fragment;
4809 + unsigned int offset;
4810 + unsigned int file_size;
4811 + unsigned short block_list[0];
4812 +} __attribute__ ((packed));
4814 +struct squashfs_lreg_inode_header {
4815 + SQUASHFS_BASE_INODE_HEADER;
4816 + unsigned int nlink;
4817 + squashfs_block_t start_block;
4818 + unsigned int fragment;
4819 + unsigned int offset;
4820 + long long file_size;
4821 + unsigned short block_list[0];
4822 +} __attribute__ ((packed));
4824 +struct squashfs_dir_inode_header {
4825 + SQUASHFS_BASE_INODE_HEADER;
4826 + unsigned int nlink;
4827 + unsigned int file_size:19;
4828 + unsigned int offset:13;
4829 + unsigned int start_block;
4830 + unsigned int parent_inode;
4831 +} __attribute__ ((packed));
4833 +struct squashfs_ldir_inode_header {
4834 + SQUASHFS_BASE_INODE_HEADER;
4835 + unsigned int nlink;
4836 + unsigned int file_size:27;
4837 + unsigned int offset:13;
4838 + unsigned int start_block;
4839 + unsigned int i_count:16;
4840 + unsigned int parent_inode;
4841 + struct squashfs_dir_index index[0];
4842 +} __attribute__ ((packed));
4844 +union squashfs_inode_header {
4845 + struct squashfs_base_inode_header base;
4846 + struct squashfs_dev_inode_header dev;
4847 + struct squashfs_symlink_inode_header symlink;
4848 + struct squashfs_reg_inode_header reg;
4849 + struct squashfs_lreg_inode_header lreg;
4850 + struct squashfs_dir_inode_header dir;
4851 + struct squashfs_ldir_inode_header ldir;
4852 + struct squashfs_ipc_inode_header ipc;
4855 +struct squashfs_dir_entry {
4856 + unsigned int offset:13;
4857 + unsigned int type:3;
4858 + unsigned int size:8;
4859 + int inode_number:16;
4860 + char name[0];
4861 +} __attribute__ ((packed));
4863 +struct squashfs_dir_header {
4864 + unsigned int count:8;
4865 + unsigned int start_block;
4866 + unsigned int inode_number;
4867 +} __attribute__ ((packed));
4869 +struct squashfs_fragment_entry {
4870 + long long start_block;
4871 + unsigned int size;
4872 + unsigned int pending;
4873 +} __attribute__ ((packed));
4875 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
4876 +extern int squashfs_uncompress_init(void);
4877 +extern int squashfs_uncompress_exit(void);
4880 + * macros to convert each packed bitfield structure from little endian to big
4881 + * endian and vice versa. These are needed when creating or using a filesystem
4882 + * on a machine with different byte ordering to the target architecture.
4884 + */
4886 +#define SQUASHFS_SWAP_START \
4887 + int bits;\
4888 + int b_pos;\
4889 + unsigned long long val;\
4890 + unsigned char *s;\
4891 + unsigned char *d;
4893 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
4894 + SQUASHFS_SWAP_START\
4895 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
4896 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
4897 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
4898 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
4899 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
4900 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
4901 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
4902 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
4903 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
4904 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
4905 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
4906 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
4907 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
4908 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
4909 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
4910 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
4911 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
4912 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
4913 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
4914 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
4915 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
4916 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
4917 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
4918 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
4919 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
4920 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
4921 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
4924 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
4925 + SQUASHFS_MEMSET(s, d, n);\
4926 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
4927 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
4928 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
4929 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
4930 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
4931 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
4933 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
4934 + SQUASHFS_SWAP_START\
4935 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
4938 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
4939 + SQUASHFS_SWAP_START\
4940 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4941 + sizeof(struct squashfs_ipc_inode_header))\
4942 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4945 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
4946 + SQUASHFS_SWAP_START\
4947 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4948 + sizeof(struct squashfs_dev_inode_header)); \
4949 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4950 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
4953 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
4954 + SQUASHFS_SWAP_START\
4955 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4956 + sizeof(struct squashfs_symlink_inode_header));\
4957 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4958 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
4961 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
4962 + SQUASHFS_SWAP_START\
4963 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4964 + sizeof(struct squashfs_reg_inode_header));\
4965 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
4966 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
4967 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
4968 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
4971 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
4972 + SQUASHFS_SWAP_START\
4973 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4974 + sizeof(struct squashfs_lreg_inode_header));\
4975 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4976 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
4977 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
4978 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
4979 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
4982 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
4983 + SQUASHFS_SWAP_START\
4984 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4985 + sizeof(struct squashfs_dir_inode_header));\
4986 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4987 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
4988 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
4989 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
4990 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
4993 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
4994 + SQUASHFS_SWAP_START\
4995 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
4996 + sizeof(struct squashfs_ldir_inode_header));\
4997 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
4998 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
4999 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
5000 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
5001 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
5002 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
5005 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
5006 + SQUASHFS_SWAP_START\
5007 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
5008 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
5009 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
5010 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
5013 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
5014 + SQUASHFS_SWAP_START\
5015 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
5016 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
5017 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
5018 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
5021 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
5022 + SQUASHFS_SWAP_START\
5023 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
5024 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
5025 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
5026 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
5027 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
5030 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
5031 + SQUASHFS_SWAP_START\
5032 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
5033 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
5034 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
5037 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
5039 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
5040 + int entry;\
5041 + int bit_position;\
5042 + SQUASHFS_SWAP_START\
5043 + SQUASHFS_MEMSET(s, d, n * 2);\
5044 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
5045 + 16)\
5046 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
5049 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
5050 + int entry;\
5051 + int bit_position;\
5052 + SQUASHFS_SWAP_START\
5053 + SQUASHFS_MEMSET(s, d, n * 4);\
5054 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
5055 + 32)\
5056 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
5059 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
5060 + int entry;\
5061 + int bit_position;\
5062 + SQUASHFS_SWAP_START\
5063 + SQUASHFS_MEMSET(s, d, n * 8);\
5064 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
5065 + 64)\
5066 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
5069 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
5070 + int entry;\
5071 + int bit_position;\
5072 + SQUASHFS_SWAP_START\
5073 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
5074 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
5075 + bits)\
5076 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
5079 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
5080 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
5082 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
5084 +struct squashfs_base_inode_header_1 {
5085 + unsigned int inode_type:4;
5086 + unsigned int mode:12; /* protection */
5087 + unsigned int uid:4; /* index into uid table */
5088 + unsigned int guid:4; /* index into guid table */
5089 +} __attribute__ ((packed));
5091 +struct squashfs_ipc_inode_header_1 {
5092 + unsigned int inode_type:4;
5093 + unsigned int mode:12; /* protection */
5094 + unsigned int uid:4; /* index into uid table */
5095 + unsigned int guid:4; /* index into guid table */
5096 + unsigned int type:4;
5097 + unsigned int offset:4;
5098 +} __attribute__ ((packed));
5100 +struct squashfs_dev_inode_header_1 {
5101 + unsigned int inode_type:4;
5102 + unsigned int mode:12; /* protection */
5103 + unsigned int uid:4; /* index into uid table */
5104 + unsigned int guid:4; /* index into guid table */
5105 + unsigned short rdev;
5106 +} __attribute__ ((packed));
5108 +struct squashfs_symlink_inode_header_1 {
5109 + unsigned int inode_type:4;
5110 + unsigned int mode:12; /* protection */
5111 + unsigned int uid:4; /* index into uid table */
5112 + unsigned int guid:4; /* index into guid table */
5113 + unsigned short symlink_size;
5114 + char symlink[0];
5115 +} __attribute__ ((packed));
5117 +struct squashfs_reg_inode_header_1 {
5118 + unsigned int inode_type:4;
5119 + unsigned int mode:12; /* protection */
5120 + unsigned int uid:4; /* index into uid table */
5121 + unsigned int guid:4; /* index into guid table */
5122 + unsigned int mtime;
5123 + unsigned int start_block;
5124 + unsigned int file_size:32;
5125 + unsigned short block_list[0];
5126 +} __attribute__ ((packed));
5128 +struct squashfs_dir_inode_header_1 {
5129 + unsigned int inode_type:4;
5130 + unsigned int mode:12; /* protection */
5131 + unsigned int uid:4; /* index into uid table */
5132 + unsigned int guid:4; /* index into guid table */
5133 + unsigned int file_size:19;
5134 + unsigned int offset:13;
5135 + unsigned int mtime;
5136 + unsigned int start_block:24;
5137 +} __attribute__ ((packed));
5139 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
5140 + SQUASHFS_MEMSET(s, d, n);\
5141 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
5142 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
5143 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
5144 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
5146 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
5147 + SQUASHFS_SWAP_START\
5148 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
5151 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
5152 + SQUASHFS_SWAP_START\
5153 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
5154 + sizeof(struct squashfs_ipc_inode_header_1));\
5155 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
5156 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
5159 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
5160 + SQUASHFS_SWAP_START\
5161 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
5162 + sizeof(struct squashfs_dev_inode_header_1));\
5163 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
5166 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
5167 + SQUASHFS_SWAP_START\
5168 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
5169 + sizeof(struct squashfs_symlink_inode_header_1));\
5170 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
5173 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
5174 + SQUASHFS_SWAP_START\
5175 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
5176 + sizeof(struct squashfs_reg_inode_header_1));\
5177 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
5178 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
5179 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
5182 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
5183 + SQUASHFS_SWAP_START\
5184 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
5185 + sizeof(struct squashfs_dir_inode_header_1));\
5186 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
5187 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
5188 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
5189 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
5192 +#endif
5194 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
5196 +struct squashfs_dir_index_2 {
5197 + unsigned int index:27;
5198 + unsigned int start_block:29;
5199 + unsigned char size;
5200 + unsigned char name[0];
5201 +} __attribute__ ((packed));
5203 +struct squashfs_base_inode_header_2 {
5204 + unsigned int inode_type:4;
5205 + unsigned int mode:12; /* protection */
5206 + unsigned int uid:8; /* index into uid table */
5207 + unsigned int guid:8; /* index into guid table */
5208 +} __attribute__ ((packed));
5210 +struct squashfs_ipc_inode_header_2 {
5211 + unsigned int inode_type:4;
5212 + unsigned int mode:12; /* protection */
5213 + unsigned int uid:8; /* index into uid table */
5214 + unsigned int guid:8; /* index into guid table */
5215 +} __attribute__ ((packed));
5217 +struct squashfs_dev_inode_header_2 {
5218 + unsigned int inode_type:4;
5219 + unsigned int mode:12; /* protection */
5220 + unsigned int uid:8; /* index into uid table */
5221 + unsigned int guid:8; /* index into guid table */
5222 + unsigned short rdev;
5223 +} __attribute__ ((packed));
5225 +struct squashfs_symlink_inode_header_2 {
5226 + unsigned int inode_type:4;
5227 + unsigned int mode:12; /* protection */
5228 + unsigned int uid:8; /* index into uid table */
5229 + unsigned int guid:8; /* index into guid table */
5230 + unsigned short symlink_size;
5231 + char symlink[0];
5232 +} __attribute__ ((packed));
5234 +struct squashfs_reg_inode_header_2 {
5235 + unsigned int inode_type:4;
5236 + unsigned int mode:12; /* protection */
5237 + unsigned int uid:8; /* index into uid table */
5238 + unsigned int guid:8; /* index into guid table */
5239 + unsigned int mtime;
5240 + unsigned int start_block;
5241 + unsigned int fragment;
5242 + unsigned int offset;
5243 + unsigned int file_size:32;
5244 + unsigned short block_list[0];
5245 +} __attribute__ ((packed));
5247 +struct squashfs_dir_inode_header_2 {
5248 + unsigned int inode_type:4;
5249 + unsigned int mode:12; /* protection */
5250 + unsigned int uid:8; /* index into uid table */
5251 + unsigned int guid:8; /* index into guid table */
5252 + unsigned int file_size:19;
5253 + unsigned int offset:13;
5254 + unsigned int mtime;
5255 + unsigned int start_block:24;
5256 +} __attribute__ ((packed));
5258 +struct squashfs_ldir_inode_header_2 {
5259 + unsigned int inode_type:4;
5260 + unsigned int mode:12; /* protection */
5261 + unsigned int uid:8; /* index into uid table */
5262 + unsigned int guid:8; /* index into guid table */
5263 + unsigned int file_size:27;
5264 + unsigned int offset:13;
5265 + unsigned int mtime;
5266 + unsigned int start_block:24;
5267 + unsigned int i_count:16;
5268 + struct squashfs_dir_index_2 index[0];
5269 +} __attribute__ ((packed));
5271 +union squashfs_inode_header_2 {
5272 + struct squashfs_base_inode_header_2 base;
5273 + struct squashfs_dev_inode_header_2 dev;
5274 + struct squashfs_symlink_inode_header_2 symlink;
5275 + struct squashfs_reg_inode_header_2 reg;
5276 + struct squashfs_dir_inode_header_2 dir;
5277 + struct squashfs_ldir_inode_header_2 ldir;
5278 + struct squashfs_ipc_inode_header_2 ipc;
5281 +struct squashfs_dir_header_2 {
5282 + unsigned int count:8;
5283 + unsigned int start_block:24;
5284 +} __attribute__ ((packed));
5286 +struct squashfs_dir_entry_2 {
5287 + unsigned int offset:13;
5288 + unsigned int type:3;
5289 + unsigned int size:8;
5290 + char name[0];
5291 +} __attribute__ ((packed));
5293 +struct squashfs_fragment_entry_2 {
5294 + unsigned int start_block;
5295 + unsigned int size;
5296 +} __attribute__ ((packed));
5298 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
5299 + SQUASHFS_MEMSET(s, d, n);\
5300 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
5301 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
5302 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
5303 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
5305 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
5306 + SQUASHFS_SWAP_START\
5307 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
5310 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
5311 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
5313 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
5314 + SQUASHFS_SWAP_START\
5315 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
5316 + sizeof(struct squashfs_dev_inode_header_2)); \
5317 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
5320 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
5321 + SQUASHFS_SWAP_START\
5322 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
5323 + sizeof(struct squashfs_symlink_inode_header_2));\
5324 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
5327 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
5328 + SQUASHFS_SWAP_START\
5329 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
5330 + sizeof(struct squashfs_reg_inode_header_2));\
5331 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
5332 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
5333 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
5334 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
5335 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
5338 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
5339 + SQUASHFS_SWAP_START\
5340 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
5341 + sizeof(struct squashfs_dir_inode_header_2));\
5342 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
5343 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
5344 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
5345 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
5348 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
5349 + SQUASHFS_SWAP_START\
5350 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
5351 + sizeof(struct squashfs_ldir_inode_header_2));\
5352 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
5353 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
5354 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
5355 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
5356 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
5359 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
5360 + SQUASHFS_SWAP_START\
5361 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
5362 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
5363 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
5364 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
5366 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
5367 + SQUASHFS_SWAP_START\
5368 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
5369 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
5370 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
5373 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
5374 + SQUASHFS_SWAP_START\
5375 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
5376 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
5377 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
5378 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
5381 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
5382 + SQUASHFS_SWAP_START\
5383 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
5384 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
5385 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
5388 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
5390 +/* fragment and fragment table defines */
5391 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
5393 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
5394 + SQUASHFS_METADATA_SIZE)
5396 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
5397 + SQUASHFS_METADATA_SIZE)
5399 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
5400 + SQUASHFS_METADATA_SIZE - 1) / \
5401 + SQUASHFS_METADATA_SIZE)
5403 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
5404 + sizeof(int))
5406 +#endif
5408 +#ifdef __KERNEL__
5411 + * macros used to swap each structure entry, taking into account
5412 + * bitfields and different bitfield placing conventions on differing
5413 + * architectures
5414 + */
5416 +#include <asm/byteorder.h>
5418 +#ifdef __BIG_ENDIAN
5419 + /* convert from little endian to big endian */
5420 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
5421 + tbits, b_pos)
5422 +#else
5423 + /* convert from big endian to little endian */
5424 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
5425 + tbits, 64 - tbits - b_pos)
5426 +#endif
5428 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
5429 + b_pos = pos % 8;\
5430 + val = 0;\
5431 + s = (unsigned char *)p + (pos / 8);\
5432 + d = ((unsigned char *) &val) + 7;\
5433 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
5434 + *d-- = *s++;\
5435 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
5438 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
5440 +#endif
5441 +#endif
5442 diff -urN linux-2.6.23/include/linux/squashfs_fs_i.h linux-2.6.23.sqlzma/include/linux/squashfs_fs_i.h
5443 --- linux-2.6.23/include/linux/squashfs_fs_i.h 1969-12-31 19:00:00.000000000 -0500
5444 +++ linux-2.6.23.sqlzma/include/linux/squashfs_fs_i.h 2007-10-14 10:24:31.000000000 -0400
5445 @@ -0,0 +1,45 @@
5446 +#ifndef SQUASHFS_FS_I
5447 +#define SQUASHFS_FS_I
5449 + * Squashfs
5451 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
5452 + * Phillip Lougher <phillip@lougher.org.uk>
5454 + * This program is free software; you can redistribute it and/or
5455 + * modify it under the terms of the GNU General Public License
5456 + * as published by the Free Software Foundation; either version 2,
5457 + * or (at your option) any later version.
5459 + * This program is distributed in the hope that it will be useful,
5460 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5461 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5462 + * GNU General Public License for more details.
5464 + * You should have received a copy of the GNU General Public License
5465 + * along with this program; if not, write to the Free Software
5466 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
5468 + * squashfs_fs_i.h
5469 + */
5471 +struct squashfs_inode_info {
5472 + long long start_block;
5473 + unsigned int offset;
5474 + union {
5475 + struct {
5476 + long long fragment_start_block;
5477 + unsigned int fragment_size;
5478 + unsigned int fragment_offset;
5479 + long long block_list_start;
5480 + } s1;
5481 + struct {
5482 + long long directory_index_start;
5483 + unsigned int directory_index_offset;
5484 + unsigned int directory_index_count;
5485 + unsigned int parent_inode;
5486 + } s2;
5487 + } u;
5488 + struct inode vfs_inode;
5490 +#endif
5491 diff -urN linux-2.6.23/include/linux/squashfs_fs_sb.h linux-2.6.23.sqlzma/include/linux/squashfs_fs_sb.h
5492 --- linux-2.6.23/include/linux/squashfs_fs_sb.h 1969-12-31 19:00:00.000000000 -0500
5493 +++ linux-2.6.23.sqlzma/include/linux/squashfs_fs_sb.h 2007-10-14 14:32:50.000000000 -0400
5494 @@ -0,0 +1,73 @@
5495 +#ifndef SQUASHFS_FS_SB
5496 +#define SQUASHFS_FS_SB
5498 + * Squashfs
5500 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
5501 + * Phillip Lougher <phillip@lougher.org.uk>
5503 + * This program is free software; you can redistribute it and/or
5504 + * modify it under the terms of the GNU General Public License
5505 + * as published by the Free Software Foundation; either version 2,
5506 + * or (at your option) any later version.
5508 + * This program is distributed in the hope that it will be useful,
5509 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5510 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5511 + * GNU General Public License for more details.
5513 + * You should have received a copy of the GNU General Public License
5514 + * along with this program; if not, write to the Free Software
5515 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
5517 + * squashfs_fs_sb.h
5518 + */
5520 +#include <linux/squashfs_fs.h>
5522 +struct squashfs_cache {
5523 + long long block;
5524 + int length;
5525 + long long next_index;
5526 + char *data;
5529 +struct squashfs_fragment_cache {
5530 + long long block;
5531 + int length;
5532 + unsigned int locked;
5533 + char *data;
5536 +struct squashfs_sb_info {
5537 + struct squashfs_super_block sblk;
5538 + int devblksize;
5539 + int devblksize_log2;
5540 + int swap;
5541 + struct squashfs_cache *block_cache;
5542 + struct squashfs_fragment_cache *fragment;
5543 + int next_cache;
5544 + int next_fragment;
5545 + int next_meta_index;
5546 + unsigned int *uid;
5547 + unsigned int *guid;
5548 + long long *fragment_index;
5549 + unsigned int *fragment_index_2;
5550 + char *read_page;
5551 + //struct mutex read_data_mutex;
5552 + struct mutex read_page_mutex;
5553 + struct mutex block_cache_mutex;
5554 + struct mutex fragment_mutex;
5555 + struct mutex meta_index_mutex;
5556 + wait_queue_head_t waitq;
5557 + wait_queue_head_t fragment_wait_queue;
5558 + struct meta_index *meta_index;
5559 + long long *inode_lookup_table;
5560 + int (*read_inode)(struct inode *i, squashfs_inode_t \
5561 + inode);
5562 + long long (*read_blocklist)(struct inode *inode, int \
5563 + index, int readahead_blks, char *block_list, \
5564 + unsigned short **block_p, unsigned int *bsize);
5565 + int (*read_fragment_index_table)(struct super_block *s);
5567 +#endif
5568 diff -urN linux-2.6.23/init/do_mounts_rd.c linux-2.6.23.sqlzma/init/do_mounts_rd.c
5569 --- linux-2.6.23/init/do_mounts_rd.c 2007-10-09 16:31:38.000000000 -0400
5570 +++ linux-2.6.23.sqlzma/init/do_mounts_rd.c 2007-10-14 10:24:31.000000000 -0400
5571 @@ -5,6 +5,7 @@
5572 #include <linux/ext2_fs.h>
5573 #include <linux/romfs_fs.h>
5574 #include <linux/cramfs_fs.h>
5575 +#include <linux/squashfs_fs.h>
5576 #include <linux/initrd.h>
5577 #include <linux/string.h>
5579 @@ -39,6 +40,7 @@
5580 * numbers could not be found.
5582 * We currently check for the following magic numbers:
5583 + * squashfs
5584 * minix
5585 * ext2
5586 * romfs
5587 @@ -53,6 +55,7 @@
5588 struct ext2_super_block *ext2sb;
5589 struct romfs_super_block *romfsb;
5590 struct cramfs_super *cramfsb;
5591 + struct squashfs_super_block *squashfsb;
5592 int nblocks = -1;
5593 unsigned char *buf;
5595 @@ -64,6 +67,7 @@
5596 ext2sb = (struct ext2_super_block *) buf;
5597 romfsb = (struct romfs_super_block *) buf;
5598 cramfsb = (struct cramfs_super *) buf;
5599 + squashfsb = (struct squashfs_super_block *) buf;
5600 memset(buf, 0xe5, size);
5603 @@ -101,6 +105,18 @@
5604 goto done;
5607 + /* squashfs is at block zero too */
5608 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
5609 + printk(KERN_NOTICE
5610 + "RAMDISK: squashfs filesystem found at block %d\n",
5611 + start_block);
5612 + if (squashfsb->s_major < 3)
5613 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
5614 + else
5615 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
5616 + goto done;
5620 * Read block 1 to test for minix and ext2 superblock