2023-03-10 10:32:50 +00:00
|
|
|
// This file is part of noxos and licensed under the MIT open source license
|
2023-02-24 00:31:11 +00:00
|
|
|
|
|
|
|
#ifndef NOX_VFS_H
|
|
|
|
#define NOX_VFS_H
|
|
|
|
|
|
|
|
#include "utils/stdtypes.h"
|
|
|
|
#include "utils/string.h"
|
|
|
|
#include "boot/boot_info.h"
|
|
|
|
|
|
|
|
#define VFS_MAX_NAME_LENGTH 128
|
|
|
|
|
|
|
|
typedef struct vfs_node_T vfs_node_T;
|
|
|
|
|
2023-02-26 15:14:37 +00:00
|
|
|
typedef enum {
|
|
|
|
FS_RAMFS,
|
|
|
|
|
|
|
|
FS_ENUM_END
|
|
|
|
} fs_type_E;
|
|
|
|
|
2023-02-24 00:31:11 +00:00
|
|
|
typedef enum {
|
|
|
|
VFS_NODE_DIRECTORY,
|
|
|
|
VFS_NODE_FILE,
|
|
|
|
VFS_NODE_MOUNT,
|
|
|
|
VFS_NODE_BLOCK_DEVICE,
|
|
|
|
|
|
|
|
VFS_NODE_ENUM_END
|
|
|
|
} vfs_node_type_E;
|
|
|
|
|
2023-02-26 15:14:37 +00:00
|
|
|
typedef struct {
|
|
|
|
fs_type_E type;
|
|
|
|
vfs_node_T* root_node;
|
|
|
|
} fs_T;
|
|
|
|
|
2023-02-24 00:31:11 +00:00
|
|
|
typedef struct {
|
|
|
|
void* buffer;
|
|
|
|
uint64_t buffer_size;
|
|
|
|
bool reclaimable;
|
|
|
|
vfs_node_T* node;
|
|
|
|
} vfs_node_cache_T;
|
|
|
|
|
|
|
|
struct vfs_node_T{
|
|
|
|
char name[VFS_MAX_NAME_LENGTH];
|
|
|
|
vfs_node_type_E type;
|
|
|
|
vfs_node_cache_T* cache;
|
2023-02-26 15:14:37 +00:00
|
|
|
uint64_t size;
|
|
|
|
void* specific;
|
|
|
|
fs_T* filesystem;
|
2023-02-24 00:31:11 +00:00
|
|
|
|
|
|
|
vfs_node_T* prev;
|
|
|
|
vfs_node_T* next;
|
|
|
|
vfs_node_T* parent;
|
|
|
|
vfs_node_T* childs;
|
|
|
|
};
|
|
|
|
|
2023-02-26 15:14:37 +00:00
|
|
|
extern fs_T g_root_fs;
|
|
|
|
|
|
|
|
vfs_node_cache_T* vfs_node_cache_create (vfs_node_T* node, uint64_t size);
|
|
|
|
void vfs_node_cache_destruct (vfs_node_cache_T* node_cache);
|
|
|
|
|
|
|
|
vfs_node_T* vfs_node_create (vfs_node_T* parent, string_t name, vfs_node_type_E type, void* specific);
|
|
|
|
void vfs_node_destruct (vfs_node_T* node);
|
2023-04-20 13:30:19 +00:00
|
|
|
void vfs_node_delete (vfs_node_T* node);
|
2023-02-26 15:14:37 +00:00
|
|
|
void vfs_node_dump_info (vfs_node_T* node, uint64_t indent);
|
|
|
|
vfs_node_T* vfs_node_resolve_child (vfs_node_T* node, string_t child_name);
|
2023-02-24 00:31:11 +00:00
|
|
|
|
2023-02-26 15:14:37 +00:00
|
|
|
vfs_node_T* vfs_file_create (fs_T* filesystem, string_t path);
|
|
|
|
void vfs_file_delete (vfs_node_T* file);
|
2023-05-02 16:01:53 +00:00
|
|
|
uint64_t vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in);
|
|
|
|
uint64_t vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out);
|
2023-02-24 00:31:11 +00:00
|
|
|
|
2023-02-27 21:50:05 +00:00
|
|
|
vfs_node_T* vfs_directory_create (fs_T* filesystem, string_t path);
|
|
|
|
void vfs_directory_delete (vfs_node_T* directory);
|
|
|
|
|
2023-02-26 15:14:37 +00:00
|
|
|
void vfs_init (boot_info_T* boot_info);
|
|
|
|
vfs_node_T* vfs_resolve_path (fs_T* filesystem, string_t path);
|
2023-02-27 21:50:05 +00:00
|
|
|
void vfs_unpack_archive_ustar (fs_T* filesystem, void* archive);
|
2023-02-24 00:31:11 +00:00
|
|
|
|
|
|
|
#endif //NOX_VFS_H
|