3 * \brief Exported VFS Definitions
4 * \author John Hodge (thePowersGang)
10 //! Maximum size of a Memory Path generated by VFS_GetMemPath
11 #define VFS_MEMPATH_SIZE (3 + (BITS/4)*2)
13 * \name Flags for VFS_Open
16 //! Open for execution
17 #define VFS_OPENFLAG_EXEC 0x01
19 #define VFS_OPENFLAG_READ 0x02
21 #define VFS_OPENFLAG_WRITE 0x04
22 //! Do not resolve the final symbolic link
23 #define VFS_OPENFLAG_NOLINK 0x40
25 #define VFS_OPENFLAG_USER 0x80
29 //! Marks a VFS handle as belonging to the kernel
30 #define VFS_KERNEL_FLAG 0x40000000
33 * \brief VFS_Seek directions
37 SEEK_SET = 1, //!< Set the current file offset
38 SEEK_CUR = 0, //!< Seek relative to the current position
39 SEEK_END = -1 //!< Seek from the end of the file backwards
43 * \name ACL Permissions
49 #define VFS_PERM_READ 0x00000001
53 #define VFS_PERM_WRITE 0x00000002
55 * \brief Append allowed
57 #define VFS_PERM_APPEND 0x00000004
61 #define VFS_PERM_EXECUTE 0x00000008
63 * \brief All permissions granted
65 #define VFS_PERM_ALL 0x7FFFFFFF // Mask for permissions
67 * \brief Denies instead of granting permissions
68 * \note Denials take precedence
70 #define VFS_PERM_DENY 0x80000000 // Inverts permissions
75 // -- System Call Structures ---
77 * \brief ACL Defintion Structure
79 typedef struct sVFS_ACL
82 unsigned Group: 1; //!< Group (as opposed to user) flag
83 unsigned ID: 31; //!< ID of Group/User (-1 for nobody/world)
86 unsigned Inv: 1; //!< Invert Permissions
87 unsigned Perms: 31; //!< Permission Flags
92 * \brief SYS_FINFO structure
96 Uint uid; //!< Owning User ID
97 Uint gid; //!< Owning Group ID
98 Uint flags; //!< File flags
99 Uint64 size; //!< File Size
100 Sint64 atime; //!< Last Accessed time
101 Sint64 mtime; //!< Last modified time
102 Sint64 ctime; //!< Creation time
103 int numacls; //!< Total number of ACL entries
104 tVFS_ACL acls[]; //!< ACL buffer (size is passed in the \a MaxACLs argument to VFS_FInfo)
109 * \brief Initialise the VFS (called by system.c)
110 * \return Boolean Success
112 extern int VFS_Init(void);
116 * \param Path Absolute or relative path to the file
117 * \param Mode Flags defining how to open the file
118 * \return VFS Handle (an integer) or -1 if an error occured
120 extern int VFS_Open(char *Path, Uint Mode);
122 * \brief Close a currently open file
123 * \param FD Handle returned by ::VFS_Open
125 extern void VFS_Close(int FD);
128 * \brief Get file information from an open file
129 * \param FD File handle returned by ::VFS_Open
130 * \param Dest Destination for the read information
131 * \param MaxACLs Number of ACL slots allocated in the \a Dest structure
132 * \return Boolean Success
134 * If the \a NumACLs is smaller than the number of ACLs the node has, only
135 * \a NumACLs will be copied into \a Dest, but the tFInfo.numacls field
136 * will be set to the true ammount of ACLs. It is up to the user to do with
137 * this information how they like.
139 extern int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs);
141 * \brief Gets the permissions appling to a user/group.
142 * \param FD File handle returned by ::VFS_Open
143 * \param Dest ACL information structure to edit
144 * \return Boolean success
146 * This function sets the tVFS_ACL.Inv and tVFS_ACL.Perms fields to what
147 * permissions the user/group specied in tVFS_ACL.ID has on the file.
149 extern int VFS_GetACL(int FD, tVFS_ACL *Dest);
151 * \brief Changes the user's current working directory
152 * \param Dest New working directory (either absolute or relative to the current)
153 * \return Boolean Success
155 extern int VFS_ChDir(char *Dest);
157 * \brief Change the current virtual root for the user
158 * \param New New virtual root (same as ::VFS_ChDir but cannot go
159 * above the current virtual root)
160 * \return Boolean success
162 extern int VFS_ChRoot(char *New);
165 * \brief Change the location of the current file pointer
166 * \param FD File handle returned by ::VFS_Open
167 * \param Offset Offset within the file to go to
168 * \param Direction A direction from ::eVFS_SeekDirs
169 * \return Boolean success
171 extern int VFS_Seek(int FD, Sint64 Offset, int Direction);
173 * \brief Returns the current file pointer
174 * \param FD File handle returned by ::VFS_Open
175 * \return Current file position
177 extern Uint64 VFS_Tell(int FD);
180 * \brief Reads data from a file
181 * \param FD File handle returned by ::VFS_Open
182 * \param Length Number of bytes to read from the file
183 * \param Buffer Destination of read data
184 * \return Number of read bytes
186 extern Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer);
188 * \brief Writes data to a file
189 * \param FD File handle returned by ::VFS_Open
190 * \param Length Number of bytes to write to the file
191 * \param Buffer Source of written data
192 * \return Number of bytes written
194 extern Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer);
197 * \brief Reads from a specific offset in the file
198 * \param FD File handle returned by ::VFS_Open
199 * \param Offset Byte offset in the file
200 * \param Length Number of bytes to read from the file
201 * \param Buffer Source of read data
202 * \return Number of bytes read
204 extern Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer);
206 * \brief Writes to a specific offset in the file
207 * \param FD File handle returned by ::VFS_Open
208 * \param Offset Byte offset in the file
209 * \param Length Number of bytes to write to the file
210 * \param Buffer Source of written data
211 * \return Number of bytes written
213 extern Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer);
216 * \brief Sends an IOCtl request to the driver
217 * \param FD File handle returned by ::VFS_Open
218 * \param ID IOCtl call ID (driver specific)
219 * \param Buffer Data pointer to send to the driver
220 * \return Driver specific response
222 extern int VFS_IOCtl(int FD, int ID, void *Buffer);
225 * \brief Creates a VFS Memory path from a pointer and size
226 * \param Dest Destination for the created path
227 * \param Base Base of the memory file
228 * \param Length Length of the memory buffer
229 * \note A maximum of VFS_MEMPATH_SIZE bytes will be required in \a Dest
231 extern void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
233 * \brief Gets the canoical (true) path of a file
234 * \param Path File path (may contain symlinks, relative elements etc.)
235 * \return Absolute path with no symlinks
237 extern char *VFS_GetTruePath(char *Path);
240 * \brief Mounts a filesystem
241 * \param Device Device to mount
242 * \param MountPoint Location to mount
243 * \param Filesystem Filesystem to use
244 * \param Options Options string to pass the driver
245 * \return 1 on succes, -1 on error
247 extern int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options);
249 * \brief Create a new directory
250 * \param Path Path to new directory (absolute or relative)
251 * \return Boolean success
252 * \note The parent of the directory must exist
254 extern int VFS_MkDir(char *Path);
256 * \brief Create a symbolic link
257 * \param Name Name of the symbolic link
258 * \param Link File the symlink points to
259 * \return Boolean success (\a Link is not tested for existence)
261 extern int VFS_Symlink(char *Name, char *Link);
263 * \brief Read from a directory
264 * \param FD File handle returned by ::VFS_Open
265 * \param Dest Destination array for the file name (max 255 bytes)
266 * \return Boolean Success
268 extern int VFS_ReadDir(int FD, char *Dest);
270 * \brief Opens a file via an open directory
271 * \note The file to open must be a direct child of the parent
272 * \param Errno Error number
273 * \param FD Parent Directory
274 * \param Name Child name
275 * \param Mode Open mode
276 * \return File handle (same as returned from VFS_Open)
278 extern int VFS_OpenChild(Uint *Errno, int FD, char *Name, Uint Mode);