打印
[牛人杂谈]

单片机的文件系统

[复制链接]
2154|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wahahaheihei|  楼主 | 2016-9-29 18:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

单片机的文件系统

原因:如果没有文件系统,用户将直接面对存储设备的底层硬件系统。

磁盘有很多扇区;每个文件存储在扇区的某块区域;文件系统的作用是管理文件在磁盘上的存储。

FAT32:分为MBR(记录磁盘的分区信息,可能位于0扇区)、DBR(可能在0扇区)、保留区、第一个FAT32表、第二个FAT32表、数据区(记录目录和数据,分成很多数据块,成为簇)。第一个FAT表存储了目录和文件数据的链式存储关系。第二个FAT表,备份FAT表1的备份。

MBR:主启动记录,位于磁盘的0扇区,但MBR有可能不存在。0扇区的第一个字节若是EB,说明不是MBR;一个磁盘可能有多个分区,分区信息记录在MBR。前面446bytes与操作系统相关,不关心。后面有一条或多条分区记录(每个记录一个分区),称为DPT,即磁盘分区表。最后两个字节是55和AA,表示磁盘分区表结束。若第一个扇区是MBR,则最后两个字节就是55和AA。

文件存储以簇为单位,就算一个字节,也要占用一个簇。一个簇有多个扇区组成。
文件/目录项存储:前8个字节存储文件名,再3个字节是扩展名,即文件类型;再一个字节是文件属性,存档、只读、隐藏等属性;后面依次是创建时间,创建日期,最后访问的日期,开始簇的高两个字节,最后修改的时间,最后修改的日期,开始簇的低两个字节,文件的大小。

认识51单片机

51单片机的引脚定义:
共四十个引脚,从左上到右上编号。9:RST;10、11:RX0、TX0,UART控制器使用;12、13:外部中断引脚;14,15:外部脉冲计数器输入端;16,17:外部存储器的写使能与读使能;21~28:外部寻址时的高8位;32~39是外部寻址的高8位。


沙发
捉虫天师| | 2016-9-30 15:33 | 只看该作者
有好多开源的文件系统可以选择。

使用特权

评论回复
板凳
wahahaheihei|  楼主 | 2016-9-30 19:22 | 只看该作者
FAT File System

The FAT file system has the file allocation table located at the beginning of a logical volume. FAT was designed for small disks and simple folder structures. Two copies of the file allocation table are stored on the volume. In the event that one copy of the file allocation table is corrupted, the other file allocation table is used.



FAT16 File System

FAT16 is included in Windows 2000 for the following reasons:

  • It provides backward compatibility in the form of an upgrade path for earlier versions of Windows-compatible products.

  • It is compatible with most other operating systems.


For Windows 2000 and Windows NT, the maximum size for a FAT16 volume is 4,095 megabytes (MB).

A volume formatted with FAT16 is allocated in clusters. The default cluster size is determined by the volume size, and can be as large as 64 kilobytes (KB). The cluster size must be a power of 2 between 512 and 65,536 bytes. Table 3.2 shows the default cluster sizes for FAT16 volumes. You can specify a different cluster size if you format the volume with the format command from the command prompt. However, the size you specify must be listed in Table 3.2.

Table   3.2 FAT16 Cluster Sizes

Volume Size

Sectors Per Cluster

Cluster Size

0 MB–32 MB

1

512 bytes

33 MB–64 MB

2

1 KB

65 MB–128 MB

4

2 KB

129 MB–255 MB

8

4 KB

256 MB–511 MB

16

8 KB

512 MB–1,023 MB

32

16 KB

1,024 MB–2,047 MB

64

32 KB

2,048 MB–4,095 MB

128

64 KB


FAT16 is not recommended for volumes larger than 511 MB because, when relatively small files are placed on a FAT16 volume, FAT uses disk space inefficiently. You cannot use FAT16 on volumes larger than 4 gigabytes (GB), regardless of the cluster size.

Note

On volumes with fewer than 32,680 sectors, the cluster sizes can be up to 8 sectors per cluster. The format program, whether you format the volume using Disk Management or by typing format at the command prompt, creates a 12-bit FAT. Volumes less than 16 MB are usually formatted for a 12-bit FAT, but the exact size depends on the disk geometry. The disk geometry also determines the point at which a larger cluster size is needed because the number of clusters on the volume must fit into 16 bits. Therefore, you might have a 33-MB volume that still has only 1 sector per cluster.

