From 61c4b23770d1b0cef7c06a23378ab544eb0c64b4 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Wed, 25 Apr 2007 17:04:23 +0100 Subject: [JFFS2] Handle inodes with only a single metadata node with non-zero isize This should never happen unless there's corruption on the medium and the actual data nodes go missing. But the failure mode (an oops when we assume the fragtree isn't empty and go looking for its last node) isn't useful. Signed-off-by: David Woodhouse --- fs/jffs2/readinode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'fs/jffs2/readinode.c') diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c index a42ffba2ed1..6aff38930b5 100644 --- a/fs/jffs2/readinode.c +++ b/fs/jffs2/readinode.c @@ -1132,7 +1132,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, struct jffs2_raw_inode *latest_node) { struct jffs2_readinode_info rii; - uint32_t crc; + uint32_t crc, new_size; size_t retlen; int ret; @@ -1233,7 +1233,12 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, case S_IFREG: /* If it was a regular file, truncate it to the latest node's isize */ - jffs2_truncate_fragtree(c, &f->fragtree, je32_to_cpu(latest_node->isize)); + new_size = jffs2_truncate_fragtree(c, &f->fragtree, je32_to_cpu(latest_node->isize)); + if (new_size != je32_to_cpu(latest_node->isize)) { + JFFS2_WARNING("Truncating ino #%u to %d bytes failed because it only had %d bytes to start with!\n", + f->inocache->ino, je32_to_cpu(latest_node->isize), new_size); + latest_node->isize = cpu_to_je32(new_size); + } break; case S_IFLNK: -- cgit v1.2.3