aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 20:19:24 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 20:19:24 +0100
commit862b93742237ed959e9b8dc12a536880ea45d0cf (patch)
tree188360ae20f8524b36fad6941523c4fada5f0d70 /src
parent109b57ea2a8a3dfd88c37a9c00ad301602108efa (diff)
downloadkogata-862b93742237ed959e9b8dc12a536880ea45d0cf.tar.gz
kogata-862b93742237ed959e9b8dc12a536880ea45d0cf.zip
Adjust nullfs header
Diffstat (limited to 'src')
-rw-r--r--src/kernel/core/kmain.c12
-rw-r--r--src/kernel/include/nullfs.h20
-rw-r--r--src/kernel/include/vfs.h5
-rw-r--r--src/kernel/user/vfs.c14
4 files changed, 31 insertions, 20 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index c9a9d13..490d463 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -270,13 +270,21 @@ void kernel_init_stage2(void* data) {
strcpy(name, "/mod/");
strcpy(name+5, modname);
- dbg_printf("Adding module to VFS: '%s'\n", name);
-
size_t len = mods[i].mod_end - mods[i].mod_start;
+
+ dbg_printf("Adding module to VFS: '%s' (size %d)\n", name, len);
+
+ /*
+ // This would be the "good" way of doing it :
fs_handle_t* mod_f = fs_open(devfs, name, FM_WRITE | FM_CREATE);
ASSERT(mod_f != 0);
ASSERT(file_write(mod_f, 0, len, (char*)mods[i].mod_start) == len);
unref_file(mod_f);
+ */
+ // But since we have a nullfs, we can do it that way to prevent useless data copies :
+ ASSERT(nullfs_add_ram_file(devfs, name,
+ (char*)mods[i].mod_start,
+ len, false, FM_READ, FM_MMAP));
}
// TEST : read /cmdline
diff --git a/src/kernel/include/nullfs.h b/src/kernel/include/nullfs.h
index 43bad5e..ba6a9c8 100644
--- a/src/kernel/include/nullfs.h
+++ b/src/kernel/include/nullfs.h
@@ -2,26 +2,18 @@
#include <vfs.h>
-#define NULLFS_OPT_CREATE_EN 1
-#define NULLFS_OPT_DELETE_EN 2
+// The nullfs accepts several flags at its creation :
+// - c : allow creation of files as ram files
+// - d : allow deletion of arbitrary nodes
+// - m : allow move operation
typedef struct nullfs nullfs_t;
-typedef struct {
- void* (*open)(void* f, int mode, fs_handle_t *h);
- size_t (*read)(void* fd, size_t offset, size_t len, char* buf);
- size_t (*write)(void* fd, size_t offset, size_t len, const char* buf);
- bool (*stat)(void* f, stat_t *st);
- int (*ioctl)(void* f, int command, void* data);
- void (*close)(void* fd);
- void (*dispose)(void* f);
-} nullfs_node_ops_t;
-
void register_nullfs_driver();
nullfs_t* as_nullfs(fs_t *fs);
-bool nullfs_add(nullfs_t *f, const char* name, void* data, nullfs_node_ops_t* ops);
-bool nullfs_add_ram_file(nullfs_t *f, const char* name, void* data, size_t init_sz, bool copy, int ok_modes);
+bool nullfs_add_node(nullfs_t *f, const char* name, fs_node_ptr data, fs_node_ops_t *ops);
+bool nullfs_add_ram_file(nullfs_t *f, const char* name, char* data, size_t init_sz, bool copy, int ok_modes);
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h
index ccb33f4..b0fd146 100644
--- a/src/kernel/include/vfs.h
+++ b/src/kernel/include/vfs.h
@@ -31,6 +31,7 @@ typedef struct {
size_t (*read)(fs_handle_ptr f, size_t offset, size_t len, char* buf);
size_t (*write)(fs_handle_ptr f, size_t offset, size_t len, const char* buf);
bool (*stat)(fs_handle_ptr f, stat_t *st);
+ bool (*readdir)(fs_handle_ptr f, dirent_t *d);
void (*close)(fs_handle_ptr f);
} fs_handle_ops_t;
@@ -138,8 +139,10 @@ int fs_ioctl(fs_t *fs, const char* file, int command, void* data);
fs_handle_t* fs_open(fs_t *fs, const char* file, int mode);
void ref_file(fs_handle_t *file);
void unref_file(fs_handle_t *file);
+int file_get_mode(fs_handle_t *f);
size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf);
size_t file_write(fs_handle_t *f, size_t offset, size_t len, const char* buf);
-int file_get_mode(fs_handle_t *f);
+bool file_stat(fs_handle_t *f, stat_t *st);
+bool file_readdir(fs_handle_t *f, dirent_t *d);
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c
index 687e7f1..38b88d7 100644
--- a/src/kernel/user/vfs.c
+++ b/src/kernel/user/vfs.c
@@ -86,7 +86,7 @@ void unref_fs_node(fs_node_t *n) {
ASSERT(n != &n->fs->root);
ASSERT(n->parent != 0);
- n->ops->dispose(n->data);
+ if (n->ops->dispose) n->ops->dispose(n->data);
unref_fs_node(n->parent);
unref_fs(n->fs);
free(n);
@@ -293,6 +293,10 @@ void unref_file(fs_handle_t *file) {
}
}
+int file_get_mode(fs_handle_t *f) {
+ return f->mode;
+}
+
size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf) {
if (!(f->mode && FM_READ)) return 0;
@@ -307,8 +311,12 @@ size_t file_write(fs_handle_t *f, size_t offset, size_t len, const char* buf) {
return f->ops->write(f->data, offset, len, buf);
}
-int file_get_mode(fs_handle_t *f) {
- return f->mode;
+bool file_stat(fs_handle_t *f, stat_t *st) {
+ return f->ops->stat && f->ops->stat(f->data, st);
+}
+
+bool file_readdir(fs_handle_t *f, dirent_t *d) {
+ return f->ops->readdir && f->ops->readdir(f->data, d);
}
/* vim: set ts=4 sw=4 tw=0 noet :*/