Espresso 0.0.1a
This commit is contained in:
@ -1,53 +1,56 @@
|
||||
#ifndef _RAM_FS_H
|
||||
#define _RAM_FS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <types.h>
|
||||
|
||||
|
||||
#define RAMFS_MAX_FILES 128
|
||||
#define RAMFS_BLOCK_SIZE 4096
|
||||
#define RAMFS_MAX_PATH_LEN 255
|
||||
#define RAMFS_FILENAME_LEN 32
|
||||
|
||||
#define RAMFS_PERM_READ 0x01
|
||||
#define RAMFS_PERM_WRITE 0x02
|
||||
#define RAMFS_PERM_EXEC 0x04
|
||||
#define RAMFS_PERM_ALL (RAMFS_PERM_READ | RAMFS_PERM_WRITE | RAMFS_PERM_EXEC)
|
||||
|
||||
typedef struct ramfs_file {
|
||||
char name[RAMFS_MAX_PATH_LEN];
|
||||
uint32_t size;
|
||||
uint8_t* data;
|
||||
uint8_t permissions;
|
||||
} ramfs_file_t;
|
||||
#define RAMFS_FILE_DIR 'd'
|
||||
#define RAMFS_FILE_TEXT 't'
|
||||
#define RAMFS_FILE_BINARY 'b'
|
||||
#define RAMFS_FILE_LINK 'l'
|
||||
#define RAMFS_FILE_NOFILE 'n'
|
||||
|
||||
typedef struct ramfs_directory {
|
||||
char name[RAMFS_MAX_PATH_LEN];
|
||||
ramfs_file_t* files[RAMFS_MAX_FILES];
|
||||
uint32_t file_count;
|
||||
} ramfs_directory_t;
|
||||
#define RAMFS_ENCR_NONE 'n'
|
||||
#define RAMFS_ENCR_SIMPLE 's'
|
||||
|
||||
typedef struct ramfs_file_header {
|
||||
char filename[RAMFS_FILENAME_LEN + 1];
|
||||
char type;
|
||||
char encryption;
|
||||
|
||||
struct ramfs_file_header* content;
|
||||
struct ramfs_file_header* parent;
|
||||
struct ramfs_file_header* next;
|
||||
struct ramfs_file_header* link_target;
|
||||
|
||||
void* data_begin;
|
||||
void* data_end;
|
||||
|
||||
int32_t read_offset;
|
||||
|
||||
int32_t fd;
|
||||
} ramfs_file_header_t;
|
||||
|
||||
void ramfs_init();
|
||||
void ramfs_init(void);
|
||||
|
||||
ramfs_file_t* ramfs_create_file(const char* name, uint32_t size, uint8_t permissions);
|
||||
bool ramfs_delete_file(const char* name);
|
||||
ramfs_file_t* ramfs_find_file(const char* name);
|
||||
ramfs_file_header_t* ramfs_make_root(void);
|
||||
ramfs_file_header_t* ramfs_get_root(void);
|
||||
int32_t ramfs_get_files(void);
|
||||
bool ramfs_get_initialized(void);
|
||||
|
||||
bool ramfs_create_directory(const char* name);
|
||||
bool ramfs_delete_directory(const char* name);
|
||||
ramfs_file_header_t* ramfs_resolve_path(const char* path);
|
||||
ramfs_file_header_t* ramfs_resolve_fd_dir(ramfs_file_header_t* current, int32_t fd);
|
||||
ramfs_file_header_t* ramfs_resolve_fd(int32_t fd);
|
||||
|
||||
bool ramfs_check_permissions(const char* name, uint8_t required_permissions);
|
||||
|
||||
bool ramfs_resize_file(const char* name, uint32_t new_size);
|
||||
bool ramfs_append_to_file(const char* name, const uint8_t* data, uint32_t data_size);
|
||||
|
||||
bool ramfs_read_file(const char* name, uint8_t* buffer, uint32_t buffer_size);
|
||||
bool ramfs_write_file(const char* name, const uint8_t* data, uint32_t size);
|
||||
bool ramfs_overwrite_file(const char* name, const uint8_t* data, uint32_t size);
|
||||
|
||||
|
||||
void ramfs_list_files();
|
||||
void ramfs_list_directories();
|
||||
ramfs_file_header_t* ramfs_create_file(char* name, char type, char encryption, ramfs_file_header_t* parent);
|
||||
int32_t ramfs_delete_file(ramfs_file_header_t* file);
|
||||
ramfs_file_header_t* ramfs_write_file(ramfs_file_header_t* file, void* data, size_t len);
|
||||
int32_t ramfs_read_file(ramfs_file_header_t* file, void* buffer, size_t buffer_len);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user