FSCK.FAT(8)

๐ŸŽ€ FSCK.FAT(8) ๐ŸŽ€

โœจ NAME โœจ

okay so the tool here is fsck.fat, and its whole job is to check and repair MS-DOS FAT filesystems ๐Ÿ’…

๐Ÿ’– SYNOPSIS ๐Ÿ’–

fsck.fat [OPTIONS] DEVICE

๐ŸŒธ DESCRIPTION ๐ŸŒธ

fsck.fat verifies that MS-DOS filesystems are consistent, and if you ask nicely (with the right flags) it'll try to fix them too ๐Ÿซถ

Here are the filesystem problems it can fix, in this exact order:

  • FAT contains invalid cluster numbers. The cluster gets changed to EOF.
  • A file's cluster chain has a loop. The loop gets broken.
  • Bad clusters (read errors). They're marked bad and removed from whatever files own them. This check is optional ๐Ÿ™ˆ
  • Directories with a large number of bad entries (probably corrupt). The directory can be deleted. bye bye ๐Ÿ˜ญ
  • Files . and .. are non-directories. They can be deleted or renamed.
  • Directories . and .. in the root directory. They get deleted.
  • Bad filenames. They can be renamed.
  • Duplicate directory entries. They can be deleted or renamed.
  • Directories with a non-zero size field. The size gets set to zero.
  • Directory . doesn't point to its parent directory. The start pointer is adjusted.
  • Directory .. doesn't point to the parent of its parent directory. The start pointer is adjusted.
  • . and .. aren't the first two entries in a non-root directory. The entries get created, and occupied slots get moved out of the way if needed.
  • A file's start cluster number is invalid. The file gets truncated.
  • A file contains bad or free clusters. The file gets truncated.
  • A file's cluster chain is longer than its size fields say. The file gets truncated.
  • Two or more files share the same cluster(s). All but one of them get truncated. If the file being truncated is a directory file that was already read, the filesystem check restarts after truncation ๐Ÿ”
  • A file's cluster chain is shorter than its size fields say. The file gets truncated.
  • The volume label in the root directory, or the label in the boot sector, is invalid. Invalid labels get removed.
  • The volume label in the root directory and the label in the boot sector are different. The volume label from the root directory gets copied to the boot sector.
  • Clusters are marked as used but aren't owned by any file. They get marked as free.

Additionally, there's one problem it detects but does not repair:

  • Invalid parameters in the boot sector
โš ๏ธ When fsck.fat checks a filesystem, it stashes all of its changes in memory and only performs them after every check is done. You can turn this off with the -w option.

Two different variants of the FAT filesystem are supported. The standard one is FAT12, FAT16 and FAT32 as defined by Microsoft, and it's what you'll find on hard disks and removable media like USB sticks and SD cards ๐Ÿ’พ The other is the legacy Atari variant used on Atari ST.

The Atari format has some small differences. A few boot sector fields get interpreted slightly differently, and the special FAT entries for end-of-file and bad cluster can be different too. Under MS-DOS, 0xfff8 is used for EOF, and Atari uses 0xffff by default, but both systems recognize every value from 0xfff8โ€“0xffff as end-of-file. MS-DOS only uses 0xfff7 for bad clusters, whereas on Atari the values 0xfff0โ€“0xfff7 are for this purpose (though the standard value is still 0xfff7).

