2023-04-20 16:25:05 +02:00
|
|
|
#include "fsctl/fugue/cluster.h"
|
|
|
|
#include "fsctl/fugue/sector.h"
|
|
|
|
#include "fsctl/fugue/utils.h"
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Public
|
|
|
|
//---
|
|
|
|
|
2023-04-21 12:49:06 +02:00
|
|
|
/* fugue_cluster_find_next() : find the next cluster address if available */
|
|
|
|
uintptr_t fugue_cluster_find_next(fugue_fs_t *fs, uint32_t cluster_idx)
|
|
|
|
{
|
|
|
|
(void)fs;
|
|
|
|
(void)cluster_idx;
|
|
|
|
return 0x00000000;
|
|
|
|
}
|
|
|
|
|
2023-04-20 16:25:05 +02:00
|
|
|
/* fugue_cluster_is_valid() : check cluster validity */
|
|
|
|
//TODO : support FAT12 / FAT32
|
|
|
|
int fugue_cluster_is_valid(fugue_fs_t *fs, int cluster_idx)
|
|
|
|
{
|
|
|
|
void *sector;
|
|
|
|
uint16_t id;
|
|
|
|
|
|
|
|
id = FAT_WORD(((uint16_t *)fs->_private.fat0)[cluster_idx]);
|
|
|
|
if (id == 0x0000)
|
|
|
|
return 0;
|
|
|
|
if (cluster_idx == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* special check for the root fake cluster */
|
|
|
|
if (cluster_idx == 1)
|
|
|
|
{
|
|
|
|
if (id != 0xffff)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster_idx -= 2;
|
|
|
|
sector = (void*)((uintptr_t)(fs->props.cluster_nb_sector * cluster_idx));
|
|
|
|
sector = (void*)((uintptr_t)sector + fs->props.sector_root_nb);
|
|
|
|
sector = (void*)((uintptr_t)sector * 512);
|
|
|
|
sector = (void*)((uintptr_t)sector + (uintptr_t)fs->_private.root);
|
|
|
|
|
|
|
|
for (int i = 0 ; i < fs->props.cluster_nb_sector ; i++)
|
|
|
|
{
|
|
|
|
if (fugue_sector_is_invalid(sector))
|
|
|
|
return -2;
|
|
|
|
sector = (void *)((uintptr_t)sector + 512);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|