Skip to content

Commit 3727637

Browse files
committed
#74 ondemand fnode creation draft
WARNING! Doesn't play nice with commands like 'ls' because fnode loading happens when fno_search() is called and readdir_r() bypass such call. WIP
1 parent b1f34b3 commit 3727637

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

kernel/drivers/xipfs.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Authors:
1818
*
1919
*/
20-
20+
2121
#include "frosted.h"
2222
#include <string.h>
2323
#include "bflt.h"
@@ -26,14 +26,18 @@
2626
#include "vfs.h"
2727
#define GDB_PATH "frosted-userland/gdb/"
2828

29-
static struct fnode *xipfs;
3029
static struct module mod_xipfs;
3130

3231
struct xipfs_fnode {
3332
struct fnode *fnode;
3433
void (*init)(void *);
3534
};
3635

36+
struct xipfs_mount_info {
37+
uint8_t *source_ptr;
38+
char *target_path;
39+
}
40+
3741

3842

3943
#define SECTOR_SIZE (512)
@@ -154,25 +158,43 @@ static int xip_add(const char *name, const void (*init), uint32_t size)
154158
return 0;
155159
}
156160

157-
static int xipfs_parse_blob(const uint8_t *blob)
161+
static int xipfs_parse_blob(const uint8_t *blob, const char *path)
158162
{
159163
const struct xipfs_fat *fat = (const struct xipfs_fat *)blob;
160164
const struct xipfs_fhdr *f;
161165
int i, offset;
162166
if (!fat || fat->fs_magic != XIPFS_MAGIC)
163167
return -1;
164168

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+
}
165175
offset = sizeof(struct xipfs_fat);
166176
for (i = 0; i < fat->fs_files; i++) {
167177
f = (const struct xipfs_fhdr *) (blob + offset);
168178
if (f->magic != XIPFS_MAGIC)
169179
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+
}
171188
offset += f->len + sizeof(struct xipfs_fhdr);
172189
}
173190
return 0;
174191
}
175192

193+
static void xipfs_lookup(const char *path)
194+
{
195+
xipfs_parse_blob((uint8_t *)mod_xipfs.private, path);
196+
}
197+
176198
static int xipfs_mount(char *source, char *tgt, uint32_t flags, void *arg)
177199
{
178200
struct fnode *tgt_dir = NULL;
@@ -192,8 +214,12 @@ static int xipfs_mount(char *source, char *tgt, uint32_t flags, void *arg)
192214
}
193215

194216
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);
197223

198224
return 0;
199225
}
@@ -212,6 +238,7 @@ void xipfs_init(void)
212238
mod_xipfs.ops.unlink = xipfs_unlink;
213239
mod_xipfs.ops.close = xipfs_close;
214240
mod_xipfs.ops.exe = xipfs_exe;
241+
mod_xipfs.ops.lookup = xipfs_lookup;
215242

216243
mod_xipfs.ops.block_read = xipfs_block_read;
217244
register_module(&mod_xipfs);

kernel/frosted.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct module {
291291
int (*unlink)(struct fnode *fno);
292292
int (*truncate)(struct fnode *fno, unsigned int size);
293293
void * (*exe)(struct fnode *fno, void *arg);
294+
void (*lookup)(const char *path);
294295

295296
/* Sockets only (NULL == file) */
296297
int (*socket)(int domain, int type, int protocol);
@@ -318,6 +319,7 @@ struct module {
318319
int (*block_write)(struct fnode *fno, const void *buf, uint32_t sector, int offset, int count);
319320

320321
} ops;
322+
void *private;
321323
struct module *next;
322324
};
323325

kernel/vfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int path_check(const char *path, const char *dirname)
277277

278278
static struct fnode *_fno_search(const char *path, struct fnode *dir, int follow)
279279
{
280-
struct fnode *cur;
280+
struct fnode *fno;
281281
char link[MAX_FILE];
282282
int check = 0;
283283
if (dir == NULL)
@@ -309,7 +309,13 @@ static struct fnode *_fno_search(const char *path, struct fnode *dir, int follow
309309
strcat( link, path_walk(path));
310310
return _fno_search( link, &FNO_ROOT, follow );
311311
}
312-
return _fno_search(path_walk(path), dir->children, follow);
312+
fno = _fno_search(path_walk(path), dir->children, follow);
313+
/* load on demand */
314+
if (!fno && dir->owner && dir->owner->ops.lookup) {
315+
dir->owner->ops.lookup(path);
316+
fno = _fno_search(path_walk(path), dir->children, follow);
317+
}
318+
return fno;
313319
}
314320

315321
struct fnode *fno_search(const char *_path)

0 commit comments

Comments
 (0)