Fat and exFAT file systems

Source: Internet
Author: User

File system

A file system is the method and data structure used by the operating system to clear the files on a disk or partition; A method for organizing files on disk. Compare common FAT file systems and exFAT file systems on mobile storage devices.

The FAT partition is divided into FAT12, FAT16 and FAT32 three formats according to the number of each cluster chain in fat table.

exFAT is a file system that is designed to address FAT32 and other files that do not support 4G and larger.

Knowledge Point BIOS
bios(basic input output system),他是一组固化在计算机主板上ROM芯片上的程序,保存着计算机最重要的基本输入输出程序,开关机自荐程序和系统自启动程序.他可以从CMOS上读写系统设置的具体信息,主要为计算机提供最底层,最直接的硬件设置和控制.
MBR sector
MBR(master boot record)即主引导扇区(或记录),位于整个硬盘的0柱面0磁头1扇区(即硬盘的第一个扇区),bios在执行完自己固有的程序后会jump到MBR的第一条指令,并将系统的控制权交由MBR,总共1个扇区的主引导记录,MBR引导程序战前446字节(0h~1bdh),随后的64字节(1beh~1fdh)为DPT(disk partitiontable),最后为"55 aa"结束符.MBR具有公共引导的特性,与具体的操作系统无关,具有唯一性.  
noun explanation
FAT :   File Allocation Table.文件分配表EXFAT:  Extended File Allocation Table .扩展文件分配表BPB:   BIOS Parameter block.BIOS参数块BS:     Boot Sector.启动扇区LSN:   Logical Sector Number.逻辑扇区号PSN:   Physical Sector Number.物理扇区号LBA:   Logical Block Address.逻辑块地址
FAT12
采用12位文件分配表最大簇总数4085(2的12次方)最大分区容量8M (4096clusters × 4sectors/clusters × 512bytes/sectors)只能是8.3格式的文件名(短名)
FAT16
采用16位的文件分配表最大簇总数65524(2的16次方)最大分区容量2G严重缺陷:大容量磁盘利用效率低
FAT32
采用32位的文件分配表最大簇总数(2的32次方)单个文件不能大于4G当分区小于512M时,Fat32不会发生作用不超过8GB的分区中,FAT32分区格式的每个簇都固定为4KBFat32不能保持向下兼容
Note: You can view the disk partition information via Winhex FAT table data structure

The Fat table is a one by one list that corresponds to the data area cluster number, and the file system allocates disk space to be allocated by cluster, so that when the file occupies disk space, the base unit is a cluster.
Fat tables are based on the number of clusters that correspond to the file. The first cluster that holds the data is cluster 2.
The size of the FAT table entry is related to the fat type, and the FAT12 table entry is 12-bit,fat16 to 16-bit,fat32 and 32-bit.
FAT32 Fat table entries only 28-bit can be used, so his high 4 bits are reserved. FAT32 completely copies a backup of the boot sector, including the contents of the BPB, in a region where the sector code is 6.

Criteria for determining the Fattype

The detection of the Fat type (fattype) (FAT12, or FAT16, or FAT32) can only be determined by calculating the number of clusters (countofclusters) of the data area in the FAT volume, and there is no other way.

FAT directory Structure

For fat12/fat16, the root directory is stored in a fixed place on disk, immediately after the last fat table. The number of sectors in the root directory is also fixed and can be computed based on **bpb_rootentcn**t.

FAT32 root directory consists of cluster chain, its sector number is not determined, the root of the first sector is stored in bpb_rootclus , the root directory is different from other directories, no date and time stamp, no directory name, and there is no "." In the root directory. and ".." These two directory entries. Another special place in the root directory is that there is a file in the root directory that sets the ATTR_VOLUME_ID bit, which is unique across the entire fat volume.

dir_ntres:
When a file has only a short name, the casing rules for that short name are as follows:

1. 此值为18H时,文件名和扩展名都小写。2. 此值为10H时,文件名大写而扩展名小写。3. 此值为08H时,文件名小写而扩展名大写。4. 此值为00H时,文件名和扩展名都大写。

dir_attr:

Long name and short name rules

Short name (8+3name) is the legacy of FAT16, in order to be compatible with Windows later versions of files and directories have long names and short names.
The following 6 processing principles are stored for long name directory entries and corresponding aliases (short name) catalog entries:

