summaryrefslogtreecommitdiff
path: root/arm9/lib/NitroSDK/include/FS_file.h
blob: f870ad2a93d412a87d7c784ee988a38336a4e511 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#ifndef NITRO_FS_FILE_H_
#define NITRO_FS_FILE_H_

#include "nitro.h"

#include "FS_archive.h"

#define FS_FILE_STATUS_BUSY      0x00000001
#define FS_FILE_STATUS_CANCEL    0x00000002
#define FS_FILE_STATUS_SYNC      0x00000004
#define FS_FILE_STATUS_ASYNC     0x00000008
#define FS_FILE_STATUS_IS_FILE   0x00000010
#define FS_FILE_STATUS_IS_DIR    0x00000020
#define FS_FILE_STATUS_OPERATING 0x00000040

#define FS_FILE_NAME_MAX 127

typedef enum FSSeekFileMode
{
    FS_SEEK_SET = 0,
    FS_SEEK_CUR,
    FS_SEEK_END
} FSSeekFileMode;

struct FSFile;

#define FS_DMA_NOT_USE ((u32)~0)

typedef struct FSDirPos
{
    struct FSArchive *arc;
    u16 own_id;
    u16 index;
    u32 pos;
}
FSDirPos; // size = 0xC

typedef struct FSFileID
{
    struct FSArchive *arc;
    u32 file_id;
}
FSFileID;

typedef struct
{
    union
    {
        FSFileID file_id;
        FSDirPos dir_id;
    };
    u32 is_directory;
    u32 name_len;
    char name[128];
}
FSDirEntry;


typedef struct
{
    FSDirPos pos;
}
FSSeekDirInfo;


typedef struct
{
    FSDirEntry *p_entry;
    BOOL skip_string;
}
FSReadDirInfo;


typedef struct
{
    FSDirPos pos;
    const char *path;
    BOOL find_directory;
    union
    {
        FSFileID *file;
        FSDirPos *dir;
    }
    result;
}
FSFindPathInfo;


typedef struct
{
    u8 *buf;
    u32 buf_len;
    u16 total_len;
    u16 dir_id;
}
FSGetPathInfo;


typedef struct
{
    FSFileID id;
}
FSOpenFileFastInfo;


typedef struct
{
    u32 top;
    u32 bottom;
    u32 index;
}
FSOpenFileDirectInfo;


typedef struct
{
    u32 reserved;
}
FSCloseFileInfo;


typedef struct
{
    void *dst;
    u32 len_org;
    u32 len;
}
FSReadFileInfo;


typedef struct
{
    const void *src;
    u32 len_org;
    u32 len;
}
FSWriteFileInfo;

typedef struct FSFile
{
    FSFileLink link;                         // 0x00
    struct FSArchive *arc;                   // 0x08
    u32 stat;                                // 0xC
    FSCommandType command;                   // 0x10
    FSResult error;                          // 0x14
    OSThreadQueue queue[1];                  // 0x18
    union {
        struct
        {
            u32 own_id;                      // 0x20
            u32 top;                         // 0x24
            u32 bottom;                      // 0x28
            u32 pos;                         // 0x2C
        } file;
        struct
        {
            FSDirPos pos;                    // 0x20
            u32 parent;                      // 0x2C
        } dir;
    } prop;                                  // 0x20

    union {
        FSReadFileInfo readfile;             // 0x30
        FSWriteFileInfo writefile;           // 0x30

        FSSeekDirInfo seekdir;               // 0x30
        FSReadDirInfo readdir;               // 0x30
        FSFindPathInfo findpath;             // 0x30
        FSGetPathInfo getpath;               // 0x30
        FSOpenFileFastInfo openfilefast;     // 0x30
        FSOpenFileDirectInfo openfiledirect; // 0x30
        FSCloseFileInfo closefile;           // 0x30
    } arg;                                   // 0x30
}
FSFile; // size = 0x50

void FS_Init(u32 default_dma_no);
BOOL FS_IsAvailable(void);
void FS_InitFile(FSFile * p_file);
int FSi_ReadFileCore(FSFile * p_file, void * dst, s32 len, BOOL async);
BOOL FS_ConvertPathToFileID(FSFileID * p_file_id, const char * path);
BOOL FS_OpenFileDirect(FSFile * p_file, FSArchive * p_arc, u32 image_top, u32 image_bottom, u32 file_index);
BOOL FS_OpenFileFast(FSFile * p_file, FSFileID file_id);
BOOL FS_OpenFile(FSFile * p_file, const char * path);
BOOL FS_CloseFile(FSFile * p_file);
BOOL FS_WaitAsync(FSFile * p_file);
int FS_ReadFileAsync(FSFile * p_file, void * dst, s32 len);
int FS_ReadFile(FSFile * p_file, void * dst, s32 len);
BOOL FS_SeekFile(FSFile * p_file, s32 offset, FSSeekFileMode origin);
BOOL FS_ChangeDir(const char * path);

static inline u32 const FS_GetFileImageTop(volatile const FSFile * p_file) {
    return p_file->prop.file.top;
}

static inline u32 const FS_GetLength(volatile const FSFile * p_file)
{
    return p_file->prop.file.bottom - p_file->prop.file.top;
}

static inline BOOL FS_IsCanceling(volatile const FSFile * p_file)
{
    return (p_file->stat & FS_FILE_STATUS_CANCEL) ? TRUE : FALSE;
}

static inline BOOL FS_IsFileSyncMode(volatile const FSFile * p_file)
{
    return (p_file->stat & FS_FILE_STATUS_SYNC) ? TRUE : FALSE;
}

static inline BOOL FS_IsBusy(volatile const FSFile * p_file)
{
    return p_file->stat & FS_FILE_STATUS_BUSY ? TRUE : FALSE;
}

static inline BOOL FS_IsSucceeded(volatile const FSFile * p_file)
{
    return (p_file->error == FS_RESULT_SUCCESS) ? TRUE : FALSE;
}

static inline BOOL FS_IsDir(volatile const FSFile * p_file)
{
    return (p_file->stat & FS_FILE_STATUS_IS_DIR) ? TRUE : FALSE;
}

#endif //NITRO_FS_FILE_H_