static void destroy_inodecache(void);
static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
struct nameidata *);
-static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
static long long read_blocklist(struct inode *inode, int index,
int readahead_blks, char *block_list,
unsigned short **block_p, unsigned int *bsize);
-static int squashfs_get_sb(struct file_system_type *, int,
- const char *, void *, struct vfsmount *);
+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
+ struct vfsmount *);
+static void vfs_read_inode(struct inode *i);
+static struct dentry *squashfs_get_parent(struct dentry *child);
static struct file_system_type squashfs_fs_type = {
.owner = THIS_MODULE,
DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
};
-static struct super_operations squashfs_ops = {
+static struct super_operations squashfs_super_ops = {
.alloc_inode = squashfs_alloc_inode,
.destroy_inode = squashfs_destroy_inode,
.statfs = squashfs_statfs,
.put_super = squashfs_put_super,
};
+static struct super_operations squashfs_export_super_ops = {
+ .alloc_inode = squashfs_alloc_inode,
+ .destroy_inode = squashfs_destroy_inode,
+ .statfs = squashfs_statfs,
+ .put_super = squashfs_put_super,
+ .read_inode = vfs_read_inode
+};
+
+struct export_operations squashfs_export_ops = {
+ .get_parent = squashfs_get_parent
+};
+
SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
.readpage = squashfs_symlink_readpage
};
SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
long long index, unsigned int length,
- long long *next_index)
+ long long *next_index, int srclength)
{
struct squashfs_sb_info *msblk = s->s_fs_info;
+ struct squashfs_super_block *sblk = &msblk->sblk;
struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
msblk->devblksize_log2) + 2];
unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
unsigned int cur_index = index >> msblk->devblksize_log2;
- int bytes, avail_bytes, b = 0, k;
+ int bytes, avail_bytes, b = 0, k = 0;
char *c_buffer;
unsigned int compressed;
unsigned int c_byte = length;
c_buffer = compressed ? msblk->read_data : buffer;
c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
- TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
- ? "" : "un", (unsigned int) c_byte);
+ TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index, compressed
+ ? "" : "un", (unsigned int) c_byte, srclength);
+
+ if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
+ goto read_failure;
if (!(bh[0] = sb_getblk(s, cur_index)))
goto block_release;
}
ll_rw_block(READ, b, bh);
} else {
+ if (index < 0 || (index + 2) > sblk->bytes_used)
+ goto read_failure;
+
if (!(bh[0] = get_block_length(s, &cur_index, &offset,
&c_byte)))
goto read_failure;
TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
? "" : "un", (unsigned int) c_byte);
+ if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
+ goto read_failure;
+
for (b = 1; bytes < c_byte; b++) {
if (!(bh[b] = sb_getblk(s, ++cur_index)))
goto block_release;
if (compressed)
down(&msblk->read_data_mutex);
- for (bytes = 0, k = 0; k < b; k++) {
+ for (bytes = 0; k < b; k++) {
avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
msblk->devblksize - offset :
c_byte - bytes;
msblk->stream.next_in = c_buffer;
msblk->stream.avail_in = c_byte;
msblk->stream.next_out = buffer;
- msblk->stream.avail_out = msblk->read_size;
+ //msblk->stream.avail_out = msblk->read_size;//srclength;
+ msblk->stream.avail_out = srclength;
if (((zlib_err = zlib_inflateInit(&msblk->stream)) != Z_OK) ||
((zlib_err = zlib_inflate(&msblk->stream, Z_FINISH))
!= Z_STREAM_END) || ((zlib_err =
zlib_inflateEnd(&msblk->stream)) != Z_OK)) {
- ERROR("zlib_fs returned unexpected result 0x%x\n",
- zlib_err);
+ //ERROR("zlib_fs returned unexpected result 0x%x\n",
+ // zlib_err);
+ ERROR("zlib_fs returned unexpected result 0x%x, srclength %d\n",
+ zlib_err, srclength);
bytes = 0;
} else
bytes = msblk->stream.total_out;
return bytes;
block_release:
- while (--b >= 0)
- brelse(bh[b]);
+ for (; k < b; k++)
+ brelse(bh[k]);
read_failure:
ERROR("sb_bread failed reading block 0x%x\n", cur_index);
msblk->block_cache[i].block = SQUASHFS_USED_BLK;
up(&msblk->block_cache_mutex);
- if (!(msblk->block_cache[i].length =
- squashfs_read_data(s,
- msblk->block_cache[i].data,
- block, 0, &next_index))) {
+ msblk->block_cache[i].length = squashfs_read_data(s,
+ msblk->block_cache[i].data, block, 0, &next_index, SQUASHFS_METADATA_SIZE);
+ if (msblk->block_cache[i].length == 0) {
ERROR("Unable to read cache block [%llx:%x]\n",
block, offset);
+ down(&msblk->block_cache_mutex);
+ msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
+ kfree(msblk->block_cache[i].data);
+ wake_up(&msblk->waitq);
+ up(&msblk->block_cache_mutex);
goto out;
}
continue;
}
- if ((bytes = msblk->block_cache[i].length - offset) >= length) {
+ bytes = msblk->block_cache[i].length - offset;
+
+ if (bytes < 1) {
+ up(&msblk->block_cache_mutex);
+ goto out;
+ } else if (bytes >= length) {
if (buffer)
memcpy(buffer, msblk->block_cache[i].data +
offset, length);
{
int i, n;
struct squashfs_sb_info *msblk = s->s_fs_info;
+ struct squashfs_super_block *sblk = &msblk->sblk;
while ( 1 ) {
down(&msblk->fragment_mutex);
if (!(msblk->fragment[i].length = squashfs_read_data(s,
msblk->fragment[i].data,
- start_block, length, NULL))) {
+ start_block, length, NULL, sblk->block_size))) {
ERROR("Unable to read fragment cache block "
"[%llx]\n", start_block);
msblk->fragment[i].locked = 0;
}
-static struct inode *squashfs_new_inode(struct super_block *s,
+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
struct squashfs_base_inode_header *inodeb)
+{
+ i->i_ino = inodeb->inode_number;
+ i->i_mtime.tv_sec = inodeb->mtime;
+ i->i_atime.tv_sec = inodeb->mtime;
+ i->i_ctime.tv_sec = inodeb->mtime;
+ i->i_uid = msblk->uid[inodeb->uid];
+ i->i_mode = inodeb->mode;
+ i->i_size = 0;
+ if (inodeb->guid == SQUASHFS_GUIDS)
+ i->i_gid = i->i_uid;
+ else
+ i->i_gid = msblk->guid[inodeb->guid];
+}
+
+
+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
{
struct squashfs_sb_info *msblk = s->s_fs_info;
- struct inode *i = new_inode(s);
-
- if (i) {
- i->i_ino = inodeb->inode_number;
- i->i_mtime.tv_sec = inodeb->mtime;
- i->i_atime.tv_sec = inodeb->mtime;
- i->i_ctime.tv_sec = inodeb->mtime;
- i->i_uid = msblk->uid[inodeb->uid];
- i->i_mode = inodeb->mode;
- i->i_size = 0;
- if (inodeb->guid == SQUASHFS_GUIDS)
- i->i_gid = i->i_uid;
- else
- i->i_gid = msblk->guid[inodeb->guid];
+ long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
+ int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
+ squashfs_inode_t inode;
+
+ TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
+
+ if (msblk->swap) {
+ squashfs_inode_t sinode;
+
+ if (!squashfs_get_cached_block(s, (char *) &sinode, start, offset,
+ sizeof(sinode), &start, &offset))
+ goto out;
+ SQUASHFS_SWAP_INODE_T((&inode), &sinode);
+ } else if (!squashfs_get_cached_block(s, (char *) &inode, start, offset,
+ sizeof(inode), &start, &offset))
+ goto out;
+
+ TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
+
+ return inode;
+
+out:
+ return SQUASHFS_INVALID_BLK;
+}
+
+
+static void vfs_read_inode(struct inode *i)
+{
+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
+ squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);
+
+ TRACE("Entered vfs_read_inode\n");
+
+ if(inode != SQUASHFS_INVALID_BLK)
+ (msblk->read_inode)(i, inode);
+}
+
+
+static struct dentry *squashfs_get_parent(struct dentry *child)
+{
+ struct inode *i = child->d_inode;
+ struct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
+ struct dentry *rv;
+
+ TRACE("Entered squashfs_get_parent\n");
+
+ if(parent == NULL) {
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ rv = d_alloc_anon(parent);
+ if(rv == NULL)
+ rv = ERR_PTR(-ENOMEM);
+
+out:
+ return rv;
+}
+
+
+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number)
+{
+ struct squashfs_sb_info *msblk = s->s_fs_info;
+ struct inode *i = iget_locked(s, inode_number);
+
+ TRACE("Entered squashfs_iget\n");
+
+ if(i && (i->i_state & I_NEW)) {
+ (msblk->read_inode)(i, inode);
+ unlock_new_inode(i);
}
return i;
}
-static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
{
- struct inode *i;
+ struct super_block *s = i->i_sb;
struct squashfs_sb_info *msblk = s->s_fs_info;
struct squashfs_super_block *sblk = &msblk->sblk;
long long block = SQUASHFS_INODE_BLK(inode) +
struct squashfs_base_inode_header *inodeb = &id.base,
*sinodeb = &sid.base;
- TRACE("Entered squashfs_iget\n");
+ TRACE("Entered squashfs_read_inode\n");
if (msblk->swap) {
if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
&next_offset))
goto failed_read;
+ squashfs_new_inode(msblk, i, inodeb);
+
switch(inodeb->inode_type) {
case SQUASHFS_FILE_TYPE: {
unsigned int frag_size;
inodep->fragment, &frag_blk, &frag_size))
goto failed_read;
- if((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = 1;
i->i_size = inodep->file_size;
i->i_fop = &generic_ro_fops;
inodep->fragment, &frag_blk, &frag_size))
goto failed_read;
- if((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_size = inodep->file_size;
i->i_fop = &generic_ro_fops;
&next_offset))
goto failed_read;
- if((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_size = inodep->file_size;
i->i_op = &squashfs_dir_inode_ops;
&next_offset))
goto failed_read;
- if((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_size = inodep->file_size;
i->i_op = &squashfs_dir_inode_ops;
&next_offset))
goto failed_read;
- if((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_size = inodep->symlink_size;
i->i_op = &page_symlink_inode_operations;
&next_offset))
goto failed_read;
- if ((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_mode |= (inodeb->inode_type ==
SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
&next_offset))
goto failed_read;
- if ((i = squashfs_new_inode(s, inodeb)) == NULL)
- goto failed_read1;
-
i->i_nlink = inodep->nlink;
i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
? S_IFIFO : S_IFSOCK;
goto failed_read1;
}
- insert_inode_hash(i);
- return i;
+ return 1;
failed_read:
ERROR("Unable to read inode [%llx:%x]\n", block, offset);
failed_read1:
- return NULL;
+ make_bad_inode(i);
+ return 0;
+}
+
+
+static int read_inode_lookup_table(struct super_block *s)
+{
+ struct squashfs_sb_info *msblk = s->s_fs_info;
+ struct squashfs_super_block *sblk = &msblk->sblk;
+ unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
+
+ TRACE("In read_inode_lookup_table, length %d\n", length);
+
+ /* Allocate inode lookup table */
+ if (!(msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL))) {
+ ERROR("Failed to allocate inode lookup table\n");
+ return 0;
+ }
+
+ if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
+ sblk->lookup_table_start, length |
+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
+ ERROR("unable to read inode lookup table\n");
+ return 0;
+ }
+
+ if (msblk->swap) {
+ int i;
+ long long block;
+
+ for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
+ SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
+ &msblk->inode_lookup_table[i], 1);
+ msblk->inode_lookup_table[i] = block;
+ }
+ }
+
+ return 1;
}
{
struct squashfs_sb_info *msblk = s->s_fs_info;
struct squashfs_super_block *sblk = &msblk->sblk;
+ unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
+
+ if(length == 0)
+ return 1;
/* Allocate fragment index table */
- if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
- (sblk->fragments), GFP_KERNEL))) {
- ERROR("Failed to allocate uid/gid table\n");
+ if (!(msblk->fragment_index = kmalloc(length, GFP_KERNEL))) {
+ ERROR("Failed to allocate fragment index table\n");
return 0;
}
- if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
- !squashfs_read_data(s, (char *)
- msblk->fragment_index,
- sblk->fragment_table_start,
- SQUASHFS_FRAGMENT_INDEX_BYTES
- (sblk->fragments) |
- SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
+ if (!squashfs_read_data(s, (char *) msblk->fragment_index,
+ sblk->fragment_table_start, length |
+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
ERROR("unable to read fragment index table\n");
return 0;
}
int i;
long long fragment;
- for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
- i++) {
+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
&msblk->fragment_index[i], 1);
msblk->fragment_index[i] = fragment;
{
struct squashfs_super_block *sblk = &msblk->sblk;
- msblk->iget = squashfs_iget;
+ msblk->read_inode = squashfs_read_inode;
msblk->read_blocklist = read_blocklist;
msblk->read_fragment_index_table = read_fragment_index_table;
init_waitqueue_head(&msblk->waitq);
init_waitqueue_head(&msblk->fragment_wait_queue);
+ sblk->bytes_used = sizeof(struct squashfs_super_block);
if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
sizeof(struct squashfs_super_block) |
- SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
SERROR("unable to read superblock\n");
goto failed_mount;
}
if(!supported_squashfs_filesystem(msblk, silent))
goto failed_mount;
+ /* Check the filesystem does not extend beyond the end of the
+ block device */
+ if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
+ goto failed_mount;
+
+ /* Check the root inode for sanity */
+ if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
+ goto failed_mount;
+
TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
TRACE("Inodes are %scompressed\n",
SQUASHFS_UNCOMPRESSED_INODES
TRACE("sblk->uid_start %llx\n", sblk->uid_start);
s->s_flags |= MS_RDONLY;
- s->s_op = &squashfs_ops;
+ s->s_op = &squashfs_super_ops;
/* Init inode_table block pointer array */
if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
((sblk->no_uids + sblk->no_guids) *
sizeof(unsigned int)) |
- SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
ERROR("unable to read uid/gid table\n");
goto failed_mount;
}
if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
((sblk->no_uids + sblk->no_guids) *
sizeof(unsigned int)) |
- SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
ERROR("unable to read uid/gid table\n");
goto failed_mount;
}
msblk->next_fragment = 0;
- /* Allocate fragment index table */
+ /* Allocate and read fragment index table */
if (msblk->read_fragment_index_table(s) == 0)
goto failed_mount;
+ if(sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
+ goto allocate_root;
+
+ /* Allocate and read inode lookup table */
+ if (read_inode_lookup_table(s) == 0)
+ goto failed_mount;
+
+ s->s_op = &squashfs_export_super_ops;
+ s->s_export_op = &squashfs_export_ops;
+
allocate_root:
- if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
+ root = new_inode(s);
+ if ((msblk->read_inode)(root, sblk->root_inode) == 0)
goto failed_mount;
+ insert_inode_hash(root);
if ((s->s_root = d_alloc_root(root)) == NULL) {
ERROR("Root inode create failed\n");
return 0;
failed_mount:
+ kfree(msblk->inode_lookup_table);
kfree(msblk->fragment_index);
kfree(msblk->fragment);
kfree(msblk->uid);
}
-static int squashfs_statfs(struct dentry *s, struct kstatfs *buf)
+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
{
- struct squashfs_sb_info *msblk = s->d_sb->s_fs_info;
+ struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
struct squashfs_super_block *sblk = &msblk->sblk;
TRACE("Entered squashfs_statfs\n");
skip)) == NULL)
goto all_done;
} else {
+ if(meta->entries == 0)
+ goto failed;
offset = index < meta->offset + meta->entries ? index :
meta->offset + meta->entries - 1;
meta_entry = &meta->meta_entry[offset - meta->offset];
down(&msblk->read_page_mutex);
if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
- block, bsize, NULL))) {
+ block, bsize, NULL, sblk->block_size))) {
ERROR("Unable to read page, block %llx, size %x\n", block,
bsize);
up(&msblk->read_page_mutex);
for (i = start_index; i <= end_index && byte_offset < bytes;
i++, byte_offset += PAGE_CACHE_SIZE) {
struct page *push_page;
- int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
+ int avail = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
PAGE_CACHE_SIZE : bytes - byte_offset;
TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
- bytes, i, byte_offset, available_bytes);
+ bytes, i, byte_offset, avail);
- if (i == page->index) {
- pageaddr = kmap_atomic(page, KM_USER0);
- memcpy(pageaddr, data_ptr + byte_offset,
- available_bytes);
- memset(pageaddr + available_bytes, 0,
- PAGE_CACHE_SIZE - available_bytes);
- kunmap_atomic(pageaddr, KM_USER0);
- flush_dcache_page(page);
- SetPageUptodate(page);
- unlock_page(page);
- } else if ((push_page =
- grab_cache_page_nowait(page->mapping, i))) {
- pageaddr = kmap_atomic(push_page, KM_USER0);
-
- memcpy(pageaddr, data_ptr + byte_offset,
- available_bytes);
- memset(pageaddr + available_bytes, 0,
- PAGE_CACHE_SIZE - available_bytes);
- kunmap_atomic(pageaddr, KM_USER0);
- flush_dcache_page(push_page);
- SetPageUptodate(push_page);
- unlock_page(push_page);
+ push_page = (i == page->index) ? page :
+ grab_cache_page_nowait(page->mapping, i);
+
+ if (!push_page)
+ continue;
+
+ if (PageUptodate(push_page))
+ goto skip_page;
+
+ pageaddr = kmap_atomic(push_page, KM_USER0);
+ memcpy(pageaddr, data_ptr + byte_offset, avail);
+ memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
+ kunmap_atomic(pageaddr, KM_USER0);
+ flush_dcache_page(push_page);
+ SetPageUptodate(push_page);
+skip_page:
+ unlock_page(push_page);
+ if(i != page->index)
page_cache_release(push_page);
- }
}
if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
PAGE_CACHE_SHIFT)) {
- pageaddr = kmap_atomic(page, KM_USER0);
block_list = NULL;
goto skip_read;
}
if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
ERROR("Failed to allocate block_list\n");
- pageaddr = kmap_atomic(page, KM_USER0);
- block_list = NULL;
goto skip_read;
}
sblk->block_log)) {
block = (msblk->read_blocklist)(inode, page->index, 1,
block_list, NULL, &bsize);
+ if(block == 0)
+ goto skip_read;
down(&msblk->read_page_mutex);
bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
- bsize, NULL);
- pageaddr = kmap_atomic(page, KM_USER0);
- if (bytes)
+ bsize, NULL, sblk->block_size);
+ if (bytes) {
+ pageaddr = kmap_atomic(page, KM_USER0);
memcpy(pageaddr, msblk->read_page, bytes);
- else
+ kunmap_atomic(pageaddr, KM_USER0);
+ } else
ERROR("Unable to read page, block %llx, size %x\n",
block, bsize);
up(&msblk->read_page_mutex);
SQUASHFS_I(inode)->
u.s1.fragment_start_block,
SQUASHFS_I(inode)-> u.s1.fragment_size);
- pageaddr = kmap_atomic(page, KM_USER0);
if (fragment) {
bytes = i_size_read(inode) & (sblk->block_size - 1);
+ pageaddr = kmap_atomic(page, KM_USER0);
memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
u.s1.fragment_offset, bytes);
+ kunmap_atomic(pageaddr, KM_USER0);
release_cached_fragment(msblk, fragment);
} else
ERROR("Unable to read page, block %llx, size %x\n",
}
skip_read:
+ pageaddr = kmap_atomic(page, KM_USER0);
memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
kunmap_atomic(pageaddr, KM_USER0);
flush_dcache_page(page);
failed_read:
ERROR("Unable to read directory block [%llx:%x]\n", next_block,
next_offset);
+ kfree(dire);
return 0;
}
if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
ERROR("Failed to allocate squashfs_dir_entry\n");
- goto exit_loop;
+ goto exit_lookup;
}
if (len > SQUASHFS_NAME_LEN)
- goto exit_loop;
+ goto exit_lookup;
length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
SQUASHFS_I(i)->u.s2.directory_index_start,
length += dire->size + 1;
if (name[0] < dire->name[0])
- goto exit_loop;
+ goto exit_lookup;
- if ((len == dire->size + 1) && !strncmp(name,
- dire->name, len)) {
- squashfs_inode_t ino =
- SQUASHFS_MKINODE(dirh.start_block,
- dire->offset);
+ if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
+ squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
+ dire->offset);
TRACE("calling squashfs_iget for directory "
"entry %s, inode %x:%x, %d\n", name,
dirh.start_block, dire->offset,
dirh.inode_number + dire->inode_number);
- inode = (msblk->iget)(i->i_sb, ino);
+ inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
- goto exit_loop;
+ goto exit_lookup;
}
}
}
-exit_loop:
+exit_lookup:
kfree(dire);
+ if (inode)
+ return d_splice_alias(inode, dentry);
d_add(dentry, inode);
return ERR_PTR(0);
failed_read:
ERROR("Unable to read directory block [%llx:%x]\n", next_block,
next_offset);
- goto exit_loop;
+ goto exit_lookup;
}
}
-static int squashfs_get_sb(struct file_system_type *fs_type,
- int flags, const char *dev_name, void *data, struct vfsmount *mnt)
+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
+ const char *dev_name, void *data,
+ struct vfsmount *mnt)
{
- return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
+ return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
+ mnt);
}
if (err)
goto out;
- printk(KERN_INFO "squashfs: version 3.1 (2006/08/09) "
+ printk(KERN_INFO "squashfs: version 3.2-alpha (2006/12/12) "
"Phillip Lougher\n");
if ((err = register_filesystem(&squashfs_fs_type)))
}
-static kmem_cache_t * squashfs_inode_cachep;
+static struct kmem_cache *squashfs_inode_cachep;
static struct inode *squashfs_alloc_inode(struct super_block *sb)
{
struct squashfs_inode_info *ei;
- ei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
+ ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void * foo, struct kmem_cache *cachep, unsigned long flags)
{
struct squashfs_inode_info *ei = foo;
static void destroy_inodecache(void)
{
- if (kmem_cache_destroy(squashfs_inode_cachep))
- printk(KERN_INFO "squashfs_inode_cache: not all structures "
- "were freed\n");
+ kmem_cache_destroy(squashfs_inode_cachep);
}
module_init(init_squashfs_fs);
module_exit(exit_squashfs_fs);
-MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
+MODULE_DESCRIPTION("squashfs 3.2, a compressed read-only filesystem");
MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
MODULE_LICENSE("GPL");