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>
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, char *mtdname)
18 struct block_device *bdev;
19 struct block2mtd_dev *dev;
20 + struct mtd_partition *part;
26 /* Setup the MTD structure */
27 /* make the name contain the block device in */
28 - dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
34 + dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
39 - sprintf(dev->mtd.name, "block2mtd: %s", devname);
40 + strcpy(dev->mtd.name, mtdname);
42 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
43 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
44 dev->mtd.erasesize = erase_size;
45 dev->mtd.writesize = 1;
46 dev->mtd.type = MTD_RAM;
49 dev->mtd.owner = THIS_MODULE;
51 - if (add_mtd_device(&dev->mtd)) {
52 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
53 + part->name = dev->mtd.name;
55 + part->size = dev->mtd.size;
56 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
57 /* Device didnt get added, so free the entry */
60 list_add(&dev->list, &blkmtd_device_list);
61 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
62 - dev->mtd.name + strlen("block2mtd: "),
63 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
64 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
70 static int block2mtd_setup2(const char *val)
72 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
73 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
78 size_t erase_size = PAGE_SIZE;
82 kill_final_newline(str);
84 - for (i = 0; i < 2; i++)
85 + for (i = 0; i < 3; i++)
86 token[i] = strsep(&str, ",");
90 parse_err("illegal erase size");
93 + if (token[2] && (strlen(token[2]) + 1 > 80))
94 + parse_err("mtd device name too long");
96 - add_device(name, erase_size);
97 + add_device(name, erase_size, token[2]);
104 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
105 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
106 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
108 static int __init block2mtd_init(void)