2 * $Id: mtdblock_ro.c,v 1.18 2003/06/23 12:00:08 dwmw2 Exp $
4 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
6 * Simple read-only (writable only for RAM) mtdblock driver
8 * (C) 2002 David McCullough, Added MAGIC_ROM_PTR support
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/blktrans.h>
16 static int mtdblock_readsect(struct mtd_blktrans_dev
*dev
,
17 unsigned long block
, char *buf
)
21 if (dev
->mtd
->read(dev
->mtd
, (block
* 512), 512, &retlen
, buf
))
26 static int mtdblock_writesect(struct mtd_blktrans_dev
*dev
,
27 unsigned long block
, char *buf
)
31 if (dev
->mtd
->write(dev
->mtd
, (block
* 512), 512, &retlen
, buf
))
36 static void mtdblock_add_mtd(struct mtd_blktrans_ops
*tr
, struct mtd_info
*mtd
)
38 struct mtd_blktrans_dev
*dev
= kmalloc(sizeof(*dev
), GFP_KERNEL
);
43 memset(dev
, 0, sizeof(*dev
));
46 dev
->devnum
= mtd
->index
;
48 dev
->size
= mtd
->size
>> 9;
50 if ((mtd
->flags
& (MTD_CLEAR_BITS
|MTD_SET_BITS
|MTD_WRITEABLE
)) !=
51 (MTD_CLEAR_BITS
|MTD_SET_BITS
|MTD_WRITEABLE
))
54 add_mtd_blktrans_dev(dev
);
57 #ifdef CONFIG_MAGIC_ROM_PTR
60 mtdblock_romptr(struct mtd_blktrans_dev
*dev
, struct vm_area_struct
* vma
)
62 struct mtd_info
*mtd
= dev
->mtd
;
66 if (!mtd
->point
/* Can't do it, No function to point to correct addr */
68 || (*mtd
->point
)(mtd
,vma
->vm_pgoff
,vma
->vm_end
-vma
->vm_start
,&len
,&ptr
) != 0)
71 vma
->vm_start
= (unsigned long) ptr
;
72 vma
->vm_end
= vma
->vm_start
+ len
;
77 static void mtdblock_remove_dev(struct mtd_blktrans_dev
*dev
)
79 del_mtd_blktrans_dev(dev
);
83 struct mtd_blktrans_ops mtdblock_tr
= {
87 .readsect
= mtdblock_readsect
,
88 .writesect
= mtdblock_writesect
,
89 .add_mtd
= mtdblock_add_mtd
,
90 .remove_dev
= mtdblock_remove_dev
,
92 #ifdef CONFIG_MAGIC_ROM_PTR
93 .romptr
= mtdblock_romptr
,
97 static int __init
mtdblock_init(void)
99 return register_mtd_blktrans(&mtdblock_tr
);
102 static void __exit
mtdblock_exit(void)
104 deregister_mtd_blktrans(&mtdblock_tr
);
107 module_init(mtdblock_init
);
108 module_exit(mtdblock_exit
);
110 MODULE_LICENSE("GPL");
111 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
112 MODULE_DESCRIPTION("Simple read-only block device emulation access to MTD devices");