The MultiMediaCard FAT16 File System Specification Version 1.0 MMCA Technical Committee MultiMediaCard System Revision History Version Date 0.1 1.0 2 03/03 Section/ Page Changes compared to previous issue all Initial file system spec proposal to MMCA Originator:MMCA FS workgroup Author:Juha Liinamaa all Conversion to MMCA look and feel formats MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System You acknowledge that the attached standard (the “Standard”) is provided to you on an “AS IS” basis. MULTIMEDIACARD ASSOCIATION (“MMCA”) MAKES NO EXPRESS, IMPLIED OR STATUTORY WARRANTIES AND EXPRESSLY DISCLAIMS THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. MMCA SHALL NOT BE LIABLE FOR (I) TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED WITHIN THE STANDARD, OR (II) ANY INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS OR LOSS OF USE) RESULTING FROM THE FURNISHING, PERFORMANCE OR USE OF THE STANDARD, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Copyright (c) March 2003 MultiMediaCard Association, 19672 Stevens Creek Blvd., #404, Cupertino, CA 95014-2465. World rights reserved. No part of this publication may be transmitted, reproduced or distributed in any way, including but not limited to photocopying, electronic copying, magnetic or other recording, without the prior written consent of MMCA. MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 3 MultiMediaCard System 4 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Table Of Contents 1 Introduction ............................................................................................................................. 7 2 Physical CHS geometry ........................................................................................................... 7 3 3.1 3.2 Master Boot Record ................................................................................................................. 9 Partition entry format ......................................................................................................... 10 Address translations ............................................................................................................ 11 4 4.1 4.2 4.3 File system............................................................................................................................... 12 Partition Boot Record ......................................................................................................... 12 Variable parameters in PBR ............................................................................................... 13 Miscellaneous notes on allocation tables and PBR ............................................................ 15 5 5.1 5.2 5.3 5.4 5.5 Directory entries .................................................................................................................... 17 Long filename support ........................................................................................................ 17 Filename character sets ....................................................................................................... 18 FAT/VFAT16 caveats ........................................................................................................ 19 Example of long filename entries ....................................................................................... 19 Example of file system memory layout .............................................................................. 20 Appendix A: Abbreviations ........................................................................................................... 23 Appendix B: References ................................................................................................................. 24 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 5 MultiMediaCard System 6 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System 1 Introduction Introduction Purpose of this document is to define the details of FAT16 file system for MultiMediaCards’ user data area. First of all, various FAT systems have their roots in magnetic media (floppy disks and hard drives). With that background, FAT file system introduces some need to relate the byte-unit linearly addressed MultiMediaCard and conventional magnetic media. In order to maintain consistency at all levels, this document deals with the following specifics: - CHS geometry: how to translate the card characteristics into the conventional CHS geometry of magnetic media - Master Boot Record (partitioning): how and why to introduce the MultiMediaCard as logical hard drive(s), conversions between physical and logical addresses and addressing modes - Partition Boot Record(s), aka partition boot sector: how to define the actual FAT16 file system within a partition - Directory entries: how to create files and directories (with conventional 8+3 filenames) - Optional long filename support (VFAT): how to avoid breaking inter operability between systems that do support VFAT and those that don’t CHS geometry is used as a basis for all calculations to maintain consistency throughout all addressing modes. 2 Physical CHS geometry The goal of this chapter is to define a way to calculate a physical (media-based) CHS geometry for an arbitrary card with the following guidelines: - Calculated CHS should reflect card properties and potential as they are expressed in the card CSD register and MultiMediaCard System Specification - Singular conversions between addressing modes (CHS, linear sector and linear card address) - Simple and efficient conversion methods - Minimal waste of card memory capacity in address conversions In order to simplify the expressions, the following notations are defined. Practical implementation of these notations should be straightforward on any platform. - floor(x): closest integer ≤ x - ceil(x): closest integer ≥ x - ceil2(x): closest even integer ≥ x - rem(x, y): remainder of integer division (x/y). The remainder, x and y are ≥ 0 - min(r): smallest value found in a finite-length range of numbers - max(r): largest value found in a finite-length range of numbers The following table summarizes the all the factors that need to be considered at this point Table 1: Physical CHS Acronym calculation parameters Explanation Range 232 Unit M Card memory capacity as expressed in the card CSD register 98304 to W Sector Size 512 byte S Number of Sectors per Head 32 sector MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA byte 7 Introduction MultiMediaCard System Table 1: Physical CHS Acronym calculation parameters Explanation Range Unit P Number of Sectors on media (aka Number of Physical sectors, aka floor(min(M)/W) to LBA’s) floor(max(M)/W) sector H Number of Heads per Cylinder [2, 4, 6,..., 256] head C Number of Cylinders on media (aka Number of Physical cylinders) [3, 4, 5,..., 1024] cylinder Min(M) is the smallest card capacity for which the FAT16 system described in this document can be implemented; reasons for this limitation become more obvious later on. Max(M) is ultimately limited by the MultiMediaCard bus protocol itself with its byte-based 32-bit addressing. Thus, maximal capacity is 4GB. Sector size (W) was defined to be 512 bytes as it is the ‘de facto’ standard of current disks, file system implementations and MultiMediaCards. However, if the card does not support data transfer operations at 512-byte granularity, host SW must provide support for the 512-byte sector size. Limitations on parameters C, H and S are introduced to maintain compatibility with the traditional BIOS int13h hard drive interface of PC computers. Parameter H is forced to even values in order to maintain consistency with disk drives; it makes sense that both sides of “disk platters” are used in conventional disk drives. Parameter S is fixed to 32 sectors for a number of reasons. It simplifies calculations, neatly divides the card capacity to fixed 16kB chunks and is sufficient to address the maximal card capacity: max ( C ) ⋅ max ( H ) ⋅ S ⋅ ( W ⁄ 1024 )KB = 1024 ⋅ 256 ⋅ 32 ⋅ 0.5KB = 4194304KB = 4GB Furthermore, it is the maximum number of card write blocks in the smallest card erase unit (erase sector). Assuming 512-byte write block and powers-of-two logic in the card memory hierarchy, it exactly covers one 8 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Introduction or more card erase units. The variable parameters are calculated as follows: Equation 1: Number of physical sectors M P = floor ----- W Equation 2: Number of physical heads P H = ceil2 ---------------------------- S ⋅ max ( C ) Equation 3: Number of physical cylinders P C = floor ------------ S⋅H Thus, the CHS geometry may waste some capacity because all existing platforms do not allow partial cylinders. Furthermore, address translations remain straightforward if CHS addressing is allowed to be the limiting factor. Amount of wasted capacity is minimized by minimizing the number of heads. Consequently, number of cylinders is maximal. 3 Master Boot Record Partition table resides at the very beginning of the media. It's total size is 16kB (32 sectors = 1 head). The partition table contains Master Boot Record (MBR) which defines the layout of file system(s) on the media. Master boot record is the very first sector on the media. The other sectors in the partition table may contain Master Boot Code or some proprietary information which is “don't care”, from standardization point of view. The MBR itself is arranged as follows: Table 2: Master Boot Record structure Byte position Length (bytes) 0x000 432 Optional MBR code (“don't care”) 0x1B0 14 Media ID entry (Defined in System Spec 3.0, chapter 11) 0x1BE 16 Partition Table Entry (see below) 0x1CE 16 Partition Table Entry (see below) 0x1DE 16 Partition Table Entry (see below) 0x1EE 16 Partition Table Entry (see below) 0x1FE 1 Signature 0x55 Entry Description Value / Range MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 9 Introduction MultiMediaCard System Table 2: Master Boot Record Byte position Length (bytes) 0x1FF 1 3.1 structure Entry Description Signature Value / Range 0xAA Partition entry format Every partition entry has the following fields (cylinder example values refer to 1st partition): Table 3: Partition Byte position Length (bytes) entry Description Value / Range Acronym 0x0 1 boot descriptor 0x00 (non-bootable), 0x80 (bootable) BF 0x1 1 Partition start head 0 0x2, bits[5:0] 6/8 Partition start sector 1 0x2, bits[7:6] 2/8 Partition start cylinder MSB: bits[9:8] 1 to (C-2) 0x3 1 Partition start cylinder, bits[7:0] 0x4 1 File system descriptor 0 = empty 4 = DOS 16-bit FAT < 32MB 6 = DOS 16-bit FAT > 32MB Other values indicate nonstandard 3rd party file system 0x5 1 Partition end head H-1 0x6, bits[5:0] 6/8 Partition end sector S 0x6, bits[7:6] 2/8 Partition end cylinder MSB: bits[9:8] 1 to (C-1) EN 0x7 1 Partition end cylinder, bits[7:0] 0x8 4 First sector position relative to the beginning of media (zero-based) B0*H*S + 0*S +1 –1 = B0*H*S ON 0xC 4 Number of sectors in partition (E0-B0+1)*H*S PN BN All formatted partitions are based on 16-bit FAT entries and may employ VFAT for long filename support. All sector numbers are stored in Little-Endian format (least significant byte first). All memory capacity related parameters depend on the CHS geometry defined in the previous chapter. As implied by the table, all partitions must be aligned to full cylinders. Partition allocation does not have to be contiguous, but partitions must not overlap and their starting/ending cylinder values must not exceed the value (C-1) defined in previous chapter. Those values with an acronym are inherited to Partition Boot Record one way or another. Values in unused partition entries are all zeroes. “Extended” partitions are beyond the scope of this document. Such partitions would require definition of nested Secondary Master Boot Record before it can be divided to logical partitions. Since supporting this fea- 10 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Introduction ture adds to the complication and is not crucial in terms of inter operability, its use is forbidden. 3.2 Address translations While all partitions reside on the same physical media, purpose of partitioning is to introduce them as separate pseudo devices which have individual file systems and logical addressing. File system addressing is partitionbased. To summarize, partitions introduce the following division between addresses: - Logical address: partition-based, either linear or CHS. It is only able to deal with sectors within a single partition - Physical address: media-based. It is capable of addressing the whole media capacity across partitions, either linearly or via CHS Per-partition logical CHS limits are defined in the following table. It is the “apparent” CHS geometry which will be applied when actual file system is created to a partition. Table 4: Logical Acronym CHS parameters Description Range / Value Unit Cn Number of cylinders in partition EN-BN+1 Cylinder HN Number of heads per cylinder in partition H Head SN Number of sectors per track in partition S Sector Since partitions were previously forced to cylinder boundaries, conversion between physical and logical CHS addresses remains simple: only cylinder offset needs correction. When converting linear addresses between physical and logical, offset is corrected by parameter ON. Conversions between linear address and CHS address are computed as follows (p = arbitrary linear, c = arbitrary cylinder, h = arbitrary head, s = arbitrary sector): Equation 4: Arbitrary CHS-to-linear address conversion p = c⋅H⋅S+h⋅S+s–1 Equation 5: Arbitrary linear-to-CHS address conversion P - c = floor ----------S ⋅ H – c ⋅ H ⋅ S- h = floor p-------------------------- S s = p – c ⋅ H ⋅ S – h ⋅ S + 1 Card address is calculated from arbitrary physical address by multiplying with W. MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 11 Introduction 4 MultiMediaCard System File system Each partition will have its own FAT16 file system. Therefore, all the parameters described are logical and only apply to the partition under consideration. With FAT16, the partition is roughly divided into two areas: - System area: reserved sectors (including boot sector, aka Partition Boot Record), file allocation tables (2pcs) and root directory entries (512pcs) - User data area: divided into allocation units (clusters) Since there are several ways to arrange the system and data area usage, the goal of this chapter is to define a FAT system according to following guidelines: - Define a singular way to arrange system and data area usage - Adhere to CHS and it’s 16kB boundaries for efficiency and consistency - Minimize wasted capacity (cluster size) 4.1 Partition Boot Record The partition Boot Record is the first sector in the partition in (logical) linear address 0. Fields with a defined acronym are computed or otherwise used later on. Table 5: PBR structure Byte position Length (bytes) 0x0 3 Jump command. NOTE: x86 machine language spe- 0xEB 0xXX 0x90 cific, must not be changed 0x3 8 OEM name. NOTE: MS Windows apparently trashes this field on removable media Don’t care 0xB 2 Bytes Per Sector W 0xD 1 Sectors per Cluster [20, 21,..., 27] sc 0xE 2 Reserved Sectors (including this PBR) [2, 4, 6,..., S] r 0x10 1 Number of FATs 2 0x11 2 Number of root directory entries (32 bytes each) 512 0x13 2 Number of sectors on partition 0 (if partition type 6) PN (if partition type 1) 0x15 1 Media descriptor 0xF8 (hard disk) 0x16 2 Sectors Per Fat 1 to 256 0x18 2 Sectors Per Track S 0x1A 2 Number of Heads H 0x1C 4 Number of Hidden sectors (part. Offset) ON 0x20 4 Extended number of sectors on partition PN (if partition type 6) 0 (if partition type 1) 0x24 1 Drive number BF (partition entry) 0x25 1 Reserved 0 12 Description Range/Value Acronym E sf MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Introduction Table 5: PBR structure Byte position Length (bytes) 0x26 1 Extended boot signature 0x29 0x27 4 Volume serial number PSN from card CID +partition index (0 to 3) 0x2B 11 Volume label (example mmcform11) ASCII string w/o NULL, SP padding (“mmcform11 “) 0x36 8 File system type ASCII string: (“FAT16”) 0x3E 448 Optional partition boot code Don’t care 0x1FE 1 Signature 0x55 0x1FF 1 Signature 0xAA Description Range/Value Acronym As can be seen, lots of information in this record is inherited from physical CHS geometry and partition table entry. Note: number of logical cylinders can be calculated either from these values or from respective partition entry values; PBR has inherited the needed parameters from partition entry. Using MBR, the logical number of cylinders CN is: Equation 6: Number of logical cylinders in partition CN = EN – BN + 1 4.2 Variable parameters in PBR At this point, we have three degrees of freedom in our FAT arrangement, namely reserved sectors (r), sectors per FAT (sf) and sectors per cluster (sc). However, these parameters are not entirely independent of each other and each has certain limitations. In the following, reserved sectors and the two FAT tables are combined to parameter hF which shall fulfill the equation S ⋅ hF = r + 2 ⋅ sF Root directory entries (512pcs) take exactly one head; each RDE is 32bytes, 512*32/W = 512*32/512 = 32 sectors = 1 head. Having these requirements in place aligns all our major file system components (reserved sectors + FATs, root directory entries and user data area) to 16kB head boundaries, hopefully increasing performance a little. Because there are two identical FATs, r is implicitly an even integer (since S is even) to satisfy the condition MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 13 Introduction MultiMediaCard System rem(r +2sF, S) = 0. Thus, it is always guaranteed that there is at least 1 “free” sector between PBR and FATs which can optionally contain proprietary information and non-x86 boot code. However, from standardization point-of-view, data in reserved sectors other than the PBR is “don’t care”. Each FAT entry is 16bits = 2bytes, yielding W/2 = 256 cluster entries per sector. Keeping in mind that the first two clusters are reserved, the combined partition capacity must satisfy the following condition Equation 7: Partition capacity equation S ⋅ hF – r ⋅ E- ⋅ S – W C ⋅ H – h – 32 - – 2 ⋅ sc < s c ⇒ ------- ⋅ -------------------------------N F 2 2 S ⋅ W ( C N ⋅ H – h F – 1 ) ⋅ 32 – ( 128 ⋅ 32 ⋅ h F – 128 ⋅ r – 2 ) ⋅ s c < s c ⇒ 32 ⋅ C N ⋅ H – 32 ⋅ h F – 32 – 4096 ⋅ s c ⋅ h F + 128 ⋅ r ⋅ s c + 2 ⋅ s c < s c ⇒ ( 4096 ⋅ s c ) ⋅ h F > 32 ⋅ C N ⋅ H + ( 128 ⋅ r + 1 ) ⋅ s c – 32 ⇒ 32 ⋅ C N ⋅ H + ( 128 ⋅ r + 1 ) ⋅ s c – 32 h F > ----------------------------------------------------------------------------------4096 ⋅ s c + 32 Thus, condition for hF is clearer, but we still have three degrees of freedom (hF, r and sc) at this point. However, our earlier definitions and the FAT16 system itself imposes some restrictions: Equation 8: Partition capacity equation restrictions h F ≤ 17 r ∈ [ 2, 4, 6, …, S ], S = 32 s c ∈ [ 2 0, 2 1, …, 2 7 ] Keeping in mind the definition of hF, condition r = 2 represents the ideal case of FAT size. Thus, equation 4-2 simplifies to equation 4-4 (dN is actual number of data clusters in the partition): Equation 9: Restricted partition capacity equations ⋅ C N ⋅ H + 257 ⋅ s c – 32 h = ceil 32 ------------------------------------------------------------- F 4096 ⋅ s c + 32 s ∈ [ 2 0, 2 1, …, 2 7 ] c h < 17 F ⋅ C N ⋅ H + 32 ⋅ h F – 32 d = floor 32 ------------------------------------------------------------ ≤ 65518 N sc Additional limitation to number of actual data clusters dN is imposed by the fact that in addition to cluster indices 0 and 1, some other indices are restricted as well: 0xFFF0 to 0xFFF6 are reserved, 0xFFF7 denotes 14 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Introduction unusable cluster and 0xFFF8 to 0xFFFF signify end of file allocation chain. Thus, maximum number of actual data clusters is (65536 – 18 = 65518). This has to be taken into account at h F = 17 boundary. At this point, the sensible thing to do is to experiment with the various cluster sizes (sC). Cluster size should be as small as possible to avoid capacity waste. So, there will be a maximum of eight iterations which repeated until calculated hF and dN meet their respective criteria. After the iterations, PBR parameter sC is already known. Parameters sF and r are computed from dN as follows: Equation 10: Computation of sF and r d N + 2 s = ceil --------------F 256 r = S – rem ( 2 ⋅ s F, S ) = 32 – rem ( 2 ⋅ s F, 32 ) 4.3 Miscellaneous notes on allocation tables and PBR - Cluster entries 0 and 1 must have values 0xFFF8 and 0xFFFF, respectively Both FAT tables are identical Free cluster entries will have value 0 Possible extraneous cluster entry values at the end of FAT tables are considered “don’t care”. For purposes of inter operability, no specific value may be assumed - Cluster entry-to-logical linear address conversions are calculated according to EN ISO 29293:1989, chapter 6.2.1 - Data space allocation from FAT is performed according to EN ISO 29293:1989, chapter 6.4.2 Table 4-2 summarizes cluster values within valid data cluster indices (2 to dN +1): Table 1: Cluster values within valid data cluster indices (2 to dN +1) Value/Range Description 0x0000 Indicates free cluster 0x0001 Invalid value, must not be used 0x0002 to (dN +1) Indicates allocated cluster. The value stored is the index of next cluster entry in an allocation chain (dN +2) to 0xFFF0 Invalid values, must not be used. Such values would point beyond the partition's data area 0xFFF0 to 0xFFF6 Reserved values, must not be used 0xFFF7 Indicates a bad (malfunctioning) cluster 0xFFF8 to 0xFFFF Indicates the end of an allocation chain Table 4-3 summarizes the cluster values (if any) in special allocation table indices: Table 2: Cluster values in special indices Indices Value/Description 0x0000 0xFFF8 (F8 is the media byte from PBR) 0x0001 Always 0xFFFF MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 15 Introduction MultiMediaCard System Table 2: Cluster values in special indices (dN +2) to 0xFFEF Last sector of FAT may contain extraneous cluster entries due to sector-boundary allocation. Values of those extraneous cluster entries should be 0x0000. However, any file system driver should not rely on these values being 0x0000. Instead, it should always be aware of the total number of data clusters (dN) 0xFFF0 to 0xFFF6 Reserved indices/values, must not be used for allocation. Refer to previous table 0xFFF7 Reserved index/value, must not be used for allocation. Refer to previous table 0xFFF8 to 0xFFFF Reserved indices/values, must not be used for allocation. Refer to previous table The following chart provides a simple example how cluster chains are formed within allocation table and how cluster indices are mapped to data area sectors. The first logical LSN of data area – “Beginning of data area” in the chart – is calculated from PBR as the sum of (r + number_of_fats*sf + 32). Note that cluster chains need not be contiguous or in ascending order. Start of allocation chain (f rom directory entry) Cluster index 0 8 16 ... ... ..., dN +1 Cluster values > dN +1 Don't care 0xFFF8 0x0000 0x0000 0xFFFF 0x0000 0x0000 Data Cluster 2 Data Cluster 6 ... Free cluster End of chain marker 0x0004 0x0000 0x0000 0x0000 0x0000 0x0000 Data Cluster 3 Data Cluster 7 Bad cluster 0x0005 0x0000 0x0000 0xFFF8 0x0000 0x0000 Data Cluster 4 Data Cluster 8 0x0000 0x0000 0x0000 0x0000 0xFFF7 0x0000 Data Cluster 5 Data Cluster 9 Beginning of data area. 1 cluster = s c consecutive sectors 16 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System 5 Directory entries Directory entries Directory entry structure shall be used according to EN ISO 29293 with the following clarification: for a directory, the file size field must be zero. The table below describes the directory entry fields, including some notes. Table 6: Structure of directory entries Offset Length (bytes) 0x0 8 Blank-padded filename. First character is set to E5h for deleted files (05h for pending delete files under Novell DOS / OpenDOS) 0x8 3 Blank-padded file extension 0xB 1 Attributes 0xC 10 MS-DOS 1.0-6.22: reserved DR DOS: used to store file password / owner Novell DOS 7: DELWATCH data MS-DOS 7/Windows95: additional file times 0x16 2 Time of creation or last update, bits [15:11]: hours (0-23) [10:5]: minutes [4:0]: seconds/2 0x18 2 Date of creation or last update, bits [15:9] year – 1980 [8:5] month [4:0] day Notes 0x1A 2 Starting cluster number 0x1C File size 4 Table 7: Format of MS-DOS 7/Windows95 additional file times Offset Length (bytes) 0x0 1 Reserved (Windows NT –specific?) 0x1 1 10-millisecond units pas creation time below (Windows NT –specific?) 0x2 2 File creation time 0x4 2 File creation date 0x6 2 Last-access date 0x8 2 FAT32: high word of starting cluster number. 0x0000 for VFAT16 5.1 Long filename support Notes VFAT16 long filename support is built on top of regular FAT16 by using extra directory entries which have all their attribute bits (Volume, Directory, Read-only, Archive). Systems without long filename support shall MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 17 Directory entries MultiMediaCard System ignore such entries. Details of long filename directory entry are as follows: Table 8: Format of long filename directory entry Length (bytes) Offset Notes 0x0 1 LFN record sequence and flags, bits [5-0]: sequence number [6:6]: set if last long-filename record for file [7:7]: set if file deleted 0x1 10 Long filename, 1st part 0xB 1 0x0F, impossible file attribute used as signature 0xC 1 Reserved (?). Set to 0x00 0xD 1 Checksum for long filename 0xE 12 Long filename, 2nd part 0x1A 2 First cluster number (always 0x0000 for long filename records) 0x1C Long filename, 3rd part 4 Long filename entries shall always be stored right prior to the short filename entry. The short filename checksum byte is computed by adding up the eleven bytes of the short filename, rotating the intermediate sum right one bit before adding the next character. In pseudocode: Byte sum=0; I=0; While (I < 11) { rotate (sum); sum += shortname [I]; I++; } 5.2 Filename character sets Short filenames must be all uppercase. Any combination of characters and numbers is valid, a blank (ASCII code 0x20h), as well as all ASCII characters above 0x7F, and the following special characters: $%'-_@~`!()^#& The following additional characters are valid in long filenames, but are not valid in 8.3 filenames: +,;=[] Long filenames are stored in 16-bit Unicode format, in practice meaning that there is 0x00 after the actual ASCII characters. Long filenames are terminated by an Unicode NULL (0x0000). Short filenames are generated from long filenames by: • Deleting any invalid characters, including . " / \ [ ] : ; = , • Removing extra periods (.) from the filename. The string after final period is considered extension and is truncated to maximum three (3) characters if the characters are valid and do not contain blanks in the mid- 18 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Directory entries dle. Otherwise, final period is ignored and the string next to final period is used as extension • If necessary, name part is truncated to a maximum six characters followed by tilde (~) and running sequence number (1, 2, 3, 4…) • If long filename contains a blank (space, ASCII code 0x20), it is replaced with an underscore (_) • The short filename characters are converted to upper case. • If filename has been a valid short name to begin with, it is only converted to upper case without any other modifications 5.3 FAT/VFAT16 caveats - Even though blank (ASCII code 0x20) is theoretically allowed in short filename, very few applications support it. Thus, it should not be used - In Windows9x, maximum short name path length is 80 characters. Creation of too deeply nested short name directory structures should be avoided for purposes of compatibility and inter operability - In Windows9x, maximum length of long filename paths is 260 characters (including terminating NULL). Long filenames can be up to 255 characters (including terminating NULL), but very long names should be avoided since in the worst case they only leave four characters for actual path - When copying/moving a directory with mixed set of long filenames and short ones, data loss may occur when a file with long name is copied, short name is generated to destination and the source contains a short name which is the same as the generated short name in destination directory Same volume label should be written both to PBR and root directory (using Label attribute in one of the root directory entries), as per MS Windows behaviour. Maximum label length is 11 characters. 5.4 Example of long filename entries Files “VeryLongFilename.txt”, “VeryVeryLongFilename.txt” and “Truly very, very long filename.txt” were MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 19 Directory entries MultiMediaCard System created to a floppy, using Windows95. The directory entries were arranged as follows: Figure 1: Example Of Directory Entry 5.5 Example of file system memory layout The following chart illustrates the memory layout of file system with a 32MB (62720 sectors) card using single partition with a file system. At first, the CHS geometry is calculated (S = 32): P = 62720 62720 H = ceil2 ---------------------- = 2 32 ⋅ 1024 62720 C = floor --------------- = 980 32 ⋅ 2 So, size of one cylinder is 32kB = 64 sectors. Since the partition is required to be on the cylinder boundary and there's a 16kB partition table in the very beginning of the media, the total number of logical cylinders in the partition is CN = 980 –1 = 979. Experimenting with clusters sizes and Equation 4-4 yields a cluster size sc 20 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Directory entries = 1 (one sector per cluster). Thus, Equations 4-4 and 4-5 produce the following results: sc = 1 ⋅ 979 ⋅ 2 + 257 ⋅ 1 – 32 h = ceil 32 ------------------------------------------------------------ F = 16 4096 ⋅ 1 + 32 32 ⋅ 979 ⋅ 2 + 32 ⋅ 16 – 32 d N = floor ------------------------------------------------------------- = 62112 1 621112 + 2- = 243 s F = ceil ------------------------- 256 r = 32 – rem ( 2 ⋅ 243, 32 ) = 32 – 6 = 26 In the following chart, data sectors are set to zero in order to highlight the arrangement of partition and system MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 21 Directory entries MultiMediaCard System areas: System area layout 640 0 32 576 512 sectors 448 243 384 Data area RDE's 2nd FAT 1st FAT Reserved Gap1 Part. table 320 256 243 192 128 64 26 32 32 0 Figure 2: System Area Layout 22 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA MultiMediaCard System Appendix A: Directory entries Abbreviations aka Also known as CHS Cylinder-Head-Sector. Traditional addressing mode of floppies and hard drives. Their range is C = 0 – 1023, H = 0 – 255, S = 1 – 63 FAT File Allocation Table, table of linked-list values in the FAT file system containing allocation information. Also generic name for various file system implementations employing FATs FAT16 16 refers to number of bits in a single allocation unit in the FAT RDE Root Directory Entry. Located immediately after FAT(s) in the file system MBR Master Boot Record. Aka Master Boot Sector. Contains partition information and optionally master boot code PBR Partition Boot Record. Aka Partition Boot Sector. Contains FAT parameters of the partition and optionally boot code SPT Sectors Per Track. Aka Sectors Per Head. Parameter S of CHS geometry MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA 23 Directory entries Appendix B: MultiMediaCard System References MultiMediaCard System Specification EN ISO 29293:1989 Undocumented DOS 2nd edition Andrew Schulman, Ralf Brown, David Maxey, Raymond J. Michels, Jim Kyle Addison-Wesley, 1993 Interrupt List Release 6.0 Ralf Brown 3. January 1999 http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html Detailed Explanation of FAT Boot Sector Reviewed: October 25, 2000 Microsoft Knowledge Base, Article ID: Q140418 Default Cluster Size for FAT and NTFS Reviewed: March 1, 2000 Microsoft Knowledge Base, Article ID: Q140365 How Windows Generates 8.3 File Names from Long File Names Reviewed: December 14, 2000 Microsoft Knowledge Base, Article ID: Q142982 Copying Files with Mix of LFN and SFN May Lead to Data Loss Last reviewed: March 1, 2000 Microsoft Knowledge Base, Article ID: Q195144 24 MultiMediaCard FAT16 File System Specification Version 1.0 Official Release (c) March 2003 MMCA