3 * \brief Exported VFS Definitions
4 * \author John Hodge (thePowersGang)
10 typedef Uint32 tMount;
13 //! Maximum size of a Memory Path generated by VFS_GetMemPath
14 #define VFS_MEMPATH_SIZE (3 + (BITS/4)*2)
16 * \name Flags for VFS_Open
19 //! Open for execution
20 #define VFS_OPENFLAG_EXEC 0x01
22 #define VFS_OPENFLAG_READ 0x02
24 #define VFS_OPENFLAG_WRITE 0x04
25 //! Do not resolve the final symbolic link
26 #define VFS_OPENFLAG_NOLINK 0x40
28 #define VFS_OPENFLAG_USER 0x80
32 //! Marks a VFS handle as belonging to the kernel
33 #define VFS_KERNEL_FLAG 0x40000000
35 //! Architectual maximum number of file descriptors
36 #define MAX_FILE_DESCS 128
39 * \brief VFS_Seek directions
43 SEEK_SET = 1, //!< Set the current file offset
44 SEEK_CUR = 0, //!< Seek relative to the current position
45 SEEK_END = -1 //!< Seek from the end of the file backwards
49 * \name ACL Permissions
55 #define VFS_PERM_READ 0x00000001
59 #define VFS_PERM_WRITE 0x00000002
61 * \brief Append allowed
63 #define VFS_PERM_APPEND 0x00000004
67 #define VFS_PERM_EXECUTE 0x00000008
69 * \brief All permissions granted
71 #define VFS_PERM_ALL 0x7FFFFFFF // Mask for permissions
73 * \brief Denies instead of granting permissions
74 * \note Denials take precedence
76 #define VFS_PERM_DENY 0x80000000 // Inverts permissions
81 #define MMAP_PROT_READ 0x001
82 #define MMAP_PROT_WRITE 0x002
83 #define MMAP_PROT_EXEC 0x004
85 #define MMAP_MAP_SHARED 0x001
86 #define MMAP_MAP_PRIVATE 0x002
87 #define MMAP_MAP_FIXED 0x004
88 #define MMAP_MAP_ANONYMOUS 0x008
90 // -- System Call Structures ---
92 * \brief ACL Defintion Structure
94 typedef struct sVFS_ACL
97 unsigned Group: 1; //!< Group (as opposed to user) flag
98 unsigned ID: 31; //!< ID of Group/User (-1 for nobody/world)
101 unsigned Inv: 1; //!< Invert Permissions
102 unsigned Perms: 31; //!< Permission Flags
107 * \brief SYS_FINFO structure
109 typedef struct sFInfo
111 tMount mount; //!< Mountpoint ID
112 tInode inode; //!< Inode
113 Uint32 uid; //!< Owning User ID
114 Uint32 gid; //!< Owning Group ID
115 Uint32 flags; //!< File flags
116 Uint64 size; //!< File Size
117 Sint64 atime; //!< Last Accessed time
118 Sint64 mtime; //!< Last modified time
119 Sint64 ctime; //!< Creation time
120 Sint32 numacls; //!< Total number of ACL entries
121 tVFS_ACL acls[]; //!< ACL buffer (size is passed in the \a MaxACLs argument to VFS_FInfo)
125 * \brief fd_set for select()
129 Uint16 flags[MAX_FILE_DESCS/16];
132 #define FD_CLR(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&=~(1<<((fd)%16)))
133 #define FD_SET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]|=~(1<<((fd)%16)))
134 #define FD_ISSET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&(1<<((fd)%16)))
138 * \brief Initialise the VFS (called by system.c)
139 * \return Boolean Success
141 extern int VFS_Init(void);
145 * \param Path Absolute or relative path to the file
146 * \param Mode Flags defining how to open the file
147 * \return VFS Handle (an integer) or -1 if an error occured
149 extern int VFS_Open(const char *Path, Uint Mode);
151 * \brief Opens a file via an open directory
152 * \note The file to open must be a direct child of the parent
153 * \param FD Parent Directory
154 * \param Name Child name
155 * \param Mode Open mode
156 * \return File handle (same as returned from VFS_Open)
158 extern int VFS_OpenChild(int FD, const char *Name, Uint Mode);
160 * \brief Opens a file given a mount ID and an inode number
161 * \param Mount Mount ID returned by FInfo
162 * \param Inode Inode number from FInfo
163 * \param Mode Open mode (see VFS_Open)
164 * \return File handle (same as VFS_Open)
166 extern int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode);
169 * \brief Close a currently open file
170 * \param FD Handle returned by ::VFS_Open
172 extern void VFS_Close(int FD);
175 * \brief Get file information from an open file
176 * \param FD File handle returned by ::VFS_Open
177 * \param Dest Destination for the read information
178 * \param MaxACLs Number of ACL slots allocated in the \a Dest structure
179 * \return Boolean Success
181 * If the \a NumACLs is smaller than the number of ACLs the node has, only
182 * \a NumACLs will be copied into \a Dest, but the tFInfo.numacls field
183 * will be set to the true ammount of ACLs. It is up to the user to do with
184 * this information how they like.
186 extern int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs);
188 * \brief Gets the permissions appling to a user/group.
189 * \param FD File handle returned by ::VFS_Open
190 * \param Dest ACL information structure to edit
191 * \return Boolean success
193 * This function sets the tVFS_ACL.Inv and tVFS_ACL.Perms fields to what
194 * permissions the user/group specied in tVFS_ACL.ID has on the file.
196 extern int VFS_GetACL(int FD, tVFS_ACL *Dest);
198 * \brief Changes the user's current working directory
199 * \param Dest New working directory (either absolute or relative to the current)
200 * \return Boolean Success
202 extern int VFS_ChDir(const char *Dest);
204 * \brief Change the current virtual root for the user
205 * \param New New virtual root (same as ::VFS_ChDir but cannot go
206 * above the current virtual root)
207 * \return Boolean success
209 extern int VFS_ChRoot(const char *New);
212 * \brief Change the location of the current file pointer
213 * \param FD File handle returned by ::VFS_Open
214 * \param Offset Offset within the file to go to
215 * \param Whence A direction from ::eVFS_SeekDirs
216 * \return Boolean success
218 extern int VFS_Seek(int FD, Sint64 Offset, int Whence);
220 * \brief Returns the current file pointer
221 * \param FD File handle returned by ::VFS_Open
222 * \return Current file position
224 extern Uint64 VFS_Tell(int FD);
227 * \brief Reads data from a file
228 * \param FD File handle returned by ::VFS_Open
229 * \param Length Number of bytes to read from the file
230 * \param Buffer Destination of read data
231 * \return Number of read bytes
233 extern Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer);
235 * \brief Writes data to a file
236 * \param FD File handle returned by ::VFS_Open
237 * \param Length Number of bytes to write to the file
238 * \param Buffer Source of written data
239 * \return Number of bytes written
241 extern Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer);
244 * \brief Reads from a specific offset in the file
245 * \param FD File handle returned by ::VFS_Open
246 * \param Offset Byte offset in the file
247 * \param Length Number of bytes to read from the file
248 * \param Buffer Source of read data
249 * \return Number of bytes read
251 extern Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer);
253 * \brief Writes to a specific offset in the file
254 * \param FD File handle returned by ::VFS_Open
255 * \param Offset Byte offset in the file
256 * \param Length Number of bytes to write to the file
257 * \param Buffer Source of written data
258 * \return Number of bytes written
260 extern Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer);
263 * \brief Sends an IOCtl request to the driver
264 * \param FD File handle returned by ::VFS_Open
265 * \param ID IOCtl call ID (driver specific)
266 * \param Buffer Data pointer to send to the driver
267 * \return Driver specific response
269 extern int VFS_IOCtl(int FD, int ID, void *Buffer);
272 * \brief Creates a VFS Memory path from a pointer and size
273 * \param Dest Destination for the created path
274 * \param Base Base of the memory file
275 * \param Length Length of the memory buffer
276 * \note A maximum of VFS_MEMPATH_SIZE bytes will be required in \a Dest
278 extern void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
280 * \brief Gets the canoical (true) path of a file
281 * \param Path File path (may contain symlinks, relative elements etc.)
282 * \return Absolute path with no symlinks
284 extern char *VFS_GetTruePath(const char *Path);
287 * \brief Mounts a filesystem
288 * \param Device Device to mount
289 * \param MountPoint Location to mount
290 * \param Filesystem Filesystem to use
291 * \param Options Options string to pass the driver
292 * \return 1 on succes, -1 on error
294 extern int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
296 * \brief Create a new directory
297 * \param Path Path to new directory (absolute or relative)
298 * \return Boolean success
299 * \note The parent of the directory must exist
301 extern int VFS_MkDir(const char *Path);
303 * \brief Create a symbolic link
304 * \param Name Name of the symbolic link
305 * \param Link File the symlink points to
306 * \return Boolean success (\a Link is not tested for existence)
308 extern int VFS_Symlink(const char *Name, const char *Link);
310 * \brief Read from a directory
311 * \param FD File handle returned by ::VFS_Open
312 * \param Dest Destination array for the file name (max 255 bytes)
313 * \return Boolean Success
315 extern int VFS_ReadDir(int FD, char *Dest);
317 * \brief Wait for an aciton on a file descriptor
318 * \param MaxHandle Maximum set handle in \a *Handles
319 * \param ReadHandles Handles to wait for data on
320 * \param WriteHandles Handles to wait to write to
321 * \param ErrHandles Handle to wait for errors on
322 * \param Timeout Timeout for select() (if null, there is no timeout), if zero select() is non blocking
323 * \param IsKernel Use kernel handles as opposed to user handles
324 * \return Number of handles that actioned
326 extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel);
329 * \brief Map a file into memory
330 * \param DestHint Suggested place for read data
331 * \param Length Size of area to map
332 * \param Protection Protection type (see `man mmap`)
333 * \param Flags Mapping flags
334 * \param FD File descriptor to load from
335 * \param Offset Start of region
337 extern void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, Uint64 Offset);
340 * \brief Unmap memory allocated by VFS_MMap
341 * \param ErrNo Error status pointer
342 * \param Addr Address of data to unmap
343 * \param Length Length of data
345 extern int VFS_MUnmap(void *Addr, size_t Length);