read.c (e0c8e42f8f218063ff6838b25038ccef7ddf257e) | read.c (182ec4eee397543101a6db8906ed88727d3f7e53) |
---|---|
1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * | 1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * |
10 * $Id: read.c,v 1.41 2005/07/22 10:32:08 dedekind Exp $ | 10 * $Id: read.c,v 1.42 2005/11/07 11:14:41 gleixner Exp $ |
11 * 12 */ 13 14#include <linux/kernel.h> 15#include <linux/slab.h> 16#include <linux/crc32.h> 17#include <linux/pagemap.h> 18#include <linux/mtd/mtd.h> --- 19 unchanged lines hidden (view full) --- 38 ret = jffs2_flash_read(c, ref_offset(fd->raw), sizeof(*ri), &readlen, (char *)ri); 39 if (ret) { 40 jffs2_free_raw_inode(ri); 41 printk(KERN_WARNING "Error reading node from 0x%08x: %d\n", ref_offset(fd->raw), ret); 42 return ret; 43 } 44 if (readlen != sizeof(*ri)) { 45 jffs2_free_raw_inode(ri); | 11 * 12 */ 13 14#include <linux/kernel.h> 15#include <linux/slab.h> 16#include <linux/crc32.h> 17#include <linux/pagemap.h> 18#include <linux/mtd/mtd.h> --- 19 unchanged lines hidden (view full) --- 38 ret = jffs2_flash_read(c, ref_offset(fd->raw), sizeof(*ri), &readlen, (char *)ri); 39 if (ret) { 40 jffs2_free_raw_inode(ri); 41 printk(KERN_WARNING "Error reading node from 0x%08x: %d\n", ref_offset(fd->raw), ret); 42 return ret; 43 } 44 if (readlen != sizeof(*ri)) { 45 jffs2_free_raw_inode(ri); |
46 printk(KERN_WARNING "Short read from 0x%08x: wanted 0x%zx bytes, got 0x%zx\n", | 46 printk(KERN_WARNING "Short read from 0x%08x: wanted 0x%zx bytes, got 0x%zx\n", |
47 ref_offset(fd->raw), sizeof(*ri), readlen); 48 return -EIO; 49 } 50 crc = crc32(0, ri, sizeof(*ri)-8); 51 52 D1(printk(KERN_DEBUG "Node read from %08x: node_crc %08x, calculated CRC %08x. dsize %x, csize %x, offset %x, buf %p\n", 53 ref_offset(fd->raw), je32_to_cpu(ri->node_crc), 54 crc, je32_to_cpu(ri->dsize), je32_to_cpu(ri->csize), 55 je32_to_cpu(ri->offset), buf)); 56 if (crc != je32_to_cpu(ri->node_crc)) { 57 printk(KERN_WARNING "Node CRC %08x != calculated CRC %08x for node at %08x\n", 58 je32_to_cpu(ri->node_crc), crc, ref_offset(fd->raw)); 59 ret = -EIO; 60 goto out_ri; 61 } 62 /* There was a bug where we wrote hole nodes out with csize/dsize 63 swapped. Deal with it */ | 47 ref_offset(fd->raw), sizeof(*ri), readlen); 48 return -EIO; 49 } 50 crc = crc32(0, ri, sizeof(*ri)-8); 51 52 D1(printk(KERN_DEBUG "Node read from %08x: node_crc %08x, calculated CRC %08x. dsize %x, csize %x, offset %x, buf %p\n", 53 ref_offset(fd->raw), je32_to_cpu(ri->node_crc), 54 crc, je32_to_cpu(ri->dsize), je32_to_cpu(ri->csize), 55 je32_to_cpu(ri->offset), buf)); 56 if (crc != je32_to_cpu(ri->node_crc)) { 57 printk(KERN_WARNING "Node CRC %08x != calculated CRC %08x for node at %08x\n", 58 je32_to_cpu(ri->node_crc), crc, ref_offset(fd->raw)); 59 ret = -EIO; 60 goto out_ri; 61 } 62 /* There was a bug where we wrote hole nodes out with csize/dsize 63 swapped. Deal with it */ |
64 if (ri->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri->dsize) && | 64 if (ri->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri->dsize) && |
65 je32_to_cpu(ri->csize)) { 66 ri->dsize = ri->csize; 67 ri->csize = cpu_to_je32(0); 68 } 69 70 D1(if(ofs + len > je32_to_cpu(ri->dsize)) { 71 printk(KERN_WARNING "jffs2_read_dnode() asked for %d bytes at %d from %d-byte node\n", 72 len, ofs, je32_to_cpu(ri->dsize)); 73 ret = -EINVAL; 74 goto out_ri; 75 }); 76 | 65 je32_to_cpu(ri->csize)) { 66 ri->dsize = ri->csize; 67 ri->csize = cpu_to_je32(0); 68 } 69 70 D1(if(ofs + len > je32_to_cpu(ri->dsize)) { 71 printk(KERN_WARNING "jffs2_read_dnode() asked for %d bytes at %d from %d-byte node\n", 72 len, ofs, je32_to_cpu(ri->dsize)); 73 ret = -EINVAL; 74 goto out_ri; 75 }); 76 |
77 | 77 |
78 if (ri->compr == JFFS2_COMPR_ZERO) { 79 memset(buf, 0, len); 80 goto out_ri; 81 } 82 83 /* Cases: 84 Reading whole node and it's uncompressed - read directly to buffer provided, check CRC. | 78 if (ri->compr == JFFS2_COMPR_ZERO) { 79 memset(buf, 0, len); 80 goto out_ri; 81 } 82 83 /* Cases: 84 Reading whole node and it's uncompressed - read directly to buffer provided, check CRC. |
85 Reading whole node and it's compressed - read into comprbuf, check CRC and decompress to buffer provided 86 Reading partial node and it's uncompressed - read into readbuf, check CRC, and copy | 85 Reading whole node and it's compressed - read into comprbuf, check CRC and decompress to buffer provided 86 Reading partial node and it's uncompressed - read into readbuf, check CRC, and copy |
87 Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy 88 */ 89 if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) { 90 readbuf = buf; 91 } else { 92 readbuf = kmalloc(je32_to_cpu(ri->csize), GFP_KERNEL); 93 if (!readbuf) { 94 ret = -ENOMEM; --- 29 unchanged lines hidden (view full) --- 124 printk(KERN_WARNING "Data CRC %08x != calculated CRC %08x for node at %08x\n", 125 je32_to_cpu(ri->data_crc), crc, ref_offset(fd->raw)); 126 ret = -EIO; 127 goto out_decomprbuf; 128 } 129 D2(printk(KERN_DEBUG "Data CRC matches calculated CRC %08x\n", crc)); 130 if (ri->compr != JFFS2_COMPR_NONE) { 131 D2(printk(KERN_DEBUG "Decompress %d bytes from %p to %d bytes at %p\n", | 87 Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy 88 */ 89 if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) { 90 readbuf = buf; 91 } else { 92 readbuf = kmalloc(je32_to_cpu(ri->csize), GFP_KERNEL); 93 if (!readbuf) { 94 ret = -ENOMEM; --- 29 unchanged lines hidden (view full) --- 124 printk(KERN_WARNING "Data CRC %08x != calculated CRC %08x for node at %08x\n", 125 je32_to_cpu(ri->data_crc), crc, ref_offset(fd->raw)); 126 ret = -EIO; 127 goto out_decomprbuf; 128 } 129 D2(printk(KERN_DEBUG "Data CRC matches calculated CRC %08x\n", crc)); 130 if (ri->compr != JFFS2_COMPR_NONE) { 131 D2(printk(KERN_DEBUG "Decompress %d bytes from %p to %d bytes at %p\n", |
132 je32_to_cpu(ri->csize), readbuf, je32_to_cpu(ri->dsize), decomprbuf)); | 132 je32_to_cpu(ri->csize), readbuf, je32_to_cpu(ri->dsize), decomprbuf)); |
133 ret = jffs2_decompress(c, f, ri->compr | (ri->usercompr << 8), readbuf, decomprbuf, je32_to_cpu(ri->csize), je32_to_cpu(ri->dsize)); 134 if (ret) { 135 printk(KERN_WARNING "Error: jffs2_decompress returned %d\n", ret); 136 goto out_decomprbuf; 137 } 138 } 139 140 if (len < je32_to_cpu(ri->dsize)) { --- 45 unchanged lines hidden (view full) --- 186 memset(buf, 0, holeend - offset); 187 buf += holeend - offset; 188 offset = holeend; 189 frag = frag_next(frag); 190 continue; 191 } else { 192 uint32_t readlen; 193 uint32_t fragofs; /* offset within the frag to start reading */ | 133 ret = jffs2_decompress(c, f, ri->compr | (ri->usercompr << 8), readbuf, decomprbuf, je32_to_cpu(ri->csize), je32_to_cpu(ri->dsize)); 134 if (ret) { 135 printk(KERN_WARNING "Error: jffs2_decompress returned %d\n", ret); 136 goto out_decomprbuf; 137 } 138 } 139 140 if (len < je32_to_cpu(ri->dsize)) { --- 45 unchanged lines hidden (view full) --- 186 memset(buf, 0, holeend - offset); 187 buf += holeend - offset; 188 offset = holeend; 189 frag = frag_next(frag); 190 continue; 191 } else { 192 uint32_t readlen; 193 uint32_t fragofs; /* offset within the frag to start reading */ |
194 | 194 |
195 fragofs = offset - frag->ofs; 196 readlen = min(frag->size - fragofs, end - offset); 197 D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%08x (%d)\n", 198 frag->ofs+fragofs, frag->ofs+fragofs+readlen, 199 ref_offset(frag->node->raw), ref_flags(frag->node->raw))); 200 ret = jffs2_read_dnode(c, f, frag->node, buf, fragofs + frag->ofs - frag->node->ofs, readlen); 201 D2(printk(KERN_DEBUG "node read done\n")); 202 if (ret) { --- 13 unchanged lines hidden --- | 195 fragofs = offset - frag->ofs; 196 readlen = min(frag->size - fragofs, end - offset); 197 D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%08x (%d)\n", 198 frag->ofs+fragofs, frag->ofs+fragofs+readlen, 199 ref_offset(frag->node->raw), ref_flags(frag->node->raw))); 200 ret = jffs2_read_dnode(c, f, frag->node, buf, fragofs + frag->ofs - frag->node->ofs, readlen); 201 D2(printk(KERN_DEBUG "node read done\n")); 202 if (ret) { --- 13 unchanged lines hidden --- |