1 diff -urN linux.old/drivers/mtd/devices/block2mtd.c linux.dev/drivers/mtd/devices/block2mtd.c
2 --- linux.old/drivers/mtd/devices/block2mtd.c 2006-07-29 19:53:54.000000000 +0200
3 +++ linux.dev/drivers/mtd/devices/block2mtd.c 2006-07-29 19:47:03.000000000 +0200
5 * block2mtd.c - create an mtd from a block device
7 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk>
8 - * Copyright (C) 2004,2005 Jörn Engel <joern@wh.fh-wedel.de>
9 + * Copyright (C) 2004-2006 Jörn Engel <joern@wh.fh-wedel.de>
13 -#include <linux/config.h>
14 #include <linux/module.h>
16 #include <linux/blkdev.h>
17 @@ -19,6 +18,7 @@ #include <linux/init.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/buffer_head.h>
20 #include <linux/mutex.h>
21 +#include <linux/mount.h>
23 #define VERSION "$Revision: 1.30 $"
26 read_lock_irq(&mapping->tree_lock);
27 for (i = 0; i < PAGE_READAHEAD; i++) {
29 - if (pagei > end_index) {
30 - INFO("Overrun end of disk in cache readahead\n");
31 + if (pagei > end_index)
34 page = radix_tree_lookup(&mapping->page_tree, pagei);
37 @@ -237,6 +237,8 @@ static int _block2mtd_write(struct block
43 static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
44 size_t *retlen, const u_char *buf)
46 @@ -300,6 +302,19 @@ static struct block2mtd_dev *add_device(
48 /* Get a handle on the device */
49 bdev = open_bdev_excl(devname, O_RDWR, NULL);
53 + /* We might not have rootfs mounted at this point. Try
54 + to resolve the device name by other means. */
56 + dev_t dev = name_to_dev_t(devname);
58 + bdev = open_by_devnum(dev, FMODE_WRITE | FMODE_READ);
64 ERROR("error: cannot open device %s", devname);
66 @@ -331,7 +347,6 @@ static struct block2mtd_dev *add_device(
67 dev->mtd.writev = default_mtd_writev;
68 dev->mtd.sync = block2mtd_sync;
69 dev->mtd.read = block2mtd_read;
70 - dev->mtd.readv = default_mtd_readv;
72 dev->mtd.owner = THIS_MODULE;
74 @@ -351,6 +366,12 @@ devinit_err:
78 +/* This function works similar to reguler strtoul. In addition, it
79 + * allows some suffixes for a more human-readable number format:
80 + * ki, Ki, kiB, KiB - multiply result with 1024
81 + * Mi, MiB - multiply result with 1024^2
82 + * Gi, GiB - multiply result with 1024^3
84 static int ustrtoul(const char *cp, char **endp, unsigned int base)
86 unsigned long result = simple_strtoul(cp, endp, base);
87 @@ -359,11 +380,16 @@ static int ustrtoul(const char *cp, char
94 /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
95 - if ((*endp)[1] == 'i')
97 + if ((*endp)[1] == 'i') {
98 + if ((*endp)[2] == 'B')
106 @@ -383,26 +409,6 @@ static int parse_num(size_t *num, const
110 -static int parse_name(char **pname, const char *token, size_t limit)
115 - len = strlen(token) + 1;
119 - name = kmalloc(len, GFP_KERNEL);
123 - strcpy(name, token);
130 static inline void kill_final_newline(char *str)
132 char *newline = strrchr(str, '\n');
133 @@ -416,9 +422,16 @@ #define parse_err(fmt, args...) do { \
137 -static int block2mtd_setup(const char *val, struct kernel_param *kp)
139 +static int block2mtd_init_called = 0;
140 +static __initdata char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
144 +static int block2mtd_setup2(const char *val)
146 - char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */
147 + char buf[80 + 12]; /* 80 for device, 12 for erase size */
151 size_t erase_size = PAGE_SIZE;
152 @@ -430,7 +443,7 @@ static int block2mtd_setup(const char *v
154 kill_final_newline(str);
156 - for (i=0; i<2; i++)
157 + for (i = 0; i < 2; i++)
158 token[i] = strsep(&str, ",");
161 @@ -439,18 +452,16 @@ static int block2mtd_setup(const char *v
163 parse_err("no argument");
165 - ret = parse_name(&name, token[0], 80);
166 - if (ret == -ENOMEM)
167 - parse_err("out of memory");
168 - if (ret == -ENOSPC)
169 - parse_err("name too long");
173 + if (strlen(name) + 1 > 80)
174 + parse_err("device name too long");
177 ret = parse_num(&erase_size, token[1]);
181 parse_err("illegal erase size");
185 add_device(name, erase_size);
186 @@ -459,13 +470,48 @@ static int block2mtd_setup(const char *v
190 +static int block2mtd_setup(const char *val, struct kernel_param *kp)
193 + return block2mtd_setup2(val);
195 + /* If more parameters are later passed in via
196 + /sys/module/block2mtd/parameters/block2mtd
197 + and block2mtd_init() has already been called,
198 + we can parse the argument now. */
200 + if (block2mtd_init_called)
201 + return block2mtd_setup2(val);
203 + /* During early boot stage, we only save the parameters
204 + here. We must parse them later: if the param passed
205 + from kernel boot command line, block2mtd_setup() is
206 + called so early that it is not possible to resolve
207 + the device (even kmalloc() fails). Deter that work to
208 + block2mtd_setup2(). */
210 + strlcpy(block2mtd_paramline, val, sizeof(block2mtd_paramline));
217 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
218 MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
220 static int __init block2mtd_init(void)
223 INFO("version " VERSION);
227 + if (strlen(block2mtd_paramline))
228 + ret = block2mtd_setup2(block2mtd_paramline);
229 + block2mtd_init_called = 1;