picox  0.1
xfscore.h
[詳解]
1 
14 /*
15  * License: MIT license
16  * Copyright (c) <2016> <MaskedW [maskedw00@gmail.com]>
17  *
18  * Permission is hereby granted, free of charge, to any person
19  * obtaining a copy of this software and associated documentation
20  * files (the "Software"), to deal in the Software without
21  * restriction, including without limitation the rights to use, copy,
22  * modify, merge, publish, distribute, sublicense, and/or sell copies
23  * of the Software, and to permit persons to whom the Software is
24  * furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be
27  * included in all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36  * SOFTWARE.
37  */
38 
39 
40 #ifndef maskedw_filesystem_xfscore_h_
41 #define maskedw_filesystem_xfscore_h_
42 
43 
44 #include <picox/core/xcore.h>
46 
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif /* __cplusplus */
51 
52 
61 /* 前方宣言 */
62 struct XVirtualFs;
63 typedef struct XVirtualFs XVirtualFs;
64 
65 
70 typedef struct
71 {
73  void* m_fs;
74  XVirtualFs* m_vfs;
75 } XFile;
76 
77 
82 typedef struct
83 {
85  void* m_fs;
86  XVirtualFs* m_vfs;
87 } XDir;
88 
89 
92 typedef struct
93 {
98 
101 
104 } XStat;
105 
106 
109 typedef struct
110 {
114  char name[X_NAME_MAX];
115 } XDirEnt;
116 
117 
124 typedef bool (*XFsTreeWalker)(void* userptr, const char* path, const XStat* statbuf, const XDirEnt* dirent);
125 
126 
134 #define XSTAT_MODE_TYPEMASK (0x0F)
135 #define XSTAT_MODE_REGULAR (0)
136 #define XSTAT_MODE_DIRECTORY (1)
137 
140 #define XSTAT_IS_REGULAR(mode) (((mode) & XSTAT_MODE_TYPEMASK) == XSTAT_MODE_REGULAR)
141 
142 
145 #define XSTAT_IS_DIRECTORY(mode) (((mode) & XSTAT_MODE_TYPEMASK) == XSTAT_MODE_DIRECTORY)
146 
147 
162 typedef XError (*XVirtualFsOpenFunc)(void* fs, const char* path, XOpenMode mode, XFile** o_fp);
163 typedef XError (*XVirtualFsCloseFunc)(XFile* fp);
164 typedef XError (*XVirtualFsReadFunc)(XFile* fp, void* dst, size_t size, size_t* nread);
165 typedef XError (*XVirtualFsWriteFunc)(XFile* fp, const void* src, size_t size, size_t* nwritten);
166 typedef XError (*XVirtualFsSeekFunc)(XFile* fp, XOffset pos, XSeekMode whence);
167 typedef XError (*XVirtualFsTellFunc)(XFile* fp, XSize* pos);
168 typedef XError (*XVirtualFsFlushFunc)(XFile* fp);
169 typedef XError (*XVirtualFsMkdirFunc)(void* fs, const char* path);
170 typedef XError (*XVirtualFsOpendirFunc)(void* fs, const char* path, XDir** o_dir);
171 typedef XError (*XVirtualFsReaddirFunc)(XDir* dir, XDirEnt* dirent, XDirEnt** result);
172 typedef XError (*XVirtualFsClosedirFunc)(XDir* dir);
173 typedef XError (*XVirtualFsChdirFunc)(void* fs, const char* path);
174 typedef XError (*XVirtualFsGetcwdFunc)(void* fs, char* buf, size_t size);
175 typedef XError (*XVirtualFsRemoveFunc)(void* fs, const char* path);
176 typedef XError (*XVirtualFsRenameFunc)(void* fs, const char* oldpath, const char* newpath);
177 typedef XError (*XVirtualFsStatFunc)(void* fs, const char* path, XStat* statbuf);
178 typedef XError (*XVirtualFsUtimeFunc)(void* fs, const char* path, XTime time);
179 
180 
183 struct XVirtualFs
184 {
186  void* m_realfs;
187  XVirtualFsOpenFunc m_open_func;
188  XVirtualFsCloseFunc m_close_func;
189  XVirtualFsReadFunc m_read_func;
190  XVirtualFsWriteFunc m_write_func;
191  XVirtualFsSeekFunc m_seek_func;
192  XVirtualFsTellFunc m_tell_func;
193  XVirtualFsFlushFunc m_flush_func;
194  XVirtualFsMkdirFunc m_mkdir_func;
195  XVirtualFsOpendirFunc m_opendir_func;
196  XVirtualFsReaddirFunc m_readdir_func;
197  XVirtualFsClosedirFunc m_closedir_func;
198  XVirtualFsChdirFunc m_chdir_func;
199  XVirtualFsGetcwdFunc m_getcwd_func;
200  XVirtualFsRemoveFunc m_remove_func;
201  XVirtualFsRenameFunc m_rename_func;
202  XVirtualFsStatFunc m_stat_func;
203  XVirtualFsUtimeFunc m_utime_func;
204 };
205 
206 
213 void xvfs_init(XVirtualFs* vfs);
214 
215 
225 #ifdef __cplusplus
226 }
227 #endif /* __cplusplus */
228 
229 
230 #endif /* maskedw_filesystem_xfscore_h_ */
Definition: xfscore.h:182
uint32_t XTime
time_tの代替をするシステム時刻を格納するための型です
Definition: xtime.h:80
XOpenMode
ファイルオープン等のモードです
Definition: xstddef.h:435
XMode mode
ファイルの種別等、属性情報
Definition: xfscore.h:103
XError
errnoの代替として使用する共通のエラーコードを表す列挙型です
Definition: xstddef.h:367
ディレクトリエントリ情報を格納する構造体です
Definition: xfscore.h:109
void xvfs_init(XVirtualFs *vfs)
Definition: xvfs.c:89
bool(* XFsTreeWalker)(void *userptr, const char *path, const XStat *statbuf, const XDirEnt *dirent)
ディレクトリ探索関数が呼び出すコールバック関数型です
Definition: xfscore.h:124
XTime mtime
ファイルのタイムスタンプ
Definition: xfscore.h:97
uint32_t XSize
何らかの大きさを表すのに十分なサイズを備えた符号なし整数型です
Definition: xstddef.h:251
ファイル操作のハンドル構造体です
Definition: xfscore.h:70
ファイルパス操作ユーティリティ定義
XSize size
ファイルのバイト数
Definition: xfscore.h:100
int32_t XOffset
何らかのオフセットを表すのに十分な大きさをもった符号あり整数型です
Definition: xstddef.h:261
uint32_t XMode
何らかのビットフラグを格納することを意図した型です
Definition: xstddef.h:287
XSeekMode
シークの起点を指定する列挙型です
Definition: xstddef.h:340
#define X_NAME_MAX
Definition: xstddef.h:491
ディレクトリ操作のハンドル構造体です
Definition: xfscore.h:82
ファイル情報を格納する構造体です
Definition: xfscore.h:92