Added VFS
git-svn-id: https://spexeah.com:8443/svn/Asuro@1318 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
df09f33e41
commit
6b6129b769
@ -296,8 +296,8 @@ begin
|
|||||||
masterDevice.sectorSize:= 512;
|
masterDevice.sectorSize:= 512;
|
||||||
if masterDevice.maxSectorCount <> 0 then begin
|
if masterDevice.maxSectorCount <> 0 then begin
|
||||||
IDEDevices[0].exists:= true;
|
IDEDevices[0].exists:= true;
|
||||||
masterDevice.readCallback:= @read;
|
masterDevice.readCallback:= @IDE.read;
|
||||||
masterDevice.writeCallback:= @write;
|
masterDevice.writeCallback:= @IDE.write;
|
||||||
storagemanagement.register_device(@masterDevice);
|
storagemanagement.register_device(@masterDevice);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
171
src/driver/storage/vfs.pas
Normal file
171
src/driver/storage/vfs.pas
Normal 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.
|
@ -11,7 +11,6 @@ uses
|
|||||||
console,
|
console,
|
||||||
lmemorymanager,
|
lmemorymanager,
|
||||||
util,
|
util,
|
||||||
strings,
|
|
||||||
tracer;
|
tracer;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -55,6 +54,9 @@ function LL_FromString(str : pchar; delimter : char) : PLinkedListBase;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
strings;
|
||||||
|
|
||||||
{ Managed Linked List }
|
{ Managed Linked List }
|
||||||
|
|
||||||
function LL_New(ElementSize : uint32) : PLinkedListBase;
|
function LL_New(ElementSize : uint32) : PLinkedListBase;
|
||||||
|
@ -9,7 +9,8 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
util,
|
util,
|
||||||
lmemorymanager;
|
lmemorymanager,
|
||||||
|
lists;
|
||||||
|
|
||||||
function stringToUpper(str : pchar) : pchar;
|
function stringToUpper(str : pchar) : pchar;
|
||||||
function stringToLower(str : pchar) : pchar;
|
function stringToLower(str : pchar) : pchar;
|
||||||
|
@ -41,7 +41,7 @@ uses
|
|||||||
base64,
|
base64,
|
||||||
rand,
|
rand,
|
||||||
terminal,
|
terminal,
|
||||||
hashmap;
|
hashmap, vfs;
|
||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
||||||
|
|
||||||
@ -185,6 +185,9 @@ begin
|
|||||||
{ Call Tracer }
|
{ Call Tracer }
|
||||||
tracer.init();
|
tracer.init();
|
||||||
|
|
||||||
|
{ VFS Init }
|
||||||
|
vfs.init();
|
||||||
|
|
||||||
{ Management Interfaces }
|
{ Management Interfaces }
|
||||||
tracer.push_trace('kmain.DRVMGMT');
|
tracer.push_trace('kmain.DRVMGMT');
|
||||||
drivermanagement.init();
|
drivermanagement.init();
|
||||||
|
@ -17,7 +17,7 @@ uses
|
|||||||
tracer,
|
tracer,
|
||||||
asuro,
|
asuro,
|
||||||
serial,
|
serial,
|
||||||
netutils, nettypes;
|
netutils, nettypes, vfs;
|
||||||
|
|
||||||
type
|
type
|
||||||
THaltCallback = procedure();
|
THaltCallback = procedure();
|
||||||
@ -115,13 +115,13 @@ end;
|
|||||||
|
|
||||||
function getWorkingDirectory : pchar;
|
function getWorkingDirectory : pchar;
|
||||||
begin
|
begin
|
||||||
getWorkingDirectory:= Working_Directory;
|
getWorkingDirectory:= vfs.getWorkingDirectory;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure setWorkingDirectory(str : pchar);
|
procedure setWorkingDirectory(str : pchar);
|
||||||
begin
|
begin
|
||||||
if str <> nil then begin
|
if str <> nil then begin
|
||||||
Working_Directory:= stringCopy(str);
|
vfs.changeDirectory(str);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ begin
|
|||||||
if not Halted then begin
|
if not Halted then begin
|
||||||
{ Reset the terminal ready for the next command }
|
{ Reset the terminal ready for the next command }
|
||||||
console.writestringWND('Asuro#', TERMINAL_HWND);
|
console.writestringWND('Asuro#', TERMINAL_HWND);
|
||||||
console.writestringWND(Working_Directory, TERMINAL_HWND);
|
console.writestringWND(vfs.getWorkingDirectory, TERMINAL_HWND);
|
||||||
console.writestringWND('> ', TERMINAL_HWND);
|
console.writestringWND('> ', TERMINAL_HWND);
|
||||||
bIndex:= 0;
|
bIndex:= 0;
|
||||||
memset(uint32(@buffer[0]), 0, 1024);
|
memset(uint32(@buffer[0]), 0, 1024);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user