1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
4 #include <linux/list.h>
5 #include <linux/init.h>
6 #include <linux/mtd/mtd.h>
7 +#include <linux/mtd/partitions.h>
8 #include <linux/buffer_head.h>
9 #include <linux/mutex.h>
10 #include <linux/mount.h>
11 @@ -232,10 +233,11 @@ static void block2mtd_free_device(struct
14 /* FIXME: ensure that mtd->size % erase_size == 0 */
15 -static struct block2mtd_dev *add_device(char *devname, int erase_size)
16 +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
18 struct block_device *bdev;
19 struct block2mtd_dev *dev;
20 + struct mtd_partition *part;
24 @@ -273,17 +275,17 @@ static struct block2mtd_dev *add_device(
26 mutex_init(&dev->write_mutex);
28 - /* Setup the MTD structure */
29 - /* make the name contain the block device in */
30 - name = kmalloc(sizeof("block2mtd: ") + strlen(devname) + 1,
35 + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
39 - sprintf(name, "block2mtd: %s", devname);
40 + strcpy(name, mtdname);
43 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
44 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
45 dev->mtd.erasesize = erase_size;
46 dev->mtd.writesize = 1;
47 dev->mtd.type = MTD_RAM;
48 @@ -296,14 +298,17 @@ static struct block2mtd_dev *add_device(
50 dev->mtd.owner = THIS_MODULE;
52 - if (add_mtd_device(&dev->mtd)) {
53 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
54 + part->name = dev->mtd.name;
56 + part->size = dev->mtd.size;
57 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
58 /* Device didnt get added, so free the entry */
61 list_add(&dev->list, &blkmtd_device_list);
62 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
63 - dev->mtd.name + strlen("block2mtd: "),
64 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
65 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
69 @@ -376,9 +381,9 @@ static char block2mtd_paramline[80 + 12]
71 static int block2mtd_setup2(const char *val)
73 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
74 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
79 size_t erase_size = PAGE_SIZE;
81 @@ -389,7 +394,7 @@ static int block2mtd_setup2(const char *
83 kill_final_newline(str);
85 - for (i = 0; i < 2; i++)
86 + for (i = 0; i < 3; i++)
87 token[i] = strsep(&str, ",");
90 @@ -408,8 +413,10 @@ static int block2mtd_setup2(const char *
91 parse_err("illegal erase size");
94 + if (token[2] && (strlen(token[2]) + 1 > 80))
95 + parse_err("mtd device name too long");
97 - add_device(name, erase_size);
98 + add_device(name, erase_size, token[2]);
102 @@ -443,7 +450,7 @@ static int block2mtd_setup(const char *v
105 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
106 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
107 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
109 static int __init block2mtd_init(void)
111 --- a/fs/partitions/check.c
112 +++ b/fs/partitions/check.c
113 @@ -637,6 +637,7 @@ try_scan:
117 +EXPORT_SYMBOL(rescan_partitions);
119 unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)