Forum > Beginners

Have anyone know how to format the partition to FAT32 File System with pascal?

(1/2) > >>

TYDQ:
I have met a bug that when I tried to format the partition to FAT32 File System with pascal,the UEFI cannot recognize my FAT32 Header,and this is the key source code:
fat32 records in uefi.pas:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type fat32_header=packed record                  JumpOrder:array[1..3] of byte;                  OemCode:array[1..8] of char;                  BytesPerSector:word;                  SectorPerCluster:byte;                  ReservedSectorCount:word;                  NumFATs:byte;                  RootEntryCount:word;                  TotalSector16:word;                  Media:byte;                  FATSectors16:word;                  SectorPerTrack:word;                  NumHeads:word;                  HiddenSectors:dword;                  TotalSectors32:dword;                  FATSector32:dword;                  ExtendedFlags:word;                  FileSystemVersion:word;                  RootCluster:dword;                  FileSystemInfo:word;                  BootSector:word;                  Reserved:array[1..12] of byte;                  DriverNumber:byte;                  Reserved1:byte;                  BootSignature:byte;                  VolumeID:dword;                  VolumeLabel:array[1..11] of char;                  FileSystemType:array[1..8] of char;                  Reserved2:array[1..420] of byte;                  SignatureWord:word;                  Reserved3:array[1..65023] of byte;                  end;     fat32_file_system_info=packed record                            FSI_leadSig:dword;                            FSI_Reserved1:array[1..480] of byte;                            FSI_StrucSig:dword;                            FSI_FreeCount:dword;                            FSI_NextFree:dword;                            FSI_Reserved2:array[1..12] of byte;                            FSI_TrailSig:dword;                            FSI_Reserved3:array[1..65023] of byte;                            end;My fat32 header to write in the specified disk's position:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if(i=harddiskindex) then    begin     fat32h.JumpOrder[1]:=$EB; fat32h.JumpOrder[2]:=$58; fat32h.JumpOrder[3]:=$90;     fat32h.OemCode[1]:='T'; fat32h.OemCode[2]:='Y'; fat32h.OemCode[3]:='D'; fat32h.OemCode[4]:='Q';     fat32h.OemCode[5]:='O'; fat32h.OemCode[6]:='S'; fat32h.OemCode[7]:=' '; fat32h.OemCode[8]:=#0;     fat32h.BytesPerSector:=blocksize;      fat32h.SectorPerCluster:=128;     fat32h.ReservedSectorCount:=4+256 div (blocksize div 512);      fat32h.NumFATs:=2;     fat32h.RootEntryCount:=0;      fat32h.TotalSector16:=0;      fat32h.Media:=$F8;     fat32h.FATSectors16:=0;      fat32h.SectorPerTrack:=0;      fat32h.NumHeads:=0;     fat32h.HiddenSectors:=0;      fat32h.TotalSectors32:=1024*100 div (blocksize div 512);      fat32h.FATSector32:=128 div (blocksize div 512);     fat32h.ExtendedFlags:=0;      fat32h.filesystemVersion:=0;      fat32h.RootCluster:=2;     fat32h.FileSystemInfo:=1;      fat32h.BootSector:=6;      for j:=1 to 12 do fat32h.Reserved[j]:=0;      fat32h.DriverNumber:=$00;      fat32h.Reserved1:=0;     fat32h.BootSignature:=$29;      fat32h.VolumeID:=0;     fat32h.VolumeLabel[1]:='E'; fat32h.VolumeLabel[2]:='F'; fat32h.VolumeLabel[3]:='I'; fat32h.VolumeLabel[4]:=' ';      fat32h.VolumeLabel[5]:='P'; fat32h.VolumeLabel[6]:='A'; fat32h.VolumeLabel[7]:='R'; fat32h.VolumeLabel[8]:='T';      fat32h.VolumeLabel[9]:=' '; fat32h.VolumeLabel[10]:=' '; fat32h.VolumeLabel[11]:=#0;     fat32h.FileSystemType[1]:='F'; fat32h.FileSystemType[2]:='A'; fat32h.FileSystemType[3]:='T';     fat32h.FileSystemType[4]:='3'; fat32h.FileSystemType[5]:='2'; fat32h.FileSystemType[6]:=' ';     fat32h.FileSystemType[7]:=' '; fat32h.FileSystemType[8]:=#0;     for j:=1 to 420 do fat32h.Reserved2[j]:=0;     fat32h.SignatureWord:=$AA55;     if(BlockSize>512) then for j:=1 to BlockSize-512 do fat32h.Reserved3[j]:=0;     fat32fs.FSI_leadsig:=$41615252;      for j:=1 to 480 do fat32fs.FSI_Reserved1[j]:=0;     fat32fs.FSI_StrucSig:=$61417272;     fat32fs.FSI_FreeCount:=100*1024 div (blocksize div 512)-128 div (blocksize div 512)-2;      fat32fs.FSI_NextFree:=2;     for j:=1 to 12 do fat32fs.FSI_Reserved2[j]:=0;     fat32fs.FSI_TrailSig:=$AA550000;     if(BlockSize>512) then for j:=1 to BlockSize-512 do fat32fs.FSI_Reserved3[j]:=0;     diop^.WriteDisk(diop,mediaid,gpt.FirstUsableLBA*blocksize,blocksize,@fat32h);     diop^.WriteDisk(diop,mediaid,gpt.FirstUsableLBA*blocksize+blocksize,blocksize,@fat32fs);    end;Have anyone know why the bug occurs and please give me a solution to format the fat32 file system in one of GPT Partitions using pascal?
My total source code is in this repository https://github.com/TYDQSoft/UEFIPascalOS

MarkMLl:
Since nobody else has commented: write your code to format the partition to /exactly/ what the canonical UEFI utilities would do, and only then start doing things like customising OemCode.

Frankly, while I've never been particularly worried about using my own code to read a preformatted filesystem, I've always been very wary about writing it. However I think that FAT (including FAT32) is somewhat more forgiving than more advances FSes: hence it's popularity.

MarkMLl

TYDQ:

--- Quote from: MarkMLl on May 09, 2024, 09:18:05 pm ---Since nobody else has commented: write your code to format the partition to /exactly/ what the canonical UEFI utilities would do, and only then start doing things like customising OemCode.

Frankly, while I've never been particularly worried about using my own code to read a preformatted filesystem, I've always been very wary about writing it. However I think that FAT (including FAT32) is somewhat more forgiving than more advances FSes: hence it's popularity.

MarkMLl

--- End quote ---
But performatted file system is invaild on the UEFI Bare Machine with all Disk Utilities are also invaild,I want to write an UEFI OS installer by myself to install my Test OS on the disk.

MarkMLl:
In that case find a preformatted FS that isn't invalid before trying to go any further.

MarkMLl

Laksen:
For it to be seen as a FAT32 fs and not a FAT12/16 the total amount of clusters must be over 65525

Navigation

[0] Message Index

[#] Next page

Go to full version