[brcm63xx] rename 96348GW-1{0,1}-gen to 96348GW-1{0,1}-generic
[openwrt.git] / target / linux / generic / patches-3.2 / 440-block2mtd_init.patch
1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
3 @@ -14,6 +14,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/buffer_head.h>
9 #include <linux/mutex.h>
10 #include <linux/mount.h>
11 @@ -232,11 +233,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 @@ -275,13 +277,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.type = MTD_RAM;
44 @@ -294,14 +299,17 @@ 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 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);
62 return dev;
63
64 devinit_err:
65 @@ -374,9 +382,9 @@ static char block2mtd_paramline[80 + 12]
66
67 static int block2mtd_setup2(const char *val)
68 {
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 */
71 char *str = buf;
72 - char *token[2];
73 + char *token[3];
74 char *name;
75 size_t erase_size = PAGE_SIZE;
76 int i, ret;
77 @@ -387,7 +395,7 @@ static int block2mtd_setup2(const char *
78 strcpy(str, val);
79 kill_final_newline(str);
80
81 - for (i = 0; i < 2; i++)
82 + for (i = 0; i < 3; i++)
83 token[i] = strsep(&str, ",");
84
85 if (str)
86 @@ -406,8 +414,10 @@ static int block2mtd_setup2(const char *
87 parse_err("illegal erase size");
88 }
89 }
90 + if (token[2] && (strlen(token[2]) + 1 > 80))
91 + parse_err("mtd device name too long");
92
93 - add_device(name, erase_size);
94 + add_device(name, erase_size, token[2]);
95
96 return 0;
97 }
98 @@ -441,7 +451,7 @@ static int block2mtd_setup(const char *v
99
100
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>]]\"");
104
105 static int __init block2mtd_init(void)
106 {
107 --- a/fs/partitions/check.c
108 +++ b/fs/partitions/check.c
109 @@ -664,6 +664,7 @@ rescan:
110 kfree(state);
111 return 0;
112 }
113 +EXPORT_SYMBOL(rescan_partitions);
114
115 unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
116 {
This page took 0.043189 seconds and 5 git commands to generate.