Monday, June 15, 2009

FAT filesystem

In this post I have tried not to mention a lot of specifics, giving only an overview of the FAT filesystem. I know it's not very well written, but please bear...promise to get better with time.
The FAT file system actually refers to a family of filesystems consisting of the VFAT, FAT12,FAT16,FAT32, the numbers indicating the number of bits used to indicate the cluster number(FAT32 is an exception). The name comes from the logical structure that the file system uses-the File Allocation Table. This filesystem was used by DOS on the first IBM PCs and became a standard for the PCs that followed. The file allocation table provides information about allocation units. Now where did they come up? Well, generally, we think of files to be referred by the number of sectors of size 512 bytes on the disk. However one can imagine the performance issues that will be encountered when keeping track of big files in terms of the sectors. Hence the idea to group sectors into bigger chunks called clusters. The process by which clusters are assigned to files is called allocation. Hence clusters are called allocation units ranging from sizes of 4 to 64 sectors.
Every file must be allocated an integer number of clusters. This means that if a volume uses clusters that contain 8,192 bytes, an 8,000 byte file uses one cluster (8,192 bytes on the disk) but a 9,000 byte file uses two clusters (16,384 bytes on the disk). This is why cluster size is an important consideration in making sure you maximize the efficient use of the disk--larger cluster sizes result in more wasted space because files are less likely to fill up an integer number of clusters. The cluster size is determined primarily by the size of the disk volume after partition: generally speaking, larger volumes use larger cluster sizes.
The structure of a volume that is formatted using FAT filesystem has the structure as shown:

| Partition Boot Sector | FAT 1 | FAT 2(Copy) | Root folder | Other folders and files |


The Partition Boot sector:
The Partition boot sector is the first sector on a logical volume. A logical volume may be a primary partition, or a logical volume within an extended partition or a composite of two or more partitions. This file system boot sector is different from the master boot record(MBR). MBR is the first sector on the whole hard disk, while the partition boot sector is the first sector on a particular partition within the disk. During the boot process, after the POST is performed, the BIOS first finds a boot device, then loads the boot sector of the device. For a hard disk,this is the MBR. The control is passed on to the MBR code. The MBR code helps to load the boot sector of the active primary partition. Upto this point the boot process remains independent of the file system or the operating system used.
Now in case of FAT volumes that have Windows NT installed, the FAT boot sector is responsible for identifying the location of the file "NTLDR" on the volume, loading it into memory, and transferring control to it. Since execution control is passed on to the boot sector, there is need for an executable to be present at its first location. This is generally a JUMP instruction that serves to jump over the following "non-executable" locations. Then comes the OEM id that identifies the operating system that formatted the volume. Following the OEM id, there is a structure known as the BIOS parameter block that provides enough information to the executable part to find the NTLDR. It consists of info like sectors per cluster, sector size, number of FATs(including the multiple copies), root entries etc. On a bootable or non-bootable volume, the BIOS parameter block is followed by execuable code. The last 2 bytes in any boot sector are always 0x55, 0xAA.

The File Allocation Table:
The file allocation table contains the following types of information about each cluster on the volume :

* Unused (0x0000)
* Cluster in use by a file
* Bad cluster (0xFFF7)
* Last cluster in a file (0xFFF8-0xFFFF)

To protect the volume, two copies of the table are kept, in case one becomes damaged. In addition, the file allocation tables must be stored in a fixed location so that the files needed to start the system can be correctly located.
There is no organization to the FAT folder structure, and files are given the first available location on the volume. The starting cluster number is the address of the first cluster used by the file. Each cluster contains a pointer to the next cluster in the file, or an indication (0xFFFF) that this cluster is the end of the file.

The Root Folder:
The root folder contains entries for each file and folder on the root. In the conventional FAT system, the root directory is fixed in place after the 2 FATs. The file system hierarchy is thus anchored at the root directory. Even the size of the root directory has a limit. It can a hold a maximum of 512 entries in case of an hard disk. This is in contrast to the regular directory that can be placed anywhere and can have a variable size. One of the improvements introduced in the FAT32 version of the FAT file system was to remove these restrictions on the root directory. Under FAT32, the root directory is treated much more like a regular directory, and can be relocated and expanded in size like any other. An entry in the root directory contains information like name, attribute, time and date when created, last accessed date, last modified date and time, starting cluster number in the FAT and the file size. A FAT file has four attributes that can be turned on or off by the user-system file, archive file, read-only and hidden.

The root folder is followed by the storage of the other files and folders.

FAT32:
FAT32 is a derivative of the File Allocation Table (FAT) file system that supports drives with over 2GB of storage. Because FAT32 drives can contain more than 65,526 clusters, smaller clusters are used than on large FAT16 drives. This method results in more efficient space allocation on the FAT32 drive. The FAT32 file system includes four bytes per cluster within the file allocation table. However, the high 4 bits of the 32-bit values in the FAT32 file allocation table are reserved and are not part of the cluster number.

Ref: http://www.ntfs.com/fat-systems.htm

Adding Categories to Blogs

In case you are wondering how I have got categories on my blog plage, just read this one. I was dying to write on different topics but the thought of putting technical things juxtaposed to travel ones or others made me think of starting another blog for a different topic. But I thought of googling...and bang...some guru has done it already..http://makemoneywithkassper.blogspot.com/2007/06/how-to-add-categories-to-blogger.html

To explain the process in brief, I will tell you how I did it. First make this html script ready in any text editor. For me the script is:

<h2 class="sidebar-title">Categories</h2>
<u1>
<li><a href="http://e-nertia.blogspot.com/search/label/Introduction">Introduction</a></li>
<li><a href="http://e-nertia.blogspot.com/search/label/Technical">Technical</a></li>
<li><a href="http://e-nertia.blogspot.com/search/label/Travel">Travel</a></li>
</u1>

Replace the "http://........blogspot.com" with your blog homepage link and change the names of the topics as you wish(for me they are Introduction, Technical..). Make sure that the term in the link and the actual label are the same.
Now go to the Layout Page. It must be showing a skeleton of your blog page. The part of it that shows your blog archive and profile must also be having a link "Add a Gadget". Click on the link . In the new window that opens, click on the HTML/Java script option. Paste the HTML script that you have written in the text editor into the content box. No title is required. Save the changes. Done.
Now whenever you are writing a post that belongs to a particular topic, write in the box for the label the exact category that you have made for it. So for this post i wrote the label as Technical.
Happy Organisation!!
The challenge I faced during writing of this blog was printing the HTML script as text to show you the script. I hardly have any idea of HTML scripts. I saw the page sources of sites that have showed examples of HTML scripts. So, as a piece of information, i have replaced all the > with &gt; and < with &lt;