7 * \brief Acess VFS Layer
15 * \name VFS Node Flags
18 #define VFS_FFLAG_READONLY 0x01 //!< Read-only file
19 #define VFS_FFLAG_DIRECTORY 0x02 //!< Directory
20 #define VFS_FFLAG_SYMLINK 0x04 //!< Symbolic Link
27 * \todo Complete / Finalise
29 typedef struct sVFS_Node {
30 Uint64 Inode; //!< Inode ID
31 Uint ImplInt; //!< Implementation Usable Integer
32 void *ImplPtr; //!< Implementation Usable Pointer
34 int ReferenceCount; //!< Number of times the node is used
36 Uint64 Size; //!< File Size
38 Uint32 Flags; //!< File Flags
40 Sint64 ATime; //!< Last Accessed Time
41 Sint64 MTime; //!< Last Modified Time
42 Sint64 CTime; //!< Creation Time
44 Uint UID; //!< Owning User
45 Uint GID; //!< Owning Group
47 int NumACLs; //!< Number of ACL entries
48 tVFS_ACL *ACLs; //!< ACL Entries
51 * \brief Reference the node
52 * \param Node Pointer to this node
54 void (*Reference)(struct sVFS_Node *Node);
56 * \brief Close (dereference) the node
57 * \param Node Pointer to this node
59 * Usually .Close is used to write any changes to the node back to
60 * the persistent storage.
62 void (*Close)(struct sVFS_Node *Node);
65 * \brief Send an IO Control
66 * \param Node Pointer to this node
67 * \param Id IOCtl call number
68 * \param Data Pointer to data to pass to the driver
69 * \return Implementation defined
71 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
74 * \brief Read from the file
75 * \param Node Pointer to this node
76 * \param Offset Byte offset in the file
77 * \param Length Number of bytes to read
78 * \param Buffer Destination for read data
79 * \return Number of bytes read
81 Uint64 (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
83 * \brief Write to the file
84 * \param Node Pointer to this node
85 * \param Offset Byte offser in the file
86 * \param Length Number of bytes to write
87 * \param Buffer Source of written data
88 * \return Number of bytes read
90 Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
93 * \brief Find an directory entry by name
94 * \param Node Pointer to this node
95 * \param Name Name of the file wanted
96 * \return Pointer to the requested node or NULL if it cannot be found
97 * \note The node returned must be accessable until ::tVFS_Node.Close
98 * is called and ReferenceCount reaches zero.
100 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, char *Name);
103 * \brief Read from a directory
104 * \param Node Pointer to this node
105 * \param Pos Offset in the directory
106 * \return Pointer to the name of the item on the heap (will be freed
107 * by the caller). If the directory end has been reached, NULL
109 * If an item is required to be skipped either &::NULLNode,
110 * ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
112 char *(*ReadDir)(struct sVFS_Node *Node, int Pos);
115 * \brief Create a node in a directory
116 * \param Node Pointer to this node
117 * \param Name Name of the new child
118 * \param Flags Flags to apply to the new child (directory or symlink)
119 * \return Boolean success
121 int (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
124 * \brief Relink (Rename/Remove) a file/directory
125 * \param Node Pointer to this node
126 * \param OldName Name of the item to move/delete
127 * \param NewName New name (or NULL if unlinking is wanted)
128 * \return Boolean Success
130 int (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
134 * \brief VFS Driver (Filesystem) Definition
136 typedef struct sVFS_Driver
138 //! \brief Unique Identifier for this filesystem type
140 //! \brief Flags applying to this driver
143 //! \brief Callback to mount a device
144 tVFS_Node *(*InitDevice)(char *Device, char **Options);
145 //! \brief Callback to unmount a device
146 void (*Unmount)(tVFS_Node *Node);
147 //! \brief Used internally (next driver in the chain)
148 struct sVFS_Driver *Next;
152 //! \brief Maximum number of elements that can be skipped in one return
153 #define VFS_MAXSKIP ((void*)1024)
154 //! \brief Skip a single entry in readdir
155 #define VFS_SKIP ((void*)1)
156 //! \brief Skip \a n entries in readdir
157 #define VFS_SKIPN(n) ((void*)(n))
159 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
161 * \name Simple ACLs to aid writing drivers
164 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
165 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
166 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
167 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
174 * \fn int VFS_AddDriver(tVFS_Driver *Info)
175 * \brief Registers the driver with the DevFS layer
176 * \param Info Driver information structure
178 extern int VFS_AddDriver(tVFS_Driver *Info);
180 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
181 * \brief Get the information structure of a driver given its name
182 * \param Name Name of filesystem driver to find
184 extern tVFS_Driver *VFS_GetFSByName(char *Name);
186 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
187 * \brief Transforms Unix Permssions into Acess ACLs
188 * \param Mode Unix RWXrwxRWX mask
189 * \param Owner UID of the file's owner
190 * \param Group GID of the file's owning group
191 * \return An array of 3 Acess ACLs
193 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
199 * \fn int Inode_GetHandle()
200 * \brief Gets a unique handle to the Node Cache
201 * \return A unique handle for use for the rest of the Inode_* functions
203 extern int Inode_GetHandle();
205 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
206 * \brief Gets an inode from the node cache
207 * \param Handle A handle returned by Inode_GetHandle()
208 * \param Inode Value of the Inode field of the ::tVFS_Node you want
209 * \return A pointer to the cached node
211 extern tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode);
213 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
214 * \brief Caches a node in the Node Cache
215 * \param Handle A handle returned by Inode_GetHandle()
216 * \param Node A pointer to the node to be cached (a copy is taken)
217 * \return A pointer to the node in the node cache
219 extern tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node);
221 * \fn void Inode_UncacheNode(int Handle, Uint64 Inode)
222 * \brief Dereferences (and removes if needed) a node from the cache
223 * \param Handle A handle returned by Inode_GetHandle()
224 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
226 extern void Inode_UncacheNode(int Handle, Uint64 Inode);
228 * \fn void Inode_ClearCache(int Handle)
229 * \brief Clears the cache for a handle
230 * \param Handle A handle returned by Inode_GetHandle()
232 extern void Inode_ClearCache(int Handle);