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 * \name tVFS_Node Flags
26 * \brief Flag values for tVFS_Node.Flags
29 //! \todo Is this still needed
30 #define VFS_FFLAG_READONLY 0x01 //!< Readonly File
32 * \brief Directory Flag
34 * This flag marks the tVFS_Node as describing a directory, and says
35 * that the tVFS_Node.FindDir, tVFS_Node.ReadDir, tVFS_Node.MkNod and
36 * tVFS_Node.Relink function pointers are valid.
37 * For a directory the tVFS_Node.Size field contains the number of files
38 * within the directory, or -1 for undetermined.
40 #define VFS_FFLAG_DIRECTORY 0x02
42 * \brief Symbolic Link Flag
44 * Marks a file as a symbolic link
46 #define VFS_FFLAG_SYMLINK 0x04
48 * \brief Set User ID Flag
50 * Allows an executable file to change it's executing user to the file's
52 * In the case of a directory, it means that all immediate children will
53 * inherit the UID of the parent.
55 #define VFS_FFLAG_SETUID 0x08
57 * \brief Set Group ID Flag
59 * Allows an executable file to change it's executing group to the file's
61 * In the case of a directory, it means that all immediate children will
62 * inherit the GID of the parent.
64 #define VFS_FFLAG_SETGID 0x10
70 * \brief Represents a node (file or directory) in the VFS tree
72 * This structure provides the VFS with the functions required to read/write
73 * the file (or directory) that it represents.
75 typedef struct sVFS_Node
79 * \brief Fields used by the driver to identify what data this node
83 Uint64 Inode; //!< Inode ID (Essentially another ImplInt)
84 Uint ImplInt; //!< Implementation Usable Integer
85 void *ImplPtr; //!< Implementation Usable Pointer
92 * \brief Stores the misc information about the node
95 int ReferenceCount; //!< Number of times the node is used
97 Uint64 Size; //!< File Size
99 Uint32 Flags; //!< File Flags
102 * \brief Pointer to cached data (FS Specific)
103 * \note The Inode_* functions will free when the node is uncached
115 Sint64 ATime; //!< Last Accessed Time
116 Sint64 MTime; //!< Last Modified Time
117 Sint64 CTime; //!< Creation Time
123 * \name Access controll
126 tUID UID; //!< ID of Owning User
127 tGID GID; //!< ID of Owning Group
129 int NumACLs; //!< Number of ACL entries
130 tVFS_ACL *ACLs; //!< Access Controll List pointer
136 * \name Common Functions
137 * \brief Functions that are used no matter the value of .Flags
141 * \brief Reference the node
142 * \param Node Pointer to this node
144 void (*Reference)(struct sVFS_Node *Node);
146 * \brief Close (dereference) the node
147 * \param Node Pointer to this node
149 * Usually .Close is used to write any changes to the node back to
150 * the persistent storage.
152 void (*Close)(struct sVFS_Node *Node);
155 * \brief Send an IO Control
156 * \param Node Pointer to this node
157 * \param Id IOCtl call number
158 * \param Data Pointer to data to pass to the driver
159 * \return Implementation defined
161 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
168 * \name Buffer Functions
169 * \brief Functions for accessing a buffer-type file (normal file or
175 * \brief Read from the file
176 * \param Node Pointer to this node
177 * \param Offset Byte offset in the file
178 * \param Length Number of bytes to read
179 * \param Buffer Destination for read data
180 * \return Number of bytes read
182 Uint64 (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
184 * \brief Write to the file
185 * \param Node Pointer to this node
186 * \param Offset Byte offser in the file
187 * \param Length Number of bytes to write
188 * \param Buffer Source of written data
189 * \return Number of bytes read
191 Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
198 * \name Directory Functions
202 * \brief Find an directory entry by name
203 * \param Node Pointer to this node
204 * \param Name Name of the file wanted
205 * \return Pointer to the requested node or NULL if it cannot be found
206 * \note The node returned must be accessable until ::tVFS_Node.Close
207 * is called and ReferenceCount reaches zero.
209 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, char *Name);
212 * \brief Read from a directory
213 * \param Node Pointer to this node
214 * \param Pos Offset in the directory
215 * \return Pointer to the name of the item on the heap (will be freed
216 * by the caller). If the directory end has been reached, NULL
218 * If an item is required to be skipped either &::NULLNode,
219 * ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
221 char *(*ReadDir)(struct sVFS_Node *Node, int Pos);
224 * \brief Create a node in a directory
225 * \param Node Pointer to this node
226 * \param Name Name of the new child
227 * \param Flags Flags to apply to the new child (directory or symlink)
228 * \return Zero on Success, non-zero on error (see errno.h)
230 int (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
233 * \brief Relink (Rename/Remove) a file/directory
234 * \param Node Pointer to this node
235 * \param OldName Name of the item to move/delete
236 * \param NewName New name (or NULL if unlinking is wanted)
237 * \return Zero on Success, non-zero on error (see errno.h)
239 int (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
242 * \brief Link a node to a name
243 * \param Node Pointer to this node (directory)
244 * \param Child Node to create a new link to
245 * \param NewName Name for the new link
246 * \return Zeron on success, non-zero on error (see errno.h)
248 int (*Link)(struct sVFS_Node *Node, struct sVFS_Node *Child, char *NewName);
256 * \brief VFS Driver (Filesystem) Definition
258 typedef struct sVFS_Driver
260 //! \brief Unique Identifier for this filesystem type
262 //! \brief Flags applying to this driver
265 //! \brief Callback to mount a device
266 tVFS_Node *(*InitDevice)(char *Device, char **Options);
267 //! \brief Callback to unmount a device
268 void (*Unmount)(tVFS_Node *Node);
269 //! \brief Used internally (next driver in the chain)
270 struct sVFS_Driver *Next;
274 //! \brief Maximum number of elements that can be skipped in one return
275 #define VFS_MAXSKIP ((void*)1024)
276 //! \brief Skip a single entry in readdir
277 #define VFS_SKIP ((void*)1)
278 //! \brief Skip \a n entries in readdir
279 #define VFS_SKIPN(n) ((void*)(n))
281 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
284 * \brief Simple ACLs to aid writing drivers
287 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
288 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
289 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
290 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
297 * \fn int VFS_AddDriver(tVFS_Driver *Info)
298 * \brief Registers the driver with the DevFS layer
299 * \param Info Driver information structure
301 extern int VFS_AddDriver(tVFS_Driver *Info);
303 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
304 * \brief Get the information structure of a driver given its name
305 * \param Name Name of filesystem driver to find
307 extern tVFS_Driver *VFS_GetFSByName(char *Name);
309 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
310 * \brief Transforms Unix Permssions into Acess ACLs
311 * \param Mode Unix RWXrwxRWX mask
312 * \param Owner UID of the file's owner
313 * \param Group GID of the file's owning group
314 * \return An array of 3 Acess ACLs
316 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
321 * \brief Functions to allow a node to be cached in memory by the VFS
323 * These functions store a node for the driver, to prevent it from having
324 * to re-generate the node on each call to FindDir. It also allows for
325 * fast cleanup when a filesystem is unmounted.
329 * \fn int Inode_GetHandle()
330 * \brief Gets a unique handle to the Node Cache
331 * \return A unique handle for use for the rest of the Inode_* functions
333 extern int Inode_GetHandle();
335 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
336 * \brief Gets an inode from the node cache
337 * \param Handle A handle returned by Inode_GetHandle()
338 * \param Inode Value of the Inode field of the ::tVFS_Node you want
339 * \return A pointer to the cached node
341 extern tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode);
343 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
344 * \brief Caches a node in the Node Cache
345 * \param Handle A handle returned by Inode_GetHandle()
346 * \param Node A pointer to the node to be cached (a copy is taken)
347 * \return A pointer to the node in the node cache
349 extern tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node);
351 * \fn int Inode_UncacheNode(int Handle, Uint64 Inode)
352 * \brief Dereferences (and removes if needed) a node from the cache
353 * \param Handle A handle returned by Inode_GetHandle()
354 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
356 extern void Inode_UncacheNode(int Handle, Uint64 Inode);
358 * \fn void Inode_ClearCache(int Handle)
359 * \brief Clears the cache for a handle
360 * \param Handle A handle returned by Inode_GetHandle()
362 extern void Inode_ClearCache(int Handle);