2013-10-31

2013-10-31 FAT and ATA drivers

So I've migrated the ATA driver from the DriveAccess kernel, it's nothing special, but it can read hard drives on an ATA interface (IDE) and also interpret standard partition tables to allow devices to specify the partition and resolve blocks relative to it.

I've also migrated much of the FAT file-system driver, but with modifications to implement the LookupFile() function which will (in future) allow the file locking system to work.

I did work out that with 32 (I think) FAT directory entries in a 512-byte block, using a uint32 to uniquely identify each directory on the FAT volume does actually limit me to partitions of 128Gb in size.  This is something I will have to address at some point.

I've created mountlists for the two hard drives that the emulated system has (one hardfile for Grub and a "hardfolder" for the kernel and other files) and I'm using these to mount the hard drives:

dos_mount
(
 "DH0:",
 &dvrata_driver,
 "PARTITION=0",
 &fat_driver,
 ""
);

dos_mount
(
 "DH1:",
 &dvrata_driver,
 "UNIT=1,PARTITION=0",
 &fat_driver,
 ""
);


I've fixed up a bug where the path splitting function was splitting on a semi-colon rather than a colon, and written file-system functions to open a file from a FileID (basically a pointer to the Directory Entry), to seek to a location within a file (with each seek reading and caching the current block), and to read a section of a file (using the seek function to actually perform the read).

The FAT Filesystem context contains the following data:

uint32 DirSectorNumber;
uint32 DirEntryNumber;
tFAT_DirectoryEntry DirectoryEntry;
uint32 FilePointer;
uint32 FirstCluster;
uint32 FileLength;
uint32 CurrentCluster;
uint32 CachedBlockNum;
uint8* CachedBlock;

and finally a small snippet of code which loads and prints a test text file to the output:

int32 lTestFile = dos_openFile( "DH1:test.txt", 0 );
uint32 lReadSize = 256;
uint8* lBuffer = kmalloc(lReadSize);
uint32 lDataRead;
while( ( lDataRead = dos_read( lTestFile, lBuffer, lReadSize ) ) == lReadSize )
{
 kernel_write( 1, lBuffer, lDataRead );
}
kfree( lBuffer );

All in all, it works.  It's mounting the device, reading the FAT parameters from the disk via the block device, looking up a file by path and opening it, and reading the content of the file.  It's a really big step forward to have the Octopus kernel able to load files, and with Bochs capable of taking a folder from the host OS and presenting it to the emulated OS as a FAT filesystem, it'll make some bits of testing a LOT easier.


No comments:

Post a Comment