Added VFS

git-svn-id: https://spexeah.com:8443/svn/Asuro@1318 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron 2020-07-18 21:00:31 +00:00
parent df09f33e41
commit 6b6129b769
6 changed files with 186 additions and 9 deletions

View File

@ -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;

171
src/driver/storage/vfs.pas Normal file
View File

@ -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.

View File

@ -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;

View File

@ -9,7 +9,8 @@ interface
uses
util,
lmemorymanager;
lmemorymanager,
lists;
function stringToUpper(str : pchar) : pchar;
function stringToLower(str : pchar) : pchar;

View File

@ -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();

View File

@ -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);