Better function names for virtual.h

This commit is contained in:
d0k3 2016-04-09 21:56:42 +02:00
parent f0c7079e08
commit c641da35f0
4 changed files with 31 additions and 31 deletions

View File

@ -63,7 +63,7 @@ void DeinitSDCardFS() {
int PathToNumFS(const char* path) { int PathToNumFS(const char* path) {
int fsnum = *path - (int) '0'; int fsnum = *path - (int) '0';
if ((fsnum < 0) || (fsnum >= NORM_FS) || (path[1] != ':')) { 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 -1;
} }
return fsnum; return fsnum;
@ -77,9 +77,9 @@ bool IsMountedFS(const char* path) {
bool CheckWritePermissions(const char* path) { bool CheckWritePermissions(const char* path) {
int pdrv = PathToNumFS(path); int pdrv = PathToNumFS(path);
if (pdrv < 0) { if (pdrv < 0) {
if (IsVirtualPath(path)) // this is a hack, but okay for now if (GetVirtualSource(path)) // this is a hack, but okay for now
pdrv = (IsVirtualPath(path) == VRT_MEMORY) ? 10 : pdrv = (GetVirtualSource(path) == VRT_MEMORY) ? 10 :
(IsVirtualPath(path) == VRT_SYSNAND) ? 1 : 4; (GetVirtualSource(path) == VRT_SYSNAND) ? 1 : 4;
else return false; else return false;
} }
@ -178,7 +178,7 @@ size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset)
return 0; return 0;
f_close(&file); f_close(&file);
return bytes_read; return bytes_read;
} else if (IsVirtualPath(path)) { } else if (GetVirtualSource(path)) {
u32 bytes_read = 0; u32 bytes_read = 0;
VirtualFile vfile; VirtualFile vfile;
if (!FindVirtualFile(&vfile, path, 0)) if (!FindVirtualFile(&vfile, path, 0))
@ -202,7 +202,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
TruncateString(deststr, dest, 36, 8); TruncateString(deststr, dest, 36, 8);
TruncateString(origstr, orig, 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 dvfile;
VirtualFile ovfile; VirtualFile ovfile;
u32 osize; u32 osize;
@ -232,7 +232,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
} }
ShowProgress(1, 1, orig); ShowProgress(1, 1, orig);
InitExtFS(); 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; VirtualFile dvfile;
FIL ofile; FIL ofile;
u32 osize; u32 osize;
@ -285,7 +285,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
ShowProgress(1, 1, orig); ShowProgress(1, 1, orig);
f_close(&ofile); f_close(&ofile);
InitExtFS(); InitExtFS();
} else if (IsVirtualPath(orig)) { // virtual to any file system } else if (GetVirtualSource(orig)) { // virtual to any file system
VirtualFile ovfile; VirtualFile ovfile;
FIL dfile; FIL dfile;
u32 osize; u32 osize;
@ -445,9 +445,9 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) {
bool PathCopy(const char* destdir, const char* orig) { bool PathCopy(const char* destdir, const char* orig) {
if (!CheckWritePermissions(destdir)) return false; if (!CheckWritePermissions(destdir)) return false;
if (IsVirtualPath(destdir) || IsVirtualPath(orig)) { if (GetVirtualSource(destdir) || GetVirtualSource(orig)) {
// users are inventive... // users are inventive...
if ((PathToNumFS(orig) > 0) && IsVirtualPath(destdir)) { if ((PathToNumFS(orig) > 0) && GetVirtualSource(destdir)) {
ShowPrompt(false, "Only files from SD card are accepted"); ShowPrompt(false, "Only files from SD card are accepted");
return false; return false;
} }
@ -609,7 +609,7 @@ bool GetRootDirContentsWorker(DirStruct* contents) {
for (u32 pdrv = 0; (pdrv < NORM_FS+VIRT_FS) && (n_entries < MAX_ENTRIES); pdrv++) { for (u32 pdrv = 0; (pdrv < NORM_FS+VIRT_FS) && (n_entries < MAX_ENTRIES); pdrv++) {
DirEntry* entry = &(contents->entry[n_entries]); DirEntry* entry = &(contents->entry[n_entries]);
if ((pdrv < NORM_FS) && !fs_mounted[pdrv]) continue; 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); memset(entry->path, 0x00, 64);
snprintf(entry->path + 0, 4, drvnum[pdrv]); snprintf(entry->path + 0, 4, drvnum[pdrv]);
snprintf(entry->path + 4, 32, "[%s] %s", drvnum[pdrv], drvname[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->type = T_DOTDOT;
contents->entry->size = 0; contents->entry->size = 0;
contents->n_entries = 1; contents->n_entries = 1;
if (IsVirtualPath(path)) { if (GetVirtualSource(path)) {
if (!GetVirtualDirContentsWorker(contents, path)) if (!GetVirtualDirContentsWorker(contents, path))
contents->n_entries = 0; contents->n_entries = 0;
} else { } else {

View File

@ -433,7 +433,7 @@ u32 GodMode() {
SetWritePermissions((GetWritePermissions() >= 3) ? 2 : 3); SetWritePermissions((GetWritePermissions() >= 3) ? 2 : 3);
} }
} else if (!switched) { // standard unswitched command set } 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"); ShowPrompt(false, "Not allowed in virtual path");
} else if (pad_state & BUTTON_X) { // delete a file } else if (pad_state & BUTTON_X) { // delete a file
u32 n_marked = 0; u32 n_marked = 0;
@ -491,7 +491,7 @@ u32 GodMode() {
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
} }
} else { // switched command set } 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"); ShowPrompt(false, "Not allowed in virtual path");
} else if ((pad_state & BUTTON_X) && (curr_entry->type != T_DOTDOT)) { // rename a file } else if ((pad_state & BUTTON_X) && (curr_entry->type != T_DOTDOT)) { // rename a file
char newname[256]; char newname[256];

View File

@ -5,29 +5,29 @@
#define VFLAG_ON_O3DS NAND_TYPE_O3DS #define VFLAG_ON_O3DS NAND_TYPE_O3DS
#define VFLAG_ON_N3DS NAND_TYPE_N3DS #define VFLAG_ON_N3DS NAND_TYPE_N3DS
#define VFLAG_ON_NO3DS NAND_TYPE_NO3DS #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_ON_MEMORY VRT_MEMORY
#define VFLAG_NAND_SIZE (1<<31) #define VFLAG_NAND_SIZE (1<<31)
// see: http://3dbrew.org/wiki/Flash_Filesystem#NAND_structure // see: http://3dbrew.org/wiki/Flash_Filesystem#NAND_structure
// see: http://3dbrew.org/wiki/Memory_layout#ARM9 // see: http://3dbrew.org/wiki/Memory_layout#ARM9
VirtualFile virtualFileTemplates[] = { VirtualFile virtualFileTemplates[] = {
{ "twln.bin" , 0x00012E00, 0x08FB5200, 0x03, VFLAG_ON_ALL }, { "twln.bin" , 0x00012E00, 0x08FB5200, 0x03, VFLAG_ON_NAND },
{ "twlp.bin" , 0x09011A00, 0x020B6600, 0x03, VFLAG_ON_ALL }, { "twlp.bin" , 0x09011A00, 0x020B6600, 0x03, VFLAG_ON_NAND },
{ "agbsave.bin" , 0x0B100000, 0x00030000, 0x07, VFLAG_ON_ALL }, { "agbsave.bin" , 0x0B100000, 0x00030000, 0x07, VFLAG_ON_NAND },
{ "firm0.bin" , 0x0B130000, 0x00400000, 0x06, VFLAG_ON_ALL }, { "firm0.bin" , 0x0B130000, 0x00400000, 0x06, VFLAG_ON_NAND },
{ "firm1.bin" , 0x0B530000, 0x00400000, 0x06, VFLAG_ON_ALL }, { "firm1.bin" , 0x0B530000, 0x00400000, 0x06, VFLAG_ON_NAND },
{ "ctrnand_fat.bin" , 0x0B95CA00, 0x2F3E3600, 0x04, VFLAG_ON_O3DS }, { "ctrnand_fat.bin" , 0x0B95CA00, 0x2F3E3600, 0x04, VFLAG_ON_O3DS },
{ "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x05, VFLAG_ON_N3DS }, { "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x05, VFLAG_ON_N3DS },
{ "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x04, VFLAG_ON_NO3DS }, { "ctrnand_fat.bin" , 0x0B95AE00, 0x41D2D200, 0x04, VFLAG_ON_NO3DS },
{ "ctrnand_full.bin" , 0x0B930000, 0x2F5D0000, 0x04, VFLAG_ON_O3DS }, { "ctrnand_full.bin" , 0x0B930000, 0x2F5D0000, 0x04, VFLAG_ON_O3DS },
{ "ctrnand_full.bin" , 0x0B930000, 0x41ED0000, 0x05, VFLAG_ON_N3DS }, { "ctrnand_full.bin" , 0x0B930000, 0x41ED0000, 0x05, VFLAG_ON_N3DS },
{ "ctrnand_full.bin" , 0x0B930000, 0x41ED0000, 0x04, VFLAG_ON_NO3DS }, { "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, 0x3AF00000, 0xFF, VFLAG_ON_O3DS },
{ "nand_minsize.bin" , 0x00000000, 0x4D800000, 0xFF, VFLAG_ON_N3DS | VFLAG_ON_NO3DS }, { "nand_minsize.bin" , 0x00000000, 0x4D800000, 0xFF, VFLAG_ON_N3DS | VFLAG_ON_NO3DS },
{ "sector0x96.bin" , 0x00012C00, 0x00000200, 0xFF, VFLAG_ON_ALL }, { "sector0x96.bin" , 0x00012C00, 0x00000200, 0xFF, VFLAG_ON_NAND },
{ "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_ALL }, { "nand_hdr.bin" , 0x00000000, 0x00000200, 0xFF, VFLAG_ON_NAND },
{ "itcm.dmp" , 0x01FF8000, 0x00008000, 0xFF, VFLAG_ON_MEMORY }, { "itcm.dmp" , 0x01FF8000, 0x00008000, 0xFF, VFLAG_ON_MEMORY },
{ "arm9internal.dmp" , 0x08000000, 0x00100000, 0xFF, VFLAG_ON_MEMORY }, { "arm9internal.dmp" , 0x08000000, 0x00100000, 0xFF, VFLAG_ON_MEMORY },
{ "vram.dmp" , 0x18000000, 0x00600000, 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 } { "bootrom_unp.dmp" , 0xFFFF0000, 0x00008000, 0xFF, VFLAG_ON_MEMORY }
}; };
u32 IsVirtualPath(const char* path) { u32 GetVirtualSource(const char* path) {
u32 plen = strnlen(path, 16); u32 plen = strnlen(path, 16);
if (strncmp(path, "S:/", (plen >= 3) ? 3 : 2) == 0) if (strncmp(path, "S:/", (plen >= 3) ? 3 : 2) == 0)
return VRT_SYSNAND; return VRT_SYSNAND;
@ -51,8 +51,8 @@ u32 IsVirtualPath(const char* path) {
return 0; return 0;
} }
bool CheckVirtualPath(const char* path) { bool CheckVirtualDrive(const char* path) {
u32 virtual_src = IsVirtualPath(path); u32 virtual_src = GetVirtualSource(path);
if ((virtual_src == VRT_EMUNAND) || (virtual_src == VRT_IMGNAND)) { if ((virtual_src == VRT_EMUNAND) || (virtual_src == VRT_IMGNAND)) {
return GetNandSizeSectors(virtual_src); return GetNandSizeSectors(virtual_src);
} }
@ -70,7 +70,7 @@ bool FindVirtualFile(VirtualFile* vfile, const char* path, u32 size)
fname++; fname++;
// check path vailidity // check path vailidity
virtual_src = IsVirtualPath(path); virtual_src = GetVirtualSource(path);
if (!virtual_src || (fname - path != 3)) if (!virtual_src || (fname - path != 3))
return false; return false;
@ -114,7 +114,7 @@ int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count,
count = vfile->size - offset; count = vfile->size - offset;
if (bytes_read) *bytes_read = count; 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 if (!(foffset % 0x200) && !(count % 0x200)) { // aligned data -> simple case
// simple wrapper function for ReadNandSectors(u8* buffer, u32 sector, u32 count, u32 keyslot, u32 src) // simple wrapper function for ReadNandSectors(u8* buffer, u32 sector, u32 count, u32 keyslot, u32 src)
return ReadNandSectors(buffer, foffset / 0x200, count / 0x200, vfile->keyslot, 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; count = vfile->size - offset;
if (bytes_written) *bytes_written = count; 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 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) // 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, return WriteNandSectors(buffer, foffset / 0x200, count / 0x200, vfile->keyslot,

View File

@ -24,8 +24,8 @@ typedef struct {
u32 flags; u32 flags;
} __attribute__((packed)) VirtualFile; } __attribute__((packed)) VirtualFile;
u32 IsVirtualPath(const char* path); u32 GetVirtualSource(const char* path);
bool CheckVirtualPath(const char* path); bool CheckVirtualDrive(const char* path);
bool FindVirtualFile(VirtualFile* vfile, const char* path, u32 size); bool FindVirtualFile(VirtualFile* vfile, const char* path, u32 size);
int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, u32* bytes_read); 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); int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written);