diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 19:24:42 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 19:24:42 +0100 |
commit | 440d9dc470703d20a55365b3a560196e71d450d4 (patch) | |
tree | bcc864c7aeb0af7a81c4fcd7430fa8c3001f8383 /src/kernel/include | |
parent | caf842864bdc0794e387f9580af96ab1036996f4 (diff) | |
download | kogata-440d9dc470703d20a55365b3a560196e71d450d4.tar.gz kogata-440d9dc470703d20a55365b3a560196e71d450d4.zip |
Start work on filesystems.
Diffstat (limited to 'src/kernel/include')
-rw-r--r-- | src/kernel/include/devfs.h | 8 | ||||
-rw-r--r-- | src/kernel/include/nullfs.h | 25 | ||||
-rw-r--r-- | src/kernel/include/process.h | 32 | ||||
-rw-r--r-- | src/kernel/include/vfs.h | 86 |
4 files changed, 124 insertions, 27 deletions
diff --git a/src/kernel/include/devfs.h b/src/kernel/include/devfs.h new file mode 100644 index 0000000..0dee246 --- /dev/null +++ b/src/kernel/include/devfs.h @@ -0,0 +1,8 @@ +#pragma once + +#include <vfs.h> + +fs_t* init_devfs(); + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/include/nullfs.h b/src/kernel/include/nullfs.h new file mode 100644 index 0000000..16fff87 --- /dev/null +++ b/src/kernel/include/nullfs.h @@ -0,0 +1,25 @@ +#pragma once + +#include <vfs.h> + +#define NULLFS_OPT_CREATE_EN 1 +#define NULLFS_OPT_DELETE_EN 2 + +typedef struct nullfs nullfs_t; + +typedef struct { + void* (*open)(void* f, int mode, fs_handle_t *h); + size_t (*read)(void* f, size_t offset, size_t len, char* buf); + size_t (*write)(void* f, size_t offset, size_t len, const char* buf); + void (*close)(void* f); + void (*delete)(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, int ok_modes); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/include/process.h b/src/kernel/include/process.h index 00ed1d7..a6ca1e9 100644 --- a/src/kernel/include/process.h +++ b/src/kernel/include/process.h @@ -3,41 +3,19 @@ // Things described in this file are essentially a public interface // All implementation details are hidden in process.c +// A process is a recipient for user code, as well as for mounting File Systems, +// which allow access to features of the system. + #include <thread.h> #include <hashtbl.h> -#include <buffer.h> - -#define PW_NOT_WAITING 0 -#define PW_WAIT_ANY_MSG 1 -#define PW_WAIT_MSG_ON_CHAN 2 - -#define PROCESS_MAILBOX_SIZE 42 - -typedef int chan_id_t; -typedef struct chan_pair { - chan_id_t fst, snd; -} chan_pair_t; - -typedef struct message { - buffer_t *data; - chan_id_t chan_id; -} message_t; struct process; typedef struct process process_t; -process_t *new_process(entry_t entry, void* data, chan_pair_t *give_chans); - -chan_pair_t new_chan(); // not used very often, but still usefull -chan_id_t unbox_chan(chan_id_t chan, chan_id_t subchan); -void detach_chan(chan_id_t chan); // chan ID is freed - -int send_message(chan_id_t chan, buffer_t *msg); // nonnull on error (recipient queue is full) +process_t *new_process(entry_t entry, void* data); -size_t await_message(); // returns the size of the first message to come -size_t await_message_on_chan(chan_id_t chan); // returns the size of the first message to come -message_t get_message(); // gets the first message in the queue (or nothing when queue is empty) +bool mmap(process_t *proc, void* addr, size_t size, int type); /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h new file mode 100644 index 0000000..5f7a0d8 --- /dev/null +++ b/src/kernel/include/vfs.h @@ -0,0 +1,86 @@ +#pragma once + +#include <stdbool.h> +#include <malloc.h> + +typedef struct { + // TODO + // (should also be moved to a user-visible header) +} stat_t; + +#define FM_READ (0x01) +#define FM_WRITE (0x02) +#define FM_MMAP (0x04) +#define FM_CREATE (0x10) +#define FM_TRUNC (0x20) +#define FM_APPEND (0x40) + +// How to use : +// - when using a filesystem : never call the operations in fs_*_ops_t directly, use +// the functions defined bellow +// - when programming a filesystem : don't worry about allocating the fs_handle_t and fs_t, +// it is done automatically + + +// Structure defining a handle to an open file + +typedef struct { + size_t (*read)(void* f, size_t offset, size_t len, char* buf); + size_t (*write)(void* f, size_t offset, size_t len, const char* buf); + void (*close)(void* f); +} fs_handle_ops_t; + +typedef struct fs_handle { + int refs; + fs_handle_ops_t *ops; + void* data; + int mode; +} fs_handle_t; + +// Structure defining a filesystem + +typedef struct { + bool (*open)(void *fs, const char* file, int mode, fs_handle_t *s); + bool (*delete)(void *fs, const char* file); + bool (*rename)(void *fs, const char* from, const char* to); + bool (*stat)(void *fs, const char* file, stat_t *st); + int (*ioctl)(void *fs, const char* file, int command, void* data); + bool (*add_source)(void* fs, fs_handle_t* source); + void (*shutdown)(void *fs); +} fs_ops_t; + +typedef struct fs { + int refs; + fs_ops_t *ops; + void* data; +} fs_t; + +// Structure defining a filesystem driver + +typedef struct { + bool (*make)(fs_handle_t *source, char* opts, fs_t *d); + bool (*detect)(fs_handle_t *source); +} fs_driver_ops_t; + +// Common functions + +void register_fs_driver(const char* name, fs_driver_ops_t *ops); + +fs_t* make_fs(const char* driver, fs_handle_t *source, char* opts); +bool fs_add_source(fs_t *fs, fs_handle_t *source); +void ref_fs(fs_t *fs); +void unref_fs(fs_t *fs); + +bool fs_delete(fs_t *fs, const char* file); +bool fs_rename(fs_t *fs, const char* from, const char* to); +bool fs_stat(fs_t *fs, const char* file, stat_t *st); +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); +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); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |