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"
26 * \brief Thread list datatype for VFS_Select
28 typedef struct sVFS_SelectList tVFS_SelectList;
30 typedef struct sVFS_NodeType tVFS_NodeType;
33 * \name tVFS_Node Flags
34 * \brief Flag values for tVFS_Node.Flags
37 //! \todo Is this still needed
38 #define VFS_FFLAG_READONLY 0x01 //!< Readonly File
40 * \brief Directory Flag
42 * This flag marks the tVFS_Node as describing a directory, and says
43 * that the tVFS_Node.FindDir, tVFS_Node.ReadDir, tVFS_Node.MkNod and
44 * tVFS_Node.Relink function pointers are valid.
45 * For a directory the tVFS_Node.Size field contains the number of files
46 * within the directory, or -1 for undetermined.
48 #define VFS_FFLAG_DIRECTORY 0x02
50 * \brief Symbolic Link Flag
52 * Marks a file as a symbolic link
54 #define VFS_FFLAG_SYMLINK 0x04
56 * \brief Set User ID Flag
58 * Allows an executable file to change it's executing user to the file's
60 * In the case of a directory, it means that all immediate children will
61 * inherit the UID of the parent.
63 #define VFS_FFLAG_SETUID 0x08
65 * \brief Set Group ID Flag
67 * Allows an executable file to change it's executing group to the file's
69 * In the case of a directory, it means that all immediate children will
70 * inherit the GID of the parent.
72 #define VFS_FFLAG_SETGID 0x10
75 * \brief "Don't do Write-Back" Flag
77 * Stops the VFS from calling tVFS_Node.Write on dirty pages when a region
78 * is unmapped. Nice for read-only files and memory-only files (or
79 * pseudo-readonly filesystems)
81 #define VFS_FFLAG_NOWRITEBACK 0x1000
84 * \brief "Dirty Metadata" Flag
86 * Indicates that the node's metadata has been altered since the flag was last
87 * cleared. Tells the driver that it should update the inode at the next flush.
89 #define VFS_FFLAG_DIRTY 0x8000
95 * \brief Represents a node (file or directory) in the VFS tree
97 * This structure provides the VFS with the functions required to read/write
98 * the file (or directory) that it represents.
100 typedef struct sVFS_Node
103 * \brief Functions associated with the node
109 * \brief Fields used by the driver to identify what data this node
113 Uint64 Inode; //!< Inode ID - Must identify the node uniquely if tVFS_Driver.GetNodeFromINode is non-NULL
114 Uint ImplInt; //!< Implementation Usable Integer
115 void *ImplPtr; //!< Implementation Usable Pointer
122 * \brief Stores the misc information about the node
125 int ReferenceCount; //!< Number of times the node is used
127 Uint64 Size; //!< File Size
129 Uint32 Flags; //!< File Flags
132 * \brief Pointer to cached data (FS Specific)
133 * \note The Inode_* functions will free when the node is uncached
140 * \note Provided for the Filesystem driver's use
152 tTime ATime; //!< Last Accessed Time
153 tTime MTime; //!< Last Modified Time
154 tTime CTime; //!< Creation Time
160 * \name Access control
163 tUID UID; //!< ID of Owning User
164 tGID GID; //!< ID of Owning Group
166 int NumACLs; //!< Number of ACL entries
167 tVFS_ACL *ACLs; //!< Access Controll List pointer
173 * \name VFS_Select() fields
174 * \note Used by the VFS internals, drivers should use VFS_Mark*
178 tVFS_SelectList *ReadThreads; //!< Threads waiting to read
180 tVFS_SelectList *WriteThreads; //!< Threads waiting to write
182 tVFS_SelectList *ErrorThreads; //!< Threads waiting for an error
188 * \name VFS_MMap() fields
198 * \name tVFS_NodeType.FindDir Flags
202 //\! Attempt non-blocking IO
203 #define VFS_IOFLAG_NOBLOCK 0x001
209 * \name tVFS_NodeType.FindDir Flags
213 //\! Call was triggered by VFS_Stat (as opposed to open)
214 #define VFS_FDIRFLAG_STAT 0x001
220 * \brief Functions for a specific node type
225 * \brief Debug name for the type
227 const char *TypeName;
230 * \name Common Functions
231 * \brief Functions that are used no matter the value of .Flags
235 * \brief Reference the node
236 * \param Node Pointer to this node
238 void (*Reference)(struct sVFS_Node *Node);
240 * \brief Close (dereference) the node
241 * \param Node Pointer to this node
243 * Usually .Close is used to write any changes to the node back to
244 * the persistent storage.
246 void (*Close)(struct sVFS_Node *Node);
249 * \brief Send an IO Control
250 * \param Node Pointer to this node
251 * \param Id IOCtl call number
252 * \param Data Pointer to data to pass to the driver
253 * \return Implementation defined
255 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
262 * \name Buffer Functions
263 * \brief Functions for accessing a buffer-type file (normal file or
269 * \brief Read from the file
270 * \param Node Pointer to this node
271 * \param Offset Byte offset in the file
272 * \param Length Number of bytes to read
273 * \param Buffer Destination for read data
274 * \return Number of bytes read
276 size_t (*Read)(struct sVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags);
278 * \brief Write to the file
279 * \param Node Pointer to this node
280 * \param Offset Byte offser in the file
281 * \param Length Number of bytes to write
282 * \param Buffer Source of written data
283 * \return Number of bytes read
285 size_t (*Write)(struct sVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags);
288 * \brief Map a region of a file into memory
289 * \param Node Pointer to this node
290 * \param Offset Start of the region (page aligned)
291 * \param Length Length of the region (page aligned)
292 * \param Dest Location to which to map
293 * \return Boolean Failure
294 * \note If NULL, the VFS implements it using .Read
296 int (*MMap)(struct sVFS_Node *Node, off_t Offset, int Length, void *Dest);
303 * \name Directory Functions
307 * \brief Find an directory entry by name
308 * \param Node Pointer to this node
309 * \param Name Name of the file wanted
310 * \return Pointer to the requested node or NULL if it cannot be found
311 * \note The node returned must be accessable until tVFS_NodeType::Close
312 * is called and ReferenceCount reaches zero.
314 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, const char *Name, Uint Flags);
317 * \brief Read from a directory
318 * \param Node Pointer to this node
319 * \param Pos Offset in the directory
320 * \param Dest Destination for filename
321 * \return Zero on success, negative on error or +ve for ignore entry
323 int (*ReadDir)(struct sVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
326 * \brief Create a node in a directory
327 * \param Node Pointer to this node
328 * \param Name Name of the new child
329 * \param Flags Flags to apply to the new child (directory or symlink)
330 * \return Created node or NULL on error
332 tVFS_Node *(*MkNod)(struct sVFS_Node *Node, const char *Name, Uint Mode);
335 * \brief Relink (Rename/Remove) a file/directory
336 * \param Node Pointer to this node
337 * \param OldName Name of the item to move/delete
338 * \return Zero on Success, non-zero on error (see errno.h)
340 int (*Unlink)(struct sVFS_Node *Node, const char *OldName);
343 * \brief Link a node to a name
344 * \param Node Pointer to this node (directory)
345 * \param NewName Name for the new link
346 * \param Child Node to create a new link to
347 * \return Zero on success, non-zero on error (see errno.h)
349 int (*Link)(struct sVFS_Node *Node, const char *NewName, struct sVFS_Node *Child);
357 * \brief VFS Driver (Filesystem) Definition
359 typedef struct sVFS_Driver
362 * \brief Unique Identifier for this filesystem type
366 * \brief Flags applying to this driver
371 * \brief Detect if a volume is accessible using this driver
372 * \return Boolean success (with higher numbers being higher priority)
374 * E.g. FAT would return 1 as it's the lowest common denominator while ext2 might return 2,
375 * because it can be embedded in a FAT volume (and is a more fully featured filesystem).
377 int (*Detect)(int FD);
380 * \brief Callback to mount a device
382 tVFS_Node *(*InitDevice)(const char *Device, const char **Options);
384 * \brief Callback to unmount a device
386 void (*Unmount)(tVFS_Node *Node);
388 * \brief Retrieve a VFS node from an inode
390 tVFS_Node *(*GetNodeFromINode)(tVFS_Node *RootNode, Uint64 InodeValue);
392 * \brief Used internally (next driver in the chain)
394 struct sVFS_Driver *Next;
398 //! \brief Maximum number of elements that can be skipped in one return
399 #define VFS_MAXSKIP ((void*)1024)
400 //! \brief Skip a single entry in readdir
401 #define VFS_SKIP ((void*)1)
402 //! \brief Skip \a n entries in readdir
403 #define VFS_SKIPN(n) ((void*)(n))
405 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
408 * \brief Simple ACLs to aid writing drivers
411 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
412 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
413 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
414 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
421 * \fn int VFS_AddDriver(tVFS_Driver *Info)
422 * \brief Registers the driver with the DevFS layer
423 * \param Info Driver information structure
425 extern int VFS_AddDriver(tVFS_Driver *Info);
427 * \brief Get the information structure of a driver given its name
428 * \param Name Name of filesystem driver to find
430 extern tVFS_Driver *VFS_GetFSByName(const char *Name);
434 * \brief Prepare a node for use
436 extern void VFS_InitNode(tVFS_Node *Node);
439 * \brief Clean up a node, ready for deletion
440 * \note This should ALWAYS be called before a node is freed, as it
441 * cleans up VFS internal structures.
443 extern void VFS_CleanupNode(tVFS_Node *Node);
446 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
447 * \brief Transforms Unix Permssions into Acess ACLs
448 * \param Mode Unix RWXrwxRWX mask
449 * \param Owner UID of the file's owner
450 * \param Group GID of the file's owning group
451 * \return An array of 3 Acess ACLs
453 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
456 * \brief Flags fro \a TypeFlag of VFS_SelectNode
459 #define VFS_SELECT_READ 0x01
460 #define VFS_SELECT_WRITE 0x02
461 #define VFS_SELECT_ERROR 0x04
467 * \brief Wait for an event on a node
468 * \param Node Node to wait on
469 * \param Type Type of wait
470 * \param Timeout Time to wait (NULL for infinite wait)
471 * \param Name Name to show in debug output
472 * \return Number of nodes that actioned (0 or 1)
474 extern int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name);
477 * \brief Change the full flag on a node
479 extern int VFS_MarkFull(tVFS_Node *Node, BOOL IsBufferFull);
481 * \brief Alter the space avaliable flag on a node
483 extern int VFS_MarkAvaliable(tVFS_Node *Node, BOOL IsDataAvaliable);
485 * \brief Alter the error flags on a node
487 extern int VFS_MarkError(tVFS_Node *Node, BOOL IsErrorState);
492 * \brief Functions to allow a node to be cached in memory by the VFS
494 * These functions store a node for the driver, to prevent it from having
495 * to re-generate the node on each call to FindDir. It also allows for
496 * fast cleanup when a filesystem is unmounted.
500 typedef struct sInodeCache tInodeCache;
502 typedef void (*tInode_CleanUpNode)(tVFS_Node *Node);
505 * \fn int Inode_GetHandle(void)
506 * \brief Gets a unique handle to the Node Cache
507 * \return A unique handle for use for the rest of the Inode_* functions
509 extern tInodeCache *Inode_GetHandle(tInode_CleanUpNode CleanUpNode);
511 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
512 * \brief Gets an inode from the node cache
513 * \param Handle A handle returned by Inode_GetHandle()
514 * \param Inode Value of the Inode field of the ::tVFS_Node you want
515 * \return A pointer to the cached node
517 extern tVFS_Node *Inode_GetCache(tInodeCache *Handle, Uint64 Inode);
519 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
520 * \brief Caches a node in the Node Cache
521 * \param Handle A handle returned by Inode_GetHandle()
522 * \param Node A pointer to the node to be cached (a copy is taken)
523 * \return A pointer to the node in the node cache
525 extern tVFS_Node *Inode_CacheNode(tInodeCache *Handle, tVFS_Node *Node);
526 extern tVFS_Node *Inode_CacheNodeEx(tInodeCache *Handle, tVFS_Node *Node, size_t Size);
528 * \fn int Inode_UncacheNode(int Handle, Uint64 Inode)
529 * \brief Dereferences (and removes if needed) a node from the cache
530 * \param Handle A handle returned by Inode_GetHandle()
531 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
532 * \return -1: Error (not present), 0: Not freed, 1: Freed
534 extern int Inode_UncacheNode(tInodeCache *Handle, Uint64 Inode);
536 * \fn void Inode_ClearCache(int Handle)
537 * \brief Clears the cache for a handle
538 * \param Handle A handle returned by Inode_GetHandle()
540 extern void Inode_ClearCache(tInodeCache *Handle);