FreeCalypso > hg > freecalypso-reveng
annotate mpffs/common.c @ 79:8f4996bff904
tiobjd: profile operation implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 26 Mar 2014 02:00:44 +0000 |
parents | 9bc7f0e03fa8 |
children |
rev | line source |
---|---|
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the code that will be common between mpffs-cat, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * mpffs-ls and mpffs-xtr. |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/file.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <sys/stat.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <endian.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <ctype.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <stdio.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <string.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include <strings.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include <stdlib.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include <unistd.h> |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "types.h" |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "struct.h" |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 u8 mpffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02}; |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
20 u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
21 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char *imgfile; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 u32 eraseblk_size; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int total_blocks; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 u32 total_ffs_size; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 u8 *image, *indexblk; |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
28 int index_blk_num = -1, root_node_no; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
29 struct objinfo root; |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 int verbose; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 /* |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 * The following function is used to verify that the specified or computed |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 * flash erase block size is a power of 2. |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 */ |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 count_ones(word) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 u32 word; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 int count; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 for (count = 0; word; word >>= 1) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 count += word & 1; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return count; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 eraseblk_size_reasonable() |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 { |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
48 if (count_ones(eraseblk_size) != 1 || eraseblk_size < 16384 || |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
49 eraseblk_size > 0x100000) { |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 fprintf(stderr, "0x%lx is an unreasonable erase block size\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 (u_long) eraseblk_size); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
56 parse_cmdline_options(argc, argv) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
57 char **argv; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
58 { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
59 extern char *optarg; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
60 int c; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
61 |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
62 while ((c = getopt(argc, argv, "a:e:mn:pr:v")) != EOF) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
63 switch (c) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
64 case 'a': |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
65 index_blk_num = atoi(optarg); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
66 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
67 case 'e': |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
68 eraseblk_size = strtoul(optarg, 0, 0); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
69 eraseblk_size_reasonable(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
70 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
71 case 'm': /* "moko" */ |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
72 eraseblk_size = 0x10000; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
73 total_blocks = 7; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
74 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
75 case 'n': |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
76 total_blocks = atoi(optarg); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
77 if (total_blocks < 1) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
78 fprintf(stderr, "invalid -n value\n"); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
79 exit(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
80 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
81 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
82 case 'p': /* Pirelli */ |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
83 eraseblk_size = 0x40000; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
84 total_blocks = 18; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
85 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
86 case 'r': |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
87 root_node_no = atoi(optarg); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
88 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
89 case 'v': |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
90 verbose++; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
91 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
92 default: |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
93 usage(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
94 exit(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
95 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
96 |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
97 return(0); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
98 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
99 |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 read_img_file() |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 int fd; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 struct stat st; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 fd = open(imgfile, O_RDONLY); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 if (fd < 0) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 perror(imgfile); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 fstat(fd, &st); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 if (!S_ISREG(st.st_mode)) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 fprintf(stderr, "%s is not a regular file\n", imgfile); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 if (!eraseblk_size && !total_blocks) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 switch (st.st_size) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 case 0x70000: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 /* assume Closedmoko */ |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 eraseblk_size = 0x10000; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 total_blocks = 7; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 break; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 case 0x480000: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 /* assume Pirelli */ |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 eraseblk_size = 0x40000; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 total_blocks = 18; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 break; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 default: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 noauto: fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 "cannot intuit the flash parameters of %s: use -e and -n options\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 imgfile); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 } else if (!total_blocks) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 total_blocks = st.st_size / eraseblk_size; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 if (!total_blocks || total_blocks * eraseblk_size != st.st_size) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 goto noauto; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 } else if (!eraseblk_size) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 if (total_blocks * 0x10000 == st.st_size) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 eraseblk_size = 0x10000; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 else if (total_blocks * 0x40000 == st.st_size) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 eraseblk_size = 0x40000; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 else |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 goto noauto; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 total_ffs_size = eraseblk_size * total_blocks; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 if (st.st_size < total_ffs_size) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 fprintf(stderr, "%s has fewer than 0x%x bytes\n", imgfile, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 total_ffs_size); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 image = malloc(total_ffs_size); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 if (!image) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 perror("malloc"); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 read(fd, image, total_ffs_size); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 close(fd); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 find_index_block() |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 int i, abcnt; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 u8 *ptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
165 if (index_blk_num >= 0) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
166 if (index_blk_num >= total_blocks) { |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 "invalid block # given with the -a option\n"); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 ptr = image + index_blk_num * eraseblk_size; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 if (bcmp(ptr, mpffs_header, 6) || ptr[8] != 0xAB) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 "no MPFFS index found at the specified block #%d\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 index_blk_num); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 indexblk = ptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 return(0); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 abcnt = 0; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 if (bcmp(ptr, mpffs_header, 6)) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 "warning: no MPFFS signature in erase block #%d (offset %x)\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 i, ptr - image); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 continue; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 switch (ptr[8]) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 case 0xAB: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 if (verbose) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 printf( |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 "Found AB index in erase block #%d (offset %x)\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 i, ptr - image); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 index_blk_num = i; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 indexblk = ptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 abcnt++; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 continue; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 case 0xBD: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 case 0xBF: |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 continue; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 "warning: non-understood block type %02X at offset %x\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 ptr[8], ptr - image); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 if (!indexblk) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 fprintf(stderr, "could not find an MPFFS index block in %s\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 imgfile); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 if (abcnt > 1) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 fprintf(stderr, "found more than one AB block; use -a\n"); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 return(0); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 get_index_entry(oi) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 struct objinfo *oi; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 struct mpffs_index *le; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 if (oi->entryno >= (eraseblk_size >> 4)) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 "error: index block pointer %x past the erase block size!\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 oi->entryno); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 le = (struct mpffs_index *) indexblk + oi->entryno; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 oi->idxrec = le; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 oi->len = le16toh(le->len); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 oi->type = le->type; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 oi->descend = le16toh(le->descend); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 oi->sibling = le16toh(le->sibling); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 return(0); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
238 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
239 validate_chunk(oi) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
240 struct objinfo *oi; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
241 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
242 u32 dptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
243 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
244 if (oi->len & 0xF || !oi->len) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
245 fprintf(stderr, "index entry #%x: invalid chunk length\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
246 oi->entryno); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
247 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
248 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 dptr = le32toh(oi->idxrec->dataptr); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 if (dptr > 0x0FFFFFFF) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 invdptr: fprintf(stderr, "index entry #%x: invalid data pointer\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 oi->entryno); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
253 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
254 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
255 dptr <<= 4; |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
256 if (dptr > total_ffs_size - oi->len) |
29
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
257 goto invdptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
258 oi->offset = dptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
259 oi->dataptr = image + dptr; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
260 return(0); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
261 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
262 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
263 validate_obj_name(oi) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
264 struct objinfo *oi; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
265 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
266 u8 *cp; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
267 int cnt; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
268 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
269 for (cp = oi->dataptr, cnt = 0; ; cp++, cnt++) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
270 if (cnt >= oi->len) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
271 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
272 "object at index %x: name expected at %x: length overrun\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
273 oi->entryno, oi->offset); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
274 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
275 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
276 if (!*cp) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
277 break; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
278 if (*cp < '!' || *cp > '~') { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
279 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
280 "object at index %x: name expected at %x: bad character\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
281 oi->entryno, oi->offset); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
282 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
283 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
284 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
285 if (!cnt) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
286 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
287 "object at index %x: name expected at %x: null string\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
288 oi->entryno, oi->offset); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
289 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
290 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
291 return(0); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
292 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
293 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
294 u8 * |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
295 find_end_of_chunk(ch) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
296 struct objinfo *ch; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
297 { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
298 u8 *p; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
299 int i; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
300 |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
301 p = ch->dataptr + ch->len; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
302 for (i = 1; i <= 16; i++) { |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
303 if (!p[-i]) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
304 return(p - i); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
305 if (p[-1] != 0xFF) |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
306 break; |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
307 } |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
308 fprintf(stderr, |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
309 "chunk starting at %x (index entry %x): no valid termination found\n", |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
310 ch->offset, ch->entryno); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
311 exit(1); |
e96d6862cec0
mpffs-rdutils code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
312 } |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
313 |
31
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
314 size_head_chunk(ch, chi) |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
315 struct objinfo *ch; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
316 struct chunkinfo *chi; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
317 { |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
318 chi->start = (u8 *) index((char *)ch->dataptr, '\0') + 1; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
319 chi->end = find_end_of_chunk(ch); |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
320 if (chi->start >= chi->end) { |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
321 chi->len = 0; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
322 return(0); |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
323 } else { |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
324 chi->len = chi->end - chi->start; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
325 return(1); |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
326 } |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
327 } |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
328 |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
329 size_extra_chunk(ch, chi) |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
330 struct objinfo *ch; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
331 struct chunkinfo *chi; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
332 { |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
333 chi->start = ch->dataptr; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
334 chi->end = find_end_of_chunk(ch); |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
335 chi->len = chi->end - chi->start; |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
336 } |
3cca8070ef0f
mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
30
diff
changeset
|
337 |
39
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
338 iterate_extra_chunks(first_extra_chunk, callback, callback_data) |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
339 void (*callback)(); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
340 u_long callback_data; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
341 { |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
342 int ent; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
343 struct objinfo obj; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
344 |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
345 for (ent = first_extra_chunk; ent != 0xFFFF; ent = obj.descend) { |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
346 loop: obj.entryno = ent; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
347 get_index_entry(&obj); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
348 switch (obj.type) { |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
349 case 0xF4: |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
350 validate_chunk(&obj); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
351 callback(&obj, callback_data); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
352 continue; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
353 case 0x00: |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
354 if (obj.sibling == 0xFFFF) { |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
355 fprintf(stderr, |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
356 "file continuation object at index %x: marked deleted, but no sibling\n", |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
357 ent); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
358 exit(1); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
359 } |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
360 ent = obj.sibling; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
361 goto loop; |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
362 default: |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
363 fprintf(stderr, |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
364 "file continuation object at index %x: unexpected type %02X\n", |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
365 ent, obj.type); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
366 exit(1); |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
367 } |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
368 } |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
369 } |
9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
31
diff
changeset
|
370 |
30
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
371 find_root_node() |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
372 { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
373 struct objinfo obj; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
374 u16 lim; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
375 |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
376 lim = (eraseblk_size >> 4) - 1; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
377 if (root_node_no) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
378 if (root_node_no < 1 || root_node_no > lim) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
379 fprintf(stderr, |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
380 "root node # given with -r is invalid\n"); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
381 exit(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
382 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
383 return(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
384 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
385 for (obj.entryno = 1; obj.entryno <= lim; obj.entryno++) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
386 get_index_entry(&obj); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
387 if (!bcmp(obj.idxrec, blank_flash_line, 16)) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
388 break; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
389 if (obj.type != 0xF2) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
390 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
391 validate_chunk(&obj); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
392 validate_obj_name(&obj); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
393 if (*obj.dataptr != '/') |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
394 continue; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
395 root_node_no = obj.entryno; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
396 if (verbose) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
397 printf("Found root node at index #%x\n", root_node_no); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
398 return(0); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
399 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
400 fprintf(stderr, "error: no root node found (try -r)\n"); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
401 exit(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
402 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
403 |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
404 validate_root_node() |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
405 { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
406 root.entryno = root_node_no; |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
407 get_index_entry(&root); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
408 validate_chunk(&root); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
409 validate_obj_name(&root); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
410 if (verbose) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
411 printf("Root node name: %s\n", (char *)root.dataptr); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
412 if (root.type != 0xF2) { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
413 fprintf(stderr, |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
414 "error: index entry #%x (expected root dir) is not a directory\n", |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
415 root_node_no); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
416 exit(1); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
417 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
418 if (root.sibling != 0xFFFF) |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
419 fprintf(stderr, |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
420 "warning: root entry has a non-nil sibling pointer\n"); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
421 return(0); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
422 } |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
423 |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
424 preliminaries() |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
425 { |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
426 read_img_file(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
427 find_index_block(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
428 find_root_node(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
429 validate_root_node(); |
9c3c5a572b57
mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
430 } |