FAT12 is the original implementation of FAT and is intended for very small media. The file allocation table for FAT12 is smaller than the file allocation table for FAT16 and FAT32, because it uses less space for each entry. This leaves more space for data. All 5.25-inch floppy disks are formatted with FAT12, and 1.44-MB 3.5-inch floppy disks are generally formatted with FAT12. Volumes on Iomega Zip and Jaz drives are formatted with FAT16.

Top Of Page


Structure of a FAT16 Volume

Figure 3.1 illustrates how FAT maps out clusters on a volume. The file allocation table (areas FAT1 and FAT2 in Figure 3.1) identifies each cluster in the volume as one of the following:

  • Unused

  • Cluster in use by a file

  • Bad cluster

  • Last cluster in a file


Figure 3.1 Organization of a FAT Volume

The only difference between the root folder and other folders is that the root folder is at a specified location and has a fixed number of entries (for a hard disk). The number of entries on a floppy disk depends on the size of the disk.

Note

Each folder and file in the root folder uses one or more entries. For example, if the fixed number of entries is 512 and you have 100 folders, you can only create 412 files.

Folders have a 32-byte entry for each file and folder contained in the folder. Assuming short file names are used, the entry includes the following information:

  • Name (8.3) xxxxxxxx.yyy. (88 bits)

  • Attribute byte (8 bits of information, described later in this section).

  • One reserved byte.

  • Create time (24 bits).

  • Create date (16 bits).

  • Last access date (16 bits).

  • Two reserved bytes.

  • Last modified time (16 bits).

  • Last modified date (16 bits).

  • Starting cluster number in the file allocation table (16 bits).

  • File size (32 bits).


In a FAT folder structure, 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 end-of-file (EOF) indicator at (0xFFFF) which indicates that this cluster is the end of the file. These pointers and end-of-file indicators are shown in Figure 3.2.

Figure 3.2 Files on a FAT Volume

Figure 3.2 shows three files in a folder. File1.txt is large enough to use three clusters. File2.txt is a fragmented file that also requires three clusters. The third file, File3.txt, fits completely in one cluster. In each case, the folder entry points to the first cluster of the file.

The information in the folder is used by all operating systems that support FAT. Windows 2000 can store additional time stamps in a FAT folder entry. These time stamps show when the file was created or last accessed.

Because all entries in a directory are the same size, the attribute byte for each entry in a directory describes what kind of entry it is. For example, one bit indicates that the entry is for a subdirectory and another bit marks the entry as a volume. Typically, only the operating system controls the settings of these bits.

The attribute byte includes four bits that can be turned on or off by the user — archive, system, hidden, and read-only.

Top Of Page


FAT32 File System

Support for FAT32 is new in Windows 2000. FAT16 supports volumes up to 4 GB, whereas theoretically FAT32 can manage volumes up to 2 terabytes. The FAT32 on-disk format and features on Windows 2000 are similar to those on Windows 95 OSR2 and Windows 98.

The size of a FAT32 cluster can range in size from 1 sector (512 bytes) to 64 sectors (32 KB), incremented in powers of 2.

Since FAT32 requires 4 bytes to store cluster values, many internal and on-disk data structures have been revised or expanded. Most programs are unaffected by these changes; however, disk utilities which read the on-disk format must be updated to support FAT32.

Two application programming interfaces (APIs) are disabled on FAT32. Since the BIOS parameter block (BPB) structure grows from 25 bytes on FAT16 to 53 bytes on FAT32, and FSCTL_QUERY_FAT_BPB is defined to return only as much of the boot sector as contains the 25 byte form of the BPB, it is disabled on FAT32. To retrieve the BPB on FAT32, applications should read the volume directly. This also works for FAT16. Extended attributes are disabled on FAT32 since increasing the cluster number to 4 bytes requires the use of the field previously used to index the extended attribute database.

Top Of Page


Structure of a FAT32 Volume

The main difference between FAT16 and FAT32 is the logical partition size. FAT32 breaks the 2-GB logical drive limitation of FAT16 volumes by extending a single logical drive capacity to at least 127 GB. If you have a 2-GB FAT16 drive, you must use a 32-KB cluster. With FAT32, the range for a 4-KB cluster, for example, includes drive sizes between 512 MB and 8 GB.

The largest possible file for a FAT32 drive is 4 GB minus 2 bytes. FAT32 uses 4 bytes per cluster within the file allocation table. This differs from FAT16, which uses 2 bytes per cluster within the file allocation table. Table 3.3 shows the default cluster sizes for FAT32.

Table 3.3 FAT32 Cluster Sizes

Partition Size

Default Cluster Size

Less than 8 GB

4 K

