Changed "common.h" to "acess.h" to reduce possible conflicts
[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         void    (*Close)(struct sVFS_Node *Node);
60         
61         /**
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
67          */
68          int    (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
69         
70         /**
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
77          */
78         Uint64  (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
79         /**
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
86          */
87         Uint64  (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
88         
89         /**
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.
96          */
97         struct sVFS_Node        *(*FindDir)(struct sVFS_Node *Node, char *Name);
98         
99         /**
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
105          *         will be returned.
106          *         If an item is required to be skipped either &::NULLNode,
107          *         ::VFS_SKIP or ::VFS_SKIPN(0...1023) will be returned.
108          */
109         char    *(*ReadDir)(struct sVFS_Node *Node, int Pos);
110         
111         /**
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
117          */
118          int    (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
119         
120         /**
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
126          */
127          int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
128 } tVFS_Node;
129
130 /**
131  * \brief VFS Driver (Filesystem) Definition
132  */
133 typedef struct sVFS_Driver
134 {
135         //! \brief Unique Identifier for this filesystem type
136         char    *Name;
137         //! \brief Flags applying to this driver
138         Uint    Flags;
139         
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;
146 } tVFS_Driver;
147
148 // === GLOBALS ===
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))
155
156 extern tVFS_Node        NULLNode;       //!< NULL VFS Node (Ignored/Skipped)
157 /**
158  * \name Simple ACLs to aid writing drivers
159  * \{
160  */
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
165 /**
166  * \}
167  */
168
169 // === FUNCTIONS ===
170 /**
171  * \fn int VFS_AddDriver(tVFS_Driver *Info)
172  * \brief Registers the driver with the DevFS layer
173  * \param Info  Driver information structure
174  */
175 extern int      VFS_AddDriver(tVFS_Driver *Info);
176 /**
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
180  */
181 extern tVFS_Driver      *VFS_GetFSByName(char *Name);
182 /**
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
189  */
190 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
191
192 // --- Node Cache --
193 //! \name Node Cache
194 //! \{
195 /**
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
199  */
200 extern int      Inode_GetHandle();
201 /**
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
207  */
208 extern tVFS_Node        *Inode_GetCache(int Handle, Uint64 Inode);
209 /**
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
215  */
216 extern tVFS_Node        *Inode_CacheNode(int Handle, tVFS_Node *Node);
217 /**
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
222  */
223 extern void     Inode_UncacheNode(int Handle, Uint64 Inode);
224 /**
225  * \fn void Inode_ClearCache(int Handle)
226  * \brief Clears the cache for a handle
227  * \param Handle        A handle returned by Inode_GetHandle()
228  */
229 extern void     Inode_ClearCache(int Handle);
230
231 //! \}
232
233 #endif

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