A update
This commit is contained in:
79
include/fs/duckfs.h
Normal file
79
include/fs/duckfs.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef _DUCKFS_H
|
||||
#define _DUCKFS_H
|
||||
|
||||
#include <stdint.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);
|
||||
|
||||
#endif
|
16
include/fs/fat32.h
Normal file
16
include/fs/fat32.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef _FAT32_H
|
||||
#define _FAT32_H
|
||||
#include <stdint.h>
|
||||
|
||||
#define FAT32_MAX_FILENAME 11
|
||||
#define FAT32_ATTR_DIRECTORY 0x10
|
||||
|
||||
int32_t fat32_init(int32_t drive); /* 0 = primary master */
|
||||
int32_t fat32_list_root(void);
|
||||
int32_t fat32_read_file(const char *name, uint8_t *buffer, uint32_t max_len);
|
||||
int32_t fat32_write_file(const char *name, const uint8_t *buffer, uint32_t len);
|
||||
int32_t fat32_create_file(const char *name);
|
||||
int32_t fat32_create_directory(const char *name);
|
||||
int32_t fat32_change_directory(const char *name);
|
||||
|
||||
#endif
|
53
include/fs/ramfs.h
Normal file
53
include/fs/ramfs.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef _RAM_FS_H
|
||||
#define _RAM_FS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#define RAMFS_MAX_FILES 128
|
||||
#define RAMFS_BLOCK_SIZE 4096
|
||||
#define RAMFS_MAX_PATH_LEN 255
|
||||
|
||||
#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;
|
||||
|
||||
typedef struct ramfs_directory {
|
||||
char name[RAMFS_MAX_PATH_LEN];
|
||||
ramfs_file_t* files[RAMFS_MAX_FILES];
|
||||
uint32_t file_count;
|
||||
} ramfs_directory_t;
|
||||
|
||||
|
||||
void ramfs_init();
|
||||
|
||||
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);
|
||||
|
||||
bool ramfs_create_directory(const char* name);
|
||||
bool ramfs_delete_directory(const char* name);
|
||||
|
||||
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();
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user