File system is a kind of documentation management system. In a typical document management system, cabinets with shelves and drawers are placed in a location and labeled. Folders to be placed in cabinet shelves and drawers are also labeled. A log book that includes labels and location of folders is prepared.
When a document on paper is placed in a folder, document name and location where it is placed (and some other information) are recorded in the log book. Separators are used between documents inside a folder.
Documents are classified in accordance with a criteria (originator, subject etc) and stored in folders accordingly.
Folders are also classified and grouped. In a file system, the logic is similar. A physical storage media is cabinets and drawers. Formatting is preparing and labeling the storage area, and creating a log book.
In PC’s world, there are various types of storages. Hard Disk Drives (HDD) are most common storage devices. Although Solid State Devices (SSD) are getting popular, mechanical (rotary) HDDs are still dominantly used. An HDD consists of a number of disks (looks similar to CDs, but CDs are optical). The data is written on / read from both sides of discs by heads. Disc’s surface called as Cylinder is logically divided into tracks. Tracks are logically divided into sectors which is the smallest units. These are performed by low-level formatting process. These parameters are named as HDD Geometry. Another important term is CHS (Cylinder, Head, Sector). It is an early method and has limitations due to number of bits reserved for each parameter. In order to overcome the limitations, a 48 bit addressing system called Logical Block Addressing (LBA) is used. LBA can be calculated by using CHS values.
FAT 12, FAT 16 and FAT 32 are very similar to each other. The number indicates how many clusters a disk drive/volume can contain. A Cluster is a Group of Sectors. In FAT 12, the field that holds the cluster number is 12-bit. Thus, the maximum of 2,048 clusters can be addressed. Maximum drive size can be 16MB while it can be 2GB (maximum of 65,526 clusters) in FAT 16.
Last member of FAT File System is 32 bit but, 28 bit numbers can be used since 4 bits are reserved. This allows 2TB drives (268M clusters). It should be noted that the size limits are for logical drives / volumes that reside on partitions, not for physical drives.
When an HDD is formatted, each partition is prepared to use a logical drive / volume. The layout of a drive is as follows;
At the beginning of each partition (first sector of a partition), a Boot Record is placed. This record keeps information about the disk such as number of number of sector size in bytes, number of sectors per cluster, sectors per track, number of heads, volume serial number, address for root directory etc. A small piece of code is provided for loading the rest of the operating system. The table ends with a boot record marker.
In the volume layout, Root Directory is in the Data Area and located after FAT area. However, the Root Directory comes first operationally. At the beginning, only known information is location of first cluster address of Root Directory. The directory entires are 32 bit records and contain following information for files / subdirectories in short filename format;
But, current systems allow longer file names. The long filename (LFN) entries occupies a number of record fields and contain the following information in the first record for backward compatibility;
Additional records are called as LFN entries and hold long file name as unicharacter that allows to use characters of different languages. First byte of each LFN entry is ordinal field that tells the order of entries. The last entry is marked by setting 6th bit of the ordinance field to high. The entries are in the descending order as shown below;
Directory records only point starting cluster of files / subdirectories. The cluster information is stored in FAT. FAT is a cluster map. Size of FAT equals the number of clusters multiplied by 32 for FAT 32. If the data occupies more than one cluster the associated FAT field shows the next cluster. If a cluster contains data that fits in one cluster or it is last cluster, its field in the FAT has FFFF FFFFh number.
In order to find where a file is stored, cluster chain needs to be followed. In an example, a file is stored in clusters; 5-9-11. Its directory entry points cluster 5. The number at position 5 of FAT is 9 (second cluster of the file). The position 9 of FAT has FFFF FFFFh to mark it as last cluster.
The rest of the logical disk drive / volume is allocated for files and subdirectories.