source: clfs-embedded/patches/linux-2.6.20-squashfs-1.patch@ 3a7d23b

Last change on this file since 3a7d23b was 5956516, checked in by Jim Gifford <clfs@…>, 18 years ago

Started Updating for 2.6.20

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