80 lines
2.3 KiB
C
80 lines
2.3 KiB
C
#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
|