FAT File System Analysis (Agan Translation)

xiaoxiao2021-03-06  147

http://www.nondot.org/sabre/os/files/filesystems/fatfilesystem.txt

Original author: Inbar Raz /

FAT is a chain structure, and DOS uses this chain to keep track of the physical location of the data on the hard disk, and can allocate space for the new file. One word in the directory entry point migration address 1AH is the cluster number of the first cluster in this allocation chain structure. If you locate this unit in FAT, it points to the tail of the chain structure, or the next unit, and so on. Observe the following example:

This chart shows some important concepts of reading the FAT. Where: 1> This file - MyFile.txt has 10 clusters of length. The first byte is at a cluster 08H, and the last byte is at cluster 1bh, which is: 8, 9, 0a, 0b, 15, 16, 17, 19, 1a, 1b. Each entry indicates the next entry of the chain structure, and the last entry is given a special code (FF). 2> The cluster 18h is identified as a bad cluster and cannot be assigned to any chain structure. 3> Clusters 6, 7, 10CH-14H, 1CH-1FH are idle, and can be assigned. 4> An additional chain structure begins at cluster 2, ending in cluster 5.

------------ | FAT Details | The FAT structure generally begins in the first logical partition of the DOS partition, (you can use int 25h and dx = 1 ----- ----- to read it). The only way to ensure that the start sector (DX = 0) is read, check the offset 0EH. This is able to know how many boot sectors and reserved sectors prior to FAT (usually 1) are assigned to DX, and then the FAT is read by interrupting INT 25H.

There may be a copy of the FAT that there is more than one copy. There are usually two complete FAT copies. If there are two or more, they will be placed in a continuous space (second FAT is then placed first).

You can help you determine the information of the FAT from the following means: 1> Use INT 25H to read the boot sector and check the data domain. 2> Use the DOS system function to call 36h or 1CH to verify the number of hard drives and clusters. 3> Use the DOS system function to call 44h (if device driver supports generic ioctl) DOS3.2 4> Call 32h using DOS system function to get all useful information. (Not publicized)

Note: Some non-start-up disks (such as some network block devices and some very old-fashioned hard drives) do not contain any useful things.

------------- | 12-bit / 16-bit | FAT table can be 12 or 16 bits. The 12-bit entrance has a high storage efficiency of less than 384K, (entire ---------------------------------- For larger Media, each FAT table entry must be mapped to a larger cluster size), thereby, a 20m hard disk will need to assign 16 disk sector units to use 12-bit formats (change one, 1 word The file will take full 8K size disk cluster. The 16-bit FAT table entry was introduced by DOS 3.0, and the purpose was to manage the 20m hard disk of AT more effectively. Despite this, the floppy disk and 10m hard drive continue to use 12 formats. You can determine that the FAT table is 12-bit structure or 16-bit structure:

DOS 3.0: If a disk has a cluster of more than 4086 (0FF6h), it will use a 16-bit format (4096 is the maximum value of 12-bit format clusters, greater than 0FF6H is reserved). DOS 3.2: If a disk has more than 20,740 (5104h) clusters, it will use 16-bit format (ie: any 10M size disk uses 16-bit format, all other - including large-capacity RAM disks - Use a 12-bit format). Note: A very common misunderstanding is: It is a 16-bit format of FAT allows DOS to work on a disk greater than 32m. In fact, the restriction factor is an interrupt call? INT 25H / 26H (DOS is not accessible with the cluster number than 65535. In general, the cluster size is 512 bytes (far less than 1K), so there is a 32M limit.

In DOS 4.0, INT 25H / 26H supports techniques that allow access cluster numbers above 65535, so support greater than 32M DOS partitions. This does not affect the implementation of FAT. Using a 16-bit FAT entry and 4 sector clusters, the DOS supports the partition with a size of 134M (twice the 8 sector cluster).

---------------- | Read FAT Table | During reading a FAT table entry (along the FAT chain structure) ?? First, the entire FAT table is read Memory, ----------------- from the directory table to get the startup cluster number, then perform the following operations on the 12-bit port:

þ Take the cluster number by 3 ------------- | þ þ þ 上 上 2 2? ------------- ---- - (Each entrance is 1.5 (3/2) byte length) þ Read a word (Word) at the obtained address. (As offset with the starting position of the FAT) þ Have the cluster number is even Use 0FFFH to shield this value (reserved low 12) assume that the cluster number is odd, and the result of 4 bits (reserved high 12 digits) is the entry of the next cluster in the chain structure.

Note: A 12-bit entry can span the boundary of the sector, so you must carefully process the buffer design of the FAT table in a sector.

The 16-bit entry should be simpler --- Each inlet contains 16-bit offset, which is an offset of the lower inlet relative to the FAT table in the chain structure (0FFFH represents the end of the chain structure).

-------------- | FAT table content | FAT table's first byte called Media Descriptor ----------- --- or the ID byte of the FAT table. The next five bytes (12-bit FAT table) or 7 bytes (16-bit FAT table) are 0ffh, and the rest of the FAT table consists of some 12-bit or 16-bit units, each unit represents A cluster on the disk. These units contain one of the following values:

þ (0) 000H ................... Idle cluster (f) FF0H THROUGH (f) FF7H ... Reserved cluster þ (f) FF7H .... ............... Brass (f) FF8H THROUGH (F) FFFH ... End Cluster (0) 002H THROUGH (F) Fefh ... chain structure Next cluster

Note: The high half byte of the above value is used in a 16-bit FAT table, for example, a bad cluster is identified in a 12-bit FAT table identifically an identifier to 0FFF7H in the 16-bit FAT table.

-------------------------------------------------- | Convert a cluster to a fan code | When you get the startup cluster number of a file from the directory interface, you may ---------------------------------------------------------------------------------------------- -------------------------- Want to locate the physical sector of the storage file (or child directory) data. A physical disk (or a DOS partition of a hard disk) is designed below:

þ Start sector and retention sector þ The first FAT table þ Second FAT table (optional - not used on the RAM disk) þ root directory þ Data area (all file data set here ^ _ _ ^, Including files and directories) each section of this design is variable. The size of each section must be obtained for clustering to the correct conversion of the sector. The following formula provides an official release method to obtain a DOS logical sector number according to cluster number: root directory sector = byte number / (number of entss in the root directory * 32) FAT table sector Number = FAT Table Number *? Each FAT table number data start fan code = reserved sector number of sectors FAT table root directory sector number

INT 25H / 26H sector number = data start fan code ((a cluster number-2) * The number of sectors per cluster)

The following variables are:

The number of bytes per sector Each FAT table number fat number

The number of entrances in the root directory reserves the number of sectors of each cluster

They are all from the boot sector or the BPB structure (if you can access). The resulting sector number can be assigned to DX, directly accessed DOS disk directly via INT 25H / 26H.

If you are an afraid of trouble, you can call the trouble by using an unapplicaled DOS system function (FN 32H - get disk information), save the calculation, this function call has been calculated in advance, including files The data start fan code (that is, the "data start fan area number" mentioned above).

Author's friendly tips: The largest place I found above is on the scan of the directory. For example, you can omit the DOS file lookup feature, you can directly read the direct read operation of the directory sector. In a program that must obtain a list of all files and directories, the direct access to the directory sector will be more than twice as fast as the DOS function calls FNS 4EH and 4FH.

转载请注明原文地址:https://www.9cbs.com/read-127910.html

New Post(0)