diff --git a/Makefile b/Makefile index 801cacb..cb35cd8 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ MAKEFLAGS += --no-print-directory #--------------------------------------------------------------------------------- # 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 diff --git a/src/dynamic_libs/os_functions.c b/src/dynamic_libs/os_functions.c index 93c4f5f..d9f59d7 100644 --- a/src/dynamic_libs/os_functions.c +++ b/src/dynamic_libs/os_functions.c @@ -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, 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_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, 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) //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -150,6 +157,11 @@ void InitOSFunctionPointers(void) OS_FIND_EXPORT(coreinit_handle, OSLockMutex); OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex); OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //! MCP functions + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + OS_FIND_EXPORT(coreinit_handle, MCP_Open); + OS_FIND_EXPORT(coreinit_handle, MCP_Close); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Memory functions @@ -171,6 +183,7 @@ void InitOSFunctionPointers(void) //! Other function addresses //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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_Close); } diff --git a/src/dynamic_libs/os_functions.h b/src/dynamic_libs/os_functions.h index 11c46b6..d11c6e0 100644 --- a/src/dynamic_libs/os_functions.h +++ b/src/dynamic_libs/os_functions.h @@ -95,6 +95,12 @@ extern void (* OSLockMutex)(void* mutex); extern void (* OSUnlockMutex)(void* mutex); extern int (* OSTryLockMutex)(void* mutex); +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! MCP functions +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +extern int (* MCP_Open)(void); +extern int (* MCP_Close)(int handle); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! System functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -106,6 +112,7 @@ extern void (* ICInvalidateRange)(const void *addr, u32 length); extern void* (* OSEffectiveToPhysical)(const void*); 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_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_Close)(int fd); diff --git a/src/fs/fs_utils.c b/src/fs/fs_utils.c index efa2e55..613cec6 100644 --- a/src/fs/fs_utils.c +++ b/src/fs/fs_utils.c @@ -95,9 +95,9 @@ int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size) *inbuffer = buffer; //! sign is optional input - if(size) + if(size) { *size = filesize; - + } return filesize; } diff --git a/src/main.c b/src/main.c index ab68275..cbe2fa0 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,43 @@ void console_printf(const char *format, ...) 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 */ int Menu_Main(void) { @@ -117,6 +154,8 @@ int Menu_Main(void) int iosuhaxMount = 0; int res = IOSUHAX_Open(NULL); + if(res < 0) + res = MCPHookOpen(); if(res < 0) { log_printf("IOSUHAX_open failed\n"); @@ -183,7 +222,7 @@ int Menu_Main(void) OSScreenFlipBuffersEx(0); 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); @@ -253,7 +292,10 @@ int Menu_Main(void) unmount_fs("storage_mlc"); unmount_fs("storage_usb"); IOSUHAX_FSA_Close(fsaFd); - IOSUHAX_Close(); + if(mcp_hook_fd >= 0) + MCPHookClose(); + else + IOSUHAX_Close(); } else { diff --git a/src/vrt.c b/src/vrt.c index e4ed863..dedf1f7 100644 --- a/src/vrt.c +++ b/src/vrt.c @@ -154,6 +154,16 @@ char *to_real_path(char *virtual_cwd, char *virtual_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, ...); 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); } +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) { - struct stat st; - if (vrt_stat(cwd, path, &st)) { - return -1; - } else if (!(st.st_mode & S_IFDIR)) { - errno = ENOTDIR; + if (vrt_checkdir(cwd, path)) { return -1; } char *abspath = virtual_abspath(cwd, path);