FreeCalypso > hg > freecalypso-sw
comparison target-utils/libmpffs/basicfind.c @ 103:ac310ee73788
target-utils/libmpffs: minor refactoring, read into RAM implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 02 Sep 2013 01:28:11 +0000 |
parents | 7f75ffdd674f |
children |
comparison
equal
deleted
inserted
replaced
102:7f75ffdd674f | 103:ac310ee73788 |
---|---|
3 #include "struct.h" | 3 #include "struct.h" |
4 #include "globals.h" | 4 #include "globals.h" |
5 #include "macros.h" | 5 #include "macros.h" |
6 | 6 |
7 extern char *index(); | 7 extern char *index(); |
8 | |
9 static u8 * | |
10 find_endofchunk(ino) | |
11 { | |
12 struct inode *irec = mpffs_active_index + ino; | |
13 u8 *p; | |
14 int i; | |
15 | |
16 p = inode_to_dataptr(irec) + irec->len; | |
17 for (i = 0; i < 16; i++) { | |
18 p--; | |
19 if (!*p) | |
20 return(p); | |
21 if (*p != 0xFF) | |
22 break; | |
23 } | |
24 printf("Error: inode #%x has no valid termination\n", ino); | |
25 return(p); /* XXX */ | |
26 } | |
27 | 8 |
28 static | 9 static |
29 find_named_child(start, seekname) | 10 find_named_child(start, seekname) |
30 char *seekname; | 11 char *seekname; |
31 { | 12 { |
80 return(-1); | 61 return(-1); |
81 } | 62 } |
82 } | 63 } |
83 return(ino); | 64 return(ino); |
84 } | 65 } |
85 | |
86 mpffs_find_file(pathname, startret, sizeret, continue_ret) | |
87 char *pathname; | |
88 u8 **startret; | |
89 size_t *sizeret; | |
90 int *continue_ret; | |
91 { | |
92 int ino, cont; | |
93 struct inode *irec; | |
94 u8 *start, *end; | |
95 int size; | |
96 | |
97 ino = mpffs_pathname_to_inode(pathname); | |
98 if (ino <= 0) | |
99 return(-1); | |
100 irec = mpffs_active_index + ino; | |
101 if (irec->type != OBJTYPE_FILE) { | |
102 printf("Error: %s is not a regular file\n", pathname); | |
103 return(-1); | |
104 } | |
105 start = inode_to_dataptr(irec); | |
106 start += strlen(start) + 1; | |
107 end = find_endofchunk(ino); | |
108 size = end - start; | |
109 if (size < 0) | |
110 size = 0; | |
111 cont = irec->descend; | |
112 if (cont == 0xFFFF) | |
113 cont = 0; | |
114 if (startret) | |
115 *startret = start; | |
116 if (sizeret) | |
117 *sizeret = size; | |
118 if (continue_ret) | |
119 *continue_ret = cont; | |
120 return(0); | |
121 } | |
122 | |
123 mpffs_get_segment(ino, startret, sizeret, continue_ret) | |
124 int ino; | |
125 u8 **startret; | |
126 size_t *sizeret; | |
127 int *continue_ret; | |
128 { | |
129 int cont; | |
130 struct inode *irec; | |
131 u8 *start, *end; | |
132 int size; | |
133 | |
134 for (;;) { | |
135 irec = mpffs_active_index + ino; | |
136 if (irec->type) | |
137 break; | |
138 if (irec->sibling == 0xFFFF) { | |
139 printf("Error: segment inode #%d: deleted and no sibling\n", | |
140 ino); | |
141 return(-1); | |
142 } | |
143 ino = irec->sibling; | |
144 } | |
145 if (irec->type != OBJTYPE_SEGMENT) { | |
146 printf("Error: inode #%x is not a segment\n", ino); | |
147 return(-1); | |
148 } | |
149 start = inode_to_dataptr(irec); | |
150 end = find_endofchunk(ino); | |
151 size = end - start; | |
152 if (size <= 0) { | |
153 printf("Error: segment inode #%x: bad length\n", ino); | |
154 return(-1); | |
155 } | |
156 cont = irec->descend; | |
157 if (cont == 0xFFFF) | |
158 cont = 0; | |
159 if (startret) | |
160 *startret = start; | |
161 if (sizeret) | |
162 *sizeret = size; | |
163 if (continue_ret) | |
164 *continue_ret = cont; | |
165 return(0); | |
166 } |