]> err.no Git - linux-2.6/blob - drivers/mtd/mtdblock_ro.c
Merge branch 'via-velocity' of git://git.kernel.org/pub/scm/linux/kernel/git/romieu...
[linux-2.6] / drivers / mtd / mtdblock_ro.c
1 /*
2  * (C) 2003 David Woodhouse <dwmw2@infradead.org>
3  *
4  * Simple read-only (writable only for RAM) mtdblock driver
5  */
6
7 #include <linux/init.h>
8 #include <linux/slab.h>
9 #include <linux/mtd/mtd.h>
10 #include <linux/mtd/blktrans.h>
11
12 static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
13                               unsigned long block, char *buf)
14 {
15         size_t retlen;
16
17         if (dev->mtd->read(dev->mtd, (block * 512), 512, &retlen, buf))
18                 return 1;
19         return 0;
20 }
21
22 static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
23                               unsigned long block, char *buf)
24 {
25         size_t retlen;
26
27         if (dev->mtd->write(dev->mtd, (block * 512), 512, &retlen, buf))
28                 return 1;
29         return 0;
30 }
31
32 static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
33 {
34         struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
35
36         if (!dev)
37                 return;
38
39         dev->mtd = mtd;
40         dev->devnum = mtd->index;
41
42         dev->size = mtd->size >> 9;
43         dev->tr = tr;
44         dev->readonly = 1;
45
46         add_mtd_blktrans_dev(dev);
47 }
48
49 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
50 {
51         del_mtd_blktrans_dev(dev);
52         kfree(dev);
53 }
54
55 static struct mtd_blktrans_ops mtdblock_tr = {
56         .name           = "mtdblock",
57         .major          = 31,
58         .part_bits      = 0,
59         .blksize        = 512,
60         .readsect       = mtdblock_readsect,
61         .writesect      = mtdblock_writesect,
62         .add_mtd        = mtdblock_add_mtd,
63         .remove_dev     = mtdblock_remove_dev,
64         .owner          = THIS_MODULE,
65 };
66
67 static int __init mtdblock_init(void)
68 {
69         return register_mtd_blktrans(&mtdblock_tr);
70 }
71
72 static void __exit mtdblock_exit(void)
73 {
74         deregister_mtd_blktrans(&mtdblock_tr);
75 }
76
77 module_init(mtdblock_init);
78 module_exit(mtdblock_exit);
79
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");