SAMPLE: Reading the Boot Sector of a Drive

Last reviewed: February 15, 1996
Article ID: Q102870
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows, version 3.1

SUMMARY

BOOTSEC demonstrates how to use Interrupt 25h (absolute disk read) to read the boot sector (the first sector on head 0, cylinder 0) off of a drive (either a floppy disk drive or hard disk).

BOOTSEC checks to see whether the drive is one of the following:

   Drive            Detection Method
   ---------------------------------
   CD-ROM           Interrupt 2F calls to MSCDEX.
   Net drive        Windows API WNetGetConnection().
   RAM drive        Checks the boot sector to see if there is one FAT.
   Hard disk        Checks the media BYTE of the boot sector. If it is
                    equal to 0xF8h then it is a hard disk.
   Floppy disk      Checks the media BYTE of the boot sector. If it is
                    not equal to 0xF8h and it is not a RAM drive, net
                    drive, or CD-ROM drive, then it is a floppy disk drive.

BOOTSEC also shows how to implement a dialog box as a main window using a private dialog class.

MORE INFORMATION

The following information is contained in the boot sector:

  • The jump instruction to the boot strap routine
  • The name of the OEM and the version of MS-DOS
  • Bytes per sector
  • Sectors per cluster
  • Reserved sectors
  • Number of file allocation tables
  • Number of root directory entries
  • Number of sectors
  • Media descriptor
  • Number of sectors occupied by each FAT
  • Number of sectors on a single track
  • Number of read/write heads on the drive
  • Number of hidden sectors
  • Number of huge sectors
  • Whether the disk is the first hard disk drive
  • The boot signature
  • The volume serial number
  • The volume label
  • The file system type

NOTE: The information contained in the boot sector was changed in MS-DOS 5.0. If this program is run on a disk that was formatted with a previous version of MS-DOS, then some of the fields in the structure will not be filled out, and the program may display garbage. The elements of the structure that were not changed will be displayed correctly.

Download BOOTSEC.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download BOOTSEC.EXE (size: 28595 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get BOOTSEC.EXE (size: 28595 bytes) 
    


Additional reference words: 3.10 INT softlib BOOTSEC.EXE
KBCategory: kbprg kbfile
KBSubcategory: KrFileIO


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.