summaryrefslogtreecommitdiff
path: root/arm9/source/devices/file.h
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-11-22 16:04:20 +1300
committerBen Bridle <ben@derelict.engineering>2024-11-22 16:15:11 +1300
commit4f8805869c469cb1b3685e03c3ea34d7654b5cb7 (patch)
treeefe555c1064b7a69738e3cf7fd107af7bdc0155f /arm9/source/devices/file.h
parentfcbc3968bd95e4d19b37d9fa4bca51b1db8596ff (diff)
downloadbedrock-nds-4f8805869c469cb1b3685e03c3ea34d7654b5cb7.zip
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
Diffstat (limited to 'arm9/source/devices/file.h')
-rw-r--r--arm9/source/devices/file.h52
1 files changed, 52 insertions, 0 deletions
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 <dirent.h>
+#include "../types/pathbuf.h"
+
+// #include <stdio.h>
+// #include <dirent.h>
+// #include <string.h>
+// #include <sys/stat.h>
+
+#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