mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Prevent a possible bug for alias drives
This commit is contained in:
parent
34b58e979a
commit
eac1591be3
45
source/fs.c
45
source/fs.c
@ -44,6 +44,7 @@ bool InitExtFS() {
|
|||||||
for (u32 i = 1; i < NORM_FS; i++) {
|
for (u32 i = 1; i < NORM_FS; i++) {
|
||||||
char fsname[8];
|
char fsname[8];
|
||||||
snprintf(fsname, 7, "%lu:", i);
|
snprintf(fsname, 7, "%lu:", i);
|
||||||
|
if (fs_mounted[i]) continue;
|
||||||
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
|
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
|
||||||
if ((i == 7) && !fs_mounted[7] && (GetMountState() == IMG_RAMDRV)) {
|
if ((i == 7) && !fs_mounted[7] && (GetMountState() == IMG_RAMDRV)) {
|
||||||
f_mkfs("7:", FM_ANY, 0, MAIN_BUFFER, MAIN_BUFFER_SIZE); // format ramdrive if required
|
f_mkfs("7:", FM_ANY, 0, MAIN_BUFFER, MAIN_BUFFER_SIZE); // format ramdrive if required
|
||||||
@ -345,7 +346,7 @@ bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset,
|
|||||||
return false;
|
return false;
|
||||||
f_lseek(&file, foffset);
|
f_lseek(&file, foffset);
|
||||||
fx_write(&file, data, size, &bytes_written);
|
fx_write(&file, data, size, &bytes_written);
|
||||||
f_close(&file);
|
fx_close(&file);
|
||||||
return (bytes_written == size);
|
return (bytes_written == size);
|
||||||
} else if (drvtype & DRV_VIRTUAL) {
|
} else if (drvtype & DRV_VIRTUAL) {
|
||||||
VirtualFile vfile;
|
VirtualFile vfile;
|
||||||
@ -365,10 +366,10 @@ size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset) {
|
|||||||
return 0;
|
return 0;
|
||||||
f_lseek(&file, foffset);
|
f_lseek(&file, foffset);
|
||||||
if (fx_read(&file, data, size, &bytes_read) != FR_OK) {
|
if (fx_read(&file, data, size, &bytes_read) != FR_OK) {
|
||||||
f_close(&file);
|
fx_close(&file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
f_close(&file);
|
fx_close(&file);
|
||||||
return bytes_read;
|
return bytes_read;
|
||||||
} else if (drvtype & DRV_VIRTUAL) {
|
} else if (drvtype & DRV_VIRTUAL) {
|
||||||
u32 bytes_read = 0;
|
u32 bytes_read = 0;
|
||||||
@ -435,7 +436,7 @@ bool FileGetSha256(const char* path, u8* sha256) {
|
|||||||
ret = false;
|
ret = false;
|
||||||
sha_update(MAIN_BUFFER, bytes_read);
|
sha_update(MAIN_BUFFER, bytes_read);
|
||||||
}
|
}
|
||||||
f_close(&file);
|
fx_close(&file);
|
||||||
}
|
}
|
||||||
ShowProgress(1, 1, path);
|
ShowProgress(1, 1, path);
|
||||||
sha_get(sha256);
|
sha_get(sha256);
|
||||||
@ -511,14 +512,14 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
|
|||||||
if (DriveType(orig) & DRV_VIRTUAL) {
|
if (DriveType(orig) & DRV_VIRTUAL) {
|
||||||
vorig = true;
|
vorig = true;
|
||||||
if (!GetVirtualFile(&ovfile, orig)) {
|
if (!GetVirtualFile(&ovfile, orig)) {
|
||||||
if (!vdest) f_close(&dfile);
|
if (!vdest) fx_close(&dfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
osize = ovfile.size;
|
osize = ovfile.size;
|
||||||
} else {
|
} else {
|
||||||
vorig = false;
|
vorig = false;
|
||||||
if (fx_open(&ofile, orig, FA_READ | FA_OPEN_EXISTING) != FR_OK) {
|
if (fx_open(&ofile, orig, FA_READ | FA_OPEN_EXISTING) != FR_OK) {
|
||||||
if (!vdest) f_close(&dfile);
|
if (!vdest) fx_close(&dfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
osize = f_size(&ofile);
|
osize = f_size(&ofile);
|
||||||
@ -529,8 +530,8 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
|
|||||||
// check file limits
|
// check file limits
|
||||||
if (offset + osize > dsize) {
|
if (offset + osize > dsize) {
|
||||||
ShowPrompt(false, "Operation would write beyond end of file");
|
ShowPrompt(false, "Operation would write beyond end of file");
|
||||||
if (!vdest) f_close(&dfile);
|
if (!vdest) fx_close(&dfile);
|
||||||
if (!vorig) f_close(&ofile);
|
if (!vorig) fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,8 +554,8 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
|
|||||||
}
|
}
|
||||||
ShowProgress(1, 1, orig);
|
ShowProgress(1, 1, orig);
|
||||||
|
|
||||||
if (!vdest) f_close(&dfile);
|
if (!vdest) fx_close(&dfile);
|
||||||
if (!vorig) f_close(&ofile);
|
if (!vorig) fx_close(&ofile);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -622,11 +623,11 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
if (!GetVirtualFile(&dvfile, dest)) {
|
if (!GetVirtualFile(&dvfile, dest)) {
|
||||||
VirtualDir vdir;
|
VirtualDir vdir;
|
||||||
if (!GetVirtualDir(&vdir, destdir)) {
|
if (!GetVirtualDir(&vdir, destdir)) {
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
} else while (true) {
|
} else while (true) {
|
||||||
if (!ReadVirtualDir(&dvfile, &vdir)) {
|
if (!ReadVirtualDir(&dvfile, &vdir)) {
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (dvfile.size == osize) // search by size should be a last resort solution
|
if (dvfile.size == osize) // search by size should be a last resort solution
|
||||||
@ -634,7 +635,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
}
|
}
|
||||||
snprintf(dest, 255, "%s/%s", destdir, dvfile.name);
|
snprintf(dest, 255, "%s/%s", destdir, dvfile.name);
|
||||||
if (!ShowPrompt(true, "Entry not found: %s\nInject into %s instead?", deststr, dest)) {
|
if (!ShowPrompt(true, "Entry not found: %s\nInject into %s instead?", deststr, dest)) {
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TruncateString(deststr, dest, 36, 8);
|
TruncateString(deststr, dest, 36, 8);
|
||||||
@ -646,12 +647,12 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
FormatBytes(dsizestr, dvfile.size);
|
FormatBytes(dsizestr, dvfile.size);
|
||||||
if (dvfile.size > osize) {
|
if (dvfile.size > osize) {
|
||||||
if (!ShowPrompt(true, "File smaller than available space:\n%s (%s)\n%s (%s)\nContinue?", origstr, osizestr, deststr, dsizestr)) {
|
if (!ShowPrompt(true, "File smaller than available space:\n%s (%s)\n%s (%s)\nContinue?", origstr, osizestr, deststr, dsizestr)) {
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ShowPrompt(false, "File bigger than available space:\n%s (%s)\n%s (%s)", origstr, osizestr, deststr, dsizestr);
|
ShowPrompt(false, "File bigger than available space:\n%s (%s)\n%s (%s)", origstr, osizestr, deststr, dsizestr);
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -668,7 +669,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
ShowProgress(1, 1, orig);
|
ShowProgress(1, 1, orig);
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
InitExtFS();
|
InitExtFS();
|
||||||
} else if (odrvtype & DRV_VIRTUAL) { // virtual to any file system
|
} else if (odrvtype & DRV_VIRTUAL) { // virtual to any file system
|
||||||
VirtualFile ovfile;
|
VirtualFile ovfile;
|
||||||
@ -716,7 +717,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
osize = ovfile.size;
|
osize = ovfile.size;
|
||||||
if (GetFreeSpace(dest) < osize) {
|
if (GetFreeSpace(dest) < osize) {
|
||||||
ShowPrompt(false, "Error: File is too big for destination");
|
ShowPrompt(false, "Error: File is too big for destination");
|
||||||
f_close(&dfile);
|
fx_close(&dfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,7 +735,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig, u32* flags) {
|
|||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
ShowProgress(1, 1, orig);
|
ShowProgress(1, 1, orig);
|
||||||
f_close(&dfile);
|
fx_close(&dfile);
|
||||||
if (!ret) f_unlink(dest);
|
if (!ret) f_unlink(dest);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -856,13 +857,13 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) {
|
|||||||
fsize = f_size(&ofile);
|
fsize = f_size(&ofile);
|
||||||
if (GetFreeSpace(dest) < fsize) {
|
if (GetFreeSpace(dest) < fsize) {
|
||||||
ShowPrompt(false, "Error: File is too big for destination");
|
ShowPrompt(false, "Error: File is too big for destination");
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fx_open(&dfile, dest, FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
|
if (fx_open(&dfile, dest, FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
|
||||||
ShowPrompt(false, "Error: Cannot create destination file");
|
ShowPrompt(false, "Error: Cannot create destination file");
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,8 +887,8 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) {
|
|||||||
}
|
}
|
||||||
ShowProgress(1, 1, orig);
|
ShowProgress(1, 1, orig);
|
||||||
|
|
||||||
f_close(&ofile);
|
fx_close(&ofile);
|
||||||
f_close(&dfile);
|
fx_close(&dfile);
|
||||||
if (!ret) f_unlink(dest);
|
if (!ret) f_unlink(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +112,12 @@ FRESULT fx_write (FIL* fp, const void* buff, UINT btw, UINT* bw) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRESULT fx_close (FIL* fp) {
|
||||||
|
FilCryptInfo* info = fx_find_cryptinfo(fp);
|
||||||
|
if (info) memset(info, 0, sizeof(FilCryptInfo));
|
||||||
|
return f_close(fp);
|
||||||
|
}
|
||||||
|
|
||||||
FRESULT fa_open (FIL* fp, const TCHAR* path, BYTE mode) {
|
FRESULT fa_open (FIL* fp, const TCHAR* path, BYTE mode) {
|
||||||
TCHAR alias[256];
|
TCHAR alias[256];
|
||||||
dealias_path(alias, path);
|
dealias_path(alias, path);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
FRESULT fx_open (FIL* fp, const TCHAR* path, BYTE mode);
|
FRESULT fx_open (FIL* fp, const TCHAR* path, BYTE mode);
|
||||||
FRESULT fx_read (FIL* fp, void* buff, UINT btr, UINT* br);
|
FRESULT fx_read (FIL* fp, void* buff, UINT btr, UINT* br);
|
||||||
FRESULT fx_write (FIL* fp, const void* buff, UINT btw, UINT* bw);
|
FRESULT fx_write (FIL* fp, const void* buff, UINT btw, UINT* bw);
|
||||||
|
FRESULT fx_close (FIL* fp);
|
||||||
|
|
||||||
void dealias_path (TCHAR* alias, const TCHAR* path);
|
void dealias_path (TCHAR* alias, const TCHAR* path);
|
||||||
FRESULT fa_open (FIL* fp, const TCHAR* path, BYTE mode);
|
FRESULT fa_open (FIL* fp, const TCHAR* path, BYTE mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user