Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / io / asyncfatfs / fat_standard.c
blob382d03bf50f5a0796e827579b24cc58354e6e472
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 #include "common/string_light.h"
20 #include "fat_standard.h"
22 bool fat16_isEndOfChainMarker(uint16_t clusterNumber)
24 return clusterNumber >= 0xFFF8;
27 // Pass the cluster number after fat32_decodeClusterNumber().
28 bool fat32_isEndOfChainMarker(uint32_t clusterNumber)
30 return clusterNumber >= 0x0FFFFFF8;
33 /**
34 * FAT32 cluster numbers are really only 28 bits, and the top 4 bits must be left alone and not treated as part of the
35 * cluster number (so various FAT drivers can use those bits for their own purposes, or they can be used in later
36 * extensions)
38 uint32_t fat32_decodeClusterNumber(uint32_t clusterNumber)
40 return clusterNumber & 0x0FFFFFFF;
43 // fat32 needs fat32_decodeClusterNumber() applied first.
44 bool fat_isFreeSpace(uint32_t clusterNumber)
46 return clusterNumber == 0;
49 bool fat_isDirectoryEntryTerminator(fatDirectoryEntry_t *entry)
51 return entry->filename[0] == 0x00;
54 bool fat_isDirectoryEntryEmpty(fatDirectoryEntry_t *entry)
56 return (unsigned char) entry->filename[0] == FAT_DELETED_FILE_MARKER;
59 /**
60 * Convert the given "prefix.ext" style filename to the FAT format to be stored on disk.
62 * fatFilename must point to a buffer which is FAT_FILENAME_LENGTH bytes long. The buffer is not null-terminated.
64 void fat_convertFilenameToFATStyle(const char *filename, uint8_t *fatFilename)
66 for (int i = 0; i < 8; i++) {
67 if (*filename == '\0' || *filename == '.') {
68 *fatFilename = ' ';
69 } else {
70 *fatFilename = sl_toupper((unsigned char)*filename);
71 filename++;
73 fatFilename++;
76 if (*filename == '.') {
77 filename++;
80 for (int i = 0; i < 3; i++) {
81 if (*filename == '\0') {
82 *fatFilename = ' ';
83 } else {
84 *fatFilename = sl_toupper((unsigned char)*filename);
85 filename++;
87 fatFilename++;