diff mbox

jffs2reader fix

Message ID AANLkTinNObFTNzS6PPuiZc+cS_Hh-WKY6+=Nxama7=yc@mail.gmail.com
State New, archived
Headers show

Commit Message

Benedikt Heinz Feb. 18, 2011, 1:29 p.m. UTC
Hi!

I changed the jffs2reader.c so it'll compile again.
Seems to work - I successfully tested it on a few jffs2 images.

Attached you'll find the patch and the full file.

Reply directly to me as I'm not on the list.

Regards,

Benedikt

--
Benedikt 'Hunz' Heinz
Jabber: hunz@jabber.berlin.ccc.de

Comments

Artem Bityutskiy Feb. 25, 2011, 10:47 a.m. UTC | #1
On Fri, 2011-02-18 at 14:29 +0100, Benedikt Heinz wrote:
> Hi!
> 
> I changed the jffs2reader.c so it'll compile again.
> Seems to work - I successfully tested it on a few jffs2 images.
> 
> Attached you'll find the patch and the full file.
> 
> Reply directly to me as I'm not on the list.

Would you please split your patch on several smaller patches, add proper
comment and send them as a nice series of patches?
diff mbox

Patch

--- jffs2reader.c.bak	2011-02-18 13:22:22.595754368 +0100
+++ jffs2reader.c	2011-02-18 14:19:42.019754370 +0100
@@ -88,8 +88,8 @@ 
 #endif
 
 
