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 void (*Close)(struct sVFS_Node *Node);
62 * \brief Send an IO Control
63 * \param Node Pointer to this node
64 * \param Id IOCtl call number
65 * \param Data Pointer to data to pass to the driver
66 * \return Implementation defined
68 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
71 * \brief Read from the file
72 * \param Node Pointer to this node
73 * \param Offset Byte offset in the file
74 * \param Length Number of bytes to read
75 * \param Buffer Destination for read data
76 * \return Number of bytes read
78 Uint64 (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
80 * \brief Write to the file
81 * \param Node Pointer to this node
82 * \param Offset Byte offser in the file
83 * \param Length Number of bytes to write
84 * \param Buffer Source of written data
85 * \return Number of bytes read
87 Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
90 * \brief Find an directory entry by name
91 * \param Node Pointer to this node
92 * \param Name Name of the file wanted
93 * \return Pointer to the requested node or NULL if it cannot be found
94 * \note The node returned must be accessable until ::tVFS_Node.Close
95 * is called and ReferenceCount reaches zero.
97 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, char *Name);
100 * \brief Read from a directory
101 * \param Node Pointer to this node
102 * \param Pos Offset in the directory
103 * \return Pointer to the name of the item on the heap (will be freed
104 * by the caller). If the directory end has been reached, NULL
106 * If an item is required to be skipped either &::NULLNode,
107 * ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
109 char *(*ReadDir)(struct sVFS_Node *Node, int Pos);
112 * \brief Create a node in a directory
113 * \param Node Pointer to this node
114 * \param Name Name of the new child
115 * \param Flags Flags to apply to the new child (directory or symlink)
116 * \return Boolean success
118 int (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
121 * \brief Relink (Rename/Remove) a file/directory
122 * \param Node Pointer to this node
123 * \param OldName Name of the item to move/delete
124 * \param NewName New name (or NULL if unlinking is wanted)
125 * \return Boolean Success
127 int (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
131 * \brief VFS Driver (Filesystem) Definition
133 typedef struct sVFS_Driver
135 //! \brief Unique Identifier for this filesystem type
137 //! \brief Flags applying to this driver
140 //! \brief Callback to mount a device
141 tVFS_Node *(*InitDevice)(char *Device, char **Options);
142 //! \brief Callback to unmount a device
143 void (*Unmount)(tVFS_Node *Node);
144 //! \brief Used internally (next driver in the chain)
145 struct sVFS_Driver *Next;
149 //! \brief Maximum number of elements that can be skipped in one return
150 #define VFS_MAXSKIP ((void*)1024)
151 //! \brief Skip a single entry in readdir
152 #define VFS_SKIP ((void*)1)
153 //! \brief Skip \a n entries in readdir
154 #define VFS_SKIPN(n) ((void*)(n))
156 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
158 * \name Simple ACLs to aid writing drivers
161 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
162 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
163 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
164 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
171 * \fn int VFS_AddDriver(tVFS_Driver *Info)
172 * \brief Registers the driver with the DevFS layer
173 * \param Info Driver information structure
175 extern int VFS_AddDriver(tVFS_Driver *Info);
177 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
178 * \brief Get the information structure of a driver given its name
179 * \param Name Name of filesystem driver to find
181 extern tVFS_Driver *VFS_GetFSByName(char *Name);
183 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
184 * \brief Transforms Unix Permssions into Acess ACLs
185 * \param Mode Unix RWXrwxRWX mask
186 * \param Owner UID of the file's owner
187 * \param Group GID of the file's owning group
188 * \return An array of 3 Acess ACLs
190 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
196 * \fn int Inode_GetHandle()
197 * \brief Gets a unique handle to the Node Cache
198 * \return A unique handle for use for the rest of the Inode_* functions
200 extern int Inode_GetHandle();
202 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
203 * \brief Gets an inode from the node cache
204 * \param Handle A handle returned by Inode_GetHandle()
205 * \param Inode Value of the Inode field of the ::tVFS_Node you want
206 * \return A pointer to the cached node
208 extern tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode);
210 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
211 * \brief Caches a node in the Node Cache
212 * \param Handle A handle returned by Inode_GetHandle()
213 * \param Node A pointer to the node to be cached (a copy is taken)
214 * \return A pointer to the node in the node cache
216 extern tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node);
218 * \fn void Inode_UncacheNode(int Handle, Uint64 Inode)
219 * \brief Dereferences (and removes if needed) a node from the cache
220 * \param Handle A handle returned by Inode_GetHandle()
221 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
223 extern void Inode_UncacheNode(int Handle, Uint64 Inode);
225 * \fn void Inode_ClearCache(int Handle)
226 * \brief Clears the cache for a handle
227 * \param Handle A handle returned by Inode_GetHandle()
229 extern void Inode_ClearCache(int Handle);