Luna/kernel/include/fs/VFS.h

81 lines
2.0 KiB
C
Raw Normal View History

#pragma once
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
typedef long ssize_t;
#define VFS_FILE 0x0
#define VFS_DIRECTORY 0x1
#define VFS_DEVICE 0x2
#define VFS_MOUNTPOINT 0x1
#define NAME_MAX 64
namespace VFS
{
struct Node;
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*);
typedef Node* (*node_finddir)(Node*, const char*);
typedef int (*node_mkdir)(Node*, const char*, mode_t);
typedef int (*node_block)(Node*);
typedef Node* (*node_readdir)(Node*, long);
struct Node
{
char name[NAME_MAX];
uint64_t inode;
2022-10-08 19:35:19 +00:00
uint64_t length;
int type;
int flags;
node_read read_func;
node_finddir find_func;
node_readdir readdir_func;
node_mkdir mkdir_func;
2022-10-11 19:03:30 +00:00
node_write write_func;
node_block block_func;
int tty = 0;
Node* link;
int uid;
int gid;
uint64_t atime;
uint64_t ctime;
uint64_t mtime;
mode_t mode;
};
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);
int mkdir(const char* path, const char* name);
int mkdir(const char* pathname);
2022-10-09 19:19:22 +00:00
int do_mkdir(const char* path, const char* name, int uid, int gid, mode_t mode);
int do_mkdir(const char* pathname, int uid, int gid, mode_t mode);
int would_block(Node* node);
void mount_root(Node* root);
2022-10-09 19:19:22 +00:00
Node* resolve_path(const char* filename, Node* root = nullptr);
2022-10-16 14:58:18 +00:00
bool exists(const char* pathname);
void mount(Node* mountpoint, Node* mounted);
void mount(const char* pathname, Node* mounted);
void unmount(Node* mountpoint);
2022-10-09 19:19:22 +00:00
Node* root();
Node* readdir(Node* dir, long offset);
bool can_execute(Node* node, int uid, int gid);
bool can_read(Node* node, int uid, int gid);
bool can_write(Node* node, int uid, int gid);
bool is_setuid(Node* node);
bool is_setgid(Node* node);
}