--- zzzz-none-000/linux-4.4.271/fs/squashfs/super.c 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/fs/squashfs/super.c 2023-04-19 10:22:30.000000000 +0000 @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #include "squashfs_fs.h" #include "squashfs_fs_sb.h" @@ -113,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; } @@ -121,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", @@ -131,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; @@ -160,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; @@ -169,16 +176,16 @@ 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); - msblk->fragments = le32_to_cpu(sblk->fragments); - msblk->ids = le16_to_cpu(sblk->no_ids); - 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); + msblk->fragments = squash_le32_to_cpu(sblk->fragments); + msblk->ids = squash_le16_to_cpu(sblk->no_ids); + 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) @@ -193,9 +200,9 @@ 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; @@ -225,7 +232,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; @@ -246,17 +253,17 @@ 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, msblk->ids); + squash_le64_to_cpu(sblk->id_table_start), next_table, msblk->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; @@ -269,7 +276,7 @@ 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; @@ -287,14 +294,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 */ @@ -398,10 +405,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); }