From 6b6129b769583bae377bb8fb3223e555cb8c4bca Mon Sep 17 00:00:00 2001 From: kieron Date: Sat, 18 Jul 2020 21:00:31 +0000 Subject: [PATCH] Added VFS git-svn-id: https://spexeah.com:8443/svn/Asuro@1318 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c --- src/driver/storage/IDE.pas | 4 +- src/driver/storage/vfs.pas | 171 +++++++++++++++++++++++++++++++++++++ src/include/lists.pas | 4 +- src/include/strings.pas | 3 +- src/kernel.pas | 5 +- src/prog/terminal.pas | 8 +- 6 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 src/driver/storage/vfs.pas diff --git a/src/driver/storage/IDE.pas b/src/driver/storage/IDE.pas index 04208b54..cc1db721 100644 --- a/src/driver/storage/IDE.pas +++ b/src/driver/storage/IDE.pas @@ -296,8 +296,8 @@ begin masterDevice.sectorSize:= 512; if masterDevice.maxSectorCount <> 0 then begin IDEDevices[0].exists:= true; - masterDevice.readCallback:= @read; - masterDevice.writeCallback:= @write; + masterDevice.readCallback:= @IDE.read; + masterDevice.writeCallback:= @IDE.write; storagemanagement.register_device(@masterDevice); end; diff --git a/src/driver/storage/vfs.pas b/src/driver/storage/vfs.pas new file mode 100644 index 00000000..786ec63f --- /dev/null +++ b/src/driver/storage/vfs.pas @@ -0,0 +1,171 @@ +unit vfs; + +interface + +uses + hashmap, strings, lmemorymanager; + +type + TOpenMode = (omReadOnly, omWriteOnly, omReadWrite); + TWriteMode = (wmRewrite, wmAppend, wmNew); + TError = (eNone, eUnknown, eFileInUse, eWriteOnly, eReadOnly, eFileDoesNotExist, eDirectoryDoesNotExist, eDirectoryAlreadyExists); + PError = ^TError; + TIsPathValid = (pvInvalid, pvFile, pvDirectory); + + TFileHandle = uint32; + + { Callbacks } + TOpenFile = function(Handle : uint32; Filename : pchar; OpenMode : TOpenMode; WriteMode : TWriteMode; Lock : Boolean; Error : PError) : TFileHandle; + TWriteFile = function(Handle : uint32; FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; + TReadFile = function(Handle : uint32; FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; + TFileSize = function(Handle : uint32; Filename : pchar; error : puint8) : uint32; + TCloseFile = function(Handle : uint32; Filehandle : TFileHandle) : boolean; + TMakeDirectory = function(Handle : uint32; Path : pchar) : TError; + TGetDirectories = function(Handle : uint32; Path : pchar) : PHashMap; + TPathValid = function(Handle : uint32; Path : pchar) : TIsPathValid; + + TObjectType = (otVDIRECTORY, otDIRECTORY, otDEVICE, otFILE, otMOUNT); + TVFSVDirectory = record + Contents : PHashMap; + end; + TVFSDrive = record + DriveHandle : uint32; + MakeDirectory : TMakeDirectory; + GetDirectories : TGetDirectories; + OpenFile : TOpenFile; + CloseFile : TCloseFile; + ReadFile : TReadFile; + WriteFile : TWriteFile; + FileSize : TFileSize; + PathValid : TPathValid; + end; + TVFSDevice = record + DeviceHandle : uint32; + MakeDirectory : TMakeDirectory; + GetDirectories : TGetDirectories; + OpenFile : TOpenFile; + CloseFile : TCloseFile; + ReadFile : TReadFile; + WriteFile : TWriteFile; + FileSize : TFileSize; + PathValid : TPathValid; + end; + TVFSFile = record + ReadFile : TReadFile; + WriteFile : TWriteFile; + end; + TVFSMount = record + Path : pchar; + ObjectType : TObjectType; + Reference : void; + end; + TVFSObject = record + ObjectType : TObjectType; + Reference : void; + end; + PVFSObject = ^TVFSObject; + +var + VirtualFileSystem : PHashMap; + CurrentDirectory : pchar = nil; + +procedure init(); +Function OpenFile(Filename : pchar; OpenMode : TOpenMode; WriteMode : TWriteMode; Lock : Boolean; Error : PError) : TFileHandle; +function WriteFile(FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; +function ReadFile(FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; +function CloseFile(Filehandle : TFileHandle) : boolean; +function FileSize(Filename : pchar; error : puint8) : uint32; +function CreateDirectory(Handle : uint32; Path : pchar) : TError; +function GetDirectories(Handle : uint32; Path : pchar) : PHashMap; +function PathValid(Handle : uint32; Path : pchar) : TPathValid; +function changeDirectory(Path : pchar) : TPathValid; +function getWorkingDirectory : pchar; + +//VFS Functions +function newVirtualDirectory(Path : pchar) : TError; + +implementation + +uses + terminal; + +{ Internal Functions } + +Procedure ChangeCurrentDirectoryValue(new : pchar); +begin + if CurrentDirectory <> nil then kfree(void(CurrentDirectory)); + CurrentDirectory:= nil; + CurrentDirectory:= stringCopy(new); +end; + + +{ Filesystem Functions } + +Function OpenFile(Filename : pchar; OpenMode : TOpenMode; WriteMode : TWriteMode; Lock : Boolean; Error : PError) : TFileHandle; +begin + +end; + +function WriteFile(FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; +begin + +end; + +function ReadFile(FileHandle : TFileHandle; Position : uint32; Buffer : puint8; Length : uint32) : uint32; +begin + +end; + +function CloseFile(Filehandle : TFileHandle) : boolean; +begin + +end; + +function FileSize(Filename : pchar; error : puint8) : uint32; +begin + +end; + +function CreateDirectory(Handle : uint32; Path : pchar) : TError; +begin + +end; + +function GetDirectories(Handle : uint32; Path : pchar) : PHashMap; +begin + +end; + +function PathValid(Handle : uint32; Path : pchar) : TPathValid; +begin + +end; + +function changeDirectory(Path : pchar) : TPathValid; +begin + +end; + +{ VFS Functions } + +function newVirtualDirectory(Path : pchar) : TError; +begin + +end; + +function getWorkingDirectory : pchar; +begin + getWorkingDirectory:= CurrentDirectory; +end; + +{ Terminal Commands } + +{ Init } + +procedure init(); +begin + VirtualFileSystem:= hashmap.new; + ChangeCurrentDirectoryValue('/'); +end; + +end. \ No newline at end of file diff --git a/src/include/lists.pas b/src/include/lists.pas index 317369a5..47159552 100644 --- a/src/include/lists.pas +++ b/src/include/lists.pas @@ -11,7 +11,6 @@ uses console, lmemorymanager, util, - strings, tracer; type @@ -55,6 +54,9 @@ function LL_FromString(str : pchar; delimter : char) : PLinkedListBase; implementation +uses + strings; + { Managed Linked List } function LL_New(ElementSize : uint32) : PLinkedListBase; diff --git a/src/include/strings.pas b/src/include/strings.pas index c4213948..8c40c17b 100644 --- a/src/include/strings.pas +++ b/src/include/strings.pas @@ -9,7 +9,8 @@ interface uses util, - lmemorymanager; + lmemorymanager, + lists; function stringToUpper(str : pchar) : pchar; function stringToLower(str : pchar) : pchar; diff --git a/src/kernel.pas b/src/kernel.pas index c44795a4..09200f19 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -41,7 +41,7 @@ uses base64, rand, terminal, - hashmap; + hashmap, vfs; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; @@ -185,6 +185,9 @@ begin { Call Tracer } tracer.init(); + { VFS Init } + vfs.init(); + { Management Interfaces } tracer.push_trace('kmain.DRVMGMT'); drivermanagement.init(); diff --git a/src/prog/terminal.pas b/src/prog/terminal.pas index 456954b6..b75caba0 100644 --- a/src/prog/terminal.pas +++ b/src/prog/terminal.pas @@ -17,7 +17,7 @@ uses tracer, asuro, serial, - netutils, nettypes; + netutils, nettypes, vfs; type THaltCallback = procedure(); @@ -115,13 +115,13 @@ end; function getWorkingDirectory : pchar; begin - getWorkingDirectory:= Working_Directory; + getWorkingDirectory:= vfs.getWorkingDirectory; end; procedure setWorkingDirectory(str : pchar); begin if str <> nil then begin - Working_Directory:= stringCopy(str); + vfs.changeDirectory(str); end; end; @@ -425,7 +425,7 @@ begin if not Halted then begin { Reset the terminal ready for the next command } console.writestringWND('Asuro#', TERMINAL_HWND); - console.writestringWND(Working_Directory, TERMINAL_HWND); + console.writestringWND(vfs.getWorkingDirectory, TERMINAL_HWND); console.writestringWND('> ', TERMINAL_HWND); bIndex:= 0; memset(uint32(@buffer[0]), 0, 1024);