-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b933038
commit 4667ddb
Showing
16 changed files
with
944 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef fs_h | ||
#define fs_h | ||
|
||
#include <std/int.h> | ||
|
||
|
||
typedef | ||
enum { | ||
NO_ERROR = 0, | ||
FILE_NOT_FOUND = 1, | ||
ARGUMENT_ERROR = 2, | ||
} F_err; | ||
|
||
typedef | ||
struct { | ||
uint8_t __open__; | ||
uint64_t __position__; | ||
void *__data__; | ||
struct filesystem_s *fs; | ||
} F; | ||
|
||
typedef | ||
struct _directory { | ||
uint64_t __position__; | ||
} D; | ||
|
||
typedef | ||
struct _stat { | ||
uint64_t __position__; | ||
} S; | ||
|
||
typedef | ||
struct filesystem_s { | ||
/* File operations */ | ||
F_err (*f_open)(F *file, char *name, uint16_t mode); | ||
F_err (*f_close)(F *file); | ||
F_err (*f_read)(F *file, void *dest, uint64_t to_read, uint64_t *actually_read); | ||
F_err (*f_write)(F *file, void *src, uint64_t to_write, uint64_t *actually_wrote); | ||
F_err (*f_lseek)(F *file, uint64_t seek_to); | ||
F_err (*f_truncate)(F *file); | ||
F_err (*f_sync)(F *file); | ||
F_err (*f_tell)(F *file, uint64_t *buffer_position); | ||
F_err (*f_eof)(F *file); | ||
F_err (*f_size)(F *file, uint64_t *file_size); | ||
|
||
/* Directory operations */ | ||
F_err (*d_open)(D *dir, char *name, uint16_t mode); | ||
F_err (*d_close)(D *dir); | ||
F_err (*d_next)(D *dir, char **name); | ||
F_err (*d_rewind)(D *dir); | ||
F_err (*d_mkdir)(char *name); | ||
|
||
/* Status operations */ | ||
F_err (*i_stat)(S *stat, char *path); | ||
F_err (*i_unlink)(char *path); | ||
F_err (*i_rename)(char *old_path, char *new_path); | ||
|
||
void *__internal__; | ||
} filesystem_t; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef kernel_fs_h | ||
#define kernel_fs_h | ||
|
||
#include <fs/fs.h> | ||
|
||
filesystem_t *kernel_fs_init(); | ||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef mapfs_h | ||
#define mapfs_h | ||
|
||
#include <fs/fs.h> | ||
#include <std/int.h> | ||
#include <std/map.h> | ||
|
||
typedef | ||
enum { | ||
FILE, | ||
DIR | ||
} TYPE; | ||
|
||
typedef | ||
struct { | ||
union { | ||
map_t dir; | ||
char *data; | ||
}; | ||
uint64_t size; | ||
TYPE type; | ||
} d_f; | ||
|
||
|
||
F_err mfs_open(F *file, char *name, uint16_t mode); | ||
F_err mfs_close(F *file); | ||
F_err mfs_read(F *file, void *dest, uint64_t to_read, uint64_t *actually_read); | ||
F_err mfs_write(F *file, void *src, uint64_t to_write, uint64_t *actually_wrote); | ||
|
||
filesystem_t *mfs_new_fs(); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef root_h | ||
#define root_h | ||
|
||
#include <fs/fs.h> | ||
|
||
void root_init(); | ||
int mount(char *path, filesystem_t *fs); | ||
|
||
|
||
int open(char *, uint16_t); | ||
int close(int); | ||
int read(int, void *, uint64_t); | ||
int write(int, void *, uint64_t); | ||
void stat(int); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef map_h | ||
#define map_h | ||
|
||
#include <std/int.h> | ||
|
||
#define MAP_MISSING -3 /* No such element */ | ||
#define MAP_FULL -2 /* Hashmap is full */ | ||
#define MAP_OMEM -1 /* Out of Memory */ | ||
#define MAP_OK 0 /* OK */ | ||
|
||
// You don't get to know what a map_t is! | ||
typedef void *map_t; | ||
|
||
// For iterating through hashmaps as a simple list | ||
typedef struct { | ||
char *key; | ||
void *data; | ||
} hashmap_iterator_element; | ||
|
||
typedef struct { | ||
int position; | ||
int maximum; | ||
hashmap_iterator_element *data; | ||
} hashmap_iterator; | ||
|
||
int hashmap_put(map_t in, char *key, void *value); | ||
|
||
int hashmap_get(map_t in, char *key, void **arg); | ||
|
||
int hashmap_remove(map_t in, char *key); | ||
|
||
void hashmap_free(map_t in); | ||
|
||
int hashmap_size(map_t in); | ||
|
||
map_t hashmap_new(); | ||
|
||
hashmap_iterator *map_iterator(map_t in); | ||
int hashmap_iterator_has_next(hashmap_iterator *itr); | ||
void hashmap_iterator_done(hashmap_iterator *itr); | ||
hashmap_iterator_element *hashmap_iterator_next(hashmap_iterator *itr); | ||
|
||
#define hashmap_iterate(m, k, v) \ | ||
for(void *___i=map_iterator(m),*___m=NULL; \ | ||
hashmap_iterator_has_next(___i)?(___m=hashmap_iterator_next(___i), \ | ||
v=((hashmap_iterator_element *)___m)->data, \ | ||
k=((hashmap_iterator_element *)___m)->key):0;) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <fs/kernel_fs.h> | ||
#include <fs/fs.h> | ||
#include <fs/mfs/map_fs.h> | ||
|
||
|
||
/* | ||
typedef | ||
struct filesystem_s { | ||
F_err (*f_open)(F *file, char *name, uint16_t mode); | ||
F_err (*f_close)(F *file); | ||
F_err (*f_read)(F *file, void *dest, uint64_t to_read, uint64_t *actually_read); | ||
F_err (*f_write)(F *file, void *src, uint64_t to_write, uint64_t *actually_wrote); | ||
F_err (*f_lseek)(F *file, uint64_t seek_to); | ||
F_err (*f_truncate)(F *file); | ||
F_err (*f_sync)(F *file); | ||
F_err (*f_tell)(F *file, uint64_t *buffer_position); | ||
F_err (*f_eof)(F *file); | ||
F_err (*f_size)(F *file, uint64_t *file_size); | ||
F_err (*d_open)(D *dir, char *name, uint16_t mode); | ||
F_err (*d_close)(D *dir); | ||
F_err (*d_next)(D *dir, char **name); | ||
F_err (*d_rewind)(D *dir); | ||
F_err (*d_mkdir)(char *name); | ||
F_err (*i_stat)(S *stat, char *path); | ||
F_err (*i_unlink)(char *path); | ||
F_err (*i_rename)(char *old_path, char *new_path); | ||
} filesystem_t; | ||
*/ | ||
|
||
filesystem_t *kernel_fs_init() { | ||
filesystem_t *result = mfs_new_fs(); | ||
|
||
result->f_open = mfs_open; | ||
result->f_close = mfs_close; | ||
result->f_read = mfs_read; | ||
result->f_write = mfs_write; | ||
|
||
return result; | ||
} |
Oops, something went wrong.