DISK001
DISK001.ZIP contains:
- DISK001.COM & the program
- DISK001.TXT & this text
- DISK001.PET & source PET4TH language
Storage devices like Floppy Disk Drive (fdd), Hard Disk Drive (hdd),
USB Flash Disk (ufd) are divided into sectors (smallest unit). The
first sector of fdd is boot sector. The first sector of hdd is master
boot record (MBR). While ufd may have MBR, it can also be formatted
like fdd.
MBR contains Partition Table. Software divides an hdd to partitions. If
Partition Table is erased, data on the hdd can not be read. Therefore
it is a good practice to save Partition Table to a file and keep it in
another drive.
DISK001 can save MBR to a file. Display MBR on the hdd or on a file
(and compare). Erase MBR. And restore MBR from MBR backup file. DISK001
can run in DOS, W95 and M98 dos prompt. It can not run in WNT, W2000,
WXP, since this OS prohibit program to access hdd BIOS service, which
is used by DISK001.
Since it accesses hdd through BIOS, it does not use drive name C: or D:
or E: but drive#, 0 for fdd A:, 1 for fdd B:, 128 for hdd C:, 129 for
second hdd or ufd. Everytime ufd is replug, a new drive# may be
assigned. To see list of available fdd, hdd and ufd, type:
disk001 - drives
First thing to do is to save MBR of hdd C: on file DISK128.DAT.
disk001 disk128.dat 128 read
Then save the file with DISK001.COM to another drive, better to a drive
that is DOS/W95/W98 bootable, fdd is OK.
Later, you may restore MBR with
disk001 disk128.dat 128 write
Be careful that this is a dangerous operation. While I write the
program carefully, anything can happen, and I will not be responsible.
Do it at your own risk.
Sometimes an hdd (stubbornly) can not be erased. You may try
disk001 - <drive#> zap
Replace <drive#> with actual drive#. Only MBR is erased, your
data is not erased properly, but the hdd can now be used again.
If you suspect the MBR is compromised, you can compare backup file with
MBR on the hdd
disk001 disk128.dat 128 display
And restore MBR if necessary. Any partition modification will modify
MBR, make sure you keep the latest backup.
Since the source is included, you may modify the program. Get PET4TH
first, a Forth Programming Language.
Author,
Petrus Prawirodidjojo 2006-03-04.
Note:
Previously a drive is accessed by cylinder/head/sector, and the first
sector is cylinder 0, head 0 and sector 1, hence 001, DISK001. Later
LBA is used, accessed by 32bit sector#.
Below of the glossary:
disk001.pet
pi fload disk001.pet, tested with PET4TH 01.00.0014
!"#$%&'()*+,-./0123456789:;<=>?@A
Z[\]^_`a z{|}~
no <text>, with <file>, with dictionary template
dos_to_tib
copy dos command line buffer to tib
unsure? ( -- flag )
return true if unsure
help
display help
readsector ( c-addr drv cyl head sec #secs -- error ior )
bios read sector to c-addr, return status/#sectors
if true
writesector ( c-addr drv cyl head sec #secs -- error ior )
bios write sector to c-addr, return status/#sectors
if true
#retry
variable # retry for tryreadsec
tryreadsec ( c-addr drv cyl head sec #secs -- error ior )
same as readsector but with retry
trywritesec ( c-addr drv cyl head sec #secs -- error ior )
same as writesector but with retry
ext13h? ( drive -- flag )
return bit0 use packet, bit1 lock and eject, bit2
support edd
dapbuf
variable 16 bytes, disk address packet buffer
readblock ( c-addr drv d_lba #block -- count ior )
bios read lba int13h 42h to c-addr, max 127, return
count, error flag
writeblock ( c-addr drv d_lba #block -- ior )
bios write lba int13h 43h from c-addr, return error
flag
drvlchs ( drv -- maxsec# maxhead# maxcyl# )
bios read logical drive parameter int13h fn 08h max
chs 8.4GB
drvbuf
variable 30 bytes, drive parameter buffer
getdrv ( drv -- d_#blocks )
bios read drive parameter int13h fn 48h, big 8 bytes
#sectors
drvpchs# ( drv -- d_#blocks d_#s/t d_#head d_#cyl )
bios read physical drive parameter, use getdrv,
int13h fn 48h
dump_ascii ( addr count -- )
dump ascii only
drive#
variable, drive# selected, $0 for first fdd $80 for
first hdd
uselba
variable, use lba instead of chs, flag
lba#
double variable, lba#
cyl#
variable, cylinder number
head#
variable, head number
sec#
variable, sector number
lcyl
variable, logical #cyl
lhead
variable, logical #head
lsec
variable, logical sectors per track
p#blk
double variable, physical #block
secbuff
buffer for 2 sectors, usually use one sector of 512
bytes only
.drive
display current drive# lba or chs
.secbuff
dump secbuff 512 bytes in ascii
readblk ( -- flag )
read a block - drive# lba# - to secbuff, return
error flag
writeblk ( -- flag )
write a block - drive# lba# - from secbuff, return
error flag
lba ( ud -- )
store lba in lba#
rddrv ( -- error_flag )
read drive# lcyl lhead lsec uselba p#blk, using bios
.drv
display drive parameter
filename
svariable 80 characters file name
fileid
file handle
filebuff
file read buffer for 1 sector for compare
drives
display all drives
readflag
value numbers of succesful read
dispsec0 ( drive# - )
display sector 0
dispfile
display file
compbuff
compare secbuff and filebuff then display result
display
display sector 0 or file or both
read ( drive# - )
read and save sector 0
iamsure
ask user a confirmation
zap ( drive# -- )
erase sector 0
write ( drive# -- )
load and write sector 0
main
main entry point
$end
end compile
Back