mirror of
https://github.com/libretro/RetroArch
synced 2024-07-05 09:48:42 +00:00
(Wiiu) Cleanup of aux files
This commit is contained in:
parent
1a87e1107b
commit
8db6197e4b
|
@ -38,9 +38,7 @@ int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||||
if (!mountSrc)
|
if (!mountSrc)
|
||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
if (!(mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE)))
|
||||||
|
|
||||||
if (!mountPath)
|
|
||||||
{
|
{
|
||||||
free(mountSrc);
|
free(mountSrc);
|
||||||
return -4;
|
return -4;
|
||||||
|
@ -66,143 +64,3 @@ int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||||
free(mountSrc);
|
free(mountSrc);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UmountFS(void *pClient, void *pCmd, const char *mountPath)
|
|
||||||
{
|
|
||||||
return FSUnmount(pClient, pCmd, mountPath, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
|
||||||
{
|
|
||||||
u8 *buffer;
|
|
||||||
u32 filesize;
|
|
||||||
int iFd;
|
|
||||||
u32 blocksize = 0x4000;
|
|
||||||
u32 done = 0;
|
|
||||||
int readBytes = 0;
|
|
||||||
|
|
||||||
/* always initialze input */
|
|
||||||
*inbuffer = NULL;
|
|
||||||
|
|
||||||
if (size)
|
|
||||||
*size = 0;
|
|
||||||
|
|
||||||
iFd = open(filepath, O_RDONLY);
|
|
||||||
if (iFd < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
filesize = lseek(iFd, 0, SEEK_END);
|
|
||||||
lseek(iFd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
buffer = (u8 *) malloc(filesize);
|
|
||||||
if (buffer == NULL)
|
|
||||||
{
|
|
||||||
close(iFd);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(done < filesize)
|
|
||||||
{
|
|
||||||
if (done + blocksize > filesize)
|
|
||||||
blocksize = filesize - done;
|
|
||||||
readBytes = read(iFd, buffer + done, blocksize);
|
|
||||||
if (readBytes <= 0)
|
|
||||||
break;
|
|
||||||
done += readBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(iFd);
|
|
||||||
|
|
||||||
if (done != filesize)
|
|
||||||
{
|
|
||||||
free(buffer);
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
*inbuffer = buffer;
|
|
||||||
|
|
||||||
/* sign is optional input */
|
|
||||||
if (size)
|
|
||||||
*size = filesize;
|
|
||||||
|
|
||||||
return filesize;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CheckFile(const char * filepath)
|
|
||||||
{
|
|
||||||
struct stat filestat;
|
|
||||||
char *notRoot = NULL;
|
|
||||||
|
|
||||||
if (!filepath)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
char dirnoslash[strlen(filepath)+2];
|
|
||||||
|
|
||||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
|
||||||
|
|
||||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
|
||||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
|
||||||
|
|
||||||
notRoot = strrchr(dirnoslash, '/');
|
|
||||||
if (!notRoot)
|
|
||||||
strcat(dirnoslash, "/");
|
|
||||||
|
|
||||||
if (stat(dirnoslash, &filestat) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CreateSubfolder(const char * fullpath)
|
|
||||||
{
|
|
||||||
int pos;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
if (!fullpath)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
char dirnoslash[strlen(fullpath)+1];
|
|
||||||
strcpy(dirnoslash, fullpath);
|
|
||||||
|
|
||||||
pos = strlen(dirnoslash)-1;
|
|
||||||
while(dirnoslash[pos] == '/')
|
|
||||||
{
|
|
||||||
dirnoslash[pos] = '\0';
|
|
||||||
pos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckFile(dirnoslash))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
{
|
|
||||||
char *ptr;
|
|
||||||
char parentpath[strlen(dirnoslash)+2];
|
|
||||||
strcpy(parentpath, dirnoslash);
|
|
||||||
ptr = strrchr(parentpath, '/');
|
|
||||||
|
|
||||||
if (!ptr)
|
|
||||||
{
|
|
||||||
/* Device root directory (must be with '/') */
|
|
||||||
struct stat filestat;
|
|
||||||
strcat(parentpath, "/");
|
|
||||||
|
|
||||||
if (stat(parentpath, &filestat) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr++;
|
|
||||||
ptr[0] = '\0';
|
|
||||||
|
|
||||||
result = CreateSubfolder(parentpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (mkdir(dirnoslash, 0777) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,13 +8,6 @@ extern "C" {
|
||||||
#include <wiiu/types.h>
|
#include <wiiu/types.h>
|
||||||
|
|
||||||
int MountFS(void *pClient, void *pCmd, char **mount_path);
|
int MountFS(void *pClient, void *pCmd, char **mount_path);
|
||||||
int UmountFS(void *pClient, void *pCmd, const char *mountPath);
|
|
||||||
|
|
||||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size);
|
|
||||||
|
|
||||||
/* TODO/FIXME: C++ class */
|
|
||||||
int CreateSubfolder(const char * fullpath);
|
|
||||||
int CheckFile(const char * filepath);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,9 @@ typedef struct _sd_fat_dir_entry_t {
|
||||||
|
|
||||||
static sd_fat_private_t *sd_fat_get_device_data(const char *path)
|
static sd_fat_private_t *sd_fat_get_device_data(const char *path)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
const devoptab_t *devoptab = NULL;
|
const devoptab_t *devoptab = NULL;
|
||||||
char name[128] = {0};
|
char name[128] = {0};
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Get the device name from the path */
|
/* Get the device name from the path */
|
||||||
strncpy(name, path, 127);
|
strncpy(name, path, 127);
|
||||||
|
@ -668,7 +668,8 @@ static int sd_fat_mkdir_r (struct _reent *r, const char *path, int mode)
|
||||||
|
|
||||||
OSUnlockMutex(dev->pMutex);
|
OSUnlockMutex(dev->pMutex);
|
||||||
|
|
||||||
if(result < 0) {
|
if(result < 0)
|
||||||
|
{
|
||||||
r->_errno = result;
|
r->_errno = result;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -679,7 +680,8 @@ static int sd_fat_mkdir_r (struct _reent *r, const char *path, int mode)
|
||||||
static int sd_fat_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
|
static int sd_fat_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
|
||||||
{
|
{
|
||||||
sd_fat_private_t *dev = sd_fat_get_device_data(path);
|
sd_fat_private_t *dev = sd_fat_get_device_data(path);
|
||||||
if(!dev) {
|
if (!dev)
|
||||||
|
{
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -826,7 +828,8 @@ static int sd_fat_dirreset_r (struct _reent *r, DIR_ITER *dirState)
|
||||||
static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st)
|
static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st)
|
||||||
{
|
{
|
||||||
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
|
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
|
||||||
if(!dirIter->dev) {
|
if(!dirIter->dev)
|
||||||
|
{
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -899,20 +902,21 @@ static const devoptab_t devops_sd_fat = {
|
||||||
|
|
||||||
static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd)
|
static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
devoptab_t *dev = NULL;
|
devoptab_t *dev = NULL;
|
||||||
char *devname = NULL;
|
char *devname = NULL;
|
||||||
char *devpath = NULL;
|
char *devpath = NULL;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (!name) {
|
if (!name)
|
||||||
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a devoptab for this device */
|
/* Allocate a devoptab for this device */
|
||||||
dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1);
|
if (!(dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1)))
|
||||||
if (!dev) {
|
{
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -923,7 +927,8 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||||
|
|
||||||
/* create private data */
|
/* create private data */
|
||||||
sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1);
|
sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1);
|
||||||
if(!priv) {
|
if (!priv)
|
||||||
|
{
|
||||||
free(dev);
|
free(dev);
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -938,7 +943,8 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||||
priv->pCmd = pCmd;
|
priv->pCmd = pCmd;
|
||||||
priv->pMutex = malloc(sizeof(OSMutex));
|
priv->pMutex = malloc(sizeof(OSMutex));
|
||||||
|
|
||||||
if(!priv->pMutex) {
|
if (!priv->pMutex)
|
||||||
|
{
|
||||||
free(dev);
|
free(dev);
|
||||||
free(priv);
|
free(priv);
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
|
@ -953,8 +959,10 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||||
dev->deviceData = priv;
|
dev->deviceData = priv;
|
||||||
|
|
||||||
/* Add the device to the devoptab table (if there is a free slot) */
|
/* Add the device to the devoptab table (if there is a free slot) */
|
||||||
for (i = 3; i < STD_MAX; i++) {
|
for (i = 3; i < STD_MAX; i++)
|
||||||
if (devoptab_list[i] == devoptab_list[0]) {
|
{
|
||||||
|
if (devoptab_list[i] == devoptab_list[0])
|
||||||
|
{
|
||||||
devoptab_list[i] = dev;
|
devoptab_list[i] = dev;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -971,9 +979,9 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||||
|
|
||||||
static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath)
|
static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
const devoptab_t *devoptab = NULL;
|
const devoptab_t *devoptab = NULL;
|
||||||
char name[128] = {0};
|
char name[128] = {0};
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Get the device name from the path */
|
/* Get the device name from the path */
|
||||||
strncpy(name, path, 127);
|
strncpy(name, path, 127);
|
||||||
|
@ -983,10 +991,13 @@ static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd,
|
||||||
/* NOTE: We do this manually due to a 'bug' in RemoveDevice */
|
/* NOTE: We do this manually due to a 'bug' in RemoveDevice */
|
||||||
/* which ignores names with suffixes and causes names */
|
/* which ignores names with suffixes and causes names */
|
||||||
/* like "ntfs" and "ntfs1" to be seen as equals */
|
/* like "ntfs" and "ntfs1" to be seen as equals */
|
||||||
for (i = 3; i < STD_MAX; i++) {
|
for (i = 3; i < STD_MAX; i++)
|
||||||
|
{
|
||||||
devoptab = devoptab_list[i];
|
devoptab = devoptab_list[i];
|
||||||
if (devoptab && devoptab->name) {
|
if (devoptab && devoptab->name)
|
||||||
if (strcmp(name, devoptab->name) == 0) {
|
{
|
||||||
|
if (strcmp(name, devoptab->name) == 0)
|
||||||
|
{
|
||||||
devoptab_list[i] = devoptab_list[0];
|
devoptab_list[i] = devoptab_list[0];
|
||||||
|
|
||||||
if(devoptab->deviceData)
|
if(devoptab->deviceData)
|
||||||
|
@ -1013,13 +1024,14 @@ static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd,
|
||||||
|
|
||||||
int mount_sd_fat(const char *path)
|
int mount_sd_fat(const char *path)
|
||||||
{
|
{
|
||||||
|
char *mountPath = NULL;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
/* get command and client */
|
/* get command and client */
|
||||||
void* pClient = malloc(sizeof(FSClient));
|
void* pClient = malloc(sizeof(FSClient));
|
||||||
void* pCmd = malloc(sizeof(FSCmdBlock));
|
void* pCmd = malloc(sizeof(FSCmdBlock));
|
||||||
|
|
||||||
if(!pClient || !pCmd) {
|
if(!pClient || !pCmd)
|
||||||
|
{
|
||||||
/* just in case free if not 0 */
|
/* just in case free if not 0 */
|
||||||
if(pClient)
|
if(pClient)
|
||||||
free(pClient);
|
free(pClient);
|
||||||
|
@ -1032,9 +1044,8 @@ int mount_sd_fat(const char *path)
|
||||||
FSInitCmdBlock(pCmd);
|
FSInitCmdBlock(pCmd);
|
||||||
FSAddClient(pClient, -1);
|
FSAddClient(pClient, -1);
|
||||||
|
|
||||||
char *mountPath = NULL;
|
if(MountFS(pClient, pCmd, &mountPath) == 0)
|
||||||
|
{
|
||||||
if(MountFS(pClient, pCmd, &mountPath) == 0) {
|
|
||||||
result = sd_fat_add_device(path, mountPath, pClient, pCmd);
|
result = sd_fat_add_device(path, mountPath, pClient, pCmd);
|
||||||
free(mountPath);
|
free(mountPath);
|
||||||
}
|
}
|
||||||
|
@ -1051,7 +1062,7 @@ int unmount_sd_fat(const char *path)
|
||||||
int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath);
|
int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath);
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
UmountFS(pClient, pCmd, mountPath);
|
FSUnmount(pClient, pCmd, mountPath, -1);
|
||||||
FSDelClient(pClient, -1);
|
FSDelClient(pClient, -1);
|
||||||
free(pClient);
|
free(pClient);
|
||||||
free(pCmd);
|
free(pCmd);
|
||||||
|
|
|
@ -182,7 +182,7 @@ static void try_shutdown_iosuhax(void)
|
||||||
MCPHookClose();
|
MCPHookClose();
|
||||||
else
|
else
|
||||||
IOSUHAX_Close();
|
IOSUHAX_Close();
|
||||||
#endif //HAVE_IOSUHAX
|
#endif /* HAVE_IOSUHAX */
|
||||||
|
|
||||||
iosuhaxMount = false;
|
iosuhaxMount = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user