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

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