Add RANGEFINDER and OPTICALFLOW MT build option (#14042)
[betaflight.git] / src / main / io / asyncfatfs / fat_standard.c
blobfebca5ef7e4b66bc20a5e40fae0e5dd43b324728
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 #include <ctype.h>
23 #include "platform.h"
25 #include "fat_standard.h"
27 bool fat16_isEndOfChainMarker(uint16_t clusterNumber)
29 return clusterNumber >= 0xFFF8;
32 // Pass the cluster number after fat32_decodeClusterNumber().
33 bool fat32_isEndOfChainMarker(uint32_t clusterNumber)
35 return clusterNumber >= 0x0FFFFFF8;
38 /**
39 * FAT32 cluster numbers are really only 28 bits, and the top 4 bits must be left alone and not treated as part of the
40 * cluster number (so various FAT drivers can use those bits for their own purposes, or they can be used in later
41 * extensions)
43 uint32_t fat32_decodeClusterNumber(uint32_t clusterNumber)
45 return clusterNumber & 0x0FFFFFFF;
48 // fat32 needs fat32_decodeClusterNumber() applied first.
49 bool fat_isFreeSpace(uint32_t clusterNumber)
51 return clusterNumber == 0;
54 bool fat_isDirectoryEntryTerminator(fatDirectoryEntry_t *entry)
56 return entry->filename[0] == 0x00;
59 bool fat_isDirectoryEntryEmpty(fatDirectoryEntry_t *entry)
61 return (unsigned char) entry->filename[0] == FAT_DELETED_FILE_MARKER;
64 /**
65 * Convert the given "prefix.ext" style filename to the FAT format to be stored on disk.
67 * fatFilename must point to a buffer which is FAT_FILENAME_LENGTH bytes long. The buffer is not null-terminated.
69 void fat_convertFilenameToFATStyle(const char *filename, uint8_t *fatFilename)
71 for (int i = 0; i < 8; i++) {
72 if (*filename == '\0' || *filename == '.') {
73 *fatFilename = ' ';
74 } else {
75 *fatFilename = toupper((unsigned char)*filename);
76 filename++;
78 fatFilename++;
81 if (*filename == '.') {
82 filename++;
85 for (int i = 0; i < 3; i++) {
86 if (*filename == '\0') {
87 *fatFilename = ' ';
88 } else {
89 *fatFilename = toupper((unsigned char)*filename);
90 filename++;
92 fatFilename++;