2019-05-20 20:08:00 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-01-05 11:46:25 +03:00
|
|
|
/*
|
|
|
|
* Squashfs - a compressed read only filesystem for Linux
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
|
2011-05-26 13:39:56 +04:00
|
|
|
* Phillip Lougher <phillip@squashfs.org.uk>
|
2009-01-05 11:46:25 +03:00
|
|
|
*
|
|
|
|
* super.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file implements code to read the superblock, read and initialise
|
|
|
|
* in-memory structures at mount time, and all the VFS glue code to register
|
|
|
|
* the filesystem.
|
|
|
|
*/
|
|
|
|
|
2014-08-07 03:03:52 +04:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2009-01-05 11:46:25 +03:00
|
|
|
#include <linux/fs.h>
|
2019-03-25 19:38:32 +03:00
|
|
|
#include <linux/fs_context.h>
|
2009-01-05 11:46:25 +03:00
|
|
|
#include <linux/vfs.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2009-01-16 00:51:03 +03:00
|
|
|
#include <linux/magic.h>
|
2010-05-14 23:48:47 +04:00
|
|
|
#include <linux/xattr.h>
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
#include "squashfs_fs.h"
|
|
|
|
#include "squashfs_fs_sb.h"
|
|
|
|
#include "squashfs_fs_i.h"
|
|
|
|
#include "squashfs.h"
|
2009-10-06 07:04:15 +04:00
|
|
|
#include "decompressor.h"
|
2010-05-17 22:39:02 +04:00
|
|
|
#include "xattr.h"
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
static struct file_system_type squashfs_fs_type;
|
2009-09-22 04:01:09 +04:00
|
|
|
static const struct super_operations squashfs_super_ops;
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2019-03-25 19:38:32 +03:00
|
|
|
static const struct squashfs_decompressor *supported_squashfs_filesystem(
|
|
|
|
struct fs_context *fc,
|
|
|
|
short major, short minor, short id)
|
2009-01-05 11:46:25 +03:00
|
|
|
{
|
2009-10-06 07:04:15 +04:00
|
|
|
const struct squashfs_decompressor *decompressor;
|
|
|
|
|
2009-01-05 11:46:25 +03:00
|
|
|
if (major < SQUASHFS_MAJOR) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "Major/Minor mismatch, older Squashfs %d.%d "
|
|
|
|
"filesystems are unsupported", major, minor);
|
2009-10-06 07:04:15 +04:00
|
|
|
return NULL;
|
2009-01-05 11:46:25 +03:00
|
|
|
} else if (major > SQUASHFS_MAJOR || minor > SQUASHFS_MINOR) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "Major/Minor mismatch, trying to mount newer "
|
|
|
|
"%d.%d filesystem", major, minor);
|
|
|
|
errorf(fc, "Please update your kernel");
|
2009-10-06 07:04:15 +04:00
|
|
|
return NULL;
|
2009-01-05 11:46:25 +03:00
|
|
|
}
|
|
|
|
|
2009-10-06 07:04:15 +04:00
|
|
|
decompressor = squashfs_lookup_decompressor(id);
|
|
|
|
if (!decompressor->supported) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "Filesystem uses \"%s\" compression. This is not supported",
|
|
|
|
decompressor->name);
|
2009-10-06 07:04:15 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2009-10-06 07:04:15 +04:00
|
|
|
return decompressor;
|
2009-01-05 11:46:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 19:38:32 +03:00
|
|
|
static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
2009-01-05 11:46:25 +03:00
|
|
|
{
|
|
|
|
struct squashfs_sb_info *msblk;
|
|
|
|
struct squashfs_super_block *sblk = NULL;
|
|
|
|
struct inode *root;
|
|
|
|
long long root_inode;
|
|
|
|
unsigned short flags;
|
|
|
|
unsigned int fragments;
|
2011-05-24 07:05:22 +04:00
|
|
|
u64 lookup_table_start, xattr_id_table_start, next_table;
|
2009-01-05 11:46:25 +03:00
|
|
|
int err;
|
|
|
|
|
|
|
|
TRACE("Entered squashfs_fill_superblock\n");
|
|
|
|
|
|
|
|
sb->s_fs_info = kzalloc(sizeof(*msblk), GFP_KERNEL);
|
|
|
|
if (sb->s_fs_info == NULL) {
|
|
|
|
ERROR("Failed to allocate squashfs_sb_info\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
msblk = sb->s_fs_info;
|
|
|
|
|
2011-10-22 04:34:48 +04:00
|
|
|
msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE);
|
2009-01-05 11:46:25 +03:00
|
|
|
msblk->devblksize_log2 = ffz(~msblk->devblksize);
|
|
|
|
|
|
|
|
mutex_init(&msblk->meta_index_mutex);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* msblk->bytes_used is checked in squashfs_read_table to ensure reads
|
|
|
|
* are not beyond filesystem end. But as we're using
|
|
|
|
* squashfs_read_table here to read the superblock (including the value
|
|
|
|
* of bytes_used) we need to set it to an initial sensible dummy value
|
|
|
|
*/
|
|
|
|
msblk->bytes_used = sizeof(*sblk);
|
2011-05-20 05:26:43 +04:00
|
|
|
sblk = squashfs_read_table(sb, SQUASHFS_START, sizeof(*sblk));
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2011-05-20 05:26:43 +04:00
|
|
|
if (IS_ERR(sblk)) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "unable to read squashfs_super_block");
|
2011-05-20 05:26:43 +04:00
|
|
|
err = PTR_ERR(sblk);
|
|
|
|
sblk = NULL;
|
2009-01-05 11:46:25 +03:00
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
2009-10-06 07:04:15 +04:00
|
|
|
err = -EINVAL;
|
|
|
|
|
2009-01-05 11:46:25 +03:00
|
|
|
/* Check it is a SQUASHFS superblock */
|
|
|
|
sb->s_magic = le32_to_cpu(sblk->s_magic);
|
|
|
|
if (sb->s_magic != SQUASHFS_MAGIC) {
|
2019-03-25 19:38:32 +03:00
|
|
|
if (!(fc->sb_flags & SB_SILENT))
|
|
|
|
errorf(fc, "Can't find a SQUASHFS superblock on %pg",
|
|
|
|
sb->s_bdev);
|
2009-01-05 11:46:25 +03:00
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
2009-10-06 07:04:15 +04:00
|
|
|
/* Check the MAJOR & MINOR versions and lookup compression type */
|
|
|
|
msblk->decompressor = supported_squashfs_filesystem(
|
2019-03-25 19:38:32 +03:00
|
|
|
fc,
|
2009-10-06 07:04:15 +04:00
|
|
|
le16_to_cpu(sblk->s_major),
|
2009-01-05 11:46:25 +03:00
|
|
|
le16_to_cpu(sblk->s_minor),
|
|
|
|
le16_to_cpu(sblk->compression));
|
2009-10-06 07:04:15 +04:00
|
|
|
if (msblk->decompressor == NULL)
|
2009-01-05 11:46:25 +03:00
|
|
|
goto failed_mount;
|
|
|
|
|
|
|
|
/* Check the filesystem does not extend beyond the end of the
|
|
|
|
block device */
|
|
|
|
msblk->bytes_used = le64_to_cpu(sblk->bytes_used);
|
|
|
|
if (msblk->bytes_used < 0 || msblk->bytes_used >
|
|
|
|
i_size_read(sb->s_bdev->bd_inode))
|
|
|
|
goto failed_mount;
|
|
|
|
|
|
|
|
/* Check block size for sanity */
|
|
|
|
msblk->block_size = le32_to_cpu(sblk->block_size);
|
|
|
|
if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE)
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2009-05-13 05:59:26 +04:00
|
|
|
/*
|
|
|
|
* Check the system page size is not larger than the filesystem
|
|
|
|
* block size (by default 128K). This is currently not supported.
|
|
|
|
*/
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
if (PAGE_SIZE > msblk->block_size) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "Page size > filesystem block size (%d). This is "
|
|
|
|
"currently not supported!", msblk->block_size);
|
2009-05-13 05:59:26 +04:00
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
2012-03-09 07:02:59 +04:00
|
|
|
/* Check block log for sanity */
|
2009-01-05 11:46:25 +03:00
|
|
|
msblk->block_log = le16_to_cpu(sblk->block_log);
|
|
|
|
if (msblk->block_log > SQUASHFS_FILE_MAX_LOG)
|
|
|
|
goto failed_mount;
|
|
|
|
|
2012-03-09 07:02:59 +04:00
|
|
|
/* Check that block_size and block_log match */
|
|
|
|
if (msblk->block_size != (1 << msblk->block_log))
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2012-03-09 07:02:59 +04:00
|
|
|
|
2009-01-05 11:46:25 +03:00
|
|
|
/* Check the root inode for sanity */
|
|
|
|
root_inode = le64_to_cpu(sblk->root_inode);
|
|
|
|
if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE)
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
msblk->inode_table = le64_to_cpu(sblk->inode_table_start);
|
|
|
|
msblk->directory_table = le64_to_cpu(sblk->directory_table_start);
|
|
|
|
msblk->inodes = le32_to_cpu(sblk->inodes);
|
2018-08-02 18:43:35 +03:00
|
|
|
msblk->fragments = le32_to_cpu(sblk->fragments);
|
2021-02-10 00:41:53 +03:00
|
|
|
msblk->ids = le16_to_cpu(sblk->no_ids);
|
2009-01-05 11:46:25 +03:00
|
|
|
flags = le16_to_cpu(sblk->flags);
|
|
|
|
|
2015-04-13 15:31:37 +03:00
|
|
|
TRACE("Found valid superblock on %pg\n", sb->s_bdev);
|
2009-01-05 11:46:25 +03:00
|
|
|
TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(flags)
|
|
|
|
? "un" : "");
|
|
|
|
TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(flags)
|
|
|
|
? "un" : "");
|
|
|
|
TRACE("Filesystem size %lld bytes\n", msblk->bytes_used);
|
|
|
|
TRACE("Block size %d\n", msblk->block_size);
|
|
|
|
TRACE("Number of inodes %d\n", msblk->inodes);
|
2018-08-02 18:43:35 +03:00
|
|
|
TRACE("Number of fragments %d\n", msblk->fragments);
|
2021-02-10 00:41:53 +03:00
|
|
|
TRACE("Number of ids %d\n", msblk->ids);
|
2009-01-05 11:46:25 +03:00
|
|
|
TRACE("sblk->inode_table_start %llx\n", msblk->inode_table);
|
|
|
|
TRACE("sblk->directory_table_start %llx\n", msblk->directory_table);
|
|
|
|
TRACE("sblk->fragment_table_start %llx\n",
|
|
|
|
(u64) le64_to_cpu(sblk->fragment_table_start));
|
|
|
|
TRACE("sblk->id_table_start %llx\n",
|
|
|
|
(u64) le64_to_cpu(sblk->id_table_start));
|
|
|
|
|
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
2019-07-30 18:22:29 +03:00
|
|
|
sb->s_time_min = 0;
|
|
|
|
sb->s_time_max = U32_MAX;
|
2017-11-28 00:05:09 +03:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2009-01-05 11:46:25 +03:00
|
|
|
sb->s_op = &squashfs_super_ops;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
|
|
|
msblk->block_cache = squashfs_cache_init("metadata",
|
|
|
|
SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
|
|
|
|
if (msblk->block_cache == NULL)
|
|
|
|
goto failed_mount;
|
|
|
|
|
|
|
|
/* Allocate read_page block */
|
2013-11-13 06:56:26 +04:00
|
|
|
msblk->read_page = squashfs_cache_init("data",
|
|
|
|
squashfs_max_decompressors(), msblk->block_size);
|
2009-01-05 11:46:25 +03:00
|
|
|
if (msblk->read_page == NULL) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "Failed to allocate read_page block");
|
2009-01-05 11:46:25 +03:00
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
2013-11-13 06:56:26 +04:00
|
|
|
msblk->stream = squashfs_decompressor_setup(sb, flags);
|
2011-02-28 04:45:42 +03:00
|
|
|
if (IS_ERR(msblk->stream)) {
|
|
|
|
err = PTR_ERR(msblk->stream);
|
|
|
|
msblk->stream = NULL;
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2011-02-28 04:45:42 +03:00
|
|
|
}
|
|
|
|
|
2011-05-24 05:57:05 +04:00
|
|
|
/* Handle xattrs */
|
|
|
|
sb->s_xattr = squashfs_xattr_handlers;
|
|
|
|
xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start);
|
2011-05-24 07:05:22 +04:00
|
|
|
if (xattr_id_table_start == SQUASHFS_INVALID_BLK) {
|
|
|
|
next_table = msblk->bytes_used;
|
2011-05-24 05:57:05 +04:00
|
|
|
goto allocate_id_index_table;
|
2011-05-24 07:05:22 +04:00
|
|
|
}
|
2011-05-24 05:57:05 +04:00
|
|
|
|
|
|
|
/* Allocate and read xattr id lookup table */
|
|
|
|
msblk->xattr_id_table = squashfs_read_xattr_id_table(sb,
|
|
|
|
xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids);
|
|
|
|
if (IS_ERR(msblk->xattr_id_table)) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "unable to read xattr id index table");
|
2011-05-24 05:57:05 +04:00
|
|
|
err = PTR_ERR(msblk->xattr_id_table);
|
|
|
|
msblk->xattr_id_table = NULL;
|
|
|
|
if (err != -ENOTSUPP)
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
2011-05-24 07:05:22 +04:00
|
|
|
next_table = msblk->xattr_table;
|
2011-05-24 05:57:05 +04:00
|
|
|
|
|
|
|
allocate_id_index_table:
|
2009-01-05 11:46:25 +03:00
|
|
|
/* Allocate and read id index table */
|
|
|
|
msblk->id_table = squashfs_read_id_index_table(sb,
|
2021-02-10 00:41:53 +03:00
|
|
|
le64_to_cpu(sblk->id_table_start), next_table, msblk->ids);
|
2009-01-05 11:46:25 +03:00
|
|
|
if (IS_ERR(msblk->id_table)) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "unable to read id index table");
|
2009-01-05 11:46:25 +03:00
|
|
|
err = PTR_ERR(msblk->id_table);
|
|
|
|
msblk->id_table = NULL;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
2011-05-29 03:38:46 +04:00
|
|
|
next_table = le64_to_cpu(msblk->id_table[0]);
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2011-05-24 05:57:05 +04:00
|
|
|
/* Handle inode lookup table */
|
|
|
|
lookup_table_start = le64_to_cpu(sblk->lookup_table_start);
|
|
|
|
if (lookup_table_start == SQUASHFS_INVALID_BLK)
|
|
|
|
goto handle_fragments;
|
|
|
|
|
|
|
|
/* Allocate and read inode lookup table */
|
|
|
|
msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb,
|
2011-05-24 07:15:21 +04:00
|
|
|
lookup_table_start, next_table, msblk->inodes);
|
2011-05-24 05:57:05 +04:00
|
|
|
if (IS_ERR(msblk->inode_lookup_table)) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "unable to read inode lookup table");
|
2011-05-24 05:57:05 +04:00
|
|
|
err = PTR_ERR(msblk->inode_lookup_table);
|
|
|
|
msblk->inode_lookup_table = NULL;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
2011-05-29 03:38:46 +04:00
|
|
|
next_table = le64_to_cpu(msblk->inode_lookup_table[0]);
|
2011-05-24 05:57:05 +04:00
|
|
|
|
|
|
|
sb->s_export_op = &squashfs_export_ops;
|
|
|
|
|
|
|
|
handle_fragments:
|
2018-08-02 18:43:35 +03:00
|
|
|
fragments = msblk->fragments;
|
2009-01-05 11:46:25 +03:00
|
|
|
if (fragments == 0)
|
2011-05-24 07:45:33 +04:00
|
|
|
goto check_directory_table;
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
msblk->fragment_cache = squashfs_cache_init("fragment",
|
|
|
|
SQUASHFS_CACHED_FRAGMENTS, msblk->block_size);
|
|
|
|
if (msblk->fragment_cache == NULL) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and read fragment index table */
|
|
|
|
msblk->fragment_index = squashfs_read_fragment_index_table(sb,
|
2011-05-24 07:33:34 +04:00
|
|
|
le64_to_cpu(sblk->fragment_table_start), next_table, fragments);
|
2009-01-05 11:46:25 +03:00
|
|
|
if (IS_ERR(msblk->fragment_index)) {
|
2019-03-25 19:38:32 +03:00
|
|
|
errorf(fc, "unable to read fragment index table");
|
2009-01-05 11:46:25 +03:00
|
|
|
err = PTR_ERR(msblk->fragment_index);
|
|
|
|
msblk->fragment_index = NULL;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
2011-05-29 03:38:46 +04:00
|
|
|
next_table = le64_to_cpu(msblk->fragment_index[0]);
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2011-05-24 07:45:33 +04:00
|
|
|
check_directory_table:
|
|
|
|
/* Sanity check directory_table */
|
2012-01-02 21:47:14 +04:00
|
|
|
if (msblk->directory_table > next_table) {
|
2011-05-24 07:45:33 +04:00
|
|
|
err = -EINVAL;
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2011-05-24 07:45:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check inode_table */
|
|
|
|
if (msblk->inode_table >= msblk->directory_table) {
|
|
|
|
err = -EINVAL;
|
2019-03-25 19:38:32 +03:00
|
|
|
goto insanity;
|
2011-05-24 07:45:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate root */
|
2009-01-05 11:46:25 +03:00
|
|
|
root = new_inode(sb);
|
|
|
|
if (!root) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = squashfs_read_inode(root, root_inode);
|
|
|
|
if (err) {
|
2010-04-16 04:01:36 +04:00
|
|
|
make_bad_inode(root);
|
|
|
|
iput(root);
|
2009-01-05 11:46:25 +03:00
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
insert_inode_hash(root);
|
|
|
|
|
2012-01-09 07:15:13 +04:00
|
|
|
sb->s_root = d_make_root(root);
|
2009-01-05 11:46:25 +03:00
|
|
|
if (sb->s_root == NULL) {
|
|
|
|
ERROR("Root inode create failed\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto failed_mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Leaving squashfs_fill_super\n");
|
|
|
|
kfree(sblk);
|
|
|
|
return 0;
|
|
|
|
|
2019-03-25 19:38:32 +03:00
|
|
|
insanity:
|
|
|
|
errorf(fc, "squashfs image failed sanity check");
|
2009-01-05 11:46:25 +03:00
|
|
|
failed_mount:
|
|
|
|
squashfs_cache_delete(msblk->block_cache);
|
|
|
|
squashfs_cache_delete(msblk->fragment_cache);
|
|
|
|
squashfs_cache_delete(msblk->read_page);
|
2013-11-13 06:56:26 +04:00
|
|
|
squashfs_decompressor_destroy(msblk);
|
2009-01-05 11:46:25 +03:00
|
|
|
kfree(msblk->inode_lookup_table);
|
|
|
|
kfree(msblk->fragment_index);
|
|
|
|
kfree(msblk->id_table);
|
2010-05-14 23:48:47 +04:00
|
|
|
kfree(msblk->xattr_id_table);
|
2009-01-05 11:46:25 +03:00
|
|
|
kfree(sb->s_fs_info);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
kfree(sblk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-03-25 19:38:32 +03:00
|
|
|
static int squashfs_get_tree(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
return get_tree_bdev(fc, squashfs_fill_super);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int squashfs_reconfigure(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
sync_filesystem(fc->root->d_sb);
|
|
|
|
fc->sb_flags |= SB_RDONLY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations squashfs_context_ops = {
|
|
|
|
.get_tree = squashfs_get_tree,
|
|
|
|
.reconfigure = squashfs_reconfigure,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int squashfs_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
fc->ops = &squashfs_context_ops;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
|
|
{
|
|
|
|
struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
|
2009-04-03 03:59:42 +04:00
|
|
|
u64 id = huge_encode_dev(dentry->d_sb->s_bdev->bd_dev);
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
TRACE("Entered squashfs_statfs\n");
|
|
|
|
|
|
|
|
buf->f_type = SQUASHFS_MAGIC;
|
|
|
|
buf->f_bsize = msblk->block_size;
|
|
|
|
buf->f_blocks = ((msblk->bytes_used - 1) >> msblk->block_log) + 1;
|
|
|
|
buf->f_bfree = buf->f_bavail = 0;
|
|
|
|
buf->f_files = msblk->inodes;
|
|
|
|
buf->f_ffree = 0;
|
|
|
|
buf->f_namelen = SQUASHFS_NAME_LEN;
|
2020-09-18 23:45:50 +03:00
|
|
|
buf->f_fsid = u64_to_fsid(id);
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void squashfs_put_super(struct super_block *sb)
|
|
|
|
{
|
|
|
|
if (sb->s_fs_info) {
|
|
|
|
struct squashfs_sb_info *sbi = sb->s_fs_info;
|
|
|
|
squashfs_cache_delete(sbi->block_cache);
|
|
|
|
squashfs_cache_delete(sbi->fragment_cache);
|
|
|
|
squashfs_cache_delete(sbi->read_page);
|
2013-11-13 06:56:26 +04:00
|
|
|
squashfs_decompressor_destroy(sbi);
|
2009-01-05 11:46:25 +03:00
|
|
|
kfree(sbi->id_table);
|
|
|
|
kfree(sbi->fragment_index);
|
|
|
|
kfree(sbi->meta_index);
|
2010-04-23 03:24:22 +04:00
|
|
|
kfree(sbi->inode_lookup_table);
|
2010-05-14 23:48:47 +04:00
|
|
|
kfree(sbi->xattr_id_table);
|
2009-01-05 11:46:25 +03:00
|
|
|
kfree(sb->s_fs_info);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct kmem_cache *squashfs_inode_cachep;
|
|
|
|
|
|
|
|
|
|
|
|
static void init_once(void *foo)
|
|
|
|
{
|
|
|
|
struct squashfs_inode_info *ei = foo;
|
|
|
|
|
|
|
|
inode_init_once(&ei->vfs_inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int __init init_inodecache(void)
|
|
|
|
{
|
|
|
|
squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
|
|
|
|
sizeof(struct squashfs_inode_info), 0,
|
2016-01-15 02:18:21 +03:00
|
|
|
SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT,
|
|
|
|
init_once);
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
return squashfs_inode_cachep ? 0 : -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void destroy_inodecache(void)
|
|
|
|
{
|
2012-09-26 05:33:07 +04:00
|
|
|
/*
|
|
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
|
|
* destroy cache.
|
|
|
|
*/
|
|
|
|
rcu_barrier();
|
2009-01-05 11:46:25 +03:00
|
|
|
kmem_cache_destroy(squashfs_inode_cachep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int __init init_squashfs_fs(void)
|
|
|
|
{
|
|
|
|
int err = init_inodecache();
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = register_filesystem(&squashfs_fs_type);
|
|
|
|
if (err) {
|
|
|
|
destroy_inodecache();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-08-07 03:03:52 +04:00
|
|
|
pr_info("version 4.0 (2009/01/31) Phillip Lougher\n");
|
2009-01-05 11:46:25 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit exit_squashfs_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&squashfs_fs_type);
|
|
|
|
destroy_inodecache();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct inode *squashfs_alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct squashfs_inode_info *ei =
|
|
|
|
kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
|
|
|
|
|
|
|
|
return ei ? &ei->vfs_inode : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-16 05:22:40 +03:00
|
|
|
static void squashfs_free_inode(struct inode *inode)
|
2009-01-05 11:46:25 +03:00
|
|
|
{
|
|
|
|
kmem_cache_free(squashfs_inode_cachep, squashfs_i(inode));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type squashfs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "squashfs",
|
2019-03-25 19:38:32 +03:00
|
|
|
.init_fs_context = squashfs_init_fs_context,
|
2009-01-05 11:46:25 +03:00
|
|
|
.kill_sb = kill_block_super,
|
|
|
|
.fs_flags = FS_REQUIRES_DEV
|
|
|
|
};
|
2013-03-11 18:05:42 +04:00
|
|
|
MODULE_ALIAS_FS("squashfs");
|
2009-01-05 11:46:25 +03:00
|
|
|
|
2009-09-22 04:01:09 +04:00
|
|
|
static const struct super_operations squashfs_super_ops = {
|
2009-01-05 11:46:25 +03:00
|
|
|
.alloc_inode = squashfs_alloc_inode,
|
2019-04-16 05:22:40 +03:00
|
|
|
.free_inode = squashfs_free_inode,
|
2009-01-05 11:46:25 +03:00
|
|
|
.statfs = squashfs_statfs,
|
|
|
|
.put_super = squashfs_put_super,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_init(init_squashfs_fs);
|
|
|
|
module_exit(exit_squashfs_fs);
|
|
|
|
MODULE_DESCRIPTION("squashfs 4.0, a compressed read-only filesystem");
|
2011-05-26 13:39:56 +04:00
|
|
|
MODULE_AUTHOR("Phillip Lougher <phillip@squashfs.org.uk>");
|
2009-01-05 11:46:25 +03:00
|
|
|
MODULE_LICENSE("GPL");
|