]> git.pld-linux.org Git - packages/kernel.git/blame - kernel-squashfs.patch
- applies
[packages/kernel.git] / kernel-squashfs.patch
CommitLineData
dc4c60aa 1diff -x .gitignore -Nurp linux-2.6.24/fs/Kconfig linux-2.6.24-squashfs3.3/fs/Kconfig
2--- linux-2.6.24/fs/Kconfig 2007-10-25 17:41:45.000000000 +0100
3+++ linux-2.6.24-squashfs3.3/fs/Kconfig 2007-11-01 05:06:25.000000000 +0000
4@@ -1396,6 +1396,56 @@ config CRAMFS
5
6 If unsure, say N.
7
8+config SQUASHFS
9+ tristate "SquashFS 3.3 - Squashed file system support"
10+ select ZLIB_INFLATE
11+ help
12+ Saying Y here includes support for SquashFS 3.3 (a Compressed
13+ Read-Only File System). Squashfs is a highly compressed read-only
14+ filesystem for Linux. It uses zlib compression to compress both
15+ files, inodes and directories. Inodes in the system are very small
16+ and all blocks are packed to minimise data overhead. Block sizes
17+ greater than 4K are supported up to a maximum of 1 Mbytes (default
18+ block size 128K). SquashFS 3.3 supports 64 bit filesystems and files
19+ (larger than 4GB), full uid/gid information, hard links and timestamps.
20+
21+ Squashfs is intended for general read-only filesystem use, for
22+ archival use (i.e. in cases where a .tar.gz file may be used), and in
23+ embedded systems where low overhead is needed. Further information
24+ and filesystem tools are available from http://squashfs.sourceforge.net.
25+
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.
31+
32+ If unsure, say N.
33+
34+config SQUASHFS_EMBEDDED
35+
36+ bool "Additional option for memory-constrained systems"
37+ depends on SQUASHFS
38+ default n
39+ help
40+ Saying Y here allows you to specify cache size.
41+
42+ If unsure, say N.
43+
44+config SQUASHFS_FRAGMENT_CACHE_SIZE
45+ int "Number of fragments cached" if SQUASHFS_EMBEDDED
46+ depends on SQUASHFS
47+ default "3"
48+ help
49+ By default SquashFS caches the last 3 fragments read from
50+ the filesystem. Increasing this amount may mean SquashFS
51+ has to re-read fragments less often from disk, at the expense
52+ of extra system memory. Decreasing this amount will mean
53+ SquashFS uses less memory at the expense of extra reads from disk.
54+
55+ Note there must be at least one cached fragment. Anything
56+ much more than three will probably not make much difference.
57+
58 config VXFS_FS
59 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
60 depends on BLOCK
61diff -x .gitignore -Nurp linux-2.6.24/fs/Makefile linux-2.6.24-squashfs3.3/fs/Makefile
62--- linux-2.6.24/fs/Makefile 2007-10-25 17:41:45.000000000 +0100
63+++ linux-2.6.24-squashfs3.3/fs/Makefile 2007-11-01 05:08:09.000000000 +0000
64@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD) += jbd/
65 obj-$(CONFIG_JBD2) += jbd2/
66 obj-$(CONFIG_EXT2_FS) += ext2/
67 obj-$(CONFIG_CRAMFS) += cramfs/
68+obj-$(CONFIG_SQUASHFS) += squashfs/
69 obj-y += ramfs/
70 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
71 obj-$(CONFIG_CODA_FS) += coda/
72diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/inode.c linux-2.6.24-squashfs3.3/fs/squashfs/inode.c
73--- linux-2.6.24/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
74+++ linux-2.6.24-squashfs3.3/fs/squashfs/inode.c 2007-11-01 05:05:00.000000000 +0000
a3d014de 75@@ -0,0 +1,2185 @@
dc4c60aa 76+/*
77+ * Squashfs - a compressed read only filesystem for Linux
78+ *
79+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
80+ * Phillip Lougher <phillip@lougher.demon.co.uk>
81+ *
82+ * This program is free software; you can redistribute it and/or
83+ * modify it under the terms of the GNU General Public License
84+ * as published by the Free Software Foundation; either version 2,
85+ * or (at your option) any later version.
86+ *
87+ * This program is distributed in the hope that it will be useful,
88+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
89+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+ * GNU General Public License for more details.
91+ *
92+ * You should have received a copy of the GNU General Public License
93+ * along with this program; if not, write to the Free Software
94+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
95+ *
96+ * inode.c
97+ */
98+
99+#include <linux/squashfs_fs.h>
100+#include <linux/module.h>
101+#include <linux/zlib.h>
102+#include <linux/fs.h>
103+#include <linux/squashfs_fs_sb.h>
104+#include <linux/squashfs_fs_i.h>
105+#include <linux/buffer_head.h>
106+#include <linux/vfs.h>
107+#include <linux/vmalloc.h>
108+#include <linux/smp_lock.h>
109+#include <linux/exportfs.h>
110+
111+#include "squashfs.h"
112+
113+int squashfs_cached_blks;
114+
dc4c60aa 115+static struct dentry *squashfs_get_parent(struct dentry *child);
116+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
117+static int squashfs_statfs(struct dentry *, struct kstatfs *);
118+static int squashfs_symlink_readpage(struct file *file, struct page *page);
119+static long long read_blocklist(struct inode *inode, int index,
120+ int readahead_blks, char *block_list,
121+ unsigned short **block_p, unsigned int *bsize);
122+static int squashfs_readpage(struct file *file, struct page *page);
123+static int squashfs_readdir(struct file *, void *, filldir_t);
124+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
125+ struct nameidata *);
126+static int squashfs_remount(struct super_block *s, int *flags, char *data);
127+static void squashfs_put_super(struct super_block *);
128+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
129+ struct vfsmount *);
130+static struct inode *squashfs_alloc_inode(struct super_block *sb);
131+static void squashfs_destroy_inode(struct inode *inode);
132+static int init_inodecache(void);
133+static void destroy_inodecache(void);
134+
135+static struct file_system_type squashfs_fs_type = {
136+ .owner = THIS_MODULE,
137+ .name = "squashfs",
138+ .get_sb = squashfs_get_sb,
139+ .kill_sb = kill_block_super,
140+ .fs_flags = FS_REQUIRES_DEV
141+};
142+
143+static const unsigned char squashfs_filetype_table[] = {
144+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
145+};
146+
147+static struct super_operations squashfs_super_ops = {
148+ .alloc_inode = squashfs_alloc_inode,
149+ .destroy_inode = squashfs_destroy_inode,
150+ .statfs = squashfs_statfs,
151+ .put_super = squashfs_put_super,
152+ .remount_fs = squashfs_remount
153+};
154+
155+static struct super_operations squashfs_export_super_ops = {
156+ .alloc_inode = squashfs_alloc_inode,
157+ .destroy_inode = squashfs_destroy_inode,
158+ .statfs = squashfs_statfs,
159+ .put_super = squashfs_put_super,
dc4c60aa 160+};
161+
162+static struct export_operations squashfs_export_ops = {
163+ .get_parent = squashfs_get_parent
164+};
165+
166+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
167+ .readpage = squashfs_symlink_readpage
168+};
169+
170+SQSH_EXTERN const struct address_space_operations squashfs_aops = {
171+ .readpage = squashfs_readpage
172+};
173+
174+static const struct file_operations squashfs_dir_ops = {
175+ .read = generic_read_dir,
176+ .readdir = squashfs_readdir
177+};
178+
179+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
180+ .lookup = squashfs_lookup
181+};
182+
183+
184+static struct buffer_head *get_block_length(struct super_block *s,
185+ int *cur_index, int *offset, int *c_byte)
186+{
187+ struct squashfs_sb_info *msblk = s->s_fs_info;
188+ unsigned short temp;
189+ struct buffer_head *bh;
190+
191+ if (!(bh = sb_bread(s, *cur_index)))
192+ goto out;
193+
194+ if (msblk->devblksize - *offset == 1) {
195+ if (msblk->swap)
196+ ((unsigned char *) &temp)[1] = *((unsigned char *)
197+ (bh->b_data + *offset));
198+ else
199+ ((unsigned char *) &temp)[0] = *((unsigned char *)
200+ (bh->b_data + *offset));
201+ brelse(bh);
202+ if (!(bh = sb_bread(s, ++(*cur_index))))
203+ goto out;
204+ if (msblk->swap)
205+ ((unsigned char *) &temp)[0] = *((unsigned char *)
206+ bh->b_data);
207+ else
208+ ((unsigned char *) &temp)[1] = *((unsigned char *)
209+ bh->b_data);
210+ *c_byte = temp;
211+ *offset = 1;
212+ } else {
213+ if (msblk->swap) {
214+ ((unsigned char *) &temp)[1] = *((unsigned char *)
215+ (bh->b_data + *offset));
216+ ((unsigned char *) &temp)[0] = *((unsigned char *)
217+ (bh->b_data + *offset + 1));
218+ } else {
219+ ((unsigned char *) &temp)[0] = *((unsigned char *)
220+ (bh->b_data + *offset));
221+ ((unsigned char *) &temp)[1] = *((unsigned char *)
222+ (bh->b_data + *offset + 1));
223+ }
224+ *c_byte = temp;
225+ *offset += 2;
226+ }
227+
228+ if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
229+ if (*offset == msblk->devblksize) {
230+ brelse(bh);
231+ if (!(bh = sb_bread(s, ++(*cur_index))))
232+ goto out;
233+ *offset = 0;
234+ }
235+ if (*((unsigned char *) (bh->b_data + *offset)) !=
236+ SQUASHFS_MARKER_BYTE) {
237+ ERROR("Metadata block marker corrupt @ %x\n",
238+ *cur_index);
239+ brelse(bh);
240+ goto out;
241+ }
242+ (*offset)++;
243+ }
244+ return bh;
245+
246+out:
247+ return NULL;
248+}
249+
250+
251+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
252+ long long index, unsigned int length,
253+ long long *next_index, int srclength)
254+{
255+ struct squashfs_sb_info *msblk = s->s_fs_info;
256+ struct squashfs_super_block *sblk = &msblk->sblk;
257+ struct buffer_head **bh;
258+ unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
259+ unsigned int cur_index = index >> msblk->devblksize_log2;
260+ int bytes, avail_bytes, b = 0, k = 0;
261+ unsigned int compressed;
262+ unsigned int c_byte = length;
263+
264+ bh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *
265+ sizeof(struct buffer_head *), GFP_KERNEL);
266+ if (bh == NULL)
267+ goto read_failure;
268+
269+ if (c_byte) {
270+ bytes = msblk->devblksize - offset;
271+ compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
272+ c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
273+
274+ TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index,
275+ compressed ? "" : "un", (unsigned int) c_byte, srclength);
276+
277+ if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
278+ goto read_failure;
279+
280+ bh[0] = sb_getblk(s, cur_index);
281+ if (bh[0] == NULL)
282+ goto block_release;
283+
284+ for (b = 1; bytes < c_byte; b++) {
285+ bh[b] = sb_getblk(s, ++cur_index);
286+ if (bh[b] == NULL)
287+ goto block_release;
288+ bytes += msblk->devblksize;
289+ }
290+ ll_rw_block(READ, b, bh);
291+ } else {
292+ if (index < 0 || (index + 2) > sblk->bytes_used)
293+ goto read_failure;
294+
295+ bh[0] = get_block_length(s, &cur_index, &offset, &c_byte);
296+ if (bh[0] == NULL)
297+ goto read_failure;
298+
299+ bytes = msblk->devblksize - offset;
300+ compressed = SQUASHFS_COMPRESSED(c_byte);
301+ c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
302+
303+ TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
304+ ? "" : "un", (unsigned int) c_byte);
305+
306+ if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
307+ goto read_failure;
308+
309+ for (b = 1; bytes < c_byte; b++) {
310+ bh[b] = sb_getblk(s, ++cur_index);
311+ if (bh[b] == NULL)
312+ goto block_release;
313+ bytes += msblk->devblksize;
314+ }
315+ ll_rw_block(READ, b - 1, bh + 1);
316+ }
317+
318+ if (compressed) {
319+ int zlib_err = 0;
320+
321+ /*
322+ * uncompress block
323+ */
324+
325+ mutex_lock(&msblk->read_data_mutex);
326+
327+ msblk->stream.next_out = buffer;
328+ msblk->stream.avail_out = srclength;
329+
330+ for (bytes = 0; k < b; k++) {
331+ avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
332+
333+ wait_on_buffer(bh[k]);
334+ if (!buffer_uptodate(bh[k]))
335+ goto release_mutex;
336+
337+ msblk->stream.next_in = bh[k]->b_data + offset;
338+ msblk->stream.avail_in = avail_bytes;
339+
340+ if (k == 0) {
341+ zlib_err = zlib_inflateInit(&msblk->stream);
342+ if (zlib_err != Z_OK) {
343+ ERROR("zlib_inflateInit returned unexpected result 0x%x,"
344+ " srclength %d\n", zlib_err, srclength);
345+ goto release_mutex;
346+ }
347+
348+ if (avail_bytes == 0) {
349+ offset = 0;
350+ brelse(bh[k]);
351+ continue;
352+ }
353+ }
354+
355+ zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
356+ if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
357+ ERROR("zlib_inflate returned unexpected result 0x%x,"
358+ " srclength %d, avail_in %d, avail_out %d\n", zlib_err,
359+ srclength, msblk->stream.avail_in, msblk->stream.avail_out);
360+ goto release_mutex;
361+ }
362+
363+ bytes += avail_bytes;
364+ offset = 0;
365+ brelse(bh[k]);
366+ }
367+
368+ if (zlib_err != Z_STREAM_END)
369+ goto release_mutex;
370+
371+ zlib_err = zlib_inflateEnd(&msblk->stream);
372+ if (zlib_err != Z_OK) {
373+ ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
374+ " srclength %d\n", zlib_err, srclength);
375+ goto release_mutex;
376+ }
377+ bytes = msblk->stream.total_out;
378+ mutex_unlock(&msblk->read_data_mutex);
379+ } else {
380+ int i;
381+
382+ for(i = 0; i < b; i++) {
383+ wait_on_buffer(bh[i]);
384+ if (!buffer_uptodate(bh[i]))
385+ goto block_release;
386+ }
387+
388+ for (bytes = 0; k < b; k++) {
389+ avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
390+
391+ memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
392+ bytes += avail_bytes;
393+ offset = 0;
394+ brelse(bh[k]);
395+ }
396+ }
397+
398+ if (next_index)
399+ *next_index = index + c_byte + (length ? 0 :
400+ (SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));
401+
402+ kfree(bh);
403+ return bytes;
404+
405+release_mutex:
406+ mutex_unlock(&msblk->read_data_mutex);
407+
408+block_release:
409+ for (; k < b; k++)
410+ brelse(bh[k]);
411+
412+read_failure:
413+ ERROR("sb_bread failed reading block 0x%x\n", cur_index);
414+ kfree(bh);
415+ return 0;
416+}
417+
418+
419+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,
420+ long long block, unsigned int offset,
421+ int length, long long *next_block,
422+ unsigned int *next_offset)
423+{
424+ struct squashfs_sb_info *msblk = s->s_fs_info;
425+ int n, i, bytes, return_length = length;
426+ long long next_index;
427+
428+ TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
429+
430+ while (1) {
431+ for (i = 0; i < squashfs_cached_blks; i++)
432+ if (msblk->block_cache[i].block == block)
433+ break;
434+
435+ mutex_lock(&msblk->block_cache_mutex);
436+
437+ if (i == squashfs_cached_blks) {
438+ /* read inode header block */
439+ if (msblk->unused_cache_blks == 0) {
440+ mutex_unlock(&msblk->block_cache_mutex);
441+ wait_event(msblk->waitq, msblk->unused_cache_blks);
442+ continue;
443+ }
444+
445+ i = msblk->next_cache;
446+ for (n = 0; n < squashfs_cached_blks; n++) {
447+ if (msblk->block_cache[i].block != SQUASHFS_USED_BLK)
448+ break;
449+ i = (i + 1) % squashfs_cached_blks;
450+ }
451+
452+ msblk->next_cache = (i + 1) % squashfs_cached_blks;
453+
454+ if (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
455+ msblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);
456+ if (msblk->block_cache[i].data == NULL) {
457+ ERROR("Failed to allocate cache block\n");
458+ mutex_unlock(&msblk->block_cache_mutex);
459+ goto out;
460+ }
461+ }
462+
463+ msblk->block_cache[i].block = SQUASHFS_USED_BLK;
464+ msblk->unused_cache_blks --;
465+ mutex_unlock(&msblk->block_cache_mutex);
466+
467+ msblk->block_cache[i].length = squashfs_read_data(s,
468+ msblk->block_cache[i].data, block, 0, &next_index,
469+ SQUASHFS_METADATA_SIZE);
470+
471+ if (msblk->block_cache[i].length == 0) {
472+ ERROR("Unable to read cache block [%llx:%x]\n", block, offset);
473+ mutex_lock(&msblk->block_cache_mutex);
474+ msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
475+ msblk->unused_cache_blks ++;
476+ smp_mb();
477+ vfree(msblk->block_cache[i].data);
478+ wake_up(&msblk->waitq);
479+ mutex_unlock(&msblk->block_cache_mutex);
480+ goto out;
481+ }
482+
483+ mutex_lock(&msblk->block_cache_mutex);
484+ msblk->block_cache[i].block = block;
485+ msblk->block_cache[i].next_index = next_index;
486+ msblk->unused_cache_blks ++;
487+ smp_mb();
488+ wake_up(&msblk->waitq);
489+ TRACE("Read cache block [%llx:%x]\n", block, offset);
490+ }
491+
492+ if (msblk->block_cache[i].block != block) {
493+ mutex_unlock(&msblk->block_cache_mutex);
494+ continue;
495+ }
496+
497+ bytes = msblk->block_cache[i].length - offset;
498+
499+ if (bytes < 1) {
500+ mutex_unlock(&msblk->block_cache_mutex);
501+ goto out;
502+ } else if (bytes >= length) {
503+ if (buffer)
504+ memcpy(buffer, msblk->block_cache[i].data + offset, length);
505+ if (msblk->block_cache[i].length - offset == length) {
506+ *next_block = msblk->block_cache[i].next_index;
507+ *next_offset = 0;
508+ } else {
509+ *next_block = block;
510+ *next_offset = offset + length;
511+ }
512+ mutex_unlock(&msblk->block_cache_mutex);
513+ goto finish;
514+ } else {
515+ if (buffer) {
516+ memcpy(buffer, msblk->block_cache[i].data + offset, bytes);
517+ buffer = (char *) buffer + bytes;
518+ }
519+ block = msblk->block_cache[i].next_index;
520+ mutex_unlock(&msblk->block_cache_mutex);
521+ length -= bytes;
522+ offset = 0;
523+ }
524+ }
525+
526+finish:
527+ return return_length;
528+out:
529+ return 0;
530+}
531+
532+
533+static int get_fragment_location(struct super_block *s, unsigned int fragment,
534+ long long *fragment_start_block,
535+ unsigned int *fragment_size)
536+{
537+ struct squashfs_sb_info *msblk = s->s_fs_info;
538+ long long start_block =
539+ msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
540+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
541+ struct squashfs_fragment_entry fragment_entry;
542+
543+ if (msblk->swap) {
544+ struct squashfs_fragment_entry sfragment_entry;
545+
546+ if (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,
547+ sizeof(sfragment_entry), &start_block, &offset))
548+ goto out;
549+ SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
550+ } else
551+ if (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,
552+ sizeof(fragment_entry), &start_block, &offset))
553+ goto out;
554+
555+ *fragment_start_block = fragment_entry.start_block;
556+ *fragment_size = fragment_entry.size;
557+
558+ return 1;
559+
560+out:
561+ return 0;
562+}
563+
564+
565+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,
566+ struct squashfs_fragment_cache *fragment)
567+{
568+ mutex_lock(&msblk->fragment_mutex);
569+ fragment->locked --;
570+ if (fragment->locked == 0) {
571+ msblk->unused_frag_blks ++;
572+ smp_mb();
573+ wake_up(&msblk->fragment_wait_queue);
574+ }
575+ mutex_unlock(&msblk->fragment_mutex);
576+}
577+
578+
579+SQSH_EXTERN
580+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,
581+ long long start_block, int length)
582+{
583+ int i, n;
584+ struct squashfs_sb_info *msblk = s->s_fs_info;
585+ struct squashfs_super_block *sblk = &msblk->sblk;
586+
587+ while (1) {
588+ mutex_lock(&msblk->fragment_mutex);
589+
590+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
591+ msblk->fragment[i].block != start_block; i++);
592+
593+ if (i == SQUASHFS_CACHED_FRAGMENTS) {
594+ if (msblk->unused_frag_blks == 0) {
595+ mutex_unlock(&msblk->fragment_mutex);
596+ wait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);
597+ continue;
598+ }
599+
600+ i = msblk->next_fragment;
601+ for (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {
602+ if (msblk->fragment[i].locked == 0)
603+ break;
604+ i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;
605+ }
606+
607+ msblk->next_fragment = (msblk->next_fragment + 1) %
608+ SQUASHFS_CACHED_FRAGMENTS;
609+
610+ if (msblk->fragment[i].data == NULL) {
611+ msblk->fragment[i].data = vmalloc(sblk->block_size);
612+ if (msblk->fragment[i].data == NULL) {
613+ ERROR("Failed to allocate fragment cache block\n");
614+ mutex_unlock(&msblk->fragment_mutex);
615+ goto out;
616+ }
617+ }
618+
619+ msblk->unused_frag_blks --;
620+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
621+ msblk->fragment[i].locked = 1;
622+ mutex_unlock(&msblk->fragment_mutex);
623+
624+ msblk->fragment[i].length = squashfs_read_data(s,
625+ msblk->fragment[i].data, start_block, length, NULL,
626+ sblk->block_size);
627+
628+ if (msblk->fragment[i].length == 0) {
629+ ERROR("Unable to read fragment cache block [%llx]\n", start_block);
630+ msblk->fragment[i].locked = 0;
631+ msblk->unused_frag_blks ++;
632+ smp_mb();
633+ wake_up(&msblk->fragment_wait_queue);
634+ goto out;
635+ }
636+
637+ mutex_lock(&msblk->fragment_mutex);
638+ msblk->fragment[i].block = start_block;
639+ TRACE("New fragment %d, start block %lld, locked %d\n",
640+ i, msblk->fragment[i].block, msblk->fragment[i].locked);
641+ mutex_unlock(&msblk->fragment_mutex);
642+ break;
643+ }
644+
645+ if (msblk->fragment[i].locked == 0)
646+ msblk->unused_frag_blks --;
647+ msblk->fragment[i].locked++;
648+ mutex_unlock(&msblk->fragment_mutex);
649+ TRACE("Got fragment %d, start block %lld, locked %d\n", i,
650+ msblk->fragment[i].block, msblk->fragment[i].locked);
651+ break;
652+ }
653+
654+ return &msblk->fragment[i];
655+
656+out:
657+ return NULL;
658+}
659+
660+
661+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
662+ struct squashfs_base_inode_header *inodeb)
663+{
664+ i->i_ino = inodeb->inode_number;
665+ i->i_mtime.tv_sec = inodeb->mtime;
666+ i->i_atime.tv_sec = inodeb->mtime;
667+ i->i_ctime.tv_sec = inodeb->mtime;
668+ i->i_uid = msblk->uid[inodeb->uid];
669+ i->i_mode = inodeb->mode;
670+ i->i_size = 0;
671+
672+ if (inodeb->guid == SQUASHFS_GUIDS)
673+ i->i_gid = i->i_uid;
674+ else
675+ i->i_gid = msblk->guid[inodeb->guid];
676+}
677+
678+
679+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
680+{
681+ struct squashfs_sb_info *msblk = s->s_fs_info;
682+ long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
683+ int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
684+ squashfs_inode_t inode;
685+
686+ TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
687+
688+ if (msblk->swap) {
689+ squashfs_inode_t sinode;
690+
691+ if (!squashfs_get_cached_block(s, &sinode, start, offset,
692+ sizeof(sinode), &start, &offset))
693+ goto out;
694+ SQUASHFS_SWAP_INODE_T((&inode), &sinode);
695+ } else if (!squashfs_get_cached_block(s, &inode, start, offset,
696+ sizeof(inode), &start, &offset))
697+ goto out;
698+
699+ TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
700+
701+ return inode;
702+
703+out:
704+ return SQUASHFS_INVALID_BLK;
705+}
706+
dc4c60aa 707+static struct dentry *squashfs_get_parent(struct dentry *child)
708+{
709+ struct inode *i = child->d_inode;
a3d014de 710+ unsigned long ino = SQUASHFS_I(i)->u.s2.parent_inode;
711+ squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, ino);
712+ struct inode *parent;
dc4c60aa 713+ struct dentry *rv;
714+
715+ TRACE("Entered squashfs_get_parent\n");
716+
a3d014de 717+ if (inode == SQUASHFS_INVALID_BLK)
718+ return ERR_PTR(-EINVAL);
719+
720+ parent = squashfs_iget(i->i_sb, inode, ino);
721+ if (IS_ERR(parent)) {
dc4c60aa 722+ rv = ERR_PTR(-EACCES);
723+ goto out;
724+ }
725+
726+ rv = d_alloc_anon(parent);
727+ if(rv == NULL)
728+ rv = ERR_PTR(-ENOMEM);
729+
730+out:
731+ return rv;
732+}
733+
a3d014de 734+
dc4c60aa 735+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,
736+ squashfs_inode_t inode, unsigned int inode_number)
737+{
738+ struct squashfs_sb_info *msblk = s->s_fs_info;
739+ struct inode *i = iget_locked(s, inode_number);
740+
741+ TRACE("Entered squashfs_iget\n");
a3d014de 742+ if (!i)
743+ return ERR_PTR(-ENOMEM);
dc4c60aa 744+
a3d014de 745+ if (i->i_state & I_NEW) {
dc4c60aa 746+ (msblk->read_inode)(i, inode);
747+ unlock_new_inode(i);
748+ }
749+
750+ return i;
751+}
752+
753+
754+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
755+{
756+ struct super_block *s = i->i_sb;
757+ struct squashfs_sb_info *msblk = s->s_fs_info;
758+ struct squashfs_super_block *sblk = &msblk->sblk;
759+ long long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;
760+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
761+ long long next_block;
762+ unsigned int next_offset;
763+ union squashfs_inode_header id, sid;
764+ struct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;
765+
766+ TRACE("Entered squashfs_read_inode\n");
767+
768+ if (msblk->swap) {
769+ if (!squashfs_get_cached_block(s, sinodeb, block, offset,
770+ sizeof(*sinodeb), &next_block, &next_offset))
771+ goto failed_read;
772+ SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));
773+ } else
774+ if (!squashfs_get_cached_block(s, inodeb, block, offset,
775+ sizeof(*inodeb), &next_block, &next_offset))
776+ goto failed_read;
777+
778+ squashfs_new_inode(msblk, i, inodeb);
779+
780+ switch(inodeb->inode_type) {
781+ case SQUASHFS_FILE_TYPE: {
782+ unsigned int frag_size;
783+ long long frag_blk;
784+ struct squashfs_reg_inode_header *inodep = &id.reg;
785+ struct squashfs_reg_inode_header *sinodep = &sid.reg;
786+
787+ if (msblk->swap) {
788+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
789+ sizeof(*sinodep), &next_block, &next_offset))
790+ goto failed_read;
791+ SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
792+ } else
793+ if (!squashfs_get_cached_block(s, inodep, block, offset,
794+ sizeof(*inodep), &next_block, &next_offset))
795+ goto failed_read;
796+
797+ frag_blk = SQUASHFS_INVALID_BLK;
798+
799+ if (inodep->fragment != SQUASHFS_INVALID_FRAG)
800+ if(!get_fragment_location(s, inodep->fragment, &frag_blk,
801+ &frag_size))
802+ goto failed_read;
803+
804+ i->i_nlink = 1;
805+ i->i_size = inodep->file_size;
806+ i->i_fop = &generic_ro_fops;
807+ i->i_mode |= S_IFREG;
808+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
809+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
810+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
811+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
812+ SQUASHFS_I(i)->start_block = inodep->start_block;
813+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
814+ SQUASHFS_I(i)->offset = next_offset;
815+ i->i_data.a_ops = &squashfs_aops;
816+
817+ TRACE("File inode %x:%x, start_block %llx, "
818+ "block_list_start %llx, offset %x\n",
819+ SQUASHFS_INODE_BLK(inode), offset,
820+ inodep->start_block, next_block,
821+ next_offset);
822+ break;
823+ }
824+ case SQUASHFS_LREG_TYPE: {
825+ unsigned int frag_size;
826+ long long frag_blk;
827+ struct squashfs_lreg_inode_header *inodep = &id.lreg;
828+ struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
829+
830+ if (msblk->swap) {
831+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
832+ sizeof(*sinodep), &next_block, &next_offset))
833+ goto failed_read;
834+ SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
835+ } else
836+ if (!squashfs_get_cached_block(s, inodep, block, offset,
837+ sizeof(*inodep), &next_block, &next_offset))
838+ goto failed_read;
839+
840+ frag_blk = SQUASHFS_INVALID_BLK;
841+
842+ if (inodep->fragment != SQUASHFS_INVALID_FRAG)
843+ if (!get_fragment_location(s, inodep->fragment, &frag_blk,
844+ &frag_size))
845+ goto failed_read;
846+
847+ i->i_nlink = inodep->nlink;
848+ i->i_size = inodep->file_size;
849+ i->i_fop = &generic_ro_fops;
850+ i->i_mode |= S_IFREG;
851+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
852+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
853+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
854+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
855+ SQUASHFS_I(i)->start_block = inodep->start_block;
856+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
857+ SQUASHFS_I(i)->offset = next_offset;
858+ i->i_data.a_ops = &squashfs_aops;
859+
860+ TRACE("File inode %x:%x, start_block %llx, "
861+ "block_list_start %llx, offset %x\n",
862+ SQUASHFS_INODE_BLK(inode), offset,
863+ inodep->start_block, next_block,
864+ next_offset);
865+ break;
866+ }
867+ case SQUASHFS_DIR_TYPE: {
868+ struct squashfs_dir_inode_header *inodep = &id.dir;
869+ struct squashfs_dir_inode_header *sinodep = &sid.dir;
870+
871+ if (msblk->swap) {
872+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
873+ sizeof(*sinodep), &next_block, &next_offset))
874+ goto failed_read;
875+ SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
876+ } else
877+ if (!squashfs_get_cached_block(s, inodep, block, offset,
878+ sizeof(*inodep), &next_block, &next_offset))
879+ goto failed_read;
880+
881+ i->i_nlink = inodep->nlink;
882+ i->i_size = inodep->file_size;
883+ i->i_op = &squashfs_dir_inode_ops;
884+ i->i_fop = &squashfs_dir_ops;
885+ i->i_mode |= S_IFDIR;
886+ SQUASHFS_I(i)->start_block = inodep->start_block;
887+ SQUASHFS_I(i)->offset = inodep->offset;
888+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
889+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
890+
891+ TRACE("Directory inode %x:%x, start_block %x, offset "
892+ "%x\n", SQUASHFS_INODE_BLK(inode),
893+ offset, inodep->start_block,
894+ inodep->offset);
895+ break;
896+ }
897+ case SQUASHFS_LDIR_TYPE: {
898+ struct squashfs_ldir_inode_header *inodep = &id.ldir;
899+ struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
900+
901+ if (msblk->swap) {
902+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
903+ sizeof(*sinodep), &next_block, &next_offset))
904+ goto failed_read;
905+ SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);
906+ } else
907+ if (!squashfs_get_cached_block(s, inodep, block, offset,
908+ sizeof(*inodep), &next_block, &next_offset))
909+ goto failed_read;
910+
911+ i->i_nlink = inodep->nlink;
912+ i->i_size = inodep->file_size;
913+ i->i_op = &squashfs_dir_inode_ops;
914+ i->i_fop = &squashfs_dir_ops;
915+ i->i_mode |= S_IFDIR;
916+ SQUASHFS_I(i)->start_block = inodep->start_block;
917+ SQUASHFS_I(i)->offset = inodep->offset;
918+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
919+ SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
920+ SQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;
921+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
922+
923+ TRACE("Long directory inode %x:%x, start_block %x, offset %x\n",
924+ SQUASHFS_INODE_BLK(inode), offset,
925+ inodep->start_block, inodep->offset);
926+ break;
927+ }
928+ case SQUASHFS_SYMLINK_TYPE: {
929+ struct squashfs_symlink_inode_header *inodep = &id.symlink;
930+ struct squashfs_symlink_inode_header *sinodep = &sid.symlink;
931+
932+ if (msblk->swap) {
933+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
934+ sizeof(*sinodep), &next_block, &next_offset))
935+ goto failed_read;
936+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);
937+ } else
938+ if (!squashfs_get_cached_block(s, inodep, block, offset,
939+ sizeof(*inodep), &next_block, &next_offset))
940+ goto failed_read;
941+
942+ i->i_nlink = inodep->nlink;
943+ i->i_size = inodep->symlink_size;
944+ i->i_op = &page_symlink_inode_operations;
945+ i->i_data.a_ops = &squashfs_symlink_aops;
946+ i->i_mode |= S_IFLNK;
947+ SQUASHFS_I(i)->start_block = next_block;
948+ SQUASHFS_I(i)->offset = next_offset;
949+
950+ TRACE("Symbolic link inode %x:%x, start_block %llx, offset %x\n",
951+ SQUASHFS_INODE_BLK(inode), offset,
952+ next_block, next_offset);
953+ break;
954+ }
955+ case SQUASHFS_BLKDEV_TYPE:
956+ case SQUASHFS_CHRDEV_TYPE: {
957+ struct squashfs_dev_inode_header *inodep = &id.dev;
958+ struct squashfs_dev_inode_header *sinodep = &sid.dev;
959+
960+ if (msblk->swap) {
961+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
962+ sizeof(*sinodep), &next_block, &next_offset))
963+ goto failed_read;
964+ SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
965+ } else
966+ if (!squashfs_get_cached_block(s, inodep, block, offset,
967+ sizeof(*inodep), &next_block, &next_offset))
968+ goto failed_read;
969+
970+ i->i_nlink = inodep->nlink;
971+ i->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?
972+ S_IFCHR : S_IFBLK;
973+ init_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));
974+
975+ TRACE("Device inode %x:%x, rdev %x\n",
976+ SQUASHFS_INODE_BLK(inode), offset, inodep->rdev);
977+ break;
978+ }
979+ case SQUASHFS_FIFO_TYPE:
980+ case SQUASHFS_SOCKET_TYPE: {
981+ struct squashfs_ipc_inode_header *inodep = &id.ipc;
982+ struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
983+
984+ if (msblk->swap) {
985+ if (!squashfs_get_cached_block(s, sinodep, block, offset,
986+ sizeof(*sinodep), &next_block, &next_offset))
987+ goto failed_read;
988+ SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
989+ } else
990+ if (!squashfs_get_cached_block(s, inodep, block, offset,
991+ sizeof(*inodep), &next_block, &next_offset))
992+ goto failed_read;
993+
994+ i->i_nlink = inodep->nlink;
995+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
996+ ? S_IFIFO : S_IFSOCK;
997+ init_special_inode(i, i->i_mode, 0);
998+ break;
999+ }
1000+ default:
1001+ ERROR("Unknown inode type %d in squashfs_iget!\n",
1002+ inodeb->inode_type);
1003+ goto failed_read1;
1004+ }
1005+
1006+ return 1;
1007+
1008+failed_read:
1009+ ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1010+
1011+failed_read1:
1012+ make_bad_inode(i);
1013+ return 0;
1014+}
1015+
1016+
1017+static int read_inode_lookup_table(struct super_block *s)
1018+{
1019+ struct squashfs_sb_info *msblk = s->s_fs_info;
1020+ struct squashfs_super_block *sblk = &msblk->sblk;
1021+ unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1022+
1023+ TRACE("In read_inode_lookup_table, length %d\n", length);
1024+
1025+ /* Allocate inode lookup table */
1026+ msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);
1027+ if (msblk->inode_lookup_table == NULL) {
1028+ ERROR("Failed to allocate inode lookup table\n");
1029+ return 0;
1030+ }
1031+
1032+ if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1033+ sblk->lookup_table_start, length |
1034+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1035+ ERROR("unable to read inode lookup table\n");
1036+ return 0;
1037+ }
1038+
1039+ if (msblk->swap) {
1040+ int i;
1041+ long long block;
1042+
1043+ for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1044+ /* XXX */
1045+ SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1046+ &msblk->inode_lookup_table[i], 1);
1047+ msblk->inode_lookup_table[i] = block;
1048+ }
1049+ }
1050+
1051+ return 1;
1052+}
1053+
1054+
1055+static int read_fragment_index_table(struct super_block *s)
1056+{
1057+ struct squashfs_sb_info *msblk = s->s_fs_info;
1058+ struct squashfs_super_block *sblk = &msblk->sblk;
1059+ unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1060+
1061+ if(length == 0)
1062+ return 1;
1063+
1064+ /* Allocate fragment index table */
1065+ msblk->fragment_index = kmalloc(length, GFP_KERNEL);
1066+ if (msblk->fragment_index == NULL) {
1067+ ERROR("Failed to allocate fragment index table\n");
1068+ return 0;
1069+ }
1070+
1071+ if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1072+ sblk->fragment_table_start, length |
1073+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1074+ ERROR("unable to read fragment index table\n");
1075+ return 0;
1076+ }
1077+
1078+ if (msblk->swap) {
1079+ int i;
1080+ long long fragment;
1081+
1082+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1083+ /* XXX */
1084+ SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1085+ &msblk->fragment_index[i], 1);
1086+ msblk->fragment_index[i] = fragment;
1087+ }
1088+ }
1089+
1090+ return 1;
1091+}
1092+
1093+
1094+static int readahead_metadata(struct super_block *s)
1095+{
1096+ struct squashfs_sb_info *msblk = s->s_fs_info;
1097+ int i;
1098+
1099+ squashfs_cached_blks = SQUASHFS_CACHED_BLKS;
1100+
1101+ /* Init inode_table block pointer array */
1102+ msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1103+ squashfs_cached_blks, GFP_KERNEL);
1104+ if (msblk->block_cache == NULL) {
1105+ ERROR("Failed to allocate block cache\n");
1106+ goto failed;
1107+ }
1108+
1109+ for (i = 0; i < squashfs_cached_blks; i++)
1110+ msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1111+
1112+ msblk->next_cache = 0;
1113+ msblk->unused_cache_blks = squashfs_cached_blks;
1114+
1115+ return 1;
1116+
1117+failed:
1118+ return 0;
1119+}
1120+
1121+
1122+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1123+{
1124+ struct squashfs_super_block *sblk = &msblk->sblk;
1125+
1126+ msblk->read_inode = squashfs_read_inode;
1127+ msblk->read_blocklist = read_blocklist;
1128+ msblk->read_fragment_index_table = read_fragment_index_table;
1129+
1130+ if (sblk->s_major == 1) {
1131+ if (!squashfs_1_0_supported(msblk)) {
1132+ SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1133+ "are unsupported\n");
1134+ SERROR("Please recompile with Squashfs 1.0 support enabled\n");
1135+ return 0;
1136+ }
1137+ } else if (sblk->s_major == 2) {
1138+ if (!squashfs_2_0_supported(msblk)) {
1139+ SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1140+ "are unsupported\n");
1141+ SERROR("Please recompile with Squashfs 2.0 support enabled\n");
1142+ return 0;
1143+ }
1144+ } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1145+ SQUASHFS_MINOR) {
1146+ SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1147+ "filesystem\n", sblk->s_major, sblk->s_minor);
1148+ SERROR("Please update your kernel\n");
1149+ return 0;
1150+ }
1151+
1152+ return 1;
1153+}
1154+
1155+
1156+static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1157+{
1158+ struct squashfs_sb_info *msblk;
1159+ struct squashfs_super_block *sblk;
1160+ int i;
1161+ char b[BDEVNAME_SIZE];
1162+ struct inode *root;
1163+
1164+ TRACE("Entered squashfs_fill_superblock\n");
1165+
1166+ s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1167+ if (s->s_fs_info == NULL) {
1168+ ERROR("Failed to allocate superblock\n");
1169+ goto failure;
1170+ }
1171+ msblk = s->s_fs_info;
1172+
1173+ msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1174+ if (msblk->stream.workspace == NULL) {
1175+ ERROR("Failed to allocate zlib workspace\n");
1176+ goto failure;
1177+ }
1178+ sblk = &msblk->sblk;
1179+
1180+ msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1181+ msblk->devblksize_log2 = ffz(~msblk->devblksize);
1182+
1183+ mutex_init(&msblk->read_data_mutex);
1184+ mutex_init(&msblk->read_page_mutex);
1185+ mutex_init(&msblk->block_cache_mutex);
1186+ mutex_init(&msblk->fragment_mutex);
1187+ mutex_init(&msblk->meta_index_mutex);
1188+
1189+ init_waitqueue_head(&msblk->waitq);
1190+ init_waitqueue_head(&msblk->fragment_wait_queue);
1191+
1192+ /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1193+ * beyond filesystem end. As we're using squashfs_read_data to read sblk here,
1194+ * first set sblk->bytes_used to a useful value */
1195+ sblk->bytes_used = sizeof(struct squashfs_super_block);
1196+ if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1197+ sizeof(struct squashfs_super_block) |
1198+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1199+ SERROR("unable to read superblock\n");
1200+ goto failed_mount;
1201+ }
1202+
1203+ /* Check it is a SQUASHFS superblock */
1204+ if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1205+ if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1206+ struct squashfs_super_block ssblk;
1207+
1208+ WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1209+ bdevname(s->s_bdev, b));
1210+
1211+ SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1212+ memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1213+ msblk->swap = 1;
1214+ } else {
1215+ SERROR("Can't find a SQUASHFS superblock on %s\n",
1216+ bdevname(s->s_bdev, b));
1217+ goto failed_mount;
1218+ }
1219+ }
1220+
1221+ /* Check the MAJOR & MINOR versions */
1222+ if(!supported_squashfs_filesystem(msblk, silent))
1223+ goto failed_mount;
1224+
1225+ /* Check the filesystem does not extend beyond the end of the
1226+ block device */
1227+ if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1228+ goto failed_mount;
1229+
1230+ /* Check the root inode for sanity */
1231+ if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1232+ goto failed_mount;
1233+
1234+ TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1235+ TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)
1236+ ? "un" : "");
1237+ TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1238+ ? "un" : "");
1239+ TRACE("Check data is %spresent in the filesystem\n",
1240+ SQUASHFS_CHECK_DATA(sblk->flags) ? "" : "not ");
1241+ TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1242+ TRACE("Block size %d\n", sblk->block_size);
1243+ TRACE("Number of inodes %d\n", sblk->inodes);
1244+ if (sblk->s_major > 1)
1245+ TRACE("Number of fragments %d\n", sblk->fragments);
1246+ TRACE("Number of uids %d\n", sblk->no_uids);
1247+ TRACE("Number of gids %d\n", sblk->no_guids);
1248+ TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1249+ TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1250+ if (sblk->s_major > 1)
1251+ TRACE("sblk->fragment_table_start %llx\n", sblk->fragment_table_start);
1252+ TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1253+
1254+ s->s_maxbytes = MAX_LFS_FILESIZE;
1255+ s->s_flags |= MS_RDONLY;
1256+ s->s_op = &squashfs_super_ops;
1257+
1258+ if (readahead_metadata(s) == 0)
1259+ goto failed_mount;
1260+
1261+ /* Allocate read_page block */
1262+ msblk->read_page = vmalloc(sblk->block_size);
1263+ if (msblk->read_page == NULL) {
1264+ ERROR("Failed to allocate read_page block\n");
1265+ goto failed_mount;
1266+ }
1267+
1268+ /* Allocate uid and gid tables */
1269+ msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1270+ sizeof(unsigned int), GFP_KERNEL);
1271+ if (msblk->uid == NULL) {
1272+ ERROR("Failed to allocate uid/gid table\n");
1273+ goto failed_mount;
1274+ }
1275+ msblk->guid = msblk->uid + sblk->no_uids;
1276+
1277+ if (msblk->swap) {
1278+ unsigned int suid[sblk->no_uids + sblk->no_guids];
1279+
1280+ if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1281+ ((sblk->no_uids + sblk->no_guids) *
1282+ sizeof(unsigned int)) |
1283+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1284+ ERROR("unable to read uid/gid table\n");
1285+ goto failed_mount;
1286+ }
1287+
1288+ SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1289+ sblk->no_guids), (sizeof(unsigned int) * 8));
1290+ } else
1291+ if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1292+ ((sblk->no_uids + sblk->no_guids) *
1293+ sizeof(unsigned int)) |
1294+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1295+ ERROR("unable to read uid/gid table\n");
1296+ goto failed_mount;
1297+ }
1298+
1299+
1300+ if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1301+ goto allocate_root;
1302+
1303+ msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *
1304+ SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);
1305+ if (msblk->fragment == NULL) {
1306+ ERROR("Failed to allocate fragment block cache\n");
1307+ goto failed_mount;
1308+ }
1309+
1310+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1311+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1312+ }
1313+
1314+ msblk->next_fragment = 0;
1315+ msblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;
1316+
1317+ /* Allocate and read fragment index table */
1318+ if (msblk->read_fragment_index_table(s) == 0)
1319+ goto failed_mount;
1320+
1321+ if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1322+ goto allocate_root;
1323+
1324+ /* Allocate and read inode lookup table */
1325+ if (read_inode_lookup_table(s) == 0)
1326+ goto failed_mount;
1327+
1328+ s->s_op = &squashfs_export_super_ops;
1329+ s->s_export_op = &squashfs_export_ops;
1330+
1331+allocate_root:
1332+ root = new_inode(s);
1333+ if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1334+ goto failed_mount;
1335+ insert_inode_hash(root);
1336+
1337+ s->s_root = d_alloc_root(root);
1338+ if (s->s_root == NULL) {
1339+ ERROR("Root inode create failed\n");
1340+ iput(root);
1341+ goto failed_mount;
1342+ }
1343+
1344+ TRACE("Leaving squashfs_fill_super\n");
1345+ return 0;
1346+
1347+failed_mount:
1348+ kfree(msblk->inode_lookup_table);
1349+ kfree(msblk->fragment_index);
1350+ kfree(msblk->fragment);
1351+ kfree(msblk->uid);
1352+ vfree(msblk->read_page);
1353+ kfree(msblk->block_cache);
1354+ kfree(msblk->fragment_index_2);
1355+ vfree(msblk->stream.workspace);
1356+ kfree(s->s_fs_info);
1357+ s->s_fs_info = NULL;
1358+ return -EINVAL;
1359+
1360+failure:
1361+ return -ENOMEM;
1362+}
1363+
1364+
1365+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1366+{
1367+ struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1368+ struct squashfs_super_block *sblk = &msblk->sblk;
1369+
1370+ TRACE("Entered squashfs_statfs\n");
1371+
1372+ buf->f_type = SQUASHFS_MAGIC;
1373+ buf->f_bsize = sblk->block_size;
1374+ buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1375+ buf->f_bfree = buf->f_bavail = 0;
1376+ buf->f_files = sblk->inodes;
1377+ buf->f_ffree = 0;
1378+ buf->f_namelen = SQUASHFS_NAME_LEN;
1379+
1380+ return 0;
1381+}
1382+
1383+
1384+static int squashfs_symlink_readpage(struct file *file, struct page *page)
1385+{
1386+ struct inode *inode = page->mapping->host;
1387+ int index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;
1388+ long long block = SQUASHFS_I(inode)->start_block;
1389+ int offset = SQUASHFS_I(inode)->offset;
1390+ void *pageaddr = kmap(page);
1391+
1392+ TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1393+ "%llx, offset %x\n", page->index,
1394+ SQUASHFS_I(inode)->start_block,
1395+ SQUASHFS_I(inode)->offset);
1396+
1397+ for (length = 0; length < index; length += bytes) {
1398+ bytes = squashfs_get_cached_block(inode->i_sb, NULL, block,
1399+ offset, PAGE_CACHE_SIZE, &block, &offset);
1400+ if (bytes == 0) {
1401+ ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1402+ goto skip_read;
1403+ }
1404+ }
1405+
1406+ if (length != index) {
1407+ ERROR("(squashfs_symlink_readpage) length != index\n");
1408+ bytes = 0;
1409+ goto skip_read;
1410+ }
1411+
1412+ avail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);
1413+
1414+ bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,
1415+ avail_bytes, &block, &offset);
1416+ if (bytes == 0)
1417+ ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1418+
1419+skip_read:
1420+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1421+ kunmap(page);
1422+ flush_dcache_page(page);
1423+ SetPageUptodate(page);
1424+ unlock_page(page);
1425+
1426+ return 0;
1427+}
1428+
1429+
1430+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1431+{
1432+ struct meta_index *meta = NULL;
1433+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1434+ int i;
1435+
1436+ mutex_lock(&msblk->meta_index_mutex);
1437+
1438+ TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1439+
1440+ if (msblk->meta_index == NULL)
1441+ goto not_allocated;
1442+
1443+ for (i = 0; i < SQUASHFS_META_NUMBER; i ++) {
1444+ if (msblk->meta_index[i].inode_number == inode->i_ino &&
1445+ msblk->meta_index[i].offset >= offset &&
1446+ msblk->meta_index[i].offset <= index &&
1447+ msblk->meta_index[i].locked == 0) {
1448+ TRACE("locate_meta_index: entry %d, offset %d\n", i,
1449+ msblk->meta_index[i].offset);
1450+ meta = &msblk->meta_index[i];
1451+ offset = meta->offset;
1452+ }
1453+ }
1454+
1455+ if (meta)
1456+ meta->locked = 1;
1457+
1458+not_allocated:
1459+ mutex_unlock(&msblk->meta_index_mutex);
1460+
1461+ return meta;
1462+}
1463+
1464+
1465+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1466+{
1467+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1468+ struct meta_index *meta = NULL;
1469+ int i;
1470+
1471+ mutex_lock(&msblk->meta_index_mutex);
1472+
1473+ TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1474+
1475+ if (msblk->meta_index == NULL) {
1476+ msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1477+ SQUASHFS_META_NUMBER, GFP_KERNEL);
1478+ if (msblk->meta_index == NULL) {
1479+ ERROR("Failed to allocate meta_index\n");
1480+ goto failed;
1481+ }
1482+ for (i = 0; i < SQUASHFS_META_NUMBER; i++) {
1483+ msblk->meta_index[i].inode_number = 0;
1484+ msblk->meta_index[i].locked = 0;
1485+ }
1486+ msblk->next_meta_index = 0;
1487+ }
1488+
1489+ for (i = SQUASHFS_META_NUMBER; i &&
1490+ msblk->meta_index[msblk->next_meta_index].locked; i --)
1491+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
1492+ SQUASHFS_META_NUMBER;
1493+
1494+ if (i == 0) {
1495+ TRACE("empty_meta_index: failed!\n");
1496+ goto failed;
1497+ }
1498+
1499+ TRACE("empty_meta_index: returned meta entry %d, %p\n",
1500+ msblk->next_meta_index,
1501+ &msblk->meta_index[msblk->next_meta_index]);
1502+
1503+ meta = &msblk->meta_index[msblk->next_meta_index];
1504+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
1505+ SQUASHFS_META_NUMBER;
1506+
1507+ meta->inode_number = inode->i_ino;
1508+ meta->offset = offset;
1509+ meta->skip = skip;
1510+ meta->entries = 0;
1511+ meta->locked = 1;
1512+
1513+failed:
1514+ mutex_unlock(&msblk->meta_index_mutex);
1515+ return meta;
1516+}
1517+
1518+
1519+void release_meta_index(struct inode *inode, struct meta_index *meta)
1520+{
1521+ meta->locked = 0;
1522+ smp_mb();
1523+}
1524+
1525+
1526+static int read_block_index(struct super_block *s, int blocks, char *block_list,
1527+ long long *start_block, int *offset)
1528+{
1529+ struct squashfs_sb_info *msblk = s->s_fs_info;
1530+ unsigned int *block_listp;
1531+ int block = 0;
1532+
1533+ if (msblk->swap) {
1534+ char sblock_list[blocks << 2];
1535+
1536+ if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1537+ *offset, blocks << 2, start_block, offset)) {
1538+ ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1539+ goto failure;
1540+ }
1541+ SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1542+ ((unsigned int *)sblock_list), blocks);
1543+ } else {
1544+ if (!squashfs_get_cached_block(s, block_list, *start_block,
1545+ *offset, blocks << 2, start_block, offset)) {
1546+ ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1547+ goto failure;
1548+ }
1549+ }
1550+
1551+ for (block_listp = (unsigned int *) block_list; blocks;
1552+ block_listp++, blocks --)
1553+ block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1554+
1555+ return block;
1556+
1557+failure:
1558+ return -1;
1559+}
1560+
1561+
1562+#define SIZE 256
1563+
1564+static inline int calculate_skip(int blocks) {
1565+ int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1566+ return skip >= 7 ? 7 : skip + 1;
1567+}
1568+
1569+
1570+static int get_meta_index(struct inode *inode, int index,
1571+ long long *index_block, int *index_offset,
1572+ long long *data_block, char *block_list)
1573+{
1574+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1575+ struct squashfs_super_block *sblk = &msblk->sblk;
1576+ int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1577+ int offset = 0;
1578+ struct meta_index *meta;
1579+ struct meta_entry *meta_entry;
1580+ long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1581+ int cur_offset = SQUASHFS_I(inode)->offset;
1582+ long long cur_data_block = SQUASHFS_I(inode)->start_block;
1583+ int i;
1584+
1585+ index /= SQUASHFS_META_INDEXES * skip;
1586+
1587+ while (offset < index) {
1588+ meta = locate_meta_index(inode, index, offset + 1);
1589+
1590+ if (meta == NULL) {
1591+ meta = empty_meta_index(inode, offset + 1, skip);
1592+ if (meta == NULL)
1593+ goto all_done;
1594+ } else {
1595+ if(meta->entries == 0)
1596+ goto failed;
1597+ /* XXX */
1598+ offset = index < meta->offset + meta->entries ? index :
1599+ meta->offset + meta->entries - 1;
1600+ /* XXX */
1601+ meta_entry = &meta->meta_entry[offset - meta->offset];
1602+ cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1603+ cur_offset = meta_entry->offset;
1604+ cur_data_block = meta_entry->data_block;
1605+ TRACE("get_meta_index: offset %d, meta->offset %d, "
1606+ "meta->entries %d\n", offset, meta->offset, meta->entries);
1607+ TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1608+ " data_block 0x%llx\n", cur_index_block,
1609+ cur_offset, cur_data_block);
1610+ }
1611+
1612+ for (i = meta->offset + meta->entries; i <= index &&
1613+ i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1614+ int blocks = skip * SQUASHFS_META_INDEXES;
1615+
1616+ while (blocks) {
1617+ int block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;
1618+ int res = read_block_index(inode->i_sb, block, block_list,
1619+ &cur_index_block, &cur_offset);
1620+
1621+ if (res == -1)
1622+ goto failed;
1623+
1624+ cur_data_block += res;
1625+ blocks -= block;
1626+ }
1627+
1628+ meta_entry = &meta->meta_entry[i - meta->offset];
1629+ meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1630+ meta_entry->offset = cur_offset;
1631+ meta_entry->data_block = cur_data_block;
1632+ meta->entries ++;
1633+ offset ++;
1634+ }
1635+
1636+ TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1637+ meta->offset, meta->entries);
1638+
1639+ release_meta_index(inode, meta);
1640+ }
1641+
1642+all_done:
1643+ *index_block = cur_index_block;
1644+ *index_offset = cur_offset;
1645+ *data_block = cur_data_block;
1646+
1647+ return offset * SQUASHFS_META_INDEXES * skip;
1648+
1649+failed:
1650+ release_meta_index(inode, meta);
1651+ return -1;
1652+}
1653+
1654+
1655+static long long read_blocklist(struct inode *inode, int index,
1656+ int readahead_blks, char *block_list,
1657+ unsigned short **block_p, unsigned int *bsize)
1658+{
1659+ long long block_ptr;
1660+ int offset;
1661+ long long block;
1662+ int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1663+ block_list);
1664+
1665+ TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1666+ " 0x%x, block 0x%llx\n", res, index, block_ptr, offset, block);
1667+
1668+ if(res == -1)
1669+ goto failure;
1670+
1671+ index -= res;
1672+
1673+ while (index) {
1674+ int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1675+ int res = read_block_index(inode->i_sb, blocks, block_list,
1676+ &block_ptr, &offset);
1677+ if (res == -1)
1678+ goto failure;
1679+ block += res;
1680+ index -= blocks;
1681+ }
1682+
1683+ if (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)
1684+ goto failure;
1685+ *bsize = *((unsigned int *) block_list);
1686+
1687+ return block;
1688+
1689+failure:
1690+ return 0;
1691+}
1692+
1693+
1694+static int squashfs_readpage(struct file *file, struct page *page)
1695+{
1696+ struct inode *inode = page->mapping->host;
1697+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1698+ struct squashfs_super_block *sblk = &msblk->sblk;
1699+ unsigned char *block_list = NULL;
1700+ long long block;
1701+ unsigned int bsize, i;
1702+ int bytes;
1703+ int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1704+ void *pageaddr;
1705+ struct squashfs_fragment_cache *fragment = NULL;
1706+ char *data_ptr = msblk->read_page;
1707+
1708+ int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1709+ int start_index = page->index & ~mask;
1710+ int end_index = start_index | mask;
1711+ int file_end = i_size_read(inode) >> sblk->block_log;
1712+ int sparse = 0;
1713+
1714+ TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1715+ page->index, SQUASHFS_I(inode)->start_block);
1716+
1717+ if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1718+ PAGE_CACHE_SHIFT))
1719+ goto out;
1720+
1721+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1722+ || index < file_end) {
1723+ block_list = kmalloc(SIZE, GFP_KERNEL);
1724+ if (block_list == NULL) {
1725+ ERROR("Failed to allocate block_list\n");
1726+ goto error_out;
1727+ }
1728+
1729+ block = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);
1730+ if (block == 0)
1731+ goto error_out;
1732+
1733+ if (bsize == 0) { /* hole */
1734+ bytes = index == file_end ?
1735+ (i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;
1736+ sparse = 1;
1737+ } else {
1738+ mutex_lock(&msblk->read_page_mutex);
1739+
1740+ bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1741+ bsize, NULL, sblk->block_size);
1742+
1743+ if (bytes == 0) {
1744+ ERROR("Unable to read page, block %llx, size %x\n", block, bsize);
1745+ mutex_unlock(&msblk->read_page_mutex);
1746+ goto error_out;
1747+ }
1748+ }
1749+ } else {
1750+ fragment = get_cached_fragment(inode->i_sb,
1751+ SQUASHFS_I(inode)-> u.s1.fragment_start_block,
1752+ SQUASHFS_I(inode)->u.s1.fragment_size);
1753+
1754+ if (fragment == NULL) {
1755+ ERROR("Unable to read page, block %llx, size %x\n",
1756+ SQUASHFS_I(inode)->u.s1.fragment_start_block,
1757+ (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1758+ goto error_out;
1759+ }
1760+ bytes = i_size_read(inode) & (sblk->block_size - 1);
1761+ data_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;
1762+ }
1763+
1764+ for (i = start_index; i <= end_index && bytes > 0; i++,
1765+ bytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {
1766+ struct page *push_page;
1767+ int avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);
1768+
1769+ TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
1770+
1771+ push_page = (i == page->index) ? page :
1772+ grab_cache_page_nowait(page->mapping, i);
1773+
1774+ if (!push_page)
1775+ continue;
1776+
1777+ if (PageUptodate(push_page))
1778+ goto skip_page;
1779+
1780+ pageaddr = kmap_atomic(push_page, KM_USER0);
1781+ memcpy(pageaddr, data_ptr, avail);
1782+ memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1783+ kunmap_atomic(pageaddr, KM_USER0);
1784+ flush_dcache_page(push_page);
1785+ SetPageUptodate(push_page);
1786+skip_page:
1787+ unlock_page(push_page);
1788+ if(i != page->index)
1789+ page_cache_release(push_page);
1790+ }
1791+
1792+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1793+ || index < file_end) {
1794+ if (!sparse)
1795+ mutex_unlock(&msblk->read_page_mutex);
1796+ kfree(block_list);
1797+ } else
1798+ release_cached_fragment(msblk, fragment);
1799+
1800+ return 0;
1801+
1802+error_out:
1803+ SetPageError(page);
1804+out:
1805+ pageaddr = kmap_atomic(page, KM_USER0);
1806+ memset(pageaddr, 0, PAGE_CACHE_SIZE);
1807+ kunmap_atomic(pageaddr, KM_USER0);
1808+ flush_dcache_page(page);
1809+ if (!PageError(page))
1810+ SetPageUptodate(page);
1811+ unlock_page(page);
1812+
1813+ kfree(block_list);
1814+ return 0;
1815+}
1816+
1817+
1818+static int get_dir_index_using_offset(struct super_block *s,
1819+ long long *next_block, unsigned int *next_offset,
1820+ long long index_start, unsigned int index_offset, int i_count,
1821+ long long f_pos)
1822+{
1823+ struct squashfs_sb_info *msblk = s->s_fs_info;
1824+ struct squashfs_super_block *sblk = &msblk->sblk;
1825+ int i, length = 0;
1826+ struct squashfs_dir_index index;
1827+
1828+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1829+ i_count, (unsigned int) f_pos);
1830+
1831+ f_pos =- 3;
1832+ if (f_pos == 0)
1833+ goto finish;
1834+
1835+ for (i = 0; i < i_count; i++) {
1836+ if (msblk->swap) {
1837+ struct squashfs_dir_index sindex;
1838+ squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1839+ sizeof(sindex), &index_start, &index_offset);
1840+ SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1841+ } else
1842+ squashfs_get_cached_block(s, &index, index_start, index_offset,
1843+ sizeof(index), &index_start, &index_offset);
1844+
1845+ if (index.index > f_pos)
1846+ break;
1847+
1848+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
1849+ index.size + 1, &index_start, &index_offset);
1850+
1851+ length = index.index;
1852+ *next_block = index.start_block + sblk->directory_table_start;
1853+ }
1854+
1855+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1856+
1857+finish:
1858+ return length + 3;
1859+}
1860+
1861+
1862+static int get_dir_index_using_name(struct super_block *s,
1863+ long long *next_block, unsigned int *next_offset,
1864+ long long index_start, unsigned int index_offset, int i_count,
1865+ const char *name, int size)
1866+{
1867+ struct squashfs_sb_info *msblk = s->s_fs_info;
1868+ struct squashfs_super_block *sblk = &msblk->sblk;
1869+ int i, length = 0;
1870+ struct squashfs_dir_index *index;
1871+ char *str;
1872+
1873+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1874+
1875+ str = kmalloc(sizeof(struct squashfs_dir_index) +
1876+ (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);
1877+ if (str == NULL) {
1878+ ERROR("Failed to allocate squashfs_dir_index\n");
1879+ goto failure;
1880+ }
1881+
1882+ index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1883+ strncpy(str, name, size);
1884+ str[size] = '\0';
1885+
1886+ for (i = 0; i < i_count; i++) {
1887+ if (msblk->swap) {
1888+ struct squashfs_dir_index sindex;
1889+ squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1890+ sizeof(sindex), &index_start, &index_offset);
1891+ SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1892+ } else
1893+ squashfs_get_cached_block(s, index, index_start, index_offset,
1894+ sizeof(struct squashfs_dir_index), &index_start, &index_offset);
1895+
1896+ squashfs_get_cached_block(s, index->name, index_start, index_offset,
1897+ index->size + 1, &index_start, &index_offset);
1898+
1899+ index->name[index->size + 1] = '\0';
1900+
1901+ if (strcmp(index->name, str) > 0)
1902+ break;
1903+
1904+ length = index->index;
1905+ *next_block = index->start_block + sblk->directory_table_start;
1906+ }
1907+
1908+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1909+ kfree(str);
1910+
1911+failure:
1912+ return length + 3;
1913+}
1914+
1915+
1916+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1917+{
1918+ struct inode *i = file->f_dentry->d_inode;
1919+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1920+ struct squashfs_super_block *sblk = &msblk->sblk;
1921+ long long next_block = SQUASHFS_I(i)->start_block +
1922+ sblk->directory_table_start;
1923+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
1924+ struct squashfs_dir_header dirh;
1925+ struct squashfs_dir_entry *dire;
1926+
1927+ TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1928+
1929+ dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1930+ SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
1931+ if (dire == NULL) {
1932+ ERROR("Failed to allocate squashfs_dir_entry\n");
1933+ goto finish;
1934+ }
1935+
1936+ while(file->f_pos < 3) {
1937+ char *name;
1938+ int size, i_ino;
1939+
1940+ if(file->f_pos == 0) {
1941+ name = ".";
1942+ size = 1;
1943+ i_ino = i->i_ino;
1944+ } else {
1945+ name = "..";
1946+ size = 2;
1947+ i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1948+ }
1949+ TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1950+ (unsigned int) dirent, name, size, (int)
1951+ file->f_pos, i_ino, squashfs_filetype_table[1]);
1952+
1953+ if (filldir(dirent, name, size, file->f_pos, i_ino,
1954+ squashfs_filetype_table[1]) < 0) {
1955+ TRACE("Filldir returned less than 0\n");
1956+ goto finish;
1957+ }
1958+ file->f_pos += size;
1959+ }
1960+
1961+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1962+ SQUASHFS_I(i)->u.s2.directory_index_start,
1963+ SQUASHFS_I(i)->u.s2.directory_index_offset,
1964+ SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1965+
1966+ while (length < i_size_read(i)) {
1967+ /* read directory header */
1968+ if (msblk->swap) {
1969+ struct squashfs_dir_header sdirh;
1970+
1971+ if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
1972+ next_offset, sizeof(sdirh), &next_block, &next_offset))
1973+ goto failed_read;
1974+
1975+ length += sizeof(sdirh);
1976+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1977+ } else {
1978+ if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
1979+ next_offset, sizeof(dirh), &next_block, &next_offset))
1980+ goto failed_read;
1981+
1982+ length += sizeof(dirh);
1983+ }
1984+
1985+ dir_count = dirh.count + 1;
1986+ while (dir_count--) {
1987+ if (msblk->swap) {
1988+ struct squashfs_dir_entry sdire;
1989+ if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
1990+ next_offset, sizeof(sdire), &next_block, &next_offset))
1991+ goto failed_read;
1992+
1993+ length += sizeof(sdire);
1994+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1995+ } else {
1996+ if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
1997+ next_offset, sizeof(*dire), &next_block, &next_offset))
1998+ goto failed_read;
1999+
2000+ length += sizeof(*dire);
2001+ }
2002+
2003+ if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2004+ next_offset, dire->size + 1, &next_block, &next_offset))
2005+ goto failed_read;
2006+
2007+ length += dire->size + 1;
2008+
2009+ if (file->f_pos >= length)
2010+ continue;
2011+
2012+ dire->name[dire->size + 1] = '\0';
2013+
2014+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2015+ (unsigned int) dirent, dire->name, dire->size + 1,
2016+ (int) file->f_pos, dirh.start_block, dire->offset,
2017+ dirh.inode_number + dire->inode_number,
2018+ squashfs_filetype_table[dire->type]);
2019+
2020+ if (filldir(dirent, dire->name, dire->size + 1, file->f_pos,
2021+ dirh.inode_number + dire->inode_number,
2022+ squashfs_filetype_table[dire->type]) < 0) {
2023+ TRACE("Filldir returned less than 0\n");
2024+ goto finish;
2025+ }
2026+ file->f_pos = length;
2027+ }
2028+ }
2029+
2030+finish:
2031+ kfree(dire);
2032+ return 0;
2033+
2034+failed_read:
2035+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2036+ next_offset);
2037+ kfree(dire);
2038+ return 0;
2039+}
2040+
2041+
2042+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2043+ struct nameidata *nd)
2044+{
2045+ const unsigned char *name = dentry->d_name.name;
2046+ int len = dentry->d_name.len;
2047+ struct inode *inode = NULL;
2048+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2049+ struct squashfs_super_block *sblk = &msblk->sblk;
2050+ long long next_block = SQUASHFS_I(i)->start_block +
2051+ sblk->directory_table_start;
2052+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
2053+ struct squashfs_dir_header dirh;
2054+ struct squashfs_dir_entry *dire;
2055+
2056+ TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2057+
2058+ dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2059+ SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
2060+ if (dire == NULL) {
2061+ ERROR("Failed to allocate squashfs_dir_entry\n");
2062+ goto exit_lookup;
2063+ }
2064+
2065+ if (len > SQUASHFS_NAME_LEN)
2066+ goto exit_lookup;
2067+
2068+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2069+ SQUASHFS_I(i)->u.s2.directory_index_start,
2070+ SQUASHFS_I(i)->u.s2.directory_index_offset,
2071+ SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
2072+
2073+ while (length < i_size_read(i)) {
2074+ /* read directory header */
2075+ if (msblk->swap) {
2076+ struct squashfs_dir_header sdirh;
2077+ if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
2078+ next_offset, sizeof(sdirh), &next_block, &next_offset))
2079+ goto failed_read;
2080+
2081+ length += sizeof(sdirh);
2082+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2083+ } else {
2084+ if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2085+ next_offset, sizeof(dirh), &next_block, &next_offset))
2086+ goto failed_read;
2087+
2088+ length += sizeof(dirh);
2089+ }
2090+
2091+ dir_count = dirh.count + 1;
2092+ while (dir_count--) {
2093+ if (msblk->swap) {
2094+ struct squashfs_dir_entry sdire;
2095+ if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2096+ next_offset, sizeof(sdire), &next_block, &next_offset))
2097+ goto failed_read;
2098+
2099+ length += sizeof(sdire);
2100+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2101+ } else {
2102+ if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2103+ next_offset, sizeof(*dire), &next_block, &next_offset))
2104+ goto failed_read;
2105+
2106+ length += sizeof(*dire);
2107+ }
2108+
2109+ if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2110+ next_offset, dire->size + 1, &next_block, &next_offset))
2111+ goto failed_read;
2112+
2113+ length += dire->size + 1;
2114+
2115+ if (name[0] < dire->name[0])
2116+ goto exit_lookup;
2117+
2118+ if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2119+ squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2120+ dire->offset);
2121+
2122+ TRACE("calling squashfs_iget for directory entry %s, inode"
2123+ " %x:%x, %d\n", name, dirh.start_block, dire->offset,
2124+ dirh.inode_number + dire->inode_number);
2125+
2126+ inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2127+
2128+ goto exit_lookup;
2129+ }
2130+ }
2131+ }
2132+
2133+exit_lookup:
2134+ kfree(dire);
2135+ if (inode)
2136+ return d_splice_alias(inode, dentry);
2137+ d_add(dentry, inode);
2138+ return ERR_PTR(0);
2139+
2140+failed_read:
2141+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2142+ next_offset);
2143+ goto exit_lookup;
2144+}
2145+
2146+
2147+static int squashfs_remount(struct super_block *s, int *flags, char *data)
2148+{
2149+ *flags |= MS_RDONLY;
2150+ return 0;
2151+}
2152+
2153+
2154+static void squashfs_put_super(struct super_block *s)
2155+{
2156+ int i;
2157+
2158+ if (s->s_fs_info) {
2159+ struct squashfs_sb_info *sbi = s->s_fs_info;
2160+ if (sbi->block_cache)
2161+ for (i = 0; i < squashfs_cached_blks; i++)
2162+ if (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)
2163+ vfree(sbi->block_cache[i].data);
2164+ if (sbi->fragment)
2165+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2166+ vfree(sbi->fragment[i].data);
2167+ kfree(sbi->fragment);
2168+ kfree(sbi->block_cache);
2169+ vfree(sbi->read_page);
2170+ kfree(sbi->uid);
2171+ kfree(sbi->fragment_index);
2172+ kfree(sbi->fragment_index_2);
2173+ kfree(sbi->meta_index);
2174+ vfree(sbi->stream.workspace);
2175+ kfree(s->s_fs_info);
2176+ s->s_fs_info = NULL;
2177+ }
2178+}
2179+
2180+
2181+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2182+ const char *dev_name, void *data, struct vfsmount *mnt)
2183+{
2184+ return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2185+ mnt);
2186+}
2187+
2188+
2189+static int __init init_squashfs_fs(void)
2190+{
2191+ int err = init_inodecache();
2192+ if (err)
2193+ goto out;
2194+
2195+ printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) "
2196+ "Phillip Lougher\n");
2197+
2198+ err = register_filesystem(&squashfs_fs_type);
2199+ if (err)
2200+ destroy_inodecache();
2201+
2202+out:
2203+ return err;
2204+}
2205+
2206+
2207+static void __exit exit_squashfs_fs(void)
2208+{
2209+ unregister_filesystem(&squashfs_fs_type);
2210+ destroy_inodecache();
2211+}
2212+
2213+
2214+static struct kmem_cache * squashfs_inode_cachep;
2215+
2216+
2217+static struct inode *squashfs_alloc_inode(struct super_block *sb)
2218+{
2219+ struct squashfs_inode_info *ei;
2220+ ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2221+ return ei ? &ei->vfs_inode : NULL;
2222+}
2223+
2224+
2225+static void squashfs_destroy_inode(struct inode *inode)
2226+{
2227+ kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2228+}
2229+
2230+
2231+static void init_once(struct kmem_cache *cachep, void *foo)
2232+{
2233+ struct squashfs_inode_info *ei = foo;
2234+
2235+ inode_init_once(&ei->vfs_inode);
2236+}
2237+
2238+
2239+static int __init init_inodecache(void)
2240+{
2241+ squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2242+ sizeof(struct squashfs_inode_info), 0,
2243+ SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);
2244+ if (squashfs_inode_cachep == NULL)
2245+ return -ENOMEM;
2246+ return 0;
2247+}
2248+
2249+
2250+static void destroy_inodecache(void)
2251+{
2252+ kmem_cache_destroy(squashfs_inode_cachep);
2253+}
2254+
2255+
2256+module_init(init_squashfs_fs);
2257+module_exit(exit_squashfs_fs);
2258+MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem");
2259+MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2260+MODULE_LICENSE("GPL");
2261diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/Makefile linux-2.6.24-squashfs3.3/fs/squashfs/Makefile
2262--- linux-2.6.24/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2263+++ linux-2.6.24-squashfs3.3/fs/squashfs/Makefile 2005-11-20 14:31:00.000000000 +0000
2264@@ -0,0 +1,7 @@
2265+#
2266+# Makefile for the linux squashfs routines.
2267+#
2268+
2269+obj-$(CONFIG_SQUASHFS) += squashfs.o
2270+squashfs-y += inode.o
2271+squashfs-y += squashfs2_0.o
2272diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs2_0.c linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c
2273--- linux-2.6.24/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2274+++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c 2007-10-25 00:43:59.000000000 +0100
2275@@ -0,0 +1,740 @@
2276+/*
2277+ * Squashfs - a compressed read only filesystem for Linux
2278+ *
2279+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
2280+ * Phillip Lougher <phillip@lougher.demon.co.uk>
2281+ *
2282+ * This program is free software; you can redistribute it and/or
2283+ * modify it under the terms of the GNU General Public License
2284+ * as published by the Free Software Foundation; either version 2,
2285+ * or (at your option) any later version.
2286+ *
2287+ * This program is distributed in the hope that it will be useful,
2288+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2289+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2290+ * GNU General Public License for more details.
2291+ *
2292+ * You should have received a copy of the GNU General Public License
2293+ * along with this program; if not, write to the Free Software
2294+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2295+ *
2296+ * squashfs2_0.c
2297+ */
2298+
2299+#include <linux/squashfs_fs.h>
2300+#include <linux/module.h>
2301+#include <linux/zlib.h>
2302+#include <linux/fs.h>
2303+#include <linux/squashfs_fs_sb.h>
2304+#include <linux/squashfs_fs_i.h>
2305+
2306+#include "squashfs.h"
2307+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2308+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2309+ struct nameidata *);
2310+
2311+static struct file_operations squashfs_dir_ops_2 = {
2312+ .read = generic_read_dir,
2313+ .readdir = squashfs_readdir_2
2314+};
2315+
2316+static struct inode_operations squashfs_dir_inode_ops_2 = {
2317+ .lookup = squashfs_lookup_2
2318+};
2319+
2320+static unsigned char squashfs_filetype_table[] = {
2321+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2322+};
2323+
2324+static int read_fragment_index_table_2(struct super_block *s)
2325+{
2326+ struct squashfs_sb_info *msblk = s->s_fs_info;
2327+ struct squashfs_super_block *sblk = &msblk->sblk;
2328+
2329+ if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2330+ (sblk->fragments), GFP_KERNEL))) {
2331+ ERROR("Failed to allocate uid/gid table\n");
2332+ return 0;
2333+ }
2334+
2335+ if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2336+ !squashfs_read_data(s, (char *)
2337+ msblk->fragment_index_2,
2338+ sblk->fragment_table_start,
2339+ SQUASHFS_FRAGMENT_INDEX_BYTES_2
2340+ (sblk->fragments) |
2341+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2342+ ERROR("unable to read fragment index table\n");
2343+ return 0;
2344+ }
2345+
2346+ if (msblk->swap) {
2347+ int i;
2348+ unsigned int fragment;
2349+
2350+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2351+ i++) {
2352+ SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2353+ &msblk->fragment_index_2[i], 1);
2354+ msblk->fragment_index_2[i] = fragment;
2355+ }
2356+ }
2357+
2358+ return 1;
2359+}
2360+
2361+
2362+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2363+ long long *fragment_start_block,
2364+ unsigned int *fragment_size)
2365+{
2366+ struct squashfs_sb_info *msblk = s->s_fs_info;
2367+ long long start_block =
2368+ msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2369+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2370+ struct squashfs_fragment_entry_2 fragment_entry;
2371+
2372+ if (msblk->swap) {
2373+ struct squashfs_fragment_entry_2 sfragment_entry;
2374+
2375+ if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2376+ start_block, offset,
2377+ sizeof(sfragment_entry), &start_block,
2378+ &offset))
2379+ goto out;
2380+ SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2381+ } else
2382+ if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2383+ start_block, offset,
2384+ sizeof(fragment_entry), &start_block,
2385+ &offset))
2386+ goto out;
2387+
2388+ *fragment_start_block = fragment_entry.start_block;
2389+ *fragment_size = fragment_entry.size;
2390+
2391+ return 1;
2392+
2393+out:
2394+ return 0;
2395+}
2396+
2397+
2398+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2399+ struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2400+{
2401+ struct squashfs_super_block *sblk = &msblk->sblk;
2402+
2403+ i->i_ino = ino;
2404+ i->i_mtime.tv_sec = sblk->mkfs_time;
2405+ i->i_atime.tv_sec = sblk->mkfs_time;
2406+ i->i_ctime.tv_sec = sblk->mkfs_time;
2407+ i->i_uid = msblk->uid[inodeb->uid];
2408+ i->i_mode = inodeb->mode;
2409+ i->i_nlink = 1;
2410+ i->i_size = 0;
2411+ if (inodeb->guid == SQUASHFS_GUIDS)
2412+ i->i_gid = i->i_uid;
2413+ else
2414+ i->i_gid = msblk->guid[inodeb->guid];
2415+}
2416+
2417+
2418+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2419+{
2420+ struct super_block *s = i->i_sb;
2421+ struct squashfs_sb_info *msblk = s->s_fs_info;
2422+ struct squashfs_super_block *sblk = &msblk->sblk;
2423+ unsigned int block = SQUASHFS_INODE_BLK(inode) +
2424+ sblk->inode_table_start;
2425+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2426+ unsigned int ino = SQUASHFS_MK_VFS_INODE(block -
2427+ sblk->inode_table_start, offset);
2428+ long long next_block;
2429+ unsigned int next_offset;
2430+ union squashfs_inode_header_2 id, sid;
2431+ struct squashfs_base_inode_header_2 *inodeb = &id.base,
2432+ *sinodeb = &sid.base;
2433+
2434+ TRACE("Entered squashfs_read_inode_2\n");
2435+
2436+ if (msblk->swap) {
2437+ if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2438+ offset, sizeof(*sinodeb), &next_block,
2439+ &next_offset))
2440+ goto failed_read;
2441+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2442+ sizeof(*sinodeb));
2443+ } else
2444+ if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2445+ offset, sizeof(*inodeb), &next_block,
2446+ &next_offset))
2447+ goto failed_read;
2448+
2449+ squashfs_new_inode(msblk, i, inodeb, ino);
2450+
2451+ switch(inodeb->inode_type) {
2452+ case SQUASHFS_FILE_TYPE: {
2453+ struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2454+ struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2455+ long long frag_blk;
2456+ unsigned int frag_size = 0;
2457+
2458+ if (msblk->swap) {
2459+ if (!squashfs_get_cached_block(s, (char *)
2460+ sinodep, block, offset,
2461+ sizeof(*sinodep), &next_block,
2462+ &next_offset))
2463+ goto failed_read;
2464+ SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2465+ } else
2466+ if (!squashfs_get_cached_block(s, (char *)
2467+ inodep, block, offset,
2468+ sizeof(*inodep), &next_block,
2469+ &next_offset))
2470+ goto failed_read;
2471+
2472+ frag_blk = SQUASHFS_INVALID_BLK;
2473+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2474+ !get_fragment_location_2(s,
2475+ inodep->fragment, &frag_blk, &frag_size))
2476+ goto failed_read;
2477+
2478+ i->i_size = inodep->file_size;
2479+ i->i_fop = &generic_ro_fops;
2480+ i->i_mode |= S_IFREG;
2481+ i->i_mtime.tv_sec = inodep->mtime;
2482+ i->i_atime.tv_sec = inodep->mtime;
2483+ i->i_ctime.tv_sec = inodep->mtime;
2484+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2485+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2486+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2487+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2488+ SQUASHFS_I(i)->start_block = inodep->start_block;
2489+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2490+ SQUASHFS_I(i)->offset = next_offset;
2491+ i->i_data.a_ops = &squashfs_aops;
2492+
2493+ TRACE("File inode %x:%x, start_block %x, "
2494+ "block_list_start %llx, offset %x\n",
2495+ SQUASHFS_INODE_BLK(inode), offset,
2496+ inodep->start_block, next_block,
2497+ next_offset);
2498+ break;
2499+ }
2500+ case SQUASHFS_DIR_TYPE: {
2501+ struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2502+ struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2503+
2504+ if (msblk->swap) {
2505+ if (!squashfs_get_cached_block(s, (char *)
2506+ sinodep, block, offset,
2507+ sizeof(*sinodep), &next_block,
2508+ &next_offset))
2509+ goto failed_read;
2510+ SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2511+ } else
2512+ if (!squashfs_get_cached_block(s, (char *)
2513+ inodep, block, offset,
2514+ sizeof(*inodep), &next_block,
2515+ &next_offset))
2516+ goto failed_read;
2517+
2518+ i->i_size = inodep->file_size;
2519+ i->i_op = &squashfs_dir_inode_ops_2;
2520+ i->i_fop = &squashfs_dir_ops_2;
2521+ i->i_mode |= S_IFDIR;
2522+ i->i_mtime.tv_sec = inodep->mtime;
2523+ i->i_atime.tv_sec = inodep->mtime;
2524+ i->i_ctime.tv_sec = inodep->mtime;
2525+ SQUASHFS_I(i)->start_block = inodep->start_block;
2526+ SQUASHFS_I(i)->offset = inodep->offset;
2527+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2528+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
2529+
2530+ TRACE("Directory inode %x:%x, start_block %x, offset "
2531+ "%x\n", SQUASHFS_INODE_BLK(inode),
2532+ offset, inodep->start_block,
2533+ inodep->offset);
2534+ break;
2535+ }
2536+ case SQUASHFS_LDIR_TYPE: {
2537+ struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2538+ struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2539+
2540+ if (msblk->swap) {
2541+ if (!squashfs_get_cached_block(s, (char *)
2542+ sinodep, block, offset,
2543+ sizeof(*sinodep), &next_block,
2544+ &next_offset))
2545+ goto failed_read;
2546+ SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2547+ sinodep);
2548+ } else
2549+ if (!squashfs_get_cached_block(s, (char *)
2550+ inodep, block, offset,
2551+ sizeof(*inodep), &next_block,
2552+ &next_offset))
2553+ goto failed_read;
2554+
2555+ i->i_size = inodep->file_size;
2556+ i->i_op = &squashfs_dir_inode_ops_2;
2557+ i->i_fop = &squashfs_dir_ops_2;
2558+ i->i_mode |= S_IFDIR;
2559+ i->i_mtime.tv_sec = inodep->mtime;
2560+ i->i_atime.tv_sec = inodep->mtime;
2561+ i->i_ctime.tv_sec = inodep->mtime;
2562+ SQUASHFS_I(i)->start_block = inodep->start_block;
2563+ SQUASHFS_I(i)->offset = inodep->offset;
2564+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2565+ SQUASHFS_I(i)->u.s2.directory_index_offset =
2566+ next_offset;
2567+ SQUASHFS_I(i)->u.s2.directory_index_count =
2568+ inodep->i_count;
2569+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
2570+
2571+ TRACE("Long directory inode %x:%x, start_block %x, "
2572+ "offset %x\n",
2573+ SQUASHFS_INODE_BLK(inode), offset,
2574+ inodep->start_block, inodep->offset);
2575+ break;
2576+ }
2577+ case SQUASHFS_SYMLINK_TYPE: {
2578+ struct squashfs_symlink_inode_header_2 *inodep =
2579+ &id.symlink;
2580+ struct squashfs_symlink_inode_header_2 *sinodep =
2581+ &sid.symlink;
2582+
2583+ if (msblk->swap) {
2584+ if (!squashfs_get_cached_block(s, (char *)
2585+ sinodep, block, offset,
2586+ sizeof(*sinodep), &next_block,
2587+ &next_offset))
2588+ goto failed_read;
2589+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2590+ sinodep);
2591+ } else
2592+ if (!squashfs_get_cached_block(s, (char *)
2593+ inodep, block, offset,
2594+ sizeof(*inodep), &next_block,
2595+ &next_offset))
2596+ goto failed_read;
2597+
2598+ i->i_size = inodep->symlink_size;
2599+ i->i_op = &page_symlink_inode_operations;
2600+ i->i_data.a_ops = &squashfs_symlink_aops;
2601+ i->i_mode |= S_IFLNK;
2602+ SQUASHFS_I(i)->start_block = next_block;
2603+ SQUASHFS_I(i)->offset = next_offset;
2604+
2605+ TRACE("Symbolic link inode %x:%x, start_block %llx, "
2606+ "offset %x\n",
2607+ SQUASHFS_INODE_BLK(inode), offset,
2608+ next_block, next_offset);
2609+ break;
2610+ }
2611+ case SQUASHFS_BLKDEV_TYPE:
2612+ case SQUASHFS_CHRDEV_TYPE: {
2613+ struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2614+ struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2615+
2616+ if (msblk->swap) {
2617+ if (!squashfs_get_cached_block(s, (char *)
2618+ sinodep, block, offset,
2619+ sizeof(*sinodep), &next_block,
2620+ &next_offset))
2621+ goto failed_read;
2622+ SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2623+ } else
2624+ if (!squashfs_get_cached_block(s, (char *)
2625+ inodep, block, offset,
2626+ sizeof(*inodep), &next_block,
2627+ &next_offset))
2628+ goto failed_read;
2629+
2630+ i->i_mode |= (inodeb->inode_type ==
2631+ SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2632+ S_IFBLK;
2633+ init_special_inode(i, i->i_mode,
2634+ old_decode_dev(inodep->rdev));
2635+
2636+ TRACE("Device inode %x:%x, rdev %x\n",
2637+ SQUASHFS_INODE_BLK(inode), offset,
2638+ inodep->rdev);
2639+ break;
2640+ }
2641+ case SQUASHFS_FIFO_TYPE:
2642+ case SQUASHFS_SOCKET_TYPE: {
2643+
2644+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2645+ ? S_IFIFO : S_IFSOCK;
2646+ init_special_inode(i, i->i_mode, 0);
2647+ break;
2648+ }
2649+ default:
2650+ ERROR("Unknown inode type %d in squashfs_iget!\n",
2651+ inodeb->inode_type);
2652+ goto failed_read1;
2653+ }
2654+
2655+ return 1;
2656+
2657+failed_read:
2658+ ERROR("Unable to read inode [%x:%x]\n", block, offset);
2659+
2660+failed_read1:
2661+ return 0;
2662+}
2663+
2664+
2665+static int get_dir_index_using_offset(struct super_block *s, long long
2666+ *next_block, unsigned int *next_offset,
2667+ long long index_start,
2668+ unsigned int index_offset, int i_count,
2669+ long long f_pos)
2670+{
2671+ struct squashfs_sb_info *msblk = s->s_fs_info;
2672+ struct squashfs_super_block *sblk = &msblk->sblk;
2673+ int i, length = 0;
2674+ struct squashfs_dir_index_2 index;
2675+
2676+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2677+ i_count, (unsigned int) f_pos);
2678+
2679+ if (f_pos == 0)
2680+ goto finish;
2681+
2682+ for (i = 0; i < i_count; i++) {
2683+ if (msblk->swap) {
2684+ struct squashfs_dir_index_2 sindex;
2685+ squashfs_get_cached_block(s, (char *) &sindex,
2686+ index_start, index_offset,
2687+ sizeof(sindex), &index_start,
2688+ &index_offset);
2689+ SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2690+ } else
2691+ squashfs_get_cached_block(s, (char *) &index,
2692+ index_start, index_offset,
2693+ sizeof(index), &index_start,
2694+ &index_offset);
2695+
2696+ if (index.index > f_pos)
2697+ break;
2698+
2699+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
2700+ index.size + 1, &index_start,
2701+ &index_offset);
2702+
2703+ length = index.index;
2704+ *next_block = index.start_block + sblk->directory_table_start;
2705+ }
2706+
2707+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2708+
2709+finish:
2710+ return length;
2711+}
2712+
2713+
2714+static int get_dir_index_using_name(struct super_block *s, long long
2715+ *next_block, unsigned int *next_offset,
2716+ long long index_start,
2717+ unsigned int index_offset, int i_count,
2718+ const char *name, int size)
2719+{
2720+ struct squashfs_sb_info *msblk = s->s_fs_info;
2721+ struct squashfs_super_block *sblk = &msblk->sblk;
2722+ int i, length = 0;
2723+ struct squashfs_dir_index_2 *index;
2724+ char *str;
2725+
2726+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2727+
2728+ if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2729+ (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2730+ ERROR("Failed to allocate squashfs_dir_index\n");
2731+ goto failure;
2732+ }
2733+
2734+ index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2735+ strncpy(str, name, size);
2736+ str[size] = '\0';
2737+
2738+ for (i = 0; i < i_count; i++) {
2739+ if (msblk->swap) {
2740+ struct squashfs_dir_index_2 sindex;
2741+ squashfs_get_cached_block(s, (char *) &sindex,
2742+ index_start, index_offset,
2743+ sizeof(sindex), &index_start,
2744+ &index_offset);
2745+ SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2746+ } else
2747+ squashfs_get_cached_block(s, (char *) index,
2748+ index_start, index_offset,
2749+ sizeof(struct squashfs_dir_index_2),
2750+ &index_start, &index_offset);
2751+
2752+ squashfs_get_cached_block(s, index->name, index_start,
2753+ index_offset, index->size + 1,
2754+ &index_start, &index_offset);
2755+
2756+ index->name[index->size + 1] = '\0';
2757+
2758+ if (strcmp(index->name, str) > 0)
2759+ break;
2760+
2761+ length = index->index;
2762+ *next_block = index->start_block + sblk->directory_table_start;
2763+ }
2764+
2765+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2766+ kfree(str);
2767+failure:
2768+ return length;
2769+}
2770+
2771+
2772+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2773+{
2774+ struct inode *i = file->f_dentry->d_inode;
2775+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2776+ struct squashfs_super_block *sblk = &msblk->sblk;
2777+ long long next_block = SQUASHFS_I(i)->start_block +
2778+ sblk->directory_table_start;
2779+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
2780+ dir_count;
2781+ struct squashfs_dir_header_2 dirh;
2782+ struct squashfs_dir_entry_2 *dire;
2783+
2784+ TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2785+
2786+ if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2787+ SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2788+ ERROR("Failed to allocate squashfs_dir_entry\n");
2789+ goto finish;
2790+ }
2791+
2792+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2793+ SQUASHFS_I(i)->u.s2.directory_index_start,
2794+ SQUASHFS_I(i)->u.s2.directory_index_offset,
2795+ SQUASHFS_I(i)->u.s2.directory_index_count,
2796+ file->f_pos);
2797+
2798+ while (length < i_size_read(i)) {
2799+ /* read directory header */
2800+ if (msblk->swap) {
2801+ struct squashfs_dir_header_2 sdirh;
2802+
2803+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2804+ next_block, next_offset, sizeof(sdirh),
2805+ &next_block, &next_offset))
2806+ goto failed_read;
2807+
2808+ length += sizeof(sdirh);
2809+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2810+ } else {
2811+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2812+ next_block, next_offset, sizeof(dirh),
2813+ &next_block, &next_offset))
2814+ goto failed_read;
2815+
2816+ length += sizeof(dirh);
2817+ }
2818+
2819+ dir_count = dirh.count + 1;
2820+ while (dir_count--) {
2821+ if (msblk->swap) {
2822+ struct squashfs_dir_entry_2 sdire;
2823+ if (!squashfs_get_cached_block(i->i_sb, (char *)
2824+ &sdire, next_block, next_offset,
2825+ sizeof(sdire), &next_block,
2826+ &next_offset))
2827+ goto failed_read;
2828+
2829+ length += sizeof(sdire);
2830+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2831+ } else {
2832+ if (!squashfs_get_cached_block(i->i_sb, (char *)
2833+ dire, next_block, next_offset,
2834+ sizeof(*dire), &next_block,
2835+ &next_offset))
2836+ goto failed_read;
2837+
2838+ length += sizeof(*dire);
2839+ }
2840+
2841+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
2842+ next_block, next_offset,
2843+ dire->size + 1, &next_block,
2844+ &next_offset))
2845+ goto failed_read;
2846+
2847+ length += dire->size + 1;
2848+
2849+ if (file->f_pos >= length)
2850+ continue;
2851+
2852+ dire->name[dire->size + 1] = '\0';
2853+
2854+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2855+ (unsigned int) dirent, dire->name,
2856+ dire->size + 1, (int) file->f_pos,
2857+ dirh.start_block, dire->offset,
2858+ squashfs_filetype_table[dire->type]);
2859+
2860+ if (filldir(dirent, dire->name, dire->size + 1,
2861+ file->f_pos, SQUASHFS_MK_VFS_INODE(
2862+ dirh.start_block, dire->offset),
2863+ squashfs_filetype_table[dire->type])
2864+ < 0) {
2865+ TRACE("Filldir returned less than 0\n");
2866+ goto finish;
2867+ }
2868+ file->f_pos = length;
2869+ }
2870+ }
2871+
2872+finish:
2873+ kfree(dire);
2874+ return 0;
2875+
2876+failed_read:
2877+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2878+ next_offset);
2879+ kfree(dire);
2880+ return 0;
2881+}
2882+
2883+
2884+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2885+ struct nameidata *nd)
2886+{
2887+ const unsigned char *name = dentry->d_name.name;
2888+ int len = dentry->d_name.len;
2889+ struct inode *inode = NULL;
2890+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2891+ struct squashfs_super_block *sblk = &msblk->sblk;
2892+ long long next_block = SQUASHFS_I(i)->start_block +
2893+ sblk->directory_table_start;
2894+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
2895+ dir_count;
2896+ struct squashfs_dir_header_2 dirh;
2897+ struct squashfs_dir_entry_2 *dire;
2898+ int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2899+
2900+ TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2901+
2902+ if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2903+ SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2904+ ERROR("Failed to allocate squashfs_dir_entry\n");
2905+ goto exit_loop;
2906+ }
2907+
2908+ if (len > SQUASHFS_NAME_LEN)
2909+ goto exit_loop;
2910+
2911+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2912+ SQUASHFS_I(i)->u.s2.directory_index_start,
2913+ SQUASHFS_I(i)->u.s2.directory_index_offset,
2914+ SQUASHFS_I(i)->u.s2.directory_index_count, name,
2915+ len);
2916+
2917+ while (length < i_size_read(i)) {
2918+ /* read directory header */
2919+ if (msblk->swap) {
2920+ struct squashfs_dir_header_2 sdirh;
2921+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2922+ next_block, next_offset, sizeof(sdirh),
2923+ &next_block, &next_offset))
2924+ goto failed_read;
2925+
2926+ length += sizeof(sdirh);
2927+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2928+ } else {
2929+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2930+ next_block, next_offset, sizeof(dirh),
2931+ &next_block, &next_offset))
2932+ goto failed_read;
2933+
2934+ length += sizeof(dirh);
2935+ }
2936+
2937+ dir_count = dirh.count + 1;
2938+ while (dir_count--) {
2939+ if (msblk->swap) {
2940+ struct squashfs_dir_entry_2 sdire;
2941+ if (!squashfs_get_cached_block(i->i_sb, (char *)
2942+ &sdire, next_block,next_offset,
2943+ sizeof(sdire), &next_block,
2944+ &next_offset))
2945+ goto failed_read;
2946+
2947+ length += sizeof(sdire);
2948+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2949+ } else {
2950+ if (!squashfs_get_cached_block(i->i_sb, (char *)
2951+ dire, next_block,next_offset,
2952+ sizeof(*dire), &next_block,
2953+ &next_offset))
2954+ goto failed_read;
2955+
2956+ length += sizeof(*dire);
2957+ }
2958+
2959+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
2960+ next_block, next_offset, dire->size + 1,
2961+ &next_block, &next_offset))
2962+ goto failed_read;
2963+
2964+ length += dire->size + 1;
2965+
2966+ if (sorted && name[0] < dire->name[0])
2967+ goto exit_loop;
2968+
2969+ if ((len == dire->size + 1) && !strncmp(name,
2970+ dire->name, len)) {
2971+ squashfs_inode_t ino =
2972+ SQUASHFS_MKINODE(dirh.start_block,
2973+ dire->offset);
2974+ unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
2975+ dire->offset);
2976+
2977+ TRACE("calling squashfs_iget for directory "
2978+ "entry %s, inode %x:%x, %lld\n", name,
2979+ dirh.start_block, dire->offset, ino);
2980+
2981+ inode = squashfs_iget(i->i_sb, ino, inode_number);
2982+
2983+ goto exit_loop;
2984+ }
2985+ }
2986+ }
2987+
2988+exit_loop:
2989+ kfree(dire);
2990+ d_add(dentry, inode);
2991+ return ERR_PTR(0);
2992+
2993+failed_read:
2994+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2995+ next_offset);
2996+ goto exit_loop;
2997+}
2998+
2999+
3000+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3001+{
3002+ struct squashfs_super_block *sblk = &msblk->sblk;
3003+
3004+ msblk->read_inode = squashfs_read_inode_2;
3005+ msblk->read_fragment_index_table = read_fragment_index_table_2;
3006+
3007+ sblk->bytes_used = sblk->bytes_used_2;
3008+ sblk->uid_start = sblk->uid_start_2;
3009+ sblk->guid_start = sblk->guid_start_2;
3010+ sblk->inode_table_start = sblk->inode_table_start_2;
3011+ sblk->directory_table_start = sblk->directory_table_start_2;
3012+ sblk->fragment_table_start = sblk->fragment_table_start_2;
3013+
3014+ return 1;
3015+}
3016diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs.h linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h
3017--- linux-2.6.24/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3018+++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h 2007-08-19 04:23:16.000000000 +0100
3019@@ -0,0 +1,86 @@
3020+/*
3021+ * Squashfs - a compressed read only filesystem for Linux
3022+ *
3023+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3024+ * Phillip Lougher <phillip@lougher.demon.co.uk>
3025+ *
3026+ * This program is free software; you can redistribute it and/or
3027+ * modify it under the terms of the GNU General Public License
3028+ * as published by the Free Software Foundation; either version 2,
3029+ * or (at your option) any later version.
3030+ *
3031+ * This program is distributed in the hope that it will be useful,
3032+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3033+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3034+ * GNU General Public License for more details.
3035+ *
3036+ * You should have received a copy of the GNU General Public License
3037+ * along with this program; if not, write to the Free Software
3038+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3039+ *
3040+ * squashfs.h
3041+ */
3042+
3043+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3044+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3045+#endif
3046+
3047+#ifdef SQUASHFS_TRACE
3048+#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3049+#else
3050+#define TRACE(s, args...) {}
3051+#endif
3052+
3053+#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3054+
3055+#define SERROR(s, args...) do { \
3056+ if (!silent) \
3057+ printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3058+ } while(0)
3059+
3060+#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3061+
3062+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3063+{
3064+ return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3065+}
3066+
3067+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3068+#define SQSH_EXTERN
3069+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3070+ long long index, unsigned int length,
3071+ long long *next_index, int srclength);
3072+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,
3073+ long long block, unsigned int offset,
3074+ int length, long long *next_block,
3075+ unsigned int *next_offset);
3076+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3077+ squashfs_fragment_cache *fragment);
3078+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3079+ *s, long long start_block,
3080+ int length);
3081+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
3082+extern const struct address_space_operations squashfs_symlink_aops;
3083+extern const struct address_space_operations squashfs_aops;
3084+extern struct inode_operations squashfs_dir_inode_ops;
3085+#else
3086+#define SQSH_EXTERN static
3087+#endif
3088+
3089+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3090+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3091+#else
3092+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3093+{
3094+ return 0;
3095+}
3096+#endif
3097+
3098+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3099+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3100+#else
3101+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3102+{
3103+ return 0;
3104+}
3105+#endif
3106diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h
3107--- linux-2.6.24/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3108+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h 2007-11-01 03:50:57.000000000 +0000
3109@@ -0,0 +1,935 @@
3110+#ifndef SQUASHFS_FS
3111+#define SQUASHFS_FS
3112+
3113+/*
3114+ * Squashfs
3115+ *
3116+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3117+ * Phillip Lougher <phillip@lougher.demon.co.uk>
3118+ *
3119+ * This program is free software; you can redistribute it and/or
3120+ * modify it under the terms of the GNU General Public License
3121+ * as published by the Free Software Foundation; either version 2,
3122+ * or (at your option) any later version.
3123+ *
3124+ * This program is distributed in the hope that it will be useful,
3125+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3126+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3127+ * GNU General Public License for more details.
3128+ *
3129+ * You should have received a copy of the GNU General Public License
3130+ * along with this program; if not, write to the Free Software
3131+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3132+ *
3133+ * squashfs_fs.h
3134+ */
3135+
3136+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3137+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3138+#endif
3139+
3140+#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3141+#define SQUASHFS_MAJOR 3
3142+#define SQUASHFS_MINOR 1
3143+#define SQUASHFS_MAGIC 0x73717368
3144+#define SQUASHFS_MAGIC_SWAP 0x68737173
3145+#define SQUASHFS_START 0
3146+
3147+/* size of metadata (inode and directory) blocks */
3148+#define SQUASHFS_METADATA_SIZE 8192
3149+#define SQUASHFS_METADATA_LOG 13
3150+
3151+/* default size of data blocks */
3152+#define SQUASHFS_FILE_SIZE 131072
3153+#define SQUASHFS_FILE_LOG 17
3154+
3155+#define SQUASHFS_FILE_MAX_SIZE 1048576
3156+
3157+/* Max number of uids and gids */
3158+#define SQUASHFS_UIDS 256
3159+#define SQUASHFS_GUIDS 255
3160+
3161+/* Max length of filename (not 255) */
3162+#define SQUASHFS_NAME_LEN 256
3163+
3164+#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3165+#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3166+#define SQUASHFS_INVALID_BLK ((long long) -1)
3167+#define SQUASHFS_USED_BLK ((long long) -2)
3168+
3169+/* Filesystem flags */
3170+#define SQUASHFS_NOI 0
3171+#define SQUASHFS_NOD 1
3172+#define SQUASHFS_CHECK 2
3173+#define SQUASHFS_NOF 3
3174+#define SQUASHFS_NO_FRAG 4
3175+#define SQUASHFS_ALWAYS_FRAG 5
3176+#define SQUASHFS_DUPLICATE 6
3177+#define SQUASHFS_EXPORT 7
3178+
3179+#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3180+
3181+#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3182+ SQUASHFS_NOI)
3183+
3184+#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3185+ SQUASHFS_NOD)
3186+
3187+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3188+ SQUASHFS_NOF)
3189+
3190+#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3191+ SQUASHFS_NO_FRAG)
3192+
3193+#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3194+ SQUASHFS_ALWAYS_FRAG)
3195+
3196+#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3197+ SQUASHFS_DUPLICATE)
3198+
3199+#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3200+ SQUASHFS_EXPORT)
3201+
3202+#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3203+ SQUASHFS_CHECK)
3204+
3205+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3206+ duplicate_checking, exortable) (noi | (nod << 1) | (check_data << 2) \
3207+ | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3208+ (duplicate_checking << 6) | (exportable << 7))
3209+
3210+/* Max number of types and file types */
3211+#define SQUASHFS_DIR_TYPE 1
3212+#define SQUASHFS_FILE_TYPE 2
3213+#define SQUASHFS_SYMLINK_TYPE 3
3214+#define SQUASHFS_BLKDEV_TYPE 4
3215+#define SQUASHFS_CHRDEV_TYPE 5
3216+#define SQUASHFS_FIFO_TYPE 6
3217+#define SQUASHFS_SOCKET_TYPE 7
3218+#define SQUASHFS_LDIR_TYPE 8
3219+#define SQUASHFS_LREG_TYPE 9
3220+
3221+/* 1.0 filesystem type definitions */
3222+#define SQUASHFS_TYPES 5
3223+#define SQUASHFS_IPC_TYPE 0
3224+
3225+/* Flag whether block is compressed or uncompressed, bit is set if block is
3226+ * uncompressed */
3227+#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3228+
3229+#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3230+ (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3231+
3232+#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3233+
3234+#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3235+
3236+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
3237+ ~SQUASHFS_COMPRESSED_BIT_BLOCK)
3238+
3239+#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3240+
3241+/*
3242+ * Inode number ops. Inodes consist of a compressed block number, and an
3243+ * uncompressed offset within that block
3244+ */
3245+#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3246+
3247+#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3248+
3249+#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3250+ << 16) + (B)))
3251+
3252+/* Compute 32 bit VFS inode number from squashfs inode number */
3253+#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3254+ ((b) >> 2) + 1))
3255+/* XXX */
3256+
3257+/* Translate between VFS mode and squashfs mode */
3258+#define SQUASHFS_MODE(a) ((a) & 0xfff)
3259+
3260+/* fragment and fragment table defines */
3261+#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3262+
3263+#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3264+ SQUASHFS_METADATA_SIZE)
3265+
3266+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3267+ SQUASHFS_METADATA_SIZE)
3268+
3269+#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3270+ SQUASHFS_METADATA_SIZE - 1) / \
3271+ SQUASHFS_METADATA_SIZE)
3272+
3273+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3274+ sizeof(long long))
3275+
3276+/* inode lookup table defines */
3277+#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3278+
3279+#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3280+ SQUASHFS_METADATA_SIZE)
3281+
3282+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3283+ SQUASHFS_METADATA_SIZE)
3284+
3285+#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3286+ SQUASHFS_METADATA_SIZE - 1) / \
3287+ SQUASHFS_METADATA_SIZE)
3288+
3289+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3290+ sizeof(long long))
3291+
3292+/* cached data constants for filesystem */
3293+#define SQUASHFS_CACHED_BLKS 8
3294+
3295+#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3296+
3297+#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3298+ (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3299+
3300+#define SQUASHFS_MARKER_BYTE 0xff
3301+
3302+/* meta index cache */
3303+#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3304+#define SQUASHFS_META_ENTRIES 31
3305+#define SQUASHFS_META_NUMBER 8
3306+#define SQUASHFS_SLOTS 4
3307+
3308+struct meta_entry {
3309+ long long data_block;
3310+ unsigned int index_block;
3311+ unsigned short offset;
3312+ unsigned short pad;
3313+};
3314+
3315+struct meta_index {
3316+ unsigned int inode_number;
3317+ unsigned int offset;
3318+ unsigned short entries;
3319+ unsigned short skip;
3320+ unsigned short locked;
3321+ unsigned short pad;
3322+ struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3323+};
3324+
3325+
3326+/*
3327+ * definitions for structures on disk
3328+ */
3329+
3330+typedef long long squashfs_block_t;
3331+typedef long long squashfs_inode_t;
3332+
3333+struct squashfs_super_block {
3334+ unsigned int s_magic;
3335+ unsigned int inodes;
3336+ unsigned int bytes_used_2;
3337+ unsigned int uid_start_2;
3338+ unsigned int guid_start_2;
3339+ unsigned int inode_table_start_2;
3340+ unsigned int directory_table_start_2;
3341+ unsigned int s_major:16;
3342+ unsigned int s_minor:16;
3343+ unsigned int block_size_1:16;
3344+ unsigned int block_log:16;
3345+ unsigned int flags:8;
3346+ unsigned int no_uids:8;
3347+ unsigned int no_guids:8;
3348+ unsigned int mkfs_time /* time of filesystem creation */;
3349+ squashfs_inode_t root_inode;
3350+ unsigned int block_size;
3351+ unsigned int fragments;
3352+ unsigned int fragment_table_start_2;
3353+ long long bytes_used;
3354+ long long uid_start;
3355+ long long guid_start;
3356+ long long inode_table_start;
3357+ long long directory_table_start;
3358+ long long fragment_table_start;
3359+ long long lookup_table_start;
3360+} __attribute__ ((packed));
3361+
3362+struct squashfs_dir_index {
3363+ unsigned int index;
3364+ unsigned int start_block;
3365+ unsigned char size;
3366+ unsigned char name[0];
3367+} __attribute__ ((packed));
3368+
3369+#define SQUASHFS_BASE_INODE_HEADER \
3370+ unsigned int inode_type:4; \
3371+ unsigned int mode:12; \
3372+ unsigned int uid:8; \
3373+ unsigned int guid:8; \
3374+ unsigned int mtime; \
3375+ unsigned int inode_number;
3376+
3377+struct squashfs_base_inode_header {
3378+ SQUASHFS_BASE_INODE_HEADER;
3379+} __attribute__ ((packed));
3380+
3381+struct squashfs_ipc_inode_header {
3382+ SQUASHFS_BASE_INODE_HEADER;
3383+ unsigned int nlink;
3384+} __attribute__ ((packed));
3385+
3386+struct squashfs_dev_inode_header {
3387+ SQUASHFS_BASE_INODE_HEADER;
3388+ unsigned int nlink;
3389+ unsigned short rdev;
3390+} __attribute__ ((packed));
3391+
3392+struct squashfs_symlink_inode_header {
3393+ SQUASHFS_BASE_INODE_HEADER;
3394+ unsigned int nlink;
3395+ unsigned short symlink_size;
3396+ char symlink[0];
3397+} __attribute__ ((packed));
3398+
3399+struct squashfs_reg_inode_header {
3400+ SQUASHFS_BASE_INODE_HEADER;
3401+ squashfs_block_t start_block;
3402+ unsigned int fragment;
3403+ unsigned int offset;
3404+ unsigned int file_size;
3405+ unsigned short block_list[0];
3406+} __attribute__ ((packed));
3407+
3408+struct squashfs_lreg_inode_header {
3409+ SQUASHFS_BASE_INODE_HEADER;
3410+ unsigned int nlink;
3411+ squashfs_block_t start_block;
3412+ unsigned int fragment;
3413+ unsigned int offset;
3414+ long long file_size;
3415+ unsigned short block_list[0];
3416+} __attribute__ ((packed));
3417+
3418+struct squashfs_dir_inode_header {
3419+ SQUASHFS_BASE_INODE_HEADER;
3420+ unsigned int nlink;
3421+ unsigned int file_size:19;
3422+ unsigned int offset:13;
3423+ unsigned int start_block;
3424+ unsigned int parent_inode;
3425+} __attribute__ ((packed));
3426+
3427+struct squashfs_ldir_inode_header {
3428+ SQUASHFS_BASE_INODE_HEADER;
3429+ unsigned int nlink;
3430+ unsigned int file_size:27;
3431+ unsigned int offset:13;
3432+ unsigned int start_block;
3433+ unsigned int i_count:16;
3434+ unsigned int parent_inode;
3435+ struct squashfs_dir_index index[0];
3436+} __attribute__ ((packed));
3437+
3438+union squashfs_inode_header {
3439+ struct squashfs_base_inode_header base;
3440+ struct squashfs_dev_inode_header dev;
3441+ struct squashfs_symlink_inode_header symlink;
3442+ struct squashfs_reg_inode_header reg;
3443+ struct squashfs_lreg_inode_header lreg;
3444+ struct squashfs_dir_inode_header dir;
3445+ struct squashfs_ldir_inode_header ldir;
3446+ struct squashfs_ipc_inode_header ipc;
3447+};
3448+
3449+struct squashfs_dir_entry {
3450+ unsigned int offset:13;
3451+ unsigned int type:3;
3452+ unsigned int size:8;
3453+ int inode_number:16;
3454+ char name[0];
3455+} __attribute__ ((packed));
3456+
3457+struct squashfs_dir_header {
3458+ unsigned int count:8;
3459+ unsigned int start_block;
3460+ unsigned int inode_number;
3461+} __attribute__ ((packed));
3462+
3463+struct squashfs_fragment_entry {
3464+ long long start_block;
3465+ unsigned int size;
3466+ unsigned int pending;
3467+} __attribute__ ((packed));
3468+
3469+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3470+extern int squashfs_uncompress_init(void);
3471+extern int squashfs_uncompress_exit(void);
3472+
3473+/*
3474+ * macros to convert each packed bitfield structure from little endian to big
3475+ * endian and vice versa. These are needed when creating or using a filesystem
3476+ * on a machine with different byte ordering to the target architecture.
3477+ *
3478+ */
3479+
3480+#define SQUASHFS_SWAP_START \
3481+ int bits;\
3482+ int b_pos;\
3483+ unsigned long long val;\
3484+ unsigned char *s;\
3485+ unsigned char *d;
3486+
3487+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3488+ SQUASHFS_SWAP_START\
3489+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3490+ SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3491+ SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3492+ SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3493+ SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3494+ SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3495+ SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3496+ SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3497+ SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3498+ SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3499+ SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3500+ SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3501+ SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3502+ SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3503+ SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3504+ SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3505+ SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3506+ SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3507+ SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3508+ SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3509+ SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3510+ SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3511+ SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3512+ SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3513+ SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3514+ SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3515+ SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3516+}
3517+
3518+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3519+ SQUASHFS_MEMSET(s, d, n);\
3520+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3521+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3522+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3523+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3524+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3525+ SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3526+
3527+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3528+ SQUASHFS_SWAP_START\
3529+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3530+}
3531+
3532+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3533+ SQUASHFS_SWAP_START\
3534+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3535+ sizeof(struct squashfs_ipc_inode_header))\
3536+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3537+}
3538+
3539+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3540+ SQUASHFS_SWAP_START\
3541+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3542+ sizeof(struct squashfs_dev_inode_header)); \
3543+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3544+ SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3545+}
3546+
3547+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3548+ SQUASHFS_SWAP_START\
3549+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550+ sizeof(struct squashfs_symlink_inode_header));\
3551+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552+ SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3553+}
3554+
3555+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3556+ SQUASHFS_SWAP_START\
3557+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3558+ sizeof(struct squashfs_reg_inode_header));\
3559+ SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3560+ SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3561+ SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3562+ SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3563+}
3564+
3565+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3566+ SQUASHFS_SWAP_START\
3567+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3568+ sizeof(struct squashfs_lreg_inode_header));\
3569+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3570+ SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3571+ SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3572+ SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3573+ SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3574+}
3575+
3576+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3577+ SQUASHFS_SWAP_START\
3578+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3579+ sizeof(struct squashfs_dir_inode_header));\
3580+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3581+ SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3582+ SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3583+ SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3584+ SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3585+}
3586+
3587+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3588+ SQUASHFS_SWAP_START\
3589+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3590+ sizeof(struct squashfs_ldir_inode_header));\
3591+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3592+ SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3593+ SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3594+ SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3595+ SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3596+ SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3597+}
3598+
3599+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3600+ SQUASHFS_SWAP_START\
3601+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3602+ SQUASHFS_SWAP((s)->index, d, 0, 32);\
3603+ SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3604+ SQUASHFS_SWAP((s)->size, d, 64, 8);\
3605+}
3606+
3607+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3608+ SQUASHFS_SWAP_START\
3609+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3610+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
3611+ SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3612+ SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3613+}
3614+
3615+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3616+ SQUASHFS_SWAP_START\
3617+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3618+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3619+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
3620+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
3621+ SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3622+}
3623+
3624+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3625+ SQUASHFS_SWAP_START\
3626+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3627+ SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3628+ SQUASHFS_SWAP((s)->size, d, 64, 32);\
3629+}
3630+
3631+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3632+
3633+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3634+ int entry;\
3635+ int bit_position;\
3636+ SQUASHFS_SWAP_START\
3637+ SQUASHFS_MEMSET(s, d, n * 2);\
3638+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3639+ 16)\
3640+ SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3641+}
3642+
3643+#define SQUASHFS_SWAP_INTS(s, d, n) {\
3644+ int entry;\
3645+ int bit_position;\
3646+ SQUASHFS_SWAP_START\
3647+ SQUASHFS_MEMSET(s, d, n * 4);\
3648+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3649+ 32)\
3650+ SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3651+}
3652+
3653+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3654+ int entry;\
3655+ int bit_position;\
3656+ SQUASHFS_SWAP_START\
3657+ SQUASHFS_MEMSET(s, d, n * 8);\
3658+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3659+ 64)\
3660+ SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3661+}
3662+
3663+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3664+ int entry;\
3665+ int bit_position;\
3666+ SQUASHFS_SWAP_START\
3667+ SQUASHFS_MEMSET(s, d, n * bits / 8);\
3668+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3669+ bits)\
3670+ SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3671+}
3672+
3673+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3674+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3675+
3676+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3677+
3678+struct squashfs_base_inode_header_1 {
3679+ unsigned int inode_type:4;
3680+ unsigned int mode:12; /* protection */
3681+ unsigned int uid:4; /* index into uid table */
3682+ unsigned int guid:4; /* index into guid table */
3683+} __attribute__ ((packed));
3684+
3685+struct squashfs_ipc_inode_header_1 {
3686+ unsigned int inode_type:4;
3687+ unsigned int mode:12; /* protection */
3688+ unsigned int uid:4; /* index into uid table */
3689+ unsigned int guid:4; /* index into guid table */
3690+ unsigned int type:4;
3691+ unsigned int offset:4;
3692+} __attribute__ ((packed));
3693+
3694+struct squashfs_dev_inode_header_1 {
3695+ unsigned int inode_type:4;
3696+ unsigned int mode:12; /* protection */
3697+ unsigned int uid:4; /* index into uid table */
3698+ unsigned int guid:4; /* index into guid table */
3699+ unsigned short rdev;
3700+} __attribute__ ((packed));
3701+
3702+struct squashfs_symlink_inode_header_1 {
3703+ unsigned int inode_type:4;
3704+ unsigned int mode:12; /* protection */
3705+ unsigned int uid:4; /* index into uid table */
3706+ unsigned int guid:4; /* index into guid table */
3707+ unsigned short symlink_size;
3708+ char symlink[0];
3709+} __attribute__ ((packed));
3710+
3711+struct squashfs_reg_inode_header_1 {
3712+ unsigned int inode_type:4;
3713+ unsigned int mode:12; /* protection */
3714+ unsigned int uid:4; /* index into uid table */
3715+ unsigned int guid:4; /* index into guid table */
3716+ unsigned int mtime;
3717+ unsigned int start_block;
3718+ unsigned int file_size:32;
3719+ unsigned short block_list[0];
3720+} __attribute__ ((packed));
3721+
3722+struct squashfs_dir_inode_header_1 {
3723+ unsigned int inode_type:4;
3724+ unsigned int mode:12; /* protection */
3725+ unsigned int uid:4; /* index into uid table */
3726+ unsigned int guid:4; /* index into guid table */
3727+ unsigned int file_size:19;
3728+ unsigned int offset:13;
3729+ unsigned int mtime;
3730+ unsigned int start_block:24;
3731+} __attribute__ ((packed));
3732+
3733+union squashfs_inode_header_1 {
3734+ struct squashfs_base_inode_header_1 base;
3735+ struct squashfs_dev_inode_header_1 dev;
3736+ struct squashfs_symlink_inode_header_1 symlink;
3737+ struct squashfs_reg_inode_header_1 reg;
3738+ struct squashfs_dir_inode_header_1 dir;
3739+ struct squashfs_ipc_inode_header_1 ipc;
3740+};
3741+
3742+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3743+ SQUASHFS_MEMSET(s, d, n);\
3744+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3745+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3746+ SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3747+ SQUASHFS_SWAP((s)->guid, d, 20, 4);
3748+
3749+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3750+ SQUASHFS_SWAP_START\
3751+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3752+}
3753+
3754+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3755+ SQUASHFS_SWAP_START\
3756+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3757+ sizeof(struct squashfs_ipc_inode_header_1));\
3758+ SQUASHFS_SWAP((s)->type, d, 24, 4);\
3759+ SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3760+}
3761+
3762+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3763+ SQUASHFS_SWAP_START\
3764+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3765+ sizeof(struct squashfs_dev_inode_header_1));\
3766+ SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3767+}
3768+
3769+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3770+ SQUASHFS_SWAP_START\
3771+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3772+ sizeof(struct squashfs_symlink_inode_header_1));\
3773+ SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3774+}
3775+
3776+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3777+ SQUASHFS_SWAP_START\
3778+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3779+ sizeof(struct squashfs_reg_inode_header_1));\
3780+ SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3781+ SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3782+ SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3783+}
3784+
3785+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3786+ SQUASHFS_SWAP_START\
3787+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3788+ sizeof(struct squashfs_dir_inode_header_1));\
3789+ SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3790+ SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3791+ SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3792+ SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3793+}
3794+
3795+#endif
3796+
3797+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3798+
3799+struct squashfs_dir_index_2 {
3800+ unsigned int index:27;
3801+ unsigned int start_block:29;
3802+ unsigned char size;
3803+ unsigned char name[0];
3804+} __attribute__ ((packed));
3805+
3806+struct squashfs_base_inode_header_2 {
3807+ unsigned int inode_type:4;
3808+ unsigned int mode:12; /* protection */
3809+ unsigned int uid:8; /* index into uid table */
3810+ unsigned int guid:8; /* index into guid table */
3811+} __attribute__ ((packed));
3812+
3813+struct squashfs_ipc_inode_header_2 {
3814+ unsigned int inode_type:4;
3815+ unsigned int mode:12; /* protection */
3816+ unsigned int uid:8; /* index into uid table */
3817+ unsigned int guid:8; /* index into guid table */
3818+} __attribute__ ((packed));
3819+
3820+struct squashfs_dev_inode_header_2 {
3821+ unsigned int inode_type:4;
3822+ unsigned int mode:12; /* protection */
3823+ unsigned int uid:8; /* index into uid table */
3824+ unsigned int guid:8; /* index into guid table */
3825+ unsigned short rdev;
3826+} __attribute__ ((packed));
3827+
3828+struct squashfs_symlink_inode_header_2 {
3829+ unsigned int inode_type:4;
3830+ unsigned int mode:12; /* protection */
3831+ unsigned int uid:8; /* index into uid table */
3832+ unsigned int guid:8; /* index into guid table */
3833+ unsigned short symlink_size;
3834+ char symlink[0];
3835+} __attribute__ ((packed));
3836+
3837+struct squashfs_reg_inode_header_2 {
3838+ unsigned int inode_type:4;
3839+ unsigned int mode:12; /* protection */
3840+ unsigned int uid:8; /* index into uid table */
3841+ unsigned int guid:8; /* index into guid table */
3842+ unsigned int mtime;
3843+ unsigned int start_block;
3844+ unsigned int fragment;
3845+ unsigned int offset;
3846+ unsigned int file_size:32;
3847+ unsigned short block_list[0];
3848+} __attribute__ ((packed));
3849+
3850+struct squashfs_dir_inode_header_2 {
3851+ unsigned int inode_type:4;
3852+ unsigned int mode:12; /* protection */
3853+ unsigned int uid:8; /* index into uid table */
3854+ unsigned int guid:8; /* index into guid table */
3855+ unsigned int file_size:19;
3856+ unsigned int offset:13;
3857+ unsigned int mtime;
3858+ unsigned int start_block:24;
3859+} __attribute__ ((packed));
3860+
3861+struct squashfs_ldir_inode_header_2 {
3862+ unsigned int inode_type:4;
3863+ unsigned int mode:12; /* protection */
3864+ unsigned int uid:8; /* index into uid table */
3865+ unsigned int guid:8; /* index into guid table */
3866+ unsigned int file_size:27;
3867+ unsigned int offset:13;
3868+ unsigned int mtime;
3869+ unsigned int start_block:24;
3870+ unsigned int i_count:16;
3871+ struct squashfs_dir_index_2 index[0];
3872+} __attribute__ ((packed));
3873+
3874+union squashfs_inode_header_2 {
3875+ struct squashfs_base_inode_header_2 base;
3876+ struct squashfs_dev_inode_header_2 dev;
3877+ struct squashfs_symlink_inode_header_2 symlink;
3878+ struct squashfs_reg_inode_header_2 reg;
3879+ struct squashfs_dir_inode_header_2 dir;
3880+ struct squashfs_ldir_inode_header_2 ldir;
3881+ struct squashfs_ipc_inode_header_2 ipc;
3882+};
3883+
3884+struct squashfs_dir_header_2 {
3885+ unsigned int count:8;
3886+ unsigned int start_block:24;
3887+} __attribute__ ((packed));
3888+
3889+struct squashfs_dir_entry_2 {
3890+ unsigned int offset:13;
3891+ unsigned int type:3;
3892+ unsigned int size:8;
3893+ char name[0];
3894+} __attribute__ ((packed));
3895+
3896+struct squashfs_fragment_entry_2 {
3897+ unsigned int start_block;
3898+ unsigned int size;
3899+} __attribute__ ((packed));
3900+
3901+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3902+ SQUASHFS_MEMSET(s, d, n);\
3903+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3904+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3905+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3906+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3907+
3908+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3909+ SQUASHFS_SWAP_START\
3910+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3911+}
3912+
3913+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3914+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3915+
3916+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3917+ SQUASHFS_SWAP_START\
3918+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3919+ sizeof(struct squashfs_dev_inode_header_2)); \
3920+ SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3921+}
3922+
3923+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3924+ SQUASHFS_SWAP_START\
3925+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3926+ sizeof(struct squashfs_symlink_inode_header_2));\
3927+ SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3928+}
3929+
3930+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3931+ SQUASHFS_SWAP_START\
3932+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3933+ sizeof(struct squashfs_reg_inode_header_2));\
3934+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3935+ SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3936+ SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3937+ SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3938+ SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3939+}
3940+
3941+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3942+ SQUASHFS_SWAP_START\
3943+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3944+ sizeof(struct squashfs_dir_inode_header_2));\
3945+ SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3946+ SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3947+ SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3948+ SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3949+}
3950+
3951+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3952+ SQUASHFS_SWAP_START\
3953+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3954+ sizeof(struct squashfs_ldir_inode_header_2));\
3955+ SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3956+ SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3957+ SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3958+ SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3959+ SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3960+}
3961+
3962+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3963+ SQUASHFS_SWAP_START\
3964+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3965+ SQUASHFS_SWAP((s)->index, d, 0, 27);\
3966+ SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3967+ SQUASHFS_SWAP((s)->size, d, 56, 8);\
3968+}
3969+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3970+ SQUASHFS_SWAP_START\
3971+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3972+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
3973+ SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3974+}
3975+
3976+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3977+ SQUASHFS_SWAP_START\
3978+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3979+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3980+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
3981+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
3982+}
3983+
3984+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3985+ SQUASHFS_SWAP_START\
3986+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3987+ SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3988+ SQUASHFS_SWAP((s)->size, d, 32, 32);\
3989+}
3990+
3991+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3992+
3993+/* fragment and fragment table defines */
3994+#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3995+
3996+#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3997+ SQUASHFS_METADATA_SIZE)
3998+
3999+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4000+ SQUASHFS_METADATA_SIZE)
4001+
4002+#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4003+ SQUASHFS_METADATA_SIZE - 1) / \
4004+ SQUASHFS_METADATA_SIZE)
4005+
4006+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4007+ sizeof(int))
4008+
4009+#endif
4010+
4011+#ifdef __KERNEL__
4012+
4013+/*
4014+ * macros used to swap each structure entry, taking into account
4015+ * bitfields and different bitfield placing conventions on differing
4016+ * architectures
4017+ */
4018+
4019+#include <asm/byteorder.h>
4020+
4021+#ifdef __BIG_ENDIAN
4022+ /* convert from little endian to big endian */
4023+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4024+ tbits, b_pos)
4025+#else
4026+ /* convert from big endian to little endian */
4027+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4028+ tbits, 64 - tbits - b_pos)
4029+#endif
4030+
4031+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4032+ b_pos = pos % 8;\
4033+ val = 0;\
4034+ s = (unsigned char *)p + (pos / 8);\
4035+ d = ((unsigned char *) &val) + 7;\
4036+ for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4037+ *d-- = *s++;\
4038+ value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4039+}
4040+
4041+#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4042+
4043+#endif
4044+#endif
4045diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_i.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h
4046--- linux-2.6.24/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4047+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h 2007-08-19 04:24:08.000000000 +0100
4048@@ -0,0 +1,45 @@
4049+#ifndef SQUASHFS_FS_I
4050+#define SQUASHFS_FS_I
4051+/*
4052+ * Squashfs
4053+ *
4054+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4055+ * Phillip Lougher <phillip@lougher.demon.co.uk>
4056+ *
4057+ * This program is free software; you can redistribute it and/or
4058+ * modify it under the terms of the GNU General Public License
4059+ * as published by the Free Software Foundation; either version 2,
4060+ * or (at your option) any later version.
4061+ *
4062+ * This program is distributed in the hope that it will be useful,
4063+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4064+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4065+ * GNU General Public License for more details.
4066+ *
4067+ * You should have received a copy of the GNU General Public License
4068+ * along with this program; if not, write to the Free Software
4069+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4070+ *
4071+ * squashfs_fs_i.h
4072+ */
4073+
4074+struct squashfs_inode_info {
4075+ long long start_block;
4076+ unsigned int offset;
4077+ union {
4078+ struct {
4079+ long long fragment_start_block;
4080+ unsigned int fragment_size;
4081+ unsigned int fragment_offset;
4082+ long long block_list_start;
4083+ } s1;
4084+ struct {
4085+ long long directory_index_start;
4086+ unsigned int directory_index_offset;
4087+ unsigned int directory_index_count;
4088+ unsigned int parent_inode;
4089+ } s2;
4090+ } u;
4091+ struct inode vfs_inode;
4092+};
4093+#endif
4094diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_sb.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h
4095--- linux-2.6.24/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4096+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h 2007-08-19 04:24:26.000000000 +0100
4097@@ -0,0 +1,76 @@
4098+#ifndef SQUASHFS_FS_SB
4099+#define SQUASHFS_FS_SB
4100+/*
4101+ * Squashfs
4102+ *
4103+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4104+ * Phillip Lougher <phillip@lougher.demon.co.uk>
4105+ *
4106+ * This program is free software; you can redistribute it and/or
4107+ * modify it under the terms of the GNU General Public License
4108+ * as published by the Free Software Foundation; either version 2,
4109+ * or (at your option) any later version.
4110+ *
4111+ * This program is distributed in the hope that it will be useful,
4112+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4113+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4114+ * GNU General Public License for more details.
4115+ *
4116+ * You should have received a copy of the GNU General Public License
4117+ * along with this program; if not, write to the Free Software
4118+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4119+ *
4120+ * squashfs_fs_sb.h
4121+ */
4122+
4123+#include <linux/squashfs_fs.h>
4124+
4125+struct squashfs_cache {
4126+ long long block;
4127+ int length;
4128+ long long next_index;
4129+ char *data;
4130+};
4131+
4132+struct squashfs_fragment_cache {
4133+ long long block;
4134+ int length;
4135+ unsigned int locked;
4136+ char *data;
4137+};
4138+
4139+struct squashfs_sb_info {
4140+ struct squashfs_super_block sblk;
4141+ int devblksize;
4142+ int devblksize_log2;
4143+ int swap;
4144+ struct squashfs_cache *block_cache;
4145+ struct squashfs_fragment_cache *fragment;
4146+ int next_cache;
4147+ int next_fragment;
4148+ int next_meta_index;
4149+ unsigned int *uid;
4150+ unsigned int *guid;
4151+ long long *fragment_index;
4152+ unsigned int *fragment_index_2;
4153+ char *read_page;
4154+ struct mutex read_data_mutex;
4155+ struct mutex read_page_mutex;
4156+ struct mutex block_cache_mutex;
4157+ struct mutex fragment_mutex;
4158+ struct mutex meta_index_mutex;
4159+ wait_queue_head_t waitq;
4160+ wait_queue_head_t fragment_wait_queue;
4161+ struct meta_index *meta_index;
4162+ z_stream stream;
4163+ long long *inode_lookup_table;
4164+ int unused_cache_blks;
4165+ int unused_frag_blks;
4166+ int (*read_inode)(struct inode *i, squashfs_inode_t \
4167+ inode);
4168+ long long (*read_blocklist)(struct inode *inode, int \
4169+ index, int readahead_blks, char *block_list, \
4170+ unsigned short **block_p, unsigned int *bsize);
4171+ int (*read_fragment_index_table)(struct super_block *s);
4172+};
4173+#endif
4174diff -x .gitignore -Nurp linux-2.6.24/init/do_mounts_rd.c linux-2.6.24-squashfs3.3/init/do_mounts_rd.c
4175--- linux-2.6.24/init/do_mounts_rd.c 2007-10-25 17:41:49.000000000 +0100
4176+++ linux-2.6.24-squashfs3.3/init/do_mounts_rd.c 2007-11-01 05:06:25.000000000 +0000
4177@@ -5,6 +5,7 @@
4178 #include <linux/ext2_fs.h>
4179 #include <linux/romfs_fs.h>
4180 #include <linux/cramfs_fs.h>
4181+#include <linux/squashfs_fs.h>
4182 #include <linux/initrd.h>
4183 #include <linux/string.h>
4184
4185@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4186 * numbers could not be found.
4187 *
4188 * We currently check for the following magic numbers:
4189+ * squashfs
4190 * minix
4191 * ext2
4192 * romfs
4193@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4194 struct ext2_super_block *ext2sb;
4195 struct romfs_super_block *romfsb;
4196 struct cramfs_super *cramfsb;
4197+ struct squashfs_super_block *squashfsb;
4198 int nblocks = -1;
4199 unsigned char *buf;
4200
4201@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4202 ext2sb = (struct ext2_super_block *) buf;
4203 romfsb = (struct romfs_super_block *) buf;
4204 cramfsb = (struct cramfs_super *) buf;
4205+ squashfsb = (struct squashfs_super_block *) buf;
4206 memset(buf, 0xe5, size);
4207
4208 /*
4209@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4210 goto done;
4211 }
4212
4213+ /* squashfs is at block zero too */
4214+ if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4215+ printk(KERN_NOTICE
4216+ "RAMDISK: squashfs filesystem found at block %d\n",
4217+ start_block);
4218+ if (squashfsb->s_major < 3)
4219+ nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4220+ else
4221+ nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4222+ goto done;
4223+ }
4224+
4225 /*
4226 * Read block 1 to test for minix and ext2 superblock
4227 */
This page took 1.407499 seconds and 4 git commands to generate.