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