summaryrefslogtreecommitdiff
path: root/arm9/lib/include/FS_file.h
blob: 4871b660ab50a075d91447786355d74c3a0f50aa (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
#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

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;

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;
    struct FSArchive *arc;
    u32 stat;
    FSCommandType command;
    FSResult error;
    OSThreadQueue queue[1];
    union {
        struct
        {
            u32 own_id;
            u32 top;
            u32 bottom;
            u32 pos;
        } file;
        struct
        {
            FSDirPos pos;
            u32 parent;
        } dir;
    } prop;

    union {
        FSReadFileInfo readfile;
        FSWriteFileInfo writefile;

        FSSeekDirInfo seekdir;
        FSReadDirInfo readdir;
        FSFindPathInfo findpath;
        FSGetPathInfo getpath;
        FSOpenFileFastInfo openfilefast;
        FSOpenFileDirectInfo openfiledirect;
        FSCloseFileInfo closefile;
    } arg;
}
FSFile;

u32 FS_SetDefaultDMA(u32 dma_no); // returns the previous selection
void FS_InitFile(FSFile * p_file);
BOOL FS_WaitAsync(FSFile * p_file);

#endif //NITRO_FS_FILE_H_