From 2432a437a715f7220697d13aae13e97087709842 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 12 Feb 2015 15:35:11 +0100 Subject: DOES NOT COMPILE | VFS structure change (VFS centralises more stuff) --- src/common/include/fs.h | 29 ++++++++++++++++++---- src/kernel/include/process.h | 14 ++++++++--- src/kernel/include/vfs.h | 58 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/common/include/fs.h b/src/common/include/fs.h index 6cd624e..d97f0fe 100644 --- a/src/common/include/fs.h +++ b/src/common/include/fs.h @@ -3,15 +3,34 @@ #include #include -typedef struct { - size_t size; - // TODO : times & more metadata -} stat_t; +#define FT_REGULAR 0 // no flags = regular file +#define FT_DIR (0x01) +#define FT_DEV (0x02) +#define FT_BLOCKDEV (0x04) +#define FT_CHARDEV (0x08) +#define FT_FIFO (0x10) +#define FT_SOCKET (0x20) #define FM_READ (0x01) #define FM_WRITE (0x02) -#define FM_MMAP (0x04) +#define FM_READDIR (0x04) +#define FM_MMAP (0x08) #define FM_CREATE (0x10) #define FM_TRUNC (0x20) #define FM_APPEND (0x40) +typedef struct { + int type; + int access; + size_t size; + // TODO : times & more metadata +} stat_t; + +#define DIR_MAX 128 // maximum length for a filename + +typedef struct { + char name[DIR_MAX]; +} dirent_t; + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/include/process.h b/src/kernel/include/process.h index a6ca1e9..d1914ef 100644 --- a/src/kernel/include/process.h +++ b/src/kernel/include/process.h @@ -1,8 +1,5 @@ #pragma once -// 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. @@ -14,8 +11,17 @@ struct process; typedef struct process process_t; -process_t *new_process(entry_t entry, void* data); +process_t *current_process(); + +process_t *new_process(process_t *parent); +void delete_process(process_t *p); + +void start_process(process_t *p, entry_t entry, void* data); + +bool proc_add_fs(process_t *p, fs_t *fs, const char* name); +fs_t *proc_find_fs(process_t *p, const char* name); bool mmap(process_t *proc, void* addr, size_t size, int type); +bool mmap_file(process_t *proc, fs_handle_t *h, void* addr, size_t size, int mode); /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h index 3ee4367..6dbbe5d 100644 --- a/src/kernel/include/vfs.h +++ b/src/kernel/include/vfs.h @@ -10,41 +10,73 @@ // the functions defined bellow // - when programming a filesystem : don't worry about allocating the fs_handle_t and fs_t, // it is done automatically +// - the three types defined below (filesystem, fs node, file handle) are reference-counters to +// some data managed by the underlying filesystem. The following types are aliases to void*, +// but are used to disambiguate the different types of void* : fs_handle_ptr, fs_node_ptr, fs_ptr +typedef void* fs_handle_ptr; +typedef void* fs_node_ptr; +typedef void* fs_ptr; // 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); - bool (*stat)(void* f, stat_t *st); - void (*close)(void* f); + 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); + void (*close)(fs_handle_ptr f); } fs_handle_ops_t; typedef struct fs_handle { + // These two field are filled by the VFS's generic open() code struct fs *fs; int refs; + + // These fields are filled by the FS's specific open() code fs_handle_ops_t *ops; - void* data; + fs_handle_ptr data; int mode; } fs_handle_t; +// Structure defining a filesystem node +// In the future this is where FS-level cache may be implemented : calls to dispose() are not +// executed immediately when refcount falls to zero but only when we need to free memory + +typedef struct { + bool (*open)(fs_node_ptr n, int mode, fs_handle_t *s); // open current node + bool (*stat)(fs_node_ptr n, stat_t *st); + bool (*walk)(fs_node_ptr n, const char* file, struct fs_node *n); + bool (*delete)(fs_node_ptr n); + bool (*create)(fs_node_ptr n, const char* name, int type); // create sub-node in directory + int (*ioctl)(fs_node_ptr n, int command, void* data) + void (*dispose)(fs_node_ptr n); +} fs_node_ops_t; + +typedef struct fs_node { + // These three fields are filled by the VFS's generic walk() code + struct fs *fs; + int refs; + struct fs_node *parent; + // These fields are filled by the FS's specific walk() code + fs_node_ops_t *ops; + fs_node_ptr data; +} fs_node_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); + bool (*add_source)(fs_ptr fs, fs_handle_t* source); + void (*shutdown)(fs_ptr fs); } fs_ops_t; typedef struct fs { + // Filled by VFS's make_fs() int refs; + // Filled by FS's specific make() fs_ops_t *ops; - void* data; + fs_ptr data; + // Filled by both according to what is specified for fs_node_t + fs_node_t root; } fs_t; // Structure defining a filesystem driver -- cgit v1.2.3