[PATCH 4/4] util/jffs2reader better output formats
Suzuki Takashi
suzuki.takashi at gmail.com
Fri Oct 14 23:13:46 EDT 2005
This is the 4th patch for util/jffs2reader.c.
It is not a bug fix and makes some improvements.
Please review and apply if it is ok.
Thanks.
[PATCH 4/4] util/jffs2reader better output formats
Some of the listings of the jffs2reader are unaligned and
prefixed by extra slashes.
This patch adjusts some alignments and removes extra slashes.
It also enables -r (recursive) option even if -d is not specified.
With this change, the default behavior comes to list files
NOT recursively like the command `ls'.
This patch depends on:
[PATCH 1/4] util/jffs2reader compile fix
[PATCH 2/4] util/jffs2reader file size fix
[PATCH 3/4] util/jffs2reader catfile fix
Signed-off-by: Suzuki Takashi <suzuki.takashi at gmail.com>
--- jffs2reader.c.catfile 2005-10-10 18:22:02.000000000 +0900
+++ jffs2reader.c 2005-10-10 19:31:21.000000000 +0900
@@ -320,6 +320,7 @@ void printdir(char *o, size_t size, stru
char *filetime;
time_t age;
struct jffs2_raw_inode *ri;
+ struct dir *od = d;
if (!path)
return;
@@ -369,7 +370,7 @@ void printdir(char *o, size_t size, stru
age = je32_to_cpu (ri->ctime);
filetime = ctime(&age);
age = time(NULL) - je32_to_cpu (ri->ctime);
- printf("%s %-4d %-8d %-8d ", mode_string(jemode_to_cpu (ri->mode)),
+ printf("%s %-4d %-5d %-5d ", mode_string(jemode_to_cpu (ri->mode)),
1, je16_to_cpu (ri->uid), je16_to_cpu (ri->gid));
if ( d->type==DT_BLK || d->type==DT_CHR ) {
dev_t rdev;
@@ -382,9 +383,14 @@ void printdir(char *o, size_t size, stru
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);
+ printf("%6.6s %5.5s ", filetime + 4, filetime + 11);
} else {
- printf("%6.6s %4.4s %s/%s%c", filetime + 4, filetime + 20, path,
d->name, m);
+ printf("%6.6s %4.4s ", filetime + 4, filetime + 20);
+ }
+ if (*path == '\0') {
+ printf ("%s%c", d->name, m);
+ } else {
+ printf ("%s/%s%c", path, d->name, m);
}
if (d->type == DT_LNK) {
char symbuf[1024];
@@ -395,19 +401,32 @@ void printdir(char *o, size_t size, stru
}
printf("\n");
- if (d->type == DT_DIR && recurse) {
- char *tmp;
- tmp = malloc(BUFSIZ);
- if (!tmp) {
- fprintf(stderr, "memory exhausted\n");
- exit(EXIT_FAILURE);
+ d = d->next;
+ }
+
+ if (recurse) {
+ d = od;
+ while (d != NULL) {
+ if (d->type == DT_DIR) {
+ char *tmp;
+ tmp = malloc(BUFSIZ);
+ if (!tmp) {
+ fprintf(stderr, "memory exhausted\n");
+ exit(EXIT_FAILURE);
+ }
+ printf ("\n");
+ if (*path == '\0') {
+ strcpy (tmp, d->name);
+ } else {
+ sprintf(tmp, "%s/%s", path, d->name);
+ }
+ printf("%s/\n", tmp);
+ lsdir(o, size, tmp, recurse); /* Go recursive */
+ free(tmp);
}
- sprintf(tmp, "%s/%s", path, d->name);
- lsdir(o, size, tmp, recurse); /* Go recursive */
- free(tmp);
- }
- d = d->next;
+ d = d->next;
+ }
}
}
@@ -1032,7 +1051,7 @@ int main(int argc, char **argv)
}
if (!dir && !file)
- lsdir(buf, st.st_size, "/", 1);
+ lsdir(buf, st.st_size, "", recurse);
free(buf);
--
Suzuki Takashi
More information about the linux-mtd
mailing list