Copyright © 2002 Katrin Becker 1998-2002 Last Modified November 26, 2002 10:33 AM

CPSC 461 File Structures
Assignment Last
Fried FAT
(Floppy Disk Recovery Program)

References: http://www.pcguide.com/ref/fdd/index.htm

Here's the deal: you have some important data stored on a floppy disk but the darned thing is corrupted and now you can't get at it. You really can't face re-creating the data so you want to try and see how much of the file you can recover. You intend to do this by reading the entire disk into a file (binary, of course), and then trying to reconstruct your file.

So far, we have managed to dump the contents of the disk into a file. Now we have to do the rest.
The Disk Info:
Here's what we know: [ using values for single-sided ]

Floppies have: 80 tracks / side; 9 sectors / track; 512 bytes / sector

= (80 X 9 X 2) = 1440 sectors total
1440 sectors X 512 bytes = 737,280 bytes total
737,280 bytes total; a minimum of 720,000 bytes are available for index information and user space
= 17,280 bytes are available for formatting and in-sector information
= 12 bytes/sector can be reserved for formatting and locating information

The typical Floppy disk addressing works like this: [ you may or may not need this information]

Head# | Track# | Sector# | Logical Sector#
0 | 0 | 1 | 0
0 | 0 | 2 | 1
: | : | : | :
0 | 0 | 9 | 8
1 | 0 | 1 | 9
1 | 0 | 2 | 10
: | : | : | :
1 | 0 | 9 | 17
0 | 1 | 1 | 18
0 | 1 | 2 | 19
: | : | : | :
0 | 1 | 9 | 26
1 | 1 | 1 | 27
1 | 1 | 2 | 28
: | : | : | :
1 | 79 | 9 | 1439

The O/S IO system is to access information on the dusk using logical addresses only but the controller expects physical addresses.

Typical FAT looks like this:

Offset | Contents
0 | 8 byte file name
8 | 3 byte extension
11 | attribute byte
| bit 0 = read only bit
| bit 1 = hidden file
| bit 2 = system file
| bit 3 = volume label entry (has no associated cluster)
| bit 4 = subdirectory entry
| bit 5 = archive (used by backup programs)
22 | time (format: 5 bits for hour; 6 bits for minute; 5 bits for second)
24 | date (format: 7 bits for year (year-1980); 4 bits for month; 6 bits for day)
26 | starting cluster
28 | 2-word byte count

Sector 0 = master boot sector (has information on how the disk is partitioned)
Sectors 1 & 2 = File Allocation Table
Sector 3 = root Directory
The FAT consists of 12-bit entries for media with < 4096 clusters
entry 0 identifies the media being used
entry 1 is reserved
entry 2...n 1 entry per cluster (gives info about the usability / reliability of the cluster
the directory entry identifies the first cluster of the file; the rest are formed by a chain of FAT entries

The File Info:

The file we are trying to recover is a Fixed Length Record file with the following format:

Field: | Contents | Size | Type |
1 | ID | 4 bytes | integer | entry-sequenced so ID#s will be sequential in an uncorrupted file starting with #314
2 | "name" | 64 | char |
3 | phone-number | 5 bytes | 10 digit BCD |
4 | "other info" | 128 | char |
5 | pad | 3 bytes | zeros | - to get us to a word boundary
total: |  | 204 bytes |  |

Records will NOT be split across sectors.

You may write this code [including shell scripts, perl, etc.] in any language your TA is willing to mark.

The program may require user input to complete its job, or it may work 'alone'.

These are the characteristics of the 'disks':

Disk 1 | - the file is fine (spread over the 'disk' in blocks, not necessarily in order), but the FAT is fried
Disk 2 | - some blocks of the file are missing
Disk 3 | - some number of data records are messed up - zero ID - bad / zero phone number - name is null
Disk 4 | - 1st 128 bytes of each block are fried
Disk 5 | - LAST 128 bytes of each block are fried
Disk 6 | - file is OK but all the ID numbers are shifted
Disk 7 | - the entire contents of the file is shifted by one byte

Requirements:

C- Version | Able to reconstruct file on test "disk" 1 |
B-Version | Able to reconstruct file on test "disks" 2-5 |
A-Version | Able to reconstruct file on test "disks" 6-7 |
BONUS | 1. [5-??? Points] print diagnostic information (like what went wrong? What is missing?) |

Copyright © 2002 Katrin Becker 1998-2002 Last Modified November 26, 2002 10:33 AM