mtd/fs/jffs2 debug.c, 1.12, 1.13 erase.c, 1.87, 1.88 gc.c, 1.156,
1.157 nodelist.c, 1.116, 1.117 os-linux.h, 1.66, 1.67 read.c,
1.42, 1.43 readinode.c, 1.144, 1.145 scan.c, 1.128,
1.129 wbuf.c, 1.104, 1.105
joern at infradead.org
joern at infradead.org
Fri Nov 11 09:29:16 EST 2005
Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/home/joern/mtd/fs/jffs2
Modified Files:
debug.c erase.c gc.c nodelist.c os-linux.h read.c readinode.c
scan.c wbuf.c
Log Message:
Encapsulate error handling for flash reads.
From: Pierre Ricadat
Index: debug.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/debug.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- debug.c 7 Nov 2005 11:14:39 -0000 1.12
+++ debug.c 11 Nov 2005 14:29:11 -0000 1.13
@@ -130,13 +130,8 @@
if (!buf)
return;
- ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
- if (ret || (retlen != len)) {
- JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
- len, ret, retlen);
- kfree(buf);
+ if (jffs2_flash_read_safe(c, ofs, len, buf))
return;
- }
ret = 0;
for (i = 0; i < len; i++)
@@ -615,16 +610,11 @@
int len = sizeof(union jffs2_node_union);
size_t retlen;
uint32_t crc;
- int ret;
printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs);
- ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
- if (ret || (retlen != len)) {
- JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
- len, ret, retlen);
+ if (jffs2_flash_read_safe(c, ofs, len, (unsigned char *)&node))
return;
- }
printk(JFFS2_DBG "magic:\t%#04x\n", je16_to_cpu(node.u.magic));
printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype));
Index: erase.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/erase.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- erase.c 7 Nov 2005 11:14:39 -0000 1.87
+++ erase.c 11 Nov 2005 14:29:12 -0000 1.88
@@ -306,7 +306,6 @@
{
void *ebuf;
uint32_t ofs;
- size_t retlen;
int ret = -EIO;
ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
@@ -323,15 +322,8 @@
*bad_offset = ofs;
- ret = jffs2_flash_read(c, ofs, readlen, &retlen, ebuf);
- if (ret) {
- printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret);
- goto fail;
- }
- if (retlen != readlen) {
- printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen);
- goto fail;
- }
+ if (jffs2_flash_read_safe(c, ofs, readlen, (void *)ebuf))
+ return ret;
for (i=0; i<readlen; i += sizeof(unsigned long)) {
/* It's OK. We know it's properly aligned */
unsigned long *datum = ebuf + i;
Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -r1.156 -r1.157
--- gc.c 11 Nov 2005 08:51:38 -0000 1.156
+++ gc.c 11 Nov 2005 14:29:12 -0000 1.157
@@ -530,11 +530,8 @@
if (!node)
return -ENOMEM;
- ret = jffs2_flash_read(c, ref_offset(raw), rawlen, &retlen, (char *)node);
- if (!ret && retlen != rawlen)
- ret = -EIO;
- if (ret)
- goto out_node;
+ if (jffs2_flash_read_safe(c, ref_offset(raw), rawlen, (char*)node))
+ return -EIO;
crc = crc32(0, node, sizeof(struct jffs2_unknown_node)-4);
if (je32_to_cpu(node->u.hdr_crc) != crc) {
@@ -818,8 +815,6 @@
if (!jffs2_can_mark_obsolete(c)) {
struct jffs2_raw_dirent *rd;
struct jffs2_raw_node_ref *raw;
- int ret;
- size_t retlen;
int name_len = strlen(fd->name);
uint32_t name_crc = crc32(0, fd->name, name_len);
uint32_t rawlen = ref_totlen(c, jeb, fd->raw);
@@ -852,17 +847,9 @@
/* This is an obsolete node belonging to the same directory, and it's of the right
length. We need to take a closer look...*/
- ret = jffs2_flash_read(c, ref_offset(raw), rawlen, &retlen, (char *)rd);
- if (ret) {
- printk(KERN_WARNING "jffs2_g_c_deletion_dirent(): Read error (%d) reading obsolete node at %08x\n", ret, ref_offset(raw));
+ if (jffs2_flash_read_safe(c, ref_offset(raw), rawlen, (char *)rd))
/* If we can't read it, we don't need to continue to obsolete it. Continue */
continue;
- }
- if (retlen != rawlen) {
- printk(KERN_WARNING "jffs2_g_c_deletion_dirent(): Short read (%zd not %u) reading header from obsolete node at %08x\n",
- retlen, rawlen, ref_offset(raw));
- continue;
- }
if (je16_to_cpu(rd->nodetype) != JFFS2_NODETYPE_DIRENT)
continue;
Index: nodelist.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -r1.116 -r1.117
--- nodelist.c 11 Nov 2005 08:51:38 -0000 1.116
+++ nodelist.c 11 Nov 2005 14:29:12 -0000 1.117
@@ -451,19 +451,8 @@
if (unlikely(!buffer))
return -ENOMEM;
- /* TODO: this is very frequent pattern, make it a separate
- * routine */
- err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
- if (err) {
- JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
- goto free_out;
- }
-
- if (retlen != len) {
- JFFS2_ERROR("short read at %#08x: %d instead of %d.\n", ofs, retlen, len);
- err = -EIO;
- goto free_out;
- }
+ if (jffs2_flash_read_safe(c, ofs, len, buffer))
+ return -EIO;
}
/* Continue calculating CRC */
@@ -497,15 +486,6 @@
spin_unlock(&c->erase_completion_lock);
return 0;
-
-free_out:
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- c->mtd->unpoint(c->mtd, buffer, ofs, len);
-#endif
- return err;
}
/*
Index: os-linux.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/os-linux.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- os-linux.h 7 Nov 2005 11:14:41 -0000 1.66
+++ os-linux.h 11 Nov 2005 14:29:12 -0000 1.67
@@ -122,6 +122,7 @@
int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino);
int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
+int jffs2_flash_read_safe(struct jffs2_sb_info *c, uint32_t ofs, int len, u_char *buf);
int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,uint32_t data_len);
int jffs2_check_nand_cleanmarker_ebh(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t *data_len);
int jffs2_write_nand_ebh(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
Index: read.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/read.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- read.c 7 Nov 2005 11:14:41 -0000 1.42
+++ read.c 11 Nov 2005 14:29:12 -0000 1.43
@@ -111,13 +111,9 @@
D2(printk(KERN_DEBUG "Read %d bytes to %p\n", je32_to_cpu(ri->csize),
readbuf));
- ret = jffs2_flash_read(c, (ref_offset(fd->raw)) + sizeof(*ri),
- je32_to_cpu(ri->csize), &readlen, readbuf);
- if (!ret && readlen != je32_to_cpu(ri->csize))
- ret = -EIO;
- if (ret)
- goto out_decomprbuf;
+ if (jffs2_flash_read_safe(c, (ref_offset(fd->raw)) + sizeof(*ri), je32_to_cpu(ri->csize), readbuf))
+ return -EIO;
crc = crc32(0, readbuf, je32_to_cpu(ri->csize));
if (crc != je32_to_cpu(ri->data_crc)) {
Index: readinode.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/readinode.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -r1.144 -r1.145
--- readinode.c 11 Nov 2005 08:51:39 -0000 1.144
+++ readinode.c 11 Nov 2005 14:29:12 -0000 1.145
@@ -400,8 +400,7 @@
static int read_more(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
int right_size, int *rdlen, unsigned char *buf, unsigned char *bufstart)
{
- int right_len, err, len;
- size_t retlen;
+ int right_len, len;
uint32_t offs;
if (jffs2_is_writebuffered(c)) {
@@ -426,18 +425,8 @@
dbg_readinode("read more %d bytes\n", len);
- err = jffs2_flash_read(c, offs, len, &retlen, bufstart);
- if (err) {
- JFFS2_ERROR("can not read %d bytes from 0x%08x, "
- "error code: %d.\n", len, offs, err);
- return err;
- }
-
- if (retlen < len) {
- JFFS2_ERROR("short read at %#08x: %d instead of %d.\n",
- offs, retlen, len);
+ if (jffs2_flash_read_safe(c, offs, len, bufstart))
return -EIO;
- }
*rdlen = right_len;
Index: scan.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/scan.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -r1.128 -r1.129
--- scan.c 11 Nov 2005 08:51:39 -0000 1.128
+++ scan.c 11 Nov 2005 14:29:12 -0000 1.129
@@ -274,18 +274,8 @@
int jffs2_fill_scan_buf (struct jffs2_sb_info *c, void *buf,
uint32_t ofs, uint32_t len)
{
- int ret;
- size_t retlen;
-
- ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
- if (ret) {
- D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", len, ofs, ret));
- return ret;
- }
- if (retlen < len) {
- D1(printk(KERN_WARNING "Read at 0x%x gave only 0x%zx bytes\n", ofs, retlen));
+ if (jffs2_flash_read_safe(c, ofs, len, buf))
return -EIO;
- }
D2(printk(KERN_DEBUG "Read 0x%x bytes from 0x%08x into buf\n", len, ofs));
D2(printk(KERN_DEBUG "000: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]));
Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- wbuf.c 11 Nov 2005 08:51:39 -0000 1.104
+++ wbuf.c 11 Nov 2005 14:29:12 -0000 1.105
@@ -925,6 +925,32 @@
}
/*
+ * Check if jffs2_flash_read was successful
+ */
+int jffs2_flash_read_safe(struct jffs2_sb_info *c, uint32_t ofs, int len, u_char *buf)
+{
+ size_t retlen;
+ int err, ret = 0;
+
+ /* read the data */
+ err = jffs2_flash_read(c, ofs, len, &retlen, buf);
+
+ /* did the read succeed? */
+ if (err) {
+ JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
+ kfree(buf);
+ ret = -EIO;
+ }
+ /* did we read all? */
+ if (retlen != len) {
+ JFFS2_ERROR("short read at 0x%08x: %d instead of %d.\n", ofs, retlen, len);
+ kfree(buf);
+ ret = -EIO;
+ }
+ return ret;
+}
+
+/*
* Check, if the out of band area is empty
*/
More information about the linux-mtd-cvs
mailing list