mirror of
https://github.com/wiiu-env/ftpiiu.git
synced 2024-11-06 01:55:07 +01:00
Ftpiiu everywhere changes (#4)
* added support for mcp hook iosuhax version * use opendir instead of stat to see if directory exists
This commit is contained in:
parent
97ef903f98
commit
8709182ed2
2
Makefile
2
Makefile
@ -56,7 +56,7 @@ MAKEFLAGS += --no-print-directory
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# any extra libraries we wish to link with the project
|
# any extra libraries we wish to link with the project
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBS := -lgcc -lgd -lpng -lz -lfreetype -lvorbisidec -lfat -liosuhax
|
LIBS := -lgcc -lfat -liosuhax
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
@ -75,6 +75,7 @@ EXPORT_DECL(int, OSScreenPutFontEx, unsigned int bufferNum, unsigned int posX, u
|
|||||||
EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable);
|
EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable);
|
||||||
|
|
||||||
EXPORT_DECL(int, IOS_Ioctl,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
|
EXPORT_DECL(int, IOS_Ioctl,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
|
||||||
|
EXPORT_DECL(int, IOS_IoctlAsync,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len, void *cb, void *cbarg);
|
||||||
EXPORT_DECL(int, IOS_Open,char *path, unsigned int mode);
|
EXPORT_DECL(int, IOS_Open,char *path, unsigned int mode);
|
||||||
EXPORT_DECL(int, IOS_Close,int fd);
|
EXPORT_DECL(int, IOS_Close,int fd);
|
||||||
|
|
||||||
@ -94,6 +95,12 @@ EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned
|
|||||||
EXPORT_DECL(void *, MEMDestroyExpHeap, int heap);
|
EXPORT_DECL(void *, MEMDestroyExpHeap, int heap);
|
||||||
EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr);
|
EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! MCP functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(int, MCP_Open, void);
|
||||||
|
EXPORT_DECL(int, MCP_Close, int handle);
|
||||||
|
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
//! Loader functions (not real rpl)
|
//! Loader functions (not real rpl)
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -150,6 +157,11 @@ void InitOSFunctionPointers(void)
|
|||||||
OS_FIND_EXPORT(coreinit_handle, OSLockMutex);
|
OS_FIND_EXPORT(coreinit_handle, OSLockMutex);
|
||||||
OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex);
|
OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex);
|
||||||
OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex);
|
OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex);
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! MCP functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MCP_Open);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MCP_Close);
|
||||||
|
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
//! Memory functions
|
//! Memory functions
|
||||||
@ -171,6 +183,7 @@ void InitOSFunctionPointers(void)
|
|||||||
//! Other function addresses
|
//! Other function addresses
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
OS_FIND_EXPORT(coreinit_handle, IOS_Ioctl);
|
OS_FIND_EXPORT(coreinit_handle, IOS_Ioctl);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, IOS_IoctlAsync);
|
||||||
OS_FIND_EXPORT(coreinit_handle, IOS_Open);
|
OS_FIND_EXPORT(coreinit_handle, IOS_Open);
|
||||||
OS_FIND_EXPORT(coreinit_handle, IOS_Close);
|
OS_FIND_EXPORT(coreinit_handle, IOS_Close);
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,12 @@ extern void (* OSLockMutex)(void* mutex);
|
|||||||
extern void (* OSUnlockMutex)(void* mutex);
|
extern void (* OSUnlockMutex)(void* mutex);
|
||||||
extern int (* OSTryLockMutex)(void* mutex);
|
extern int (* OSTryLockMutex)(void* mutex);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! MCP functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
extern int (* MCP_Open)(void);
|
||||||
|
extern int (* MCP_Close)(int handle);
|
||||||
|
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
//! System functions
|
//! System functions
|
||||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -106,6 +112,7 @@ extern void (* ICInvalidateRange)(const void *addr, u32 length);
|
|||||||
extern void* (* OSEffectiveToPhysical)(const void*);
|
extern void* (* OSEffectiveToPhysical)(const void*);
|
||||||
extern int (* __os_snprintf)(char* s, int n, const char * format, ...);
|
extern int (* __os_snprintf)(char* s, int n, const char * format, ...);
|
||||||
extern int (*IOS_Ioctl)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
|
extern int (*IOS_Ioctl)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
|
||||||
|
extern int (*IOS_IoctlAsync)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len, void *cb, void *cbarg);
|
||||||
extern int (*IOS_Open)(char *path, unsigned int mode);
|
extern int (*IOS_Open)(char *path, unsigned int mode);
|
||||||
extern int (*IOS_Close)(int fd);
|
extern int (*IOS_Close)(int fd);
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
|||||||
*inbuffer = buffer;
|
*inbuffer = buffer;
|
||||||
|
|
||||||
//! sign is optional input
|
//! sign is optional input
|
||||||
if(size)
|
if(size) {
|
||||||
*size = filesize;
|
*size = filesize;
|
||||||
|
}
|
||||||
return filesize;
|
return filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
src/main.c
46
src/main.c
@ -83,6 +83,43 @@ void console_printf(const char *format, ...)
|
|||||||
OSScreenFlipBuffersEx(1);
|
OSScreenFlipBuffersEx(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//just to be able to call async
|
||||||
|
void someFunc(void *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mcp_hook_fd = -1;
|
||||||
|
int MCPHookOpen()
|
||||||
|
{
|
||||||
|
//take over mcp thread
|
||||||
|
mcp_hook_fd = MCP_Open();
|
||||||
|
if(mcp_hook_fd < 0)
|
||||||
|
return -1;
|
||||||
|
IOS_IoctlAsync(mcp_hook_fd, 0x62, (void*)0, 0, (void*)0, 0, someFunc, (void*)0);
|
||||||
|
//let wupserver start up
|
||||||
|
sleep(1);
|
||||||
|
if(IOSUHAX_Open("/dev/mcp") < 0)
|
||||||
|
{
|
||||||
|
MCP_Close(mcp_hook_fd);
|
||||||
|
mcp_hook_fd = -1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCPHookClose()
|
||||||
|
{
|
||||||
|
if(mcp_hook_fd < 0)
|
||||||
|
return;
|
||||||
|
//close down wupserver, return control to mcp
|
||||||
|
IOSUHAX_Close();
|
||||||
|
//wait for mcp to return
|
||||||
|
sleep(1);
|
||||||
|
MCP_Close(mcp_hook_fd);
|
||||||
|
mcp_hook_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Entry point */
|
/* Entry point */
|
||||||
int Menu_Main(void)
|
int Menu_Main(void)
|
||||||
{
|
{
|
||||||
@ -117,6 +154,8 @@ int Menu_Main(void)
|
|||||||
int iosuhaxMount = 0;
|
int iosuhaxMount = 0;
|
||||||
|
|
||||||
int res = IOSUHAX_Open(NULL);
|
int res = IOSUHAX_Open(NULL);
|
||||||
|
if(res < 0)
|
||||||
|
res = MCPHookOpen();
|
||||||
if(res < 0)
|
if(res < 0)
|
||||||
{
|
{
|
||||||
log_printf("IOSUHAX_open failed\n");
|
log_printf("IOSUHAX_open failed\n");
|
||||||
@ -183,7 +222,7 @@ int Menu_Main(void)
|
|||||||
OSScreenFlipBuffersEx(0);
|
OSScreenFlipBuffersEx(0);
|
||||||
OSScreenFlipBuffersEx(1);
|
OSScreenFlipBuffersEx(1);
|
||||||
|
|
||||||
console_printf("FTPiiU v0.4 is listening on %u.%u.%u.%u:%i", (network_gethostip() >> 24) & 0xFF, (network_gethostip() >> 16) & 0xFF, (network_gethostip() >> 8) & 0xFF, (network_gethostip() >> 0) & 0xFF, PORT);
|
console_printf("FTPiiU v0.4u2 is listening on %u.%u.%u.%u:%i", (network_gethostip() >> 24) & 0xFF, (network_gethostip() >> 16) & 0xFF, (network_gethostip() >> 8) & 0xFF, (network_gethostip() >> 0) & 0xFF, PORT);
|
||||||
|
|
||||||
int serverSocket = create_server(PORT);
|
int serverSocket = create_server(PORT);
|
||||||
|
|
||||||
@ -253,7 +292,10 @@ int Menu_Main(void)
|
|||||||
unmount_fs("storage_mlc");
|
unmount_fs("storage_mlc");
|
||||||
unmount_fs("storage_usb");
|
unmount_fs("storage_usb");
|
||||||
IOSUHAX_FSA_Close(fsaFd);
|
IOSUHAX_FSA_Close(fsaFd);
|
||||||
IOSUHAX_Close();
|
if(mcp_hook_fd >= 0)
|
||||||
|
MCPHookClose();
|
||||||
|
else
|
||||||
|
IOSUHAX_Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
30
src/vrt.c
30
src/vrt.c
@ -154,6 +154,16 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int checkdir(char *path) {
|
||||||
|
DIR *dir = opendir(path);
|
||||||
|
if(dir)
|
||||||
|
{
|
||||||
|
closedir(dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
typedef void * (*path_func)(char *path, ...);
|
typedef void * (*path_func)(char *path, ...);
|
||||||
|
|
||||||
static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_path, s32 failed, ...) {
|
static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_path, s32 failed, ...) {
|
||||||
@ -205,13 +215,23 @@ int vrt_stat(char *cwd, char *path, struct stat *st) {
|
|||||||
return (int)with_virtual_path(cwd, stat, path, -1, st, NULL);
|
return (int)with_virtual_path(cwd, stat, path, -1, st, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int vrt_checkdir(char *cwd, char *path) {
|
||||||
|
char *real_path = to_real_path(cwd, path);
|
||||||
|
if (!real_path)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (!*real_path || (strcmp(path, ".") == 0) || (strlen(cwd) == 1) || ((strlen(cwd) > 1) && (strcmp(path, "..") == 0)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
free(real_path);
|
||||||
|
return (int)with_virtual_path(cwd, checkdir, path, -1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int vrt_chdir(char *cwd, char *path) {
|
int vrt_chdir(char *cwd, char *path) {
|
||||||
|
|
||||||
struct stat st;
|
if (vrt_checkdir(cwd, path)) {
|
||||||
if (vrt_stat(cwd, path, &st)) {
|
|
||||||
return -1;
|
|
||||||
} else if (!(st.st_mode & S_IFDIR)) {
|
|
||||||
errno = ENOTDIR;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char *abspath = virtual_abspath(cwd, path);
|
char *abspath = virtual_abspath(cwd, path);
|
||||||
|
Loading…
Reference in New Issue
Block a user