diff --git a/include/fs.h b/include/fs.h new file mode 100644 index 0000000..c7b2b4c --- /dev/null +++ b/include/fs.h @@ -0,0 +1,32 @@ +#ifndef FROSTBYTE_FS_H +#define FROSTBYTE_FS_H + +#define oReadOnly 0x0 +#define oWriteOnly 0x1 +#define oReadWrite 0x2 +#define oCreate 0x40 +#define oTrunc 0x200 +#define oAppend 0x400 + +#define seekSet 0 +#define seekCur 1 +#define seekEnd 2 + +#define fsTypeFile 1 +#define fsTypeDir 2 + +#define fsNameMax 64 + +typedef struct FbStat { + unsigned long size; + unsigned int type; + unsigned int mode; +} FbStat; + +typedef struct FbDirent { + unsigned int type; + unsigned int nameLength; + char name[fsNameMax]; +} FbDirent; + +#endif diff --git a/include/initrd.h b/include/initrd.h new file mode 100644 index 0000000..21d0fc6 --- /dev/null +++ b/include/initrd.h @@ -0,0 +1,17 @@ +#ifndef FROSTBYTE_INITRD_H +#define FROSTBYTE_INITRD_H + +#include "types.h" + +typedef struct UstarEntry { + const char* name; + const uint8* data; + uint64 size; + bool isDir; +} UstarEntry; + +void initrdInit(uint64 start, uint64 end); +uint32 initrdCount(void); +bool initrdAt(uint32 index, UstarEntry* out); + +#endif diff --git a/include/vfs.h b/include/vfs.h new file mode 100644 index 0000000..e9832c8 --- /dev/null +++ b/include/vfs.h @@ -0,0 +1,49 @@ +#ifndef FROSTBYTE_VFS_H +#define FROSTBYTE_VFS_H + +#include "types.h" +#include "fs.h" + +struct VfsNode; + +typedef enum { + fdFree = 0, + fdConsole = 1, + fdFile = 2 +} FdKind; + +typedef struct FileDescriptor { + struct VfsNode* node; + uint64 offset; + uint32 kind; + uint32 flags; +} FileDescriptor; + +#define maxOpenFiles 16 + +void vfsInit(void); +void vfsMountUstar(uint64 start, uint64 end); +void vfsMountTmpfs(const char* path); +void vfsFdInit(FileDescriptor* fds); + +int vfsOpen(const char* path, uint32 flags); +int vfsClose(int fd); +int64 vfsRead(int fd, void* buffer, uint64 length); +int64 vfsWrite(int fd, const void* buffer, uint64 length); +int64 vfsLseek(int fd, int64 offset, int whence); +int vfsStat(const char* path, FbStat* out); +int64 vfsGetdents(int fd, void* buffer, uint64 length); +int vfsMkdir(const char* path); +int vfsUnlink(const char* path); + +typedef struct VfsNode VfsNode; +VfsNode* vfsLookup(const char* path); +VfsNode* vfsChild(VfsNode* dir); +VfsNode* vfsNext(VfsNode* node); +const char* vfsName(VfsNode* node); +bool vfsIsDir(VfsNode* node); +uint64 vfsSize(VfsNode* node); +const void* vfsFileData(VfsNode* node); +void vfsPath(VfsNode* node, char* out, uint64 cap); + +#endif