--- zzzz-none-000/linux-3.10.107/fs/squashfs/super.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/fs/squashfs/super.c 2021-02-04 17:41:59.000000000 +0000 @@ -27,6 +27,8 @@ * the filesystem. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -36,6 +38,9 @@ #include #include #include +#include +#include +#include #include "squashfs_fs.h" #include "squashfs_fs_sb.h" @@ -98,7 +103,6 @@ msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE); msblk->devblksize_log2 = ffz(~msblk->devblksize); - mutex_init(&msblk->read_data_mutex); mutex_init(&msblk->meta_index_mutex); /* @@ -112,7 +116,8 @@ if (IS_ERR(sblk)) { ERROR("unable to read squashfs_super_block\n"); - err = PTR_ERR(sblk); + /*--- err = PTR_ERR(sblk); ---*//*--- JZ-27891 mit err = -EIO wird kein anderes FS mehr gemountet ---*/ + err = -EINVAL; sblk = NULL; goto failed_mount; } @@ -120,7 +125,7 @@ err = -EINVAL; /* Check it is a SQUASHFS superblock */ - sb->s_magic = le32_to_cpu(sblk->s_magic); + sb->s_magic = squash_le32_to_cpu(sblk->s_magic); if (sb->s_magic != SQUASHFS_MAGIC) { if (!silent) ERROR("Can't find a SQUASHFS superblock on %s\n", @@ -130,21 +135,24 @@ /* Check the MAJOR & MINOR versions and lookup compression type */ msblk->decompressor = supported_squashfs_filesystem( - le16_to_cpu(sblk->s_major), - le16_to_cpu(sblk->s_minor), - le16_to_cpu(sblk->compression)); + squash_le16_to_cpu(sblk->s_major), + squash_le16_to_cpu(sblk->s_minor), + squash_le16_to_cpu(sblk->compression)); if (msblk->decompressor == NULL) 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); + msblk->bytes_used = squash_le64_to_cpu(sblk->bytes_used); if (msblk->bytes_used < 0 || msblk->bytes_used > - i_size_read(sb->s_bdev->bd_inode)) + i_size_read(sb->s_bdev->bd_inode)){ + printk("SQFS-Size %llu is to big for given device size %llu. Is mtdram1 too small?\n", + 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); + msblk->block_size = squash_le32_to_cpu(sblk->block_size); if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE) goto failed_mount; @@ -159,7 +167,7 @@ } /* Check block log for sanity */ - msblk->block_log = le16_to_cpu(sblk->block_log); + msblk->block_log = squash_le16_to_cpu(sblk->block_log); if (msblk->block_log > SQUASHFS_FILE_MAX_LOG) goto failed_mount; @@ -168,14 +176,14 @@ goto failed_mount; /* Check the root inode for sanity */ - root_inode = le64_to_cpu(sblk->root_inode); + root_inode = squash_le64_to_cpu(sblk->root_inode); if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE) goto failed_mount; - 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); - flags = le16_to_cpu(sblk->flags); + msblk->inode_table = squash_le64_to_cpu(sblk->inode_table_start); + msblk->directory_table = squash_le64_to_cpu(sblk->directory_table_start); + msblk->inodes = squash_le32_to_cpu(sblk->inodes); + flags = squash_le16_to_cpu(sblk->flags); TRACE("Found valid superblock on %s\n", bdevname(sb->s_bdev, b)); TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(flags) @@ -185,14 +193,14 @@ 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); - TRACE("Number of fragments %d\n", le32_to_cpu(sblk->fragments)); - TRACE("Number of ids %d\n", le16_to_cpu(sblk->no_ids)); + TRACE("Number of fragments %d\n", squash_le32_to_cpu(sblk->fragments)); + TRACE("Number of ids %d\n", squash_le16_to_cpu(sblk->no_ids)); 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)); + (u64) squash_le64_to_cpu(sblk->fragment_table_start)); TRACE("sblk->id_table_start %llx\n", - (u64) le64_to_cpu(sblk->id_table_start)); + (u64) squash_le64_to_cpu(sblk->id_table_start)); sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_flags |= MS_RDONLY; @@ -206,13 +214,14 @@ goto failed_mount; /* Allocate read_page block */ - msblk->read_page = squashfs_cache_init("data", 1, msblk->block_size); + msblk->read_page = squashfs_cache_init("data", + squashfs_max_decompressors(), msblk->block_size); if (msblk->read_page == NULL) { ERROR("Failed to allocate read_page block\n"); goto failed_mount; } - msblk->stream = squashfs_decompressor_init(sb, flags); + msblk->stream = squashfs_decompressor_setup(sb, flags); if (IS_ERR(msblk->stream)) { err = PTR_ERR(msblk->stream); msblk->stream = NULL; @@ -221,7 +230,7 @@ /* Handle xattrs */ sb->s_xattr = squashfs_xattr_handlers; - xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start); + xattr_id_table_start = squash_le64_to_cpu(sblk->xattr_id_table_start); if (xattr_id_table_start == SQUASHFS_INVALID_BLK) { next_table = msblk->bytes_used; goto allocate_id_index_table; @@ -242,18 +251,18 @@ allocate_id_index_table: /* Allocate and read id index table */ msblk->id_table = squashfs_read_id_index_table(sb, - le64_to_cpu(sblk->id_table_start), next_table, - le16_to_cpu(sblk->no_ids)); + squash_le64_to_cpu(sblk->id_table_start), next_table, + squash_le16_to_cpu(sblk->no_ids)); if (IS_ERR(msblk->id_table)) { ERROR("unable to read id index table\n"); err = PTR_ERR(msblk->id_table); msblk->id_table = NULL; goto failed_mount; } - next_table = le64_to_cpu(msblk->id_table[0]); + next_table = squash_le64_to_cpu(msblk->id_table[0]); /* Handle inode lookup table */ - lookup_table_start = le64_to_cpu(sblk->lookup_table_start); + lookup_table_start = squash_le64_to_cpu(sblk->lookup_table_start); if (lookup_table_start == SQUASHFS_INVALID_BLK) goto handle_fragments; @@ -266,12 +275,12 @@ msblk->inode_lookup_table = NULL; goto failed_mount; } - next_table = le64_to_cpu(msblk->inode_lookup_table[0]); + next_table = squash_le64_to_cpu(msblk->inode_lookup_table[0]); sb->s_export_op = &squashfs_export_ops; handle_fragments: - fragments = le32_to_cpu(sblk->fragments); + fragments = squash_le32_to_cpu(sblk->fragments); if (fragments == 0) goto check_directory_table; @@ -284,14 +293,14 @@ /* Allocate and read fragment index table */ msblk->fragment_index = squashfs_read_fragment_index_table(sb, - le64_to_cpu(sblk->fragment_table_start), next_table, fragments); + squash_le64_to_cpu(sblk->fragment_table_start), next_table, fragments); if (IS_ERR(msblk->fragment_index)) { ERROR("unable to read fragment index table\n"); err = PTR_ERR(msblk->fragment_index); msblk->fragment_index = NULL; goto failed_mount; } - next_table = le64_to_cpu(msblk->fragment_index[0]); + next_table = squash_le64_to_cpu(msblk->fragment_index[0]); check_directory_table: /* Sanity check directory_table */ @@ -336,7 +345,7 @@ squashfs_cache_delete(msblk->block_cache); squashfs_cache_delete(msblk->fragment_cache); squashfs_cache_delete(msblk->read_page); - squashfs_decompressor_free(msblk, msblk->stream); + squashfs_decompressor_destroy(msblk); kfree(msblk->inode_lookup_table); kfree(msblk->fragment_index); kfree(msblk->id_table); @@ -371,6 +380,7 @@ static int squashfs_remount(struct super_block *sb, int *flags, char *data) { + sync_filesystem(sb); *flags |= MS_RDONLY; return 0; } @@ -383,7 +393,7 @@ squashfs_cache_delete(sbi->block_cache); squashfs_cache_delete(sbi->fragment_cache); squashfs_cache_delete(sbi->read_page); - squashfs_decompressor_free(sbi, sbi->stream); + squashfs_decompressor_destroy(sbi); kfree(sbi->id_table); kfree(sbi->fragment_index); kfree(sbi->meta_index); @@ -394,10 +404,36 @@ } } +/* copy from init/do_mounts.h */ +static inline int create_dev(char *name, dev_t dev) +{ + sys_unlink(name); + return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev)); +} + static struct dentry *squashfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { + char dev[32]; + + if (!strncmp(dev_name, "mtd:", 4) || !strncmp(dev_name, "ubi:", 4)) { + struct mtd_info *mtd = get_mtd_device_nm(dev_name + 4); + + if (!IS_ERR(mtd)) { + void *bdev; + + sprintf(dev, "/dev/mtdblock%d", mtd->index); + bdev = blkdev_get_by_path(dev, FMODE_READ, fs_type); + if (!IS_ERR(bdev)) { + dev_name = dev; + } else if (PTR_ERR(bdev) == -ENOENT) { + create_dev(dev, + MKDEV(MTD_BLOCK_MAJOR, mtd->index)); + dev_name = dev; + } + } + } return mount_bdev(fs_type, flags, dev_name, data, squashfs_fill_super); } @@ -447,8 +483,7 @@ return err; } - printk(KERN_INFO "squashfs: version 4.0 (2009/01/31) " - "Phillip Lougher\n"); + pr_info("version 4.0 (2009/01/31) Phillip Lougher\n"); return 0; }