mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-07 09:57:49 +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)
|
||||
return -3;
|
||||
|
||||
mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
||||
|
||||
if (!mountPath)
|
||||
if (!(mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE)))
|
||||
{
|
||||
free(mountSrc);
|
||||
return -4;
|
||||
@ -66,143 +64,3 @@ int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||
free(mountSrc);
|
||||
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>
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -84,9 +84,9 @@ typedef struct _sd_fat_dir_entry_t {
|
||||
|
||||
static sd_fat_private_t *sd_fat_get_device_data(const char *path)
|
||||
{
|
||||
int i;
|
||||
const devoptab_t *devoptab = NULL;
|
||||
char name[128] = {0};
|
||||
int i;
|
||||
|
||||
/* Get the device name from the path */
|
||||
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);
|
||||
|
||||
if(result < 0) {
|
||||
if(result < 0)
|
||||
{
|
||||
r->_errno = result;
|
||||
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)
|
||||
{
|
||||
sd_fat_private_t *dev = sd_fat_get_device_data(path);
|
||||
if(!dev) {
|
||||
if (!dev)
|
||||
{
|
||||
r->_errno = ENODEV;
|
||||
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)
|
||||
{
|
||||
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
|
||||
if(!dirIter->dev) {
|
||||
if(!dirIter->dev)
|
||||
{
|
||||
r->_errno = ENODEV;
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
devoptab_t *dev = NULL;
|
||||
char *devname = NULL;
|
||||
char *devpath = NULL;
|
||||
int i;
|
||||
|
||||
/* Sanity check */
|
||||
if (!name) {
|
||||
if (!name)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Allocate a devoptab for this device */
|
||||
dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1);
|
||||
if (!dev) {
|
||||
if (!(dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1)))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -923,22 +927,24 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||
|
||||
/* create private data */
|
||||
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);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
devpath = (char*)(priv+1);
|
||||
devpath = (char*)(priv+1);
|
||||
strcpy(devpath, mount_path);
|
||||
|
||||
/* setup private data */
|
||||
priv->mount_path = devpath;
|
||||
priv->pClient = pClient;
|
||||
priv->pCmd = pCmd;
|
||||
priv->pMutex = malloc(sizeof(OSMutex));
|
||||
priv->pClient = pClient;
|
||||
priv->pCmd = pCmd;
|
||||
priv->pMutex = malloc(sizeof(OSMutex));
|
||||
|
||||
if(!priv->pMutex) {
|
||||
if (!priv->pMutex)
|
||||
{
|
||||
free(dev);
|
||||
free(priv);
|
||||
errno = ENOMEM;
|
||||
@ -953,8 +959,10 @@ static int sd_fat_add_device (const char *name, const char *mount_path, void *pC
|
||||
dev->deviceData = priv;
|
||||
|
||||
/* Add the device to the devoptab table (if there is a free slot) */
|
||||
for (i = 3; i < STD_MAX; i++) {
|
||||
if (devoptab_list[i] == devoptab_list[0]) {
|
||||
for (i = 3; i < STD_MAX; i++)
|
||||
{
|
||||
if (devoptab_list[i] == devoptab_list[0])
|
||||
{
|
||||
devoptab_list[i] = dev;
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
const devoptab_t *devoptab = NULL;
|
||||
char name[128] = {0};
|
||||
int i;
|
||||
|
||||
/* Get the device name from the path */
|
||||
strncpy(name, path, 127);
|
||||
@ -983,27 +991,30 @@ static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd,
|
||||
/* NOTE: We do this manually due to a 'bug' in RemoveDevice */
|
||||
/* which ignores names with suffixes and causes names */
|
||||
/* 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];
|
||||
if (devoptab && devoptab->name) {
|
||||
if (strcmp(name, devoptab->name) == 0) {
|
||||
devoptab_list[i] = devoptab_list[0];
|
||||
if (devoptab && devoptab->name)
|
||||
{
|
||||
if (strcmp(name, devoptab->name) == 0)
|
||||
{
|
||||
devoptab_list[i] = devoptab_list[0];
|
||||
|
||||
if(devoptab->deviceData)
|
||||
{
|
||||
sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData;
|
||||
*pClient = priv->pClient;
|
||||
*pCmd = priv->pCmd;
|
||||
*mountPath = (char*) malloc(strlen(priv->mount_path)+1);
|
||||
if(*mountPath)
|
||||
strcpy(*mountPath, priv->mount_path);
|
||||
if(priv->pMutex)
|
||||
free(priv->pMutex);
|
||||
free(devoptab->deviceData);
|
||||
}
|
||||
if(devoptab->deviceData)
|
||||
{
|
||||
sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData;
|
||||
*pClient = priv->pClient;
|
||||
*pCmd = priv->pCmd;
|
||||
*mountPath = (char*) malloc(strlen(priv->mount_path)+1);
|
||||
if(*mountPath)
|
||||
strcpy(*mountPath, priv->mount_path);
|
||||
if(priv->pMutex)
|
||||
free(priv->pMutex);
|
||||
free(devoptab->deviceData);
|
||||
}
|
||||
|
||||
free((devoptab_t*)devoptab);
|
||||
return 0;
|
||||
free((devoptab_t*)devoptab);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1013,30 +1024,30 @@ static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd,
|
||||
|
||||
int mount_sd_fat(const char *path)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
char *mountPath = NULL;
|
||||
int result = -1;
|
||||
/* get command and client */
|
||||
void* pClient = malloc(sizeof(FSClient));
|
||||
void* pCmd = malloc(sizeof(FSCmdBlock));
|
||||
void* pClient = malloc(sizeof(FSClient));
|
||||
void* pCmd = malloc(sizeof(FSCmdBlock));
|
||||
|
||||
if(!pClient || !pCmd) {
|
||||
/* just in case free if not 0 */
|
||||
if(pClient)
|
||||
free(pClient);
|
||||
if(pCmd)
|
||||
free(pCmd);
|
||||
return -2;
|
||||
if(!pClient || !pCmd)
|
||||
{
|
||||
/* just in case free if not 0 */
|
||||
if(pClient)
|
||||
free(pClient);
|
||||
if(pCmd)
|
||||
free(pCmd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
FSInit();
|
||||
FSInitCmdBlock(pCmd);
|
||||
FSAddClient(pClient, -1);
|
||||
|
||||
char *mountPath = NULL;
|
||||
|
||||
if(MountFS(pClient, pCmd, &mountPath) == 0) {
|
||||
result = sd_fat_add_device(path, mountPath, pClient, pCmd);
|
||||
free(mountPath);
|
||||
if(MountFS(pClient, pCmd, &mountPath) == 0)
|
||||
{
|
||||
result = sd_fat_add_device(path, mountPath, pClient, pCmd);
|
||||
free(mountPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -1051,7 +1062,7 @@ int unmount_sd_fat(const char *path)
|
||||
int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath);
|
||||
if(result == 0)
|
||||
{
|
||||
UmountFS(pClient, pCmd, mountPath);
|
||||
FSUnmount(pClient, pCmd, mountPath, -1);
|
||||
FSDelClient(pClient, -1);
|
||||
free(pClient);
|
||||
free(pCmd);
|
||||
|
@ -182,7 +182,7 @@ static void try_shutdown_iosuhax(void)
|
||||
MCPHookClose();
|
||||
else
|
||||
IOSUHAX_Close();
|
||||
#endif //HAVE_IOSUHAX
|
||||
#endif /* HAVE_IOSUHAX */
|
||||
|
||||
iosuhaxMount = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user