diff options
Diffstat (limited to 'include/user/kernel/iofilemgr')
-rw-r--r-- | include/user/kernel/iofilemgr/async.h | 104 | ||||
-rw-r--r-- | include/user/kernel/iofilemgr/dirent.h | 82 | ||||
-rw-r--r-- | include/user/kernel/iofilemgr/stat.h | 101 | ||||
-rw-r--r-- | include/user/kernel/iofilemgr/syscall.h | 79 |
4 files changed, 366 insertions, 0 deletions
diff --git a/include/user/kernel/iofilemgr/async.h b/include/user/kernel/iofilemgr/async.h new file mode 100644 index 0000000..77fac3d --- /dev/null +++ b/include/user/kernel/iofilemgr/async.h @@ -0,0 +1,104 @@ +#ifndef _DOLCESDK_PSP2_KERNEL_IOFILEMGR_ASYNC_H_ +#define _DOLCESDK_PSP2_KERNEL_IOFILEMGR_ASYNC_H_ + +#include <psp2common/kernel/iofilemgr/async.h> +#include <psp2/kernel/threadmgr.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Async IO operations are scheduled automatically, similar to FIOS2. + * You can make calls to sceIoOpenAsync(), sceIoReadAsync(), + * sceIoCloseAsync() right after each other, they will be put in a schedule + * and performed automatically. + * + * All async IO functions return UID of operation handle, not file descriptor UID. + */ + +/** + * Cancel an asynchronous operation. + * + * @param opHandle - The operation handle to perform cancel on. + * + * @return < 0 on error. If operation has been canceled(finished) already, returns 0x80010002 + */ +int sceIoCancel(SceUID opHandle); + +/** + * Complete an asynchronous operation. + * + * @param opHandle - The operation handle to complete. + * + * @return < 0 on error. + */ +int sceIoComplete(SceUID opHandle); + +/** + * Complete multiple asynchronous operations. + * + * @param asyncParam - Array of ::SceIoAsyncParam representing IO operations to complete. retVal member must have opHandle value assigned to it. + * @param numOfParam - Number of ::SceIoAsyncParam structs in asyncParam array + * @param numOfCompleted - Number of operations that has been completed successfully + * + * @return < 0 on last encountered error. + */ +int sceIoCompleteMultiple(SceIoAsyncParam* asyncParam, int numOfParam, int* numOfCompleted); + +/** + * Wait until asynchronous operation has been finished. + * + * @param opHandle - The operation handle to wait for. + * + * @return < 0 on error. + */ +inline +int sceIoWaitAsync(SceUID opHandle) +{ + int ret = sceKernelWaitEvent(opHandle, 1, NULL, NULL, NULL); + if (ret == 0) + return sceIoComplete(opHandle); + else + return ret; +} + +/** + * Wait until asynchronous operation has been finished with callbacks. + * + * @param opHandle - The operation handle to wait for. + * + * @return < 0 on error. + */ +inline +int sceIoWaitAsyncCB(SceUID opHandle) +{ + int ret = sceKernelWaitEventCB(opHandle, 1, NULL, NULL, NULL); + if (ret == 0) + return sceIoComplete(opHandle); + else + return ret; +} + +/** + * Poll asynchronous operation status. + * + * @param opHandle - The operation handle to poll status for. + * + * @return < 0 on error or if operation is not finished. + */ +inline +int sceIoPollAsync(SceUID opHandle) +{ + int ret = sceKernelPollEvent(opHandle, 1, NULL, NULL); + if (ret == 0) + return sceIoComplete(opHandle); + else + return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _DOLCESDK_PSP2_KERNEL_IOFILEMGR_ASYNC_H_ */ diff --git a/include/user/kernel/iofilemgr/dirent.h b/include/user/kernel/iofilemgr/dirent.h new file mode 100644 index 0000000..c518a08 --- /dev/null +++ b/include/user/kernel/iofilemgr/dirent.h @@ -0,0 +1,82 @@ +#ifndef _DOLCESDK_PSP2_KERNEL_IOFILEMGR_DIRENT_H_ +#define _DOLCESDK_PSP2_KERNEL_IOFILEMGR_DIRENT_H_ + +#include <psp2common/kernel/iofilemgr/dirent.h> +#include <psp2/kernel/iofilemgr/async.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Open a directory + * + * @par Example: + * @code + * int dfd; + * dfd = sceIoDopen("device:/"); + * if(dfd >= 0) + * { Do something with the file descriptor } + * @endcode + * @param dirname - The directory to open for reading. + * @return If >= 0 then a valid file descriptor, otherwise a Sony error code. + */ +SceUID sceIoDopen(const char *dirname); + +/** + * Close an opened directory file descriptor + * + * @param fd - Already opened file descriptor (using ::sceIoDopen) + * @return < 0 on error + */ +int sceIoDclose(SceUID fd); + +/** + * Reads an entry from an opened file descriptor. + * + * @param fd - Already opened file descriptor (using ::sceIoDopen) + * @param buf - Pointer to a ::SceIoDirent structure to hold the file information + * + * @return Read status + * - 0 - No more directory entries left + * - > 0 - More directory entries to go + * - < 0 - Error + */ +int sceIoDread(SceUID fd, SceIoDirent *buf); + +/** + * Open a directory (asynchronous) + * + * @param dirname - The directory to open for reading. + * @param asyncParam - parameters related to async operation. + * + * @return If >= 0 then a valid op handle, otherwise a Sony error code. + */ +SceUID sceIoDopenAsync(const char *dirname, SceIoAsyncParam* asyncParam); + +/** + * Reads an entry from an opened file descriptor (asynchronous) + * + * @param fd - Already opened file descriptor (using ::sceIoDopen or ::sceIoDopenAsync) + * @param dir - Pointer to a ::SceIoDirent structure to hold the file information + * @param asyncParam - parameters related to async operation. + * + * @return If >= 0 then a valid op handle, otherwise a Sony error code. + */ +SceUID sceIoDreadAsync(SceUID fd, SceIoDirent *dir, SceIoAsyncParam* asyncParam); + +/** + * Close an opened directory file descriptor (asynchronous) + * + * @param fd - Already opened file descriptor (using ::sceIoDopen or ::sceIoDopenAsync) + * @param asyncParam - parameters related to async operation. + * + * @return If >= 0 then a valid op handle, otherwise a Sony error code. + */ +SceUID sceIoDcloseAsync(SceUID fd, SceIoAsyncParam* asyncParam); + +#ifdef __cplusplus +} +#endif + +#endif /* _DOLCESDK_PSP2_KERNEL_IOFILEMGR_DIRENT_H_ */ diff --git a/include/user/kernel/iofilemgr/stat.h b/include/user/kernel/iofilemgr/stat.h new file mode 100644 index 0000000..b0b57f6 --- /dev/null +++ b/include/user/kernel/iofilemgr/stat.h @@ -0,0 +1,101 @@ +#ifndef _DOLCESDK_PSP2_KERNEL_IOFILEMGR_STAT_H_ +#define _DOLCESDK_PSP2_KERNEL_IOFILEMGR_STAT_H_ + +#include <psp2common/kernel/iofilemgr/stat.h> +#include <psp2/kernel/iofilemgr/async.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Change the status of a file. + * + * @param name - The path to the file. + * @param buf - A pointer to a ::SceIoStat structure. + * @param cbit - Bitmask defining which bits to change. + * + * @return < 0 on error. + */ +int sceIoChstat(const char *name, const SceIoStat *buf, unsigned int cbit); + +/** + * Get the status of a file. + * + * @param name - The path to the file. + * @param buf - A pointer to a ::SceIoStat structure. + * + * @return < 0 on error. + */ +int sceIoGetstat(const char *name, SceIoStat *buf); + +/** + * Get the status of a file descriptor. + * + * @param fd - The file descriptor. + * @param buf - A pointer to a ::SceIoStat structure. + * + * @return < 0 on error. + */ +int sceIoGetstatByFd(SceUID fd, SceIoStat *buf); + +/** + * Change the status of a file descriptor. + * + * @param fd - The file descriptor. + * @param buf - A pointer to an io_stat_t structure. + * @param cbit - Bitmask defining which bits to change. + * + * @return < 0 on error. + */ +int sceIoChstatByFd(SceUID fd, const SceIoStat *buf, unsigned int cbit); + +/** + * Make a directory file (asynchronous) + * + * @param dir - The path to the directory + * @param mode - Access mode (One or more ::SceIoAccessMode). + * @param asyncParam - parameters related to async operation. + * + * @return A non-negative integer is a valid op handle, anything else an error + */ +SceUID sceIoMkdirAsync(const char *dir, SceMode mode, SceIoAsyncParam* asyncParam); + +/** + * Remove a directory file (asynchronous) + * + * @param path - Removes a directory file pointed by the string path + * @param asyncParam - parameters related to async operation. + * + * @return A non-negative integer is a valid op handle, anything else an error + */ +SceUID sceIoRmdirAsync(const char *path, SceIoAsyncParam* asyncParam); + +/** + * Get the status of a file (asynchronous) + * + * @param file - The path to the file. + * @param stat - A pointer to a ::SceIoStat structure. + * @param asyncParam - parameters related to async operation. + * + * @return A non-negative integer is a valid op handle, anything else an error + */ +SceUID sceIoGetstatAsync(const char *file, SceIoStat *stat, SceIoAsyncParam* asyncParam); + +/** + * Change the status of a file (asynchronous) + * + * @param file - The path to the file. + * @param stat - A pointer to a ::SceIoStat structure. + * @param bits - Bitmask defining which bits to change. + * @param asyncParam - parameters related to async operation. + * + * @return A non-negative integer is a valid op handle, anything else an error + */ +SceUID sceIoChstatAsync(const char *file, SceIoStat *stat, int bits, SceIoAsyncParam* asyncParam); + +#ifdef __cplusplus +} +#endif + +#endif /* _DOLCESDK_PSP2_KERNEL_IOFILEMGR_STAT_H_ */ diff --git a/include/user/kernel/iofilemgr/syscall.h b/include/user/kernel/iofilemgr/syscall.h new file mode 100644 index 0000000..c47623a --- /dev/null +++ b/include/user/kernel/iofilemgr/syscall.h @@ -0,0 +1,79 @@ +#ifndef _DOLCESDK_PSP2_KERNEL_IOFILEMGR_SYSCALL_H_ +#define _DOLCESDK_PSP2_KERNEL_IOFILEMGR_SYSCALL_H_ + +#include <psp2/kernel/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Struct definitions */ + +typedef struct SceIoUnusedSyscallParam0x8 { + char unused[0x8]; +} SceIoUnusedSyscallParam0x8; + +typedef struct SceIoUnusedSyscallParam0x10 { + char unused[0x10]; +} SceIoUnusedSyscallParam0x10; + +typedef struct SceIoDevctlSyscallParam { + SceSize arglen; + void *bufp; + SceSize buflen; + char unused[0xC]; + // size 0x18 +} SceIoDevctlSyscallParam; + +typedef struct SceIoIoctlSyscallParam { + SceSize arglen; + void *bufp; + SceSize buflen; + char unused[0x4]; + // size 0x10 +} SceIoIoctlSyscallParam; + +typedef struct SceIoLseekSyscallParam { + SceOff offset; + int whence; + char unused[0x4]; + // size 0x10 +} SceIoLseekSyscallParam; + +typedef struct SceIoPreadSyscallParam { + SceOff offset; + char unused[0x8]; + // size 0x10 +} SceIoPreadSyscallParam; + +typedef SceIoPreadSyscallParam SceIoPwriteSyscallParam; + +/* Function declarations */ + +SceUID _sceIoRemove(const char *filename, SceIoUnusedSyscallParam0x8 param); + +int _sceIoMkdir(const char *dirname, SceIoMode mode, SceIoUnusedSyscallParam0x8 param); + +int _sceIoRmdir(const char *dirname, SceIoUnusedSyscallParam0x8 param); + +int _sceIoRename(const char *oldname, const char *newname, SceIoUnusedSyscallParam0x10 param); + +int _sceIoDevctl(const char *devname, int cmd, const void *arg, SceIoDevctlSyscallParam param); + +int _sceIoSync(const char *devname, int flag, SceIoUnusedSyscallParam0x8 param); + +SceUID _sceIoOpen(const char *filename, int flag, SceIoMode mode, SceIoUnusedSyscallParam0x8 param); + +int _sceIoIoctl(SceUID fd, int cmd, const void *argp, SceIoIoctlSyscallParam param); + +SceOff _sceIoLseek(SceUID fd, SceIoLseekSyscallParam param); + +SceSSize _sceIoPread(SceUID fd, void *buf, SceSize nbyte, SceIoPreadSyscallParam param); + +SceSSize _sceIoPwrite(SceUID fd, const void *buf, SceSize nbyte, SceIoPwriteSyscallParam param); + +#ifdef __cplusplus +} +#endif + +#endif /* _DOLCESDK_PSP2_KERNEL_IOFILEMGR_SYSCALL_H_ */ |