25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/types.h>
65 static int erase_write (
struct mtd_info *mtd,
unsigned long pos,
66 int len,
const char *
buf)
80 erase.callback = erase_callback;
83 erase.priv = (
u_long)&wait_q;
105 ret =
mtd_write(mtd, pos, len, &retlen, buf);
114 static int write_cached_data (
struct mtdblk_dev *mtdblk)
122 pr_debug(
"mtdblock: writing cached data for \"%s\" "
123 "at 0x%lx, size 0x%x\n", mtd->
name,
143 static int do_cached_write (
struct mtdblk_dev *mtdblk,
unsigned long pos,
144 int len,
const char *buf)
151 pr_debug(
"mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n",
152 mtd->
name, pos, len);
155 return mtd_write(mtd, pos, len, &retlen, buf);
158 unsigned long sect_start = (pos/sect_size)*sect_size;
159 unsigned int offset = pos - sect_start;
164 if (size == sect_size) {
170 ret = erase_write (mtd, pos, size, buf);
178 ret = write_cached_data(mtdblk);
187 ret =
mtd_read(mtd, sect_start, sect_size,
191 if (retlen != sect_size)
213 static int do_cached_read (
struct mtdblk_dev *mtdblk,
unsigned long pos,
221 pr_debug(
"mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
222 mtd->
name, pos, len);
225 return mtd_read(mtd, pos, len, &retlen, buf);
228 unsigned long sect_start = (pos/sect_size)*sect_size;
229 unsigned int offset = pos - sect_start;
230 unsigned int size = sect_size -
offset;
244 ret =
mtd_read(mtd, pos, size, &retlen, buf);
260 unsigned long block,
char *buf)
263 return do_cached_read(mtdblk, block<<9, 512, buf);
267 unsigned long block,
char *buf)
279 return do_cached_write(mtdblk, block<<9, 512, buf);
320 write_cached_data(mtdblk);
323 if (!--mtdblk->
count) {
345 write_cached_data(mtdblk);
361 dev->
mbd.size = mtd->
size >> 9;
365 dev->
mbd.readonly = 1;
381 .open = mtdblock_open,
382 .flush = mtdblock_flush,
383 .release = mtdblock_release,
384 .readsect = mtdblock_readsect,
385 .writesect = mtdblock_writesect,
386 .add_mtd = mtdblock_add_mtd,
387 .remove_dev = mtdblock_remove_dev,
391 static int __init init_mtdblock(
void)
396 static void __exit cleanup_mtdblock(
void)
407 MODULE_DESCRIPTION(
"Caching read/erase/writeback block device emulation access to MTD devices");