mtd/drivers/mtd/devices block2mtd.c,1.17,1.18
joern at infradead.org
joern at infradead.org
Wed Dec 22 08:13:05 EST 2004
Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/home/joern/mtd/drivers/mtd/devices
Modified Files:
block2mtd.c
Log Message:
Renames _erase and _read functions and removes some leftover erase
region stuff.
Index: block2mtd.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/block2mtd.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- block2mtd.c 22 Dec 2004 13:12:34 -0000 1.17
+++ block2mtd.c 22 Dec 2004 13:13:02 -0000 1.18
@@ -223,59 +223,36 @@
/* erase a specified part of the device */
-static int blkmtd_erase(struct mtd_info *mtd, struct erase_info *instr)
+static int blockmtd_erase(struct mtd_info *mtd, struct erase_info *instr)
{
struct blockmtd_dev *dev = mtd->priv;
- struct mtd_erase_region_info *einfo = mtd->eraseregions;
- int numregions = mtd->numeraseregions;
- size_t from;
- u_long len;
- int err = -EIO;
+ size_t from = instr->addr;
+ size_t len = instr->len;
size_t retlen;
+ int err;
instr->state = MTD_ERASING;
- from = instr->addr;
- len = instr->len;
-
- /* check erase region has valid start and length */
- while (numregions) {
- if (from >= einfo->offset && from < einfo->offset + (einfo->erasesize * einfo->numblocks)) {
- if (len == einfo->erasesize && ((from - einfo->offset) % einfo->erasesize == 0))
- break;
- }
- numregions--;
- einfo++;
- }
-
- if (!numregions) {
- /* Not a valid erase block */
- ERROR("erase: invalid erase request 0x%lX @ 0x%08zX", len,from);
+ err = write_pages(dev, NULL, from, len, &retlen);
+ if (err || retlen != len) {
+ ERROR("erase failed err = %d", err);
instr->state = MTD_ERASE_FAILED;
- err = -EIO;
- }
-
- if (instr->state != MTD_ERASE_FAILED) {
- /* do the erase */
- err = write_pages(dev, NULL, from, len, &retlen);
- if (err || retlen != len) {
- ERROR("erase failed err = %d", err);
- instr->state = MTD_ERASE_FAILED;
- } else {
- instr->state = MTD_ERASE_DONE;
- }
+ } else {
+ instr->state = MTD_ERASE_DONE;
}
+ instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr);
return err;
}
-static int blkmtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
+
+static int blockmtd_read(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, u_char *buf)
{
struct blockmtd_dev *dev = mtd->priv;
struct page *page;
- //
int index = from >> PAGE_SHIFT;
- int offset = from - (index << PAGE_SHIFT);
+ int offset = from & (PAGE_SHIFT-1);
int cpylen;
if (from > mtd->size)
@@ -298,7 +275,7 @@
if (!page)
return -ENOMEM;
if (IS_ERR(page))
- return -EIO;
+ return PTR_ERR(page);
memcpy(buf, page_address(page) + offset, cpylen);
page_cache_release(page);
@@ -308,15 +285,14 @@
buf += cpylen;
offset = 0;
index++;
-
}
return 0;
}
/* write data to the underlying device */
-static int blkmtd_write(struct mtd_info *mtd, loff_t to, size_t len,
- size_t *retlen, const u_char *buf)
+static int blockmtd_write(struct mtd_info *mtd, loff_t to, size_t len,
+ size_t *retlen, const u_char *buf)
{
struct blockmtd_dev *dev = mtd->priv;
int err;
@@ -361,6 +337,7 @@
}
+/* FIXME: ensure that mtd->size % erase_size == 0 */
static struct blockmtd_dev *add_device(char *devname, int erase_size)
{
struct block_device *bdev;
@@ -403,11 +380,11 @@
dev->mtd.erasesize = erase_size;
dev->mtd.type = MTD_RAM;
dev->mtd.flags = MTD_CAP_RAM;
- dev->mtd.erase = blkmtd_erase;
- dev->mtd.write = blkmtd_write;
+ dev->mtd.erase = blockmtd_erase;
+ dev->mtd.write = blockmtd_write;
dev->mtd.writev = default_mtd_writev;
dev->mtd.sync = blockmtd_sync;
- dev->mtd.read = blkmtd_read;
+ dev->mtd.read = blockmtd_read;
dev->mtd.readv = default_mtd_readv;
dev->mtd.priv = dev;
dev->mtd.owner = THIS_MODULE;
More information about the linux-mtd-cvs
mailing list