# HG changeset patch # User Michael Spacefalcon # Date 1390794371 0 # Node ID 43642cf7c98c5032cdb7e8b238e3488f7aa8203c # Parent 924a80747176d459164a5abbe5356b59c1950ad9 tiffs: added global option for offset of FFS within the file (new -o) diff -r 924a80747176 -r 43642cf7c98c ffstools/tiffs-rd/basics.c --- a/ffstools/tiffs-rd/basics.c Mon Jan 27 03:05:56 2014 +0000 +++ b/ffstools/tiffs-rd/basics.c Mon Jan 27 03:46:11 2014 +0000 @@ -32,13 +32,19 @@ fprintf(stderr, "error: %s is not a regular file\n", imgfile); exit(1); } - if (st.st_size < total_ffs_size) { + if (st.st_size < imgfile_offset) { + fprintf(stderr, + "error: offset given with -o exceeds the size of the file\n"); + exit(1); + } + if (st.st_size - imgfile_offset < total_ffs_size) { fprintf(stderr, "error: %s is shorter than FFS size of 0x%lx bytes\n", imgfile, (u_long)total_ffs_size); exit(1); } - image = mmap(NULL, total_ffs_size, PROT_READ, MAP_PRIVATE, fd, 0); + image = mmap(NULL, total_ffs_size, PROT_READ, MAP_PRIVATE, fd, + imgfile_offset); if (image == MAP_FAILED) { perror("mmap"); exit(1); diff -r 924a80747176 -r 43642cf7c98c ffstools/tiffs-rd/globals.c --- a/ffstools/tiffs-rd/globals.c Mon Jan 27 03:05:56 2014 +0000 +++ b/ffstools/tiffs-rd/globals.c Mon Jan 27 03:46:11 2014 +0000 @@ -7,6 +7,7 @@ #include "struct.h" char *imgfile; +off_t imgfile_offset; u32 eraseblk_size; int total_blocks; u32 total_ffs_size; diff -r 924a80747176 -r 43642cf7c98c ffstools/tiffs-rd/globals.h --- a/ffstools/tiffs-rd/globals.h Mon Jan 27 03:05:56 2014 +0000 +++ b/ffstools/tiffs-rd/globals.h Mon Jan 27 03:46:11 2014 +0000 @@ -3,6 +3,7 @@ */ extern char *imgfile; +extern off_t imgfile_offset; extern u32 eraseblk_size; extern int total_blocks; extern u32 total_ffs_size; diff -r 924a80747176 -r 43642cf7c98c ffstools/tiffs-rd/main.c --- a/ffstools/tiffs-rd/main.c Mon Jan 27 03:05:56 2014 +0000 +++ b/ffstools/tiffs-rd/main.c Mon Jan 27 03:46:11 2014 +0000 @@ -84,11 +84,14 @@ char *cmd; struct cmdtab *tp; - while ((c = getopt(argc, argv, "+a:r:v")) != EOF) + while ((c = getopt(argc, argv, "+a:o:r:v")) != EOF) switch (c) { case 'a': index_blk_num = atoi(optarg); continue; + case 'o': + imgfile_offset = strtoul(optarg, 0, 0); + continue; case 'r': root_inode = strtoul(optarg, 0, 16); continue;