user16028858
user16028858

Reputation: 61

Reading Files/Folders from disk with FAT12 in Own OS

I am developing an OS, I am trying to Implement FAT12 Filesystem from an Other's OS Source Code, Finally, I can Mount a FAT12 Formatted disk and Get its FAT12 Information.

It can Read DriveName ( When 'Location = 0' ). But When I am trying to List Directories from disk, It is not Working!

Here, This is My Code to Get Directories,

void FAT12_PrintDirectories(uint32_t Location, uint32_t numEntries, uint8_t DriveNum)
{

   uint8_t read[((numEntries*32)/4096)+1];

   AHCI::Port* port = AHCI::GlobalAHCI->ports[0];

   port->Configure();

   port->buffer = (uint8_t*)GlobalAllocator.RequestPage();
        
   memset(port->buffer, 0, ((numEntries*32)/4096)+1);

   
   port->Read(Location /* If I write here '0' Instead of Location, then Output is Image2 */, Location+((numEntries*32)/4096)+1, port->buffer);

   for (int n = 0; n < sizeof(port->buffer); n++)
   {
        GlobalRenderer->PutChar(port->buffer[n]);
        read[n] = port->buffer[n];
   }


   char drivename[12];

   memset(&drivename, 0, 12);

   memcpy(drivename, read, 8);


    if(read[9] != ' ')
    {

        drivename[8] = '.';

        memcpy(drivename + 9, read + 8, 3);

    }


    drivename[11] = 0;


    // Print test read

    GlobalRenderer->Next();

    for (int n = 0; n < sizeof(read); n++)
    {
        GlobalRenderer->Print("=");
        GlobalRenderer->Print(to_string((uint64_t)read[n]));
    }
    


    GlobalRenderer->Next();
    GlobalRenderer->Print("Listing Dirs!");

    GlobalRenderer->Next();
    GlobalRenderer->Print("DriveName : ");
    GlobalRenderer->Print(drivename);
    GlobalRenderer->Next();


    uint8_t *reads = read;


    GlobalRenderer->Print("Dirs : ");
    GlobalRenderer->Next();

    for (unsigned int i = 0; i < numEntries; i++)
    {
        
        if(!reads[11] & 0x08 || reads[11] & 0x02 || reads[0] == 0 || reads[0] == 0xE5)
        {

            // Print FileName
            for (uint8_t j = 0; j < 11; j++)
            {
                
                if(j == 8 && reads[j] != ' ')
                {
                    GlobalRenderer->Print(".");

                }


                if(reads[j] != 0x20)
                {
                    GlobalRenderer->Print(to_string((uint64_t)reads[j]));

                }


                if(reads[11] & 0x10 && j == 10)
                {
                    
                    GlobalRenderer->Print("/");

                }



                uint32_t nextCluster = (reads[27] << 8) | reads[26];

                uint32_t size = *(uint32_t *)&reads[28];



            }


            reads += 32;
            

        }


        GlobalRenderer->Print("-");


    }


}

Here It is my Calling Code for that function FAT12_PrintDirectories(dirOff, 32, 0);

This time dirOff = 2097153

Output :

After 'Dirs' text - Image1 Image2

Location =          ((FAT12_MOUNT *)getDiskMount(numActiveMounts).mount)->RootDirectoryOffset*512+1;

Upvotes: 1

Views: 424

Answers (0)

Related Questions