--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -45,6 +45,16 @@
+@@ -45,6 +45,16 @@ config MTD_PARTITIONS
devices. Partitioning on NFTL 'devices' is a different - that's the
'normal' form of partitioning used on a block device.
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
-@@ -37,7 +39,7 @@
+@@ -37,7 +39,7 @@ struct mtd_part {
* the pointer to that structure with this macro.
*/
#define PART(x) ((struct mtd_part *)(x))
/*
* MTD methods which simply translate the effective address and pass through
-@@ -489,6 +491,148 @@
+@@ -489,6 +491,147 @@ out_register:
return slave;
}
+#define ROOTFS_REMOVED_NAME "<removed>"
+static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
+{
-+ char buf[512];
-+ struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
++ struct squashfs_super_block sb;
+ int len, ret;
+
-+ ret = master->read(master, offset, sizeof(*sb), &len, buf);
-+ if (ret || (len != sizeof(*sb))) {
++ ret = master->read(master, offset, sizeof(sb), &len, (void *) &sb);
++ if (ret || (len != sizeof(sb))) {
+ printk(KERN_ALERT "split_squashfs: error occured while reading "
+ "from \"%s\"\n", master->name);
+ return -EINVAL;
+ }
+
-+ if (*((u32 *) buf) != SQUASHFS_MAGIC) {
++ if (sb.s_magic != SQUASHFS_MAGIC) {
+ printk(KERN_ALERT "split_squashfs: no squashfs found in \"%s\"\n",
+ master->name);
+ *split_offset = 0;
+ return 0;
+ }
+
-+ if (sb->bytes_used <= 0) {
++ if (sb.bytes_used <= 0) {
+ printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
+ master->name);
+ *split_offset = 0;
+ return 0;
+ }
+
-+ len = (u32) sb->bytes_used;
++ len = (u32) sb.bytes_used;
+ len += (offset & 0x000fffff);
+ len += (master->erasesize - 1);
+ len &= ~(master->erasesize - 1);
/*
* This function, given a master MTD object and a partition table, creates
* and registers slave MTD objects which are bound to the master according to
-@@ -502,14 +646,29 @@
+@@ -502,14 +645,29 @@ int add_mtd_partitions(struct mtd_info *
{
struct mtd_part *slave;
u_int32_t cur_offset = 0;
cur_offset = slave->offset + slave->mtd.size;
}
-@@ -517,6 +676,32 @@
+@@ -517,6 +675,32 @@ int add_mtd_partitions(struct mtd_info *
}
EXPORT_SYMBOL(add_mtd_partitions);
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
-@@ -29,6 +29,8 @@
+@@ -29,6 +29,8 @@ struct block2mtd_dev {
struct block_device *blkdev;
struct mtd_info mtd;
struct mutex write_mutex;
};
-@@ -81,6 +83,12 @@
+@@ -81,6 +83,12 @@ static int block2mtd_erase(struct mtd_in
size_t len = instr->len;
int err;
instr->state = MTD_ERASING;
mutex_lock(&dev->write_mutex);
err = _block2mtd_erase(dev, from, len);
-@@ -93,6 +101,10 @@
+@@ -93,6 +101,10 @@ static int block2mtd_erase(struct mtd_in
instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr);
return err;
}
-@@ -104,10 +116,14 @@
+@@ -104,10 +116,14 @@ static int block2mtd_read(struct mtd_inf
struct page *page;
int index = from >> PAGE_SHIFT;
int offset = from & (PAGE_SIZE-1);
if (from + len > mtd->size)
len = mtd->size - from;
-@@ -122,10 +138,14 @@
+@@ -122,10 +138,14 @@ static int block2mtd_read(struct mtd_inf
len = len - cpylen;
page = page_read(dev->blkdev->bd_inode->i_mapping, index);
memcpy(buf, page_address(page) + offset, cpylen);
page_cache_release(page);
-@@ -136,7 +156,10 @@
+@@ -136,7 +156,10 @@ static int block2mtd_read(struct mtd_inf
offset = 0;
index++;
}
}
-@@ -188,12 +211,22 @@
+@@ -188,12 +211,22 @@ static int block2mtd_write(struct mtd_in
size_t *retlen, const u_char *buf)
{
struct block2mtd_dev *dev = mtd->priv;
if (to + len > mtd->size)
len = mtd->size - to;
-@@ -202,6 +235,9 @@
+@@ -202,6 +235,9 @@ static int block2mtd_write(struct mtd_in
mutex_unlock(&dev->write_mutex);
if (err > 0)
err = 0;
return err;
}
-@@ -210,7 +246,12 @@
+@@ -210,52 +246,29 @@ static int block2mtd_write(struct mtd_in
static void block2mtd_sync(struct mtd_info *mtd)
{
struct block2mtd_dev *dev = mtd->priv;
- sync_blockdev(dev->blkdev);
-+
+- return;
+-}
+-
+-
+-static void block2mtd_free_device(struct block2mtd_dev *dev)
+-{
+- if (!dev)
+- return;
+-
+- kfree(dev->mtd.name);
+
+- if (dev->blkdev) {
+- invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
+- 0, -1);
+- close_bdev_excl(dev->blkdev);
+- }
+ read_lock(&dev->bdev_mutex);
+ if (dev->blkdev)
+ sync_blockdev(dev->blkdev);
+ read_unlock(&dev->bdev_mutex);
-+
- return;
- }
-@@ -231,31 +272,22 @@
- kfree(dev);
+- kfree(dev);
++ return;
}
--
+
-/* FIXME: ensure that mtd->size % erase_size == 0 */
-static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
+static int _open_bdev(struct block2mtd_dev *dev)
{
struct block_device *bdev;
- struct block2mtd_dev *dev;
- struct mtd_partition *part;
- char *name;
-
+- struct block2mtd_dev *dev;
+- struct mtd_partition *part;
+- char *name;
+-
- if (!devname)
- return NULL;
-
- dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
- if (!dev)
- return NULL;
--
+
/* Get a handle on the device */
- bdev = open_bdev_excl(devname, O_RDWR, NULL);
+ bdev = open_bdev_excl(dev->devname, O_RDWR, NULL);
if (devt) {
bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ);
}
-@@ -263,17 +295,96 @@
+@@ -263,17 +276,97 @@ static struct block2mtd_dev *add_device(
#endif
if (IS_ERR(bdev)) {
+{
+ struct block2mtd_dev *dev;
+ struct mtd_partition *part;
++ char *name;
+
+ if (!devname)
+ return NULL;
if (!mtdname)
mtdname = devname;
-@@ -297,6 +408,7 @@
+@@ -297,6 +390,7 @@ static struct block2mtd_dev *add_device(
dev->mtd.read = block2mtd_read;
dev->mtd.priv = dev;
dev->mtd.owner = THIS_MODULE;
#include <asm/uaccess.h>
-@@ -771,6 +772,13 @@
+@@ -771,6 +772,13 @@ static int mtd_ioctl(struct inode *inode
file->f_pos = 0;
break;
}
ret = -ENOTTY;
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
-@@ -96,6 +96,7 @@
+@@ -96,6 +96,7 @@ struct mtd_oob_ops {
uint8_t *oobbuf;
};
struct mtd_info {
u_char type;
u_int32_t flags;
-@@ -211,6 +212,9 @@
+@@ -211,6 +212,9 @@ struct mtd_info {
struct module *owner;
int usecount;
struct mtd_partition {
char *name; /* identifier string */
u_int32_t size; /* partition size */
-@@ -41,6 +42,7 @@
+@@ -41,6 +42,7 @@ struct mtd_partition {
u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
struct mtd_info **mtdp; /* pointer to store the MTD object */
};
#define MTDPART_OFS_NXTBLK (-2)
-@@ -50,6 +52,7 @@
+@@ -50,6 +52,7 @@ struct mtd_partition {
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
int del_mtd_partitions(struct mtd_info *);
* Functions dealing with the various ways of partitioning the space
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
-@@ -93,6 +93,7 @@
+@@ -93,6 +93,7 @@ struct otp_info {
#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
#define MTDFILEMODE _IO('M', 19)