Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on DeviceBlockInfo_FindRegionFromAddress #357

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/PAL/BlockStorage/nanoPAL_BlockStorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,35 @@ __nfweak SectorAddress DeviceBlockInfo_PhysicalToSectorAddress(DeviceBlockInfo*
return phyAddress;
}

__nfweak bool DeviceBlockInfo_FindRegionFromAddress(DeviceBlockInfo* blockInfo, ByteAddress address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
bool DeviceBlockInfo_FindRegionFromAddress(DeviceBlockInfo* blockInfo, ByteAddress address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
{
return false;
const BlockRegionInfo *pRegion;

*blockRegionIndex = 0;

for(uint32_t i = 0; i < blockInfo->NumRegions; i++)
{
pRegion = &blockInfo->Regions[i];

if(pRegion->Start <= address && address < (pRegion->Start + pRegion->NumBlocks * pRegion->BytesPerBlock))
{
uint32_t endRangeAddr = pRegion->Start + pRegion->BytesPerBlock * pRegion->BlockRanges[0].StartBlock;

for(uint32_t j =0; j < pRegion->NumBlockRanges; j++)
{
endRangeAddr += pRegion->BytesPerBlock * BlockRange_GetBlockCount(pRegion->BlockRanges[j]);

if(address < endRangeAddr)
{
*blockRegionIndex = i;
*blockRangeIndex = j;
return true;
}
}
}
}

return false;
}

__nfweak bool DeviceBlockInfo_FindNextUsageBlock(DeviceBlockInfo* blockInfo, unsigned int blockUsage, unsigned int* address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
Expand Down