Reading the boot sector. 
Author Message
 Reading the boot sector.

Hi Martin,

After much fiddling about (and some advice from David Milton) I've
managed to refine the code so that it obtains both the boot record
*and* partition table from physical drives. Here's the updated code...

--- cut here ---------------------------------------------------------------
' BOOTSEX.BAS   reads the hard drive boot sector into memory.
'
'   Author:     Christy Gemmell
'   Additions:  Martin Overton
'               David Milton
'   Date:       4/7/1995
'
'   $INCLUDE: 'VBDOS.BI'
'
    DECLARE SUB BootSex (Drive$, ParTable%, Done%)

    CONST FALSE = 0, TRUE = NOT FALSE

    DIM SHARED Regs AS RegTypeX
    DIM SHARED Sector AS STRING * 512
    DIM SHARED Part AS STRING * 512

    CLS : PRINT : Drive$ = "C:"         ' Read from drive C:
    BootSex Drive$, ParTable%, Done%    ' Read boot sector
    IF Done% THEN                       ' If successful...
       PRINT "Boot Sector for Drive "; Drive$
       PRINT "========================"
       PRINT "Media descriptor  = "; HEX$(ASC(MID$(Sector, 22, 8)))
       PRINT "OEM Identifier    = "; MID$(Sector, 4, 8)
       PRINT "Volume label      = "; MID$(Sector, 44, 11)
       PRINT "Serial number     = ";
       FOR I% = 43 TO 40 STEP -1
               PRINT RIGHT$("0" + HEX$(ASC(MID$(Sector, I%, 1))), 2);
               IF I% = 42 THEN PRINT "-";
       NEXT I%
       PRINT : PRINT "File system       = "; MID$(Sector, 55, 8)
       PRINT
       IF ParTable% THEN
              PRINT "Partition Table for Drive "; Drive$
              PRINT "============================"
              I% = 447: P% = 1
              DO
                     PRINT "Partition"; P%;
                     IF ASC(MID$(Part, I%, 1)) = 128 THEN
                            PRINT TAB(21); "ACTIVE PARTITION";
                     END IF
                     OS% = ASC(MID$(Part, I% + 4, 1))
                     PRINT TAB(41);
                     SELECT CASE OS%
                             CASE 0
                                      PRINT "Empty"
                             CASE 1
                                      PRINT "DOS 12-bit FAT"
                             CASE 4
                                      PRINT "DOS 16-bit FAT (up to 32MB)"
                             CASE 5
                                      PRINT "Extended partition"
                             CASE 6
                                      PRINT "16-bit FAT (over 32MB)"
                             CASE 7
                                      PRINT "OS/2 HPFS or Windows NTFS"
                             CASE ELSE
                                      PRINT
                     END SELECT
                     I% = I% + 16: P% = P% + 1
              LOOP UNTIL P% > 4
              PRINT
              Sig& = ASC(MID$(Part, I%, 1)) _
               + (256& * ASC(MID$(Part, I% + 1, 1)))
              IF Sig& = 43605 THEN
                     PRINT "Valid boot block"
              END IF
       END IF
       PRINT "-----------------------------------------------------------"
    END IF
END

'   Read the boot sector and partition table of a specified drive.
'
SUB BootSex (Drive$, ParTable%, Done%)
    LSET Sector = STRING$(512, 0)       ' Fill sector buffer with zeroes
    Disk% = ASC(UCASE$(Drive$)) - 65    ' Get drive number
    Head% = 0                           ' Floppies use head zero
    IF Disk% > 1 THEN                   ' Adjust
       Disk% = (Disk% + 128) - 2        '   for hard
       Head% = 1                        '     disk
    END IF                              '       drives
    Regs.cx = &H1                       ' Get sector 1 of track zero
    Regs.dx = (Head% * 256) + Disk%     '   of selected drive
    Regs.ax = &H201                     ' Read one full sector
    Regs.bx = VARPTR(Sector)            ' Offset of read buffer
    Regs.es = VARSEG(Sector)            ' Segment of read buffer
    INTERRUPTX &H13, Regs, Regs         ' Read sector into memory
    IF Regs.flags AND 1 THEN            ' Test carry flag for error
       Done% = FALSE                    ' If set report an error
    ELSE                                ' Otherwise
       IF Disk% > 1 THEN                ' Hard drive
              LSET Part = STRING$(512, 0)   ' Fill partition buffer with zeroes
              Head% = 0                     ' Partition table is under head zero
              Regs.cx = &H1                 ' Get sector 1 of track zero
              Regs.dx = (Head% * 256) + Disk% ' of selected drive
              Regs.ax = &H201               ' Read one full sector
(Continued to next message)
---
 * 1st 2.00o #323 * Someday my ship will come in... but I'll be at the airport.



Sat, 20 Dec 1997 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Reading the boot sector

2. Reading the boot sector and partition table into memory

3. Reading the boot sector and partition table

4. How do I Read/Write BOOT SECTOR in VB 4.0

5. Read Boot Sector

6. Need some help with boot sectors.

7. Writing to Boot Sector

8. Boot sector.

9. Writing to floppy disk boot sector - how ?

10. Write to boot sector with VB?

11. Crash damaging boot sector

12. Timberland Boots, Cheap Timberland Boots, Hiking Waterproof Work boots

 

 
Powered by phpBB® Forum Software