๐Ÿฆ‹ OPTIONS ๐Ÿฆ‹

  • -a โ€” Auto-repair the filesystem with zero user intervention needed ๐Ÿค– Whenever there's more than one way to fix a problem, the least destructive approach gets picked.
  • -A โ€” Switches to the Atari variant of the FAT filesystem if it isn't already active, otherwise switches to the standard one. This is selected by default when mkfs.fat runs on 68k Atari Linux.
  • -b โ€” Does a read-only boot sector check.
  • -c PAGE โ€” Uses DOS codepage PAGE to decode short file names. By default, codepage 850 is used.
  • -d PATH โ€” Deletes the specified file. If more than one file has that name, the first one gets deleted. You can give this option more than once ๐Ÿ—‘๏ธ
  • -f โ€” Salvages unused cluster chains into files. By default, unused clusters get added back to the free disk space, except in auto mode (-a).
  • -F NUM โ€” Uses FAT table NUM for filesystem access. By default the value is 0, and then the first uncorrupted FAT table gets chosen. "Uncorrupted" means the FAT table has a valid first cluster. If you keep the default 0 and every FAT table is corrupted, fsck.fat gives up and doesn't try to repair the FAT filesystem ๐Ÿ˜ต If you specify a non-zero NUM, fsck.fat uses FAT table NUM to repair the filesystem, and if that table has a corrupted first cluster, fsck.fat will repair it. In any case, if the FAT filesystem has more FAT tables, the repaired content of the chosen FAT table gets copied to the other FAT tables. To repair a corrupted first cluster, you have to call fsck.fat with a non-zero NUM value.
  • -l โ€” Lists the path names of the files being processed.
  • -n โ€” No-operation mode! It checks for errors non-interactively, but doesn't write anything to the filesystem ๐Ÿ‘€
  • -p โ€” Same as -a, just for compatibility with other *fsck tools.
  • -r โ€” Interactively repairs the filesystem. Whenever there's more than one approach to fix an inconsistency, you get asked for advice. This is the default mode, and the option is only kept around for backwards compatibility.
  • -S โ€” Treats short (8.3) file names with spaces in the middle as invalid, the way previous versions of this program did ๐Ÿ™…โ€โ™€๏ธ Here's the tea: the FAT spec doesn't forbid these names, and Microsoft's own file system checking tools never flagged them as errors. But plenty of DOS programs can't handle files with names like that. Using this option can make those files accessible to those programs.

Short file names that start with a space are considered invalid no matter how this option is set.

Previous versions of this program made a special exception and treated EA DATA. SF and WP ROOT. SF as valid short names. Using this option does not keep that exception.

  • -t โ€” Marks unreadable clusters as bad.
  • -u PATH โ€” Tries to undelete the specified file. fsck.fat attempts to allocate a chain of contiguous unallocated clusters starting from the start cluster of the undeleted file. You can give this option more than once ๐Ÿช„
  • -U โ€” Treats lowercase volume and boot labels as invalid, and only allows uppercase characters. The FAT spec forbids lowercase labels, but Linux tools use them all the time. MS-DOS and Windows have no trouble reading them, so by default, volume and boot labels with lowercase characters are allowed ๐Ÿซถ
  • -v โ€” Verbose mode. Generates slightly more output ๐Ÿ“ฃ
  • -V โ€” Performs a verification pass. The filesystem check gets repeated after the first run. The second pass should never report any fixable errors. It can take a lot longer than the first pass, because the first pass may have generated a long list of modifications that has to be scanned on every disk read ๐Ÿข
  • --variant TYPE โ€” Creates a filesystem of variant TYPE. The acceptable values are standard and atari (in any combination of upper and lower case). Check the DESCRIPTION section above for the differences.
  • -w โ€” Writes changes to disk immediately โšก
  • -y โ€” Same as -a (auto-repair the filesystem), just for compatibility with other fsck tools.
  • --help โ€” Displays a help message describing usage and options, then exits ๐Ÿ’โ€โ™€๏ธ

๐ŸŒˆ EXIT STATUS ๐ŸŒˆ

  • 0 โ€” No recoverable errors were detected. Slay โœจ
  • 1 โ€” Recoverable errors were detected, or fsck.fat ran into an internal inconsistency ๐Ÿ˜ฌ
  • 2 โ€” Usage error. fsck.fat didn't access the filesystem.

๐Ÿ“ FILES ๐Ÿ“

  • fsck0000.rec, fsck0001.rec, ... โ€” When recovering from a corrupted filesystem, fsck.fat dumps the recovered data into files named fsckNNNN.rec in the top level directory of the filesystem.

๐Ÿ™ˆ BUGS ๐Ÿ™ˆ

  • It doesn't remove entirely empty directories. ๐Ÿ˜ญ
  • It should give more diagnostic messages.
  • Undeleting files should use a more sophisticated algorithm.

๐Ÿ”— SEE ALSO ๐Ÿ”—

fatlabel(8), mkfs.fat(8)

๐Ÿ“ HOMEPAGE ๐Ÿ“

The home for the dosfstools project is its GitHub project page.

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

dosfstools were written by Werner Almesberger, Roman Hodek, and others. The current maintainers are Andreas Bombe and Pali Rohรกr ๐Ÿซถ


Bestie, that's the whole FSCK.FAT(8) page, served with extra sparkle ๐Ÿ’… dosfstools 4.2, last updated 2021-01-31 ๐Ÿ’– Stay iconic and keep your FAT tables healthy ๐Ÿงš๐ŸŒธ