Progress
This commit is contained in:
109
src/driver/storage/flatfs.pas
Normal file
109
src/driver/storage/flatfs.pas
Normal file
@ -0,0 +1,109 @@
|
||||
// Copyright 2021 Aaron Hance
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
{
|
||||
Driver->Storage->flatfs super simple flat filesystem
|
||||
|
||||
@author(Aaron Hance ah@aaronhance.me)
|
||||
}
|
||||
|
||||
unit flatfs;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
tracer,
|
||||
strings,
|
||||
volumemanager;
|
||||
|
||||
type
|
||||
|
||||
TDisk_Info = bitpacked record
|
||||
jmp2boot: ubit24;
|
||||
OEMName: array[0..7] of char;
|
||||
version: uint16;
|
||||
sectorCount : uint16;
|
||||
fileCount : uint16;
|
||||
signature : uint32 = $0B00B1E5;
|
||||
end;
|
||||
PDisk_Info = ^TDisk_Info;
|
||||
|
||||
TFile_Entry = packed record
|
||||
name: array[0..59] of char;
|
||||
size: uint16;
|
||||
start : uint16;
|
||||
end;
|
||||
PFile_Entry = ^TFile_Entry;
|
||||
|
||||
var
|
||||
filesystem : TFilesystem;
|
||||
|
||||
|
||||
procedure init;
|
||||
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
|
||||
procedure detect_volumes(disk : PStorage_Device);
|
||||
|
||||
implementation
|
||||
|
||||
procedure detect_volumes(disk : PStorage_Device);
|
||||
var
|
||||
buffer : puint32;
|
||||
volume : PStorage_volume;
|
||||
begin
|
||||
push_trace('flatfs.detectVolumes()');
|
||||
|
||||
volume:= PStorage_volume(kalloc(sizeof(TStorage_Volume)));
|
||||
//check first address for MBR
|
||||
//if found then add volume and use info to see if there is another volume
|
||||
buffer := puint32(kalloc(512));
|
||||
memset(uint32(buffer), 0, 512);
|
||||
disk^.readcallback(disk, 2, 1, buffer);
|
||||
|
||||
|
||||
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then begin
|
||||
console.writestringln('FlatFS: volume found!');
|
||||
volume^.device:= disk;
|
||||
volume^.sectorStart:= 2;
|
||||
volume^.sectorSize:= 512;
|
||||
volume^.sectorCount:= PDisk_Info(buffer)^.sectorCount;
|
||||
volume^.freeSectors:= 1000000; //TODO implement get free sectors need FSINFO implemented first
|
||||
volume^.filesystem := @filesystem;
|
||||
volume^.isBootDrive := false;
|
||||
|
||||
// storagemanagement.register_volume(disk, volume); TODO repalce with new thing
|
||||
|
||||
end;
|
||||
|
||||
kfree(buffer);
|
||||
end;
|
||||
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
push_trace('flatfs.init()');
|
||||
filesystem.sName:= 'FlatFS';
|
||||
filesystem.system_id:= $02;
|
||||
filesystem.readDirCallback:= @readDirectoryGen;
|
||||
filesystem.createDirCallback:= @writeDirectoryGen;
|
||||
filesystem.createcallback:= @create_volume;
|
||||
filesystem.detectcallback:= @detect_volumes;
|
||||
filesystem.writecallback:= @writeFile;
|
||||
filesystem.readcallback := @readFile;
|
||||
filesystem.formatVolumeCallback := @create_volume;
|
||||
|
||||
volumemanager.register_filesystem(@filesystem);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
Reference in New Issue
Block a user