summaryrefslogtreecommitdiff
path: root/jffs-dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'jffs-dump.c')
-rw-r--r--jffs-dump.c374
1 files changed, 187 insertions, 187 deletions
diff --git a/jffs-dump.c b/jffs-dump.c
index 771025e..4d76aca 100644
--- a/jffs-dump.c
+++ b/jffs-dump.c
@@ -27,8 +27,8 @@
/* How many padding bytes should be inserted between two chunks of data
on the flash? */
#define JFFS_GET_PAD_BYTES(size) ((JFFS_ALIGN_SIZE \
- - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
- % JFFS_ALIGN_SIZE)
+ - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
+ % JFFS_ALIGN_SIZE)
#define JFFS_EMPTY_BITMASK 0xffffffff
#define JFFS_MAGIC_BITMASK 0x34383931
@@ -38,36 +38,36 @@
struct jffs_raw_inode
{
- uint32_t magic; /* A constant magic number. */
- uint32_t ino; /* Inode number. */
- uint32_t pino; /* Parent's inode number. */
- uint32_t version; /* Version number. */
- uint32_t mode; /* file_type, mode */
- uint16_t uid;
- uint16_t gid;
- uint32_t atime;
- uint32_t mtime;
- uint32_t ctime;
- uint32_t offset; /* Where to begin to write. */
- uint32_t dsize; /* Size of the file data. */
- uint32_t rsize; /* How much are going to be replaced? */
- uint8_t nsize; /* Name length. */
- uint8_t nlink; /* Number of links. */
- uint8_t spare : 6; /* For future use. */
- uint8_t rename : 1; /* Is this a special rename? */
- uint8_t deleted : 1; /* Has this file been deleted? */
- uint8_t accurate; /* The inode is obsolete if accurate == 0. */
- uint32_t dchksum; /* Checksum for the data. */
- uint16_t nchksum; /* Checksum for the name. */
- uint16_t chksum; /* Checksum for the raw_inode. */
+ uint32_t magic; /* A constant magic number. */
+ uint32_t ino; /* Inode number. */
+ uint32_t pino; /* Parent's inode number. */
+ uint32_t version; /* Version number. */
+ uint32_t mode; /* file_type, mode */
+ uint16_t uid;
+ uint16_t gid;
+ uint32_t atime;
+ uint32_t mtime;
+ uint32_t ctime;
+ uint32_t offset; /* Where to begin to write. */
+ uint32_t dsize; /* Size of the file data. */
+ uint32_t rsize; /* How much are going to be replaced? */
+ uint8_t nsize; /* Name length. */
+ uint8_t nlink; /* Number of links. */
+ uint8_t spare : 6; /* For future use. */
+ uint8_t rename : 1; /* Is this a special rename? */
+ uint8_t deleted : 1; /* Has this file been deleted? */
+ uint8_t accurate; /* The inode is obsolete if accurate == 0. */
+ uint32_t dchksum; /* Checksum for the data. */
+ uint16_t nchksum; /* Checksum for the name. */
+ uint16_t chksum; /* Checksum for the raw_inode. */
};
struct jffs_file
{
- struct jffs_raw_inode inode;
- char *name;
- unsigned char *data;
+ struct jffs_raw_inode inode;
+ char *name;
+ unsigned char *data;
};
@@ -83,68 +83,68 @@ int endian = ENDIAN_HOST;
static uint32_t jffs_checksum(void *data, int size);
void jffs_print_trace(const char *path, int depth);
int make_root_dir(FILE *fs, int first_ino, const char *root_dir_path,
- int depth);
+ int depth);
void write_file(struct jffs_file *f, FILE *fs, struct stat st);
void read_data(struct jffs_file *f, const char *path, int offset);
int mkfs(FILE *fs, const char *path, int ino, int parent, int depth);
-static uint32_t
+ static uint32_t
jffs_checksum(void *data, int size)
{
- uint32_t sum = 0;
- uint8_t *ptr = (uint8_t *)data;
+ uint32_t sum = 0;
+ uint8_t *ptr = (uint8_t *)data;
- while (size-- > 0)
- {
- sum += *ptr++;
- }
+ while (size-- > 0)
+ {
+ sum += *ptr++;
+ }
- return sum;
+ return sum;
}
-void
+ void
jffs_print_trace(const char *path, int depth)
{
- int path_len = strlen(path);
- int out_pos = depth * JFFS_TRACE_INDENT;
- int pos = path_len - 1;
- char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
-
- if (verbose >= 2)
- {
- fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
- }
-
- if (!out) {
- fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
- fprintf(stderr, " path: \"%s\"\n", path);
- fprintf(stderr, "depth: %d\n", depth);
- exit(1);
- }
-
- memset(out, ' ', depth * JFFS_TRACE_INDENT);
-
- if (path[pos] == '/')
- {
- pos--;
- }
- while (path[pos] && (path[pos] != '/'))
- {
- pos--;
- }
- for (pos++; path[pos] && (path[pos] != '/'); pos++)
- {
- out[out_pos++] = path[pos];
- }
- out[out_pos] = '\0';
- fprintf(stderr, "%s\n", out);
+ int path_len = strlen(path);
+ int out_pos = depth * JFFS_TRACE_INDENT;
+ int pos = path_len - 1;
+ char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
+
+ if (verbose >= 2)
+ {
+ fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
+ }
+
+ if (!out) {
+ fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
+ fprintf(stderr, " path: \"%s\"\n", path);
+ fprintf(stderr, "depth: %d\n", depth);
+ exit(1);
+ }
+
+ memset(out, ' ', depth * JFFS_TRACE_INDENT);
+
+ if (path[pos] == '/')
+ {
+ pos--;
+ }
+ while (path[pos] && (path[pos] != '/'))
+ {
+ pos--;
+ }
+ for (pos++; path[pos] && (path[pos] != '/'); pos++)
+ {
+ out[out_pos++] = path[pos];
+ }
+ out[out_pos] = '\0';
+ fprintf(stderr, "%s\n", out);
}
/* Print the contents of a raw inode. */
-void
+ void
jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
{
fprintf(stdout, "jffs_raw_inode: inode number: %u, version %u\n", raw_inode->ino, raw_inode->version);
@@ -165,13 +165,13 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
fprintf(stdout, " 0x%02x, /* nsize */\n", raw_inode->nsize);
fprintf(stdout, " 0x%02x, /* nlink */\n", raw_inode->nlink);
fprintf(stdout, " 0x%02x, /* spare */\n",
- raw_inode->spare);
+ raw_inode->spare);
fprintf(stdout, " %u, /* rename */\n",
- raw_inode->rename);
+ raw_inode->rename);
fprintf(stdout, " %u, /* deleted */\n",
- raw_inode->deleted);
+ raw_inode->deleted);
fprintf(stdout, " 0x%02x, /* accurate */\n",
- raw_inode->accurate);
+ raw_inode->accurate);
fprintf(stdout, " 0x%08x, /* dchksum */\n", raw_inode->dchksum);
fprintf(stdout, " 0x%04x, /* nchksum */\n", raw_inode->nchksum);
fprintf(stdout, " 0x%04x, /* chksum */\n", raw_inode->chksum);
@@ -180,71 +180,71 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
static void write_val32(uint32_t *adr, uint32_t val)
{
- switch(endian) {
- case ENDIAN_HOST:
- *adr = val;
- break;
- case ENDIAN_LITTLE:
- *adr = __cpu_to_le32(val);
- break;
- case ENDIAN_BIG:
- *adr = __cpu_to_be32(val);
- break;
- }
+ switch(endian) {
+ case ENDIAN_HOST:
+ *adr = val;
+ break;
+ case ENDIAN_LITTLE:
+ *adr = __cpu_to_le32(val);
+ break;
+ case ENDIAN_BIG:
+ *adr = __cpu_to_be32(val);
+ break;
+ }
}
static void write_val16(uint16_t *adr, uint16_t val)
{
- switch(endian) {
- case ENDIAN_HOST:
- *adr = val;
- break;
- case ENDIAN_LITTLE:
- *adr = __cpu_to_le16(val);
- break;
- case ENDIAN_BIG:
- *adr = __cpu_to_be16(val);
- break;
- }
+ switch(endian) {
+ case ENDIAN_HOST:
+ *adr = val;
+ break;
+ case ENDIAN_LITTLE:
+ *adr = __cpu_to_le16(val);
+ break;
+ case ENDIAN_BIG:
+ *adr = __cpu_to_be16(val);
+ break;
+ }
}
static uint32_t read_val32(uint32_t *adr)
{
- uint32_t val;
-
- switch(endian) {
- case ENDIAN_HOST:
- val = *adr;
- break;
- case ENDIAN_LITTLE:
- val = __le32_to_cpu(*adr);
- break;
- case ENDIAN_BIG:
- val = __be32_to_cpu(*adr);
- break;
- }
- return val;
+ uint32_t val;
+
+ switch(endian) {
+ case ENDIAN_HOST:
+ val = *adr;
+ break;
+ case ENDIAN_LITTLE:
+ val = __le32_to_cpu(*adr);
+ break;
+ case ENDIAN_BIG:
+ val = __be32_to_cpu(*adr);
+ break;
+ }
+ return val;
}
static uint16_t read_val16(uint16_t *adr)
{
- uint16_t val;
-
- switch(endian) {
- case ENDIAN_HOST:
- val = *adr;
- break;
- case ENDIAN_LITTLE:
- val = __le16_to_cpu(*adr);
- break;
- case ENDIAN_BIG:
- val = __be16_to_cpu(*adr);
- break;
- }
- return val;
+ uint16_t val;
+
+ switch(endian) {
+ case ENDIAN_HOST:
+ val = *adr;
+ break;
+ case ENDIAN_LITTLE:
+ val = __le16_to_cpu(*adr);
+ break;
+ case ENDIAN_BIG:
+ val = __be16_to_cpu(*adr);
+ break;
+ }
+ return val;
}
-int
+ int
main(int argc, char **argv)
{
int fs;
@@ -268,8 +268,8 @@ main(int argc, char **argv)
}
if (argc > 2) {
- myino = atol(argv[2]);
- printf("Printing ino #%d\n" , myino);
+ myino = atol(argv[2]);
+ printf("Printing ino #%d\n" , myino);
}
if (fstat(fs, &sb) < 0) {
@@ -286,73 +286,73 @@ main(int argc, char **argv)
}
switch(wordbuf) {
- case JFFS_EMPTY_BITMASK:
- // printf("0xff started at 0x%lx\n", pos);
- for (; pos < end && wordbuf == JFFS_EMPTY_BITMASK; pos += 4) {
- if (pread(fs, &wordbuf, 4, pos) < 0) {
- perror("pread");
- exit(1);
+ case JFFS_EMPTY_BITMASK:
+ // printf("0xff started at 0x%lx\n", pos);
+ for (; pos < end && wordbuf == JFFS_EMPTY_BITMASK; pos += 4) {
+ if (pread(fs, &wordbuf, 4, pos) < 0) {
+ perror("pread");
+ exit(1);
+ }
}
- }
- if (pos < end)
- pos -= 4;
- // printf("0xff ended at 0x%lx\n", pos);
- continue;
-
- case JFFS_DIRTY_BITMASK:
- // printf("0x00 started at 0x%lx\n", pos);
- for (; pos < end && wordbuf == JFFS_DIRTY_BITMASK; pos += 4) {
- if (pread(fs, &wordbuf, 4, pos) < 0) {
- perror("pread");
- exit(1);
+ if (pos < end)
+ pos -= 4;
+ // printf("0xff ended at 0x%lx\n", pos);
+ continue;
+
+ case JFFS_DIRTY_BITMASK:
+ // printf("0x00 started at 0x%lx\n", pos);
+ for (; pos < end && wordbuf == JFFS_DIRTY_BITMASK; pos += 4) {
+ if (pread(fs, &wordbuf, 4, pos) < 0) {
+ perror("pread");
+ exit(1);
+ }
}
- }
- if (pos < end)
- pos -=4;
- // printf("0x00 ended at 0x%lx\n", pos);
- continue;
-
- default:
- printf("Argh. Dirty memory at 0x%lx\n", pos);
- // file_hexdump(fs, pos, 128);
- for (pos += 4; pos < end; pos += 4) {
- if (pread(fs, &wordbuf, 4, pos) < 0) {
+ if (pos < end)
+ pos -=4;
+ // printf("0x00 ended at 0x%lx\n", pos);
+ continue;
+
+ default:
+ printf("Argh. Dirty memory at 0x%lx\n", pos);
+ // file_hexdump(fs, pos, 128);
+ for (pos += 4; pos < end; pos += 4) {
+ if (pread(fs, &wordbuf, 4, pos) < 0) {
+ perror("pread");
+ exit(1);
+ }
+ if (wordbuf == JFFS_MAGIC_BITMASK)
+ break;
+ }
+
+ case JFFS_MAGIC_BITMASK:
+ if (pread(fs, &ino, sizeof(ino), pos) < 0) {
perror("pread");
exit(1);
}
- if (wordbuf == JFFS_MAGIC_BITMASK)
- break;
- }
-
- case JFFS_MAGIC_BITMASK:
- if (pread(fs, &ino, sizeof(ino), pos) < 0) {
- perror("pread");
- exit(1);
- }
- if (myino == -1 || ino.ino == myino) {
- printf("Magic found at 0x%lx\n", pos);
- jffs_print_raw_inode(&ino);
- }
- pos += sizeof(ino);
-
- if (myino == -1 || ino.ino == myino) {
- if (ino.nsize) {
- if (pread(fs, namebuf, min(ino.nsize, 4095), pos) < 0) {
- perror("pread");
- exit(1);
+ if (myino == -1 || ino.ino == myino) {
+ printf("Magic found at 0x%lx\n", pos);
+ jffs_print_raw_inode(&ino);
+ }
+ pos += sizeof(ino);
+
+ if (myino == -1 || ino.ino == myino) {
+ if (ino.nsize) {
+ if (pread(fs, namebuf, min(ino.nsize, 4095), pos) < 0) {
+ perror("pread");
+ exit(1);
+ }
+ if (ino.nsize < 4095)
+ namebuf[ino.nsize] = 0;
+ else
+ namebuf[4095] = 0;
+ printf("Name: \"%s\"\n", namebuf);
+ } else {
+ printf("No Name\n");
}
- if (ino.nsize < 4095)
- namebuf[ino.nsize] = 0;
- else
- namebuf[4095] = 0;
- printf("Name: \"%s\"\n", namebuf);
- } else {
- printf("No Name\n");
}
- }
- pos += (ino.nsize + 3) & ~3;
+ pos += (ino.nsize + 3) & ~3;
- pos += (ino.dsize + 3) & ~3;
+ pos += (ino.dsize + 3) & ~3;
}