NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fat_standard.h File Reference
#include <stdint.h>
#include <stdbool.h>
Include dependency graph for fat_standard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mbrPartitionEntry_t
 
struct  fat16Descriptor_t
 
struct  fat32Descriptor_t
 
struct  fatVolumeID_t
 
struct  fatDirectoryEntry_t
 

Macros

#define MBR_PARTITION_TYPE_FAT16   0x06
 
#define MBR_PARTITION_TYPE_FAT32   0x0B
 
#define MBR_PARTITION_TYPE_FAT32_LBA   0x0C
 
#define MBR_PARTITION_TYPE_FAT16_LBA   0x0E
 
#define FAT_VOLUME_ID_SIGNATURE_1   0x55
 
#define FAT_VOLUME_ID_SIGNATURE_2   0xAA
 
#define FAT_DIRECTORY_ENTRY_SIZE   32
 
#define FAT_SMALLEST_LEGAL_CLUSTER_NUMBER   2
 
#define FAT_MAXIMUM_FILESIZE   0xFFFFFFFF
 
#define FAT12_MAX_CLUSTERS   4084
 
#define FAT16_MAX_CLUSTERS   65524
 
#define FAT_FILE_ATTRIBUTE_READ_ONLY   0x01
 
#define FAT_FILE_ATTRIBUTE_HIDDEN   0x02
 
#define FAT_FILE_ATTRIBUTE_SYSTEM   0x04
 
#define FAT_FILE_ATTRIBUTE_VOLUME_ID   0x08
 
#define FAT_FILE_ATTRIBUTE_DIRECTORY   0x10
 
#define FAT_FILE_ATTRIBUTE_ARCHIVE   0x20
 
#define FAT_FILENAME_LENGTH   11
 
#define FAT_DELETED_FILE_MARKER   0xE5
 
#define FAT_MAKE_DATE(year, month, day)   (day | (month << 5) | ((year - 1980) << 9))
 
#define FAT_MAKE_TIME(hour, minute, second)   ((second / 2) | (minute << 5) | (hour << 11))
 

Enumerations

enum  fatFilesystemType_e { FAT_FILESYSTEM_TYPE_INVALID, FAT_FILESYSTEM_TYPE_FAT12, FAT_FILESYSTEM_TYPE_FAT16, FAT_FILESYSTEM_TYPE_FAT32 }
 

Functions

struct mbrPartitionEntry_t __attribute__ ((packed)) mbrPartitionEntry_t
 
uint32_t fat32_decodeClusterNumber (uint32_t clusterNumber)
 
bool fat32_isEndOfChainMarker (uint32_t clusterNumber)
 
bool fat16_isEndOfChainMarker (uint16_t clusterNumber)
 
bool fat_isFreeSpace (uint32_t clusterNumber)
 
bool fat_isDirectoryEntryTerminator (fatDirectoryEntry_t *entry)
 
bool fat_isDirectoryEntryEmpty (fatDirectoryEntry_t *entry)
 
void fat_convertFilenameToFATStyle (const char *filename, uint8_t *fatFilename)
 

Variables

uint8_t bootFlag
 
uint8_t chsBegin [3]
 
uint8_t type
 
uint8_t chsEnd [3]
 
uint32_t lbaBegin
 
uint32_t numSectors
 
uint8_t driveNumber
 
uint8_t reserved1
 
uint8_t bootSignature
 
uint32_t volumeID
 
char volumeLabel [11]
 
char fileSystemType [8]
 
uint32_t FATSize32
 
uint16_t extFlags
 
uint16_t fsVer
 
uint32_t rootCluster
 
uint16_t fsInfo
 
uint16_t backupBootSector
 
uint8_t reserved [12]
 
uint8_t jmpBoot [3]
 
char oemName [8]
 
uint16_t bytesPerSector
 
uint8_t sectorsPerCluster
 
uint16_t reservedSectorCount
 
uint8_t numFATs
 
uint16_t rootEntryCount
 
uint16_t totalSectors16
 
uint8_t media
 
uint16_t FATSize16
 
uint16_t sectorsPerTrack
 
uint16_t numHeads
 
uint32_t hiddenSectors
 
uint32_t totalSectors32
 
union {
   fat16Descriptor_t   fat16
 
