@@ -1014,24 +1014,7 @@ void DoDiskInsert(struct Globals *glob)
10141014 return ;
10151015 } else {
10161016 ULONG RDB_ID = ((read_buffer [0 ]<<24 ) + (read_buffer [1 ]<<16 ) + (read_buffer [2 ]<<8 ) + read_buffer [3 ]);
1017- D (kprintf ("[FAT] [%s] RDB = %4d|%08x\n" , __FUNCTION__ , 0x200 , RDB_ID ));
1018- if (RDB_ID == 0x5244534b )
1019- {
1020- glob -> diskioreq -> iotd_Req .io_Command = 0xffff ;
1021- glob -> diskioreq -> iotd_Req .io_Length = 1 ;
1022- DoIO ((struct IORequest * )glob -> diskioreq );
1023- return ;
1024- }
1025- }
1026-
1027- err = RawDiskSectorRead (1 , geometry .dg_SectorSize , (UBYTE * )& read_buffer [0 ], glob );
1028- if (err )
1029- {
1030- D (bug ("[FAT] [%s] Read Error = %d on BootSector #1 (RDB Check)\n" ,__FUNCTION__ , err ));
1031- return ;
1032- } else {
1033- ULONG RDB_ID = ((read_buffer [0 ]<<24 ) + (read_buffer [1 ]<<16 ) + (read_buffer [2 ]<<8 ) + read_buffer [3 ]);
1034- D (kprintf ("[FAT] [%s] RDB = %4d|%08x\n" , __FUNCTION__ , 0x200 , RDB_ID ));
1017+ D (kprintf ("[FAT] [%s] RDB = %04x|%08x\n" , __FUNCTION__ , 0x200 , RDB_ID ));
10351018 if (RDB_ID == 0x5244534b )
10361019 {
10371020 glob -> diskioreq -> iotd_Req .io_Command = 0xffff ;
@@ -1051,44 +1034,57 @@ void DoDiskInsert(struct Globals *glob)
10511034 }
10521035
10531036 UWORD MBR_ID = (read_buffer [0x1fe ]<<8 ) + read_buffer [0x1ff ];
1054- D (kprintf ("[FAT] [%s] MBR = %4d |%08x\n" , __FUNCTION__ , 0x1fe , MBR_ID ));
1037+ D (kprintf ("[FAT] [%s] MBR = %04x |%08x\n" , __FUNCTION__ , 0x1fe , MBR_ID ));
10551038 if (MBR_ID != 0x55aa )
10561039 {
10571040 D (bug ("[FAT] [%s] No RDB or MBR Boot Record found\n" ,__FUNCTION__ ));
10581041 return ;
10591042 }
10601043
1044+ UBYTE MDB_PART1_STATUS = (read_buffer [0x1be + 0x0 ]);
10611045 ULONG MDB_PART1_START = (read_buffer [0x1be + 0x8 ])+ (read_buffer [0x1be + 0x9 ]<<8 )+ (read_buffer [0x1be + 0xa ]<<16 )+ (read_buffer [0x1be + 0xb ]<<24 );
10621046 ULONG MDB_PART1_TOTAL = (read_buffer [0x1be + 0xc ])+ (read_buffer [0x1be + 0xd ]<<8 )+ (read_buffer [0x1be + 0xe ]<<16 )+ (read_buffer [0x1be + 0xf ]<<24 );
1047+
1048+ UBYTE MDB_PART2_STATUS = (read_buffer [0x1ce + 0x0 ]);
10631049 ULONG MDB_PART2_START = (read_buffer [0x1ce + 0x8 ])+ (read_buffer [0x1ce + 0x9 ]<<8 )+ (read_buffer [0x1ce + 0xa ]<<16 )+ (read_buffer [0x1ce + 0xb ]<<24 );
10641050 ULONG MDB_PART2_TOTAL = (read_buffer [0x1ce + 0xc ])+ (read_buffer [0x1ce + 0xd ]<<8 )+ (read_buffer [0x1ce + 0xe ]<<16 )+ (read_buffer [0x1ce + 0xf ]<<24 );
1051+
1052+ UBYTE MDB_PART3_STATUS = (read_buffer [0x1de + 0x0 ]);
10651053 ULONG MDB_PART3_START = (read_buffer [0x1de + 0x8 ])+ (read_buffer [0x1de + 0x9 ]<<8 )+ (read_buffer [0x1de + 0xa ]<<16 )+ (read_buffer [0x1de + 0xb ]<<24 );
10661054 ULONG MDB_PART3_TOTAL = (read_buffer [0x1de + 0xc ])+ (read_buffer [0x1de + 0xd ]<<8 )+ (read_buffer [0x1de + 0xe ]<<16 )+ (read_buffer [0x1de + 0xf ]<<24 );
1055+
1056+ UBYTE MDB_PART4_STATUS = (read_buffer [0x1ee + 0x0 ]);
10671057 ULONG MDB_PART4_START = (read_buffer [0x1ee + 0x8 ])+ (read_buffer [0x1ee + 0x9 ]<<8 )+ (read_buffer [0x1ee + 0xa ]<<16 )+ (read_buffer [0x1ee + 0xb ]<<24 );
10681058 ULONG MDB_PART4_TOTAL = (read_buffer [0x1ee + 0xc ])+ (read_buffer [0x1ee + 0xd ]<<8 )+ (read_buffer [0x1ee + 0xe ]<<16 )+ (read_buffer [0x1ee + 0xf ]<<24 );
10691059
1070- D (kprintf ("\tPART#1-LBA-Start = %4d|%08x\n" , 0x1be + 0x8 , MDB_PART1_START ));
1071- D (kprintf ("\tPART#1-LBA-Total = %4d|%08x\n" , 0x1be + 0xc , MDB_PART1_TOTAL ));
1072- D (kprintf ("\tPART#2-LBA-Start = %4d|%08x\n" , 0x1ce + 0x8 , MDB_PART2_START ));
1073- D (kprintf ("\tPART#2-LBA-Total = %4d|%08x\n" , 0x1ce + 0xc , MDB_PART2_TOTAL ));
1074- D (kprintf ("\tPART#3-LBA-Start = %4d|%08x\n" , 0x1de + 0x8 , MDB_PART3_START ));
1075- D (kprintf ("\tPART#3-LBA-Total = %4d|%08x\n" , 0x1de + 0xc , MDB_PART3_TOTAL ));
1076- D (kprintf ("\tPART#4-LBA-Start = %4d|%08x\n" , 0x1ee + 0x8 , MDB_PART4_START ));
1077- D (kprintf ("\tPART#4-LBA-Total = %4d|%08x\n\n" , 0x1ee + 0xc , MDB_PART4_TOTAL ));
1060+ D (bug ("\tPART#1 LBA-Start = %04x|%08x | LBA-Total = %04x|%08x | STATUS = %04x|%02x\n" , 0x1be + 0x8 , MDB_PART1_START , 0x1be + 0xc , MDB_PART1_TOTAL , 0x1be , MDB_PART1_STATUS ));
1061+ D (bug ("\tPART#2 LBA-Start = %04x|%08x | LBA-Total = %04x|%08x | STATUS = %04x|%02x\n" , 0x1ce + 0x8 , MDB_PART2_START , 0x1ce + 0xc , MDB_PART2_TOTAL , 0x1ce , MDB_PART2_STATUS ));
1062+ D (bug ("\tPART#3 LBA-Start = %04x|%08x | LBA-Total = %04x|%08x | STATUS = %04x|%02x\n" , 0x1de + 0x8 , MDB_PART3_START , 0x1de + 0xc , MDB_PART3_TOTAL , 0x1de , MDB_PART3_STATUS ));
1063+ D (bug ("\tPART#4 LBA-Start = %04x|%08x | LBA-Total = %04x|%08x | STATUS = %04x|%02x\n" , 0x1ee + 0x8 , MDB_PART4_START , 0x1ee + 0xc , MDB_PART4_TOTAL , 0x1ee , MDB_PART4_STATUS ));
10781064
10791065 //Final step is to translate MDB_PART1_START LBA addresses to a valid LowCyl and with MDB_PART1_TOTAL also a valid HighCyl
10801066 //LBA = Surfaces * BlocksPerTrack * Cylinders or Cylinders = LBA / Surfaces / BlocksPerTrack
10811067 //In most cases the default values of Surfaces = 16 and BlocksPerTrack = 64 will work, but for smaller SD this may fail because Cylinder must be an integer and >0
10821068
1083- if (( MDB_PART1_START % de -> de_BlocksPerTrack % de -> de_Surfaces ) == 0 )
1069+ if (MDB_PART1_STATUS == 0x00 )
10841070 {
1085- de -> de_LowCyl = MDB_PART1_START / de -> de_BlocksPerTrack / de -> de_Surfaces ; // Read ULONG from MBR-PART1 = 0x1BE + 0x8
1086- de -> de_HighCyl = MDB_PART1_TOTAL / de -> de_BlocksPerTrack / de -> de_Surfaces + de -> de_LowCyl ; // Read ULONG from MBR-PART1 = 0x1BE + 0xC
1071+ D (bug ("[FAT] Valid First Partition Found\n" ));
1072+ if ((MDB_PART1_START % de -> de_BlocksPerTrack % de -> de_Surfaces ) == 0 )
1073+ {
1074+ D (bug ("[FAT] First Partition Start Block (%d) aligns with Cylinders/Tracks (%d) and Heads/Surfaces (%d)\n" , MDB_PART1_START , de -> de_BlocksPerTrack , de -> de_Surfaces ));
1075+ de -> de_LowCyl = MDB_PART1_START / de -> de_BlocksPerTrack / de -> de_Surfaces ;
1076+ de -> de_HighCyl = MDB_PART1_TOTAL / de -> de_BlocksPerTrack / de -> de_Surfaces + de -> de_LowCyl ;
1077+ } else {
1078+ D (bug ("[FAT] First Partition Start Block (%d) does NOT align with Cylinders/Tracks (%d) and Heads/Surfaces (%d)\n" , MDB_PART1_START , de -> de_BlocksPerTrack , de -> de_Surfaces ));
1079+ de -> de_Surfaces = 1 ;
1080+ de -> de_BlocksPerTrack = 1 ;
1081+ de -> de_LowCyl = MDB_PART1_START ;
1082+ de -> de_HighCyl = MDB_PART1_TOTAL ;
1083+ }
10871084 } else {
1088- de -> de_Surfaces = 1 ;
1089- de -> de_BlocksPerTrack = 1 ;
1090- de -> de_LowCyl = MDB_PART1_START ;
1091- de -> de_HighCyl = MDB_PART1_TOTAL ;
1085+ D (bug ("[FAT] NO Valid First Partition Found, default to Full Disk Partition\n" ));
1086+ de -> de_LowCyl = 0 ;
1087+ de -> de_HighCyl = geometry .dg_Cylinders ;
10921088 }
10931089
10941090 D (bug ("\n[FAT] [%s] Drive Geometry transfer to glob->fssm->fssm_Environ:\n" ,__FUNCTION__ ));
0 commit comments