Skip to content

Commit

Permalink
#74 ondemand fnode creation draft
Browse files Browse the repository at this point in the history
WARNING! Doesn't play nice with commands like 'ls'
because fnode loading happens when fno_search() is called and
readdir_r() bypass such call.
  • Loading branch information
acardace committed Aug 26, 2017
1 parent b1f34b3 commit d6b3899
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
24 changes: 18 additions & 6 deletions kernel/drivers/xipfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Authors:
*
*/

#include "frosted.h"
#include <string.h>
#include "bflt.h"
Expand All @@ -26,7 +26,6 @@
#include "vfs.h"
#define GDB_PATH "frosted-userland/gdb/"

static struct fnode *xipfs;
static struct module mod_xipfs;

struct xipfs_fnode {
Expand Down Expand Up @@ -154,7 +153,7 @@ static int xip_add(const char *name, const void (*init), uint32_t size)
return 0;
}

static int xipfs_parse_blob(const uint8_t *blob)
static int xipfs_parse_blob(const uint8_t *blob, const char *path)
{
const struct xipfs_fat *fat = (const struct xipfs_fat *)blob;
const struct xipfs_fhdr *f;
Expand All @@ -167,12 +166,24 @@ static int xipfs_parse_blob(const uint8_t *blob)
f = (const struct xipfs_fhdr *) (blob + offset);
if (f->magic != XIPFS_MAGIC)
return -1;
xip_add(f->name, f->payload, f->len);
if (path) {
if (strncmp(f->name, path, strlen(path)+1) == 0) {
xip_add(f->name, f->payload, f->len);
return 0;
}
} else {
xip_add(f->name, f->payload, f->len);
}
offset += f->len + sizeof(struct xipfs_fhdr);
}
return 0;
}

static void xipfs_lookup(const char *path)
{
xipfs_parse_blob((uint8_t *)mod_xipfs.private, path);
}

static int xipfs_mount(char *source, char *tgt, uint32_t flags, void *arg)
{
struct fnode *tgt_dir = NULL;
Expand All @@ -192,8 +203,8 @@ static int xipfs_mount(char *source, char *tgt, uint32_t flags, void *arg)
}

tgt_dir->owner = &mod_xipfs;
if (xipfs_parse_blob((uint8_t *)source) < 0)
return -1;
/* cache the value for later */
mod_xipfs.private = (void *) source;

return 0;
}
Expand All @@ -212,6 +223,7 @@ void xipfs_init(void)
mod_xipfs.ops.unlink = xipfs_unlink;
mod_xipfs.ops.close = xipfs_close;
mod_xipfs.ops.exe = xipfs_exe;
mod_xipfs.ops.lookup = xipfs_lookup;

mod_xipfs.ops.block_read = xipfs_block_read;
register_module(&mod_xipfs);
Expand Down
2 changes: 2 additions & 0 deletions kernel/frosted.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ struct module {
int (*unlink)(struct fnode *fno);
int (*truncate)(struct fnode *fno, unsigned int size);
void * (*exe)(struct fnode *fno, void *arg);
void (*lookup)(const char *path);

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

} ops;
void *private;
struct module *next;
};

Expand Down
10 changes: 8 additions & 2 deletions kernel/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static int path_check(const char *path, const char *dirname)

static struct fnode *_fno_search(const char *path, struct fnode *dir, int follow)
{
struct fnode *cur;
struct fnode *fno;
char link[MAX_FILE];
int check = 0;
if (dir == NULL)
Expand Down Expand Up @@ -309,7 +309,13 @@ static struct fnode *_fno_search(const char *path, struct fnode *dir, int follow
strcat( link, path_walk(path));
return _fno_search( link, &FNO_ROOT, follow );
}
return _fno_search(path_walk(path), dir->children, follow);
fno = _fno_search(path_walk(path), dir->children, follow);
/* load on demand */
if (!fno && dir->owner && dir->owner->ops.lookup) {
dir->owner->ops.lookup(path_walk(path));

This comment has been minimized.

Copy link
@brabo

brabo Aug 27, 2017

Member

Shouldn't we pass the full path here?

fno = _fno_search(path_walk(path), dir->children, follow);
}
return fno;
}

struct fnode *fno_search(const char *_path)
Expand Down

0 comments on commit d6b3899

Please sign in to comment.