4617bf41701740a308f27fd8c534459fa83eb93d
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.12 / 440-block2mtd_init.patch
1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
3 @@ -17,6 +17,7 @@
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/mutex.h>
9 #include <linux/mount.h>
10 #include <linux/slab.h>
11 @@ -209,11 +210,12 @@ static void block2mtd_free_device(struct
12
13
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)
17 {
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;
22 char *name;
23
24 if (!devname)
25 @@ -252,13 +254,16 @@ static struct block2mtd_dev *add_device(
26
27 /* Setup the MTD structure */
28 /* make the name contain the block device in */
29 - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
30 + if (!mtdname)
31 + mtdname = devname;
32 + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
33 if (!name)
34 goto devinit_err;
35
36 + strcpy(name, mtdname);
37 dev->mtd.name = name;
38
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.writebufsize = PAGE_SIZE;
44 @@ -271,15 +276,18 @@ static struct block2mtd_dev *add_device(
45 dev->mtd.priv = dev;
46 dev->mtd.owner = THIS_MODULE;
47
48 - if (mtd_device_register(&dev->mtd, NULL, 0)) {
49 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
50 + part->name = name;
51 + part->offset = 0;
52 + part->size = dev->mtd.size;
53 + if (mtd_device_register(&dev->mtd, part, 1)) {
54 /* Device didn't get added, so free the entry */
55 goto devinit_err;
56 }
57 list_add(&dev->list, &blkmtd_device_list);
58 pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
59 dev->mtd.index,
60 - dev->mtd.name + strlen("block2mtd: "),
61 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
62 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
63 return dev;
64
65 devinit_err:
66 @@ -346,9 +354,9 @@ static char block2mtd_paramline[80 + 12]
67
68 static int block2mtd_setup2(const char *val)
69 {
70 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
71 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
72 char *str = buf;
73 - char *token[2];
74 + char *token[3];
75 char *name;
76 size_t erase_size = PAGE_SIZE;
77 int i, ret;
78 @@ -361,7 +369,7 @@ static int block2mtd_setup2(const char *
79 strcpy(str, val);
80 kill_final_newline(str);
81
82 - for (i = 0; i < 2; i++)
83 + for (i = 0; i < 3; i++)
84 token[i] = strsep(&str, ",");
85
86 if (str) {
87 @@ -387,8 +395,10 @@ static int block2mtd_setup2(const char *
88 return 0;
89 }
90 }
91 + if (token[2] && (strlen(token[2]) + 1 > 80))
92 + parse_err("mtd device name too long");
93
94 - add_device(name, erase_size);
95 + add_device(name, erase_size, token[2]);
96
97 return 0;
98 }
99 @@ -422,7 +432,7 @@ static int block2mtd_setup(const char *v
100
101
102 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
103 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
104 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
105
106 static int __init block2mtd_init(void)
107 {
108 --- a/block/partition-generic.c
109 +++ b/block/partition-generic.c
110 @@ -548,6 +548,7 @@ int invalidate_partitions(struct gendisk
111
112 return 0;
113 }
114 +EXPORT_SYMBOL(rescan_partitions);
115
116 unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
117 {