#ifndef _VFS_EXT_H
#define _VFS_EXT_H
+//! Inode number type
+typedef Uint64 tInode;
+
+//! Mountpoint identifier type
+typedef Uint32 tMount;
+
// === CONSTANTS ===
//! Maximum size of a Memory Path generated by VFS_GetMemPath
#define VFS_MEMPATH_SIZE (3 + (BITS/4)*2)
//! Marks a VFS handle as belonging to the kernel
#define VFS_KERNEL_FLAG 0x40000000
+//! Architectual maximum number of file descriptors
+#define MAX_FILE_DESCS 128
+
/**
* \brief VFS_Seek directions
*/
* \}
*/
+/**
+ * \brief MMap protection flags
+ * \{
+ */
+#define MMAP_PROT_READ 0x001 //!< Readable memory
+#define MMAP_PROT_WRITE 0x002 //!< Writable memory
+#define MMAP_PROT_EXEC 0x004 //!< Executable memory
+/**
+ * \}
+ */
+
+/**
+ * \brief MMap mapping flags
+ * \{
+ */
+#define MMAP_MAP_SHARED 0x001 //!< Shared with all other users of the FD
+#define MMAP_MAP_PRIVATE 0x002 //!< Local (COW) copy
+#define MMAP_MAP_FIXED 0x004 //!< Load to a fixed address
+#define MMAP_MAP_ANONYMOUS 0x008 //!< Not associated with a FD
+/**
+ * \}
+ */
+
// -- System Call Structures ---
/**
* \brief ACL Defintion Structure
unsigned Inv: 1; //!< Invert Permissions
unsigned Perms: 31; //!< Permission Flags
};
-} tVFS_ACL;
+} tVFS_ACL;
/**
* \brief SYS_FINFO structure
*/
typedef struct sFInfo
{
- Uint uid; //!< Owning User ID
- Uint gid; //!< Owning Group ID
- Uint flags; //!< File flags
+ tMount mount; //!< Mountpoint ID
+ tInode inode; //!< Inode
+ Uint32 uid; //!< Owning User ID
+ Uint32 gid; //!< Owning Group ID
+ Uint32 flags; //!< File flags
Uint64 size; //!< File Size
Sint64 atime; //!< Last Accessed time
Sint64 mtime; //!< Last modified time
Sint64 ctime; //!< Creation time
- int numacls; //!< Total number of ACL entries
+ Sint32 numacls; //!< Total number of ACL entries
tVFS_ACL acls[]; //!< ACL buffer (size is passed in the \a MaxACLs argument to VFS_FInfo)
-} tFInfo;
+} PACKED tFInfo;
+
+/**
+ * \brief fd_set for select()
+ */
+typedef struct
+{
+ //! Bitmap of set file descriptors
+ Uint16 flags[MAX_FILE_DESCS/16];
+} fd_set;
+
+/**
+ * \brief Clear a descriptor flag in a fd_set
+ * \param fd File descriptor to clear
+ * \param fdsetp Set to modify
+ */
+#define FD_CLR(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&=~(1<<((fd)%16)))
+/**
+ * \brief Set a descriptor flag in a fd_set
+ * \param fd File descriptor to set
+ * \param fdsetp Set to modify
+ */
+#define FD_SET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]|=~(1<<((fd)%16)))
+/**
+ * \brief Test a descriptor flag in a fd_set
+ * \param fd File descriptor to test
+ * \param fdsetp Set to modify
+ */
+#define FD_ISSET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&(1<<((fd)%16)))
// === FUNCTIONS ===
/**
* \return VFS Handle (an integer) or -1 if an error occured
*/
extern int VFS_Open(const char *Path, Uint Mode);
+/**
+ * \brief Opens a file via an open directory
+ * \note The file to open must be a direct child of the parent
+ * \param FD Parent Directory
+ * \param Name Child name
+ * \param Mode Open mode
+ * \return File handle (same as returned from VFS_Open)
+ */
+extern int VFS_OpenChild(int FD, const char *Name, Uint Mode);
+/**
+ * \brief Opens a file given a mount ID and an inode number
+ * \param Mount Mount ID returned by FInfo
+ * \param Inode Inode number from FInfo
+ * \param Mode Open mode (see VFS_Open)
+ * \return File handle (same as VFS_Open)
+ */
+extern int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode);
+
/**
* \brief Close a currently open file
* \param FD Handle returned by ::VFS_Open
* \param Dest New working directory (either absolute or relative to the current)
* \return Boolean Success
*/
-extern int VFS_ChDir(char *Dest);
+extern int VFS_ChDir(const char *Dest);
/**
* \brief Change the current virtual root for the user
* \param New New virtual root (same as ::VFS_ChDir but cannot go
* above the current virtual root)
* \return Boolean success
*/
-extern int VFS_ChRoot(char *New);
+extern int VFS_ChRoot(const char *New);
/**
* \brief Change the location of the current file pointer
*/
extern int VFS_ReadDir(int FD, char *Dest);
/**
- * \brief Opens a file via an open directory
- * \note The file to open must be a direct child of the parent
- * \param Errno Error number
- * \param FD Parent Directory
- * \param Name Child name
- * \param Mode Open mode
- * \return File handle (same as returned from VFS_Open)
+ * \brief Wait for an aciton on a file descriptor
+ * \param MaxHandle Maximum set handle in \a *Handles
+ * \param ReadHandles Handles to wait for data on
+ * \param WriteHandles Handles to wait to write to
+ * \param ErrHandles Handle to wait for errors on
+ * \param Timeout Timeout for select() (if null, there is no timeout), if zero select() is non blocking
+ * \param IsKernel Use kernel handles as opposed to user handles
+ * \return Number of handles that actioned
+ */
+extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel);
+
+/**
+ * \brief Map a file into memory
+ * \param DestHint Suggested place for read data
+ * \param Length Size of area to map
+ * \param Protection Protection type (see `man mmap`)
+ * \param Flags Mapping flags
+ * \param FD File descriptor to load from
+ * \param Offset Start of region
*/
-extern int VFS_OpenChild(Uint *Errno, int FD, const char *Name, Uint Mode);
+extern void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, Uint64 Offset);
+/**
+ * \brief Unmap memory allocated by VFS_MMap
+ * \param Addr Address of data to unmap
+ * \param Length Length of data
+ */
+extern int VFS_MUnmap(void *Addr, size_t Length);
#endif