[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / io / asyncfatfs / fat_standard.h
blobec3d645884ca6f6be8f3a48fc88ebf93995b5afa
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <stdint.h>
24 #include <stdbool.h>
26 #define MBR_PARTITION_TYPE_FAT16 0x06
27 #define MBR_PARTITION_TYPE_FAT32 0x0B
28 #define MBR_PARTITION_TYPE_FAT32_LBA 0x0C
29 #define MBR_PARTITION_TYPE_FAT16_LBA 0x0E
31 // Signature bytes found at index 510 and 511 in the volume ID sector
32 #define FAT_VOLUME_ID_SIGNATURE_1 0x55
33 #define FAT_VOLUME_ID_SIGNATURE_2 0xAA
35 #define FAT_DIRECTORY_ENTRY_SIZE 32
36 #define FAT_SMALLEST_LEGAL_CLUSTER_NUMBER 2
38 #define FAT_MAXIMUM_FILESIZE 0xFFFFFFFF
40 #define FAT12_MAX_CLUSTERS 4084
41 #define FAT16_MAX_CLUSTERS 65524
43 #define FAT_FILE_ATTRIBUTE_READ_ONLY 0x01
44 #define FAT_FILE_ATTRIBUTE_HIDDEN 0x02
45 #define FAT_FILE_ATTRIBUTE_SYSTEM 0x04
46 #define FAT_FILE_ATTRIBUTE_VOLUME_ID 0x08
47 #define FAT_FILE_ATTRIBUTE_DIRECTORY 0x10
48 #define FAT_FILE_ATTRIBUTE_ARCHIVE 0x20
50 #define FAT_FILENAME_LENGTH 11
51 #define FAT_DELETED_FILE_MARKER 0xE5
53 #define FAT_MAKE_DATE(year, month, day) (day | (month << 5) | ((year - 1980) << 9))
54 #define FAT_MAKE_TIME(hour, minute, second) ((second / 2) | (minute << 5) | (hour << 11))
56 typedef enum {
57 FAT_FILESYSTEM_TYPE_INVALID,
58 FAT_FILESYSTEM_TYPE_FAT12,
59 FAT_FILESYSTEM_TYPE_FAT16,
60 FAT_FILESYSTEM_TYPE_FAT32
61 } fatFilesystemType_e;
63 typedef struct mbrPartitionEntry_t {
64 uint8_t bootFlag;
65 uint8_t chsBegin[3];
66 uint8_t type;
67 uint8_t chsEnd[3];
68 uint32_t lbaBegin;
69 uint32_t numSectors;
70 } __attribute__((packed)) mbrPartitionEntry_t;
72 typedef struct fat16Descriptor_t {
73 uint8_t driveNumber;
74 uint8_t reserved1;
75 uint8_t bootSignature;
76 uint32_t volumeID;
77 char volumeLabel[11];
78 char fileSystemType[8];
79 } __attribute__((packed)) fat16Descriptor_t;
81 typedef struct fat32Descriptor_t {
82 uint32_t FATSize32;
83 uint16_t extFlags;
84 uint16_t fsVer;
85 uint32_t rootCluster;
86 uint16_t fsInfo;
87 uint16_t backupBootSector;
88 uint8_t reserved[12];
89 uint8_t driveNumber;
90 uint8_t reserved1;
91 uint8_t bootSignature;
92 uint32_t volumeID;
93 char volumeLabel[11];
94 char fileSystemType[8];
95 } __attribute__((packed)) fat32Descriptor_t;
97 typedef struct fatVolumeID_t {
98 uint8_t jmpBoot[3];
99 char oemName[8];
100 uint16_t bytesPerSector;
101 uint8_t sectorsPerCluster;
102 uint16_t reservedSectorCount;
103 uint8_t numFATs;
104 uint16_t rootEntryCount;
105 uint16_t totalSectors16;
106 uint8_t media;
107 uint16_t FATSize16;
108 uint16_t sectorsPerTrack;
109 uint16_t numHeads;
110 uint32_t hiddenSectors;
111 uint32_t totalSectors32;
112 union {
113 fat16Descriptor_t fat16;
114 fat32Descriptor_t fat32;
115 } fatDescriptor;
116 } __attribute__((packed)) fatVolumeID_t;
118 typedef struct fatDirectoryEntry_t {
119 char filename[FAT_FILENAME_LENGTH];
120 uint8_t attrib;
121 uint8_t ntReserved;
122 uint8_t creationTimeTenths;
123 uint16_t creationTime;
124 uint16_t creationDate;
125 uint16_t lastAccessDate;
126 uint16_t firstClusterHigh;
127 uint16_t lastWriteTime;
128 uint16_t lastWriteDate;
129 uint16_t firstClusterLow;
130 uint32_t fileSize;
131 } __attribute__((packed)) fatDirectoryEntry_t;
133 uint32_t fat32_decodeClusterNumber(uint32_t clusterNumber);
135 bool fat32_isEndOfChainMarker(uint32_t clusterNumber);
136 bool fat16_isEndOfChainMarker(uint16_t clusterNumber);
138 bool fat_isFreeSpace(uint32_t clusterNumber);
140 bool fat_isDirectoryEntryTerminator(fatDirectoryEntry_t *entry);
141 bool fat_isDirectoryEntryEmpty(fatDirectoryEntry_t *entry);
143 void fat_convertFilenameToFATStyle(const char *filename, uint8_t *fatFilename);