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 @@ -233,10 +234,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 @@ -276,13 +278,16 @@ static struct block2mtd_dev *add_device(
26 /* Setup the MTD structure */
27 /* make the name contain the block device in */
28 - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
31 + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
35 + strcpy(name, mtdname);
38 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
39 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
40 dev->mtd.erasesize = erase_size;
41 dev->mtd.writesize = 1;
42 dev->mtd.type = MTD_RAM;
43 @@ -295,14 +300,17 @@ static struct block2mtd_dev *add_device(
45 dev->mtd.owner = THIS_MODULE;
47 - if (add_mtd_device(&dev->mtd)) {
48 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
49 + part->name = dev->mtd.name;
51 + part->size = dev->mtd.size;
52 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
53 /* Device didnt get added, so free the entry */
56 list_add(&dev->list, &blkmtd_device_list);
57 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
58 - dev->mtd.name + strlen("block2mtd: "),
59 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
60 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
64 @@ -375,9 +383,9 @@ static char block2mtd_paramline[80 + 12]
66 static int block2mtd_setup2(const char *val)
68 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
69 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
74 size_t erase_size = PAGE_SIZE;
76 @@ -388,7 +396,7 @@ static int block2mtd_setup2(const char *
78 kill_final_newline(str);
80 - for (i = 0; i < 2; i++)
81 + for (i = 0; i < 3; i++)
82 token[i] = strsep(&str, ",");
85 @@ -407,8 +415,10 @@ static int block2mtd_setup2(const char *
86 parse_err("illegal erase size");
89 + if (token[2] && (strlen(token[2]) + 1 > 80))
90 + parse_err("mtd device name too long");
92 - add_device(name, erase_size);
93 + add_device(name, erase_size, token[2]);
97 @@ -442,7 +452,7 @@ static int block2mtd_setup(const char *v
100 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
101 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
102 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
104 static int __init block2mtd_init(void)
106 --- a/fs/partitions/check.c
107 +++ b/fs/partitions/check.c
108 @@ -639,6 +639,7 @@ try_scan:
112 +EXPORT_SYMBOL(rescan_partitions);
114 unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)