File Allocation Table

Source: Internet
Author: User
Fat is the file addressing format of DOS and Windows9x systems. It is located after DBR.
When interpreting the concept of a file allocation table, we need to talk about the concept of a cluster. Files occupy disk space. The basic unit is not a byte but a cluster. In general, each floppy disk cluster has one sector. The number of sectors in each cluster of the hard disk is related to the total capacity of the hard disk, which may be 4, 8, 16, 32, 64 ...... The data of the same file is not necessarily completely stored in a continuous area of the disk, but is often divided into several segments and stored like a chain. This storage method is called the chained storage of files. Because the hard disk stores the connection information (FAT) between segments, the operating system can always accurately locate and read each segment while reading files.
To achieve file chain storage, the hard disk must accurately record which clusters have been occupied by files, and specify the cluster number of the next cluster for each occupied cluster. For the last cluster of a file, you must specify that the cluster has no successor cluster. These are all stored in the fat table. There are many table items in the table, and each item records the information of a cluster. Because of the importance of fat for file management, fat has a backup to ensure security, that is, the same fat is created after the original fat. All items in the initial fat are marked as "not occupied", but if the disk is partially damaged, format Program The damaged cluster will be detected, and the corresponding item will be marked as "bad cluster". This cluster will not be used when files are stored in the future. The number of fat items is the same as the total number of clusters on the hard disk. The number of bytes occupied by each item must be consistent with the total number of clusters, because the number of clusters must be stored. There are multiple fat formats, the most common of which are fat16 and FAT32.
After a disk is formatted, an important data table-File Allocation (fat) exists in several sectors following its logical 0-sector (that is, the Boot Sector). The file allocation table is in duplicate, the size of the occupied sector depends on the disk type. As the name suggests, the file allocation table is used to indicate the air separation configuration information of the disk component. It does not represent the information of the file directory in the boot area or actually store the file content.

We know that a disk is composed of one slice, and several slice are combined into one cluster. File Access is based on a cluster, even if the file contains only one byte. Each cluster has corresponding table items in the file allocation table. The cluster number is the table item number, and each table item occupies 1.5 bytes (the disk space is less than 10 MB) or 2 bytes (the disk space is more than 10 MB ). For convenience, the table items mentioned later refer to two bytes.

The file allocation table structure is as follows: 1 (h indicates hexadecimal)
Table 1
0th-byte header, table disk type. FFH dual-sided floppy disk, each 8-sector Feh single-sided floppy disk, each 8-sector FDH dual-sided floppy disk, 9-sector fcch single-sided floppy disk per track, 9-sector fc8h hard disk per track
1st ~ 2 bytes (table entry 1) indicates the status of the first cluster. Because the first cluster is occupied by the system, the two bytes are ffffh.
3rd ~ 4-byte (Table item 2) indicates the status of the second cluster. If this cluster is bad in the fffh table, DOS has been marked as unavailable. 0000h indicates that the cluster is empty and can be used; the fff8h table cannot indicate that the cluster is the last cluster of the file. The remaining number indicates the next cluster number of the file. Note that the high byte is before the low byte.
5th ~ 6 bytes (table entry 3) indicates the status of the third cluster, as shown in the preceding figure.

Note:
Do not mistakenly think of the number in the table item as the current cluster number. Instead, it should be the cluster number of the next cluster in the file .. After the high byte is reached, the low byte is in front of the data storage method. You should adjust it when reading the data. For example, two bytes of 12 h and 34 h should be adjusted to 3412 H.
The file allocation table works with the file directory (FDT) to manage files on the entire disk in a unified manner. It tells the system disk which clusters are bad or used, which clusters can be used, and stores the cluster numbers used by each file. It is the "Chief scheduler" of the file ".
When writing a file in DOS, first check whether the same file name exists in the file directory. If no file name exists, use a file directory and table item. Then, check the cluster corresponding to each table item in fat, at the same time, write the cluster number to the 26-27 bytes of the table item in the file directory. If the file length is more than one cluster, continue searching for available clusters, after finding the cluster number, write it to the table item found last time until the end of the file. Fill in fff8h In the table item of the last cluster to form a one-way linked list.
When deleting a file, DOS only changes The 0th bytes of the table item in the file directory table to e5h. The table item has been deleted, in the file allocation table, clear the table items of the clusters occupied by the file to 0 and release the space. The reason why the undelete.exe, unerase.exe, and other types of restoration and deletion tools can work is still being deleted.
The position of a file allocation table in the system is very important. You are advised not to modify it to avoid serious consequences caused by misoperations.

