CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
vfsobj.h
Go to the documentation of this file.
1
6
7#pragma once
8// This header file is auto-generated!
9// Do not make changes to this file or they will be overwritten.
10// clang-format off
11#include <cx/obj.h>
12#include <cx/struct.h>
13#include <cx/thread/atomic.h>
14#include <cx/thread/rwlock.h>
15
16CX_C_BEGIN
17
18typedef struct VFSDir VFSDir;
19typedef struct VFS VFS;
20typedef struct VFS_WeakRef VFS_WeakRef;
21typedef struct VFSMount VFSMount;
22typedef struct VFSMount_WeakRef VFSMount_WeakRef;
24saDeclarePtr(VFS_WeakRef);
25#define _sti_VFS _sti_object
26#define SType_VFS VFS*
27#define STStorageType_VFS VFS*
28#define STypeArg_VFS(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(VFS, val))
29#define STypeArgPtr_VFS(type, val) (stgeneric*)objInstCheckClassPtr(VFS, val)
30#define STypeCheckedArg_VFS(type, val) stType(type), stArg(type, val)
31#define STypeCheckedPtrArg_VFS(type, val) stType(type), stArgPtr(type, val)
32saDeclarePtr(VFSMount);
33saDeclarePtr(VFSMount_WeakRef);
34#define _sti_VFSMount _sti_object
35#define SType_VFSMount VFSMount*
36#define STStorageType_VFSMount VFSMount*
37#define STypeArg_VFSMount(type, val) stgeneric(object, (ObjInst*)objInstCheckClass(VFSMount, val))
38#define STypeArgPtr_VFSMount(type, val) (stgeneric*)objInstCheckClassPtr(VFSMount, val)
39#define STypeCheckedArg_VFSMount(type, val) stType(type), stArg(type, val)
40#define STypeCheckedPtrArg_VFSMount(type, val) stType(type), stArgPtr(type, val)
41
43typedef struct VFSDirCache {
44 atomic(int64) lastprune;
45 atomic(uint32) dircount;
46 uint32 maxdirs;
47 int64 ttl;
49
51typedef struct VFS {
52 union {
53 ObjIface* _;
54 void* _is_VFS;
55 void* _is_ObjInst;
56 };
57 ObjClassInfo* _clsinfo;
58 atomic(uintptr) _ref;
59 atomic(ptr) _weakref;
60
61 VFSDir* root;
62 hashtable namespaces;
63 string curdir;
64 // Two locks, and vfsdlock is always the outer one: a thread may take vfsdlock and then
65 // vfslock, never the reverse.
66 // // vfslock guards additions to the directory cache and the curdir string. vfsdlock guards
67 // operations that destroy VFSDir entries or remove mounts. The invariant that makes that
68 // split work is stronger than it looks and is not enforced anywhere: every reader that
69 // walks the directory tree takes vfsdlock for read first, so holding vfsdlock for write is
70 // by itself exclusive against all of them. That is why the mount and unmount paths mutate
71 // the subdirs and files hashtables with vfslock never taken at all. A new code path that
72 // takes only vfslock and then touches the tree breaks this.
73 RWLock vfslock;
74 RWLock vfsdlock;
78 uint32 mountgen;
79 uint32 flags;
81} VFS;
82extern ObjClassInfo VFS_clsinfo;
83#define VFS(inst) objInstCheckClass(VFS, inst)
84#define VFSNone ((VFS*)NULL)
85
86typedef struct VFS_WeakRef {
87 union {
88 ObjInst* _inst;
89 void* _is_VFS_WeakRef;
90 void* _is_ObjInst_WeakRef;
91 };
92 atomic(uintptr) _ref;
93 RWLock _lock;
94} VFS_WeakRef;
95#define VFS_WeakRef(inst) objWeakRefCheckClass(VFS, inst)
96
97_objfactory_guaranteed VFS* VFS_create(uint32 flags);
115#define vfsCreate(flags) VFS_create(flags)
116
117_objfactory_check VFS* VFS_createFromFS();
144#define vfsCreateFromFS() VFS_createFromFS()
145
146
147typedef struct VFSMount {
148 union {
149 ObjIface* _;
150 void* _is_VFSMount;
151 void* _is_ObjInst;
152 };
153 ObjClassInfo* _clsinfo;
154 atomic(uintptr) _ref;
155 atomic(ptr) _weakref;
156
157 ObjInst* provider;
158 uint32 flags;
159} VFSMount;
160extern ObjClassInfo VFSMount_clsinfo;
161#define VFSMount(inst) objInstCheckClass(VFSMount, inst)
162#define VFSMountNone ((VFSMount*)NULL)
163
164typedef struct VFSMount_WeakRef {
165 union {
166 ObjInst* _inst;
167 void* _is_VFSMount_WeakRef;
168 void* _is_ObjInst_WeakRef;
169 };
170 atomic(uintptr) _ref;
171 RWLock _lock;
172} VFSMount_WeakRef;
173#define VFSMount_WeakRef(inst) objWeakRefCheckClass(VFSMount, inst)
174
175_objfactory_guaranteed VFSMount* VFSMount_create(ObjInst* provider, uint32 flags);
176// VFSMount* vfsmountCreate(ObjInst* provider, uint32 flags);
177#define vfsmountCreate(provider, flags) VFSMount_create(ObjInst(provider), flags)
178
179
180CX_C_END
Atomic operations.
#define saDeclarePtr(name)
Definition sarray.h:100
#define _objfactory_check
Definition objimpl.h:112
#define _objfactory_guaranteed
Definition objimpl.h:106
CX Struct System - Introspectable, serializable POD structures in C.
CX Object System - Object-oriented programming in C.
Reader-writer lock synchronization primitive.
Directory cache accounting. See vfsSetCacheLimits().
Definition vfsobj.h:43
uint32 maxdirs
node count above which a prune is allowed to run
Definition vfsobj.h:46
atomic(uint32) dircount
VFSDir nodes currently in the tree.
atomic(int64) lastprune
clockTimer() when the last prune ran
int64 ttl
how long an unused directory survives, in microseconds
Definition vfsobj.h:47
VFS Object.
Definition vfsobj.h:51
VFSDir * root
Root for namespaceless paths.
Definition vfsobj.h:61
string curdir
Current working directory of the VFS.
Definition vfsobj.h:63
hashtable namespaces
Hashtable of string/VFSDir.
Definition vfsobj.h:62
uint32 mountgen
Definition vfsobj.h:78
VFSDirCache dcache
directory cache size accounting
Definition vfsobj.h:80