CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
vfs.h
Go to the documentation of this file.
1
3
30
31#pragma once
32
33#include <cx/fs/file.h>
34#include <cx/fs/fs.h>
35#include <cx/fs/vfsobj.h>
36#include <cx/fs/vfsprovider.h>
37
40typedef struct VFS VFS;
41
44typedef struct VFSFile VFSFile;
45
46CX_C_BEGIN
47
58_At_(*pvfs, _Pre_maybenull_ _Post_null_) void vfsDestroy(VFS** pvfs);
59
68bool vfsUnmount(_Inout_ VFS* vfs, _In_opt_ strref path);
69
70bool _vfsMountProvider(_Inout_ VFS* vfs, _Inout_ ObjInst* provider, _In_opt_ strref path,
71 flags_t flags);
72
91#define vfsMountProvider(vfs, provider, path, ...) \
92 _vfsMountProvider(vfs, objInstBase(provider), path, opt_flags(__VA_ARGS__))
93
94bool _vfsMountFS(_Inout_ VFS* vfs, _In_opt_ strref path, _In_opt_ strref fsroot, flags_t flags);
95
116#define vfsMountFS(vfs, path, fsroot, ...) _vfsMountFS(vfs, path, fsroot, opt_flags(__VA_ARGS__))
117
118bool _vfsMountVFS(_Inout_ VFS* vfs, _In_opt_ strref path, _Inout_ VFS* vfs2,
119 _In_opt_ strref vfs2root, flags_t flags);
120
143#define vfsMountVFS(vfs, path, vfs2, vfs2root, ...) \
144 _vfsMountVFS(vfs, path, vfs2, vfs2root, opt_flags(__VA_ARGS__))
145
153void vfsCurDir(_Inout_ VFS* vfs, _Inout_ string* out);
154
163bool vfsSetCurDir(_Inout_ VFS* vfs, _In_opt_ strref cur);
164
173void vfsAbsolutePath(_Inout_ VFS* vfs, _Inout_ string* out, _In_opt_ strref path);
174
175#define _vfsStatAnno _Success_(return != FS_Nonexistent)
176
186_vfsStatAnno FSPathStat vfsStat(_Inout_ VFS* vfs, _In_opt_ strref path, _Out_opt_ FSStat* stat);
187
193_meta_inline bool vfsExist(_Inout_ VFS* vfs, _In_opt_ strref path)
194{
195 return vfsStat(vfs, path, NULL) != FS_Nonexistent;
196}
197
203_meta_inline bool vfsIsDir(_Inout_ VFS* vfs, _In_opt_ strref path)
204{
205 return vfsStat(vfs, path, NULL) == FS_Directory;
206}
207
213_meta_inline bool vfsIsFile(_Inout_ VFS* vfs, _In_opt_ strref path)
214{
215 return vfsStat(vfs, path, NULL) == FS_File;
216}
217
228bool vfsSetTimes(_Inout_ VFS* vfs, _In_opt_ strref path, int64 modified, int64 accessed);
229
238bool vfsCreateDir(_Inout_ VFS* vfs, _In_opt_ strref path);
239
248bool vfsCreateAll(_Inout_ VFS* vfs, _In_opt_ strref path);
249
257bool vfsRemoveDir(_Inout_ VFS* vfs, _In_opt_ strref path);
258
267bool vfsDelete(_Inout_ VFS* vfs, _In_opt_ strref path);
268
278bool vfsCopy(_Inout_ VFS* vfs, _In_opt_ strref from, _In_opt_ strref to);
279
290bool vfsRename(_Inout_ VFS* vfs, _In_opt_ strref from, _In_opt_ strref to);
291
306bool vfsGetFSPath(_Inout_ string* out, _Inout_ VFS* vfs, _In_opt_ strref path);
307
308typedef struct FSSearchIter FSSearchIter;
309
326bool vfsSearchInit(_Out_ FSSearchIter* iter, _Inout_ VFS* vfs, _In_opt_ strref path,
327 _In_opt_ strref pattern, int typefilter, bool stat);
328
333bool vfsSearchNext(_Inout_ FSSearchIter* iter);
334
341void vfsSearchFinish(_Inout_ FSSearchIter* iter);
342
347_meta_inline bool vfsSearchValid(_In_ FSSearchIter* iter)
348{
349 return iter->_search;
350}
351
364_Ret_opt_valid_ VFSFile* vfsOpen(_Inout_ VFS* vfs, _In_opt_ strref path, flags_t flags);
365
373bool vfsClose(_Pre_opt_valid_ _Post_invalid_ VFSFile* file);
374
385bool vfsRead(_Inout_ VFSFile* file, _Out_writes_bytes_to_(sz, *bytesread) void* buf, size_t sz,
386 _Out_ _Deref_out_range_(0, sz) size_t* bytesread);
387
398bool vfsWrite(_Inout_ VFSFile* file, _In_reads_bytes_(sz) void* buf, size_t sz,
399 _Out_opt_ _Deref_out_range_(0, sz) size_t* byteswritten);
400
410bool vfsWriteString(_Inout_ VFSFile* file, _In_opt_ strref str, _Out_opt_ size_t* byteswritten);
411
416int64 vfsTell(_Inout_ VFSFile* file);
417
426int64 vfsSeek(_Inout_ VFSFile* file, int64 off, FSSeekType seektype);
427
434bool vfsFlush(_Inout_ VFSFile* file);
435
440 // Flags valid for both VFS creation and provider mounting:
441
442 VFS_ReadOnly = 0x00000001,
445
446 VFS_CaseSensitive = 0x00000002,
450
451 VFS_NoCache = 0x00000004,
453
454 // Flags valid only for provider mounting:
455
456 VFS_NewFiles = 0x00000008,
458
459 VFS_AlwaysCOW = 0x00000010,
462
463 VFS_Opaque = 0x00000020,
465};
466
468
469CX_C_END
Low-level file I/O operations.
Platform-specific filesystem operations.
enum FSSeekTypeEnum FSSeekType
enum FSPathStatEnum FSPathStat
@ FS_Directory
Path is a directory.
Definition fs.h:95
@ FS_File
Path is a regular file.
Definition fs.h:96
@ FS_Nonexistent
Path does not exist.
Definition fs.h:94
bool vfsSearchValid(FSSearchIter *iter)
Definition vfs.h:347
bool vfsWrite(VFSFile *file, void *buf, size_t sz, size_t *byteswritten)
void vfsCurDir(VFS *vfs, string *out)
struct VFSFile VFSFile
Definition vfs.h:44
bool vfsSearchInit(FSSearchIter *iter, VFS *vfs, strref path, strref pattern, int typefilter, bool stat)
bool vfsCreateAll(VFS *vfs, strref path)
void vfsSearchFinish(FSSearchIter *iter)
bool vfsDelete(VFS *vfs, strref path)
VFSFlags
Definition vfs.h:439
FSPathStat vfsStat(VFS *vfs, strref path, FSStat *stat)
bool vfsIsDir(VFS *vfs, strref path)
Definition vfs.h:203
bool vfsSearchNext(FSSearchIter *iter)
bool vfsFlush(VFSFile *file)
bool vfsRemoveDir(VFS *vfs, strref path)
void vfsDestroy(VFS **pvfs)
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
bool vfsUnmount(VFS *vfs, strref path)
bool vfsWriteString(VFSFile *file, strref str, size_t *byteswritten)
bool vfsExist(VFS *vfs, strref path)
Definition vfs.h:193
void vfsAbsolutePath(VFS *vfs, string *out, strref path)
int64 vfsSeek(VFSFile *file, int64 off, FSSeekType seektype)
bool vfsCopy(VFS *vfs, strref from, strref to)
bool vfsCreateDir(VFS *vfs, strref path)
bool vfsRead(VFSFile *file, void *buf, size_t sz, size_t *bytesread)
bool vfsGetFSPath(string *out, VFS *vfs, strref path)
bool vfsClose(VFSFile *file)
bool vfsSetTimes(VFS *vfs, strref path, int64 modified, int64 accessed)
bool vfsSetCurDir(VFS *vfs, strref cur)
bool vfsRename(VFS *vfs, strref from, strref to)
bool vfsIsFile(VFS *vfs, strref path)
Definition vfs.h:213
int64 vfsTell(VFSFile *file)
@ VFS_CaseSensitive
Definition vfs.h:446
@ VFS_NoCache
Definition vfs.h:451
@ VFS_NewFiles
Definition vfs.h:456
@ VFS_AlwaysCOW
Definition vfs.h:459
@ VFS_Opaque
Definition vfs.h:463
@ VFS_ReadOnly
Definition vfs.h:442
FSStat stat
File metadata (only valid if stat=true in fsSearchInit)
Definition fs.h:239
Definition fs.h:103
VFS Object.
Definition vfsobj.h:25
VFS object definitions.