Fat table Positioning
The main structure of Hard Disk partitioning:
(Cylinder cylindrical/track-side head-sector address? -? -?)
Primary Partition
Name address length (slice)
Main Boot Record 0-0-1 1
System sector (system secotrs) 0-0-2, 0-0-63 62
Boot Sector (BOOT) 0-1-1 1
In the fat16 system, this sector contains the BPB (BiOS parameter block) Table, which describes the Logical Disk structure and contains the number of hidden sectors (calculated from 0-1-1), the number of fat sectors, the number of fat copies, the total number of Hard Disk heads, and the maximum value of the root directory table.
In the FAT32 system, the offset of the BPB table is different from that of the fat16 table, but the table items are basically the same. The entire hidden sector is used as the description area of the Logical Disk.
Hidden sector (hidden secotrs ):
Fat16 0-1-1 1
FAT32 0-1-1 32
File Allocation Table ):
Fat16 0-1-2 varies according to the Logical Disk capacity
FAT32 0-1-33 varies according to the Logical Disk capacity
Note:
Each table item in fat16 consists of 2 bytes (16 bits). Generally, each table item points to a cluster containing 64 sectors, namely, 32 KB.
The maximum size of a logical disk is 2047 MB.
Each table item of FAT32 consists of 4 bytes (32 bits). Generally, each table item points to a cluster containing 8 sectors, that is, 4 K bytes.
The Logical Disk capacity is 512 MB at least.
For the C partition, at the 0c2h offset of MBR, fat16 is 06 h, and FAT32 is 0ch.
The calculation formula is as follows:
Length of each slice = 512 bytes
Total number of clusters = Logical Disk capacity/cluster capacity
Total number of clusters = fat table length (bytes)/length of each table item (bytes)-2
Fat table length = Logical Disk capacity/cluster capacity * length of each table item
The fat table starts with a media descriptor + a string of "occupied" signs:
Fat16 hard drive ---- F8 FF 7f
FAT32 hard disk ---- F8 FF 0f FF 0f
Each valid fat structure zone contains two identical copies: fat1 and fat2.
File directory table, also known as the root directory:
Followed by the next sector in fat2, with a length of 32 sectors (256 table items ). If long file names are supported
The value is 64 bytes. The first 32 bytes are long file links. The last 32 bytes are file attributes, including the file length.
Degree, start address, date, and time. If long file names are not supported, the attribute description of each table item is 32 bytes.
Data Area ):
It follows the next sector of the FDT until the end address of the Logical Disk.
Extended partitions
Name address length (slice)
Extend partition )? -Y-1 1
System secotrs )? -Y-2 ,? Y-63 62
Boot Sector )? -(Y + 1)-1 1
The subsequent items are the same as those in the primary partition ......

Read/write failures caused by fat tables

The Hard Disk File Allocation Table is huge and cannot be repaired manually. You can only rely on tools.
The fat table records the storage address of the hard disk data. Each file has a set of fat chains to specify the address of the cluster to store. Corruption of the fat table means the loss of file content. Fortunately, the DOS system provides two fat tables. If the current fat table is damaged, the second fat table can be replaced. However, because the length of the fat table of disks of different specifications and the address of the second fat table are not fixed, you must find the correct position in the fix, some tool software such as Nu has such repair functions and is very convenient to use. Debug can also be used to implement this operation, that is, use its m command to move the second fat table to the first table (this is not recommended ). If the second fat table is damaged, the hard disk cannot be restored to its original state, but the file data is still stored in the data area of the hard disk, you can use the chkdsk or Scandisk command to fix the issue *. chk file, which is the loss of the sector data of the fat chain. If it is a text file, you can extract the complete or part of the file content from it.

Fat table for allocation of floppy disk files

when running a program, you may sometimes see the File Allocation Table bad and drive a (Bad File Allocation Table) error information on the screen, causing the program to fail to run properly.
we know that there are two file allocation tables on the disk: fat1 and fat2. Fat1 is used for daily work, and fat2 is used for backup. Therefore, the fat2 table can be patched when fat1 is damaged.
the specific method is to run debug, read fat2 into the buffer, and overwrite fat1 in the disk with the fat2 data of the buffer.
for example, to fix a 3-inch M floppy disk, go to the drive
debug environment in the DOS environment
at the "-" prompt, perform the following operations:
-L 100 0 0a 9
-W 100 0 1 9
-q
The following table describes how to fix other types of floppy disks.
starting and ending logical sector 5.25 "low password 5.25" high password 3.5 "low password 3.5" high password
boot Zone 0 0 0 0
fat1 1-2 1-7 1 -3 1-9
fat2 3-4 8-0eh 4-6 0a-12h
for example, we want to fix the fat 5.25 "high-density floppy disk, change the preceding parameters to
-L 100 0 8 7
-W 100 0 1 7
-q

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.