# FatFs - Generic FAT Filesystem Module

FatFs is a generic FAT/exFAT filesystem module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk control layer. Therefore it is independent of the platforms and storage devices. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, RX and etc. Also Petit FatFs module for tiny microcontrollers is available here.

#### Features

- DOS/Windows Compatible FAT/exFAT Filesystem.
- Platform Independent. Easy to port.
- Very Small Footprint for Program Code and Work Area.
- Various Configuration Options to Support for:
  - Long File Name in ANSI/OEM or Unicode.
  - exFAT Filesystem, 64-bit LBA and GPT for Huge Storages.
  - Thread Safe for RTOS.
  - Multiple Volumes. (Physical Drives and Partitions)
  - Variable Sector Size.
  - Multiple Code Pages Including DBCS.
  - Read-only, Optional APIs, I/O Buffer and etc...

### Application Interface

FatFs provides various filesystem functions for the applications as shown below.

- File Access
  - f_open - Open/Create a file
  - f_close - Close an open file
  - f_read - Read data from the file
  - f_write - Write data to the file
  - f_lseek - Move read/write pointer, Expand size
  - f_truncate - Truncate file size
  - f_sync - Flush cached data
  - f_forward - Forward data to the stream
  - f_expand - Allocate a contiguous block to the file
  - f_gets - Read a string
  - f_putc - Write a character
  - f_puts - Write a string
  - f_printf - Write a formatted string
  - f_tell - Get current read/write pointer
  - f_eof - Test for end-of-file
  - f_size - Get size
  - f_error - Test for an error
- Directory Access
  - f_opendir - Open a directory
  - f_closedir - Close an open directory
  - f_readdir - Read a directory item
  - f_findfirst - Open a directory and read the first item matched
  - f_findnext - Read a next item matched
- File and Directory Management
  - f_stat - Check existance of a file or sub-directory
  - f_unlink - Remove a file or sub-directory
  - f_rename - Rename/Move a file or sub-directory
  - f_chmod - Change attribute of a file or sub-directory
  - f_utime - Change timestamp of a file or sub-directory
  - f_mkdir - Create a sub-directory
  - f_chdir - Change current directory
  - f_chdrive - Change current drive
  - f_getcwd - Retrieve the current directory and drive
- Volume Management and System Configuration
  - f_mount - Register/Unregister the work area of the volume
  - f_mkfs - Create an FAT volume on the logical drive
  - f_fdisk - Create partitions on the physical drive
  - f_getfree - Get free space on the volume
  - f_getlabel - Get volume label
  - f_setlabel - Set volume label
  - f_setcp - Set active code page

### Media Access Interface

Since FatFs module is the Filesystem Layer independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The storage device control module is not a part of FatFs module and it needs to be provided by implementer. FatFs controls the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for storage device control module is available here.

- Storage Device Controls
  - disk_status - Get device status
  - disk_initialize - Initialize device
  - disk_read - Read data
  - disk_write - Write data
  - disk_ioctl - Control device dependent functions
- Real Time Clock
  - get_fattime - Get current time

### Resources

The FatFs module is a free software opened for education, research and development. You can use, modify and/or redistribute it for any purpose without any restriction under your responsibility. For further information, refer to the application note.

- Getting Started: FatFs Application Note
- FAT32 Specification by Microsoft (The authorized document on FAT filesystem)
- The basics of FAT filesystem (FatFs is written based on this documentation)
- The basics of exFAT filesystem (FatFs is written based on this documentation)
- How to use MMC/SDC
- Playing with FlashAir and FatFs
- Nemuisan's Blog (Well written implementations for STM32F/SPI & SDIO and LPC4088/SDMMC)
- Read SD card with FatFs on STM32F4xx devices by Tilen Majerle (Quick and easy implementation for STM32F4-Discovery)

Go to FatFs Home Page