Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * JFFS2 -- Journalling Flash File System, Version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright © 2001-2007 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Created by David Woodhouse <dwmw2@infradead.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * For licensing information, see the file 'LICENCE' in this directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "nodelist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "compr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		     struct jffs2_full_dnode *fd, unsigned char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		     int ofs, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct jffs2_raw_inode *ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	size_t readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	uint32_t crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned char *decomprbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned char *readbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	ri = jffs2_alloc_raw_inode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (!ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	ret = jffs2_flash_read(c, ref_offset(fd->raw), sizeof(*ri), &readlen, (char *)ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		jffs2_free_raw_inode(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		pr_warn("Error reading node from 0x%08x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			ref_offset(fd->raw), ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (readlen != sizeof(*ri)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		jffs2_free_raw_inode(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		pr_warn("Short read from 0x%08x: wanted 0x%zx bytes, got 0x%zx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			ref_offset(fd->raw), sizeof(*ri), readlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	crc = crc32(0, ri, sizeof(*ri)-8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	jffs2_dbg(1, "Node read from %08x: node_crc %08x, calculated CRC %08x. dsize %x, csize %x, offset %x, buf %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		  ref_offset(fd->raw), je32_to_cpu(ri->node_crc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		  crc, je32_to_cpu(ri->dsize), je32_to_cpu(ri->csize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		  je32_to_cpu(ri->offset), buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (crc != je32_to_cpu(ri->node_crc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pr_warn("Node CRC %08x != calculated CRC %08x for node at %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			je32_to_cpu(ri->node_crc), crc, ref_offset(fd->raw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		goto out_ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* There was a bug where we wrote hole nodes out with csize/dsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	   swapped. Deal with it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (ri->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri->dsize) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	    je32_to_cpu(ri->csize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		ri->dsize = ri->csize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		ri->csize = cpu_to_je32(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	D1(if(ofs + len > je32_to_cpu(ri->dsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			pr_warn("jffs2_read_dnode() asked for %d bytes at %d from %d-byte node\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				len, ofs, je32_to_cpu(ri->dsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		goto out_ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	});
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (ri->compr == JFFS2_COMPR_ZERO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		memset(buf, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		goto out_ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* Cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	   Reading whole node and it's uncompressed - read directly to buffer provided, check CRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	   Reading whole node and it's compressed - read into comprbuf, check CRC and decompress to buffer provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	   Reading partial node and it's uncompressed - read into readbuf, check CRC, and copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	   Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		readbuf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		readbuf = kmalloc(je32_to_cpu(ri->csize), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (!readbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			goto out_ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (ri->compr != JFFS2_COMPR_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (len < je32_to_cpu(ri->dsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			decomprbuf = kmalloc(je32_to_cpu(ri->dsize), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			if (!decomprbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				goto out_readbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			decomprbuf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		decomprbuf = readbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	jffs2_dbg(2, "Read %d bytes to %p\n", je32_to_cpu(ri->csize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		  readbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ret = jffs2_flash_read(c, (ref_offset(fd->raw)) + sizeof(*ri),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			       je32_to_cpu(ri->csize), &readlen, readbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (!ret && readlen != je32_to_cpu(ri->csize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		goto out_decomprbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	crc = crc32(0, readbuf, je32_to_cpu(ri->csize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (crc != je32_to_cpu(ri->data_crc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		pr_warn("Data CRC %08x != calculated CRC %08x for node at %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			je32_to_cpu(ri->data_crc), crc, ref_offset(fd->raw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		goto out_decomprbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	jffs2_dbg(2, "Data CRC matches calculated CRC %08x\n", crc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (ri->compr != JFFS2_COMPR_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		jffs2_dbg(2, "Decompress %d bytes from %p to %d bytes at %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			  je32_to_cpu(ri->csize), readbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			  je32_to_cpu(ri->dsize), decomprbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		ret = jffs2_decompress(c, f, ri->compr | (ri->usercompr << 8), readbuf, decomprbuf, je32_to_cpu(ri->csize), je32_to_cpu(ri->dsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			pr_warn("Error: jffs2_decompress returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			goto out_decomprbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (len < je32_to_cpu(ri->dsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		memcpy(buf, decomprbuf+ofs, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  out_decomprbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if(decomprbuf != buf && decomprbuf != readbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		kfree(decomprbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  out_readbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if(readbuf != buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		kfree(readbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  out_ri:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	jffs2_free_raw_inode(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int jffs2_read_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			   unsigned char *buf, uint32_t offset, uint32_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	uint32_t end = offset + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct jffs2_node_frag *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	jffs2_dbg(1, "%s(): ino #%u, range 0x%08x-0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		  __func__, f->inocache->ino, offset, offset + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	frag = jffs2_lookup_node_frag(&f->fragtree, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* XXX FIXME: Where a single physical node actually shows up in two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	   frags, we read it twice. Don't do that. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* Now we're pointing at the first frag which overlaps our page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 * (or perhaps is before it, if we've been asked to read off the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * end of the file). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	while(offset < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		jffs2_dbg(2, "%s(): offset %d, end %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			  __func__, offset, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (unlikely(!frag || frag->ofs > offset ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			     frag->ofs + frag->size <= offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			uint32_t holesize = end - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			if (frag && frag->ofs > offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				jffs2_dbg(1, "Eep. Hole in ino #%u fraglist. frag->ofs = 0x%08x, offset = 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 					  f->inocache->ino, frag->ofs, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				holesize = min(holesize, frag->ofs - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			jffs2_dbg(1, "Filling non-frag hole from %d-%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				  offset, offset + holesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			memset(buf, 0, holesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			buf += holesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			offset += holesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		} else if (unlikely(!frag->node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			uint32_t holeend = min(end, frag->ofs + frag->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			jffs2_dbg(1, "Filling frag hole from %d-%d (frag 0x%x 0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				  offset, holeend, frag->ofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 				  frag->ofs + frag->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			memset(buf, 0, holeend - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			buf += holeend - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			offset = holeend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			frag = frag_next(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			uint32_t readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			uint32_t fragofs; /* offset within the frag to start reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			fragofs = offset - frag->ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			readlen = min(frag->size - fragofs, end - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			jffs2_dbg(1, "Reading %d-%d from node at 0x%08x (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				  frag->ofs+fragofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				  frag->ofs + fragofs+readlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				  ref_offset(frag->node->raw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				  ref_flags(frag->node->raw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			ret = jffs2_read_dnode(c, f, frag->node, buf, fragofs + frag->ofs - frag->node->ofs, readlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			jffs2_dbg(2, "node read done\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				jffs2_dbg(1, "%s(): error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 					  __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 				memset(buf, 0, readlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			buf += readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			offset += readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			frag = frag_next(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			jffs2_dbg(2, "node read was OK. Looping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)