mirror of
https://github.com/Scandal-UK/Incognito_RCM.git
synced 2024-11-22 20:06:42 +00:00
formatting
This commit is contained in:
parent
ed43620605
commit
141a6f390c
1 changed files with 37 additions and 33 deletions
|
@ -408,20 +408,19 @@ bool readData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
|||
{
|
||||
u32 sectorsToRead = SECTORS_IN_CLUSTER - clusterOffset;
|
||||
if (disk_read_prod(tmp + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorsToRead, enc) != RES_OK)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
sector += sectorsToRead;
|
||||
sectorCount -= sectorsToRead;
|
||||
clusterOffset = 0;
|
||||
sectorOffset += sectorsToRead;
|
||||
}
|
||||
if(sectorCount == 0) goto done;
|
||||
if (sectorCount == 0)
|
||||
goto done;
|
||||
|
||||
if (disk_read_prod(tmp + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
memcpy(buffer, tmp + newOffset, length);
|
||||
done:
|
||||
|
@ -442,27 +441,32 @@ bool writeData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
|||
u32 newOffset = (offset % NX_EMMC_BLOCKSIZE);
|
||||
|
||||
// if there is a sector offset, read involved sector, write data to it with offset and write back whole sector to be sector aligned
|
||||
if(newOffset > 0){
|
||||
if (newOffset > 0)
|
||||
{
|
||||
|
||||
u32 bytesToRead;
|
||||
if(length > NX_EMMC_BLOCKSIZE){
|
||||
if (length > NX_EMMC_BLOCKSIZE)
|
||||
{
|
||||
bytesToRead = NX_EMMC_BLOCKSIZE - newOffset;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesToRead = length - newOffset;
|
||||
}
|
||||
if(disk_read_prod(tmp_sec, sector, 1, enc) != RES_OK){
|
||||
if (disk_read_prod(tmp_sec, sector, 1, enc) != RES_OK)
|
||||
goto out;
|
||||
}
|
||||
|
||||
memcpy(tmp_sec + newOffset, buffer, bytesToRead);
|
||||
if(disk_write_prod(tmp_sec, sector, 1, enc) != RES_OK){
|
||||
if (disk_write_prod(tmp_sec, sector, 1, enc) != RES_OK)
|
||||
goto out;
|
||||
}
|
||||
|
||||
sector++;
|
||||
length -= bytesToRead;
|
||||
newOffset = bytesToRead;
|
||||
|
||||
// are we done?
|
||||
if(length == 0) goto done;
|
||||
if (length == 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
// write whole sectors in chunks while being cluster aligned
|
||||
|
@ -474,9 +478,9 @@ bool writeData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
|||
while (clusterOffset + sectorCount > SECTORS_IN_CLUSTER)
|
||||
{
|
||||
u32 sectorsToRead = SECTORS_IN_CLUSTER - clusterOffset;
|
||||
if(disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorsToRead, enc) != RES_OK){
|
||||
if (disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorsToRead, enc) != RES_OK)
|
||||
goto out;
|
||||
}
|
||||
|
||||
sector += sectorsToRead;
|
||||
sectorOffset += sectorsToRead;
|
||||
sectorCount -= sectorsToRead;
|
||||
|
@ -485,29 +489,30 @@ bool writeData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
|||
}
|
||||
|
||||
// write remaining sectors
|
||||
if(sectorCount > 0){
|
||||
if(disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK){
|
||||
if (sectorCount > 0)
|
||||
{
|
||||
if (disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK)
|
||||
goto out;
|
||||
}
|
||||
|
||||
length -= sectorCount * NX_EMMC_BLOCKSIZE;
|
||||
sector += sectorCount;
|
||||
sectorOffset += sectorCount;
|
||||
}
|
||||
|
||||
// if there is data remaining that is smaller than a sector, read that sector, write remaining data to it and write back whole sector
|
||||
if(length == 0) goto done;
|
||||
if(length >= NX_EMMC_BLOCKSIZE){
|
||||
if (length == 0)
|
||||
goto done;
|
||||
if (length >= NX_EMMC_BLOCKSIZE)
|
||||
{
|
||||
gfx_printf("\n%kERROR, ERROR!! remaining length: %d\n", COLOR_RED, length);
|
||||
goto out;
|
||||
}
|
||||
if(disk_read_prod(tmp_sec, sector, 1, enc) != RES_OK){
|
||||
if (disk_read_prod(tmp_sec, sector, 1, enc) != RES_OK)
|
||||
goto out;
|
||||
}
|
||||
memcpy(tmp, buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), length);
|
||||
if(disk_write_prod(tmp_sec, sector, 1, enc) != RES_OK){
|
||||
goto out;
|
||||
}
|
||||
|
||||
memcpy(tmp, buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), length);
|
||||
if (disk_write_prod(tmp_sec, sector, 1, enc) != RES_OK)
|
||||
goto out;
|
||||
|
||||
done:
|
||||
result = true;
|
||||
|
@ -516,7 +521,6 @@ out:
|
|||
free(tmp);
|
||||
return result;
|
||||
|
||||
|
||||
// u32 sector = (offset / NX_EMMC_BLOCKSIZE);
|
||||
// u32 newOffset = (offset % NX_EMMC_BLOCKSIZE);
|
||||
|
||||
|
|
Loading…
Reference in a new issue