7 * \brief Acess VFS Layer
9 * The Acess Virtual File System (VFS) provides abstraction of multiple
10 * physical filesystems, network storage and devices (both hardware and
11 * virtual) to the user.
13 * The core of the VFS is the concept of a \ref tVFS_Node "VFS Node".
14 * A VFS Node represents a "file" in the VFS tree, this can be any sort
15 * of file (an ordinary file, a directory, a symbolic link or a device)
16 * depending on the bits set in the \ref tVFS_Node.Flags Flags field.
17 * - For more information see "VFS Node Flags"
25 * \brief Thread list datatype for VFS_Select
27 typedef struct sVFS_SelectList tVFS_SelectList;
30 * \name tVFS_Node Flags
31 * \brief Flag values for tVFS_Node.Flags
34 //! \todo Is this still needed
35 #define VFS_FFLAG_READONLY 0x01 //!< Readonly File
37 * \brief Directory Flag
39 * This flag marks the tVFS_Node as describing a directory, and says
40 * that the tVFS_Node.FindDir, tVFS_Node.ReadDir, tVFS_Node.MkNod and
41 * tVFS_Node.Relink function pointers are valid.
42 * For a directory the tVFS_Node.Size field contains the number of files
43 * within the directory, or -1 for undetermined.
45 #define VFS_FFLAG_DIRECTORY 0x02
47 * \brief Symbolic Link Flag
49 * Marks a file as a symbolic link
51 #define VFS_FFLAG_SYMLINK 0x04
53 * \brief Set User ID Flag
55 * Allows an executable file to change it's executing user to the file's
57 * In the case of a directory, it means that all immediate children will
58 * inherit the UID of the parent.
60 #define VFS_FFLAG_SETUID 0x08
62 * \brief Set Group ID Flag
64 * Allows an executable file to change it's executing group to the file's
66 * In the case of a directory, it means that all immediate children will
67 * inherit the GID of the parent.
69 #define VFS_FFLAG_SETGID 0x10
72 * \brief "Don't do Write-Back" Flag
74 * Stops the VFS from calling tVFS_Node.Write on dirty pages when a region
75 * is unmapped. Nice for read-only files and memory-only files (or
76 * pseudo-readonly filesystems)
78 #define VFS_FFLAG_NOWRITEBACK
84 * \brief Represents a node (file or directory) in the VFS tree
86 * This structure provides the VFS with the functions required to read/write
87 * the file (or directory) that it represents.
89 typedef struct sVFS_Node
93 * \brief Fields used by the driver to identify what data this node
97 Uint64 Inode; //!< Inode ID (Essentially another ImplInt)
98 Uint ImplInt; //!< Implementation Usable Integer
99 void *ImplPtr; //!< Implementation Usable Pointer
106 * \brief Stores the misc information about the node
109 int ReferenceCount; //!< Number of times the node is used
111 Uint64 Size; //!< File Size
113 Uint32 Flags; //!< File Flags
116 * \brief Pointer to cached data (FS Specific)
117 * \note The Inode_* functions will free when the node is uncached
124 * \note Provided for the Filesystem driver's use
136 Sint64 ATime; //!< Last Accessed Time
137 Sint64 MTime; //!< Last Modified Time
138 Sint64 CTime; //!< Creation Time
144 * \name Access control
147 tUID UID; //!< ID of Owning User
148 tGID GID; //!< ID of Owning Group
150 int NumACLs; //!< Number of ACL entries
151 tVFS_ACL *ACLs; //!< Access Controll List pointer
157 * \name VFS_Select() fields
161 tVFS_SelectList *ReadThreads; //!< Threads waiting to read
163 tVFS_SelectList *WriteThreads; //!< Threads waiting to write
165 tVFS_SelectList *ErrorThreads; //!< Threads waiting for an error
171 * \name Common Functions
172 * \brief Functions that are used no matter the value of .Flags
176 * \brief Reference the node
177 * \param Node Pointer to this node
179 void (*Reference)(struct sVFS_Node *Node);
181 * \brief Close (dereference) the node
182 * \param Node Pointer to this node
184 * Usually .Close is used to write any changes to the node back to
185 * the persistent storage.
187 void (*Close)(struct sVFS_Node *Node);
190 * \brief Send an IO Control
191 * \param Node Pointer to this node
192 * \param Id IOCtl call number
193 * \param Data Pointer to data to pass to the driver
194 * \return Implementation defined
196 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
203 * \name Buffer Functions
204 * \brief Functions for accessing a buffer-type file (normal file or
210 * \brief Read from the file
211 * \param Node Pointer to this node
212 * \param Offset Byte offset in the file
213 * \param Length Number of bytes to read
214 * \param Buffer Destination for read data
215 * \return Number of bytes read
217 Uint64 (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
219 * \brief Write to the file
220 * \param Node Pointer to this node
221 * \param Offset Byte offser in the file
222 * \param Length Number of bytes to write
223 * \param Buffer Source of written data
224 * \return Number of bytes read
226 Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
229 * \brief Map a region of a file into memory
230 * \param Node Pointer to this node
231 * \param Offset Start of the region (page aligned)
232 * \param Length Length of the region (page aligned)
233 * \param Dest Location to which to map
234 * \return Boolean Failure
235 * \note If NULL, the VFS implements it using .Read
237 int (*MMap)(struct sVFS_Node *Node, Uint64 Offset, int Length, void *Dest);
244 * \name Directory Functions
248 * \brief Find an directory entry by name
249 * \param Node Pointer to this node
250 * \param Name Name of the file wanted
251 * \return Pointer to the requested node or NULL if it cannot be found
252 * \note The node returned must be accessable until ::tVFS_Node.Close
253 * is called and ReferenceCount reaches zero.
255 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, const char *Name);
258 * \brief Read from a directory
259 * \param Node Pointer to this node
260 * \param Pos Offset in the directory
261 * \return Pointer to the name of the item on the heap (will be freed
262 * by the caller). If the directory end has been reached, NULL
264 * If an item is required to be skipped either &::NULLNode,
265 * ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
267 char *(*ReadDir)(struct sVFS_Node *Node, int Pos);
270 * \brief Create a node in a directory
271 * \param Node Pointer to this node
272 * \param Name Name of the new child
273 * \param Flags Flags to apply to the new child (directory or symlink)
274 * \return Zero on Success, non-zero on error (see errno.h)
276 int (*MkNod)(struct sVFS_Node *Node, const char *Name, Uint Flags);
279 * \brief Relink (Rename/Remove) a file/directory
280 * \param Node Pointer to this node
281 * \param OldName Name of the item to move/delete
282 * \param NewName New name (or NULL if unlinking is wanted)
283 * \return Zero on Success, non-zero on error (see errno.h)
285 int (*Relink)(struct sVFS_Node *Node, const char *OldName, const char *NewName);
288 * \brief Link a node to a name
289 * \param Node Pointer to this node (directory)
290 * \param Child Node to create a new link to
291 * \param NewName Name for the new link
292 * \return Zeron on success, non-zero on error (see errno.h)
294 int (*Link)(struct sVFS_Node *Node, struct sVFS_Node *Child, const char *NewName);
302 * \brief VFS Driver (Filesystem) Definition
304 typedef struct sVFS_Driver
306 //! \brief Unique Identifier for this filesystem type
308 //! \brief Flags applying to this driver
311 //! \brief Callback to mount a device
312 tVFS_Node *(*InitDevice)(const char *Device, const char **Options);
313 //! \brief Callback to unmount a device
314 void (*Unmount)(tVFS_Node *Node);
315 //! \brief Used internally (next driver in the chain)
316 struct sVFS_Driver *Next;
320 //! \brief Maximum number of elements that can be skipped in one return
321 #define VFS_MAXSKIP ((void*)1024)
322 //! \brief Skip a single entry in readdir
323 #define VFS_SKIP ((void*)1)
324 //! \brief Skip \a n entries in readdir
325 #define VFS_SKIPN(n) ((void*)(n))
327 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
330 * \brief Simple ACLs to aid writing drivers
333 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
334 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
335 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
336 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
343 * \fn int VFS_AddDriver(tVFS_Driver *Info)
344 * \brief Registers the driver with the DevFS layer
345 * \param Info Driver information structure
347 extern int VFS_AddDriver(tVFS_Driver *Info);
349 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
350 * \brief Get the information structure of a driver given its name
351 * \param Name Name of filesystem driver to find
353 extern tVFS_Driver *VFS_GetFSByName(const char *Name);
357 * \brief Prepare a node for use
359 extern void VFS_InitNode(tVFS_Node *Node);
362 * \brief Clean up a node, ready for deletion
363 * \note This should ALWAYS be called before a node is freed, as it
364 * cleans up VFS internal structures.
366 extern void VFS_CleanupNode(tVFS_Node *Node);
369 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
370 * \brief Transforms Unix Permssions into Acess ACLs
371 * \param Mode Unix RWXrwxRWX mask
372 * \param Owner UID of the file's owner
373 * \param Group GID of the file's owning group
374 * \return An array of 3 Acess ACLs
376 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
379 * \brief Flags fro \a TypeFlag of VFS_SelectNode
382 #define VFS_SELECT_READ 0x01
383 #define VFS_SELECT_WRITE 0x02
384 #define VFS_SELECT_ERROR 0x04
390 * \brief Wait for an event on a node
391 * \param Node Node to wait on
392 * \param Type Type of wait
393 * \param Timeout Time to wait (NULL for infinite wait)
394 * \param Name Name to show in debug output
395 * \return Number of nodes that actioned (0 or 1)
397 extern int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name);
400 * \brief Change the full flag on a node
402 extern int VFS_MarkFull(tVFS_Node *Node, BOOL IsBufferFull);
403 extern int VFS_MarkAvaliable(tVFS_Node *Node, BOOL IsDataAvaliable);
404 extern int VFS_MarkError(tVFS_Node *Node, BOOL IsErrorState);
409 * \brief Functions to allow a node to be cached in memory by the VFS
411 * These functions store a node for the driver, to prevent it from having
412 * to re-generate the node on each call to FindDir. It also allows for
413 * fast cleanup when a filesystem is unmounted.
417 * \fn int Inode_GetHandle(void)
418 * \brief Gets a unique handle to the Node Cache
419 * \return A unique handle for use for the rest of the Inode_* functions
421 extern int Inode_GetHandle(void);
423 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
424 * \brief Gets an inode from the node cache
425 * \param Handle A handle returned by Inode_GetHandle()
426 * \param Inode Value of the Inode field of the ::tVFS_Node you want
427 * \return A pointer to the cached node
429 extern tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode);
431 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
432 * \brief Caches a node in the Node Cache
433 * \param Handle A handle returned by Inode_GetHandle()
434 * \param Node A pointer to the node to be cached (a copy is taken)
435 * \return A pointer to the node in the node cache
437 extern tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node);
439 * \fn int Inode_UncacheNode(int Handle, Uint64 Inode)
440 * \brief Dereferences (and removes if needed) a node from the cache
441 * \param Handle A handle returned by Inode_GetHandle()
442 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
444 extern void Inode_UncacheNode(int Handle, Uint64 Inode);
446 * \fn void Inode_ClearCache(int Handle)
447 * \brief Clears the cache for a handle
448 * \param Handle A handle returned by Inode_GetHandle()
450 extern void Inode_ClearCache(int Handle);