Cleanups & Implementations to allow IPStack to compile
[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  * \name VFS Node Flags
45  * \{
46  */
47 #define VFS_FFLAG_READONLY      0x01    //!< Read-only file
48 #define VFS_FFLAG_DIRECTORY     0x02    //!< Directory
49 #define VFS_FFLAG_SYMLINK       0x04    //!< Symbolic Link
50 /**
51  * \}
52  */
53
54 /**
55  * \brief VFS Node
56  */
57 typedef struct sVFS_Node {      
58         Uint64  Inode;  //!< Inode ID
59         Uint    ImplInt;        //!< Implementation Usable Integer
60         void    *ImplPtr;       //!< Implementation Usable Pointer
61         
62          int    ReferenceCount; //!< Number of times the node is used
63         
64         Uint64  Size;   //!< File Size
65         
66         Uint32  Flags;  //!< File Flags
67         
68         Sint64  ATime;  //!< Last Accessed Time
69         Sint64  MTime;  //!< Last Modified Time
70         Sint64  CTime;  //!< Creation Time
71         
72         Uint    UID;    //!< Owning User
73         Uint    GID;    //!< Owning Group
74         
75          int    NumACLs;        //!< Number of ACL entries
76         tVFS_ACL        *ACLs;  //!< ACL Entries
77         
78         //! Reference the node
79         void    (*Reference)(struct sVFS_Node *Node);
80         //! Close (dereference) the node
81         void    (*Close)(struct sVFS_Node *Node);
82         //! Send an IO Control
83          int    (*IOCtl)(struct sVFS_Node *Node, int Id, void *Data);
84         
85         //! \brief Read from the file
86         Uint64  (*Read)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
87         //! \brief Write to the file
88         Uint64  (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
89         
90         //! \brief Find an directory entry by name
91         //! \note The node returned must be accessable until ::tVFS_Node.Close is called
92         struct sVFS_Node        *(*FindDir)(struct sVFS_Node *Node, char *Name);
93         
94         //! \brief Read from a directory
95         //! \note MUST return a heap address
96         char    *(*ReadDir)(struct sVFS_Node *Node, int Pos);
97         
98         //! \brief Create a node in a directory
99          int    (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags);
100         
101         //! \brief Relink (Rename/Remove) a file/directory
102          int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
103         
104         //!< \todo Complete
105 } tVFS_Node;
106
107 /**
108  * \brief VFS Driver (Filesystem) Definition
109  */
110 typedef struct sVFS_Driver
111 {
112         //! \brief Unique Identifier for this filesystem type
113         char    *Name;
114         //! \brief Flags applying to this driver
115         Uint    Flags;
116         
117         //! \brief Callback to mount a device
118         tVFS_Node       *(*InitDevice)(char *Device, char **Options);
119         //! \brief Callback to unmount a device
120         void    (*Unmount)(tVFS_Node *Node);
121         //! \brief Used internally (next driver in the chain)
122         struct sVFS_Driver      *Next;
123 } tVFS_Driver;
124
125 // === GLOBALS ===
126 //! \brief Maximum number of elements that can be skipped in one return
127 #define VFS_MAXSKIP     ((void*)1024)
128 //! \brief Skip a single entry in readdir
129 #define VFS_SKIP        ((void*)1)
130 //! \brief Skip \a n entries in readdir
131 #define VFS_SKIPN(n)    ((void*)(n))
132
133 extern tVFS_Node        NULLNode;       //!< NULL VFS Node (Ignored/Skipped)
134 /**
135  * \name Simple ACLs to aid writing drivers
136  * \{
137  */
138 extern tVFS_ACL gVFS_ACL_EveryoneRWX;   //!< Everyone Read/Write/Execute
139 extern tVFS_ACL gVFS_ACL_EveryoneRW;    //!< Everyone Read/Write
140 extern tVFS_ACL gVFS_ACL_EveryoneRX;    //!< Everyone Read/Execute
141 extern tVFS_ACL gVFS_ACL_EveryoneRO;    //!< Everyone Read only
142 /**
143  * \}
144  */
145
146 // === FUNCTIONS ===
147 /**
148  * \fn int VFS_AddDriver(tVFS_Driver *Info)
149  * \brief Registers the driver with the DevFS layer
150  * \param Info  Driver information structure
151  */
152 extern int      VFS_AddDriver(tVFS_Driver *Info);
153 /**
154  * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
155  * \brief Get the information structure of a driver given its name
156  * \param Name  Name of filesystem driver to find
157  */
158 extern tVFS_Driver      *VFS_GetFSByName(char *Name);
159 /**
160  * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
161  * \brief Transforms Unix Permssions into Acess ACLs
162  * \param Mode  Unix RWXrwxRWX mask
163  * \param Owner UID of the file's owner
164  * \param Group GID of the file's owning group
165  * \return An array of 3 Acess ACLs
166  */
167 extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
168
169 // --- Node Cache --
170 //! \name Node Cache
171 //! \{
172 /**
173  * \fn int Inode_GetHandle()
174  * \brief Gets a unique handle to the Node Cache
175  * \return A unique handle for use for the rest of the Inode_* functions
176  */
177 extern int      Inode_GetHandle();
178 /**
179  * \fn tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode)
180  * \brief Gets an inode from the node cache
181  * \param Handle        A handle returned by Inode_GetHandle()
182  * \param Inode Value of the Inode field of the ::tVFS_Node you want
183  * \return A pointer to the cached node
184  */
185 extern tVFS_Node        *Inode_GetCache(int Handle, Uint64 Inode);
186 /**
187  * \fn tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node)
188  * \brief Caches a node in the Node Cache
189  * \param Handle        A handle returned by Inode_GetHandle()
190  * \param Node  A pointer to the node to be cached (a copy is taken)
191  * \return A pointer to the node in the node cache
192  */
193 extern tVFS_Node        *Inode_CacheNode(int Handle, tVFS_Node *Node);
194 /**
195  * \fn void Inode_UncacheNode(int Handle, Uint64 Inode)
196  * \brief Dereferences (and removes if needed) a node from the cache
197  * \param Handle        A handle returned by Inode_GetHandle()
198  * \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
199  */
200 extern void     Inode_UncacheNode(int Handle, Uint64 Inode);
201 /**
202  * \fn void Inode_ClearCache(int Handle)
203  * \brief Clears the cache for a handle
204  * \param Handle        A handle returned by Inode_GetHandle()
205  */
206 extern void     Inode_ClearCache(int Handle);
207
208 //! \}
209
210 #endif

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