FAT学习笔记(四)——Dir Entry

本文详细介绍了FAT32文件系统中的短目录和长目录的构成、大小限制、文件名及路径规则,以及其数据格式和时间日期表示方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,短目录和长目录:

短目录和长目录都是放在Data region里的,一个directory entry占用32byte,具体参考下表:

Short directory entry

Name

Offset (byte)

Size (bytes)

Description

DIR_Name

0

11

Short name.

DIR_Attr

11

1

File attributes:

ATTR_READ_ONLY                0x01

ATTR_HIDDEN                       0x02

ATTR_SYSTEM                       0x04

ATTR_VOLUME_ID               0x08

ATTR_DIRECTORY                 0x10

ATTR_ARCHIVE                     0x20

ATTR_LONG_NAME              ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID

The upper two bits of the attribute byte are reserved and should always be set to 0 when a file is created and never modified or looked at after that.

 

DIR_NTRes121Reserved for use by Windows NT.
DIR_CrtTimeTenth131Millisecond stamp at file creation time.
DIR_CrtTime142Time file was created.
DIR_CrtDate162Date file was created.
DIR_LstAccDate182Last access date.
DIR_FstClusHI202High word of this entry’s first cluster number (always 0 for a FAT12 or FAT16 volume).
DIR_WrtTime222Time of last write.
DIR_WrtDate242Date of last write.
DIR_FstClusLO262Low word of this entry’s first cluster number.
DIR_FileSize284

32-bit DWORD holding this file’s size in bytes.

所以FAT32支持文件的最大大小为4G

 

 

DIR_Name不能包含以下字符:

1, 任何小于0X20值的字符,除了0x05(0X05代表的含义是该目录entry可以被重新使用,删除一个文件的时候用0x05来覆盖DIR_Name[0,如果DIR_Name[0]的值为0,表示该entry可以被使用~之前没有被使用过)

2,0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, and 0x7C.

Shaort name举例如下:

“foo.bar”            -> “FOO     BAR”

“FOO.BAR”            -> “FOO     BAR”

“Foo.Bar”            -> “FOO     BAR”

“foo”                -> “FOO        “

“foo.”               -> “FOO        “

“PICKLE.A”           -> “PICKLE  A  “

“prettybg.big”       -> “PRETTYBGBIG”

“.big”               -> illegal, DIR_Name[0] cannot be 0x20


 Data format:

a date relative to the MS-DOS epoch of 01/01/1980

Bits

Description

15-9

Year (0 = 1980, 127 = 2107)

8-5

Month (1 = January, 12 = December)

4-0

Day (1 - 31)

Time format:

The valid time range is from Midnight 00:00:00 to 23:59:58

Bits

Description

15-11

Hours (0-23)

10-5

Minutes (0-59)

4-0

Seconds/2 (0-29)


 

long directory entry

Name

Offset

(byte)

Size

(bytes)

Description

LDIR_Ord

0

1

The order of this entry in the sequence of long dir entries associated with the short dir entry at the end of the long dir set.


If masked with 0x40 (LAST_LONG_ENTRY), this indicates the entry is the last long dir entry in a set of long dir entries. All valid sets of long dir entries must begin with an entry having this mask.

LDIR_Name1

1

10

Characters 1-5 of the long-name sub-component in this dir entry.

LDIR_Attr

11

1

Attributes - must be ATTR_LONG_NAME

LDIR_Type

12

1

If zero, indicates a directory entry that is a sub-component of a long name.  NOTE: Other values reserved for future extensions.

Non-zero implies other dirent types.

LDIR_Chksum

13

1

Checksum of name in the short dir entry at the end of the long dir set.

LDIR_Name2

14

12

Characters 6-11 of the long-name sub-component in this dir entry.

LDIR_FstClusLO

26

2

Must be ZERO. This is an artifact of the FAT "first cluster" and must be zero for compatibility with existing disk utilities.  It's meaningless in the context of a long dir entry.

LDIR_Name3

28

4

Characters 12-13 of the long-name sub-component in this dir entry.

 

Example:

当一个文件名字是"The quick brown.fox". 以下的表格说明了它是如何存放在directory entry里的。

 

FAT32对文件名以及文件路径的限制:

1, 短目录名可以包含任何字母数字以及下面的字符:

$   %   '   -   _   @   ~    `   !   (    )   {   }  ^  #  &

2, 长目录名不能包含如下字符

+   ,   ;   =   [   ]

3, 短目录名路径最大长度是8+3,端目录完整路径长度最大为80(包含最后的结束NUL字符)

4, 长目录完整路径最大为255(不包含最后的NUL字符)

5, 长目录entry是通过UNICODE来放具体名字的字符的,2byte对应一个字符,区分大小写。

6, 短目录entry是不区分大小写的。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值