[net.micro.pc] DOS File Allocation Table

aaa@mtunh.UUCP (Aaron Akman) (07/24/85)

****

1.	The identity of the first cluster in a DOS file is contained
	in the file's directory entry.  The directory entry also has
	the size of the file in it...

2.	The locations of subsequent clusters are found in the File
	Allocation Table--they are in sort of a linked list.  The
	File Allocation Table is a big array that has (more or less)
	one entry for each cluster on your disk.  To find the second
	cluster in the file, you use the identity of the first cluster
	to index into the FAT--like so:

		second_cluster = FAT[first_cluster]

	The third cluster is obtained using the second cluster, and so
	on...

3.	You know that you have reached the last allocated cluster if
	the next one is between FF8H and FFFH (this is how it is for
	DOS 2.0 anyhow...)

4.	Any cluster that is marked in the FAT with a zero, is free to
	be allocated...

5.	When you delete a file, all of the FAT entries corresponding
	to the clusters of that file are marked with a zero...the
	directory entry for the file is not deleted, but the first
	character in the file's name is changed to E5H...the next time
	a file is created in that directory, that slot may be reused.

6.	Here's how an UNERASE utility might work:

	a. Show the user a list of the files whose names begin with
	   E5H and let them choose the file that they want to
	   UNERASE...let them change the first character back to some
	   readable ASCII character...

	b. Using the directory entry, which is still intact, find the
	   first cluster of the file (on a double-sided, double-density
	   floppy each cluster is 1024 bytes, and on a 10Mbyte hard
	   disk each is cluster is 4096 bytes [I think...])

	c. Working through the FAT, show the user each cluster that is
	   listed as being free (zero in the FAT), and ask them if they
	   want to add that to the file...using that size of the file--
	   which was still intact in the file's directory entry--repeat
	   this procedure until the user has added the number of clusters
	   that would be needed to contain a file of the size indicated.

	d. This doesn't always work...but it works enough to make it a
	   popular utility to have...

7.	That's all...

Aaron Akman, allegra!mtunh!aaa