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