17
17
* Authors:
18
18
*
19
19
*/
20
-
20
+
21
21
#include "frosted.h"
22
22
#include <string.h>
23
23
#include "bflt.h"
26
26
#include "vfs.h"
27
27
#define GDB_PATH "frosted-userland/gdb/"
28
28
29
- static struct fnode * xipfs ;
30
29
static struct module mod_xipfs ;
31
30
32
31
struct xipfs_fnode {
33
32
struct fnode * fnode ;
34
33
void (* init )(void * );
35
34
};
36
35
36
+ struct xipfs_mount_info {
37
+ uint8_t * source_ptr ;
38
+ char * target_path ;
39
+ }
40
+
37
41
38
42
39
43
#define SECTOR_SIZE (512)
@@ -154,25 +158,43 @@ static int xip_add(const char *name, const void (*init), uint32_t size)
154
158
return 0 ;
155
159
}
156
160
157
- static int xipfs_parse_blob (const uint8_t * blob )
161
+ static int xipfs_parse_blob (const uint8_t * blob , const char * path )
158
162
{
159
163
const struct xipfs_fat * fat = (const struct xipfs_fat * )blob ;
160
164
const struct xipfs_fhdr * f ;
161
165
int i , offset ;
162
166
if (!fat || fat -> fs_magic != XIPFS_MAGIC )
163
167
return -1 ;
164
168
169
+ char * full_path = NULL ;
170
+ if (path ) {
171
+ size_t len_root = strlen ();
172
+ size_t len_path = strlen (path );
173
+ full_path = kalloc (sizeof (char )*
174
+ }
165
175
offset = sizeof (struct xipfs_fat );
166
176
for (i = 0 ; i < fat -> fs_files ; i ++ ) {
167
177
f = (const struct xipfs_fhdr * ) (blob + offset );
168
178
if (f -> magic != XIPFS_MAGIC )
169
179
return -1 ;
170
- xip_add (f -> name , f -> payload , f -> len );
180
+ if (path ) {
181
+ if (strncmp (f -> name , path , strlen (path )+ 1 ) == 0 ) {
182
+ xip_add (f -> name , f -> payload , f -> len );
183
+ return 0 ;
184
+ }
185
+ } else {
186
+ xip_add (f -> name , f -> payload , f -> len );
187
+ }
171
188
offset += f -> len + sizeof (struct xipfs_fhdr );
172
189
}
173
190
return 0 ;
174
191
}
175
192
193
+ static void xipfs_lookup (const char * path )
194
+ {
195
+ xipfs_parse_blob ((uint8_t * )mod_xipfs .private , path );
196
+ }
197
+
176
198
static int xipfs_mount (char * source , char * tgt , uint32_t flags , void * arg )
177
199
{
178
200
struct fnode * tgt_dir = NULL ;
@@ -192,8 +214,12 @@ static int xipfs_mount(char *source, char *tgt, uint32_t flags, void *arg)
192
214
}
193
215
194
216
tgt_dir -> owner = & mod_xipfs ;
195
- if (xipfs_parse_blob ((uint8_t * )source ) < 0 )
196
- return -1 ;
217
+ /* cache the value for later */
218
+ size_t tgt_len = strlen (tgt -> fname );
219
+ mod_xipfs .private = (struct xipfs_mount_info * )kalloc (sizeof (xipfs_mount_info ));
220
+ mod_xipfs .private -> target_path = (char * ) kalloc (sizeof (char )* tgt_len + 1 );
221
+ mod_xipfs .private -> source_ptr = source ;
222
+ strncpy (mod_xipfs .private -> target_path , tgt -> fname , tgt_len + 1 );
197
223
198
224
return 0 ;
199
225
}
@@ -212,6 +238,7 @@ void xipfs_init(void)
212
238
mod_xipfs .ops .unlink = xipfs_unlink ;
213
239
mod_xipfs .ops .close = xipfs_close ;
214
240
mod_xipfs .ops .exe = xipfs_exe ;
241
+ mod_xipfs .ops .lookup = xipfs_lookup ;
215
242
216
243
mod_xipfs .ops .block_read = xipfs_block_read ;
217
244
register_module (& mod_xipfs );
0 commit comments