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,11 +233,12 @@ 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 const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
19 struct block_device *bdev;
20 struct block2mtd_dev *dev;
21 + struct mtd_partition *part;
25 @@ -275,13 +277,16 @@ static struct block2mtd_dev *add_device(
27 /* Setup the MTD structure */
28 /* make the name contain the block device in */
29 - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
32 + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
36 + strcpy(name, mtdname);
39 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
40 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
41 dev->mtd.erasesize = erase_size;
42 dev->mtd.writesize = 1;
43 dev->mtd.type = MTD_RAM;
44 @@ -294,14 +299,17 @@ static struct block2mtd_dev *add_device(
46 dev->mtd.owner = THIS_MODULE;
48 - if (add_mtd_device(&dev->mtd)) {
49 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
52 + part->size = dev->mtd.size;
53 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
54 /* Device didnt get added, so free the entry */
57 list_add(&dev->list, &blkmtd_device_list);
58 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
59 - dev->mtd.name + strlen("block2mtd: "),
60 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
61 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
65 @@ -374,9 +382,9 @@ static char block2mtd_paramline[80 + 12]
67 static int block2mtd_setup2(const char *val)
69 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
70 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
75 size_t erase_size = PAGE_SIZE;
77 @@ -387,7 +395,7 @@ static int block2mtd_setup2(const char *
79 kill_final_newline(str);
81 - for (i = 0; i < 2; i++)
82 + for (i = 0; i < 3; i++)
83 token[i] = strsep(&str, ",");
86 @@ -406,8 +414,10 @@ static int block2mtd_setup2(const char *
87 parse_err("illegal erase size");
90 + if (token[2] && (strlen(token[2]) + 1 > 80))
91 + parse_err("mtd device name too long");
93 - add_device(name, erase_size);
94 + add_device(name, erase_size, token[2]);
98 @@ -441,7 +451,7 @@ static int block2mtd_setup(const char *v
101 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
102 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
103 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
105 static int __init block2mtd_init(void)
107 --- a/fs/partitions/check.c
108 +++ b/fs/partitions/check.c
109 @@ -663,6 +663,7 @@ rescan:
113 +EXPORT_SYMBOL(rescan_partitions);
115 unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)