annotate ffstools/tiffs-rd/main.c @ 875:dab341e172de

fc-shell: sysprim sending (sp command) implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 30 May 2015 07:41:23 +0000
parents 10afa4d39a7b
children 09b8b2327838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This C module contains the main() function for the tiffs utility,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * dispatching control to different operation commands.
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <ctype.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <string.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <strings.h>
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "types.h"
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 230
diff changeset
13 #include "globals.h"
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 parse_org_arg(arg)
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *arg;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 char *cp;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 cp = index(arg, 'x');
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 fprintf(stderr,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 "error: TIFFS organization argument \"%s\" is invalid\n", arg);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 exit(1);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 *cp++ = '\0';
229
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
27 if (!strcmp(arg, "8"))
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
28 eraseblk_size = 0x2000;
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
29 else if (!strcmp(arg, "16"))
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 eraseblk_size = 0x4000;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 else if (!strcmp(arg, "32"))
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 eraseblk_size = 0x8000;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 else if (!strcmp(arg, "64"))
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 eraseblk_size = 0x10000;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 else if (!strcmp(arg, "128"))
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 eraseblk_size = 0x20000;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 else if (!strcmp(arg, "256"))
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 eraseblk_size = 0x40000;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 else {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 fprintf(stderr,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 "error: \"%s\" is not a recognized flash sector size\n",
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 arg);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 exit(1);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 total_blocks = atoi(cp);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 if (total_blocks < 1 || total_blocks > 128) {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 fprintf(stderr,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 "error: \"%s\" is not a reasonable number of FFS sectors\n",
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 cp);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 exit(1);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 total_ffs_size = eraseblk_size * total_blocks;
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 230
diff changeset
53 inode_limit = eraseblk_size >> 4;
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55
229
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
56 extern int cmd_blkhdr();
240
acedd4c88d2e tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 238
diff changeset
57 extern int cmd_cat();
241
c95efd27fb2e tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 240
diff changeset
58 extern int cmd_catino();
230
ffaa033e7643 tiffs IVA: find_inode_block() integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 229
diff changeset
59 extern int cmd_fsinfo();
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
60 extern int cmd_ls();
238
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
61 extern int cmd_lsino();
248
10afa4d39a7b tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 243
diff changeset
62 extern int cmd_xtr();
229
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
63
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 static struct cmdtab {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 char *cmd;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 int (*func)();
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 } cmdtab[] = {
229
24ed817dd25d tiffs IVA: reads image via mmap and displays block headers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 225
diff changeset
68 {"blkhdr", cmd_blkhdr},
240
acedd4c88d2e tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 238
diff changeset
69 {"cat", cmd_cat},
241
c95efd27fb2e tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 240
diff changeset
70 {"catino", cmd_catino},
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 {"fsck", NULL},
230
ffaa033e7643 tiffs IVA: find_inode_block() integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 229
diff changeset
72 {"fsinfo", cmd_fsinfo},
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
73 {"ls", cmd_ls},
238
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
74 {"lsino", cmd_lsino},
248
10afa4d39a7b tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 243
diff changeset
75 {"xtr", cmd_xtr},
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 {NULL, NULL}
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 };
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 main(argc, argv)
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 char **argv;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 extern int optind;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 extern char *optarg;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 int c;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 char *cmd;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 struct cmdtab *tp;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87
243
43642cf7c98c tiffs: added global option for offset of FFS within the file (new -o)
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 241
diff changeset
88 while ((c = getopt(argc, argv, "+a:o:r:v")) != EOF)
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 switch (c) {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 case 'a':
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 index_blk_num = atoi(optarg);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 continue;
243
43642cf7c98c tiffs: added global option for offset of FFS within the file (new -o)
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 241
diff changeset
93 case 'o':
43642cf7c98c tiffs: added global option for offset of FFS within the file (new -o)
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 241
diff changeset
94 imgfile_offset = strtoul(optarg, 0, 0);
43642cf7c98c tiffs: added global option for offset of FFS within the file (new -o)
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 241
diff changeset
95 continue;
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 case 'r':
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 230
diff changeset
97 root_inode = strtoul(optarg, 0, 16);
225
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 continue;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 case 'v':
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 verbose++;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 continue;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 default:
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 usage: fprintf(stderr,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 "usage: %s [global-options] <imgfile> <org> <op> ...\n",
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 argv[0]);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 exit(1);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 if (argc - optind < 3)
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 goto usage;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 imgfile = argv[optind];
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 parse_org_arg(argv[optind+1]);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 cmd = argv[optind+2];
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 for (tp = cmdtab; tp->cmd; tp++)
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 if (!strcmp(tp->cmd, cmd))
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 break;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 if (!tp->func) {
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 fprintf(stderr,
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 "%s: operation \"%s\" is unknown or unimplemented\n",
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 argv[0], cmd);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 exit(1);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 }
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 optind += 2;
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 return tp->func(argc - optind, argv + optind);
c04aa85559ed TIFFS in vitro reader started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 }