7 * \brief Acess VFS Layer
14 //! \name ACL Permissions
19 #define VFS_PERM_READ 0x00000001
23 #define VFS_PERM_WRITE 0x00000002
25 * \brief Append allowed
27 #define VFS_PERM_APPEND 0x00000004
31 #define VFS_PERM_EXECUTE 0x00000008
33 * \brief All permissions granted
35 #define VFS_PERM_ALL 0x7FFFFFFF // Mask for permissions
37 * \brief Denies instead of granting permissions
38 * \note Denials take precedence
40 #define VFS_PERM_DENY 0x80000000 // Inverts permissions
44 * \brief ACL Defintion Structure
46 typedef struct sVFS_ACL
49 unsigned Group: 1; //!< Group (as opposed to user) flag
50 unsigned ID: 31; //!< ID of Group/User (-1 for nobody/world)
53 unsigned Inv: 1; //!< Invert Permissions
54 unsigned Perms: 31; //!< Permission Flags
59 * \name VFS Node Flags
62 #define VFS_FFLAG_READONLY 0x01 //!< Read-only file
63 #define VFS_FFLAG_DIRECTORY 0x02 //!< Directory
64 #define VFS_FFLAG_SYMLINK 0x04 //!< Symbolic Link
72 typedef struct sVFS_Node {
73 Uint64 Inode; //!< Inode ID
74 Uint ImplInt; //!< Implementation Usable Integer
75 void *ImplPtr; //!< Implementation Usable Pointer
77 int ReferenceCount; //!< Number of times the node is used
79 Uint64 Size; //!< File Size
81 Uint32 Flags; //!< File Flags
83 Sint64 ATime; //!< Last Accessed Time
84 Sint64 MTime; //!< Last Modified Time
85 Sint64 CTime; //!< Creation Time
87 Uint UID; //!< Owning User
88 Uint GID; //!< Owning Group
90 int NumACLs; //!< Number of ACL entries
91 tVFS_ACL *ACLs; //!< ACL Entries
93 //! Reference the node
94 void (*Reference)(struct sVFS_Node *Node);
95 //! Close (dereference) the node
96 void (*Close)(struct sVFS_Node *Node);
97 //! Send an IO Control
98 int (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
100 //! \brief Read from the file
101 Uint64 (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
102 //! \brief Write to the file
103 Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
105 //! \brief Find an directory entry by name
106 //! \note The node returned must be accessable until ::tVFS_Node.Close is called
107 struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, char *Name);
109 //! \brief Read from a directory
110 //! \note MUST return a heap address
111 char *(*ReadDir)(struct sVFS_Node *Node, int Pos);
113 //! \brief Create a node in a directory
114 int (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
116 //! \brief Relink (Rename/Remove) a file/directory
117 int (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
123 * \brief VFS Driver (Filesystem) Definition
125 typedef struct sVFS_Driver
127 //! \brief Unique Identifier for this filesystem type
129 //! \brief Flags applying to this driver
132 //! \brief Callback to mount a device
133 tVFS_Node *(*InitDevice)(char *Device, char **Options);
134 //! \brief Callback to unmount a device
135 void (*Unmount)(tVFS_Node *Node);
136 //! \brief Used internally (next driver in the chain)
137 struct sVFS_Driver *Next;
141 //! \brief Maximum number of elements that can be skipped in one return
142 #define VFS_MAXSKIP ((void*)1024)
143 //! \brief Skip a single entry in readdir
144 #define VFS_SKIP ((void*)1)
145 //! \brief Skip \a n entries in readdir
146 #define VFS_SKIPN(n) ((void*)(n))
148 extern tVFS_Node NULLNode; //!< NULL VFS Node (Ignored/Skipped)
150 * \name Simple ACLs to aid writing drivers
153 extern tVFS_ACL gVFS_ACL_EveryoneRWX; //!< Everyone Read/Write/Execute
154 extern tVFS_ACL gVFS_ACL_EveryoneRW; //!< Everyone Read/Write
155 extern tVFS_ACL gVFS_ACL_EveryoneRX; //!< Everyone Read/Execute
156 extern tVFS_ACL gVFS_ACL_EveryoneRO; //!< Everyone Read only
163 * \fn int VFS_AddDriver(tVFS_Driver *Info)
164 * \brief Registers the driver with the DevFS layer
165 * \param Info Driver information structure
167 extern int VFS_AddDriver(tVFS_Driver *Info);
169 * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
170 * \brief Get the information structure of a driver given its name
171 * \param Name Name of filesystem driver to find
173 extern tVFS_Driver *VFS_GetFSByName(char *Name);
175 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
176 * \brief Transforms Unix Permssions into Acess ACLs
177 * \param Mode Unix RWXrwxRWX mask
178 * \param Owner UID of the file's owner
179 * \param Group GID of the file's owning group
180 * \return An array of 3 Acess ACLs
182 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
188 * \fn int Inode_GetHandle()
189 * \brief Gets a unique handle to the Node Cache
190 * \return A unique handle for use for the rest of the Inode_* functions
192 extern int Inode_GetHandle();
194 * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
195 * \brief Gets an inode from the node cache
196 * \param Handle A handle returned by Inode_GetHandle()
197 * \param Inode Value of the Inode field of the ::tVFS_Node you want
198 * \return A pointer to the cached node
200 extern tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode);
202 * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
203 * \brief Caches a node in the Node Cache
204 * \param Handle A handle returned by Inode_GetHandle()
205 * \param Node A pointer to the node to be cached (a copy is taken)
206 * \return A pointer to the node in the node cache
208 extern tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node);
210 * \fn void Inode_UncacheNode(int Handle, Uint64 Inode)
211 * \brief Dereferences (and removes if needed) a node from the cache
212 * \param Handle A handle returned by Inode_GetHandle()
213 * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
215 extern void Inode_UncacheNode(int Handle, Uint64 Inode);
217 * \fn void Inode_ClearCache(int Handle)
218 * \brief Clears the cache for a handle
219 * \param Handle A handle returned by Inode_GetHandle()
221 extern void Inode_ClearCache(int Handle);