提交 846b730e 编写于 作者: P Phillip Lougher

Squashfs: Generalise paging handling in the decompressors

Further generalise the decompressors by adding a page handler
abstraction.  This adds helpers to allow the decompressors
to access and process the output buffers in an implementation
independant manner.

This allows different types of output buffer to be passed
to the decompressors, with the implementation specific
aspects handled at decompression time, but without the
knowledge being held in the decompressor wrapper code.

This will allow the decompressors to handle Squashfs
cache buffers, and page cache pages.

This patch adds the abstraction and an implementation for
the caches.
Signed-off-by: NPhillip Lougher <phillip@squashfs.org.uk>
Reviewed-by: NMinchan Kim <minchan@kernel.org>
上级 d208383d
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "squashfs.h" #include "squashfs.h"
#include "decompressor.h" #include "decompressor.h"
#include "page_actor.h"
/* /*
* Read the metadata block length, this is stored in the first two * Read the metadata block length, this is stored in the first two
...@@ -86,16 +87,16 @@ static struct buffer_head *get_block_length(struct super_block *sb, ...@@ -86,16 +87,16 @@ static struct buffer_head *get_block_length(struct super_block *sb,
* generated a larger block - this does occasionally happen with compression * generated a larger block - this does occasionally happen with compression
* algorithms). * algorithms).
*/ */
int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, int squashfs_read_data(struct super_block *sb, u64 index, int length,
int length, u64 *next_index, int srclength, int pages) u64 *next_index, struct squashfs_page_actor *output)
{ {
struct squashfs_sb_info *msblk = sb->s_fs_info; struct squashfs_sb_info *msblk = sb->s_fs_info;
struct buffer_head **bh; struct buffer_head **bh;
int offset = index & ((1 << msblk->devblksize_log2) - 1); int offset = index & ((1 << msblk->devblksize_log2) - 1);
u64 cur_index = index >> msblk->devblksize_log2; u64 cur_index = index >> msblk->devblksize_log2;
int bytes, compressed, b = 0, k = 0, page = 0, avail, i; int bytes, compressed, b = 0, k = 0, avail, i;
bh = kcalloc(((srclength + msblk->devblksize - 1) bh = kcalloc(((output->length + msblk->devblksize - 1)
>> msblk->devblksize_log2) + 1, sizeof(*bh), GFP_KERNEL); >> msblk->devblksize_log2) + 1, sizeof(*bh), GFP_KERNEL);
if (bh == NULL) if (bh == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -111,9 +112,9 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, ...@@ -111,9 +112,9 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
*next_index = index + length; *next_index = index + length;
TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n",
index, compressed ? "" : "un", length, srclength); index, compressed ? "" : "un", length, output->length);
if (length < 0 || length > srclength || if (length < 0 || length > output->length ||
(index + length) > msblk->bytes_used) (index + length) > msblk->bytes_used)
goto read_failure; goto read_failure;
...@@ -145,7 +146,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, ...@@ -145,7 +146,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
TRACE("Block @ 0x%llx, %scompressed size %d\n", index, TRACE("Block @ 0x%llx, %scompressed size %d\n", index,
compressed ? "" : "un", length); compressed ? "" : "un", length);
if (length < 0 || length > srclength || if (length < 0 || length > output->length ||
(index + length) > msblk->bytes_used) (index + length) > msblk->bytes_used)
goto block_release; goto block_release;
...@@ -165,8 +166,8 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, ...@@ -165,8 +166,8 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
} }
if (compressed) { if (compressed) {
length = squashfs_decompress(msblk, buffer, bh, b, offset, length = squashfs_decompress(msblk, bh, b, offset, length,
length, srclength, pages); output);
if (length < 0) if (length < 0)
goto read_failure; goto read_failure;
} else { } else {
...@@ -174,19 +175,20 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, ...@@ -174,19 +175,20 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
* Block is uncompressed. * Block is uncompressed.
*/ */
int in, pg_offset = 0; int in, pg_offset = 0;
void *data = squashfs_first_page(output);
for (bytes = length; k < b; k++) { for (bytes = length; k < b; k++) {
in = min(bytes, msblk->devblksize - offset); in = min(bytes, msblk->devblksize - offset);
bytes -= in; bytes -= in;
while (in) { while (in) {
if (pg_offset == PAGE_CACHE_SIZE) { if (pg_offset == PAGE_CACHE_SIZE) {
page++; data = squashfs_next_page(output);
pg_offset = 0; pg_offset = 0;
} }
avail = min_t(int, in, PAGE_CACHE_SIZE - avail = min_t(int, in, PAGE_CACHE_SIZE -
pg_offset); pg_offset);
memcpy(buffer[page] + pg_offset, memcpy(data + pg_offset, bh[k]->b_data + offset,
bh[k]->b_data + offset, avail); avail);
in -= avail; in -= avail;
pg_offset += avail; pg_offset += avail;
offset += avail; offset += avail;
...@@ -194,6 +196,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, ...@@ -194,6 +196,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
offset = 0; offset = 0;
put_bh(bh[k]); put_bh(bh[k]);
} }
squashfs_finish_page(output);
} }
kfree(bh); kfree(bh);
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "squashfs_fs.h" #include "squashfs_fs.h"
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "squashfs.h" #include "squashfs.h"
#include "page_actor.h"
/* /*
* Look-up block in cache, and increment usage count. If not in cache, read * Look-up block in cache, and increment usage count. If not in cache, read
...@@ -119,9 +120,8 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb, ...@@ -119,9 +120,8 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
entry->error = 0; entry->error = 0;
spin_unlock(&cache->lock); spin_unlock(&cache->lock);
entry->length = squashfs_read_data(sb, entry->data, entry->length = squashfs_read_data(sb, block, length,
block, length, &entry->next_index, &entry->next_index, entry->actor);
cache->block_size, cache->pages);
spin_lock(&cache->lock); spin_lock(&cache->lock);
...@@ -220,6 +220,7 @@ void squashfs_cache_delete(struct squashfs_cache *cache) ...@@ -220,6 +220,7 @@ void squashfs_cache_delete(struct squashfs_cache *cache)
kfree(cache->entry[i].data[j]); kfree(cache->entry[i].data[j]);
kfree(cache->entry[i].data); kfree(cache->entry[i].data);
} }
kfree(cache->entry[i].actor);
} }
kfree(cache->entry); kfree(cache->entry);
...@@ -280,6 +281,13 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries, ...@@ -280,6 +281,13 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
goto cleanup; goto cleanup;
} }
} }
entry->actor = squashfs_page_actor_init(entry->data,
cache->pages, 0);
if (entry->actor == NULL) {
ERROR("Failed to allocate %s cache entry\n", name);
goto cleanup;
}
} }
return cache; return cache;
...@@ -410,6 +418,7 @@ void *squashfs_read_table(struct super_block *sb, u64 block, int length) ...@@ -410,6 +418,7 @@ void *squashfs_read_table(struct super_block *sb, u64 block, int length)
int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
int i, res; int i, res;
void *table, *buffer, **data; void *table, *buffer, **data;
struct squashfs_page_actor *actor;
table = buffer = kmalloc(length, GFP_KERNEL); table = buffer = kmalloc(length, GFP_KERNEL);
if (table == NULL) if (table == NULL)
...@@ -421,19 +430,28 @@ void *squashfs_read_table(struct super_block *sb, u64 block, int length) ...@@ -421,19 +430,28 @@ void *squashfs_read_table(struct super_block *sb, u64 block, int length)
goto failed; goto failed;
} }
actor = squashfs_page_actor_init(data, pages, length);
if (actor == NULL) {
res = -ENOMEM;
goto failed2;
}
for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE)
data[i] = buffer; data[i] = buffer;
res = squashfs_read_data(sb, data, block, length | res = squashfs_read_data(sb, block, length |
SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages); SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, actor);
kfree(data); kfree(data);
kfree(actor);
if (res < 0) if (res < 0)
goto failed; goto failed;
return table; return table;
failed2:
kfree(data);
failed: failed:
kfree(table); kfree(table);
return ERR_PTR(res); return ERR_PTR(res);
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "decompressor.h" #include "decompressor.h"
#include "squashfs.h" #include "squashfs.h"
#include "page_actor.h"
/* /*
* This file (and decompressor.h) implements a decompressor framework for * This file (and decompressor.h) implements a decompressor framework for
...@@ -87,6 +88,7 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags) ...@@ -87,6 +88,7 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags)
{ {
struct squashfs_sb_info *msblk = sb->s_fs_info; struct squashfs_sb_info *msblk = sb->s_fs_info;
void *buffer = NULL, *comp_opts; void *buffer = NULL, *comp_opts;
struct squashfs_page_actor *actor = NULL;
int length = 0; int length = 0;
/* /*
...@@ -99,9 +101,14 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags) ...@@ -99,9 +101,14 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags)
goto out; goto out;
} }
length = squashfs_read_data(sb, &buffer, actor = squashfs_page_actor_init(&buffer, 1, 0);
sizeof(struct squashfs_super_block), 0, NULL, if (actor == NULL) {
PAGE_CACHE_SIZE, 1); comp_opts = ERR_PTR(-ENOMEM);
goto out;
}
length = squashfs_read_data(sb,
sizeof(struct squashfs_super_block), 0, NULL, actor);
if (length < 0) { if (length < 0) {
comp_opts = ERR_PTR(length); comp_opts = ERR_PTR(length);
...@@ -112,6 +119,7 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags) ...@@ -112,6 +119,7 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags)
comp_opts = squashfs_comp_opts(msblk, buffer, length); comp_opts = squashfs_comp_opts(msblk, buffer, length);
out: out:
kfree(actor);
kfree(buffer); kfree(buffer);
return comp_opts; return comp_opts;
} }
......
...@@ -27,8 +27,9 @@ struct squashfs_decompressor { ...@@ -27,8 +27,9 @@ struct squashfs_decompressor {
void *(*init)(struct squashfs_sb_info *, void *); void *(*init)(struct squashfs_sb_info *, void *);
void *(*comp_opts)(struct squashfs_sb_info *, void *, int); void *(*comp_opts)(struct squashfs_sb_info *, void *, int);
void (*free)(void *); void (*free)(void *);
int (*decompress)(struct squashfs_sb_info *, void *, void **, int (*decompress)(struct squashfs_sb_info *, void *,
struct buffer_head **, int, int, int, int, int); struct buffer_head **, int, int, int,
struct squashfs_page_actor *);
int id; int id;
char *name; char *name;
int supported; int supported;
......
...@@ -183,15 +183,14 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk, ...@@ -183,15 +183,14 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk,
} }
int squashfs_decompress(struct squashfs_sb_info *msblk, int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
void **buffer, struct buffer_head **bh, int b, int offset, int length, int b, int offset, int length, struct squashfs_page_actor *output)
int srclength, int pages)
{ {
int res; int res;
struct squashfs_stream *stream = msblk->stream; struct squashfs_stream *stream = msblk->stream;
struct decomp_stream *decomp_stream = get_decomp_stream(msblk, stream); struct decomp_stream *decomp_stream = get_decomp_stream(msblk, stream);
res = msblk->decompressor->decompress(msblk, decomp_stream->stream, res = msblk->decompressor->decompress(msblk, decomp_stream->stream,
buffer, bh, b, offset, length, srclength, pages); bh, b, offset, length, output);
put_decomp_stream(decomp_stream, stream); put_decomp_stream(decomp_stream, stream);
if (res < 0) if (res < 0)
ERROR("%s decompression failed, data probably corrupt\n", ERROR("%s decompression failed, data probably corrupt\n",
......
...@@ -74,15 +74,14 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk) ...@@ -74,15 +74,14 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
} }
} }
int squashfs_decompress(struct squashfs_sb_info *msblk, int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
void **buffer, struct buffer_head **bh, int b, int offset, int length, int b, int offset, int length, struct squashfs_page_actor *output)
int srclength, int pages)
{ {
struct squashfs_stream __percpu *percpu = struct squashfs_stream __percpu *percpu =
(struct squashfs_stream __percpu *) msblk->stream; (struct squashfs_stream __percpu *) msblk->stream;
struct squashfs_stream *stream = get_cpu_ptr(percpu); struct squashfs_stream *stream = get_cpu_ptr(percpu);
int res = msblk->decompressor->decompress(msblk, stream->stream, buffer, int res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
bh, b, offset, length, srclength, pages); offset, length, output);
put_cpu_ptr(stream); put_cpu_ptr(stream);
if (res < 0) if (res < 0)
......
...@@ -61,16 +61,15 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk) ...@@ -61,16 +61,15 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
} }
} }
int squashfs_decompress(struct squashfs_sb_info *msblk, int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
void **buffer, struct buffer_head **bh, int b, int offset, int length, int b, int offset, int length, struct squashfs_page_actor *output)
int srclength, int pages)
{ {
int res; int res;
struct squashfs_stream *stream = msblk->stream; struct squashfs_stream *stream = msblk->stream;
mutex_lock(&stream->mutex); mutex_lock(&stream->mutex);
res = msblk->decompressor->decompress(msblk, stream->stream, buffer, res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
bh, b, offset, length, srclength, pages); offset, length, output);
mutex_unlock(&stream->mutex); mutex_unlock(&stream->mutex);
if (res < 0) if (res < 0)
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "squashfs.h" #include "squashfs.h"
#include "decompressor.h" #include "decompressor.h"
#include "page_actor.h"
struct squashfs_lzo { struct squashfs_lzo {
void *input; void *input;
...@@ -75,13 +76,13 @@ static void lzo_free(void *strm) ...@@ -75,13 +76,13 @@ static void lzo_free(void *strm)
static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm, static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm,
void **buffer, struct buffer_head **bh, int b, int offset, int length, struct buffer_head **bh, int b, int offset, int length,
int srclength, int pages) struct squashfs_page_actor *output)
{ {
struct squashfs_lzo *stream = strm; struct squashfs_lzo *stream = strm;
void *buff = stream->input; void *buff = stream->input, *data;
int avail, i, bytes = length, res; int avail, i, bytes = length, res;
size_t out_len = srclength; size_t out_len = output->length;
for (i = 0; i < b; i++) { for (i = 0; i < b; i++) {
avail = min(bytes, msblk->devblksize - offset); avail = min(bytes, msblk->devblksize - offset);
...@@ -98,12 +99,20 @@ static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -98,12 +99,20 @@ static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm,
goto failed; goto failed;
res = bytes = (int)out_len; res = bytes = (int)out_len;
for (i = 0, buff = stream->output; bytes && i < pages; i++) { data = squashfs_first_page(output);
avail = min_t(int, bytes, PAGE_CACHE_SIZE); buff = stream->output;
memcpy(buffer[i], buff, avail); while (data) {
buff += avail; if (bytes <= PAGE_CACHE_SIZE) {
bytes -= avail; memcpy(data, buff, bytes);
break;
} else {
memcpy(data, buff, PAGE_CACHE_SIZE);
buff += PAGE_CACHE_SIZE;
bytes -= PAGE_CACHE_SIZE;
data = squashfs_next_page(output);
}
} }
squashfs_finish_page(output);
return res; return res;
......
#ifndef PAGE_ACTOR_H
#define PAGE_ACTOR_H
/*
* Copyright (c) 2013
* Phillip Lougher <phillip@squashfs.org.uk>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/
struct squashfs_page_actor {
void **page;
int pages;
int length;
int next_page;
};
static inline struct squashfs_page_actor *squashfs_page_actor_init(void **page,
int pages, int length)
{
struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
if (actor == NULL)
return NULL;
actor->length = length ? : pages * PAGE_CACHE_SIZE;
actor->page = page;
actor->pages = pages;
actor->next_page = 0;
return actor;
}
static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
{
actor->next_page = 1;
return actor->page[0];
}
static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
{
return actor->next_page == actor->pages ? NULL :
actor->page[actor->next_page++];
}
static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
{
/* empty */
}
#endif
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#define WARNING(s, args...) pr_warning("SQUASHFS: "s, ## args) #define WARNING(s, args...) pr_warning("SQUASHFS: "s, ## args)
/* block.c */ /* block.c */
extern int squashfs_read_data(struct super_block *, void **, u64, int, u64 *, extern int squashfs_read_data(struct super_block *, u64, int, u64 *,
int, int); struct squashfs_page_actor *);
/* cache.c */ /* cache.c */
extern struct squashfs_cache *squashfs_cache_init(char *, int, int); extern struct squashfs_cache *squashfs_cache_init(char *, int, int);
...@@ -53,8 +53,8 @@ extern void *squashfs_decompressor_setup(struct super_block *, unsigned short); ...@@ -53,8 +53,8 @@ extern void *squashfs_decompressor_setup(struct super_block *, unsigned short);
/* decompressor_xxx.c */ /* decompressor_xxx.c */
extern void *squashfs_decompressor_create(struct squashfs_sb_info *, void *); extern void *squashfs_decompressor_create(struct squashfs_sb_info *, void *);
extern void squashfs_decompressor_destroy(struct squashfs_sb_info *); extern void squashfs_decompressor_destroy(struct squashfs_sb_info *);
extern int squashfs_decompress(struct squashfs_sb_info *, void **, extern int squashfs_decompress(struct squashfs_sb_info *, struct buffer_head **,
struct buffer_head **, int, int, int, int, int); int, int, int, struct squashfs_page_actor *);
extern int squashfs_max_decompressors(void); extern int squashfs_max_decompressors(void);
/* export.c */ /* export.c */
......
...@@ -50,6 +50,7 @@ struct squashfs_cache_entry { ...@@ -50,6 +50,7 @@ struct squashfs_cache_entry {
wait_queue_head_t wait_queue; wait_queue_head_t wait_queue;
struct squashfs_cache *cache; struct squashfs_cache *cache;
void **data; void **data;
struct squashfs_page_actor *actor;
}; };
struct squashfs_sb_info { struct squashfs_sb_info {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "squashfs.h" #include "squashfs.h"
#include "decompressor.h" #include "decompressor.h"
#include "page_actor.h"
struct squashfs_xz { struct squashfs_xz {
struct xz_dec *state; struct xz_dec *state;
...@@ -129,11 +130,11 @@ static void squashfs_xz_free(void *strm) ...@@ -129,11 +130,11 @@ static void squashfs_xz_free(void *strm)
static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm, static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm,
void **buffer, struct buffer_head **bh, int b, int offset, int length, struct buffer_head **bh, int b, int offset, int length,
int srclength, int pages) struct squashfs_page_actor *output)
{ {
enum xz_ret xz_err; enum xz_ret xz_err;
int avail, total = 0, k = 0, page = 0; int avail, total = 0, k = 0;
struct squashfs_xz *stream = strm; struct squashfs_xz *stream = strm;
xz_dec_reset(stream->state); xz_dec_reset(stream->state);
...@@ -141,7 +142,7 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -141,7 +142,7 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm,
stream->buf.in_size = 0; stream->buf.in_size = 0;
stream->buf.out_pos = 0; stream->buf.out_pos = 0;
stream->buf.out_size = PAGE_CACHE_SIZE; stream->buf.out_size = PAGE_CACHE_SIZE;
stream->buf.out = buffer[page++]; stream->buf.out = squashfs_first_page(output);
do { do {
if (stream->buf.in_pos == stream->buf.in_size && k < b) { if (stream->buf.in_pos == stream->buf.in_size && k < b) {
...@@ -153,11 +154,12 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -153,11 +154,12 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm,
offset = 0; offset = 0;
} }
if (stream->buf.out_pos == stream->buf.out_size if (stream->buf.out_pos == stream->buf.out_size) {
&& page < pages) { stream->buf.out = squashfs_next_page(output);
stream->buf.out = buffer[page++]; if (stream->buf.out != NULL) {
stream->buf.out_pos = 0; stream->buf.out_pos = 0;
total += PAGE_CACHE_SIZE; total += PAGE_CACHE_SIZE;
}
} }
xz_err = xz_dec_run(stream->state, &stream->buf); xz_err = xz_dec_run(stream->state, &stream->buf);
...@@ -166,6 +168,8 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -166,6 +168,8 @@ static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void *strm,
put_bh(bh[k++]); put_bh(bh[k++]);
} while (xz_err == XZ_OK); } while (xz_err == XZ_OK);
squashfs_finish_page(output);
if (xz_err != XZ_STREAM_END || k < b) if (xz_err != XZ_STREAM_END || k < b)
goto out; goto out;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
#include "squashfs.h" #include "squashfs.h"
#include "decompressor.h" #include "decompressor.h"
#include "page_actor.h"
static void *zlib_init(struct squashfs_sb_info *dummy, void *buff) static void *zlib_init(struct squashfs_sb_info *dummy, void *buff)
{ {
...@@ -62,14 +63,14 @@ static void zlib_free(void *strm) ...@@ -62,14 +63,14 @@ static void zlib_free(void *strm)
static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
void **buffer, struct buffer_head **bh, int b, int offset, int length, struct buffer_head **bh, int b, int offset, int length,
int srclength, int pages) struct squashfs_page_actor *output)
{ {
int zlib_err, zlib_init = 0; int zlib_err, zlib_init = 0, k = 0;
int k = 0, page = 0;
z_stream *stream = strm; z_stream *stream = strm;
stream->avail_out = 0; stream->avail_out = PAGE_CACHE_SIZE;
stream->next_out = squashfs_first_page(output);
stream->avail_in = 0; stream->avail_in = 0;
do { do {
...@@ -81,15 +82,18 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -81,15 +82,18 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
offset = 0; offset = 0;
} }
if (stream->avail_out == 0 && page < pages) { if (stream->avail_out == 0) {
stream->next_out = buffer[page++]; stream->next_out = squashfs_next_page(output);
stream->avail_out = PAGE_CACHE_SIZE; if (stream->next_out != NULL)
stream->avail_out = PAGE_CACHE_SIZE;
} }
if (!zlib_init) { if (!zlib_init) {
zlib_err = zlib_inflateInit(stream); zlib_err = zlib_inflateInit(stream);
if (zlib_err != Z_OK) if (zlib_err != Z_OK) {
squashfs_finish_page(output);
goto out; goto out;
}
zlib_init = 1; zlib_init = 1;
} }
...@@ -99,6 +103,8 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, ...@@ -99,6 +103,8 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
put_bh(bh[k++]); put_bh(bh[k++]);
} while (zlib_err == Z_OK); } while (zlib_err == Z_OK);
squashfs_finish_page(output);
if (zlib_err != Z_STREAM_END) if (zlib_err != Z_STREAM_END)
goto out; goto out;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册