CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
vfs_private.h
1#pragma once
2
3#include "vfs.h"
4#include "fs_private.h"
5#include "cx/container.h"
6#include "cx/string.h"
7
8typedef struct VFSFile {
9 VFS *vfs;
10
11 ObjInst *fileprov; // VFSFileProvider
12 VFSFileProvider *fileprovif;
13
14 // for copy-on-write files
15 ObjInst *cowprov; // VFSProvider
16 string cowpath; // absolute path to COW file (for cache invalidation)
17 string cowrpath; // relative path for COW file for provider
18} VFSFile;
19
20typedef struct VFSDirEnt {
21 string name;
22 int type;
23 FSStat stat;
24} VFSDirEnt;
25saDeclare(VFSDirEnt);
26
27typedef struct VFSSearch {
28 VFS *vfs;
29
30 sa_VFSDirEnt ents;
31 int32 idx;
32} VFSSearch;
33
34// object-like structures for VFS
35// these use custom type ops instead of the object framework so that
36// they can be tightly packed into arrays/hashtables
37
38typedef struct VFSMount VFSMount;
39typedef struct VFSCacheEnt {
40 VFSMount *mount; // which VFS mount this file belongs to
41 string origpath; // original path (relative to provider)
42} VFSCacheEnt;
43VFSCacheEnt *_vfsCacheEntCreate(VFSMount *m, strref opath);
44extern STypeOps VFSCacheEnt_ops;
45
46typedef struct VFSDir VFSDir;
47typedef struct VFSDir {
48 string name;
49 VFSDir *parent;
50 sa_VFSMount mounts; // VFS providers mounted in this directory
51
52 hashtable subdirs; // hashtable of string/VFSDir*
53
54 // CACHE
55 hashtable files; // hashtable of string/VFSCacheEnt*
56 uint64 touched; // timestamp of last use
57 bool cache; // only exists to cache directory entries, can be discarded
58} VFSDir;
59_Ret_valid_
60VFSDir *_vfsDirCreate(_Inout_ VFS *vfs, _In_opt_ VFSDir *parent);
61extern STypeOps VFSDir_ops;
62
63// gets (and creates) path in VFS cache
64// must be called with vfslock read (or write) lock held!
65_Ret_valid_
66_When_(!writelockheld, _Requires_shared_lock_held_(vfs->vfslock))
67VFSDir *_vfsGetDir(_Inout_ VFS *vfs, _In_opt_ strref path, bool isfile, bool cache, bool writelockheld);
68// gets a file from VFS cache if it exists
69// must be called with vfslock read (or write) lock held!
70_Ret_valid_
71_When_(!writelockheld, _Requires_shared_lock_held_(vfs->vfslock))
72VFSCacheEnt *_vfsGetFile(_Inout_ VFS *vfs, _In_opt_ strref path, bool writelockheld);
73// finds a suitable provider for a particular file
74enum VFS_FIND_PROVIDER_ENUM {
75 VFS_FindWriteFile = 0x0100,
76 VFS_FindCreate = 0x0200,
77 VFS_FindDelete = 0x0400,
78 VFS_FindCache = 0x1000,
79};
80_Ret_opt_valid_
81VFSMount *_vfsFindMount(_Inout_ VFS *vfs, _Inout_ string *rpath, _In_opt_ strref path, _Out_opt_ VFSMount **cowmount, _Inout_opt_ string *cowrpath, flags_t flags);
82void _vfsInvalidateCache(_Inout_ VFS *vfs, _In_opt_ strref path);
83void _vfsInvalidateRecursive(_Inout_ VFS *vfs, _In_ VFSDir *dir, bool havelock);
84void _vfsAbsPath(_Inout_ VFS *vfs, _Inout_ string *out, _In_opt_ strref path);
85
86_Requires_shared_lock_held_(vfs->vfslock)
87int _vfsFindCIHelper(_Inout_ VFS *vfs, _In_ VFSDir *vdir, _Inout_ string *out, _In_ sa_string components, _Inout_ VFSMount *mount, _Inout_ VFSProvider *provif);
88
89bool _vfsAddPlatformSpecificMounts(_Inout_ VFS *vfs);
90bool _vfsIsPlatformCaseSensitive();
Generic type-safe containers with runtime type system integration.
#define saDeclare(name)
Definition sarray.h:91
struct VFSFile VFSFile
Definition vfs.h:44
Copy-on-write strings with automatic memory management and rope optimization.
Definition fs.h:103
VFS Object.
Definition vfsobj.h:25
Virtual Filesystem (VFS)