FreeCalypso > hg > freecalypso-tools
comparison ffstools/tiffs-rd/main.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | d68275d47a32 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This C module contains the main() function for the tiffs utility, | |
3 * dispatching control to different operation commands. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <ctype.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include "types.h" | |
13 #include "globals.h" | |
14 | |
15 parse_org_arg(arg) | |
16 char *arg; | |
17 { | |
18 char *cp; | |
19 | |
20 cp = index(arg, 'x'); | |
21 if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) { | |
22 fprintf(stderr, | |
23 "error: TIFFS organization argument \"%s\" is invalid\n", arg); | |
24 exit(1); | |
25 } | |
26 *cp++ = '\0'; | |
27 if (!strcmp(arg, "8")) | |
28 eraseblk_size = 0x2000; | |
29 else if (!strcmp(arg, "16")) | |
30 eraseblk_size = 0x4000; | |
31 else if (!strcmp(arg, "32")) | |
32 eraseblk_size = 0x8000; | |
33 else if (!strcmp(arg, "64")) | |
34 eraseblk_size = 0x10000; | |
35 else if (!strcmp(arg, "128")) | |
36 eraseblk_size = 0x20000; | |
37 else if (!strcmp(arg, "256")) | |
38 eraseblk_size = 0x40000; | |
39 else { | |
40 fprintf(stderr, | |
41 "error: \"%s\" is not a recognized flash sector size\n", | |
42 arg); | |
43 exit(1); | |
44 } | |
45 total_blocks = atoi(cp); | |
46 if (total_blocks < 1 || total_blocks > 128) { | |
47 fprintf(stderr, | |
48 "error: \"%s\" is not a reasonable number of FFS sectors\n", | |
49 cp); | |
50 exit(1); | |
51 } | |
52 total_ffs_size = eraseblk_size * total_blocks; | |
53 inode_limit = eraseblk_size >> 4; | |
54 } | |
55 | |
56 extern int cmd_blkhdr(); | |
57 extern int cmd_cat(); | |
58 extern int cmd_catino(); | |
59 extern int cmd_fsinfo(); | |
60 extern int cmd_ls(); | |
61 extern int cmd_lsino(); | |
62 extern int cmd_xtr(); | |
63 | |
64 static struct cmdtab { | |
65 char *cmd; | |
66 int (*func)(); | |
67 } cmdtab[] = { | |
68 {"blkhdr", cmd_blkhdr}, | |
69 {"cat", cmd_cat}, | |
70 {"catino", cmd_catino}, | |
71 {"fsck", NULL}, | |
72 {"fsinfo", cmd_fsinfo}, | |
73 {"ls", cmd_ls}, | |
74 {"lsino", cmd_lsino}, | |
75 {"xtr", cmd_xtr}, | |
76 {NULL, NULL} | |
77 }; | |
78 | |
79 main(argc, argv) | |
80 char **argv; | |
81 { | |
82 extern int optind; | |
83 extern char *optarg; | |
84 int c; | |
85 char *cmd; | |
86 struct cmdtab *tp; | |
87 | |
88 while ((c = getopt(argc, argv, "+a:o:Or:v")) != EOF) | |
89 switch (c) { | |
90 case 'a': | |
91 index_blk_num = atoi(optarg); | |
92 continue; | |
93 case 'o': | |
94 imgfile_offset = strtoul(optarg, 0, 0); | |
95 continue; | |
96 case 'O': | |
97 old_16bit_location = 1; | |
98 continue; | |
99 case 'r': | |
100 root_inode = strtoul(optarg, 0, 16); | |
101 continue; | |
102 case 'v': | |
103 verbose++; | |
104 continue; | |
105 default: | |
106 usage: fprintf(stderr, | |
107 "usage: %s [global-options] <imgfile> <org> <op> ...\n", | |
108 argv[0]); | |
109 exit(1); | |
110 } | |
111 if (argc - optind < 3) | |
112 goto usage; | |
113 imgfile = argv[optind]; | |
114 parse_org_arg(argv[optind+1]); | |
115 cmd = argv[optind+2]; | |
116 | |
117 for (tp = cmdtab; tp->cmd; tp++) | |
118 if (!strcmp(tp->cmd, cmd)) | |
119 break; | |
120 if (!tp->func) { | |
121 fprintf(stderr, | |
122 "%s: operation \"%s\" is unknown or unimplemented\n", | |
123 argv[0], cmd); | |
124 exit(1); | |
125 } | |
126 optind += 2; | |
127 return tp->func(argc - optind, argv + optind); | |
128 } |