
Reading the boot sector and partition table
MO> PS (here's another plea for help) Have you a routine for getting the
> BOOT sector or PARTITION table from a HD(s). I currently use a debug
> script, created at run time shelled & piped to debug. It's a bit messy,
> but it does work!
Well I tried writing the one below and it works fine for floppy disks
but, for some reason, when I try it with a hard disk all it returns is
garbage. I've checked it and checked it, using Norton Disk Editor and
Ralf Brown's interrupt list as references, but I can't see where it's
going wrong at all.
It's just possible that it might work for you because my computer has
DOS 7/Windows 95 installed and I've heard that it locks your computer
against direct disk access. However if this were the case then I'd
expect it to return an error in the carry flag instead of just sending
back garbage.
There's probably a stupid error someone in the code so, if anybody who's
reading this can spot it, do please let us know. I don't mind egg on my
face as long as we can get the flipping thing working!
--- cut here ---------------------------------------------------------------
' BOOTSEX.BAS displays information from the boot sector and
' partition table of the specified disk drive.
'
' Author: Christy Gemmell
' For: Martin Overton
' Date: 30/6/1995
'
' $INCLUDE: 'QB.BI'
'
DECLARE SUB BootSex (Drive$, Done%)
CONST FALSE = 0, TRUE = NOT FALSE
DIM SHARED Regs AS RegTypeX
DIM SHARED Sector AS STRING * 1024
CLS : PRINT : Drive$ = "C:" ' Read from drive C:
BootSex Drive$, 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 "-----------------------------------------------------------"
PRINT : I% = 446: P% = 1
DO
PRINT "Partition"; P%;
IF ASC(MID$(Sector, I%, 1)) = 128 THEN
PRINT TAB(21); "ACTIVE PARTITION";
END IF
OS% = ASC(MID$(Sector, 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 : I% = 511
Sig& = ASC(MID$(Sector, I%, 1)) + (256& * ASC(MID$(Sector, I% + 1, 1)))
IF Sig& = &HAA55 THEN
PRINT "Valid boot block"
END IF
END IF
END
' Read the boot sector of a specified drive into memory
'
SUB BootSex (Drive$, Done%)
LSET Sector = STRING$(1024, 0) ' Fill read buffer with zeroes
Disk% = ASC(UCASE$(Drive$)) - 65 ' Get drive number
IF Disk% > 1 THEN ' Adjust for
Disk% = (Disk% + 128) - 2 ' hard disk
END IF ' drives
Head% = 0 ' Read from head zero
Regs.cx = &H1 ' Get sector 1, track zero
Regs.dx = (Head% * 256) + Disk% ' from 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
(Continued to next message)
* 1st 2.00o #323 * Man: the useless bit of skin on the end of a {*filter*}.