git-svn-id: https://spexeah.com:8443/svn/Asuro@498 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
183
src/driver/storage/fat32.pas
Normal file
183
src/driver/storage/fat32.pas
Normal file
@ -0,0 +1,183 @@
|
||||
{ ************************************************
|
||||
* Asuro
|
||||
* Unit: Drivers/storage/fat32
|
||||
* Description: fat32 file system driver
|
||||
*
|
||||
************************************************
|
||||
* Author: Aaron Hance
|
||||
* Contributors:
|
||||
************************************************ }
|
||||
|
||||
unit FAT32;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
console, storagemanagement;
|
||||
|
||||
type
|
||||
|
||||
TBootRecord = bitpacked record
|
||||
jmp2boot : ubit24;
|
||||
OEMName : array[0..7] of char;
|
||||
sectorSize : uint16;
|
||||
spc : uint8;
|
||||
rsvSectors : uint16;
|
||||
numFats : uint8;
|
||||
numDirEnt : uint16;
|
||||
numSectors : uint16;
|
||||
mediaDescp : uint8;
|
||||
sectorsPerFat : uint16;
|
||||
sectorsPerTrack : uint16;
|
||||
heads : uint16;
|
||||
hiddenSectors : uint32;
|
||||
manySectors : uint32;
|
||||
FATSize : uint32;
|
||||
flags : uint16;
|
||||
signature : uint8;
|
||||
FATVersion : uint16;
|
||||
rootCluster : uint32;
|
||||
FSInfoCluster : uint16;
|
||||
backupCluster : uint16;
|
||||
reserved0 : array[0..11] of uint8;
|
||||
driveNumber : uint8;
|
||||
reserved1 : uint8;
|
||||
bsignature : uint8;// = $28;
|
||||
volumeID : uint32;
|
||||
volumeLabel : array[0..10] of uint8;
|
||||
identString : array[0..7] of char;// = 'FAT32 ';
|
||||
end;
|
||||
|
||||
byteArray8 = array[0..7] of char;
|
||||
byteArray12 = array[0..11] of uint8;
|
||||
|
||||
TDirectory = bitpacked record
|
||||
fileName : uint64;
|
||||
fileExtension : ubit24;
|
||||
attributes : uint8;
|
||||
reserved0 : uint8;
|
||||
timeFine : uint8;
|
||||
time : uint16;
|
||||
date : uint16;
|
||||
accessTime : uint16;
|
||||
clusterHigh : uint16;
|
||||
modifiedTime : uint16;
|
||||
modifiedDate : uint16;
|
||||
clusterLow : uint16;
|
||||
byteSize : uint32;
|
||||
end;
|
||||
|
||||
TFilesystemInfo = record
|
||||
FATBaseAddress : uint32;
|
||||
RootDirectory : uint32;
|
||||
end;
|
||||
|
||||
TFatVolumeInfo = record
|
||||
sectorsPerCluster : uint8; // must be power of 2 and mult by sectorsize to max 32k
|
||||
end;
|
||||
PFatVolumeInfo = ^TFatVolumeInfo;
|
||||
|
||||
procedure init;
|
||||
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
|
||||
procedure detect_volumes(disk : PStorage_Device; volumes : puint32);
|
||||
|
||||
implementation
|
||||
|
||||
function load(ptr : void) : boolean;
|
||||
begin
|
||||
console.outputln('DUMMY DRIVER', 'LOADED.')
|
||||
end;
|
||||
|
||||
procedure read(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure write(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure init;
|
||||
var
|
||||
filesystem : TFilesystem;
|
||||
begin
|
||||
filesystem.sName:= 'FAT32';
|
||||
filesystem.writecallback:= @write;
|
||||
filesystem.readcallback:= @read;
|
||||
filesystem.createcallback:= @create_volume;
|
||||
filesystem.detectcallback:= @detect_volumes;
|
||||
storagemanagement.register_filesystem(filesystem);
|
||||
end;
|
||||
|
||||
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
|
||||
var
|
||||
i : uint8;
|
||||
bootRecord : TBootRecord;
|
||||
buffer : puint32;
|
||||
asuroArray : byteArray8;// = byteArray8(['A','S','U','R','O',' ','V','1']);
|
||||
fatArray : byteArray8;// = byteArray8(['F','A','T','3','2',' ',' ',' ']);
|
||||
begin
|
||||
|
||||
asuroArray[0] := 'A';
|
||||
asuroArray[1] := 's';
|
||||
asuroArray[2] := 'u';
|
||||
asuroArray[3] := 'r';
|
||||
asuroArray[4] := 'o';
|
||||
asuroArray[5] := ' ';
|
||||
asuroArray[6] := 'V';
|
||||
asuroArray[7] := '1';
|
||||
|
||||
fatArray[0] := 'F';
|
||||
fatArray[1] := 'A';
|
||||
fatArray[2] := 'T';
|
||||
fatArray[3] := '3';
|
||||
fatArray[4] := '2';
|
||||
fatArray[5] := ' ';
|
||||
fatArray[6] := ' ';
|
||||
fatArray[7] := ' ';
|
||||
|
||||
|
||||
bootrecord.jmp2boot:= $00; // TODO what ahppens here???
|
||||
bootRecord.OEMName:= asuroArray;
|
||||
bootrecord.sectorsize:= disk^.sectorSize;
|
||||
bootrecord.spc:= PFatVolumeInfo(config)^.sectorsPerCluster;
|
||||
bootrecord.rsvSectors:= 32; //Is this acceptable?
|
||||
bootrecord.numFats:= 2;
|
||||
bootrecord.numDirEnt:= 0;
|
||||
bootRecord.numSectors:= 0;
|
||||
bootrecord.mediaDescp:= $F8;
|
||||
bootrecord.sectorsPerFat:= 0;
|
||||
bootRecord.sectorsPerTrack:= 0;
|
||||
bootRecord.heads:= 0;
|
||||
bootRecord.hiddenSectors:= start;
|
||||
bootRecord.manySectors:= sectors;
|
||||
|
||||
BootRecord.FATSize:= ((sectors DIV PFatVolumeInfo(config)^.sectorsPerCluster) * 16 DIV disk^.sectorSize);
|
||||
BootRecord.flags:= 1 shl 7;
|
||||
BootRecord.FATVersion:= 0;
|
||||
BootRecord.rootCluster:= 2; // can be changed if needed.
|
||||
BootRecord.FSInfoCluster:=1; //TODO need FSINFO
|
||||
BootRecord.driveNumber:= $80;
|
||||
//BootRecord.reserved0:=0;
|
||||
//BootRecord.reserved1:=0;
|
||||
BootRecord.volumeID := 53424; //need random number generator
|
||||
//BootRecord.volumeLabel[0] := 0; //needs to be set later !!!
|
||||
BootRecord.bsignature:= $29;
|
||||
BootRecord.identString:= fatArray;
|
||||
|
||||
buffer:= @bootrecord;
|
||||
disk^.writeCallback(disk, 1, sizeof(TBootRecord), buffer);
|
||||
|
||||
|
||||
//448bytes bootstrap
|
||||
//2bytes end mark 55AA
|
||||
|
||||
end;
|
||||
|
||||
procedure detect_volumes(disk : PStorage_Device; volumes : puint32);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user