changeset 243:43642cf7c98c

tiffs: added global option for offset of FFS within the file (new -o)
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 27 Jan 2014 03:46:11 +0000
parents 924a80747176
children 48a254ca4493
files ffstools/tiffs-rd/basics.c ffstools/tiffs-rd/globals.c ffstools/tiffs-rd/globals.h ffstools/tiffs-rd/main.c
diffstat 4 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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;
--- 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;
--- 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;