Added delete code for certain virtual files (not used)

This commit is contained in:
d0k3 2017-09-16 17:07:51 +02:00
parent 5941ce41bc
commit c164077434
4 changed files with 32 additions and 11 deletions

View File

@ -101,8 +101,12 @@ FRESULT fvx_rename (const TCHAR* path_old, const TCHAR* path_new) {
}
FRESULT fvx_unlink (const TCHAR* path) {
if (GetVirtualSource(path)) return FR_DENIED;
return fa_unlink( path );
if (GetVirtualSource(path)) {
VirtualFile vfile;
if (!GetVirtualFile(&vfile, path)) return FR_NO_PATH;
if (DeleteVirtualFile(&vfile) != 0) return FR_DENIED;
return FR_OK;
} else return fa_unlink( path );
}
FRESULT fvx_mkdir (const TCHAR* path) {
@ -237,7 +241,7 @@ FRESULT worker_fvx_runlink (TCHAR* tpath) {
FRESULT res;
// this code handles directory content deletion
if ((res = fa_stat(tpath, &fno)) != FR_OK) return res; // tpath does not exist
if ((res = fvx_stat(tpath, &fno)) != FR_OK) return res; // tpath does not exist
if (fno.fattrib & AM_DIR) { // process folder contents
DIR pdir;
TCHAR* fname = tpath + strnlen(tpath, 255);
@ -246,7 +250,7 @@ FRESULT worker_fvx_runlink (TCHAR* tpath) {
if ((res = fa_opendir(&pdir, tpath)) != FR_OK) return res;
*(fname++) = '/';
while (f_readdir(&pdir, &fno) == FR_OK) {
while (fvx_readdir(&pdir, &fno) == FR_OK) {
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
continue; // filter out virtual entries
strncpy(fname, fno.fname, tpath + 255 - fname);
@ -256,11 +260,11 @@ FRESULT worker_fvx_runlink (TCHAR* tpath) {
worker_fvx_runlink(tpath);
}
}
f_closedir(&pdir);
fvx_closedir(&pdir);
*(--fname) = '\0';
}
return fa_unlink( tpath );
return fvx_unlink( tpath );
}
#endif

View File

@ -181,6 +181,21 @@ int WriteVirtualFile(const VirtualFile* vfile, const void* buffer, u64 offset, u
return -1;
}
int DeleteVirtualFile(const VirtualFile* vfile) {
u8* zeroes = (u8*) TEMP_BUFFER;
u32 zeroes_size = TEMP_BUFFER_SIZE;
if (!(vfile->flags & VFLAG_DELETABLE)) return -1;
memset(zeroes, 0x00, TEMP_BUFFER_SIZE);
for (u64 pos = 0; pos < vfile->size; pos += zeroes_size) {
u64 wipe_bytes = min(zeroes_size, vfile->size - pos);
if (WriteVirtualFile(vfile, zeroes, pos, wipe_bytes, NULL) != 0)
return -1;
}
return 0;
}
u64 GetVirtualDriveSize(const char* path) {
u32 virtual_src = GetVirtualSource(path);
if (virtual_src & (VRT_SYSNAND|VRT_EMUNAND|VRT_IMGNAND))

View File

@ -18,7 +18,8 @@
#define VFLAG_DIR (1UL<<10)
#define VFLAG_ROOT (1UL<<11)
#define VFLAG_READONLY (1UL<<12)
#define VFLAG_LV3 (1UL<<13)
#define VFLAG_DELETABLE (1UL<<13)
#define VFLAG_LV3 (1UL<<14)
#define VRT_DRIVES {'S', VRT_SYSNAND}, {'E', VRT_EMUNAND}, {'I', VRT_IMGNAND}, {'X', VRT_XORPAD }, \
@ -59,5 +60,6 @@ bool GetVirtualFilename(char* name, const VirtualFile* vfile, u32 n_chars);
int ReadVirtualFile(const VirtualFile* vfile, void* buffer, u64 offset, u64 count, u32* bytes_read);
int WriteVirtualFile(const VirtualFile* vfile, const void* buffer, u64 offset, u64 count, u32* bytes_written);
int DeleteVirtualFile(const VirtualFile* vfile);
u64 GetVirtualDriveSize(const char* path);

View File

@ -22,12 +22,12 @@ typedef struct {
static const VirtualNandTemplate vNandTemplates[] = {
{ "nand_hdr.bin" , NP_TYPE_NCSD , NP_SUBTYPE_CTR , 0, 0 },
{ "twlmbr.bin" , NP_TYPE_STD , NP_SUBTYPE_TWL , 0, VFLAG_MBR },
{ "essential.exefs" , NP_TYPE_D0K3 , NP_SUBTYPE_NONE , 0, VFLAG_ESSENTIAL },
{ "essential.exefs" , NP_TYPE_D0K3 , NP_SUBTYPE_NONE , 0, VFLAG_DELETABLE | VFLAG_ESSENTIAL },
{ "sector0x96.bin" , NP_TYPE_SECRET, NP_SUBTYPE_CTR_N, 0, VFLAG_NEEDS_OTP },
{ "twln.bin" , NP_TYPE_FAT , NP_SUBTYPE_TWL , 0, 0 },
{ "twlp.bin" , NP_TYPE_FAT , NP_SUBTYPE_TWL , 1, 0 },
{ "agbsave.bin" , NP_TYPE_AGB , NP_SUBTYPE_CTR , 0, 0 },
{ "gbavc.sav" , NP_TYPE_AGB , NP_SUBTYPE_CTR , 0, VFLAG_GBA_VC },
{ "agbsave.bin" , NP_TYPE_AGB , NP_SUBTYPE_CTR , 0, VFLAG_DELETABLE },
{ "gbavc.sav" , NP_TYPE_AGB , NP_SUBTYPE_CTR , 0, VFLAG_DELETABLE | VFLAG_GBA_VC },
{ "firm0.bin" , NP_TYPE_FIRM , NP_SUBTYPE_CTR , 0, 0 },
{ "firm1.bin" , NP_TYPE_FIRM , NP_SUBTYPE_CTR , 1, 0 },
{ "firm2.bin" , NP_TYPE_FIRM , NP_SUBTYPE_CTR , 2, 0 },
@ -40,7 +40,7 @@ static const VirtualNandTemplate vNandTemplates[] = {
{ "ctrnand_full.bin" , NP_TYPE_STD , NP_SUBTYPE_CTR_N, 0, 0 },
{ "ctrnand_fat.bin" , NP_TYPE_FAT , NP_SUBTYPE_CTR , 0, 0 },
{ "ctrnand_fat.bin" , NP_TYPE_FAT , NP_SUBTYPE_CTR_N, 0, 0 },
{ "bonus.bin" , NP_TYPE_BONUS , NP_SUBTYPE_CTR , 0, 0 },
{ "bonus.bin" , NP_TYPE_BONUS , NP_SUBTYPE_CTR , 0, VFLAG_DELETABLE },
{ "nand.bin" , NP_TYPE_NONE , NP_SUBTYPE_NONE , 0, VFLAG_NAND_SIZE },
{ "nand_minsize.bin" , NP_TYPE_NONE , NP_SUBTYPE_NONE , 0, 0 }
};