-#define DIRENT_INO(dirent) ((dirent)!=NULL?(dirent)->ino:0)
-#define DIRENT_PINO(dirent) ((dirent)!=NULL?(dirent)->pino:0)
+#define DIRENT_INO(dirent) ((dirent)!=NULL?(dirent)->ino.v32:0)
+#define DIRENT_PINO(dirent) ((dirent)!=NULL?(dirent)->pino.v32:0)
 
 struct dir {
 	struct dir *next;
@@ -101,7 +101,7 @@ 
 
 void putblock(char *, size_t, size_t *, struct jffs2_raw_inode *);
 struct dir *putdir(struct dir *, struct jffs2_raw_dirent *);
-void printdir(char *o, size_t size, struct dir *d, char *path,
+void printdir(char *o, size_t size, struct dir *d, const char *path,
 		int recurse);
 void freedir(struct dir *);
 
@@ -111,12 +111,12 @@ 
 struct jffs2_raw_dirent *resolvename(char *, size_t, uint32_t, char *, uint8_t);
 struct jffs2_raw_dirent *resolveinode(char *, size_t, uint32_t);
 
-struct jffs2_raw_dirent *resolvepath0(char *, size_t, uint32_t, char *,
+struct jffs2_raw_dirent *resolvepath0(char *, size_t, uint32_t, const char *,
 		uint32_t *, int);
-struct jffs2_raw_dirent *resolvepath(char *, size_t, uint32_t, char *,
+struct jffs2_raw_dirent *resolvepath(char *, size_t, uint32_t, const char *,
 		uint32_t *);
 
-void lsdir(char *, size_t, char *, int);
+void lsdir(char *, size_t, const char *, int);
 void catfile(char *, size_t, char *, char *, size_t, size_t *);
 
 int main(int, char **);
@@ -134,30 +134,30 @@ 
 void putblock(char *b, size_t bsize, size_t * rsize,
 		struct jffs2_raw_inode *n)
 {
-	uLongf dlen = n->dsize;
+	uLongf dlen = n->dsize.v32;
 
-	if (n->isize > bsize || (n->offset + dlen) > bsize) {
+	if (n->isize.v32 > bsize || (n->offset.v32 + dlen) > bsize) {
 		fprintf(stderr, "File does not fit into buffer!\n");
 		exit(EXIT_FAILURE);
 	}
 
-	if (*rsize < n->isize)
-		bzero(b + *rsize, n->isize - *rsize);
+	if (*rsize < n->isize.v32)
+		bzero(b + *rsize, n->isize.v32 - *rsize);
 
 	switch (n->compr) {
 		case JFFS2_COMPR_ZLIB:
-			uncompress((Bytef *) b + n->offset, &dlen,
+			uncompress((Bytef *) b + n->offset.v32, &dlen,
 					(Bytef *) ((char *) n) + sizeof(struct jffs2_raw_inode),
-					(uLongf) n->csize);
+					(uLongf) n->csize.v32);
 			break;
 
 		case JFFS2_COMPR_NONE:
-			memcpy(b + n->offset,
+			memcpy(b + n->offset.v32,
 					((char *) n) + sizeof(struct jffs2_raw_inode), dlen);
 			break;
 
 		case JFFS2_COMPR_ZERO:
-			bzero(b + n->offset, dlen);
+			bzero(b + n->offset.v32, dlen);
 			break;
 
 			/* [DYN]RUBIN support required! */
@@ -167,7 +167,7 @@ 
 			exit(EXIT_FAILURE);
 	}
 
-	*rsize = n->isize;
+	*rsize = n->isize.v32;
 }
 
 /* adds/removes directory node into dir struct. */
@@ -186,13 +186,13 @@ 
 
 	o = dd;
 
-	if (n->ino) {
+	if (n->ino.v32) {
 		if (dd == NULL) {
 			d = malloc(sizeof(struct dir));
 			d->type = n->type;
 			memcpy(d->name, n->name, n->nsize);
 			d->nsize = n->nsize;
-			d->ino = n->ino;
+			d->ino = n->ino.v32;
 			d->next = NULL;
 
 			return d;
@@ -202,7 +202,7 @@ 
 			if (n->nsize == dd->nsize &&
 					!memcmp(n->name, dd->name, n->nsize)) {
 				dd->type = n->type;
-				dd->ino = n->ino;
+				dd->ino = n->ino.v32;
 
 				return o;
 			}
@@ -212,7 +212,7 @@ 
 				dd->next->type = n->type;
 				memcpy(dd->next->name, n->name, n->nsize);
 				dd->next->nsize = n->nsize;
-				dd->next->ino = n->ino;
+				dd->next->ino = n->ino.v32;
 				dd->next->next = NULL;
 
 				return o;
@@ -297,7 +297,7 @@ 
    d       - dir struct
  */
 
-void printdir(char *o, size_t size, struct dir *d, char *path, int recurse)
+void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse)
 {
 	char m;
 	char *filetime;
@@ -350,16 +350,16 @@ 
 		}
 
 		filetime = ctime((const time_t *) &(ri->ctime));
-		age = time(NULL) - ri->ctime;
-		printf("%s %-4d %-8d %-8d ", mode_string(ri->mode),
-				1, ri->uid, ri->gid);
+		age = time(NULL) - ri->ctime.v32;
+		printf("%s %-4d %-8d %-8d ", mode_string(ri->mode.m),
+				1, ri->uid.v16, ri->gid.v16);
 		if ( d->type==DT_BLK || d->type==DT_CHR ) {
 			dev_t rdev;
 			size_t devsize;
 			putblock((char*)&rdev, sizeof(rdev), &devsize, ri);
 			printf("%4d, %3d ", (int)MAJOR(rdev), (int)MINOR(rdev));
 		} else {
-			printf("%9ld ", (long)ri->dsize);
+			printf("%9ld ", (long)ri->dsize.v32);
 		}
 		d->name[d->nsize]='\0';
 		if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
@@ -445,12 +445,15 @@ 
 	lr = n;
 
 	do {
-		while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+		while (n < e && n->u.magic.v16 != JFFS2_MAGIC_BITMASK) {
+			char * n_ = (char *) n;
+			n_ += 4;
+			n = (union jffs2_node_union *) n_;
+		}
 
-		if (n < e && n->u.magic == JFFS2_MAGIC_BITMASK) {
-			if (n->u.nodetype == JFFS2_NODETYPE_INODE &&
-					n->i.ino == ino && (v = n->i.version) > vcur) {
+		if (n < e && n->u.magic.v16 == JFFS2_MAGIC_BITMASK) {
+			if (n->u.nodetype.v16 == JFFS2_NODETYPE_INODE &&
+					n->i.ino.v32 == ino && (v = n->i.version.v32) > vcur) {
 				/* XXX crc check */
 
 				if (vmaxt < v)
@@ -464,7 +467,11 @@ 
 					return (&(n->i));
 			}
 
-			((char *) n) += ((n->u.totlen + 3) & ~3);
+			{
+			char * n_ = (char *) n;
+			n_ += ((n->u.totlen.v32 + 3) & ~3);
+			n = (union jffs2_node_union *) n_;
+			}
 		} else
 			n = (union jffs2_node_union *) o;	/* we're at the end, rewind to the beginning */
 
@@ -513,12 +520,15 @@ 
 	lr = n;
 
 	do {
-		while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+		while (n < e && n->u.magic.v16 != JFFS2_MAGIC_BITMASK)  {
+			char * n_ = (char *) n;
+			n_ += 4;
+			n = (union jffs2_node_union *) n_;
+		}
 
-		if (n < e && n->u.magic == JFFS2_MAGIC_BITMASK) {
-			if (n->u.nodetype == JFFS2_NODETYPE_DIRENT &&
-					n->d.pino == ino && (v = n->d.version) > vcur) {
+		if (n < e && n->u.magic.v16 == JFFS2_MAGIC_BITMASK) {
+			if (n->u.nodetype.v16 == JFFS2_NODETYPE_DIRENT &&
+					n->d.pino.v32 == ino && (v = n->d.version.v32) > vcur) {
 				/* XXX crc check */
 
 				if (vmaxt < v)
@@ -537,7 +547,12 @@ 
 				}
 			}
 
-			((char *) n) += ((n->u.totlen + 3) & ~3);
+			{
+			char * n_ = (char *) n;
+			n_ += ((n->u.totlen.v32 + 3) & ~3);
+			n = (union jffs2_node_union *) n_;
+			}
+
 		} else
 			n = (union jffs2_node_union *) o;	/* we're at the end, rewind to the beginning */
 
@@ -551,7 +566,7 @@ 
 
 				lr = n =
 					(union jffs2_node_union *) (((char *) mp) +
-							((mp->u.totlen + 3) & ~3));
+							((mp->u.totlen.v32 + 3) & ~3));
 
 				vcur = vmin;
 			}
@@ -600,14 +615,17 @@ 
 	n = (union jffs2_node_union *) o;
 
 	do {
-		while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+		while (n < e && n->u.magic.v16 != JFFS2_MAGIC_BITMASK) {
+			char * n_ = (char *) n;
+			n_ += 4;
+			n = (union jffs2_node_union *) n_;
+		}
 
-		if (n < e && n->u.magic == JFFS2_MAGIC_BITMASK) {
-			if (n->u.nodetype == JFFS2_NODETYPE_DIRENT &&
-					(!ino || n->d.ino == ino) &&
-					(v = n->d.version) > vmax &&
-					(!pino || (n->d.pino == pino &&
+		if (n < e && n->u.magic.v16 == JFFS2_MAGIC_BITMASK) {
+			if (n->u.nodetype.v16 == JFFS2_NODETYPE_DIRENT &&
+					(!ino || n->d.ino.v32 == ino) &&
+					(v = n->d.version.v32) > vmax &&
+					(!pino || (n->d.pino.v32 == pino &&
 							   nsize == n->d.nsize &&
 							   !memcmp(name, n->d.name, nsize)))) {
 				/* XXX crc check */
@@ -618,7 +636,12 @@ 
 				}
 			}
 
-			((char *) n) += ((n->u.totlen + 3) & ~3);
+			{
+			char * n_ = (char *) n;
+			n_ += ((n->u.totlen.v32 + 3) & ~3);
+			n = (union jffs2_node_union *) n_;
+			}
+
 		} else
 			return dd;
 	} while (1);
@@ -678,7 +701,7 @@ 
  */
 
 struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
-		char *p, uint32_t * inos, int recc)
+		const char *p, uint32_t * inos, int recc)
 {
 	struct jffs2_raw_dirent *dir = NULL;
 
@@ -794,7 +817,7 @@ 
  */
 
 struct jffs2_raw_dirent *resolvepath(char *o, size_t size, uint32_t ino,
-		char *p, uint32_t * inos)
+		const char *p, uint32_t * inos)
 {
 	return resolvepath0(o, size, ino, p, inos, 0);
 }
@@ -807,7 +830,7 @@ 
    p       - path to be resolved
  */
 
-void lsdir(char *o, size_t size, char *path, int recurse)
+void lsdir(char *o, size_t size, const char *path, int recurse)
 {
 	struct jffs2_raw_dirent *dd;
 	struct dir *d = NULL;
@@ -861,7 +884,10 @@ 
 	ri = find_raw_inode(o, size, ino);
 	putblock(b, bsize, rsize, ri);
 
-	write(1, b, *rsize);
+	if(write(1, b, *rsize) != *rsize) {
+		fprintf(stderr, "write failed!?\n");
+		exit(EXIT_FAILURE);
+	}
 }
 
 /* usage example */