1.取长文件名的前6个字符加上“~1”形成长文件名的别名(即短文件名),并将长文件名中最后一部分(最后一个间隔符“.”后面字符)的前3个字符作为其扩展名。  2.如果已存在这个名字的文件,则符号“~”后的数字会自动增加  3.任何包括小写字母的文件名都被看作是长文件名,而不管其长度是多少。  4.长文件名存储在属性标志为OFH的32字节目录登记项中(这是与短文件名目录项的区别)。用Unicode格式编码,每个字符(无论是英文或是汉字)均占2字节。  6.每个目录登记项用26个字节存储13个字符(序号由第1字节指定)。位置多余时,先用00h表示结束,再用FFH填充。  7.长文件名用若干个长名目录项保存,长文件名目录项倒序排在文件短目录项前面。  

Windows9x will give different file names according to the nature of the application, 16-bit applications get 8.3-format file names, and 32-bit applications get long filenames.

Note: Try not to create long filenames under the root directory! Fat Calculation formula

The number of sectors that the root directory occupies (rootdirsectors):

Rootdirsectors = ((BPB_ROOTENTCNT * +) + (bpb_bytepersec-1))/bpb_bytepersec;

Start address of data area (Firstdatasector):

Firstdatasector = bpb_rsvdseccnt + (Bpb_numfats * Fatsz) + rootdirsectors;

其中,FATSz可以由下面条件获取:  If(BPB_FATSz16 != 0)      FATSz = BPB_FATSz16;  Else      FATSz = BPB_FATSz32;  

Since each cluster that holds the data is cluster 2, the starting address of the data area is also the same as the starting address of cluster 2, thus the following calculation formula can be obtained.
To a valid cluster number N (n>=2), each sector area code of the cluster can be computed by the cluster number:

Firstsectorofcluster = ((N-2) * bpb_secperclus + firstdatasector)

Number of sectors in the data area (DATASEC):

Datasec=totsec-firstdatasector;

其中,TotSec可以由下面条件获取:If(BPB_TotSec16 != 0)    TotSec = BPB_TotSec16;Else    TotSec = BPB_TotSec32;

Total number of clusters in the data area (countofclusters):

Countofclusters = Datasec/bpb_secpeclus;

The location of a cluster number in the FAT table:
A) cluster n number of sectors in the first Fat table (thisfatsecnum):

Thisfatsecnum = bpb_rsvdseccnt + (fatoffset/bpb_bytepersec);

其中FATOffset可以由下面条件获取:If(FATType == FAT16){    FATOffset = N*2;}Else If(FATType == FAT32){    FATOffset = N*4;}

B) cluster n offset from the sector in the first Fat table (thisfatentoffset):

Thisfatentoffset = fatoffset% Bpb_bytepersec;

* Note: The above calculation results are rounded.

EXFAT
单个文件大小突破4GB的限制,最大可达到32GB、分区大小突破之前32GB的限制,最大可达到2TB。内部结构调整,实现同样功能的操作,相比较之前的FAT系统,减少读写设备的次数。对DBR表,文件名,文件目录项等,增加校验字段,提高数据安全性。簇大小可高达32MB。采用了剩余空间分配表,剩余空间分配性能改进。同一目录下最大文件数可达65535个。

The internal structure of the exFAT file system is assigned as follows:

The boot area of the exFAT is at least 24 sectors, divided into the boot zone and the backup boot area, and two sectors each with 12 sectors.
Jump command EB is also a exFAT type ID

exFAT Directory

The root directory is special and there are three special directory entries below. Specific as follows:

其中第一个目录项不知道有何具体用意。第二个目录项0x81,表示簇堆分配表文件。第三个目录项0x82,表示大写表文件。EXFAT普通目录下没有“.”和“..”目录项。特殊目录项只存在根目录下,有卷标目录项、位映射目录项和大写表目录项,分别记录分区卷标,簇堆分配表文件和大写表文件。
exFAT Cluster Allocation table

A cluster allocation table that records the usage of all clusters on a partition. Each bit represents a cluster, 0 represents an empty cluster, and 1 indicates that the cluster is already occupied. Starting cluster number starting from 2, that is BIT0 corresponding cluster number 2,bit1 corresponding to cluster number 3. The cluster allocation table exists as a file store, usually corresponding to the first file in the root directory, which is the second directory entry. His size is determined by the total number of clusters, occupying n clusters of space.

exFAT Capitalization Conversion table

An uppercase table is a Unicode character map that occupies 2 bytes per character. File name comparison, first convert the file name format to Unicode, and then through the table to convert the file name to uppercase Unicode, the conversion is done before the file name comparison. The data in the uppercase table is partially compressed, the starting flag code FFFFH is compressed, followed by a compressed length.

Note: Physical structure of the hard disk

Fat and exFAT file systems

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.