Skip to content

Instantly share code, notes, and snippets.

@rw-r-r-0644
Created March 31, 2021 00:05
Show Gist options
  • Save rw-r-r-0644/4dc6f83ee94dc8f0b5054292da8cd188 to your computer and use it in GitHub Desktop.
Save rw-r-r-0644/4dc6f83ee94dc8f0b5054292da8cd188 to your computer and use it in GitHub Desktop.
int ISFS_Setup(ISFS *this,int init)
{
if (init == 0)
return 0;
super = ISFS_LoadSuperblock(this);
if (!super)
return -0x8046F;
int rc = ISFS_ProcessSuperblock(this,super,0,3,0);
if (rc != 0)
return rc;
uint32_t nandClusters = this->nandSizeBytes >> 0xe;
uint32_t superblockSize = (1 << this->metadataSizeLog2 - this->superblockCountLog2);
uint32_t fstEntryCount = (superblockSize - (nandClusters * sizeof(u16)) - 0xc) / sizeof(FST_Entry);
for (uint32_t i = 1; i < fstEntryCount; i++)
if (super->fst[i].mode & 3)
super->fst[i].size &= 0x7fffffff;
for (uint32_t i = 0; i < nandClusters; i++)
if (super->fat[i] == 0xffff)
super->fat[i] = 0xfffe;
for (int i = 0; i < 0x10; i++)
this->structunk2[i].valid = 0;
this->field_0x48d68 = 0xfffd;
this->field_0x48d6a = 0xfffd;
return ISFS_ProcessSuperblockUsage(this, super);
}
int ISFS_ProcessSuperblockUsage(ISFS *this,ISFS_Superblock *super)
{
this->clusterSize = 0x4000;
isfs->numClustersEmpty = 0;
isfs->numClustersUsed = 0;
isfs->numClustersBad = 0;
isfs->numClustersReserved = 0;
this->numFSTEmpty = 0;
this->numFSTUsed = 0;
uint32_t dataClustersStart = this->fsOffset >> 0xe;
uint32_t dataClustersEnd = dataClustersStart + (this->dataAreaSize >> 0xe);
for (uint32_t i = dataClustersStart; i < dataClustersEnd; i++)
{
if (super->fat[i] >= 0xfffe)
this->numClustersEmpty++;
else if (super->fat[i] < 0xfffc)
this->numClustersUsed++;
else if (super->fat[i] == 0xfffd)
this->numClustersBad++;
else if (super->fat[i] == 0xfffc)
this->numClustersReserved++;
}
uint32_t nandClusters = this->nandSizeBytes >> 0xe;
uint32_t superblockSize = (1 << this->metadataSizeLog2 - this->superblockCountLog2);
uint32_t fstEntryCount = (superblockSize - (nandClusters * sizeof(u16)) - 0xc) / sizeof(FST_Entry);
for (uint32_t i = 0; i < fstEntryCount; i++)
{
if ((super->fst[i].mode & 3) == 0)
this->numFSTEmpty++;
else
this->numFSTUsed++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment