2 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
4 * Simple read-only (writable only for RAM) mtdblock driver
7 #include <linux/init.h>
8 #include <linux/slab.h>
9 #include <linux/mtd/mtd.h>
10 #include <linux/mtd/blktrans.h>
12 static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
13 unsigned long block, char *buf)
17 if (dev->mtd->read(dev->mtd, (block * 512), 512, &retlen, buf))
22 static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
23 unsigned long block, char *buf)
27 if (dev->mtd->write(dev->mtd, (block * 512), 512, &retlen, buf))
32 static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
34 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
40 dev->devnum = mtd->index;
42 dev->size = mtd->size >> 9;
46 add_mtd_blktrans_dev(dev);
49 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
51 del_mtd_blktrans_dev(dev);
55 static struct mtd_blktrans_ops mtdblock_tr = {
60 .readsect = mtdblock_readsect,
61 .writesect = mtdblock_writesect,
62 .add_mtd = mtdblock_add_mtd,
63 .remove_dev = mtdblock_remove_dev,
67 static int __init mtdblock_init(void)
69 return register_mtd_blktrans(&mtdblock_tr);
72 static void __exit mtdblock_exit(void)
74 deregister_mtd_blktrans(&mtdblock_tr);
77 module_init(mtdblock_init);
78 module_exit(mtdblock_exit);
80 MODULE_LICENSE("GPL");
81 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
82 MODULE_DESCRIPTION("Simple read-only block device emulation access to MTD devices");