summaryrefslogtreecommitdiff
path: root/arm9/source/devices/file.h
blob: f295e89bbb12781bf5fa0ed2a51a830722b9d949 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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
        bool at_root;         // current entry is the root directory
    } FileDevice;

    void init_filesystem();
    bool filesystem_enabled();

    void create_parents(u8 *path);

    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