7. Saving and Deleting files.

So you read about how the details of a file are stored within a Directory Table and the File Allocation Table. But how does a file get saved onto hard disk in the first place?

This is the job of the file manager. In Windows, the application is called 'Windows Explorer'.

Saving a file

When a file needs to be stored, the File Manager will begin to traverse the FAT looksaveing for a free cluster. Once it finds one, it notes the starting cluster in the relevant Directory table.

Then it writes a chunk of the file into the cluster.

Next, it looks for another free cluster as noted in the FAT and writes another chunk of data and so on, until the last chunk of data is written. If the last chunk of data is smaller than a cluster, then that unused space is wasted.

So the size of a cluster determines how efficient the filing system is in using the hard disk. If the cluster is too small (2kb?), then that limits how many files can be stored on the disk (A FAT can only hold so many records). If the cluster is too large (32kb?), then the unused space of a smaller file is wasted.

Deleting a file

As noted, a file is made up of a chain of clusters. When a file is 'deleted' the data on the hard disk is not removed - it is still there.

But what happens is that the File Manager starts with the first cluster and marks that as 'free' in the File Allocation Table. Then it goes to the next cluster in the chain and marks that as free and so on, until the last cluster is marked as free. Then it goes to the Directory Table and flags the file as 'deleted' often by just changing the first character of the file name to a special character.

The next file to be saved may or may not come across those freed clusters, it just depends on which ones the file manager finds at the time.

This is why you can have 'file recovery' applications that have a good chance of 'un-deleting' a file. The recovery application will obtain the location of the first cluster and then traverse the FAT marking the file chain as 'not free' once more. Then it will update the file name in the relevant directory table and voila! you have a recovered file.

The 'recycle' bin in Windows works in a similar manner. It will prevent the file clusters from being over-written until there are no more free clusters available.

 

 

 

Copyright © www.teach-ict.com