FreeCalypso > hg > freecalypso-reveng
annotate mpffs/find.c @ 140:21fda9752bd9
OSL flash objects: created disasm hints for os_com through os_mis
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 09 Apr 2014 02:40:20 +0000 |
parents | 95f61c3b430a |
children |
rev | line source |
---|---|
34
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the code for searching the FFS tree structure |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * for a specified absolute pathname. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <ctype.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdio.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <stdlib.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <unistd.h> |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "types.h" |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "struct.h" |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 extern int root_node_no; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 /* |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 * The following function iterates through the descendants of a directory |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 * object looking for a specific directory-member filename. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 * |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 * Arguments: |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 * - index # of the first descendant (descendant pointer from the dir object) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 * - filename to search for |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 * |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 * Returns: index # of the sought descendant object if found, 0 otherwise. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 */ |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 find_dir_member(first_descend, srchname) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 char *srchname; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 int ent; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 struct objinfo obj; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 for (ent = first_descend; ent != 0xFFFF; ent = obj.sibling) { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 obj.entryno = ent; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 get_index_entry(&obj); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 if (!obj.type) /* skip deleted objects w/o further looking */ |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 continue; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 validate_chunk(&obj); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 validate_obj_name(&obj); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (!strcmp(obj.dataptr, srchname)) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 return(ent); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 return(0); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 /* |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 * The following function searches for a pathname from the root down. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 * Returns the index # if found, otherwise exits with an error message |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 * indicating which step failed. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 * |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 * Warning: the pathname in the argument buffer will be destroyed: |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 * 0s put in place of the slashes. |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 */ |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 find_pathname(pathname) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 char *pathname; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 char *cur, *next; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 int idx; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 struct objinfo dir; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 cur = pathname; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 if (*cur == '/') |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 cur++; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 for (idx = root_node_no; cur; cur = next) { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 if (!*cur) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 break; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 next = index(cur, '/'); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 if (next == cur) { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 fprintf(stderr, |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 "malformed pathname: multiple adjacent slashes\n"); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 exit(1); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 if (next) |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 *next++ = '\0'; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 dir.entryno = idx; |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 get_index_entry(&dir); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 if (dir.type != 0xF2) { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 fprintf(stderr, |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 "pathname search error: encountered a non-directory\n"); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 exit(1); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 idx = find_dir_member(dir.descend, cur); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 if (!idx) { |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 fprintf(stderr, |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 "pathname search error: component name not found\n"); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 exit(1); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 } |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 return(idx); |
95f61c3b430a
mpffs-rdutils: pathname search implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 } |