[SCSI] qla4xxx: Reset seconds_since_last_heartbeat correctly.
[linux-2.6/linux-mips.git] / drivers / mtd / mtdblock_ro.c
blob795a8c0a05b82cf4a7cf0bc5d1e31bed4890b9e4
1 /*
2 * Simple read-only (writable only for RAM) mtdblock driver
4 * Copyright © 2001-2010 David Woodhouse <dwmw2@infradead.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/blktrans.h>
27 static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
28 unsigned long block, char *buf)
30 size_t retlen;
32 if (dev->mtd->read(dev->mtd, (block * 512), 512, &retlen, buf))
33 return 1;
34 return 0;
37 static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
38 unsigned long block, char *buf)
40 size_t retlen;
42 if (dev->mtd->write(dev->mtd, (block * 512), 512, &retlen, buf))
43 return 1;
44 return 0;
47 static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
49 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
51 if (!dev)
52 return;
54 dev->mtd = mtd;
55 dev->devnum = mtd->index;
57 dev->size = mtd->size >> 9;
58 dev->tr = tr;
59 dev->readonly = 1;
61 if (add_mtd_blktrans_dev(dev))
62 kfree(dev);
65 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
67 del_mtd_blktrans_dev(dev);
70 static struct mtd_blktrans_ops mtdblock_tr = {
71 .name = "mtdblock",
72 .major = 31,
73 .part_bits = 0,
74 .blksize = 512,
75 .readsect = mtdblock_readsect,
76 .writesect = mtdblock_writesect,
77 .add_mtd = mtdblock_add_mtd,
78 .remove_dev = mtdblock_remove_dev,
79 .owner = THIS_MODULE,
82 static int __init mtdblock_init(void)
84 return register_mtd_blktrans(&mtdblock_tr);
87 static void __exit mtdblock_exit(void)
89 deregister_mtd_blktrans(&mtdblock_tr);
92 module_init(mtdblock_init);
93 module_exit(mtdblock_exit);
95 MODULE_LICENSE("GPL");
96 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
97 MODULE_DESCRIPTION("Simple read-only block device emulation access to MTD devices");