This is a special implementation of FAT16/32 file system support. While it
can be tested in a non-AVR environment, it is designed to be RAM frugal
enough to run on systems with 1K RAM, or larger. Because it is designed
to operate with a maximum of one disk sector buffer, it is not efficient
by design.
The user supplies his own disk I/O routines so that the library is
completely independent of the physical disk implementation. The fatfs
package was however, designed with SD/MMC card support in mind.
Additionally, the user may call File System date/time routines to update
the file system's concept of date and time. In this manner, fatfs is
decoupled from the host's concept of date and time.
The fatfs package supports the maintenance of up to 4 FAT tables. Only the first
FAT is ever searched, though all parallel FAT tables are updated if there are
changes. However, for SD/MMC card use, you may wish to format for just one FAT table,
for greater efficiency.
Most of the underlying data types come from Interfaces:
Arrays of these types are defined in fatfs as:
type U8_Array is array(Unsigned_16 range <>) of Unsigned_8; type U16_Array is array(Unsigned_16 range <>) of Unsigned_16; type U32_Array is array(Unsigned_16 range <>) of Unsigned_32;
For Convenience, there is also a Sector Buffer type defined as follows:
type Block_Type is array(Unsigned_16 range <>) of Unsigned_8; for Block_Type'Component_Size use 8; for Block_Type'Alignment use 4; subtype Block_512 is Block_Type(0..511);
It is recommended that you use type Block_512 wherever a sector buffer is required.
The enumerated type FS_Type indicates the type of FAT file system support is involved:
type FS_Type is ( FS_FAT12, -- FAT12 (unsupported) FS_FAT16, -- FAT16 FS_FAT32, -- FAT32 FS_Unknown -- Unknown or bad media );
Only FAT16 and FAT32 are currently supported. FAT12 involves FAT entries that span sector boundaries, which would have bloated the suppport code. Since FAT12 is intended for small file systems, the decision was made not to support it.
type FAT_Copies_Type is new Unsigned_8; -- # of FAT tables type Sector_Type is new Unsigned_32; -- Disk sector # type Cluster_Type is new Sector_Type; -- Cluster # type Year_Type is mod 2**7; -- Year in directory entry (minus 1980) type Month_Type is mod 2**4; -- Month in directory entry type Day_Type is mod 2**5; -- Day in directory entry type Hour_Type is mod 2**5; -- Hour in directory entry type Minute_Type is mod 2**6; -- Minute in directory entry type Seconds2_Type is mod 2**5; -- Seconds / 2 in directory entry
type Boot_Sector_Type is record Jump : Bytes(0..2); -- 0-2 : Jump to bootstrap OEM_Name : String(3..10); -- 3-10 : OEM name/version (E.g. "IBM 3.3", "IBM 20.0", "MSDOS5.0") Bytes_Per_Sector : Unsigned_16; -- 11-12 : Bytes per sector (512 for FAT12) Sectors_Per_Cluster : Unsigned_8; -- 13 : 1, 2, 3, 8, 16, 32, 64, 128 Reserved_Sectors : Unsigned_16; -- 14-15 : For FAT 12/16 = 1, FAT32 = 32 FAT_Copies : FAT_Copies_Type; -- 16 : 2 Root_Dir_Entries : Unsigned_16; -- 17-18 : FAT12=224, FAT32=0, 512 recommended for FAT16 Total_Sectors_in_FS : Unsigned_16; -- 19-20 : 2880 when not FAT32 and < 32MB Media_Descriptor : Unsigned_8; -- 21 : F0 = 1.44MB floppy, F8 = HD Sectors_Per_FAT : Unsigned_16; -- 22-23 : 9, FAT32 = 0 Sectors_Per_Track : Unsigned_16; -- 24-25 : 12 No_Of_Heads : Unsigned_16; -- 26-27 : 2 for double sided diskette Hidden_Sectors_32 : Unsigned_32; -- 28-31 : FAT32 Total_Sectors_32 : Unsigned_32; -- 32-35 : FAT32 Sectors_Per_FAT_32 : Unsigned_32; -- 36-39 : FAT32 Mirror_Flags : Unsigned_16; -- 40-41 : FAT32 FS_Version_Major : Unsigned_8; -- 42-42 : FAT32 FS_Version_Minor : Unsigned_8; -- 43-43 : FAT32 Root_Dir_First_Cluster: Unsigned_32; -- 44-47 : FAT32 FS_Info_Sector : Unsigned_16; -- 48-49 : FAT32 Backup_Boot_Sector : Unsigned_16; -- 50-51 : FAT32 Reserved : Bytes(52..63); -- 52-63 : FAT32 Bootstrap_Code : Bytes(64..509); Signature : Bytes(0..1); -- 510-511: 55 AA end record; for Boot_Sector_Type'Alignment use 4;
type Dir_Entry_Type is record Filename : String(1..8); Extension : String(1..3); Reserved_7 : Boolean; Reserved_6 : Boolean; Archive : Boolean; Subdirectory : Boolean; Volume_Name : Boolean; System_File : Boolean; Hidden_File : Boolean; Read_Only : Boolean; Reserved : String(1..8); Cluster_High : Unsigned_16; -- FAT32 only Hour : Hour_Type; Minute : Minute_Type; Second2 : Seconds2_Type; Year : Year_Type; Month : Month_Type; Day : Day_Type; First_Cluster : Unsigned_16; File_Size : Unsigned_32; end record;
Wiki: FATFS_Binary_IO
Wiki: FATFS_Directory
Wiki: FATFS_File_System
Wiki: FATFS_Pathname
Wiki: FATFS_Sector_IO
Wiki: FATFS_Text_IO
Wiki: Home
Wiki: Setup