Espresso 0.0.1a

This commit is contained in:
2025-06-17 15:50:07 -05:00
parent eeea3b2d86
commit fca025a9bf
24 changed files with 1080 additions and 600 deletions

View File

@ -1,79 +1,8 @@
#ifndef _DUCKFS_H
#define _DUCKFS_H
#include <stdint.h>
#include <types.h>
#define DFS_MAGIC 0xDF1984CC
#define DFS_BLOCK_SIZE 512
#define DFS_VERSION_0 "DuckFS, wheresDax?"
#define DFS_VERSION_1 "DuckFS, Terminator"
#define DFS_VERSION_2 "DuckFS-Terminator2"
#define DFS_VERSION_3 "DuckFS,StarWarsEIV"
#define DFS_VERSION_4 "DuckFS QUACK,QUACK"
#define DFS_FILE_ERROR -8
#define DFS_FILE_UNUSED -1
#define DFS_FILE_USED 0
#define DFS_FILE_TEXT 0
#define DFS_FILE_BINARY 1
#define DFS_FILE_DIRECTORY 2
/* encryption algorithms */
#define DFS_CAESAR_5 88
#define DFS_CAESAR_8 84
#define DFS_CAESAR_2 09
#define DFS_QUACK_32 99
#define DFS_MAX_FILENAME_LEN 64
#define DFS_MAX_FILES 256
typedef struct duckfs_file_header {
char filename[DFS_MAX_FILENAME_LEN + 1]; /* + 1 for the \0 */
char permissions[3]; /* Same thing here */
/*
512 Bytes per sector, meaning a 2 sector file is 1024 bytes, or 1 KiB.
Only valid if this file is not a directory.
*/
int32_t num_sectors;
int16_t type; /* Indicates the file type. -1 for null file, 0 for a text file, 1 for a binary file, and 2 for a directory. */
uint16_t _reserved0; /* (align to 4) */
struct duckfs_file_header* next;
struct duckfs_file_header* prev;
struct duckfs_file_header* contents; /* contains the directories files. only valid if this file is a directory. */
uint32_t lba_start; /* only is valid if this file is not a directory. */
uint32_t lba_end; /* only is valid if this file is not a directory. */
uint8_t _reserved1[158]; /* padding to 256 bytes total */
} duckfs_file_header_t;
typedef struct duckfs_superblock {
int32_t duckfs_magic; /* must be DFS_MAGIC. */
char duckfs_version_string[19];
char volume_label[19]; /* 18 characters and a null zero. */
int16_t encryption;
struct duckfs_file_header* duckfs_root;
uint32_t _padding[116];
} duckfs_superblock_t;
int32_t duckfs_init(int16_t drive);
void duckfs_format(int16_t drive);
int32_t duckfs_makedir(const char* filename, const char* perms);
void duckfs_free_directory(duckfs_file_header_t* dir);
duckfs_file_header_t duckfs_create_entry(const char* name, const char* perms, const char* type);
bool duckfs_add_entry(duckfs_file_header_t* dir, duckfs_file_header_t* entry);
void duckfs_init(void);
#endif

View File

@ -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

20
include/fs/vfs.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef _VFS_H
#define _VFS_H
#include <types.h>
typedef int32_t FILE;
void vfs_init(void);
FILE create_file(char* filename, char type, char encryption, FILE parent);
int32_t delete_file(FILE file);
FILE open_file(char* filename);
FILE write_file(FILE file, void* data, size_t len);
int32_t read_file(FILE file, void* buf, size_t buflen);
int32_t reset_read_offset(FILE file);
#endif