Added file reading without cluster chain following
This commit is contained in:
parent
32b0d990df
commit
61f1852420
@ -122,6 +122,8 @@ extern "C" void kernel ()
|
||||
printf(" [Size: %d bytes, Attributes: %d]\n", entry->ATTR, entry->FileSize);
|
||||
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY ){
|
||||
FAT::OpenSubdir(entry, bpb);
|
||||
} else {
|
||||
FAT::readFile(entry, bpb);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,8 +146,6 @@ uint16_t FAT::GetFATEntry (BiosParameterBlock* bpb, unsigned int cluster){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t FAT::DetermineFreeSpace()
|
||||
{
|
||||
// Loop through all FAT entries in all FAT's
|
||||
@ -180,8 +178,6 @@ unsigned int FAT::RootDirSize(BiosParameterBlock* bpb)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t* ReadFAT (BiosParameterBlock& bpb , bool DEBUG = false ) {
|
||||
uint32_t FATAddress = /*StartAddress*/ 0x00 + bpb.RsvdSecCnt ;
|
||||
uint16_t* FAT = (uint16_t*)malloc(sizeof (uint16_t) * 256);
|
||||
@ -253,42 +249,29 @@ void FAT::OpenSubdir(DIR* directory, BiosParameterBlock* bpb ){
|
||||
printf("LFN\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void FAT::readFile(DIR* fileEntry , BiosParameterBlock* bpb){
|
||||
unsigned int cluster = fileEntry->FstClusLo;
|
||||
unsigned int FATEntry = FAT::GetFATEntry(bpb, cluster);
|
||||
unsigned int root_dir_sectors = FAT::RootDirSize(bpb);
|
||||
unsigned int fat_size = bpb->FATSz16;
|
||||
unsigned int first_data_sector = bpb->RsvdSecCnt + (bpb->NumFATs * fat_size) + root_dir_sectors;
|
||||
unsigned int file_data_sector = ((cluster -2) * bpb->SecPerClus) + first_data_sector;
|
||||
printf("FAT entry = %x\n", FATEntry);
|
||||
uint16_t data[256];
|
||||
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, file_data_sector, data);
|
||||
|
||||
void readFile(uint32_t DataRegion, DIR* entry, uint16_t FATentry, BiosParameterBlock& bpb ){
|
||||
printf("Show contents");
|
||||
|
||||
printf("Start cluster of the file: 0x%x\n", entry->FileSize);
|
||||
|
||||
printf("IS it only 1 cluster? %s\n", FATentry == 0xFFFF ? "Yes" : "No");
|
||||
|
||||
uint32_t sector = DataRegion + ((entry->FileSize - 0x02) * bpb.SecPerClus);
|
||||
|
||||
|
||||
uint16_t dataBlob[256];
|
||||
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob);
|
||||
for (unsigned short n: dataBlob) {
|
||||
for (unsigned short n : data)
|
||||
{
|
||||
kterm_put(n & 0x00ff);
|
||||
|
||||
kterm_put(n >> 8);
|
||||
}
|
||||
kterm_put('\n');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
file fsysFatDirectory (const char* DirectoryName){
|
||||
file file;
|
||||
|
@ -83,6 +83,7 @@ public:
|
||||
static int GetSectorOfRootDirectory(BiosParameterBlock*);
|
||||
static unsigned int RootDirSize(BiosParameterBlock*);
|
||||
static void OpenSubdir (DIR*, BiosParameterBlock*);
|
||||
static void readFile(DIR*, BiosParameterBlock*);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user