47cbe190f983c4ef03a2cc778120d756010d4d50
[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  * 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.
12  * 
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"
18  */
19 #ifndef _VFS_H
20 #define _VFS_H
21
22 #include <acess.h>
23
24 /**
25  * \name tVFS_Node Flags
26  * \brief Flag values for tVFS_Node.Flags
27  * \{
28  */
29 //! \todo Is this still needed
30 #define VFS_FFLAG_READONLY      0x01    //!< Readonly File
31 /**
32  * \brief Directory Flag
33  * 
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.
39  */
40 #define VFS_FFLAG_DIRECTORY     0x02
41 /**
42  * \brief Symbolic Link Flag
43  * 
44  * Marks a file as a symbolic link
45  */
46 #define VFS_FFLAG_SYMLINK       0x04
47 /**
48  * \}
49  */
50
51 /**
52  * \brief VFS Node
53  * 
54  * This structure provides the VFS with the functions required to read/write
55  * the file (or directory) that it represents.
56  */
57 typedef struct sVFS_Node {
58         /**
59          * \name Identifiers
60          * \brief Fields used by the driver to identify what data this node
61          *        corresponds to.
62          * \{
63          */
64         Uint64  Inode;  //!< Inode ID (Essentially another ImplInt)
65         Uint    ImplInt;        //!< Implementation Usable Integer
66         void    *ImplPtr;       //!< Implementation Usable Pointer
67         /**
68          * \}
69          */
70         
71          int    ReferenceCount; //!< Number of times the node is used
72         
73         Uint64  Size;   //!< File Size
74         
75         Uint32  Flags;  //!< File Flags
76         
77         /**
78          * \name Times
79          * \{
80          */
81         Sint64  ATime;  //!< Last Accessed Time
82         Sint64  MTime;  //!< Last Modified Time
83         Sint64  CTime;  //!< Creation Time
84         /**
85          * \}
86          */
87         
88         /**
89          * \name Access controll
90          * \{
91          */
92         tUID    UID;    //!< ID of Owning User
93         tGID    GID;    //!< ID of Owning Group
94         
95          int    NumACLs;        //!< Number of ACL entries
96         tVFS_ACL        *ACLs;  //!< Access Controll List pointer
97         /**
98          * \}
99          */
100         
101         /**
102          * \name Common Functions
103          * \brief Functions that are used no matter the value of .Flags
104          * \{
105          */
106         /**
107          * \brief Reference the node
108          * \param Node Pointer to this node
109          */
110         void    (*Reference)(struct sVFS_Node *Node);
111         /**
112          * \brief Close (dereference) the node
113          * \param Node  Pointer to this node
114          * 
115          * Usually .Close is used to write any changes to the node back to
116          * the persistent storage.
117          */
118         void    (*Close)(struct sVFS_Node *Node);
119         
120         /**
121          * \brief Send an IO Control
122          * \param Node  Pointer to this node
123          * \param Id    IOCtl call number
124          * \param Data  Pointer to data to pass to the driver
125          * \return Implementation defined
126          */
127          int    (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
128         
129         /**
130          * }
131          */
132         
133         /**
134          * \name Buffer Functions
135          * \brief Functions for accessing a buffer-type file (normal file or
136          *        symbolic link)
137          * \{
138          */
139         
140         /**
141          * \brief Read from the file
142          * \param Node  Pointer to this node
143          * \param Offset        Byte offset in the file
144          * \param Length        Number of bytes to read
145          * \param Buffer        Destination for read data
146          * \return Number of bytes read
147          */
148         Uint64  (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
149         /**
150          * \brief Write to the file
151          * \param Node  Pointer to this node
152          * \param Offset        Byte offser in the file
153          * \param Length        Number of bytes to write
154          * \param Buffer        Source of written data
155          * \return Number of bytes read
156          */
157         Uint64  (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
158         
159         /**
160          * }
161          */
162         
163         /**
164          * \name Directory Functions
165          * \{
166          */
167         /**
168          * \brief Find an directory entry by name
169          * \param Node  Pointer to this node
170          * \param Name  Name of the file wanted
171          * \return Pointer to the requested node or NULL if it cannot be found
172          * \note The node returned must be accessable until ::tVFS_Node.Close
173          *       is called and ReferenceCount reaches zero.
174          */
175         struct sVFS_Node        *(*FindDir)(struct sVFS_Node *Node, char *Name);
176         
177         /**
178          * \brief Read from a directory
179          * \param Node  Pointer to this node
180          * \param Pos   Offset in the directory
181          * \return Pointer to the name of the item on the heap (will be freed
182          *         by the caller). If the directory end has been reached, NULL
183          *         will be returned.
184          *         If an item is required to be skipped either &::NULLNode,
185          *         ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
186          */
187         char    *(*ReadDir)(struct sVFS_Node *Node, int Pos);
188         
189         /**
190          * \brief Create a node in a directory
191          * \param Node  Pointer to this node
192          * \param Name  Name of the new child
193          * \param Flags Flags to apply to the new child (directory or symlink)
194          * \return Boolean success
195          */
196          int    (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
197         
198         /**
199          * \brief Relink (Rename/Remove) a file/directory
200          * \param Node  Pointer to this node
201          * \param OldName       Name of the item to move/delete
202          * \param NewName       New name (or NULL if unlinking is wanted)
203          * \return Boolean Success
204          */
205          int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
206          
207          /**
208           * }
209           */
210 } tVFS_Node;
211
212 /**
213  * \brief VFS Driver (Filesystem) Definition
214  */
215 typedef struct sVFS_Driver
216 {
217         //! \brief Unique Identifier for this filesystem type
218         char    *Name;
219         //! \brief Flags applying to this driver
220         Uint    Flags;
221         
222         //! \brief Callback to mount a device
223         tVFS_Node       *(*InitDevice)(char *Device, char **Options);
224         //! \brief Callback to unmount a device
225         void    (*Unmount)(tVFS_Node *Node);
226         //! \brief Used internally (next driver in the chain)
227         struct sVFS_Driver      *Next;
228 } tVFS_Driver;
229
230 // === GLOBALS ===
231 //! \brief Maximum number of elements that can be skipped in one return
232 #define VFS_MAXSKIP     ((void*)1024)
233 //! \brief Skip a single entry in readdir
234 #define VFS_SKIP        ((void*)1)
235 //! \brief Skip \a n entries in readdir
236 #define VFS_SKIPN(n)    ((void*)(n))
237
238 extern tVFS_Node        NULLNode;       //!< NULL VFS Node (Ignored/Skipped)
239 /**
240  * \name Static ACLs
241  * \brief Simple ACLs to aid writing drivers
242  * \{
243  */
244 extern tVFS_ACL gVFS_ACL_EveryoneRWX;   //!< Everyone Read/Write/Execute
245 extern tVFS_ACL gVFS_ACL_EveryoneRW;    //!< Everyone Read/Write
246 extern tVFS_ACL gVFS_ACL_EveryoneRX;    //!< Everyone Read/Execute
247 extern tVFS_ACL gVFS_ACL_EveryoneRO;    //!< Everyone Read only
248 /**
249  * \}
250  */
251
252 // === FUNCTIONS ===
253 /**
254  * \fn int VFS_AddDriver(tVFS_Driver *Info)
255  * \brief Registers the driver with the DevFS layer
256  * \param Info  Driver information structure
257  */
258 extern int      VFS_AddDriver(tVFS_Driver *Info);
259 /**
260  * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
261  * \brief Get the information structure of a driver given its name
262  * \param Name  Name of filesystem driver to find
263  */
264 extern tVFS_Driver      *VFS_GetFSByName(char *Name);
265 /**
266  * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
267  * \brief Transforms Unix Permssions into Acess ACLs
268  * \param Mode  Unix RWXrwxRWX mask
269  * \param Owner UID of the file's owner
270  * \param Group GID of the file's owning group
271  * \return An array of 3 Acess ACLs
272  */
273 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
274
275 // --- Node Cache --
276 /**
277  * \name Node Cache
278  * \brief Functions to allow a node to be cached in memory by the VFS
279  * 
280  * These functions store a node for the driver, to prevent it from having
281  * to re-generate the node on each call to FindDir. It also allows for
282  * fast cleanup when a filesystem is unmounted.
283  * \{
284  */
285 /**
286  * \fn int Inode_GetHandle()
287  * \brief Gets a unique handle to the Node Cache
288  * \return A unique handle for use for the rest of the Inode_* functions
289  */
290 extern int      Inode_GetHandle();
291 /**
292  * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
293  * \brief Gets an inode from the node cache
294  * \param Handle        A handle returned by Inode_GetHandle()
295  * \param Inode Value of the Inode field of the ::tVFS_Node you want
296  * \return A pointer to the cached node
297  */
298 extern tVFS_Node        *Inode_GetCache(int Handle, Uint64 Inode);
299 /**
300  * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
301  * \brief Caches a node in the Node Cache
302  * \param Handle        A handle returned by Inode_GetHandle()
303  * \param Node  A pointer to the node to be cached (a copy is taken)
304  * \return A pointer to the node in the node cache
305  */
306 extern tVFS_Node        *Inode_CacheNode(int Handle, tVFS_Node *Node);
307 /**
308  * \fn void Inode_UncacheNode(int Handle, Uint64 Inode)
309  * \brief Dereferences (and removes if needed) a node from the cache
310  * \param Handle        A handle returned by Inode_GetHandle()
311  * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
312  */
313 extern void     Inode_UncacheNode(int Handle, Uint64 Inode);
314 /**
315  * \fn void Inode_ClearCache(int Handle)
316  * \brief Clears the cache for a handle
317  * \param Handle        A handle returned by Inode_GetHandle()
318  */
319 extern void     Inode_ClearCache(int Handle);
320
321 /**
322  * \}
323  */
324
325 #endif

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