19 #include <linux/module.h>
35 static void *zisofs_zlib_workspace;
43 static loff_t zisofs_uncompress_block(
struct inode *
inode, loff_t block_start,
44 loff_t block_end,
int pcount,
48 unsigned int zisofs_block_shift = ISOFS_I(inode)->i_format_parm[1];
51 unsigned int bufmask = bufsize - 1;
57 int needblocks = (block_size + (block_start & bufmask) + bufmask)
61 struct buffer_head *bhs[needblocks + 1];
64 if (block_size > deflateBound(1
UL << zisofs_block_shift)) {
69 if (block_size == 0) {
70 for ( i = 0 ; i < pcount ; i++ ) {
75 SetPageUptodate(pages[i]);
81 blocknum = block_start >> bufshift;
82 memset(bhs, 0, (needblocks + 1) *
sizeof(
struct buffer_head *));
98 wait_on_buffer(bhs[0]);
99 if (!buffer_uptodate(bhs[0])) {
104 stream.
workspace = zisofs_zlib_workspace;
118 while (curpage < pcount && curbh < haveblocks &&
121 if (pages[curpage]) {
127 stream.
next_out = (
void *)&zisofs_sink_page;
132 wait_on_buffer(bhs[curbh]);
133 if (!buffer_uptodate(bhs[curbh])) {
137 stream.
next_in = bhs[curbh]->b_data +
138 (block_start & bufmask);
140 (block_start & bufmask),
158 "zisofs: zisofs_inflate returned"
160 " page idx = %d, bh idx = %d,"
163 zerr, inode->
i_ino, curpage,
174 if (pages[curpage]) {
176 SetPageUptodate(pages[curpage]);
190 for (i = 0; i < haveblocks; i++)
199 static int zisofs_fill_pages(
struct inode *inode,
int full_page,
int pcount,
202 loff_t start_off, end_off;
203 loff_t block_start, block_end;
204 unsigned int header_size = ISOFS_I(inode)->i_format_parm[0];
205 unsigned int zisofs_block_shift = ISOFS_I(inode)->i_format_parm[1];
209 struct buffer_head *bh;
211 unsigned int blksize = 1 << blkbits;
215 BUG_ON(!pages[full_page]);
225 cstart_block = start_off >> zisofs_block_shift;
226 cend_block = (end_off + (1 << zisofs_block_shift) - 1)
227 >> zisofs_block_shift;
235 blockptr = (header_size + cstart_block) << 2;
240 (bh->b_data + (blockptr & (blksize - 1))));
242 while (cstart_block < cend_block && pcount > 0) {
246 if (!(blockptr & (blksize - 1))) {
254 (bh->b_data + (blockptr & (blksize - 1))));
255 if (block_start > block_end) {
260 ret = zisofs_uncompress_block(inode, block_start, block_end,
261 pcount, pages, poffset, &err);
279 block_start = block_end;
283 if (poffset && *pages) {
287 SetPageUptodate(*pages);
299 struct inode *inode = file->
f_path.dentry->d_inode;
302 int i, pcount, full_page;
303 unsigned int zisofs_block_shift = ISOFS_I(inode)->i_format_parm[1];
304 unsigned int zisofs_pages_per_cblock =
305 PAGE_CACHE_SHIFT <= zisofs_block_shift ?
307 struct page *pages[
max_t(
unsigned, zisofs_pages_per_cblock, 1)];
315 if (index >= end_index) {
316 SetPageUptodate(page);
321 if (PAGE_CACHE_SHIFT <= zisofs_block_shift) {
324 full_page = index & (zisofs_pages_per_cblock - 1);
325 pcount =
min_t(
int, zisofs_pages_per_cblock,
326 end_index - (index & ~(zisofs_pages_per_cblock - 1)));
332 pages[full_page] =
page;
334 for (i = 0; i < pcount; i++, index++) {
338 ClearPageError(pages[i]);
343 err = zisofs_fill_pages(inode, full_page, pcount, pages);
346 for (i = 0; i < pcount; i++) {
349 if (i == full_page && err)
350 SetPageError(pages[i]);
363 .readpage = zisofs_readpage,
371 if ( !zisofs_zlib_workspace )
379 vfree(zisofs_zlib_workspace);