45 #include <linux/kernel.h>
46 #include <linux/slab.h>
47 #include <linux/string.h>
69 TRACE(
"locate_meta_index: index %d, offset %d\n", index, offset);
79 TRACE(
"locate_meta_index: entry %d, offset %d\n", i,
99 static struct meta_index *empty_meta_index(
struct inode *inode,
int offset,
108 TRACE(
"empty_meta_index: offset %d, skip %d\n", offset, skip);
117 msblk->
meta_index = kcalloc(SQUASHFS_META_SLOTS,
120 ERROR(
"Failed to allocate meta_index\n");
130 for (i = SQUASHFS_META_SLOTS; i &&
136 TRACE(
"empty_meta_index: failed!\n");
140 TRACE(
"empty_meta_index: returned meta entry %d, %p\n",
160 static void release_meta_index(
struct inode *inode,
struct meta_index *meta)
181 ERROR(
"read_indexes: Failed to allocate block_list\n");
189 offset, blocks << 2);
191 ERROR(
"read_indexes: reading block [%llx:%x]\n",
192 *start_block, *offset);
196 for (i = 0; i < blocks; i++) {
223 static inline int calculate_skip(
int blocks)
236 static int fill_meta_index(
struct inode *inode,
int index,
237 u64 *index_block,
int *index_offset,
u64 *data_block)
240 int skip = calculate_skip(i_size_read(inode) >> msblk->
block_log);
244 u64 cur_index_block = squashfs_i(inode)->block_list_start;
245 int cur_offset = squashfs_i(inode)->
offset;
246 u64 cur_data_block = squashfs_i(inode)->start;
254 while (offset < index) {
255 meta = locate_meta_index(inode, offset + 1, index);
258 meta = empty_meta_index(inode, offset + 1, skip);
267 cur_offset = meta_entry->
offset;
269 TRACE(
"get_meta_index: offset %d, meta->offset %d, "
270 "meta->entries %d\n", offset, meta->
offset,
272 TRACE(
"get_meta_index: index_block 0x%llx, offset 0x%x"
273 " data_block 0x%llx\n", cur_index_block,
274 cur_offset, cur_data_block);
285 long long res = read_indexes(inode->
i_sb, blocks,
286 &cur_index_block, &cur_offset);
299 cur_data_block +=
res;
303 meta_entry->
offset = cur_offset;
309 TRACE(
"get_meta_index: meta->offset %d, meta->entries %d\n",
312 release_meta_index(inode, meta);
316 *index_block = cur_index_block;
317 *index_offset = cur_offset;
318 *data_block = cur_data_block;
323 return offset * SQUASHFS_META_INDEXES *
skip;
326 release_meta_index(inode, meta);
335 static int read_blocklist(
struct inode *inode,
int index,
u64 *block)
341 int res = fill_meta_index(inode, index, &start, &offset, block);
343 TRACE(
"read_blocklist: res %d, index %d, start 0x%llx, offset"
344 " 0x%x, block 0x%llx\n", res, index, start, offset,
357 blks = read_indexes(inode->
i_sb, index - res, &start, &offset);
376 struct inode *inode = page->
mapping->host;
378 int bytes,
i, offset = 0, sparse = 0;
384 int start_index = page->
index & ~mask;
385 int end_index = start_index |
mask;
386 int file_end = i_size_read(inode) >> msblk->
block_log;
388 TRACE(
"Entered squashfs_readpage, page index %lx, start block %llx\n",
389 page->
index, squashfs_i(inode)->start);
395 if (index < file_end || squashfs_i(inode)->fragment_block ==
402 int bsize = read_blocklist(inode, index, &block);
407 bytes = index == file_end ?
408 (i_size_read(inode) & (msblk->
block_size - 1)) :
418 ERROR(
"Unable to read page, block %llx, size %x"
431 squashfs_i(inode)->fragment_block,
432 squashfs_i(inode)->fragment_size);
435 ERROR(
"Unable to read page, block %llx, size %x\n",
436 squashfs_i(inode)->fragment_block,
437 squashfs_i(inode)->fragment_size);
441 bytes = i_size_read(inode) & (msblk->
block_size - 1);
442 offset = squashfs_i(inode)->fragment_offset;
451 for (i = start_index; i <= end_index && bytes > 0; i++,
453 struct page *push_page;
456 TRACE(
"bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
458 push_page = (i == page->
index) ? page :
464 if (PageUptodate(push_page))
472 SetPageUptodate(push_page);
475 if (i != page->
index)
491 if (!PageError(page))
492 SetPageUptodate(page);
500 .readpage = squashfs_readpage