Added IO Cache Library, Moved FDD Driver to Modules Tree, Fixed Doxygen commenting
[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 <common.h>
13
14 //! \name ACL Permissions
15 //! \{
16 /**
17  * \brief Readable
18  */
19 #define VFS_PERM_READ   0x00000001
20 /**
21  * \brief Writeable
22  */
23 #define VFS_PERM_WRITE  0x00000002
24 /**
25  * \brief Append allowed
26  */
27 #define VFS_PERM_APPEND 0x00000004
28 /**
29  * \brief Executable
30  */
31 #define VFS_PERM_EXECUTE        0x00000008
32 /**
33  * \brief All permissions granted
34  */
35 #define VFS_PERM_ALL    0x7FFFFFFF      // Mask for permissions
36 /**
37  * \brief Denies instead of granting permissions
38  * \note Denials take precedence
39  */
40 #define VFS_PERM_DENY   0x80000000      // Inverts permissions
41 //! \}
42
43 /**
44  * \brief ACL Defintion Structure
45  */
46 typedef struct sVFS_ACL
47 {
48         struct {
49                 unsigned Group: 1;      //!< Group (as opposed to user) flag
50                 unsigned ID:    31;     //!< ID of Group/User (-1 for nobody/world)
51         };
52         struct {
53                 unsigned Inv:   1;      //!< Invert Permissions
54                 unsigned Perms: 31;     //!< Permission Flags
55         };
56 } tVFS_ACL;
57
58 /**
59  * \name VFS Node Flags
60  * \{
61  */
62 #define VFS_FFLAG_READONLY      0x01    //!< Read-only file
63 #define VFS_FFLAG_DIRECTORY     0x02    //!< Directory
64 #define VFS_FFLAG_SYMLINK       0x04    //!< Symbolic Link
65 /**
66  * \}
67  */
68
69 /**
70  * \brief VFS Node
71  */
72 typedef struct sVFS_Node {      
73         Uint64  Inode;  //!< Inode ID
74         Uint    ImplInt;        //!< Implementation Usable Integer
75         void    *ImplPtr;       //!< Implementation Usable Pointer
76         
77          int    ReferenceCount; //!< Number of times the node is used
78         
79         Uint64  Size;   //!< File Size
80         
81         Uint32  Flags;  //!< File Flags
82         
83         Sint64  ATime;  //!< Last Accessed Time
84         Sint64  MTime;  //!< Last Modified Time
85         Sint64  CTime;  //!< Creation Time
86         
87         Uint    UID;    //!< Owning User
88         Uint    GID;    //!< Owning Group
89         
90          int    NumACLs;        //!< Number of ACL entries
91         tVFS_ACL        *ACLs;  //!< ACL Entries
92         
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);
99         
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);
104         
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);
108         
109         //! \brief Read from a directory
110         //! \note MUST return a heap address
111         char    *(*ReadDir)(struct sVFS_Node *Node, int Pos);
112         
113         //! \brief Create a node in a directory
114          int    (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
115         
116         //! \brief Relink (Rename/Remove) a file/directory
117          int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
118         
119         //!< \todo Complete
120 } tVFS_Node;
121
122 /**
123  * \brief VFS Driver (Filesystem) Definition
124  */
125 typedef struct sVFS_Driver
126 {
127         //! \brief Unique Identifier for this filesystem type
128         char    *Name;
129         //! \brief Flags applying to this driver
130         Uint    Flags;
131         
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;
138 } tVFS_Driver;
139
140 // === GLOBALS ===
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))
147
148 extern tVFS_Node        NULLNode;       //!< NULL VFS Node (Ignored/Skipped)
149 /**
150  * \name Simple ACLs to aid writing drivers
151  * \{
152  */
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
157 /**
158  * \}
159  */
160
161 // === FUNCTIONS ===
162 /**
163  * \fn int VFS_AddDriver(tVFS_Driver *Info)
164  * \brief Registers the driver with the DevFS layer
165  * \param Info  Driver information structure
166  */
167 extern int      VFS_AddDriver(tVFS_Driver *Info);
168 /**
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
172  */
173 extern tVFS_Driver      *VFS_GetFSByName(char *Name);
174 /**
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
181  */
182 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
183
184 // --- Node Cache --
185 //! \name Node Cache
186 //! \{
187 /**
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
191  */
192 extern int      Inode_GetHandle();
193 /**
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
199  */
200 extern tVFS_Node        *Inode_GetCache(int Handle, Uint64 Inode);
201 /**
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
207  */
208 extern tVFS_Node        *Inode_CacheNode(int Handle, tVFS_Node *Node);
209 /**
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
214  */
215 extern void     Inode_UncacheNode(int Handle, Uint64 Inode);
216 /**
217  * \fn void Inode_ClearCache(int Handle)
218  * \brief Clears the cache for a handle
219  * \param Handle        A handle returned by Inode_GetHandle()
220  */
221 extern void     Inode_ClearCache(int Handle);
222
223 //! \}
224
225 #endif

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