1 / 26

File Systems in Real-Time Embedded Applications

File Systems in Real-Time Embedded Applications. Understanding How the File Allocation Table (FAT) Operates. March 5th Eric Julien. Timeline Summary. Microsoft worked actively on FAT for 20 years: Original 8-bit in 1977 FAT12 in 1980: 32 MB FAT16 – first version in 1984: 2 GB

scatherine
Download Presentation

File Systems in Real-Time Embedded Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File Systems in Real-Time Embedded Applications Understanding How the File Allocation Table (FAT) Operates March 5thEric Julien

  2. Timeline Summary Microsoft worked actively on FAT for 20 years: • Original 8-bit in 1977 • FAT12 in 1980: 32 MB • FAT16 – first version in 1984: 2 GB • FAT32 – introduced in 1996: 2 TB • Today: still the most common format for removable media (usb drives, sd cards, etc.)

  3. FAT characteristics FAT is • A disk file system, • Designed to support sector-based devices, • Very light-weight, • Popular for removable media, • Supported by major desktop OSes.

  4. Master Boot Record (MBR)

  5. Partitioning *Each partition can become a volume

  6. Volume Layout *2nd FAT optional Sec 1 Sec 2 Sec 3 … Sec N Cluster

  7. Reserved Area Boot Sector • VBR (Volume Boot Record) • VBR contains the BPB (BIOS Parameter Block) FS Info Sector (FAT32) AdditionalReservedSectors (optional)

  8. Bios Parameter Block (BPB) 15 12 20 23 27 511 2 10 0 13 16 18 21 25 31 35 509 … Number of sectors in File System Number of sectors per FAT Number of sectors in File System (< 16 bits) Number of files in root directory. 512 for FAT16 Number FATs Number of sectors of Reserved Area Number of sectors per cluster. Power of 2, Max 32KB Bytes per sector (512, 1024, 2048 and 4096 are valid values) Signature value (0xAA55) Offsets in bytes.

  9. Data Area The data area: • Is divided in clusters of equal size • Contains file data • Contains file metadata (name, size, etc.) • Contains directory organization info • Contains the Root Directory (FAT32 only)

  10. File Allocation Table (FAT) The FAT is a cluster « map »: • Each cluster is represented by an entry in the FAT • Entry size depends on which FAT: 12/16/32 … … 38 39 40 41 42 FAT Table Data Cluster 38 Data Cluster 39 Data Cluster 40 Data Cluster 41 Data Cluster 42 Data area 216 200 204 208 212 Sector index:

  11. FAT Each entry indicateseither: • the next cluster number in a chain • the EOC (end of chain) • the cluster isbad • the cluster is not used

  12. Directory entries Directory entries are used to store metadata • For a file • For a directory • For LFN (Long file names)

  13. Directory entries The directory entries contain information about files and directories : • File name and extension • Timestamps • First cluster number • Size

  14. An entry example 5,923

  15. Files and directories The data contained in files is located in the data area. Data storage is allocated on a per-cluster basis. Each files consumes an integer number of clusters.

  16. Files and directories A directory table (folder) is just a special type of file. Its data is a list of directory entries (that can point to other files and directory tables). 5,923

  17. LFN (VFAT) The original FAT specification supported only 8.3 naming To support up to 255 UTF-16 characters, VFAT introduced the Long File Names (LFN) VFAT uses « special » directory entries (up to 20) that contain the LFN.

  18. LFN (VFAT) File Name Checksum Attributes ( 0x0f ) Reserved Sequence Number LFN Directory Entry [1-5] [12-13] [6-11] 0 31 … Normal Directory Entry

  19. File search With LFN enabled, a file name can be contained in up to 21 directory entries, each of them comprised of 32 bytes. Hence, a single file/folder can use up to 672 bytes in a directory table. This means it can span across multiple sectors.

  20. File search If your file system suite was implemented to limit the usage of RAM, it is likely that internal buffers (used for file search) are equal to a sector size (512 bytes typically).

  21. File search Example: Searching for a file in a folder containing 50 files. Worst case : 21 entries * 32 bytes * 50 files = 33600 bytes = 66 sectors to read = 66 read operations on file system

  22. File system transactions Transactions can trigger up to 3 different operations • Allocation/deallocation of clusters (FAT region) • Creation/deletion/update of the directory entry (directory table, part of the data region or root directory) • Update of the data (data region)

  23. File system transactions These transactions are NOT atomic. An unexpected interruption (such as a power failure, or a « hot » media removal) can corrupt the file system AND the data.

  24. File system and data corruption Incomplete transactions can create errors: • Orphaned cluster chains • Orphaned directory entries • Chain length mismatch • Unbounded cluster chains • Cross-Linked files

  25. Licensing Microsoft owns a patent for the support of long file names (LFN). Microsoft recently won a few times in court even if the validity has been disputed several times. The cost: $0.25 per unit, up to $250,000.

  26. Future FAT32 is limited to 2 TB in volume size. File size is limited to 4GB without FAT+. Microsoft proposed exFAT (covered by patents). Not supported outside Windows and OS X. Recommended by the SDXC specification.

More Related