/* * fileio.h * * Created on: Aug 23, 2011 * Author: Tiberiu */ #ifndef FILEIO_H_ #define FILEIO_H_ #include #include // Device routines, will read/write 'BlockSize' bytes per call typedef uint32 (*DevReadRoutine)(uint32 offset, void* buffer); typedef uint32 (*DevWriteRoutine)(uint32 offset, void* buffer); enum FileFlags { FileFile = 0x1, FileDirectory = 0x2, FileCharDevice = 0x3, FileBlockDevice = 0x4, FilePipe = 0x5, FileSymbolLink = 0x6, FileMountPoint = 0x7, FileOwnerRead = 0x8, FileOwnerWrite = 0x10, FileOwnerExecute = 0x20, FileGroupRead = 0x40, FileGroupWrite = 0x80, FileGroupExecute = 0x100, FileOtherRead = 0x200, FileOtherWrite = 0x400, FileOtherExecute = 0x800, FileHidden = 0x1000, }; typedef struct _FILE { uint32 DeviceId; // The VFS identifies the mounted device that uses this uint32 Id; // The FS idenitifies files using this field char Name[128]; /*** Looks like this: * bits description * 0-2 file type * 3-5 owner permissions (rwx) * 6-8 group permissions (rwx) * 9-11 other permissions (rwx) * 12 hidden * 13-31 (unassigned yet) * * Note: In windows FS, the readonly and system attributes are set using permissions and userid */ uint32 Flags; uint32 OwnerId, GroupId; uint32 Size; } FILE; typedef struct _DirectoryEntry { char Name[128]; uint32 Flags, OwnerId, GroupId, Size; TimeSystem TimeCreated, TimeModified, TimeAccessed; } DirectoryEntry; typedef struct { uint32 Id; uint32 FsId; char Name[128]; uint32 BlockSize; DevReadRoutine Read; DevWriteRoutine Write; } MountPoint; // File system routines typedef uint32 (*FsReadRoutine)(const MountPoint*, FILE*, uint32, uint32, uint8*); typedef uint32 (*FsWriteRoutine)(const MountPoint*, FILE*, uint32, uint32, uint8*); typedef FILE* (*FsOpenRoutine)(const MountPoint*, FILE*,string); typedef DirectoryEntry* (*FsTestRoutine)(const MountPoint*, string); // Test if a file exists, and returns info typedef FILE* (*FsCloseRoutine)(const MountPoint*, FILE*); typedef DirectoryEntry* (*FsReadDirRoutine)(const MountPoint*,FILE*,uint32); typedef uint32 (*FsDetectRoutine) (DevReadRoutine, uint32 blocksz); // File system structure typedef struct { uint32 Id; char Name[16]; FsDetectRoutine Detect; FsOpenRoutine Open; FsCloseRoutine Close; FsReadRoutine Read; FsWriteRoutine Write; FsTestRoutine Test; // See if file exists without having to open it FsReadDirRoutine ReadDirectory; } FileSystem; // Vfs routines extern void VfsInstall (); extern uint8 VfsInstallFs (FileSystem* fs); extern uint32 VfsFindDevice (string dev); extern uint32 VfsParsePath (string* path); extern uint8 VfsMount (string Name, DevReadRoutine R, DevWriteRoutine W, uint32 BlockSize); extern void VfsUnmount (uint32 dev_id); extern FILE* VfsOpen (FILE* file, string path); extern DirectoryEntry* VfsTest (string path); extern FILE* VfsClose (FILE* file); extern uint32 VfsRead (FILE* file, uint32 bsz, uint32 n, uint8* buffer); extern uint32 VfsWrite (FILE* file, uint32 bsz, uint32 n, uint8* buffer); extern DirectoryEntry* VfsReadDirectory (FILE* handle, uint32 index); #endif /* FILEIO_H_ */