   fat32Descriptor_t   fat32
 
fatDescriptor
 
char filename [FAT_FILENAME_LENGTH]
 
uint8_t attrib
 
uint8_t ntReserved
 
uint8_t creationTimeTenths
 
uint16_t creationTime
 
uint16_t creationDate
 
uint16_t lastAccessDate
 
uint16_t firstClusterHigh
 
uint16_t lastWriteTime
 
uint16_t lastWriteDate
 
uint16_t firstClusterLow
 
uint32_t fileSize
 

Macro Definition Documentation

#define FAT12_MAX_CLUSTERS   4084
#define FAT16_MAX_CLUSTERS   65524
#define FAT_DELETED_FILE_MARKER   0xE5
#define FAT_DIRECTORY_ENTRY_SIZE   32
#define FAT_FILE_ATTRIBUTE_ARCHIVE   0x20
#define FAT_FILE_ATTRIBUTE_DIRECTORY   0x10
#define FAT_FILE_ATTRIBUTE_HIDDEN   0x02
#define FAT_FILE_ATTRIBUTE_READ_ONLY   0x01
#define FAT_FILE_ATTRIBUTE_SYSTEM   0x04
#define FAT_FILE_ATTRIBUTE_VOLUME_ID   0x08
#define FAT_FILENAME_LENGTH   11
#define FAT_MAKE_DATE (   year,
  month,
  day 
)    (day | (month << 5) | ((year - 1980) << 9))
#define FAT_MAKE_TIME (   hour,
  minute,
  second 
)    ((second / 2) | (minute << 5) | (hour << 11))
#define FAT_MAXIMUM_FILESIZE   0xFFFFFFFF
#define FAT_SMALLEST_LEGAL_CLUSTER_NUMBER   2
#define FAT_VOLUME_ID_SIGNATURE_1   0x55
#define FAT_VOLUME_ID_SIGNATURE_2   0xAA
#define MBR_PARTITION_TYPE_FAT16   0x06
#define MBR_PARTITION_TYPE_FAT16_LBA   0x0E
#define MBR_PARTITION_TYPE_FAT32   0x0B
#define MBR_PARTITION_TYPE_FAT32_LBA   0x0C

Enumeration Type Documentation

Enumerator
FAT_FILESYSTEM_TYPE_INVALID 
FAT_FILESYSTEM_TYPE_FAT12 
FAT_FILESYSTEM_TYPE_FAT16 
FAT_FILESYSTEM_TYPE_FAT32 

Function Documentation

struct mbrPartitionEntry_t __attribute__ ( (packed)  )
bool fat16_isEndOfChainMarker ( uint16_t  clusterNumber)
uint32_t fat32_decodeClusterNumber ( uint32_t  clusterNumber)

FAT32 cluster numbers are really only 28 bits, and the top 4 bits must be left alone and not treated as part of the cluster number (so various FAT drivers can use those bits for their own purposes, or they can be used in later extensions)

bool fat32_isEndOfChainMarker ( uint32_t  clusterNumber)
void fat_convertFilenameToFATStyle ( const char *  filename,
uint8_t *  fatFilename 
)

Convert the given "prefix.ext" style filename to the FAT format to be stored on disk.

fatFilename must point to a buffer which is FAT_FILENAME_LENGTH bytes long. The buffer is not null-terminated.

bool fat_isDirectoryEntryEmpty ( fatDirectoryEntry_t entry)
bool fat_isDirectoryEntryTerminator ( fatDirectoryEntry_t entry)
bool fat_isFreeSpace ( uint32_t  clusterNumber)

Variable Documentation

uint8_t attrib
uint16_t backupBootSector
uint8_t bootFlag
uint8_t bootSignature
uint16_t bytesPerSector
uint8_t chsBegin[3]
uint8_t chsEnd[3]
uint16_t creationDate
uint16_t creationTime
uint8_t creationTimeTenths
uint8_t driveNumber
uint16_t extFlags
union { ... } fatDescriptor
uint16_t FATSize16
uint32_t FATSize32
char filename[FAT_FILENAME_LENGTH]
uint32_t fileSize
char fileSystemType
uint16_t firstClusterHigh
uint16_t firstClusterLow
uint16_t fsInfo
uint16_t fsVer
uint32_t hiddenSectors
uint8_t jmpBoot[3]
uint16_t lastAccessDate
uint16_t lastWriteDate
uint16_t lastWriteTime
uint32_t lbaBegin
uint8_t media
uint8_t ntReserved
uint8_t numFATs
uint16_t numHeads
uint32_t numSectors
char oemName[8]
uint8_t reserved[12]
uint8_t reserved1
uint16_t reservedSectorCount
uint32_t rootCluster
uint16_t rootEntryCount
uint8_t sectorsPerCluster
uint16_t sectorsPerTrack
uint16_t totalSectors16
uint32_t totalSectors32
uint8_t type
uint32_t volumeID
char volumeLabel