Rounding up the bytes

Copyright Dr Alan Solomon, 1986-1995

Modern farmers these days are increasingly grassing over their meadows, and 
raising a very profitable crop of tourists.  They use computers to run this 
business, as you have to keep track of bookings, invoices, payments and a 
computer system can be ideal.  Mr Giles phoned me up with a tale of 
disaster;  he was keeping track of his 12 holiday cottages using a Symphony 
database, and something had gone badly wrong.  His holiday bookings for this 
year had vanished, and he was fairly desperate.  I invited him round.  He 
turned up in the sort of car that says "money is no object", and I invited 
him in. 

He explained what had happened.  He'd been showing a friend how marvelous 
Symphony was;  demonstrated setting up a spreadsheet, and saved it to his 
disk.  Then he came out of Symphony and deleted the little demo file.  After 
that, whenever he loaded up his 160K database, Symphony reported "part of 
file is missing", and sure enough, none of his data were there.  "I can't 
get over what an idiot I was," he said. "Firstly not to have a backup, and 
secondly to use my data disk for a casual demonstration." I agreed with him 
(the customer is always right) and asked to see the disk.  I popped it into 
my disk drive, carefully did a Diskcopy and gave it back.  Then I looked at 
the disk.  The directory sector said it had two files on it;  the main 
BOOKINGS file and a small one that had been deleted.  Mr Giles said that the 
small one was the demo.  Then I had a look at the File Allocation Table, and 
that was very strange.  It was the FAT for a disk with eleven files, each 
one contiguous.  The FAT shows the end of file with an FFF flag, and there 
should have been just one of these;  instead there were several scattered 
around.  The second copy of the FAT was exactly the same.  I really can't 
imagine how it could have got like that - DOS does some pretty weird things 

CHKDSK confirmed my findings - it reported 11 chains of "lost clusters". A 
cluster is the unit of disk allocation space - on a double sided diskette, 
that is 1024 bytes (two sectors).  "Lost clusters" is the name given to a 
chain of clusters that is exactly what you would expect for a file, but 
there is no entry in the directory that points to the start of the chain.  
If you ask CHKDSK nicely, it will turn these into files with names like 
FILE0000.CHK.  In some cases, that will work, as if I had done that, and 
then concatenated the files together, there might have been extra bytes at 
the end of each chain, that would have got in the way of the data.  In this 
case, though, it would have worked.  But it didn't occur to me to do that. 

Another method that would have worked would have been to delete the file, 
zero out the FAT, then undelete the file.  The directory entry had the 
correct number of bytes, and because the file was contiguous, any undeleting 
program (such as my own UnDelete) would have worked.  Again, I didn't do 
that, because it didn't occur to me. 

I did it the hard way.  As soon as I saw the FAT, I knew what needed doing, 
and I went into the FAT with my bare hands, and replaced each FFF end-of-
file marker with a pointer to the next cluster.  Then I did the same thing 
with the second copy of the FAT, and then I turned to Mr Giles and said "Its 

He looked a bit surprised - "You haven't done anything yet", he said.  I got 
my copy of Symphony and fired it up.  I loaded his spreadsheet in, and it 
read the disk for ages.  I could see hope beginning to dawn, and then his 
auto-start macro began to run.  We wandered around inside his spreadsheet 
for a few minutes, and he was delighted.  I made an extra copy of his data 
for him, and he departed, slightly poorer in cash, considerably richer in 
data, and somewhat wiser in his attitudes to backups.