mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-16 17:59:19 +01:00
Emulate fs:/ and fs:/vol/ in a very hacky way.
This commit is contained in:
parent
4174957106
commit
b509af2bf9
@ -104,6 +104,10 @@ ON_APPLICATION_START(args) {
|
|||||||
VirtualMountDevice("storage_mlc:/");
|
VirtualMountDevice("storage_mlc:/");
|
||||||
VirtualMountDevice("storage_usb:/");
|
VirtualMountDevice("storage_usb:/");
|
||||||
VirtualMountDevice("usb:/");
|
VirtualMountDevice("usb:/");
|
||||||
|
|
||||||
|
AddVirtualFSPath("vol", nullptr, nullptr);
|
||||||
|
AddVirtualFSVOLPath("external01", nullptr, nullptr);
|
||||||
|
AddVirtualFSVOLPath("content", nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread = BackgroundThread::getInstance();
|
thread = BackgroundThread::getInstance();
|
||||||
|
@ -32,7 +32,13 @@
|
|||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
uint8_t MAX_VIRTUAL_PARTITIONS = 0;
|
uint8_t MAX_VIRTUAL_PARTITIONS = 0;
|
||||||
VIRTUAL_PARTITION * VIRTUAL_PARTITIONS = NULL;
|
VIRTUAL_PARTITION *VIRTUAL_PARTITIONS = NULL;
|
||||||
|
|
||||||
|
uint8_t MAX_VIRTUAL_FS = 0;
|
||||||
|
VIRTUAL_PARTITION *VIRTUAL_FS = NULL;
|
||||||
|
|
||||||
|
uint8_t MAX_VIRTUAL_FS_VOL = 0;
|
||||||
|
VIRTUAL_PARTITION *VIRTUAL_FS_VOL = NULL;
|
||||||
|
|
||||||
void VirtualMountDevice(const char * path)
|
void VirtualMountDevice(const char * path)
|
||||||
{
|
{
|
||||||
@ -91,6 +97,45 @@ void AddVirtualPath(const char *name, const char *alias, const char *prefix)
|
|||||||
MAX_VIRTUAL_PARTITIONS++;
|
MAX_VIRTUAL_PARTITIONS++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AddVirtualFSPath(const char *name, const char *alias, const char *prefix) {
|
||||||
|
if (!VIRTUAL_FS) {
|
||||||
|
VIRTUAL_FS = (VIRTUAL_PARTITION *) malloc(sizeof(VIRTUAL_PARTITION));
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_FS, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_FS + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
free(VIRTUAL_FS);
|
||||||
|
MAX_VIRTUAL_FS = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRTUAL_FS = tmp;
|
||||||
|
|
||||||
|
VIRTUAL_FS[MAX_VIRTUAL_FS].name = strdup(name);
|
||||||
|
|
||||||
|
MAX_VIRTUAL_FS++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddVirtualFSVOLPath(const char *name, const char *alias, const char *prefix) {
|
||||||
|
if (!VIRTUAL_FS_VOL) {
|
||||||
|
VIRTUAL_FS_VOL = (VIRTUAL_PARTITION *) malloc(sizeof(VIRTUAL_PARTITION));
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_FS_VOL, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_FS_VOL + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
free(VIRTUAL_FS_VOL);
|
||||||
|
MAX_VIRTUAL_FS_VOL = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRTUAL_FS_VOL = tmp;
|
||||||
|
|
||||||
|
VIRTUAL_FS_VOL[MAX_VIRTUAL_FS_VOL].name = strdup(name);
|
||||||
|
|
||||||
|
MAX_VIRTUAL_FS_VOL++;
|
||||||
|
}
|
||||||
|
|
||||||
void MountVirtualDevices()
|
void MountVirtualDevices()
|
||||||
{
|
{
|
||||||
VirtualMountDevice("fs:/");
|
VirtualMountDevice("fs:/");
|
||||||
|
@ -47,8 +47,16 @@ typedef struct {
|
|||||||
extern VIRTUAL_PARTITION * VIRTUAL_PARTITIONS;
|
extern VIRTUAL_PARTITION * VIRTUAL_PARTITIONS;
|
||||||
extern uint8_t MAX_VIRTUAL_PARTITIONS;
|
extern uint8_t MAX_VIRTUAL_PARTITIONS;
|
||||||
|
|
||||||
|
extern VIRTUAL_PARTITION * VIRTUAL_FS;
|
||||||
|
extern uint8_t MAX_VIRTUAL_FS;
|
||||||
|
|
||||||
|
extern VIRTUAL_PARTITION * VIRTUAL_FS_VOL;
|
||||||
|
extern uint8_t MAX_VIRTUAL_FS_VOL;
|
||||||
|
|
||||||
void VirtualMountDevice(const char * devicepath);
|
void VirtualMountDevice(const char * devicepath);
|
||||||
void AddVirtualPath(const char *name, const char *alias, const char *prefix);
|
void AddVirtualPath(const char *name, const char *alias, const char *prefix);
|
||||||
|
void AddVirtualFSPath(const char *name, const char *alias, const char *prefix);
|
||||||
|
void AddVirtualFSVOLPath(const char *name, const char *alias, const char *prefix);
|
||||||
void MountVirtualDevices();
|
void MountVirtualDevices();
|
||||||
void UnmountVirtualPaths();
|
void UnmountVirtualPaths();
|
||||||
|
|
||||||
|
62
src/vrt.c
62
src/vrt.c
@ -155,9 +155,15 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int checkdir(char *path) {
|
static int checkdir(char *path) {
|
||||||
|
if (path != NULL &&
|
||||||
|
(strcmp(path, "fs:/vol") == 0 ||
|
||||||
|
strcmp(path, "fs:/vol/") == 0 ||
|
||||||
|
strcmp(path, "fs:/") == 0)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
if(dir)
|
if (dir) {
|
||||||
{
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -264,42 +270,52 @@ int vrt_rename(char *cwd, char *from_path, char *to_path) {
|
|||||||
/*
|
/*
|
||||||
When in vfs-root this creates a fake DIR_ITER.
|
When in vfs-root this creates a fake DIR_ITER.
|
||||||
*/
|
*/
|
||||||
DIR_P *vrt_opendir(char *cwd, char *path)
|
DIR_P *vrt_opendir(char *cwd, char *path) {
|
||||||
{
|
|
||||||
char *real_path = to_real_path(cwd, path);
|
char *real_path = to_real_path(cwd, path);
|
||||||
if (!real_path) return NULL;
|
if (!real_path) { return NULL; }
|
||||||
|
|
||||||
DIR_P *iter = malloc(sizeof(DIR_P));
|
DIR_P *iter = malloc(sizeof(DIR_P));
|
||||||
if (!iter)
|
if (!iter) {
|
||||||
{
|
if (*real_path != 0) {
|
||||||
if (*real_path != 0)
|
|
||||||
free(real_path);
|
free(real_path);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->virt_root = 0;
|
iter->virt_root = 0;
|
||||||
|
iter->virtual_fs = 0;
|
||||||
|
iter->virtual_fs_vol = 0;
|
||||||
iter->path = real_path;
|
iter->path = real_path;
|
||||||
|
|
||||||
if (*iter->path == 0) {
|
if (*iter->path == 0 || (strncmp(iter->path, "fs:", 3) == 0 && strlen(iter->path) <= 4) || (strncmp(iter->path, "fs:/vol", 3) == 0 && strlen(iter->path) <= 8)) {
|
||||||
iter->dir = malloc(sizeof(DIR));
|
iter->dir = malloc(sizeof(DIR));
|
||||||
if(!iter->dir) {
|
if (!iter->dir) {
|
||||||
// root path is not allocated
|
// root path is not allocated
|
||||||
free(iter);
|
free(iter);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(iter->dir, 0, sizeof(DIR));
|
memset(iter->dir, 0, sizeof(DIR));
|
||||||
|
|
||||||
|
if (strncmp(iter->path, "fs:/vol", 7) == 0) {
|
||||||
|
iter->virtual_fs_vol = 1; // we are at the virtual fs
|
||||||
|
} else if (strncmp(iter->path, "fs:", 3) == 0) {
|
||||||
|
iter->virtual_fs = 1; // we are at the virtual fs
|
||||||
|
} else {
|
||||||
iter->virt_root = 1; // we are at the virtual root
|
iter->virt_root = 1; // we are at the virtual root
|
||||||
|
}
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
iter->dir = with_virtual_path(cwd, opendir, path, 0, NULL);
|
iter->dir = with_virtual_path(cwd, opendir, path, 0, NULL);
|
||||||
if(!iter->dir)
|
if (!iter->dir) {
|
||||||
{
|
|
||||||
free(iter->path);
|
free(iter->path);
|
||||||
free(iter);
|
free(iter);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,21 +323,35 @@ DIR_P *vrt_opendir(char *cwd, char *path)
|
|||||||
Yields virtual aliases when pDir->virt_root
|
Yields virtual aliases when pDir->virt_root
|
||||||
*/
|
*/
|
||||||
struct dirent *vrt_readdir(DIR_P *pDir) {
|
struct dirent *vrt_readdir(DIR_P *pDir) {
|
||||||
if(!pDir || !pDir->dir) return NULL;
|
if (!pDir || !pDir->dir) { return NULL; }
|
||||||
|
|
||||||
DIR *iter = pDir->dir;
|
DIR *iter = pDir->dir;
|
||||||
if (pDir->virt_root) {
|
if (pDir->virt_root || pDir->virtual_fs || pDir->virtual_fs_vol) {
|
||||||
for (; (uint32_t)iter->position < MAX_VIRTUAL_PARTITIONS; iter->position++) {
|
int max = MAX_VIRTUAL_PARTITIONS;
|
||||||
VIRTUAL_PARTITION *partition = VIRTUAL_PARTITIONS + (int)iter->position;
|
VIRTUAL_PARTITION * PARTITION_PTR = VIRTUAL_PARTITIONS;
|
||||||
|
if(pDir->virtual_fs){
|
||||||
|
max = MAX_VIRTUAL_FS;
|
||||||
|
PARTITION_PTR = VIRTUAL_FS;
|
||||||
|
} else if (pDir->virtual_fs_vol){
|
||||||
|
max = MAX_VIRTUAL_FS_VOL;
|
||||||
|
PARTITION_PTR = VIRTUAL_FS_VOL;
|
||||||
|
}
|
||||||
|
for (; (uint32_t) iter->position < max; iter->position++) {
|
||||||
|
VIRTUAL_PARTITION *partition = PARTITION_PTR + (int) iter->position;
|
||||||
if (partition->inserted) {
|
if (partition->inserted) {
|
||||||
iter->fileData.d_type = DT_DIR;
|
iter->fileData.d_type = DT_DIR;
|
||||||
|
if(pDir->virtual_fs || pDir->virtual_fs_vol){
|
||||||
|
strcpy(iter->fileData.d_name, partition->name);
|
||||||
|
}else{
|
||||||
strcpy(iter->fileData.d_name, partition->alias + 1);
|
strcpy(iter->fileData.d_name, partition->alias + 1);
|
||||||
|
}
|
||||||
iter->position++;
|
iter->position++;
|
||||||
return &iter->fileData;
|
return &iter->fileData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return readdir(iter);
|
return readdir(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ typedef struct
|
|||||||
DIR *dir;
|
DIR *dir;
|
||||||
char *path;
|
char *path;
|
||||||
uint8_t virt_root;
|
uint8_t virt_root;
|
||||||
|
uint8_t virtual_fs;
|
||||||
|
uint8_t virtual_fs_vol;
|
||||||
} DIR_P;
|
} DIR_P;
|
||||||
|
|
||||||
char *to_real_path(char *virtual_cwd, char *virtual_path);
|
char *to_real_path(char *virtual_cwd, char *virtual_path);
|
||||||
|
Loading…
Reference in New Issue
Block a user