2025-05-28 14:41:02 -05:00
|
|
|
#ifndef _DUCKFS_H
|
|
|
|
#define _DUCKFS_H
|
|
|
|
|
2025-06-17 15:50:07 -05:00
|
|
|
#include <types.h>
|
2025-05-28 14:41:02 -05:00
|
|
|
|
2025-06-27 14:48:06 -05:00
|
|
|
#define DUCKFS_MAGIC "DUCKFS1"
|
|
|
|
#define DUCKFS_NAME_LEN 32
|
|
|
|
|
|
|
|
typedef enum { DUCKFS_TYPE_FILE = 0, DUCKFS_TYPE_DIR = 1, DUCKFS_TYPE_SYMLINK = 2 } duckfs_type_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char name[DUCKFS_NAME_LEN];
|
|
|
|
duckfs_type_t type;
|
|
|
|
uint8_t permissions; /* rwxrwxrwx packed into 9 bits */
|
|
|
|
uint16_t uid;
|
|
|
|
uint16_t gid;
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t created;
|
|
|
|
uint64_t modified;
|
|
|
|
uint64_t first_block_lba;
|
|
|
|
uint64_t next_file_lba;
|
|
|
|
uint64_t child_lba; /* only for directories */
|
|
|
|
} __attribute__((packed)) duckfs_file_header_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char magic[8]; /* "DUCKFS1\0" */
|
|
|
|
uint32_t block_size;
|
|
|
|
uint64_t total_blocks;
|
|
|
|
uint64_t root_header_lba;
|
|
|
|
uint64_t free_list_lba;
|
|
|
|
uint32_t fs_version;
|
|
|
|
} __attribute__((packed)) duckfs_superblock_t;
|
|
|
|
|
|
|
|
struct free_block {
|
|
|
|
uint64_t next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DuckFS API */
|
|
|
|
int32_t duckfs_mount(void);
|
|
|
|
|
|
|
|
int32_t duckfs_find(const char* path, duckfs_file_header_t* out);
|
|
|
|
|
|
|
|
int32_t duckfs_create_file(const char* name, const void* content, size_t size, uint16_t uid, uint16_t gid, uint8_t perms, duckfs_file_header_t* parent_dir);
|
|
|
|
int32_t duckfs_create_dir(const char* name, uint16_t uid, uint16_t gid, uint8_t perms, duckfs_file_header_t* parent_dir);
|
|
|
|
int32_t duckfs_delete_file(const char* name, duckfs_file_header_t* parent_dir);
|
|
|
|
int32_t duckfs_delete_dir(const char* name, duckfs_file_header_t* parent_dir);
|
|
|
|
|
|
|
|
int32_t duckfs_read_file(const duckfs_file_header_t* file, void* buffer, size_t size);
|
|
|
|
int32_t duckfs_write_data(duckfs_file_header_t* file, const void* data, size_t offset, size_t length);
|
|
|
|
int32_t duckfs_append_data(duckfs_file_header_t* file, const void* data, size_t length);
|
|
|
|
|
|
|
|
int32_t duckfs_truncate(duckfs_file_header_t* file, size_t new_size);
|
2025-05-28 14:41:02 -05:00
|
|
|
|
|
|
|
#endif
|