Add sd cluster size check

If a sd is present, and its cluster size is bigger than 32k, abort installing
This commit is contained in:
Edoardo Lolletti 2024-07-28 11:03:31 +02:00
parent f1d6f13ff2
commit 001442fd8a
3 changed files with 38 additions and 0 deletions

View File

@ -200,6 +200,13 @@ int main(int argc, char **argv)
messageBox("fatInitDefault()...\x1B[31mFailed\n\x1B[47m");
}
u32 clusterSize = getClusterSizeForPartition("sd:/");
if(clusterSize > 32768)
{
messageBox("Sd card cluster size is too large");
return 0;
}
//setup nand access
if (!fatMountSimple("nand", &io_dsi_nand))
{

View File

@ -226,3 +226,32 @@ bool removeIfExists(const char* path)
{
return remove(path) == 0 || errno == ENOENT;
}
// Filesystem type
typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE;
//trimmed down PARTITION struct from libfat internals
typedef struct {
const void* disc;
void* cache;
// Info about the partition
FS_TYPE filesysType;
uint64_t totalSize;
sec_t rootDirStart;
uint32_t rootDirCluster;
uint32_t numberOfSectors;
sec_t dataStart;
uint32_t bytesPerSector;
uint32_t sectorsPerCluster;
uint32_t bytesPerCluster;
uint32_t fsInfoSector;
} PARTITION;
extern PARTITION* _FAT_partition_getPartitionFromPath(const char* path);
u32 getClusterSizeForPartition(const char* path)
{
PARTITION* p = _FAT_partition_getPartitionFromPath(path);
if(!p)
return 0;
return p->bytesPerCluster;
}

View File

@ -25,6 +25,8 @@ bool safeCreateDir(const char* path);
//Files and directories
bool removeIfExists(const char* path);
u32 getClusterSizeForPartition(const char* path);
#ifdef __cplusplus
}
#endif