f2f1b2f7c0890d05a717ac82eeae3e594de99e65
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.25 / 060-block2mtd_init.patch
1 Index: linux-2.6.25.4/drivers/mtd/devices/block2mtd.c
2 ===================================================================
3 --- linux-2.6.25.4.orig/drivers/mtd/devices/block2mtd.c
4 +++ linux-2.6.25.4/drivers/mtd/devices/block2mtd.c
5 @@ -16,6 +16,7 @@
6 #include <linux/list.h>
7 #include <linux/init.h>
8 #include <linux/mtd/mtd.h>
9 +#include <linux/mtd/partitions.h>
10 #include <linux/buffer_head.h>
11 #include <linux/mutex.h>
12 #include <linux/mount.h>
13 @@ -237,10 +238,11 @@ static void block2mtd_free_device(struct
14
15
16 /* FIXME: ensure that mtd->size % erase_size == 0 */
17 -static struct block2mtd_dev *add_device(char *devname, int erase_size)
18 +static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
19 {
20 struct block_device *bdev;
21 struct block2mtd_dev *dev;
22 + struct mtd_partition *part;
23
24 if (!devname)
25 return NULL;
26 @@ -279,14 +281,18 @@ static struct block2mtd_dev *add_device(
27
28 /* Setup the MTD structure */
29 /* make the name contain the block device in */
30 - dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
31 - GFP_KERNEL);
32 +
33 + if (!mtdname)
34 + mtdname = devname;
35 +
36 + dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
37 +
38 if (!dev->mtd.name)
39 goto devinit_err;
40 +
41 + strcpy(dev->mtd.name, mtdname);
42
43 - sprintf(dev->mtd.name, "block2mtd: %s", devname);
44 -
45 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
46 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
47 dev->mtd.erasesize = erase_size;
48 dev->mtd.writesize = 1;
49 dev->mtd.type = MTD_RAM;
50 @@ -298,15 +304,18 @@ static struct block2mtd_dev *add_device(
51 dev->mtd.read = block2mtd_read;
52 dev->mtd.priv = dev;
53 dev->mtd.owner = THIS_MODULE;
54 -
55 - if (add_mtd_device(&dev->mtd)) {
56 +
57 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
58 + part->name = dev->mtd.name;
59 + part->offset = 0;
60 + part->size = dev->mtd.size;
61 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
62 /* Device didnt get added, so free the entry */
63 goto devinit_err;
64 }
65 list_add(&dev->list, &blkmtd_device_list);
66 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
67 - dev->mtd.name + strlen("blkmtd: "),
68 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
69 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
70 return dev;
71
72 devinit_err:
73 @@ -379,9 +388,9 @@ static char block2mtd_paramline[80 + 12]
74
75 static int block2mtd_setup2(const char *val)
76 {
77 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
78 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
79 char *str = buf;
80 - char *token[2];
81 + char *token[3];
82 char *name;
83 size_t erase_size = PAGE_SIZE;
84 int i, ret;
85 @@ -392,7 +401,7 @@ static int block2mtd_setup2(const char *
86 strcpy(str, val);
87 kill_final_newline(str);
88
89 - for (i = 0; i < 2; i++)
90 + for (i = 0; i < 3; i++)
91 token[i] = strsep(&str, ",");
92
93 if (str)
94 @@ -411,8 +420,10 @@ static int block2mtd_setup2(const char *
95 parse_err("illegal erase size");
96 }
97 }
98 + if (token[2] && (strlen(token[2]) + 1 > 80))
99 + parse_err("mtd device name too long");
100
101 - add_device(name, erase_size);
102 + add_device(name, erase_size, token[2]);
103
104 return 0;
105 }
106 @@ -446,7 +457,7 @@ static int block2mtd_setup(const char *v
107
108
109 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
110 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
111 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
112
113 static int __init block2mtd_init(void)
114 {
This page took 0.05154 seconds and 3 git commands to generate.