From 4f8805869c469cb1b3685e03c3ea34d7654b5cb7 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 22 Nov 2024 16:04:20 +1300 Subject: Implement file device There is still a small amount of work to be done on the file device: - Read file size only when requested - Hide '.' and '..' directories - Resize files --- arm9/source/devices/file.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 arm9/source/devices/file.h (limited to 'arm9/source/devices/file.h') diff --git a/arm9/source/devices/file.h b/arm9/source/devices/file.h new file mode 100644 index 0000000..86ca039 --- /dev/null +++ b/arm9/source/devices/file.h @@ -0,0 +1,52 @@ +#include +#include "../types/pathbuf.h" + +// #include +// #include +// #include +// #include + +#ifndef FILE_H_ + #define FILE_H_ + + typedef struct { + bool open; // true if an entry is open + bool success; // true if the previous operation was successful + bool is_dir; // true if the open entry is a directory + bool child_is_dir; // true if the selected child is a directory + PathBuf entry; // write buffer for entry port + PathBuf action; // write buffer for action port + PathBuf path; // path of the open entry + PathBuf child_path; // path of the selected child + u32 pointer; // pointer in the open entry, whether dir or file + u32 length; // length of the open entry, whether dir or file + u32 pointer_write; // write cache for pointer + u32 length_write; // write cache for length + + DIR *dir; // structure pointing to current directory + FILE *file; // opaque ID referencing the open file + + FILE *tmpfile; // to open file and keep existing file open + struct dirent *child; // currently-selected directory child information + u32 dir_i; // index of next child to read from dir + } FileDevice; + + void init_filesystem(); + bool filesystem_enabled(); + + void fs_push_entry(FileDevice *fs, u8 byte); + void fs_push_action(FileDevice *fs, u8 byte); + bool fs_push_byte(PathBuf *buf, u8 byte); + + u8 fs_read_byte(FileDevice *fs); + void fs_write_byte(FileDevice *fs, u8 byte); + + void fs_ascend(FileDevice *fs); + void fs_descend(FileDevice *fs); + + void fs_seek(FileDevice *fs); + void fs_resize(FileDevice *fs); + + void fs_select_child(FileDevice *fs, u32 pointer); + +#endif -- cgit v1.2.3-70-g09d2