* [PATCH 1/7] jffs2reader: update the header inclusion block
@ 2011-09-19 11:25 Andy Shevchenko
2011-09-19 11:25 ` [PATCH 2/7] jffs2reader: eliminate compiler errors Andy Shevchenko
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
jffs2reader.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/jffs2reader.c b/jffs2reader.c
index d5a3d95..11f841d 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -64,7 +64,6 @@ BUGS:
#define PROGRAM_NAME "jffs2reader"
-#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -74,9 +73,10 @@ BUGS:
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/param.h>
#include <dirent.h>
-#include <linux/jffs2.h>
+#include <zlib.h>
+
+#include "mtd/jffs2-user.h"
#include "common.h"
#define SCRATCH_SIZE (5*1024*1024)
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/7] jffs2reader: eliminate compiler errors
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-20 21:11 ` Brian Norris
2011-09-19 11:25 ` [PATCH 3/7] jffs2reader: introduce ADD_BYTES macro Andy Shevchenko
` (5 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
There are many errors like "error: invalid operands to binary". This patch
converts the values to the proper types.
Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
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);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/7] jffs2reader: introduce ADD_BYTES macro
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
2011-09-19 11:25 ` [PATCH 2/7] jffs2reader: eliminate compiler errors Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-19 11:25 ` [PATCH 4/7] jffs2reader: get rid of linker error Andy Shevchenko
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
This macro is dedicated to get rid of the compiler errors:
lvalue required as left operand of assignment
Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
jffs2reader.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/jffs2reader.c b/jffs2reader.c
index 1fc9e74..9aee92c 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -88,6 +88,9 @@ BUGS:
#define MINOR(dev) ((dev)&0xff)
#endif
+/* macro to avoid "lvalue required as left operand of assignment" error */
+#define ADD_BYTES(p, n) ((p) = (typeof(p))((char *)(p) + (n)))
+
#define DIRENT_INO(dirent) ((dirent)!=NULL?je32_to_cpu((dirent)->ino):0)
#define DIRENT_PINO(dirent) ((dirent)!=NULL?je32_to_cpu((dirent)->pino):0)
@@ -441,7 +444,7 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
do {
while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
- ((char *) n) += 4;
+ ADD_BYTES(n, 4);
if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_INODE &&
@@ -459,7 +462,7 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
return (&(n->i));
}
- ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+ ADD_BYTES(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 */
@@ -509,7 +512,7 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
do {
while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
- ((char *) n) += 4;
+ ADD_BYTES(n, 4);
if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT &&
@@ -532,7 +535,7 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
}
}
- ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+ ADD_BYTES(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 */
@@ -596,7 +599,7 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
do {
while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
- ((char *) n) += 4;
+ ADD_BYTES(n, 4);
if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT &&
@@ -613,7 +616,7 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
}
}
- ((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+ ADD_BYTES(n, ((je32_to_cpu(n->u.totlen) + 3) & ~3));
} else
return dd;
} while (1);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/7] jffs2reader: get rid of linker error
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
2011-09-19 11:25 ` [PATCH 2/7] jffs2reader: eliminate compiler errors Andy Shevchenko
2011-09-19 11:25 ` [PATCH 3/7] jffs2reader: introduce ADD_BYTES macro Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-19 11:25 ` [PATCH 5/7] jffs2reader: use const char * for path variables Andy Shevchenko
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
There is a linker errors:
undefined reference to `target_endian'
This patch fixes the issue and turns on the jffs2reader build in the Makefile.
Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
Makefile | 2 +-
jffs2reader.c | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile
index 5a0044b..f067d86 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ MTD_BINS = \
nftldump nftl_format docfdisk \
rfddump rfdformat \
serve_image recv_image \
- sumtool #jffs2reader
+ sumtool jffs2reader
UBI_BINS = \
ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \
ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol
diff --git a/jffs2reader.c b/jffs2reader.c
index 9aee92c..52f8d34 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -102,6 +102,8 @@ struct dir {
char name[256];
};
+int target_endian = __BYTE_ORDER;
+
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,
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/7] jffs2reader: use const char * for path variables
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
` (2 preceding siblings ...)
2011-09-19 11:25 ` [PATCH 4/7] jffs2reader: get rid of linker error Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-19 11:25 ` [PATCH 6/7] jffs2reader: print ctime only by user's request Andy Shevchenko
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
This patch brings const char * type for path variables. It allows to eliminate
compiler warning.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
jffs2reader.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/jffs2reader.c b/jffs2reader.c
index 52f8d34..c0d118c 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -106,7 +106,7 @@ int target_endian = __BYTE_ORDER;
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 *);
@@ -116,12 +116,12 @@ struct jffs2_raw_dirent *resolvedirent(char *, size_t, uint32_t, uint32_t,
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 **);
@@ -299,7 +299,7 @@ const char *mode_string(int mode)
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;
@@ -678,7 +678,7 @@ struct jffs2_raw_dirent *resolveinode(char *o, size_t size, uint32_t ino)
*/
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 +794,7 @@ struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
*/
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 +807,7 @@ struct jffs2_raw_dirent *resolvepath(char *o, size_t size, uint32_t ino,
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;
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/7] jffs2reader: print ctime only by user's request
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
` (3 preceding siblings ...)
2011-09-19 11:25 ` [PATCH 5/7] jffs2reader: use const char * for path variables Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-19 11:25 ` [PATCH 7/7] jffs2reader: use major() and minor() helpers Andy Shevchenko
2011-09-21 6:33 ` [PATCH 1/7] jffs2reader: update the header inclusion block Bityutskiy, Artem
6 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
jffs2reader.c | 36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/jffs2reader.c b/jffs2reader.c
index c0d118c..238e617 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -107,7 +107,7 @@ int target_endian = __BYTE_ORDER;
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, const char *path,
- int recurse);
+ int recurse, int want_ctime);
void freedir(struct dir *);
struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino);
@@ -121,7 +121,7 @@ struct jffs2_raw_dirent *resolvepath0(char *, size_t, uint32_t, const char *,
struct jffs2_raw_dirent *resolvepath(char *, size_t, uint32_t, const char *,
uint32_t *);
-void lsdir(char *, size_t, const char *, int);
+void lsdir(char *, size_t, const char *, int, int);
void catfile(char *, size_t, char *, char *, size_t, size_t *);
int main(int, char **);
@@ -299,7 +299,8 @@ const char *mode_string(int mode)
d - dir struct
*/
-void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse)
+void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse,
+ int want_ctime)
{
char m;
char *filetime;
@@ -366,12 +367,14 @@ void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse
printf("%9ld ", (long)je32_to_cpu(ri->dsize));
}
d->name[d->nsize]='\0';
- if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
- /* hh:mm if less than 6 months old */
- printf("%6.6s %5.5s %s/%s%c", filetime + 4, filetime + 11, path, d->name, m);
- } else {
- printf("%6.6s %4.4s %s/%s%c", filetime + 4, filetime + 20, path, d->name, m);
+ if (want_ctime) {
+ if (age < 3600L * 24 * 365 / 2 && age > -15 * 60)
+ /* hh:mm if less than 6 months old */
+ printf("%6.6s %5.5s ", filetime + 4, filetime + 11);
+ else
+ printf("%6.6s %4.4s ", filetime + 4, filetime + 20);
}
+ printf("%s/%s%c", path, d->name, m);
if (d->type == DT_LNK) {
char symbuf[1024];
size_t symsize;
@@ -385,7 +388,7 @@ void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse
char *tmp;
tmp = xmalloc(BUFSIZ);
sprintf(tmp, "%s/%s", path, d->name);
- lsdir(o, size, tmp, recurse); /* Go recursive */
+ lsdir(o, size, tmp, recurse, want_ctime); /* Go recursive */
free(tmp);
}
@@ -807,7 +810,7 @@ struct jffs2_raw_dirent *resolvepath(char *o, size_t size, uint32_t ino,
p - path to be resolved
*/
-void lsdir(char *o, size_t size, const char *path, int recurse)
+void lsdir(char *o, size_t size, const char *path, int recurse, int want_ctime)
{
struct jffs2_raw_dirent *dd;
struct dir *d = NULL;
@@ -821,7 +824,7 @@ void lsdir(char *o, size_t size, const char *path, int recurse)
errmsg_die("%s: No such file or directory", path);
d = collectdir(o, size, ino, d);
- printdir(o, size, d, path, recurse);
+ printdir(o, size, d, path, recurse, want_ctime);
freedir(d);
}
@@ -861,7 +864,7 @@ void catfile(char *o, size_t size, char *path, char *b, size_t bsize,
int main(int argc, char **argv)
{
- int fd, opt, recurse = 0;
+ int fd, opt, recurse = 0, want_ctime = 0;
struct stat st;
char *scratch, *dir = NULL, *file = NULL;
@@ -869,7 +872,7 @@ int main(int argc, char **argv)
char *buf;
- while ((opt = getopt(argc, argv, "rd:f:")) > 0) {
+ while ((opt = getopt(argc, argv, "rd:f:t")) > 0) {
switch (opt) {
case 'd':
dir = optarg;
@@ -880,6 +883,9 @@ int main(int argc, char **argv)
case 'r':
recurse++;
break;
+ case 't':
+ want_ctime++;
+ break;
default:
fprintf(stderr,
"Usage: %s <image> [-d|-f] < path >\n",
@@ -901,7 +907,7 @@ int main(int argc, char **argv)
sys_errmsg_die("%s", argv[optind]);
if (dir)
- lsdir(buf, st.st_size, dir, recurse);
+ lsdir(buf, st.st_size, dir, recurse, want_ctime);
if (file) {
scratch = xmalloc(SCRATCH_SIZE);
@@ -911,7 +917,7 @@ int main(int argc, char **argv)
}
if (!dir && !file)
- lsdir(buf, st.st_size, "/", 1);
+ lsdir(buf, st.st_size, "/", 1, want_ctime);
free(buf);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/7] jffs2reader: use major() and minor() helpers
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
` (4 preceding siblings ...)
2011-09-19 11:25 ` [PATCH 6/7] jffs2reader: print ctime only by user's request Andy Shevchenko
@ 2011-09-19 11:25 ` Andy Shevchenko
2011-09-21 6:33 ` [PATCH 1/7] jffs2reader: update the header inclusion block Bityutskiy, Artem
6 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2011-09-19 11:25 UTC (permalink / raw)
To: Artem Bityutskiy, linux-mtd; +Cc: Alexey Dokuchaev, Andy Shevchenko
There are major() and minor() helpers in the standard library. We can use them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
jffs2reader.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)
diff --git a/jffs2reader.c b/jffs2reader.c
index 238e617..11a46eb 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -81,13 +81,6 @@ BUGS:
#define SCRATCH_SIZE (5*1024*1024)
-#ifndef MAJOR
-/* FIXME: I am using illicit insider knowledge of
- * kernel major/minor representation... */
-#define MAJOR(dev) (((dev)>>8)&0xff)
-#define MINOR(dev) ((dev)&0xff)
-#endif
-
/* macro to avoid "lvalue required as left operand of assignment" error */
#define ADD_BYTES(p, n) ((p) = (typeof(p))((char *)(p) + (n)))
@@ -362,7 +355,7 @@ void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse
dev_t rdev;
size_t devsize;
putblock((char*)&rdev, sizeof(rdev), &devsize, ri);
- printf("%4d, %3d ", (int)MAJOR(rdev), (int)MINOR(rdev));
+ printf("%4d, %3d ", major(rdev), minor(rdev));
} else {
printf("%9ld ", (long)je32_to_cpu(ri->dsize));
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/7] jffs2reader: eliminate compiler errors
2011-09-19 11:25 ` [PATCH 2/7] jffs2reader: eliminate compiler errors Andy Shevchenko
@ 2011-09-20 21:11 ` Brian Norris
0 siblings, 0 replies; 9+ messages in thread
From: Brian Norris @ 2011-09-20 21:11 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Alexey Dokuchaev, Artem Bityutskiy, linux-mtd
On Mon, Sep 19, 2011 at 4:25 AM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> -#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)
Can you include proper spacing around the '!=', '?', and ':'
operators? It's easier to read.
Otherwise, I don't know the specifics on JFSS2-endianness, but the
motivation looks good...
Brian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/7] jffs2reader: update the header inclusion block
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
` (5 preceding siblings ...)
2011-09-19 11:25 ` [PATCH 7/7] jffs2reader: use major() and minor() helpers Andy Shevchenko
@ 2011-09-21 6:33 ` Bityutskiy, Artem
6 siblings, 0 replies; 9+ messages in thread
From: Bityutskiy, Artem @ 2011-09-21 6:33 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Alexey Dokuchaev, linux-mtd@lists.infradead.org
Amended the spacing as Brian asked and pushed the series, thanks!
--
Best Regards,
Artem Bityutskiy
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki
Business Identity Code: 0357606 - 4
Domiciled in Helsinki
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-09-21 6:33 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-19 11:25 [PATCH 1/7] jffs2reader: update the header inclusion block Andy Shevchenko
2011-09-19 11:25 ` [PATCH 2/7] jffs2reader: eliminate compiler errors Andy Shevchenko
2011-09-20 21:11 ` Brian Norris
2011-09-19 11:25 ` [PATCH 3/7] jffs2reader: introduce ADD_BYTES macro Andy Shevchenko
2011-09-19 11:25 ` [PATCH 4/7] jffs2reader: get rid of linker error Andy Shevchenko
2011-09-19 11:25 ` [PATCH 5/7] jffs2reader: use const char * for path variables Andy Shevchenko
2011-09-19 11:25 ` [PATCH 6/7] jffs2reader: print ctime only by user's request Andy Shevchenko
2011-09-19 11:25 ` [PATCH 7/7] jffs2reader: use major() and minor() helpers Andy Shevchenko
2011-09-21 6:33 ` [PATCH 1/7] jffs2reader: update the header inclusion block Bityutskiy, Artem
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).