1

Been seaching google for a good explanation for how FAT systems identify free space and the structure of FAT Entry files.

Alot of the explanations ive found are quite hard to follow can anyone help brief sum these up?

i understand that clusters are marked as unused but is this within the root directory or data region? and is the information on clusters status just marked in a table?

I haven't managed to gain any knowledge on the structure of the entry files either, just that they use chains to keep the clusters together

Anyone help?

user1949280
  • 75
  • 2
  • 8
  • Straight from the source: http://staff.washington.edu/dittrich/misc/fatgen103.pdf –  Jan 06 '13 at 19:11

2 Answers2

0

A file system can be thought of having three (3) types of data: file data, file meta-data and file system meta-data. File data is file or directory contents. File meta-data is that which tells us where the file data is stored on the disk. File system meta-data tells us how the file system allocates the blocks used in the file system.

The FAT file system however does not keep the lines so clear cut. Its disk structures often blur these distinctions.

The File Allocation Table (FAT) itself blurs the lines of the file meta-data and file system meta-data. That is, the FAT entries identify both the cluster number of the where the next cluster of file (or directory) data can be found as well as indicating to the file system whether the cluster identified by the index into the FAT is available (or not). As you indicated in your question, this forms a chain. A special marker (the specific value escapes my memory) indicates that the cluster identified by the index into the FAT is the last cluster in the chain.

Directory entries in a FAT based file system are both file data and file meta-data. They read like files with their entries being the "file data". However, their entries are also interpreted as file meta-data, for they contain the file attributes (permissions, file size, and the starting cluster number--which is an index into the FAT).

The root directory is a special directory on a FAT file system. If memory serves, it does not have either a "." nor a ".." entry. On FAT12 and FAT16 systems, the size of the root directory is specified when the disk is formatted and is thus of fixed size--however, its clusters are still marked in the FAT. On FAT32, the root directory size is not set at format time and can grow. The starting cluster of the root directory is stored in a special field in one of the file system meta-data structures (as I'm going by memory the name of this structure eludes me).

Hope this helps.

Sparky
  • 13,505
  • 4
  • 26
  • 27
  • To my understanding this answer does not clarify how to identify (calculate) free space in a FAT filesystem... – goulashsoup Jun 15 '22 at 14:47
  • 1
    Good point. Free space can be calculated by iterating through the FAT and counting the number of entries that have an available cluster number (typically the value 0x0). If memory serves, FAT32 reserves the top 4 bits so for that you need to mask with 0xF0000000 and check that result against 0. The free space is then calculated by # of available clusters times the cluster size. – Sparky Jun 16 '22 at 11:46
  • That seems absolutely logical, but is there any documentation or standard that specifies this method? Point is: An empty FAT filesystem will have `0xFFFFFFFF` in the 3. FAT entry to clarify that this is the last sector of the root parition, therefore this calculation method would result in having always 1 block used. (This is actually the case when using `df` or `stat`) – goulashsoup Jun 16 '22 at 14:30
  • There was a document from MS that touted itself as having the official FAT description that I can't seem to find at the moment. For FAT32, a new on disk structure was added to track FAT usage (count of free clusters and the like). As I recall, it stated that that new structure should only be used as a hint/guide to determine the FAT usage when mounted, and that the only true way of knowing is to scan the FAT as described above. – Sparky Jul 19 '22 at 20:42
-2

Here is a fairly long article that has lots of information about fat file systems. It should provide all the details you need.

http://en.wikipedia.org/wiki/File_Allocation_Table

Wouter J
  • 41,455
  • 15
  • 107
  • 112
Marichyasana
  • 2,966
  • 1
  • 19
  • 20