Changeset 208


Ignore:
Timestamp:
Feb 26, 2021, 1:33:13 PM (4 years ago)
Author:
David Azarewicz
Message:

Use standardized routines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/ata.c

    r207 r208  
    429429
    430430  return(rc);
    431 }
    432 
    433 /* Adjust the cylinder count in the physical
    434  * geometry to the last full cylinder.
    435  */
    436 int adjust_cylinders(GEOMETRY64 *geometry, ULONG TotalSectors)
    437 {
    438   USHORT SecPerCyl;
    439   int rc = FALSE;
    440 
    441   geometry->TotalSectors = TotalSectors;
    442   SecPerCyl = geometry->SectorsPerTrack * geometry->NumHeads;
    443   if (SecPerCyl > 0)
    444   {
    445     ULONG TotalCylinders  = TotalSectors / SecPerCyl;
    446 
    447     geometry->TotalSectors   = TotalCylinders * SecPerCyl;
    448     geometry->TotalCylinders = TotalCylinders;
    449     if (TotalCylinders >> 16)
    450     {
    451       geometry->TotalCylinders = 65535;
    452       rc = TRUE;
    453     }
    454   }
    455   return (rc);
    456 }
    457 
    458 /* Calculate the logical geometry based on the input physcial geometry
    459  * using the LBA Assist Translation algorithm.
    460  */
    461 #define BIOS_MAX_CYLINDERS       1024l
    462 #define BIOS_MAX_NUMHEADS         255
    463 #define BIOS_MAX_SECTORSPERTRACK   63
    464 void log_geom_calculate_LBA_assist(GEOMETRY64 *geometry, ULONG TotalSectors)
    465 {
    466   UCHAR numSpT   = BIOS_MAX_SECTORSPERTRACK;
    467   UCHAR numHeads = BIOS_MAX_NUMHEADS;
    468   ULONG Cylinders;
    469 
    470   if (TotalSectors <= (BIOS_MAX_CYLINDERS * 128 * BIOS_MAX_SECTORSPERTRACK))
    471   {
    472     USHORT temp = (TotalSectors - 1) / (BIOS_MAX_CYLINDERS * BIOS_MAX_SECTORSPERTRACK);
    473 
    474     if (temp < 16)      numHeads = 16;
    475     else if (temp < 32) numHeads = 32;
    476     else if (temp < 64) numHeads = 64;
    477     else                numHeads = 128;
    478   }
    479 
    480   do
    481   {
    482     Cylinders = TotalSectors / (USHORT)(numHeads * numSpT);
    483     if (Cylinders >> 16)
    484     {
    485       if (numSpT < 128)
    486         numSpT = (numSpT << 1) | 1;
    487       else
    488         Cylinders = 65535; // overflow !
    489     }
    490   } while (Cylinders >> 16);
    491 
    492   geometry->TotalCylinders  = Cylinders;
    493   geometry->NumHeads        = numHeads;
    494   geometry->SectorsPerTrack = numSpT;
    495431}
    496432
     
    676612
    677613  if (is_lvm_geometry(pIorb)) Method = "LVM";  /* Writes TotalSectors/ullTotalSectors */
    678   else
    679   {
    680     if (add_workspace(pIorb)->fIs64bit)
    681     {
    682       geometry->NumHeads        = 255;
    683       geometry->SectorsPerTrack = 255;
    684       geometry->TotalCylinders  = ullTotalSectors / (255*255);
    685       geometry->ullTotalSectors = ullTotalSectors;
    686     }
    687     else
    688     {
    689       /* Fixup the geometry in case the geometry reported by the BIOS is bad */
    690       if (adjust_cylinders(geometry, ullTotalSectors))  /* Writes TotalSectors */
    691       { // cylinder overflow
    692         log_geom_calculate_LBA_assist(geometry, ullTotalSectors); /* Does not write TotalSectors */
    693         ullTotalSectors = (USHORT)(geometry->NumHeads * geometry->SectorsPerTrack) * (ULONG)geometry->TotalCylinders;
    694       }
    695       adjust_cylinders(geometry, ullTotalSectors); /* Writes TotalSectors */
    696     }
    697   }
     614  else CalculateLogicalGeometry(geometry, add_workspace(pIorb)->fIs64bit, ullTotalSectors);
    698615  if (add_workspace(pIorb)->fIs64bit) ullTotalSectors = geometry->ullTotalSectors;
    699616  else ullTotalSectors = geometry->TotalSectors;
Note: See TracChangeset for help on using the changeset viewer.