From patchwork Mon Sep 19 11:25:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 115396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B483BB7090 for ; Tue, 20 Sep 2011 07:48:04 +1000 (EST) Received: from canuck.infradead.org ([134.117.69.58]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1R5dMF-0007AX-G4; Mon, 19 Sep 2011 12:53:59 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R5bzM-0001na-MR; Mon, 19 Sep 2011 11:26:16 +0000 Received: from mga11.intel.com ([192.55.52.93]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R5bzH-0001lp-1H for linux-mtd@lists.infradead.org; Mon, 19 Sep 2011 11:26:12 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 19 Sep 2011 04:26:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.68,404,1312182000"; d="scan'208";a="53139295" Received: from unknown (HELO smile) ([10.255.14.174]) by fmsmga001.fm.intel.com with ESMTP; 19 Sep 2011 04:26:06 -0700 Received: from andy by smile with local (Exim 4.76) (envelope-from ) id 1R5byx-0002av-HY; Mon, 19 Sep 2011 14:25:51 +0300 From: Andy Shevchenko To: Artem Bityutskiy , linux-mtd@lists.infradead.org Subject: [PATCH 2/7] jffs2reader: eliminate compiler errors Date: Mon, 19 Sep 2011 14:25:19 +0300 Message-Id: <44e5a23d776bc650f9b605911f09deb438506c05.1316431431.git.andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110919_072611_417433_B9E229B6 X-CRM114-Status: GOOD ( 17.47 ) X-Spam-Score: -5.5 (-----) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-5.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.55.52.93 listed in list.dnswl.org] Cc: Alexey Dokuchaev , Andy Shevchenko X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org There are many errors like "error: invalid operands to binary". This patch converts the values to the proper types. Signed-off-by: Alexey Dokuchaev Signed-off-by: Andy Shevchenko --- jffs2reader.c | 77 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 39 insertions(+), 38 deletions(-) diff --git a/jffs2reader.c b/jffs2reader.c index 11f841d..1fc9e74 100644 --- a/jffs2reader.c +++ b/jffs2reader.c @@ -88,9 +88,8 @@ BUGS: #define MINOR(dev) ((dev)&0xff) #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?je32_to_cpu((dirent)->ino):0) +#define DIRENT_PINO(dirent) ((dirent)!=NULL?je32_to_cpu((dirent)->pino):0) struct dir { struct dir *next; @@ -135,28 +134,28 @@ int main(int, char **); void putblock(char *b, size_t bsize, size_t * rsize, struct jffs2_raw_inode *n) { - uLongf dlen = n->dsize; + uLongf dlen = je32_to_cpu(n->dsize); - if (n->isize > bsize || (n->offset + dlen) > bsize) + if (je32_to_cpu(n->isize) > bsize || (je32_to_cpu(n->offset) + dlen) > bsize) errmsg_die("File does not fit into buffer!"); - if (*rsize < n->isize) - bzero(b + *rsize, n->isize - *rsize); + if (*rsize < je32_to_cpu(n->isize)) + bzero(b + *rsize, je32_to_cpu(n->isize) - *rsize); switch (n->compr) { case JFFS2_COMPR_ZLIB: - uncompress((Bytef *) b + n->offset, &dlen, + uncompress((Bytef *) b + je32_to_cpu(n->offset), &dlen, (Bytef *) ((char *) n) + sizeof(struct jffs2_raw_inode), - (uLongf) n->csize); + (uLongf) je32_to_cpu(n->csize)); break; case JFFS2_COMPR_NONE: - memcpy(b + n->offset, + memcpy(b + je32_to_cpu(n->offset), ((char *) n) + sizeof(struct jffs2_raw_inode), dlen); break; case JFFS2_COMPR_ZERO: - bzero(b + n->offset, dlen); + bzero(b + je32_to_cpu(n->offset), dlen); break; /* [DYN]RUBIN support required! */ @@ -165,7 +164,7 @@ void putblock(char *b, size_t bsize, size_t * rsize, errmsg_die("Unsupported compression method!"); } - *rsize = n->isize; + *rsize = je32_to_cpu(n->isize); } /* adds/removes directory node into dir struct. */ @@ -184,13 +183,13 @@ struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n) o = dd; - if (n->ino) { + if (je32_to_cpu(n->ino)) { if (dd == NULL) { d = xmalloc(sizeof(struct dir)); d->type = n->type; memcpy(d->name, n->name, n->nsize); d->nsize = n->nsize; - d->ino = n->ino; + d->ino = je32_to_cpu(n->ino); d->next = NULL; return d; @@ -200,7 +199,7 @@ struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n) if (n->nsize == dd->nsize && !memcmp(n->name, dd->name, n->nsize)) { dd->type = n->type; - dd->ino = n->ino; + dd->ino = je32_to_cpu(n->ino); return o; } @@ -210,7 +209,7 @@ struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n) 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 = je32_to_cpu(n->ino); dd->next->next = NULL; return o; @@ -301,6 +300,7 @@ void printdir(char *o, size_t size, struct dir *d, char *path, int recurse) char *filetime; time_t age; struct jffs2_raw_inode *ri; + jint32_t mode; if (!path) return; @@ -348,16 +348,17 @@ void printdir(char *o, size_t size, struct dir *d, char *path, int recurse) } 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) - je32_to_cpu(ri->ctime); + mode.v32 = ri->mode.m; + printf("%s %-4d %-8d %-8d ", mode_string(je32_to_cpu(mode)), + 1, je16_to_cpu(ri->uid), je16_to_cpu(ri->gid)); 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)je32_to_cpu(ri->dsize)); } d->name[d->nsize]='\0'; if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { @@ -439,12 +440,12 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino) lr = n; do { - while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK) + while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK) ((char *) n) += 4; - 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 && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) { + if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_INODE && + je32_to_cpu(n->i.ino) == ino && (v = je32_to_cpu(n->i.version)) > vcur) { /* XXX crc check */ if (vmaxt < v) @@ -458,7 +459,7 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino) return (&(n->i)); } - ((char *) n) += ((n->u.totlen + 3) & ~3); + ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3); } else n = (union jffs2_node_union *) o; /* we're at the end, rewind to the beginning */ @@ -507,12 +508,12 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d) lr = n; do { - while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK) + while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK) ((char *) n) += 4; - 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 && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) { + if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT && + je32_to_cpu(n->d.pino) == ino && (v = je32_to_cpu(n->d.version)) > vcur) { /* XXX crc check */ if (vmaxt < v) @@ -531,7 +532,7 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d) } } - ((char *) n) += ((n->u.totlen + 3) & ~3); + ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3); } else n = (union jffs2_node_union *) o; /* we're at the end, rewind to the beginning */ @@ -545,7 +546,7 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d) lr = n = (union jffs2_node_union *) (((char *) mp) + - ((mp->u.totlen + 3) & ~3)); + ((je32_to_cpu(mp->u.totlen) + 3) & ~3)); vcur = vmin; } @@ -594,14 +595,14 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size, n = (union jffs2_node_union *) o; do { - while (n < e && n->u.magic != JFFS2_MAGIC_BITMASK) + while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK) ((char *) n) += 4; - 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 && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) { + if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT && + (!ino || je32_to_cpu(n->d.ino) == ino) && + (v = je32_to_cpu(n->d.version)) > vmax && + (!pino || (je32_to_cpu(n->d.pino) == pino && nsize == n->d.nsize && !memcmp(name, n->d.name, nsize)))) { /* XXX crc check */ @@ -612,7 +613,7 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size, } } - ((char *) n) += ((n->u.totlen + 3) & ~3); + ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3); } else return dd; } while (1);