++
++#ifdef CONFIG_MTD_ROOTFS_SPLIT
++#define ROOTFS_SPLIT_NAME "rootfs_data"
++static int split_squashfs(struct mtd_info *master, struct mtd_partition *old,
++ struct mtd_partition **new)
++{
++ struct mtd_partition *part = NULL;
++ int len;
++ char buf[512];
++ struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
++ int ret;
++
++ ret = master->read(master, old->offset, sizeof(*sb), &len, buf);
++ if (ret) {
++ printk(KERN_ALERT "split_squashfs: error occured while reading "
++ "from \"%s\"\n", master->name);
++ goto out;
++ }
++
++ if (len != sizeof(*sb)) {
++ printk(KERN_ALERT "split_squashfs: unable to read superblock "
++ "from \"%s\"\n", master->name);
++ ret=-1;
++ goto out;
++ }
++
++ if (*((u32 *) buf) != SQUASHFS_MAGIC) {
++ printk(KERN_ALERT "split_squasfs: no squashfs found in \"%s\"\n",
++ master->name);
++ ret=0;
++ goto out;
++ }
++
++ if (sb->bytes_used <= 0) {
++ printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
++ master->name);
++ ret=0;
++ goto out;
++ }
++
++ part = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
++ if (part == NULL) {
++ printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
++ ROOTFS_SPLIT_NAME);
++ ret = -ENOMEM;
++ goto out;
++ }
++
++ part->name = (unsigned char *)&part[1];
++ memcpy(part, old, sizeof(*part));
++ strcpy(part->name, ROOTFS_SPLIT_NAME);
++
++ len = (u32) sb->bytes_used;
++ len += (part->offset & 0x000fffff);
++ len += (master->erasesize - 1);
++ len &= ~(master->erasesize - 1);
++ len -= (part->offset & 0x000fffff);
++ part->offset += len;
++ part->size -= len;
++
++ ret = 0;
++
++out:
++ *new = part;
++ return ret;
++}
++
++static int split_rootfs_data(struct mtd_info *master, struct mtd_partition *part,
++ int index)
++{
++ struct mtd_partition *dpart;
++ int ret;
++
++ ret = split_squashfs(master, part, &dpart);
++ if (ret)
++ return ret;
++
++ if (dpart == NULL)
++ return 1;
++
++ printk(KERN_INFO "mtd: \"%s\" created, ofs=%lX, len=%lX \n",
++ ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
++
++ ret = add_one_partition(master, dpart, index, NULL);
++ if (ret)
++ kfree(dpart);
++
++ return ret;
++}
++#endif /* CONFIG_MTD_ROOTFS_SPLIT */