mirror of
https://github.com/Scandal-UK/Incognito_RCM.git
synced 2024-11-08 13:11:52 +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;
|
u32 sectorsToRead = SECTORS_IN_CLUSTER - clusterOffset;
|
||||||
if (disk_read_prod(tmp + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorsToRead, enc) != RES_OK)
|
if (disk_read_prod(tmp + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorsToRead, enc) != RES_OK)
|
||||||
{
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
sector += sectorsToRead;
|
sector += sectorsToRead;
|
||||||
sectorCount -= sectorsToRead;
|
sectorCount -= sectorsToRead;
|
||||||
clusterOffset = 0;
|
clusterOffset = 0;
|
||||||
sectorOffset += sectorsToRead;
|
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)
|
if (disk_read_prod(tmp + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK)
|
||||||
{
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(buffer, tmp + newOffset, length);
|
memcpy(buffer, tmp + newOffset, length);
|
||||||
done:
|
done:
|
||||||
|
@ -442,27 +441,32 @@ bool writeData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
||||||
u32 newOffset = (offset % NX_EMMC_BLOCKSIZE);
|
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 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;
|
u32 bytesToRead;
|
||||||
if(length > NX_EMMC_BLOCKSIZE){
|
if (length > NX_EMMC_BLOCKSIZE)
|
||||||
|
{
|
||||||
bytesToRead = NX_EMMC_BLOCKSIZE - newOffset;
|
bytesToRead = NX_EMMC_BLOCKSIZE - newOffset;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bytesToRead = length - newOffset;
|
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;
|
goto out;
|
||||||
}
|
|
||||||
memcpy(tmp_sec + newOffset, buffer, bytesToRead);
|
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;
|
goto out;
|
||||||
}
|
|
||||||
sector++;
|
sector++;
|
||||||
length -= bytesToRead;
|
length -= bytesToRead;
|
||||||
newOffset = bytesToRead;
|
newOffset = bytesToRead;
|
||||||
|
|
||||||
// are we done?
|
// are we done?
|
||||||
if(length == 0) goto done;
|
if (length == 0)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write whole sectors in chunks while being cluster aligned
|
// 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)
|
while (clusterOffset + sectorCount > SECTORS_IN_CLUSTER)
|
||||||
{
|
{
|
||||||
u32 sectorsToRead = SECTORS_IN_CLUSTER - clusterOffset;
|
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;
|
goto out;
|
||||||
}
|
|
||||||
sector += sectorsToRead;
|
sector += sectorsToRead;
|
||||||
sectorOffset += sectorsToRead;
|
sectorOffset += sectorsToRead;
|
||||||
sectorCount -= sectorsToRead;
|
sectorCount -= sectorsToRead;
|
||||||
|
@ -485,29 +489,30 @@ bool writeData(u8 *buffer, u32 offset, u32 length, u8 enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write remaining sectors
|
// write remaining sectors
|
||||||
if(sectorCount > 0){
|
if (sectorCount > 0)
|
||||||
if(disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK){
|
{
|
||||||
|
if (disk_write_prod(buffer + newOffset + (sectorOffset * NX_EMMC_BLOCKSIZE), sector, sectorCount, enc) != RES_OK)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
length -= sectorCount * NX_EMMC_BLOCKSIZE;
|
length -= sectorCount * NX_EMMC_BLOCKSIZE;
|
||||||
sector += sectorCount;
|
sector += sectorCount;
|
||||||
sectorOffset += 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 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 == 0)
|
||||||
if(length >= NX_EMMC_BLOCKSIZE){
|
goto done;
|
||||||
|
if (length >= NX_EMMC_BLOCKSIZE)
|
||||||
|
{
|
||||||
gfx_printf("\n%kERROR, ERROR!! remaining length: %d\n", COLOR_RED, length);
|
gfx_printf("\n%kERROR, ERROR!! remaining length: %d\n", COLOR_RED, length);
|
||||||
goto out;
|
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;
|
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:
|
done:
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -516,7 +521,6 @@ out:
|
||||||
free(tmp);
|
free(tmp);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
||||||
// u32 sector = (offset / NX_EMMC_BLOCKSIZE);
|
// u32 sector = (offset / NX_EMMC_BLOCKSIZE);
|
||||||
// u32 newOffset = (offset % NX_EMMC_BLOCKSIZE);
|
// u32 newOffset = (offset % NX_EMMC_BLOCKSIZE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue