Kernel[Tegra2] - Messing about debugging tegra stuff
[tpg/acess2.git] / KernelLand / Kernel / include / vfs_ext.h
1 /**
2  * \file vfs_ext.h
3  * \brief Exported VFS Definitions
4  * \author John Hodge (thePowersGang)
5  */
6 #ifndef _VFS_EXT_H
7 #define _VFS_EXT_H
8
9 //! Inode number type
10 typedef Uint64  tInode;
11
12 //! Mountpoint identifier type
13 typedef Uint32  tMount;
14
15 // === CONSTANTS ===
16 #define FILENAME_MAX    256
17 //! Maximum size of a Memory Path generated by VFS_GetMemPath
18 #define VFS_MEMPATH_SIZE        (3 + (BITS/4)*2)
19 /**
20  * \name Flags for VFS_Open
21  * \{
22  */
23 //! Open for execution
24 #define VFS_OPENFLAG_EXEC       0x01
25 //! Open for reading
26 #define VFS_OPENFLAG_READ       0x02
27 //! Open for writing
28 #define VFS_OPENFLAG_WRITE      0x04
29 //! Do not resolve the final symbolic link
30 #define VFS_OPENFLAG_NOLINK     0x40
31 //! Create the file if it doesn't exist
32 #define VFS_OPENFLAG_CREATE     0x80
33 //! Treat as a directory
34 #define VFS_OPENFLAG_DIRECTORY  0x100
35 //! Open as a user
36 #define VFS_OPENFLAG_USER       0x8000
37 /**
38  * \}
39  */
40 //! Marks a VFS handle as belonging to the kernel
41 #define VFS_KERNEL_FLAG 0x40000000
42
43 //! Architectual maximum number of file descriptors
44 #define MAX_FILE_DESCS  128
45
46 /**
47  * \brief VFS_Seek directions
48  */
49 enum eVFS_SeekDirs
50 {
51         SEEK_SET = 1,   //!< Set the current file offset
52         SEEK_CUR = 0,   //!< Seek relative to the current position
53         SEEK_END = -1   //!< Seek from the end of the file backwards
54 };
55
56 /**
57  * \name ACL Permissions
58  * \{
59  */
60 /**
61  * \brief Readable
62  */
63 #define VFS_PERM_READ   0x00000001
64 /**
65  * \brief Writeable
66  */
67 #define VFS_PERM_WRITE  0x00000002
68 /**
69  * \brief Append allowed
70  */
71 #define VFS_PERM_APPEND 0x00000004
72 /**
73  * \brief Executable
74  */
75 #define VFS_PERM_EXECUTE        0x00000008
76 /**
77  * \brief All permissions granted
78  */
79 #define VFS_PERM_ALL    0x7FFFFFFF      // Mask for permissions
80 /**
81  * \brief Denies instead of granting permissions
82  * \note Denials take precedence
83  */
84 #define VFS_PERM_DENY   0x80000000      // Inverts permissions
85 /**
86  * \}
87  */
88
89 /**
90  * \brief MMap protection flags
91  * \{
92  */
93 #define MMAP_PROT_READ  0x001   //!< Readable memory
94 #define MMAP_PROT_WRITE 0x002   //!< Writable memory
95 #define MMAP_PROT_EXEC  0x004   //!< Executable memory
96 /**
97  * \}
98  */
99
100 /**
101  * \brief MMap mapping flags
102  * \{
103  */
104 #define MMAP_MAP_SHARED         0x001   //!< Shared with all other users of the FD
105 #define MMAP_MAP_PRIVATE        0x002   //!< Local (COW) copy
106 #define MMAP_MAP_FIXED          0x004   //!< Load to a fixed address
107 #define MMAP_MAP_ANONYMOUS      0x008   //!< Not associated with a FD
108 /**
109  * \}
110  */
111
112 // -- System Call Structures ---
113 /**
114  * \brief ACL Defintion Structure
115  */
116 typedef struct sVFS_ACL
117 {
118         struct {
119                 unsigned Group: 1;      //!< Group (as opposed to user) flag
120                 unsigned ID:    31;     //!< ID of Group/User (-1 for nobody/world)
121         } Ent;
122         struct {
123                 unsigned Inv:   1;      //!< Invert Permissions
124                 unsigned Perms: 31;     //!< Permission Flags
125         } Perm;
126 } tVFS_ACL;
127
128 /**
129  * \brief SYS_FINFO structure
130  */
131 typedef struct sFInfo
132 {
133         tMount  mount;  //!< Mountpoint ID
134         tInode  inode;  //!< Inode
135         Uint32  uid;    //!< Owning User ID
136         Uint32  gid;    //!< Owning Group ID
137         Uint32  flags;  //!< File flags
138         Uint64  size;   //!< File Size
139         Sint64  atime;  //!< Last Accessed time
140         Sint64  mtime;  //!< Last modified time
141         Sint64  ctime;  //!< Creation time
142         Sint32  numacls;        //!< Total number of ACL entries
143         tVFS_ACL        acls[]; //!< ACL buffer (size is passed in the \a MaxACLs argument to VFS_FInfo)
144 } PACKED tFInfo;
145
146 // --- fd_set --
147 #include "../../../Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h"
148
149 #if 0
150 /**
151  * \brief fd_set for select()
152  */
153 typedef struct
154 {
155         //! Bitmap of set file descriptors
156         Uint16  flags[MAX_FILE_DESCS/16];
157 }       fd_set;
158
159 /**
160  * \brief Clear a descriptor flag in a fd_set
161  * \param fd    File descriptor to clear
162  * \param fdsetp        Set to modify
163  */
164 #define FD_CLR(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&=~(1<<((fd)%16)))
165 /**
166  * \brief Set a descriptor flag in a fd_set
167  * \param fd    File descriptor to set
168  * \param fdsetp        Set to modify
169  */
170 #define FD_SET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]|=~(1<<((fd)%16)))
171 /**
172  * \brief Test a descriptor flag in a fd_set
173  * \param fd    File descriptor to test
174  * \param fdsetp        Set to modify
175  */
176 #define FD_ISSET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&(1<<((fd)%16)))
177 #endif
178
179 // === FUNCTIONS ===
180 /**
181  * \brief Initialise the VFS (called by system.c)
182  * \return Boolean Success
183  */
184 extern int      VFS_Init(void);
185
186 /**
187  * \brief Open a file
188  * \param Path  Absolute or relative path to the file
189  * \param Flags Flags defining how to open the file
190  * \return VFS Handle (an integer) or -1 if an error occured
191  * \note Calls VFS_OpenEx(Path, Flags, 0)
192  */
193 extern int      VFS_Open(const char *Path, Uint Flags);
194 /**
195  * \brief Open a file
196  * \param Path  Absolute or relative path to the file
197  * \param Flags Flags defining how to open the file
198  * \param Mode  Mode for newly created file (POSIX compatability)
199  * \return VFS Handle (an integer) or -1 if an error occured
200  */
201 extern int      VFS_OpenEx(const char *Path, Uint Flags, Uint Mode);
202 /**
203  * \brief Opens a file via an open directory
204  * \note The file to open must be a direct child of the parent
205  * \param FD    Parent Directory
206  * \param Name  Child name
207  * \param Mode  Open mode
208  * \return File handle (same as returned from VFS_Open)
209  */
210 extern int      VFS_OpenChild(int FD, const char *Name, Uint Mode);
211 /**
212  * \brief Opens a file given a mount ID and an inode number
213  * \param Mount Mount ID returned by FInfo
214  * \param Inode Inode number from FInfo
215  * \param Mode  Open mode (see VFS_Open)
216  * \return File handle (same as VFS_Open)
217  */
218 extern int      VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode);
219
220 /**
221  * \brief Close a currently open file
222  * \param FD    Handle returned by ::VFS_Open
223  */
224 extern void     VFS_Close(int FD);
225
226 /**
227  * \brief Get file information from an open file
228  * \param FD    File handle returned by ::VFS_Open
229  * \param Dest  Destination for the read information
230  * \param MaxACLs       Number of ACL slots allocated in the \a Dest structure
231  * \return Boolean Success
232  * 
233  * If the \a NumACLs is smaller than the number of ACLs the node has, only
234  * \a NumACLs will be copied into \a Dest, but the tFInfo.numacls field
235  * will be set to the true ammount of ACLs. It is up to the user to do with
236  * this information how they like.
237  */
238 extern int      VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs);
239 /**
240  * \brief Gets the permissions appling to a user/group.
241  * \param FD    File handle returned by ::VFS_Open
242  * \param Dest  ACL information structure to edit
243  * \return Boolean success
244  * 
245  * This function sets the tVFS_ACL.Inv and tVFS_ACL.Perms fields to what
246  * permissions the user/group specied in tVFS_ACL.ID has on the file.
247  */
248 extern int      VFS_GetACL(int FD, tVFS_ACL *Dest);
249 /**
250  * \brief Changes the user's current working directory
251  * \param Dest  New working directory (either absolute or relative to the current)
252  * \return Boolean Success
253  */
254 extern int      VFS_ChDir(const char *Dest);
255 /**
256  * \brief Change the current virtual root for the user
257  * \param New New virtual root (same as ::VFS_ChDir but cannot go
258  *            above the current virtual root)
259  * \return Boolean success
260  */
261 extern int      VFS_ChRoot(const char *New);
262
263 /**
264  * \brief Change the location of the current file pointer
265  * \param FD    File handle returned by ::VFS_Open
266  * \param Offset        Offset within the file to go to
267  * \param Whence        A direction from ::eVFS_SeekDirs
268  * \return Boolean success
269  */
270 extern int      VFS_Seek(int FD, Sint64 Offset, int Whence);
271 /**
272  * \brief Returns the current file pointer
273  * \param FD    File handle returned by ::VFS_Open
274  * \return Current file position
275  */
276 extern Uint64   VFS_Tell(int FD);
277
278 /**
279  * \brief Reads data from a file
280  * \param FD    File handle returned by ::VFS_Open
281  * \param Length        Number of bytes to read from the file
282  * \param Buffer        Destination of read data
283  * \return Number of read bytes
284  */
285 extern size_t   VFS_Read(int FD, size_t Length, void *Buffer);
286 /**
287  * \brief Writes data to a file
288  * \param FD    File handle returned by ::VFS_Open
289  * \param Length        Number of bytes to write to the file
290  * \param Buffer        Source of written data
291  * \return Number of bytes written
292  */
293 extern size_t   VFS_Write(int FD, size_t Length, const void *Buffer);
294
295 /**
296  * \brief Reads from a specific offset in the file
297  * \param FD    File handle returned by ::VFS_Open
298  * \param Offset        Byte offset in the file
299  * \param Length        Number of bytes to read from the file
300  * \param Buffer        Source of read data
301  * \return Number of bytes read
302  */
303 extern size_t   VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer);
304 /**
305  * \brief Writes to a specific offset in the file
306  * \param FD    File handle returned by ::VFS_Open
307  * \param Offset        Byte offset in the file
308  * \param Length        Number of bytes to write to the file
309  * \param Buffer        Source of written data
310  * \return Number of bytes written
311  */
312 extern size_t   VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer);
313
314 /**
315  * \brief Sends an IOCtl request to the driver
316  * \param FD    File handle returned by ::VFS_Open
317  * \param ID    IOCtl call ID (driver specific)
318  * \param Buffer        Data pointer to send to the driver
319  * \return Driver specific response
320  */
321 extern int      VFS_IOCtl(int FD, int ID, void *Buffer);
322
323 /**
324  * \brief Creates a VFS Memory path from a pointer and size
325  * \param Dest  Destination for the created path
326  * \param Base  Base of the memory file
327  * \param Length        Length of the memory buffer
328  * \note A maximum of VFS_MEMPATH_SIZE bytes will be required in \a Dest
329  */
330 extern void     VFS_GetMemPath(char *Dest, void *Base, Uint Length);
331 /**
332  * \brief Gets the canoical (true) path of a file
333  * \param Path  File path (may contain symlinks, relative elements etc.)
334  * \return Absolute path with no symlinks
335  */
336 extern char     *VFS_GetTruePath(const char *Path);
337
338 /**
339  * \brief Mounts a filesystem
340  * \param Device        Device to mount
341  * \param MountPoint    Location to mount
342  * \param Filesystem    Filesystem to use
343  * \param Options       Options string to pass the driver
344  * \return 1 on succes, -1 on error
345  */
346 extern int      VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
347 /**
348  * \brief Unmount a mounted filesystem
349  * \param Mountpoint    Location of the mount
350  * \return 0 on success, errno on error
351  */
352 extern int      VFS_Unmount(const char *Mountpoint);
353 /**
354  * \brief Attemt to unmount all fileystems
355  * \return Number of unmounted filesytems, -1 if none left to unmount
356  * \note Can return 0 when there are stil volumes mounted if there are open handles
357  */
358 extern int      VFS_UnmountAll(void);
359
360 /**
361  * \brief Create a new directory
362  * \param Path  Path to new directory (absolute or relative)
363  * \return Boolean success
364  * \note The parent of the directory must exist
365  */
366 extern int      VFS_MkDir(const char *Path);
367 /**
368  * \brief Create a symbolic link
369  * \param Name  Name of the symbolic link
370  * \param Link  File the symlink points to
371  * \return Boolean success (\a Link is not tested for existence)
372  */
373 extern int      VFS_Symlink(const char *Name, const char *Link);
374 /**
375  * \brief Read from a directory
376  * \param FD    File handle returned by ::VFS_Open
377  * \param Dest  Destination array for the file name (max FILENAME_MAX bytes)
378  * \return Boolean Success
379  */
380 extern int      VFS_ReadDir(int FD, char Dest[FILENAME_MAX]);
381 /**
382  * \brief Wait for an aciton on a file descriptor
383  * \param MaxHandle     Maximum set handle in \a *Handles
384  * \param ReadHandles   Handles to wait for data on
385  * \param WriteHandles  Handles to wait to write to
386  * \param ErrHandles    Handle to wait for errors on
387  * \param Timeout       Timeout for select() (if null, there is no timeout), if zero select() is non blocking
388  * \param ExtraEvents   Extra event set to wait on
389  * \param IsKernel      Use kernel handles as opposed to user handles
390  * \return Number of handles that actioned
391  */
392 extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, Uint32 ExtraEvents, BOOL IsKernel);
393
394 /**
395  * \brief Map a file into memory
396  * \param DestHint      Suggested place for read data
397  * \param Length        Size of area to map
398  * \param Protection    Protection type (see `man mmap`)
399  * \param Flags Mapping flags
400  * \param FD    File descriptor to load from
401  * \param Offset        Start of region
402  */
403 extern void     *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, Uint64 Offset);
404
405 /**
406  * \brief Unmap memory allocated by VFS_MMap
407  * \param Addr  Address of data to unmap
408  * \param Length        Length of data
409  */
410 extern int      VFS_MUnmap(void *Addr, size_t Length);
411 #endif

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