home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DRIVE.ZIP / DRIVE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-10-30  |  4.2 KB  |  126 lines

  1. {*********************************************************}
  2. {*                     DRIVE.PAS 1.0                     *}
  3. {*                by TurboPower Software                 *}
  4. {*********************************************************}
  5.  
  6. program ClassifyDrives;
  7.  
  8. uses
  9.   Dos;
  10.  
  11.   {-------------------------------------------------------------------}
  12.  
  13. type
  14.   DiskClass = (
  15.     Floppy360, Floppy720, Floppy12, Floppy144, OtherFloppy, Bernoulli,
  16.     HardDisk, RamDisk, SubstDrive, UnknownDisk, InvalidDrive);
  17.  
  18.   function GetDiskClass(Drive : Char; var SubstDriveChar : Char) : DiskClass;
  19.     {-Return the disk class for the drive with the specified letter}
  20.     {-This routine uses an undocumented DOS function ($32). Information about
  21.       this function was obtained from Terry Dettmann's DOS Programmer's
  22.       Reference (Que, 1988).}
  23.   type
  24.     ParamBlock =
  25.       record
  26.         DriveNumber, DeviceDriverUnit : Byte;
  27.         BytesPerSector : Word;
  28.         SectorsPerCluster, ShiftFactor : Byte;
  29.         ReservedBootSectors : Word;
  30.         FatCopies : Byte;
  31.         RootDirEntries, FirstDataSector, HighestCluster : Word;
  32.         SectorsPerFat : Byte;
  33.         RootDirStartingSector : Word;
  34.         DeviceDriverAddress : Pointer;
  35.         Media2and3 : Byte; {media descriptor here in DOS 2.x and 3.x}
  36.         Media4 : Byte;     {media descriptor here in DOS 4.x}
  37.         NextDeviceParamBlock : Pointer;
  38.       end;
  39.     ParamBlockPtr = ^ParamBlock;
  40.   var
  41.     DriveNum : Byte;
  42.     MediaDescriptor : Byte;
  43.     Regs : Registers;
  44.   begin
  45.     {assume failure}
  46.     GetDiskClass := InvalidDrive;
  47.  
  48.     {assume that this is not a SUBSTituted drive}
  49.     SubstDriveChar := Drive;
  50.  
  51.     {convert drive letter to drive number}
  52.     Drive := Upcase(Drive);
  53.     case Drive of
  54.       'A'..'Z' : DriveNum := Ord(Drive)-$40;
  55.       else Exit;
  56.     end;
  57.  
  58.     with Regs do begin
  59.       {get pointer to media descriptor byte}
  60.       AH := $1C;
  61.       DL := DriveNum;
  62.       MsDos(Regs);
  63.       MediaDescriptor := Mem[DS:BX];
  64.  
  65.       {get pointer to drive parameter block}
  66.       AH := $32;
  67.       DL := DriveNum;
  68.       MsDos(Regs);
  69.  
  70.       {drive invalid if AL = $FF}
  71.       if (AL = $FF) then
  72.         Exit;
  73.  
  74.       with ParamBlockPtr(Ptr(DS,BX))^ do begin
  75.         {check for SUBSTituted drive}
  76.         if (DriveNumber <> Pred(DriveNum)) then begin
  77.           GetDiskClass := SubstDrive;
  78.           SubstDriveChar := Char(Ord('A')+DriveNumber);
  79.         end
  80.         else if (FatCopies = 1) then
  81.           {RAM disks have one copy of File Allocation Table}
  82.           GetDiskClass := RamDisk
  83.         else if (MediaDescriptor = $F8) then
  84.           {MediaDescriptor of $F8 indicates hard disk}
  85.           GetDiskClass := HardDisk
  86.         else if (MediaDescriptor = $FD) and (SectorsPerFat <> 2) then
  87.           {Bernoulli drives have more than 2 sectors per FAT}
  88.           GetDiskClass := Bernoulli
  89.         else if (MediaDescriptor >= $F9) then
  90.           {media descriptors >= $F9 are for floppy disks}
  91.           case HighestCluster of
  92.              355 : GetDiskClass := Floppy360;
  93.              714,
  94.             1423 : GetDiskClass := Floppy720;
  95.             2372 : GetDiskClass := Floppy12;
  96.             else   GetDiskClass := OtherFloppy;
  97.           end
  98.         else if (MediaDescriptor = $F0) and (HighestCluster = 2848) then
  99.           {it's a 1.44 meg floppy}
  100.           GetDiskClass := Floppy144
  101.         else
  102.           {unable to classify disk/drive}
  103.           GetDiskClass := UnknownDisk;
  104.       end;
  105.     end;
  106.   end;
  107.  
  108.   {-------------------------------------------------------------------}
  109.  
  110. var
  111.   Disk, SubstDisk : Char;
  112. const
  113.   DiskClasses : array[DiskClass] of string[34] = (
  114.     '360K floppy', '720K floppy', '1.2 meg floppy', '1.44 meg floppy',
  115.     'unknown floppy', 'Bernoulli drive', 'hard disk', 'RAM disk',
  116.     'SUBSTituted drive', 'unknown disk type', 'invalid drive (or not ready)');
  117. begin
  118.   for Disk := 'A' to 'J' do begin
  119.     Write('Drive ', Disk, ' is a ', DiskClasses[GetDiskClass(Disk, SubstDisk)]);
  120.     if SubstDisk <> Disk then
  121.       Write(' (actual drive, ', SubstDisk, ', is a ',
  122.         DiskClasses[GetDiskClass(SubstDisk, SubstDisk)], ')');
  123.     WriteLn;
  124.   end;
  125. end.
  126.