-
Notifications
You must be signed in to change notification settings - Fork 0
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
b638f11
commit cf60d75
Showing
6 changed files
with
65 additions
and
131 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +1,28 @@ | ||
#include "vfs.h" | ||
|
||
struct fs_node_s *fs_root = NULL; | ||
PFILE root; | ||
|
||
uint32_t fs_write(struct fs_node_s* node, uint32_t offset, uint32_t size, uint8_t* buffer) { | ||
if (!node->write) return node->write(node, offset, size, buffer); | ||
uint32_t fs_read(PFILE node, uint32_t offset, uint32_t size, char* buffer) { | ||
if (node->node_operations.read) return node->node_operations.read(node, offset, size, buffer); | ||
return 0; | ||
} | ||
|
||
uint32_t fs_read(struct fs_node_s* node, uint32_t offset, uint32_t size, uint8_t* buffer) { | ||
if (!node->read) return node->read(node, offset, size, buffer); | ||
uint32_t fs_write(PFILE node,uint32_t offset, uint32_t size, char* buffer) { | ||
if (node->node_operations.write) return node->node_operations.write(node, offset, size, buffer); | ||
return 0; | ||
} | ||
|
||
void fs_open(struct fs_node_s* node, uint8_t read, uint8_t write) { | ||
if (!node->open) (node->open(node)); | ||
} | ||
|
||
void fs_close(struct fs_node_s* node) { | ||
if (!node->close) (node->close(node)); | ||
uint32_t fs_open(PFILE node, enum open_flags flags) { | ||
if (node->node_operations.open) return node->node_operations.open(node, flags); | ||
return 0; | ||
} | ||
|
||
dir_entry_t* readdir_fs(struct fs_node_s* node, uint32_t index) { | ||
if (!node->readdir && (node->flags & 7 == FS_DIRECTORY)) return node->readdir(node, index); | ||
return NULL; | ||
uint32_t fs_close(PFILE node) { | ||
if (node->node_operations.close) return node->node_operations.close(node); | ||
return 0; | ||
} | ||
|
||
struct fs_node_s* finddir_fs(struct fs_node_s* node, char* name) { | ||
if (!node->finddir && (node->flags & 7 == FS_DIRECTORY)) return node->finddir(node, name); | ||
dentry* fs_readdir(PFILE node, uint32_t index) { | ||
if ((node->type & FS_DIR) && node->node_operations.readdir) return node->readdir(node, index); | ||
return NULL; | ||
} |
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 |
---|---|---|
@@ -1,58 +1,52 @@ | ||
#ifndef VFS_H | ||
#define VFS_H | ||
|
||
#include <stdint.h> | ||
#include <stduint32_t.h> | ||
#include <stddef.h> | ||
#include "../../lib/string/string.h" | ||
#include "../../memory/vmm/vmm.h" | ||
|
||
enum fs_flags { | ||
FS_FILE = 1, | ||
FS_DIRECTORY = 2, | ||
FS_CHARDEVICE = 3, | ||
FS_BLOCKDEVICE = 4, | ||
FS_PIPE = 5, | ||
FS_SYMLINK = 6, | ||
FS_MOUNTPOINT = 8 | ||
typedef enum node_type { | ||
FS_FILE, | ||
FS_DIR, | ||
FS_CHARDEVICE, | ||
FS_BLOCKDEVICE, | ||
FS_PIPE, | ||
FS_SYMLINK, | ||
FS_MOUNTPOINT | ||
}; | ||
|
||
typedef uint32_t (*rw_t)(struct fs_node_s*, uint32_t, uint32_t, uint8_t*); | ||
typedef void (*oc_t)(struct fs_node_s*); | ||
typedef struct dir_entry_s * (*readdir_t)(struct fs_node_s*, uint32_t); | ||
typedef struct fs_node_s * (*finddir_t)(struct fs_node_s*, char* name); | ||
|
||
typedef struct fs_node_s { | ||
char name[128]; // Should move it to directory node | ||
uint32_t permissions; | ||
uint32_t uid; | ||
uint32_t gid; | ||
uint32_t flags; | ||
uint32_t inode; // Provide to a filesystem a way to identify nodes | ||
uint32_t len; | ||
uint32_t impl; // Implementation-defined number | ||
// These are pointers to callbacks | ||
rw_t read; | ||
rw_t write; | ||
oc_t open; | ||
oc_t close; | ||
readdir_t readdir; | ||
finddir_t finddir; | ||
struct fs_node_s *ptr; // For symlink and mountpoint | ||
} fs_node_t; | ||
|
||
typedef struct dir_entry_s { | ||
char name[128]; | ||
uint32_t inode; | ||
} dir_entry_t; | ||
|
||
|
||
uint32_t fs_write(struct fs_node_s* node, uint32_t offset, uint32_t size, uint8_t* buffer); | ||
uint32_t fs_read(struct fs_node_s* node, uint32_t offset, uint32_t size, uint8_t* buffer); | ||
void fs_open(struct fs_node_s* node, uint8_t read, uint8_t write); | ||
void fs_close(struct fs_node_s* node); | ||
dir_entry_t* readdir_fs(struct fs_node_s* node, uint32_t index); | ||
struct fs_node_s* finddir_fs(struct fs_node_s*, char* name); | ||
typedef enum open_flags { | ||
READ, | ||
WRITE | ||
}; | ||
|
||
extern fs_node_t* fs_root; | ||
typedef struct _dentry { | ||
char name[32]; | ||
uint32_t inode; | ||
} dentry; | ||
|
||
typedef struct _FILE { | ||
char name[32]; | ||
uint32_t permissions; | ||
enum node_type type; | ||
uint32_t uid; | ||
uint32_t sid; | ||
uint32_t inode; | ||
uint32_t length; | ||
struct node_operations { | ||
uint32_t (*read)(struct FILE*,uint32_t,uint32_t,char*buffer); | ||
uint32_t (*write)(struct FILE*,uint32_t,uint32_t,char*buffer); | ||
uint32_t (*open)(struct FILE*, enum open_flags); | ||
uint32_t (*close)(struct FILE*); | ||
dentry* (*readdir)(struct FILE*,uint32_t); | ||
}; | ||
} FILE, *PFILE; | ||
|
||
uint32_t fs_close(PFILE); | ||
uint32_t fs_write(PFILE,uint32_t,uint32_t,char*buffer); | ||
uint32_t fs_read(PFILE,uint32_t,uint32_t,char*buffer); | ||
uint32_t fs_open(PFILE, enum open_flags); | ||
dentry* fs_readdir(PFILE,uint32_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