diff --git a/source/fs.c b/source/fs.c index a536c5d..0dea843 100644 --- a/source/fs.c +++ b/source/fs.c @@ -63,7 +63,7 @@ void DeinitSDCardFS() { int PathToNumFS(const char* path) { int fsnum = *path - (int) '0'; if ((fsnum < 0) || (fsnum >= NORM_FS) || (path[1] != ':')) { - if (!IsVirtualPath(path)) ShowPrompt(false, "Invalid path (%s)", path); + if (!GetVirtualSource(path)) ShowPrompt(false, "Invalid path (%s)", path); return -1; } return fsnum; @@ -77,9 +77,9 @@ bool IsMountedFS(const char* path) { bool CheckWritePermissions(const char* path) { int pdrv = PathToNumFS(path); if (pdrv < 0) { - if (IsVirtualPath(path)) // this is a hack, but okay for now - pdrv = (IsVirtualPath(path) == VRT_MEMORY) ? 10 : - (IsVirtualPath(path) == VRT_SYSNAND) ? 1 : 4; + if (GetVirtualSource(path)) // this is a hack, but okay for now + pdrv = (GetVirtualSource(path) == VRT_MEMORY) ? 10 : + (GetVirtualSource(path) == VRT_SYSNAND) ? 1 : 4; else return false; } @@ -178,7 +178,7 @@ size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset) return 0; f_close(&file); return bytes_read; - } else if (IsVirtualPath(path)) { + } else if (GetVirtualSource(path)) { u32 bytes_read = 0; VirtualFile vfile; if (!FindVirtualFile(&vfile, path, 0)) @@ -202,7 +202,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) { TruncateString(deststr, dest, 36, 8); TruncateString(origstr, orig, 36, 8); - if (IsVirtualPath(dest) && IsVirtualPath(orig)) { // virtual to virtual + if (GetVirtualSource(dest) && GetVirtualSource(orig)) { // virtual to virtual VirtualFile dvfile; VirtualFile ovfile; u32 osize; @@ -232,7 +232,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) { } ShowProgress(1, 1, orig); InitExtFS(); - } else if (IsVirtualPath(dest)) { // SD card to virtual (other FAT not allowed!) + } else if (GetVirtualSource(dest)) { // SD card to virtual (other FAT not allowed!) VirtualFile dvfile; FIL ofile; u32 osize; @@ -285,7 +285,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) { ShowProgress(1, 1, orig); f_close(&ofile); InitExtFS(); - } else if (IsVirtualPath(orig)) { // virtual to any file system + } else if (GetVirtualSource(orig)) { // virtual to any file system VirtualFile ovfile; FIL dfile; u32 osize; @@ -445,9 +445,9 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) { bool PathCopy(const char* destdir, const char* orig) { if (!CheckWritePermissions(destdir)) return false; - if (IsVirtualPath(destdir) || IsVirtualPath(orig)) { + if (GetVirtualSource(destdir) || GetVirtualSource(orig)) { // users are inventive... - if ((PathToNumFS(orig) > 0) && IsVirtualPath(destdir)) { + if ((PathToNumFS(orig) > 0) && GetVirtualSource(destdir)) { ShowPrompt(false, "Only files from SD card are accepted"); return false; } @@ -609,7 +609,7 @@ bool GetRootDirContentsWorker(DirStruct* contents) { for (u32 pdrv = 0; (pdrv < NORM_FS+VIRT_FS) && (n_entries < MAX_ENTRIES); pdrv++) { DirEntry* entry = &(contents->entry[n_entries]); if ((pdrv < NORM_FS) && !fs_mounted[pdrv]) continue; - else if ((pdrv >= NORM_FS) && (!CheckVirtualPath(drvnum[pdrv]))) continue; + else if ((pdrv >= NORM_FS) && (!CheckVirtualDrive(drvnum[pdrv]))) continue; memset(entry->path, 0x00, 64); snprintf(entry->path + 0, 4, drvnum[pdrv]); snprintf(entry->path + 4, 32, "[%s] %s", drvnum[pdrv], drvname[pdrv]); @@ -702,7 +702,7 @@ void GetDirContents(DirStruct* contents, const char* path) { contents->entry->type = T_DOTDOT; contents->entry->size = 0; contents->n_entries = 1; - if (IsVirtualPath(path)) { + if (GetVirtualSource(path)) { if (!GetVirtualDirContentsWorker(contents, path)) contents->n_entries = 0; } else { diff --git a/source/godmode.c b/source/godmode.c index 6b2f7b4..2f80ee4 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -433,7 +433,7 @@ u32 GodMode() { SetWritePermissions((GetWritePermissions() >= 3) ? 2 : 3); } } else if (!switched) { // standard unswitched command set - if (IsVirtualPath(current_path) && (pad_state & BUTTON_X)) { + if (GetVirtualSource(current_path) && (pad_state & BUTTON_X)) { ShowPrompt(false, "Not allowed in virtual path"); } else if (pad_state & BUTTON_X) { // delete a file u32 n_marked = 0; @@ -491,7 +491,7 @@ u32 GodMode() { ClearScreenF(true, false, COLOR_STD_BG); } } else { // switched command set - if (IsVirtualPath(current_path) && (pad_state & (BUTTON_X|BUTTON_Y))) { + if (GetVirtualSource(current_path) && (pad_state & (BUTTON_X|BUTTON_Y))) { ShowPrompt(false, "Not allowed in virtual path"); } else if ((pad_state & BUTTON_X) && (curr_entry->type != T_DOTDOT)) { // rename a file char newname[256]; diff --git a/source/nand/virtual.c b/source/nand/virtual.c index 248be9f..c226a06 100644 --- a/source/nand/virtual.c +++ b/source/nand/virtual.c @@ -5,29 +5,29 @@ #define VFLAG_ON_O3DS NAND_TYPE_O3DS #define VFLAG_ON_N3DS NAND_TYPE_N3DS #define VFLAG_ON_NO3DS NAND_TYPE_NO3DS -#define VFLAG_ON_ALL (VFLAG_ON_O3DS | VFLAG_ON_N3DS | VFLAG_ON_NO3DS) +#define VFLAG_ON_NAND (VFLAG_ON_O3DS | VFLAG_ON_N3DS | VFLAG_ON_NO3DS) #define VFLAG_ON_MEMORY VRT_MEMORY #define VFLAG_NAND_SIZE (1<<31) // see: http://3dbrew.org/wiki/Flash_Filesystem#NAND_structure // see: http://3dbrew.org/wiki/Memory_layout#ARM9 VirtualFile virtualFileTemplates[] = { - { "twln.bin" , 0x00012E00, 0x08FB5200, 0x03, VFLAG_ON_ALL }, - { "twlp.bin" , 0x09011A00, 0x020B6600, 0x03, VFLAG_ON_ALL }, - { "agbsave.bin" , 0x0B100000, 0x00030000, 0x07, VFLAG_ON_ALL }, - { "firm0.bin" , 0x0B130000, 0x00400000, 0x06, VFLAG_ON_ALL }, - { "firm1.bin" , 0x0B530000, 0x00400000, 0x06, VFLAG_ON_ALL }, + { "twln.bin" , 0x00012E00, 0x08FB5200, 0x03, VFLAG_ON_NAND }, + { "twlp.bin" , 0x09011A00, 0x020B6600, 0x03, VFLAG_ON_NAND }, + { "agbsave.bin" , 0x0B100000, 0x00030000, 0x07, VFLAG_ON_NAND }, + { "firm0.bin" , 0x0B130000, 0x00400000, 0x06, VFLAG_ON_NAND }, + { "firm1.bin" , 0x0B530000, 0x00400000, 0x06, VFLAG_ON_NAND }, { "ctrnand_fat.bin" , 0x0B95CA00, 0x2F3E3600, 0x04, VFLAG_ON_O3DS }, { "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x05, VFLAG_ON_N3DS }, { "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x04, VFLAG_ON_NO3DS }, { "ctrnand_full.bin" , 0x0B930000, 0x2F5D0000, 0x04, VFLAG_ON_O3DS }, { "ctrnand_full.bin" , 0x0B930000, 0x41ED0000, 0x05, VFLAG_ON_N3DS }, { "ctrnand_full.bin" , 0x0B930000, 0x41ED0000, 0x04, VFLAG_ON_NO3DS }, - { "nand.bin" , 0x00000000, 0x00000000, 0xFF, VFLAG_ON_ALL | VFLAG_NAND_SIZE }, + { "nand.bin" , 0x00000000, 0x00000000, 0xFF, VFLAG_ON_NAND | VFLAG_NAND_SIZE }, { "nand_minsize.bin" , 0x00000000, 0x3AF00000, 0xFF, VFLAG_ON_O3DS }, { "nand_minsize.bin" , 0x00000000, 0x4D800000, 0xFF, VFLAG_ON_N3DS | VFLAG_ON_NO3DS }, - { "sector0x96.bin" , 0x00012C00, 0x00000200, 0xFF, VFLAG_ON_ALL }, - { "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_ALL }, + { "sector0x96.bin" , 0x00012C00, 0x00000200, 0xFF, VFLAG_ON_NAND }, + { "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_NAND }, { "itcm.dmp" , 0x01FF8000, 0x00008000, 0xFF, VFLAG_ON_MEMORY }, { "arm9internal.dmp" , 0x08000000, 0x00100000, 0xFF, VFLAG_ON_MEMORY }, { "vram.dmp" , 0x18000000, 0x00600000, 0xFF, VFLAG_ON_MEMORY }, @@ -38,7 +38,7 @@ VirtualFile virtualFileTemplates[] = { { "bootrom_unp.dmp" , 0xFFFF0000, 0x00008000, 0xFF, VFLAG_ON_MEMORY } }; -u32 IsVirtualPath(const char* path) { +u32 GetVirtualSource(const char* path) { u32 plen = strnlen(path, 16); if (strncmp(path, "S:/", (plen >= 3) ? 3 : 2) == 0) return VRT_SYSNAND; @@ -51,8 +51,8 @@ u32 IsVirtualPath(const char* path) { return 0; } -bool CheckVirtualPath(const char* path) { - u32 virtual_src = IsVirtualPath(path); +bool CheckVirtualDrive(const char* path) { + u32 virtual_src = GetVirtualSource(path); if ((virtual_src == VRT_EMUNAND) || (virtual_src == VRT_IMGNAND)) { return GetNandSizeSectors(virtual_src); } @@ -70,7 +70,7 @@ bool FindVirtualFile(VirtualFile* vfile, const char* path, u32 size) fname++; // check path vailidity - virtual_src = IsVirtualPath(path); + virtual_src = GetVirtualSource(path); if (!virtual_src || (fname - path != 3)) return false; @@ -114,7 +114,7 @@ int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, count = vfile->size - offset; if (bytes_read) *bytes_read = count; - if (vfile->flags & VFLAG_ON_ALL) { + if (vfile->flags & VFLAG_ON_NAND) { if (!(foffset % 0x200) && !(count % 0x200)) { // aligned data -> simple case // simple wrapper function for ReadNandSectors(u8* buffer, u32 sector, u32 count, u32 keyslot, u32 src) return ReadNandSectors(buffer, foffset / 0x200, count / 0x200, vfile->keyslot, @@ -163,7 +163,7 @@ int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count = vfile->size - offset; if (bytes_written) *bytes_written = count; - if (vfile->flags & VFLAG_ON_ALL) { + if (vfile->flags & VFLAG_ON_NAND) { if (!(foffset % 0x200) && !(count % 0x200)) { // aligned data -> simple case // simple wrapper function for WriteNandSectors(const u8* buffer, u32 sector, u32 count, u32 keyslot, u32 dest) return WriteNandSectors(buffer, foffset / 0x200, count / 0x200, vfile->keyslot, diff --git a/source/nand/virtual.h b/source/nand/virtual.h index 79e142c..8f5513c 100644 --- a/source/nand/virtual.h +++ b/source/nand/virtual.h @@ -24,8 +24,8 @@ typedef struct { u32 flags; } __attribute__((packed)) VirtualFile; -u32 IsVirtualPath(const char* path); -bool CheckVirtualPath(const char* path); +u32 GetVirtualSource(const char* path); +bool CheckVirtualDrive(const char* path); bool FindVirtualFile(VirtualFile* vfile, const char* path, u32 size); int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, u32* bytes_read); int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written);