Differences between Xbox FATX and MS-DOS FAT

From Xbox-Linux

by Michael Steil (original version: 30 November 2003)

There is already a document describing the FATX filesystem structure ("Xbox Disk Layout" by Andrew de Quincey and Lucien Murray-Pitts). The document you are reading right now points out the differences between FATX and the FAT16/FAT32 file systems of MS-DOS/Windows, and requires the reader to know about FAT. The differences are especially important for instance when modifying the Linux FAT driver to support FATX.

Table of contents

Basics

FATX is basically a FAT derivative that dropped some legacy fields as well as redundant information that could lead to inconsistencies and thus create possible security problems.

The FAT filesystem consists of the boot block (or superblock in Unix jargon), the File Allocation Table(s), the directory entries and the actual file data. The File Allocation Table format and the file data layout on disk are actually identical on FAT and FATX. This shows that both are very similar.

The Superblock

The DOS boot block is partially defined by the IBM-PC hard disk layout (boot program, OEM string, ...). FATX has a very different boot block. The actual data is 18 bytes long, but the complete boot block always occupies 4 KB.

Offset Size Description
0 4 "FATX" string (ASCII)
4 4 Volume ID (int)
8 4 Cluster size in (512 byte) sectors
12 2 Number of FAT copies
14 4 Unknown (always 0?)
18 4078 Unused

On the Xbox, the cluster size is always set to 32 sectors (that's 16 KB) and the number of FATs is always 1.

As you can see, the FATX boot block lacks some fields of the FAT one:

Field FAT Version Comment
Bytes per sector all Always 512 on FATX
Reserved clusters all no reserved clusters on FATX
Number of root directory entries all Always 256 (one cluster) on FATX
Number of sectors all Redundant, definied by partitioning
Media code all Legacy
Number of sectors the FAT occupies all Redundant, can be calculated with volume size
Sectors per track all Legacy
Heads all Legacy
Flags ("Fat Mirroring", "Active FAT") FAT32 only Not supported on FATX
Filesystem version FAT32 only There will never be more than one version of FATX.
First cluster in root directory FAT32 only Not needed on FATX
Filesystem info sector FAT32 only Not supported on FATX
Backup boot sector FAT32 only Not supported on FATX

The File Allocation Table

The (single) File Allocation Table always starts at position 4 KB of the filesystem. Its format is identical to the FAT16/32 formats. Partitions with less than 65525 clusters (smaller than about 1GB) will be FATX16, else FATX32. Just as FAT16/FAT32, FATX16 has 16 bit FAT entries and FATX32 has 32 bit FAT entries.

On the Xbox, partitions 0, 1, 2 and 3 (Scratch A, B, C and System) are FATX16, partition 4 (Data) is FATX32.

The size of the FAT can be calculated like this (cluster map size entry being 16 or 32):

FAT size in bytes = ((partition size in bytes / cluster size) * cluster map entry size) rounded up to the nearest 4096 byte boundary.

The Directory Entries

FAT directory entries are quite complicated because of their ancient original design and the downwards-compatible extension to long file names. FATX has directory entries similar to the orginal FAT ones, but with long filenames (up to 42 characters).

A directory entry is 64 bytes long, thus a cluster can contain up to 256 directory entries. Subdirectories can contain more than 256 entries, since they may consist of more than one cluster, as on FAT.

A directory entry looks like this:

Offset Size Description
0 1 Size of filename (max. 42)
1 1 Attribute as on FAT
2 42 Filename in ASCII, padded with 0xff (not zero-terminated)
44 4 First cluster
48 4 File size in bytes
52 2 Modification time
54 2 Modification date
56 2 Creation time
58 2 Creation date
60 2 Last access time
62 2 Last access date

The order of the three time stamps has not yet been verified, the order in the table corresponds to the order in VFAT directory entries. The format of the timestamps looks a lot like the DOS one, but this has not been fully confirmed yet.

Note that FATX doesn't support Unicode filenames. The file names are case insensitive but case preserving, as on FAT.

Deleted files are marked with a value of 0xe5 in the filename size field. (FAT marks deleted files with a first filename character of 0xe5.) A directory entry with a filename size of 0xff marks the end of the directory.

Open Questions

  • What about ANSI filenames? Can the Xbox kernel correctly convert the case?
  • What is the meaning of the unknown fields in the superblock? Is there a flag for "unmounted cleanly"?