1 Index: linux-2.6.25.1/drivers/mtd/Kconfig
2 ===================================================================
3 --- linux-2.6.25.1.orig/drivers/mtd/Kconfig
4 +++ linux-2.6.25.1/drivers/mtd/Kconfig
5 @@ -47,6 +47,16 @@ config MTD_PARTITIONS
6 devices. Partitioning on NFTL 'devices' is a different - that's the
7 'normal' form of partitioning used on a block device.
9 +config MTD_ROOTFS_ROOT_DEV
10 + bool "Automatically set 'rootfs' partition to be root filesystem"
11 + depends on MTD_PARTITIONS
14 +config MTD_ROOTFS_SPLIT
15 + bool "Automatically split 'rootfs' partition for squashfs"
16 + depends on MTD_PARTITIONS
19 config MTD_REDBOOT_PARTS
20 tristate "RedBoot partition table parsing"
21 depends on MTD_PARTITIONS
22 Index: linux-2.6.25.1/drivers/mtd/mtdpart.c
23 ===================================================================
24 --- linux-2.6.25.1.orig/drivers/mtd/mtdpart.c
25 +++ linux-2.6.25.1/drivers/mtd/mtdpart.c
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/compatmac.h>
30 +#include <linux/squashfs_fs.h>
31 +#include <linux/root_dev.h>
33 /* Our partition linked list */
34 static LIST_HEAD(mtd_partitions);
35 @@ -39,7 +41,7 @@ struct mtd_part {
36 * the pointer to that structure with this macro.
38 #define PART(x) ((struct mtd_part *)(x))
40 +#define IS_PART(mtd) (mtd->read == part_read)
43 * MTD methods which simply translate the effective address and pass through
44 @@ -322,6 +324,316 @@ int del_mtd_partitions(struct mtd_info *
48 +static u_int32_t cur_offset = 0;
49 +static int add_one_partition(struct mtd_info *master, const struct mtd_partition *part,
50 + int i, struct mtd_part **slp)
52 + struct mtd_part *slave;
54 + /* allocate the partition structure */
55 + slave = kzalloc (sizeof(*slave), GFP_KERNEL);
57 + printk ("memory allocation error while creating partitions for \"%s\"\n",
59 + del_mtd_partitions(master);
62 + list_add(&slave->list, &mtd_partitions);
64 + /* set up the MTD object for this partition */
65 + slave->mtd.type = master->type;
66 + slave->mtd.flags = master->flags & ~part->mask_flags;
67 + slave->mtd.size = part->size;
68 + slave->mtd.writesize = master->writesize;
69 + slave->mtd.oobsize = master->oobsize;
70 + slave->mtd.oobavail = master->oobavail;
71 + slave->mtd.subpage_sft = master->subpage_sft;
73 + slave->mtd.name = part->name;
74 + slave->mtd.owner = master->owner;
76 + slave->mtd.read = part_read;
77 + slave->mtd.write = part_write;
79 + if (master->panic_write)
80 + slave->mtd.panic_write = part_panic_write;
82 + slave->mtd.refresh_device = part->refresh_partition;
84 + if(master->point && master->unpoint){
85 + slave->mtd.point = part_point;
86 + slave->mtd.unpoint = part_unpoint;
89 + if (master->read_oob)
90 + slave->mtd.read_oob = part_read_oob;
91 + if (master->write_oob)
92 + slave->mtd.write_oob = part_write_oob;
93 + if(master->read_user_prot_reg)
94 + slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
95 + if(master->read_fact_prot_reg)
96 + slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
97 + if(master->write_user_prot_reg)
98 + slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
99 + if(master->lock_user_prot_reg)
100 + slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
101 + if(master->get_user_prot_info)
102 + slave->mtd.get_user_prot_info = part_get_user_prot_info;
103 + if(master->get_fact_prot_info)
104 + slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
106 + slave->mtd.sync = part_sync;
107 + if (!i && master->suspend && master->resume) {
108 + slave->mtd.suspend = part_suspend;
109 + slave->mtd.resume = part_resume;
111 + if (master->writev)
112 + slave->mtd.writev = part_writev;
114 + slave->mtd.lock = part_lock;
115 + if (master->unlock)
116 + slave->mtd.unlock = part_unlock;
117 + if (master->block_isbad)
118 + slave->mtd.block_isbad = part_block_isbad;
119 + if (master->block_markbad)
120 + slave->mtd.block_markbad = part_block_markbad;
121 + slave->mtd.erase = part_erase;
122 + slave->master = master;
123 + slave->offset = part->offset;
126 + if (slave->offset == MTDPART_OFS_APPEND)
127 + slave->offset = cur_offset;
128 + if (slave->offset == MTDPART_OFS_NXTBLK) {
129 + slave->offset = cur_offset;
130 + if ((cur_offset % master->erasesize) != 0) {
131 + /* Round up to next erasesize */
132 + slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
133 + printk(KERN_NOTICE "Moving partition %d: "
134 + "0x%08x -> 0x%08x\n", i,
135 + cur_offset, slave->offset);
138 + if (slave->mtd.size == MTDPART_SIZ_FULL)
139 + slave->mtd.size = master->size - slave->offset;
140 + cur_offset = slave->offset + slave->mtd.size;
142 + printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
143 + slave->offset + slave->mtd.size, slave->mtd.name);
145 + /* let's do some sanity checks */
146 + if (slave->offset >= master->size) {
147 + /* let's register it anyway to preserve ordering */
149 + slave->mtd.size = 0;
150 + printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
153 + if (slave->offset + slave->mtd.size > master->size) {
154 + slave->mtd.size = master->size - slave->offset;
155 + printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
156 + part->name, master->name, slave->mtd.size);
158 + if (master->numeraseregions>1) {
159 + /* Deal with variable erase size stuff */
161 + struct mtd_erase_region_info *regions = master->eraseregions;
163 + /* Find the first erase regions which is part of this partition. */
164 + for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
167 + for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
168 + if (slave->mtd.erasesize < regions[i].erasesize) {
169 + slave->mtd.erasesize = regions[i].erasesize;
173 + /* Single erase size */
174 + slave->mtd.erasesize = master->erasesize;
177 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
178 + (slave->offset % slave->mtd.erasesize)) {
179 + /* Doesn't start on a boundary of major erase size */
180 + /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
181 + slave->mtd.flags &= ~MTD_WRITEABLE;
182 + printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
185 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
186 + (slave->mtd.size % slave->mtd.erasesize)) {
187 + slave->mtd.flags &= ~MTD_WRITEABLE;
188 + printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
192 + slave->mtd.ecclayout = master->ecclayout;
193 + if (master->block_isbad) {
196 + while(offs < slave->mtd.size) {
197 + if (master->block_isbad(master,
198 + offs + slave->offset))
199 + slave->mtd.ecc_stats.badblocks++;
200 + offs += slave->mtd.erasesize;
205 + { /* store the object pointer (caller may or may not register it */
206 + *part->mtdp = &slave->mtd;
207 + slave->registered = 0;
211 + /* register our partition */
212 + add_mtd_device(&slave->mtd);
213 + slave->registered = 1;
222 +#ifdef CONFIG_MTD_ROOTFS_SPLIT
223 +#define ROOTFS_SPLIT_NAME "rootfs_data"
224 +#define ROOTFS_REMOVED_NAME "<removed>"
225 +static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
228 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
231 + ret = master->read(master, offset, sizeof(*sb), &len, buf);
232 + if (ret || (len != sizeof(*sb))) {
233 + printk(KERN_ALERT "split_squashfs: error occured while reading "
234 + "from \"%s\"\n", master->name);
238 + if (*((u32 *) buf) != SQUASHFS_MAGIC) {
239 + printk(KERN_ALERT "split_squashfs: no squashfs found in \"%s\"\n",
245 + if (sb->bytes_used <= 0) {
246 + printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
252 + len = (u32) sb->bytes_used;
253 + len += (offset & 0x000fffff);
254 + len += (master->erasesize - 1);
255 + len &= ~(master->erasesize - 1);
256 + len -= (offset & 0x000fffff);
257 + *split_offset = offset + len;
262 +static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, struct mtd_partition *part,
265 + struct mtd_partition *dpart;
266 + struct mtd_part *slave = NULL;
267 + int split_offset = 0;
270 + ret = split_squashfs(master, part->offset, &split_offset);
274 + if (split_offset <= 0)
277 + dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
278 + if (dpart == NULL) {
279 + printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
280 + ROOTFS_SPLIT_NAME);
284 + memcpy(dpart, part, sizeof(*part));
285 + dpart->name = (unsigned char *)&dpart[1];
286 + strcpy(dpart->name, ROOTFS_SPLIT_NAME);
288 + dpart->size -= split_offset - dpart->offset;
289 + dpart->offset = split_offset;
294 + printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%X, len=%X \n",
295 + ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
297 + ret = add_one_partition(master, dpart, index, &slave);
301 + rpart->split = &slave->mtd;
306 +static int refresh_rootfs_split(struct mtd_info *mtd)
308 + struct mtd_partition tpart;
309 + struct mtd_part *part;
316 + /* check for the new squashfs offset first */
317 + ret = split_squashfs(part->master, part->offset, &offset);
321 + if ((offset > 0) && !mtd->split) {
322 + printk(KERN_INFO "%s: creating new split partition for \"%s\"\n", __func__, mtd->name);
323 + /* if we don't have a rootfs split partition, create a new one */
324 + tpart.name = mtd->name;
325 + tpart.size = mtd->size;
326 + tpart.offset = part->offset;
328 + /* find the index of the last partition */
329 + if (!list_empty(&mtd_partitions))
330 + index = list_first_entry(&mtd_partitions, struct mtd_part, list)->index + 1;
332 + return split_rootfs_data(part->master, &part->mtd, &tpart, index);
333 + } else if ((offset > 0) && mtd->split) {
334 + /* update the offsets of the existing partition */
335 + size = mtd->size + part->offset - offset;
337 + part = PART(mtd->split);
338 + part->offset = offset;
339 + part->mtd.size = size;
340 + printk(KERN_INFO "%s: %s partition \"" ROOTFS_SPLIT_NAME "\", offset: 0x%06x (0x%06x)\n",
341 + __func__, (!strcmp(part->mtd.name, ROOTFS_SPLIT_NAME) ? "updating" : "creating"),
342 + part->offset, part->mtd.size);
343 + strcpy(part->mtd.name, ROOTFS_SPLIT_NAME);
344 + } else if ((offset <= 0) && mtd->split) {
345 + printk(KERN_INFO "%s: removing partition \"%s\"\n", __func__, mtd->split->name);
347 + /* mark existing partition as removed */
348 + part = PART(mtd->split);
349 + strcpy(part->mtd.name, ROOTFS_REMOVED_NAME);
351 + part->mtd.size = 0;
356 +#endif /* CONFIG_MTD_ROOTFS_SPLIT */
359 * This function, given a master MTD object and a partition table, creates
360 * and registers slave MTD objects which are bound to the master according to
361 @@ -334,171 +646,31 @@ int add_mtd_partitions(struct mtd_info *
364 struct mtd_part *slave;
365 - u_int32_t cur_offset = 0;
367 + struct mtd_partition *part;
370 printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
372 - for (i = 0; i < nbparts; i++) {
374 - /* allocate the partition structure */
375 - slave = kzalloc (sizeof(*slave), GFP_KERNEL);
377 - printk ("memory allocation error while creating partitions for \"%s\"\n",
379 - del_mtd_partitions(master);
382 - list_add(&slave->list, &mtd_partitions);
384 - /* set up the MTD object for this partition */
385 - slave->mtd.type = master->type;
386 - slave->mtd.flags = master->flags & ~parts[i].mask_flags;
387 - slave->mtd.size = parts[i].size;
388 - slave->mtd.writesize = master->writesize;
389 - slave->mtd.oobsize = master->oobsize;
390 - slave->mtd.oobavail = master->oobavail;
391 - slave->mtd.subpage_sft = master->subpage_sft;
393 - slave->mtd.name = parts[i].name;
394 - slave->mtd.owner = master->owner;
396 - slave->mtd.read = part_read;
397 - slave->mtd.write = part_write;
399 - if (master->panic_write)
400 - slave->mtd.panic_write = part_panic_write;
402 - if(master->point && master->unpoint){
403 - slave->mtd.point = part_point;
404 - slave->mtd.unpoint = part_unpoint;
407 - if (master->read_oob)
408 - slave->mtd.read_oob = part_read_oob;
409 - if (master->write_oob)
410 - slave->mtd.write_oob = part_write_oob;
411 - if(master->read_user_prot_reg)
412 - slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
413 - if(master->read_fact_prot_reg)
414 - slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
415 - if(master->write_user_prot_reg)
416 - slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
417 - if(master->lock_user_prot_reg)
418 - slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
419 - if(master->get_user_prot_info)
420 - slave->mtd.get_user_prot_info = part_get_user_prot_info;
421 - if(master->get_fact_prot_info)
422 - slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
424 - slave->mtd.sync = part_sync;
425 - if (!i && master->suspend && master->resume) {
426 - slave->mtd.suspend = part_suspend;
427 - slave->mtd.resume = part_resume;
429 - if (master->writev)
430 - slave->mtd.writev = part_writev;
432 - slave->mtd.lock = part_lock;
433 - if (master->unlock)
434 - slave->mtd.unlock = part_unlock;
435 - if (master->block_isbad)
436 - slave->mtd.block_isbad = part_block_isbad;
437 - if (master->block_markbad)
438 - slave->mtd.block_markbad = part_block_markbad;
439 - slave->mtd.erase = part_erase;
440 - slave->master = master;
441 - slave->offset = parts[i].offset;
444 - if (slave->offset == MTDPART_OFS_APPEND)
445 - slave->offset = cur_offset;
446 - if (slave->offset == MTDPART_OFS_NXTBLK) {
447 - slave->offset = cur_offset;
448 - if ((cur_offset % master->erasesize) != 0) {
449 - /* Round up to next erasesize */
450 - slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
451 - printk(KERN_NOTICE "Moving partition %d: "
452 - "0x%08x -> 0x%08x\n", i,
453 - cur_offset, slave->offset);
456 - if (slave->mtd.size == MTDPART_SIZ_FULL)
457 - slave->mtd.size = master->size - slave->offset;
458 - cur_offset = slave->offset + slave->mtd.size;
460 - printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
461 - slave->offset + slave->mtd.size, slave->mtd.name);
463 - /* let's do some sanity checks */
464 - if (slave->offset >= master->size) {
465 - /* let's register it anyway to preserve ordering */
467 - slave->mtd.size = 0;
468 - printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
471 - if (slave->offset + slave->mtd.size > master->size) {
472 - slave->mtd.size = master->size - slave->offset;
473 - printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
474 - parts[i].name, master->name, slave->mtd.size);
476 - if (master->numeraseregions>1) {
477 - /* Deal with variable erase size stuff */
479 - struct mtd_erase_region_info *regions = master->eraseregions;
481 - /* Find the first erase regions which is part of this partition. */
482 - for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
485 - for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
486 - if (slave->mtd.erasesize < regions[i].erasesize) {
487 - slave->mtd.erasesize = regions[i].erasesize;
489 + for (i = 0, j = 0; i < nbparts; i++) {
490 + part = (struct mtd_partition *) &parts[i];
491 + ret = add_one_partition(master, part, j, &slave);
496 + if (strcmp(part->name, "rootfs") == 0 && slave->registered) {
497 +#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
498 + if (ROOT_DEV == 0) {
499 + printk(KERN_NOTICE "mtd: partition \"rootfs\" "
500 + "set to be root filesystem\n");
501 + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, slave->mtd.index);
504 - /* Single erase size */
505 - slave->mtd.erasesize = master->erasesize;
508 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
509 - (slave->offset % slave->mtd.erasesize)) {
510 - /* Doesn't start on a boundary of major erase size */
511 - /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
512 - slave->mtd.flags &= ~MTD_WRITEABLE;
513 - printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
516 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
517 - (slave->mtd.size % slave->mtd.erasesize)) {
518 - slave->mtd.flags &= ~MTD_WRITEABLE;
519 - printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
523 - slave->mtd.ecclayout = master->ecclayout;
524 - if (master->block_isbad) {
527 - while(offs < slave->mtd.size) {
528 - if (master->block_isbad(master,
529 - offs + slave->offset))
530 - slave->mtd.ecc_stats.badblocks++;
531 - offs += slave->mtd.erasesize;
536 - { /* store the object pointer (caller may or may not register it */
537 - *parts[i].mtdp = &slave->mtd;
538 - slave->registered = 0;
542 - /* register our partition */
543 - add_mtd_device(&slave->mtd);
544 - slave->registered = 1;
546 +#ifdef CONFIG_MTD_ROOTFS_SPLIT
547 + ret = split_rootfs_data(master, &slave->mtd, part, j);
554 @@ -574,6 +746,32 @@ int parse_mtd_partitions(struct mtd_info
558 +int refresh_mtd_partitions(struct mtd_info *mtd)
562 + if (IS_PART(mtd)) {
563 + struct mtd_part *part;
564 + struct mtd_info *master;
567 + master = part->master;
568 + if (master->refresh_device)
569 + ret = master->refresh_device(master);
572 + if (!ret && mtd->refresh_device)
573 + ret = mtd->refresh_device(mtd);
575 +#ifdef CONFIG_MTD_ROOTFS_SPLIT
576 + if (!ret && IS_PART(mtd) && !strcmp(mtd->name, "rootfs"))
577 + refresh_rootfs_split(mtd);
583 EXPORT_SYMBOL_GPL(parse_mtd_partitions);
584 +EXPORT_SYMBOL_GPL(refresh_mtd_partitions);
585 EXPORT_SYMBOL_GPL(register_mtd_parser);
586 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
587 Index: linux-2.6.25.1/drivers/mtd/devices/block2mtd.c
588 ===================================================================
589 --- linux-2.6.25.1.orig/drivers/mtd/devices/block2mtd.c
590 +++ linux-2.6.25.1/drivers/mtd/devices/block2mtd.c
591 @@ -34,6 +34,8 @@ struct block2mtd_dev {
592 struct block_device *blkdev;
594 struct mutex write_mutex;
595 + rwlock_t bdev_mutex;
600 @@ -86,6 +88,12 @@ static int block2mtd_erase(struct mtd_in
601 size_t len = instr->len;
604 + read_lock(&dev->bdev_mutex);
605 + if (!dev->blkdev) {
610 instr->state = MTD_ERASING;
611 mutex_lock(&dev->write_mutex);
612 err = _block2mtd_erase(dev, from, len);
613 @@ -98,6 +106,10 @@ static int block2mtd_erase(struct mtd_in
615 instr->state = MTD_ERASE_DONE;
616 mtd_erase_callback(instr);
619 + read_unlock(&dev->bdev_mutex);
624 @@ -109,10 +121,14 @@ static int block2mtd_read(struct mtd_inf
626 int index = from >> PAGE_SHIFT;
627 int offset = from & (PAGE_SIZE-1);
629 + int cpylen, err = 0;
631 + read_lock(&dev->bdev_mutex);
632 + if (!dev->blkdev || (from > mtd->size)) {
637 - if (from > mtd->size)
639 if (from + len > mtd->size)
640 len = mtd->size - from;
642 @@ -127,10 +143,14 @@ static int block2mtd_read(struct mtd_inf
645 page = page_read(dev->blkdev->bd_inode->i_mapping, index);
649 - return PTR_ERR(page);
654 + if (IS_ERR(page)) {
655 + err = PTR_ERR(page);
659 memcpy(buf, page_address(page) + offset, cpylen);
660 page_cache_release(page);
661 @@ -141,7 +161,10 @@ static int block2mtd_read(struct mtd_inf
668 + read_unlock(&dev->bdev_mutex);
673 @@ -193,12 +216,22 @@ static int block2mtd_write(struct mtd_in
674 size_t *retlen, const u_char *buf)
676 struct block2mtd_dev *dev = mtd->priv;
680 + read_lock(&dev->bdev_mutex);
681 + if (!dev->blkdev) {
688 - if (to >= mtd->size)
692 + if (to >= mtd->size) {
697 if (to + len > mtd->size)
698 len = mtd->size - to;
700 @@ -207,6 +240,9 @@ static int block2mtd_write(struct mtd_in
701 mutex_unlock(&dev->write_mutex);
706 + read_unlock(&dev->bdev_mutex);
710 @@ -215,51 +251,29 @@ static int block2mtd_write(struct mtd_in
711 static void block2mtd_sync(struct mtd_info *mtd)
713 struct block2mtd_dev *dev = mtd->priv;
714 - sync_blockdev(dev->blkdev);
719 -static void block2mtd_free_device(struct block2mtd_dev *dev)
724 - kfree(dev->mtd.name);
727 - invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
729 - close_bdev_excl(dev->blkdev);
731 + read_lock(&dev->bdev_mutex);
733 + sync_blockdev(dev->blkdev);
734 + read_unlock(&dev->bdev_mutex);
741 -/* FIXME: ensure that mtd->size % erase_size == 0 */
742 -static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
743 +static int _open_bdev(struct block2mtd_dev *dev)
745 struct block_device *bdev;
746 - struct block2mtd_dev *dev;
747 - struct mtd_partition *part;
752 - dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
756 /* Get a handle on the device */
757 - bdev = open_bdev_excl(devname, O_RDWR, NULL);
758 + bdev = open_bdev_excl(dev->devname, O_RDWR, NULL);
762 /* We might not have rootfs mounted at this point. Try
763 to resolve the device name by other means. */
765 - dev_t devt = name_to_dev_t(devname);
766 + dev_t devt = name_to_dev_t(dev->devname);
768 bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ);
770 @@ -267,17 +281,96 @@ static struct block2mtd_dev *add_device(
774 - ERROR("error: cannot open device %s", devname);
776 + ERROR("error: cannot open device %s", dev->devname);
781 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
782 ERROR("attempting to use an MTD device as a block device");
790 +static void _close_bdev(struct block2mtd_dev *dev)
792 + struct block_device *bdev;
797 + bdev = dev->blkdev;
798 + invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 0, -1);
799 + close_bdev_excl(dev->blkdev);
800 + dev->blkdev = NULL;
803 +static void block2mtd_free_device(struct block2mtd_dev *dev)
808 + kfree(dev->mtd.name);
814 +static int block2mtd_refresh(struct mtd_info *mtd)
816 + struct block2mtd_dev *dev = mtd->priv;
817 + struct block_device *bdev;
821 + /* no other mtd function can run at this point */
822 + write_lock(&dev->bdev_mutex);
824 + /* get the device number for the whole disk */
825 + devt = MKDEV(MAJOR(dev->blkdev->bd_dev), 0);
827 + /* close the old block device */
830 + /* open the whole disk, issue a partition rescan, then */
831 + bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ);
832 + if (!bdev || !bdev->bd_disk)
835 + err = rescan_partitions(bdev->bd_disk, bdev);
838 + close_bdev_excl(bdev);
840 + /* try to open the partition block device again */
842 + write_unlock(&dev->bdev_mutex);
847 +/* FIXME: ensure that mtd->size % erase_size == 0 */
848 +static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
850 + struct block2mtd_dev *dev;
851 + struct mtd_partition *part;
856 + dev = kzalloc(sizeof(struct block2mtd_dev) + strlen(devname) + 1, GFP_KERNEL);
860 + strcpy(dev->devname, devname);
862 + if (_open_bdev(dev))
865 mutex_init(&dev->write_mutex);
866 + rwlock_init(&dev->bdev_mutex);
868 /* Setup the MTD structure */
869 /* make the name contain the block device in */
870 @@ -304,6 +397,7 @@ static struct block2mtd_dev *add_device(
871 dev->mtd.read = block2mtd_read;
873 dev->mtd.owner = THIS_MODULE;
874 + dev->mtd.refresh_device = block2mtd_refresh;
876 part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
877 part->name = dev->mtd.name;
878 Index: linux-2.6.25.1/drivers/mtd/mtdchar.c
879 ===================================================================
880 --- linux-2.6.25.1.orig/drivers/mtd/mtdchar.c
881 +++ linux-2.6.25.1/drivers/mtd/mtdchar.c
884 #include <linux/mtd/mtd.h>
885 #include <linux/mtd/compatmac.h>
886 +#include <linux/mtd/partitions.h>
888 #include <asm/uaccess.h>
890 @@ -756,6 +757,13 @@ static int mtd_ioctl(struct inode *inode
894 +#ifdef CONFIG_MTD_PARTITIONS
897 + ret = refresh_mtd_partitions(mtd);
904 Index: linux-2.6.25.1/include/linux/mtd/mtd.h
905 ===================================================================
906 --- linux-2.6.25.1.orig/include/linux/mtd/mtd.h
907 +++ linux-2.6.25.1/include/linux/mtd/mtd.h
908 @@ -98,6 +98,7 @@ struct mtd_oob_ops {
916 @@ -211,6 +212,9 @@ struct mtd_info {
917 struct module *owner;
920 + int (*refresh_device)(struct mtd_info *mtd);
921 + struct mtd_info *split;
923 /* If the driver is something smart, like UBI, it may need to maintain
924 * its own reference counting. The below functions are only for driver.
925 * The driver may register its callbacks. These callbacks are not
926 Index: linux-2.6.25.1/include/linux/mtd/partitions.h
927 ===================================================================
928 --- linux-2.6.25.1.orig/include/linux/mtd/partitions.h
929 +++ linux-2.6.25.1/include/linux/mtd/partitions.h
931 * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
934 +struct mtd_partition;
935 struct mtd_partition {
936 char *name; /* identifier string */
937 u_int32_t size; /* partition size */
938 @@ -43,6 +44,7 @@ struct mtd_partition {
939 u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
940 struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
941 struct mtd_info **mtdp; /* pointer to store the MTD object */
942 + int (*refresh_partition)(struct mtd_info *);
945 #define MTDPART_OFS_NXTBLK (-2)
946 @@ -52,6 +54,7 @@ struct mtd_partition {
948 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
949 int del_mtd_partitions(struct mtd_info *);
950 +int refresh_mtd_partitions(struct mtd_info *);
953 * Functions dealing with the various ways of partitioning the space
954 Index: linux-2.6.25.1/include/mtd/mtd-abi.h
955 ===================================================================
956 --- linux-2.6.25.1.orig/include/mtd/mtd-abi.h
957 +++ linux-2.6.25.1/include/mtd/mtd-abi.h
958 @@ -95,6 +95,7 @@ struct otp_info {
959 #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
960 #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
961 #define MTDFILEMODE _IO('M', 19)
962 +#define MTDREFRESH _IO('M', 23)
965 * Obsolete legacy interface. Keep it in order not to break userspace