2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
29#include "../hw/evmu_flash.h"
31#include <gimbal/utils/gimbal_date_time.h>
34
35
36
37
38
39
42
43
44
45#define EVMU_FAT_TYPE (GBL_TYPEID
(EvmuFat))
46#define EVMU_FAT(self) (GBL_CAST(EvmuFat, self))
51#define EVMU_FAT_NAME "fat"
52#define EVMU_FAT_GAME_VMS_HEADER_OFFSET 0x200
55
56
57
58#define EVMU_FAT_BLOCK_SIZE 512
59#define EVMU_FAT_BLOCK_COUNT_DEFAULT 256
60#define EVMU_FAT_BLOCK_ROOT 255
61#define EVMU_FAT_BLOCK_ROOT_SIZE 1
62#define EVMU_FAT_BLOCK_USERDATA_DEFAULT 0
63#define EVMU_FAT_BLOCK_USERDATA_SIZE_DEFAULT 200
64#define EVMU_FAT_BLOCK_EXTRA_DEFAULT 200
65#define EVMU_FAT_BLOCK_EXTRA_SIZE_DEFAULT 31
66#define EVMU_FAT_BLOCK_DIRECTORY_DEFAULT 253
67#define EVMU_FAT_BLOCK_DIRECTORY_SIZE_DEFAULT 13
68#define EVMU_FAT_BLOCK_DIRECTORY_ENTRIES_DEFAULT 200
69#define EVMU_FAT_BLOCK_FAT_DEFAULT 254
70#define EVMU_FAT_BLOCK_FAT_SIZE_DEFAULT 1
71#define EVMU_FAT_BLOCK_FAT_COUNT_DEFAULT 256
75
76
77
78#define EVMU_FAT_ROOT_BLOCK_FORMATTED_SIZE 16
79#define EVMU_FAT_ROOT_BLOCK_FORMATTED_BYTE 0x55
80#define EVMU_FAT_ROOT_BLOCK_VOLUME_LABEL_SIZE 32
81#define EVMU_FAT_ROOT_BLOCK_ICON_SHAPE_MAX 123
82#define EVMU_FAT_ROOT_BLOCK_RESERVED_SIZE 8
83#define EVMU_FAT_ROOT_BLOCK_RESERVED2_SIZE 8
87
88
89
90#define EVMU_FAT_BLOCK_FAT_UNALLOCATED 0xfffc
91#define EVMU_FAT_BLOCK_FAT_LAST_IN_FILE 0xfffa
92#define EVMU_FAT_BLOCK_FAT_DAMAGED 0xffff
95#define GBL_SELF_TYPE EvmuFat
99GBL_FORWARD_DECLARE_STRUCT(EvmuNewFileInfo);
100GBL_FORWARD_DECLARE_STRUCT(EvmuVms);
101GBL_FORWARD_DECLARE_STRUCT(EvmuFat);
107
108
109
110
111
112
113
114
115
116
117
118
119
178
179
180
181
182
183
184
185
186
187GBL_CLASS_DERIVE(EvmuFat, EvmuFlash)
188 EVMU_RESULT (*pFnInfo)(GBL_CSELF, EvmuFatInfo* pInfo);
189 EVMU_RESULT (*pFnRoot)(GBL_CSELF, EvmuRootBlock** ppRoot);
193
194
195
196
197
198
199
200
201
202
203
226
227
228
229
253
254
255
256
276 EVMU_FILE_TYPE type) GBL_NOEXCEPT;
280
281
282
283
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
#define EVMU_FAT_ROOT_BLOCK_FORMATTED_SIZE
Size in bytes of the format string in the EvmuRootBlock structure.
#define EVMU_FAT_ROOT_BLOCK_RESERVED2_SIZE
uint16_t EvmuBlock
FAT block index.
#define EVMU_FAT_ROOT_BLOCK_RESERVED_SIZE
Size in bytes of the first reserved field in the EvmuRootBlock structure.
GblType EvmuFat_type(void)
Returns the GblType UUID associated with EvmuFat.
#define EVMU_FAT_ROOT_BLOCK_VOLUME_LABEL_SIZE
Size in bytes of the volume label in the EvmuRootBlock structure.
#define GBL_PROPERTIES(object,...)
Peripheral providing 8-bit FAT API.
EVMU_RESULT EvmuFat_blockLink(const EvmuFat *pSelf, EvmuBlock b, EvmuBlock lnk)
Sets the given block to point to the linked block as its next entry in the file allocation table.
size_t EvmuFat_blockCount(const EvmuFat *pSelf)
Returns the total number of blocks in the filesystem.
void EvmuFat_dirEntryLog(const EvmuFat *pSelf, const EvmuDirEntry *pEntry)
Dumps information about a given directory to the libGimbal log for debugging.
void EvmuFat_log(const EvmuFat *pSelf)
Dumps detailed information about the entire filesystem to the libGimbal log for debugging.
EvmuBlock EvmuFat_blockNext(const EvmuFat *pSelf, EvmuBlock block)
Returns the next block pointed to by the given block in the file allocation table.
EvmuBlock EvmuFat_blockTable(const EvmuFat *pSelf)
Returns the block location of the file allocation table (FAT) region.
size_t EvmuFat_userBlocks(const EvmuFat *pSelf)
Returns the total number of blocks available to the user for storing files.
void EvmuFat_usage(const EvmuFat *pSelf, EvmuFatUsage *pUsage)
Queries the fat table for filesystem block usage information, populating the given EvmuFatUsage objec...
EvmuDirEntry * EvmuFat_dirEntryAlloc(const EvmuFat *pSelf, EVMU_FILE_TYPE fileType)
Allocates an entry within the directory for the given file type.
size_t EvmuFat_seqFreeBlocks(const EvmuFat *pSelf)
Returns the total number of sequential free blocks, starting at block 0 (used for GAME file allocatio...
size_t EvmuFat_dirEntryCount(const EvmuFat *pSelf)
Returns the total number of entries in the file system directory, including unused ones.
EVMU_RESULT EvmuFat_format(const EvmuFat *pSelf, const EvmuRootBlock *pRoot)
Formats the filesystem, erasing all files and resetting everything to defaults.
GblBool EvmuFat_isFormatted(const EvmuFat *pSelf)
Checks whether the given filesystem has the correct EvmuRootBlock::formatted field values.
size_t EvmuFat_dirEntryIndex(const EvmuFat *pSelf, const EvmuDirEntry *pEntry)
Returns the index into the directory for the given directory entry.
EVMU_RESULT EvmuFat_blockFree(const EvmuFat *pSelf, EvmuBlock block)
Frees the given block in the file allocation table.
EvmuBlock EvmuFat_blockAlloc(const EvmuFat *pSelf, EvmuBlock prev, EVMU_FILE_TYPE type)
Allocates a block in the file allocation table based on the given type, linking it to the previous bl...
size_t EvmuFat_toBlocks(const EvmuFat *pSelf, size_t bytes)
Converts the given number of bytes to the number of blocks required to hold them.
EVMU_RESULT EvmuFat_info(const EvmuFat *pSelf, EvmuFatInfo *pInfo)
Populates the given EvmuFatInfo structure with information on the volume.
EvmuBlock EvmuFat_blockDirectory(const EvmuFat *pSelf)
Returns the block location of the FAT directory region.
const void * EvmuFat_blockData(const EvmuFat *pSelf, EvmuBlock block)
Returns the actual raw data at the given block location.
EvmuDirEntry * EvmuFat_dirEntry(const EvmuFat *pSelf, size_t index)
Returns the directory entry at the given index (may be unused)
size_t EvmuFat_capacity(const EvmuFat *pSelf)
Returns the total capacity of the filesystem in bytes.
size_t EvmuFat_blockSize(const EvmuFat *pSelf)
Returns the size in bytes of a single block in the file system.
EvmuRootBlock * EvmuFat_root(const EvmuFat *pSelf)
Returns a pointer to the root block of the filesystem.
Matches maple attributes for describing storage medium.
uint8_t writes
Number of writes required to fetch whole block of data.
uint16_t blockSize
Number of bytes within a single block.
uint8_t crcCheck
1 if CRC calculation is required for read/writes, 0 otherwise
uint8_t partitions
Number of partitions on the device.
uint8_t reads
Number of reads required to fetch whole block of data.
uint8_t removable
1 if medium is a removable device, 0 if fixed
Struct used for querying current FAT block allocation status.
uint16_t blocksDamaged
Number of unusable, damaged blocks.
uint16_t blocksUsed
Total number of allocated blocks.
uint16_t blocksFree
Number of available blocks.
uint16_t blocksHidden
Number of unavailable, hidden system blocks.
Filesystem root FAT block.
uint8_t bytes[32]
Raw byte size of volume label (32 bytes, everything after vmu struct is unknown/unused)
uint16_t totalSize
Last indexable block in partition (default: 255)
uint16_t dirSize
Size of Directory in blocks (default: 13)
uint16_t extraBlock
Location of Extra region (default: 200)
uint8_t reserved2[8]
Reserved or unused, all zeroes.
uint8_t sortFlag
Sort flag? (no fucking idea)
uint8_t g
Custom color green channel (0-255)
uint16_t rootBlock
Location of Root block (default: 255)
uint8_t r
Custom color red channel (0-255)
uint8_t customColor
1 if using color, 0 otherwise
uint16_t fatBlock
Location of FAT table (default: 254)
uint16_t fatSize
Size of FAT table in blocks (default: 1)
uint16_t extraSize
Size of Extra region in blocks (default: 41)
uint8_t reserved[8]
Reserved or unused, all zeroes.
uint8_t b
Custom color blue channel (0-255)
uint16_t dirBlock
Location of Directory (default: 253)
uint8_t a
Custom color alpha channel (0-255)
uint8_t iconShape
Icon type or shape (built into BIOS font: 0-123)
uint8_t formatted[16]
Set to 0x55 to signify formatted device.
uint16_t partition
Partition number (default: 0)
uint16_t gameBlock
Starting location for GAME file (default: 0)
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)