Greater than or equal to 8 GB, and less than 16 GB

8 K

Greater than or equal to 16 GB, and less than 32 GB

16 K

Greater than or equal to 32 GB

32 K


A FAT32 volume must have at least 65,527 clusters. Also, the cluster size on a FAT32 volume cannot be such that the file allocation table is greater than (16 MB – 64 KB)/4, or almost 4 million clusters.

FAT16 and FAT32 do not scale well. As the volume gets bigger, the file allocation table gets bigger, which dramatically increases the amount of time it takes Windows 2000 to compute how much free space is on the boot volume when the system is restarted.

For this reason, you may not create a FAT32 volume larger than 32 GB using the Format utility. However, the Windows 2000 Fastfat driver enables you to mount and fully support a FAT32 volume larger than 32 GB.

Use NTFS to format volumes larger than these. For more information about why you should format all Windows 2000 partitions with NTFS, see "Advantages of NTFS" later in this chapter.

Top Of Page


File Names on FAT Volumes

Files created or renamed on FAT volumes use attribute bits to support long file names in a way that does not interfere with how MS-DOS gains access to the volume.

Whenever you create a file with a long file name, Windows 2000 creates a conventional 8.3 name for the file and one or more secondary folder entries for the file, one for each 13 characters in the long file name. Each secondary folder entry stores a corresponding part of the long file name in Unicode.

Windows 2000 marks the secondary folder entries as part of a long file name by setting the volume ID, read-only, system, and hidden attribute bits. MS-DOS generally ignores folder entries with all four of these attribute bits set, so these entries are invisible to these operating systems. MS-DOS accesses the file by using the conventional 8.3 file name contained in the folder entry for the file.

Figure 3.3 shows all of the folder entries for the file Thequi~1.fox, which has a long name of The quick brown.fox. The long name is in Unicode so each character in the name uses 2 bytes in the folder entry. The attribute field for the long-name entries has the value0x0F . The attribute field for the short name has the value 0x20 .

Figure 3.3 Long File Name on a FAT Volume

Note

Windows NT and Windows 2000 do not use the same algorithm to create long and short file names as Windows 95 and Windows 98. However, on computers that multiple-boot these operating systems, files that you create when running one operating system can be accessed when running the other.

For information about how Windows 2000 creates short file names, see "Using Long File Names" later in this chapter.

By default, Windows 2000 supports long file names on FAT volumes. You can prevent a FAT file system from creating long file names by setting the value of the Win31FileSystem registry entry (in HKEY_LOCAL_MACHINESystem CurrentControlSetControlFileSystemWin31FileSystem) to  1 .

Caution

Do not use a registry editor to edit the registry directly unless you have no alternative. The registry editors bypass the standard safeguards provided by administrative tools. These safeguards prevent you from entering conflicting settings or settings that are likely to degrade performance or damage your system. Editing the registry directly can have serious, unexpected consequences that can prevent the system from starting and require that you reinstall Windows 2000. To configure or customize Windows 2000, use the programs in Control Panel or Microsoft Management Console (MMC) whenever possible.

This value prevents Windows 2000 from creating new long file names on all FAT volumes, but it does not affect existing long file names.

Top Of Page


Using FAT with Windows 2000

FAT16 works the same way in Windows 2000 as it does in MS-DOS, Windows 3. x , Windows 95, and Windows 98. FAT32 works the same way in Windows 2000 as it does in Windows 95 OSR2 and Windows 98. In fact, you can install Windows 2000 on an existing FAT primary partition or logical drive. When running Windows 2000, you can move or copy files between FAT and NTFS volumes.




使用特权

评论回复
地板
mintspring| | 2016-10-8 18:40 | 只看该作者
FAT文件系统白皮书.pdf (1001.14 KB)

[size=13.3333339691162px]FAT文件系统白皮书

使用特权

评论回复
5
quray1985| | 2016-10-9 19:29 | 只看该作者
文件系统挺多的,并且有很多开源的

使用特权

评论回复
6
598330983| | 2016-10-9 21:27 | 只看该作者
创建时间,创建日期,最后访问的日期

使用特权

评论回复
7
wahahaheihei|  楼主 | 2016-10-10 13:03 | 只看该作者
文件系统要基于基本的存储器读写函数来做。

使用特权

评论回复
8
wahahaheihei|  楼主 | 2016-10-10 18:05 | 只看该作者
作为文件系统,其实最大的目的不仅仅是为了管理文件方便,而是为了兼容其他的系统,比如PC,Windows。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

213

主题

3022

帖子

12

粉丝