Classic Computer Magazine Archive COMPUTE! ISSUE 80 / JANUARY 1987 / PAGE 77

Disk FIX
For IBM PC/PCjr

Bradley Franklin

Virtually every computer user has suffered the consequences of deleting an important file by accident. This convenient utility can recover such a file as long as it hasn't been overwritten by other disk operations.


Regardless of experience and interest level, nearly every computer user has suffered the same unpleasant feeling: After pressing Enter, you realize that you just accidentally deleted an important disk file. In the case of commercial software, such accidents can be costly as well as embarrassing. "Disk Fix" makes it possible to recover accidentally deleted files. Type in and save the program; then run it to create a machine language file named DISKFIX.COM. (Don't use that name for the BASIC program that creates the file.) The filemaker program also creates a backup copy of the file with the name DISKFIX.BKP (to use this file, change the extension BKP to .COM).

Using DISKFIX.COM
DISKFIX.COM is a machine language program that runs from the DOS prompt; you needn't be a machine language expert to use this program, however. To recover the lost data, go to the DOS command level (A> or B>). If you are currently in BASIC, the SYSTEM command takes you to the DOS command level. Insert the disk that contains Disk Fix; then type DISKFIX and press Enter. The drive lights for an instant as the computer loads Disk Fix into memory. When the light goes out, insert the disk that contains the file you want to recover. Press any key to begin the recovery process. The drive will light for a second time, then stop.
    At this point, the lost file has been recovered. If you perform DIR from the DOS prompt, the filename should appear in the directory, with a dollar sign ($) where the first character of the filename previously appeared. (The dollar sign replaces a marker which DOS placed there when deleting the file.) Now that the file is restored, you can rename it and perform any other operation you wish. Since it searches for all deleted files, Disk Fix also works in cases where you have deleted a group of related files with a wild-card command.
    It's important that you understand which files Disk Fix cannot recover. If you accidentally delete a file, Disk Fix can restore it only if you act before you write any additional files to the same disk. As long as no new files have been written to that disk, all the information in the deleted file is still intact and can be restored. If you save a new program on the disk, however, it may write over the deleted file's data, destroying it forever.
    Disk Fix does not harm any other files on the disk. However, if you have deleted a file with a name like FFILE.BAS and the disk still contains the file $FILE.BAS, Disk Fix cannot work correctly. Since the recovered program is renamed from FFILE.BAS to $FILE.BAS, the disk now contains two programs of the same name. For this reason, you should avoid the practice of beginning filenames with a dollar sign.
    This program takes advantage of the fact that deleting a file doesn't erase its data from disk. Instead, DOS changes the first character of the filename to a marker which indicates the file is deleted. As a result, DOS skips over the file whenever it searches the disk, making it impossible to use the file in a normal way. Disk Fix simply searches the disk's FAT (File Allocation Table) and replaces all deletion markers with dollar signs. The effect is to restore all previously deleted files.


DISKFIX.COM Filernaker
For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" in this issue of COMPUTE!.

MN 10 CLEAR ,50000!
HM 20 CLS
OI 30 READ AE:IF A$="BF" THEN 50
AE 40 PRINT CHRS(7):PRINT "THE F
      IRST NUMBER IS BF,NOT ";A$
      :END
LF 50 FOR X=1 TO 19
DO 60 FOR Y=1 TO 10
LL 70 READ A$
A6 80 NEXT Y
CA 90 READ A$:G=G+VAL("&h"+A$)
6N 100 NEXT X
BL 110 IF HEX$(G)="4D1C" THEN RE
       STORE:GOTO 130
KO 120 PRINT CHR$(7):PRINT "ERRO
       R:CHECK END NUMBERS" :END
NI 130 G=0
QO 140 READ A$
IF 150 FOR X=1 TO 19
PH 160 FOR Y=1 TO 10
AE 170 READ A$
NC 180 G=G+VAL("&h"+A$)
IJ 190 NEXT Y
PH 200 READ A$
KM 210 IF G<>VAL("&H"+A$) THEN 2
       50
NH 220 G=0
BE 230 NEXT X
FB 240 GOTO 260
NC 250 PRINT CHR$(7):PRINT "ERRO
       R:CHECK DATA STATEMENTS I
       N LINE:";X*10+430:END
BN 260 READ A$:IF A$<>"13" THEN
       X=20:GOTO 250
JJ 270 READ A$:IF A$<>"C3" THEN
       X=20:GOTO 250
   280 PRINT "CONGRATULATIONS!!
       DATA IS OKAY!!(WHEW!)"
MD 290 RESTORE
FL 300 XX=50000!
CA 310 READ A$:POKE XX,VAL("&h"+
       A$)
IB 320 FOR X=1 TO 19
PD 330 FOR Y=1 TO 10
MP 340 XX=XX+1
AC 350 READ A$
BF 360 POKE XX,VAL("&h"+A$)
HH 370 NEXT Y
DE 380 READ A$:NEXT X
KM 390 READ A$:XX=XX+1:POKE XX,V
       AL("&h"+A$)
JL 400 READ A$:XX=XX+1:POKE XX,V
       AL("&h"+A$)
AD 410 OPEN "DISKFIX.COM" AS #1
       LEN=1
QN 420 OPEN "DISKFIX.BKP" AS #2
       LEN=1
LC 430 FIELD #1,1 AS A$
QI 440 FIELD #2,1 AS AA$
GH 450 FOR Q=0 TO XX-50000!:LSET
        A$-CHR$(PEEK(0+50000!)):
       AA$-A$:PUT #2:PUT #1:NEXT
        Q
FM 460 CLOSE:END
JS 470 DATA BF
EM 480 DATA B4,0,CD,16,B8,0,17,8
       E,D8,B8,484
LK 490 DATA 0,17,8E,C0,B9,3,0,51
       ,BB,0,32D
DN 500 DATA 4,B2,0,B6,0,B5,0,B1,
       6,B0,388
KI 510 DATA 4,B4,2,CD,13,59,EB,9
       2,0,80,3ED
NF 520 DATA FC,0,74,7,B4,0,CD,13
       ,E2,DF,4CC
OD 530 DATA C3,B9,3,0,51,BB,0,8,
       B2,0,345
DE 540 DATA B6,1,B5,0,B1,1,B0,3,
       84,2,387
NF 550 DATA CD,13,59,E8,6D,0,80,
       FC,0,74,47E
QK 560 DATA 7,B4,0,CD,13,E2,DF,C
       3,B9,48,520
GL 570 DATA 20,BB,0,4,80,3F,E5,7
       4,7,83,381
FL 580 DATA C3,1,E2,F6,EB,5,C6,7
       ,24,EB,568
KF 590 DATA F4,B9,3,0,51,BB,0,4,
       B2,0,372
LB 600 DATA B6,0,B5,0,B1,6,B0,4,
       B4,3,38D
HK 610 DATA CD,13,59,EB,31,0,80,
       FC,0,74,442
HC 620 DATA 7,B4,0,CD,13,E2,DF,C
       3,B9,3,4DB
FD 630 DATA 0,51,BB,0,8,B2,0,B6,
       1,B5,332
PL 640 DATA 0,B1,1,B0,3,B4,3,CD,
       13,59,355
MH 650 DATA E8,C,0,80,FC,0,74,6,
       B4,0,39E
KC 660 DATA CD,13,E2,DF,C3,B4,1,
       B0,0,CD,596
GO 670 DATA 13,C3