2022-10-08 19:22:46 +00:00
|
|
|
#pragma once
|
2022-10-09 19:30:38 +00:00
|
|
|
#include <stddef.h>
|
2022-10-08 19:22:46 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-10-09 19:30:38 +00:00
|
|
|
typedef long ssize_t;
|
|
|
|
|
2022-10-11 15:48:11 +00:00
|
|
|
#define VFS_FILE 0x0
|
|
|
|
#define VFS_DIRECTORY 0x1
|
2022-10-12 13:22:34 +00:00
|
|
|
#define VFS_DEVICE 0x2
|
2022-10-11 15:48:11 +00:00
|
|
|
|
2022-10-11 16:23:00 +00:00
|
|
|
#define VFS_MOUNTPOINT 0x1
|
|
|
|
|
2022-10-08 19:22:46 +00:00
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
struct Node;
|
|
|
|
|
2022-10-09 19:30:38 +00:00
|
|
|
typedef ssize_t (*node_read)(Node*, size_t, size_t, char*);
|
2022-10-11 19:03:30 +00:00
|
|
|
typedef ssize_t (*node_write)(Node*, size_t, size_t, const char*);
|
2022-10-08 19:22:46 +00:00
|
|
|
typedef Node* (*node_finddir)(Node*, const char*);
|
2022-10-11 16:23:00 +00:00
|
|
|
typedef int (*node_mkdir)(Node*, const char*);
|
2022-10-21 19:26:19 +00:00
|
|
|
typedef int (*node_block)(Node*);
|
2022-10-23 12:03:46 +00:00
|
|
|
typedef Node* (*node_readdir)(Node*, long);
|
2022-10-08 19:22:46 +00:00
|
|
|
|
|
|
|
struct Node
|
|
|
|
{
|
|
|
|
char name[64];
|
|
|
|
uint64_t inode;
|
2022-10-08 19:35:19 +00:00
|
|
|
uint64_t length;
|
2022-10-11 15:48:11 +00:00
|
|
|
int type;
|
2022-10-11 16:23:00 +00:00
|
|
|
int flags;
|
2022-10-08 19:22:46 +00:00
|
|
|
node_read read_func;
|
|
|
|
node_finddir find_func;
|
2022-10-23 12:03:46 +00:00
|
|
|
node_readdir readdir_func;
|
2022-10-11 16:23:00 +00:00
|
|
|
node_mkdir mkdir_func;
|
2022-10-11 19:03:30 +00:00
|
|
|
node_write write_func;
|
2022-10-21 19:26:19 +00:00
|
|
|
node_block block_func;
|
2022-10-21 16:34:31 +00:00
|
|
|
int tty = 0;
|
2022-10-11 16:23:00 +00:00
|
|
|
Node* link;
|
2022-10-08 19:22:46 +00:00
|
|
|
};
|
|
|
|
|
2022-10-09 19:30:38 +00:00
|
|
|
ssize_t read(Node* node, size_t offset, size_t length, char* buffer);
|
2022-10-11 19:03:30 +00:00
|
|
|
ssize_t write(Node* node, size_t offset, size_t length, const char* buffer);
|
2022-10-16 12:45:25 +00:00
|
|
|
int mkdir(const char* path, const char* name);
|
|
|
|
int mkdir(const char* pathname);
|
2022-10-09 19:19:22 +00:00
|
|
|
|
2022-10-21 19:26:19 +00:00
|
|
|
int would_block(Node* node);
|
|
|
|
|
2022-10-08 19:22:46 +00:00
|
|
|
void mount_root(Node* root);
|
2022-10-09 19:19:22 +00:00
|
|
|
|
2022-10-10 16:44:43 +00:00
|
|
|
Node* resolve_path(const char* filename, Node* root = nullptr);
|
|
|
|
|
2022-10-16 14:58:18 +00:00
|
|
|
bool exists(const char* pathname);
|
|
|
|
|
2022-10-11 16:23:00 +00:00
|
|
|
void mount(Node* mountpoint, Node* mounted);
|
2022-10-11 17:21:16 +00:00
|
|
|
void mount(const char* pathname, Node* mounted);
|
2022-10-11 16:23:00 +00:00
|
|
|
|
|
|
|
void unmount(Node* mountpoint);
|
|
|
|
|
2022-10-09 19:19:22 +00:00
|
|
|
Node* root();
|
2022-10-23 12:03:46 +00:00
|
|
|
|
|
|
|
Node* readdir(Node* dir, long offset);
|
2022-10-08 19:22:46 +00:00
|
|
|
}
|