mirror of
https://github.com/rvtr/TDT.git
synced 2025-10-31 13:51:07 -04:00
Better NAND written check
Previously it'd break if you missed anywhere
This commit is contained in:
parent
0d957e476a
commit
ee8da6519d
@ -391,8 +391,6 @@ bool install(char* fpath, bool systemTitle)
|
||||
|
||||
sprintf(dirPath, "nand:/title/%08x/%08x", (unsigned int)h->tid_high, (unsigned int)h->tid_low);
|
||||
|
||||
nandWritten = true;
|
||||
|
||||
//check if title is free
|
||||
if (_titleIsUsed(h))
|
||||
{
|
||||
|
||||
@ -306,7 +306,6 @@ static bool delete(Menu* m)
|
||||
{
|
||||
if (remove(fpath) == 0)
|
||||
{
|
||||
nandWritten = true;
|
||||
result = true;
|
||||
messageBox("\x1B[42mFile deleted.\x1B[47m");
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#define VERSION "0.7.1"
|
||||
|
||||
bool programEnd = false;
|
||||
bool nandWritten = false;
|
||||
|
||||
PrintConsole topScreen;
|
||||
PrintConsole bottomScreen;
|
||||
@ -156,10 +155,8 @@ int main(int argc, char **argv)
|
||||
clearScreen(&bottomScreen);
|
||||
printf("Unmounting NAND...\n");
|
||||
fatUnmount("nand:");
|
||||
if(nandWritten) {
|
||||
printf("Merging stages...\n");
|
||||
nandio_shutdown();
|
||||
}
|
||||
printf("Merging stages...\n");
|
||||
nandio_shutdown();
|
||||
|
||||
fifoSendValue32(FIFO_USER_02, 0x54495845); // 'EXIT'
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern bool programEnd;
|
||||
extern bool nandWritten;
|
||||
|
||||
void installMenu();
|
||||
void titleMenu();
|
||||
|
||||
@ -33,6 +33,8 @@ const DISC_INTERFACE io_dsi_nand = {
|
||||
|
||||
bool is3DS;
|
||||
|
||||
static bool nandWritten = false;
|
||||
|
||||
extern bool nand_Startup();
|
||||
|
||||
static u8* crypt_buf = 0;
|
||||
@ -167,6 +169,8 @@ bool nandio_read_sectors(sec_t offset, sec_t len, void *buffer)
|
||||
|
||||
bool nandio_write_sectors(sec_t offset, sec_t len, const void *buffer)
|
||||
{
|
||||
nandWritten = true;
|
||||
|
||||
while (len >= CRYPT_BUF_LEN)
|
||||
{
|
||||
if (!write_sectors(offset, CRYPT_BUF_LEN, buffer))
|
||||
@ -193,33 +197,37 @@ bool nandio_clear_status()
|
||||
|
||||
bool nandio_shutdown()
|
||||
{
|
||||
// at cleanup we synchronize the FAT statgings
|
||||
// A FatFS might have multiple copies of the FAT.
|
||||
// we will get them back synchonized as we just worked on the first copy
|
||||
// this allows us to revert changes in the FAT if we did not properly finish
|
||||
// and did not push the changes to the other copies
|
||||
// to do this we read the first partition sector
|
||||
nandio_read_sectors(fat_sig_fix_offset, 1, sector_buf) ;
|
||||
u8 stagingLevels = sector_buf[0x10] ;
|
||||
u8 reservedSectors = sector_buf[0x0E] ;
|
||||
u16 sectorsPerFatCopy = sector_buf[0x16] | ((u16)sector_buf[0x17] << 8) ;
|
||||
/*
|
||||
iprintf("[i] Staging for %i FAT copies\n",stagingLevels);
|
||||
iprintf("[i] Stages starting at %i\n",reservedSectors);
|
||||
iprintf("[i] %i sectors per stage\n",sectorsPerFatCopy);
|
||||
*/
|
||||
if (stagingLevels > 1)
|
||||
{
|
||||
for (u32 sector = 0;sector < sectorsPerFatCopy; sector++)
|
||||
if(nandWritten) {
|
||||
|
||||
// at cleanup we synchronize the FAT statgings
|
||||
// A FatFS might have multiple copies of the FAT.
|
||||
// we will get them back synchonized as we just worked on the first copy
|
||||
// this allows us to revert changes in the FAT if we did not properly finish
|
||||
// and did not push the changes to the other copies
|
||||
// to do this we read the first partition sector
|
||||
nandio_read_sectors(fat_sig_fix_offset, 1, sector_buf) ;
|
||||
u8 stagingLevels = sector_buf[0x10] ;
|
||||
u8 reservedSectors = sector_buf[0x0E] ;
|
||||
u16 sectorsPerFatCopy = sector_buf[0x16] | ((u16)sector_buf[0x17] << 8) ;
|
||||
/*
|
||||
iprintf("[i] Staging for %i FAT copies\n",stagingLevels);
|
||||
iprintf("[i] Stages starting at %i\n",reservedSectors);
|
||||
iprintf("[i] %i sectors per stage\n",sectorsPerFatCopy);
|
||||
*/
|
||||
if (stagingLevels > 1)
|
||||
{
|
||||
// read fat sector
|
||||
nandio_read_sectors(fat_sig_fix_offset + reservedSectors + sector, 1, sector_buf) ;
|
||||
// write to each copy, except the source copy
|
||||
for (int stage = 1;stage < stagingLevels;stage++)
|
||||
for (u32 sector = 0;sector < sectorsPerFatCopy; sector++)
|
||||
{
|
||||
nandio_write_sectors(fat_sig_fix_offset + reservedSectors + sector + (stage *sectorsPerFatCopy), 1, sector_buf) ;
|
||||
// read fat sector
|
||||
nandio_read_sectors(fat_sig_fix_offset + reservedSectors + sector, 1, sector_buf) ;
|
||||
// write to each copy, except the source copy
|
||||
for (int stage = 1;stage < stagingLevels;stage++)
|
||||
{
|
||||
nandio_write_sectors(fat_sig_fix_offset + reservedSectors + sector + (stage *sectorsPerFatCopy), 1, sector_buf) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
nandWritten = false;
|
||||
}
|
||||
free(crypt_buf);
|
||||
crypt_buf = 0;
|
||||
|
||||
@ -83,9 +83,6 @@ int copyFile(char const* src, char const* dst)
|
||||
{
|
||||
if (!src) return 1;
|
||||
|
||||
if(strncmp(dst, "nand:", 5) == 0)
|
||||
nandWritten = true;
|
||||
|
||||
unsigned long long size = getFileSizePath(src);
|
||||
return copyFilePart(src, 0, size, dst);
|
||||
}
|
||||
@ -95,9 +92,6 @@ int copyFilePart(char const* src, u32 offset, u32 size, char const* dst)
|
||||
if (!src) return 1;
|
||||
if (!dst) return 2;
|
||||
|
||||
if(strncmp(dst, "nand:", 5) == 0)
|
||||
nandWritten = true;
|
||||
|
||||
FILE* fin = fopen(src, "rb");
|
||||
|
||||
if (!fin)
|
||||
@ -185,9 +179,6 @@ bool padFile(char const* path, int size)
|
||||
{
|
||||
if (!path) return false;
|
||||
|
||||
if(strncmp(path, "nand:", 5) == 0)
|
||||
nandWritten = true;
|
||||
|
||||
FILE* f = fopen(path, "ab");
|
||||
if (!f)
|
||||
{
|
||||
@ -221,9 +212,6 @@ bool copyDir(char const* src, char const* dst)
|
||||
{
|
||||
if (!src || !dst) return false;
|
||||
|
||||
if(strncmp(dst, "nand:", 5) == 0)
|
||||
nandWritten = true;
|
||||
|
||||
// iprintf("copyDir\n%s\n%s\n\n", src, dst);
|
||||
|
||||
bool result = true;
|
||||
@ -321,9 +309,6 @@ bool deleteDir(char const* path)
|
||||
{
|
||||
if (!path) return false;
|
||||
|
||||
if(strncmp(path, "nand:", 5) == 0)
|
||||
nandWritten = true;
|
||||
|
||||
if (strcmp("/", path) == 0)
|
||||
{
|
||||
//oh fuck no
|
||||
|
||||
Loading…
Reference in New Issue
Block a user