Changes to the module loader to handle specific errors from modules
[tpg/acess2.git] / Kernel / include / vfs.h
1 /* 
2  * Acess2
3  * VFS Common Header
4  */
5 /**
6  * \file vfs.h
7  * \brief Acess VFS Layer
8  */
9 #ifndef _VFS_H
10 #define _VFS_H
11
12 #include <acess.h>
13
14 /**
15  * \name VFS Node Flags
16  * \{
17  */
18 #define VFS_FFLAG_READONLY      0x01    //!< Read-only file
19 #define VFS_FFLAG_DIRECTORY     0x02    //!< Directory
20 #define VFS_FFLAG_SYMLINK       0x04    //!< Symbolic Link
21 /**
22  * \}
23  */
24
25 /**
26  * \brief VFS Node
27  * \todo Complete / Finalise
28  */
29 typedef struct sVFS_Node {      
30         Uint64  Inode;  //!< Inode ID
31         Uint    ImplInt;        //!< Implementation Usable Integer
32         void    *ImplPtr;       //!< Implementation Usable Pointer
33         
34          int    ReferenceCount; //!< Number of times the node is used
35         
36         Uint64  Size;   //!< File Size
37         
38         Uint32  Flags;  //!< File Flags
39         
40         Sint64  ATime;  //!< Last Accessed Time
41         Sint64  MTime;  //!< Last Modified Time
42         Sint64  CTime;  //!< Creation Time
43         
44         Uint    UID;    //!< Owning User
45         Uint    GID;    //!< Owning Group
46         
47          int    NumACLs;        //!< Number of ACL entries
48         tVFS_ACL        *ACLs;  //!< ACL Entries
49         
50         /**
51          * \brief Reference the node
52          * \param Node Pointer to this node
53          */
54         void    (*Reference)(struct sVFS_Node *Node);
55         /**
56          * \brief Close (dereference) the node
57          * \param Node  Pointer to this node
58          * 
59          * Usually .Close is used to write any changes to the node back to
60          * the persistent storage.
61          */
62         void    (*Close)(struct sVFS_Node *Node);
63         
64         /**
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
70          */
71          int    (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
72         
73         /**
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
80          */
81         Uint64  (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
82         /**
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
89          */
90         Uint64  (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
91         
92         /**
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.
99          */
100         struct sVFS_Node        *(*FindDir)(struct sVFS_Node *Node, char *Name);
101         
102         /**
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
108          *         will be returned.
109          *         If an item is required to be skipped either &::NULLNode,
110          *         ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
111          */
112         char    *(*ReadDir)(struct sVFS_Node *Node, int Pos);
113         
114         /**
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
120          */
121          int    (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
122         
123         /**
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
129          */
130          int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
131 } tVFS_Node;
132
133 /**
134  * \brief VFS Driver (Filesystem) Definition
135  */
136 typedef struct sVFS_Driver
137 {
138         //! \brief Unique Identifier for this filesystem type
139         char    *Name;
140         //! \brief Flags applying to this driver
141         Uint    Flags;
142         
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;
149 } tVFS_Driver;
150
151 // === GLOBALS ===
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))
158
159 extern tVFS_Node        NULLNode;       //!< NULL VFS Node (Ignored/Skipped)
160 /**
161  * \name Simple ACLs to aid writing drivers
162  * \{
163  */
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
168 /**
169  * \}
170  */
171
172 // === FUNCTIONS ===
173 /**
174  * \fn int VFS_AddDriver(tVFS_Driver *Info)
175  * \brief Registers the driver with the DevFS layer
176  * \param Info  Driver information structure
177  */
178 extern int      VFS_AddDriver(tVFS_Driver *Info);
179 /**
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
183  */
184 extern tVFS_Driver      *VFS_GetFSByName(char *Name);
185 /**
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
192  */
193 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
194
195 // --- Node Cache --
196 //! \name Node Cache
197 //! \{
198 /**
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
202  */
203 extern int      Inode_GetHandle();
204 /**
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
210  */
211 extern tVFS_Node        *Inode_GetCache(int Handle, Uint64 Inode);
212 /**
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
218  */
219 extern tVFS_Node        *Inode_CacheNode(int Handle, tVFS_Node *Node);
220 /**
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
225  */
226 extern void     Inode_UncacheNode(int Handle, Uint64 Inode);
227 /**
228  * \fn void Inode_ClearCache(int Handle)
229  * \brief Clears the cache for a handle
230  * \param Handle        A handle returned by Inode_GetHandle()
231  */
232 extern void     Inode_ClearCache(int Handle);
233
234 //! \}
235
236 #endif

UCC git Repository :: git.ucc.asn.au