From 38eaa155cc6ecd28100b047f742be1f14746bc9a Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 18 Jun 2022 12:47:27 +0200 Subject: [PATCH] Add FSA structs and function declarations (#228) --- include/coreinit/filesystem.h | 203 +++++- include/coreinit/filesystem_fsa.h | 612 ++++++++++++++++++ include/coreinit/ipcbufpool.h | 138 ++++ .../test_compile_headers_list.h | 2 + 4 files changed, 930 insertions(+), 25 deletions(-) create mode 100644 include/coreinit/filesystem_fsa.h create mode 100644 include/coreinit/ipcbufpool.h diff --git a/include/coreinit/filesystem.h b/include/coreinit/filesystem.h index 71c734e5..72949636 100644 --- a/include/coreinit/filesystem.h +++ b/include/coreinit/filesystem.h @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include /** * \defgroup coreinit_fs Filesystem @@ -22,14 +25,21 @@ extern "C" { #endif +#define FS_MAX_PATH (0x27F) + typedef uint32_t FSDirectoryHandle; typedef uint32_t FSFileHandle; typedef uint32_t FSPriority; typedef uint64_t FSTime; +typedef struct FSFsm FSFsm; +typedef struct FSCmdQueue FSCmdQueue; +typedef struct FSClientBodyLink FSClientBodyLink; typedef struct FSAsyncData FSAsyncData; typedef struct FSAsyncResult FSAsyncResult; +typedef struct FSClientBody FSClientBody; typedef struct FSClient FSClient; +typedef struct FSCmdBlockBody FSCmdBlockBody; typedef struct FSCmdBlock FSCmdBlock; typedef struct FSDirectoryEntry FSDirectoryEntry; typedef struct FSMessage FSMessage; @@ -82,6 +92,7 @@ typedef enum FSStatus typedef enum FSError { + FS_ERROR_OK = 0, FS_ERROR_NOT_INIT = -0x30001, FS_ERROR_BUSY = -0x30002, FS_ERROR_CANCELLED = -0x30003, @@ -169,21 +180,137 @@ typedef enum FSVolumeState FS_VOLUME_STATE_INVALID = 11, } FSVolumeState; -typedef enum FSMountSourceType -{ - FS_MOUNT_SOURCE_SD = 0, - FS_MOUNT_SOURCE_UNK = 1, +typedef enum FSMediaState { + FS_MEDIA_STATE_READY = 0, + FS_MEDIA_STATE_NO_MEDIA = 1, + FS_MEDIA_STATE_INVALID_MEDIA = 2, + FS_MEDIA_STATE_DIRTY_MEDIA = 3, + FS_MEDIA_STATE_MEDIA_ERROR = 4, +} FSMediaState; + +typedef enum FSMountSourceType { + FS_MOUNT_SOURCE_SD = 0, + FS_MOUNT_SOURCE_UNK = 1, } FSMountSourceType; typedef void(*FSAsyncCallback)(FSClient *, FSCmdBlock *, FSStatus, uint32_t); typedef void(*FSStateChangeCallback)(FSClient *, FSVolumeState, void *); +struct FSFsm +{ + WUT_UNKNOWN_BYTES(0x38); +}; +WUT_CHECK_SIZE(FSFsm, 0x38); + +struct FSCmdQueue +{ + WUT_UNKNOWN_BYTES(0x44); +}; +WUT_CHECK_SIZE(FSCmdQueue, 0x44); + +struct FSMessage +{ + //! Message data + void *data; + + WUT_UNKNOWN_BYTES(8); + + //! Type of message + OSFunctionType type; +}; +WUT_CHECK_OFFSET(FSMessage, 0x00, data); +WUT_CHECK_OFFSET(FSMessage, 0x0C, type); +WUT_CHECK_SIZE(FSMessage, 0x10); + +/** + * Link entry used for FSClientBodyQueue. + */ +struct FSClientBodyLink +{ + FSClientBody* next; + FSClientBody* prev; +}; +WUT_CHECK_OFFSET(FSClientBodyLink, 0x00, next); +WUT_CHECK_OFFSET(FSClientBodyLink, 0x04, prev); +WUT_CHECK_SIZE(FSClientBodyLink, 0x8); + +struct FSClientBody +{ + WUT_UNKNOWN_BYTES(0x1444); + + //! IOSHandle returned from fsaShimOpen. + IOSHandle clientHandle; + + //! State machine. + FSFsm fsm; + + //! Command queue of FS commands. + FSCmdQueue cmdQueue; + + //! The last dequeued command. + FSCmdBlockBody* lastDequeuedCommand; + + //! Emulated error, set with FSSetEmulatedError. + FSError emulatedError; + + WUT_UNKNOWN_BYTES(0x1560 - 0x14CC); + + //! Mutex used to protect FSClientBody data. + OSFastMutex mutex; + + WUT_UNKNOWN_BYTES(4); + + //! Alarm used by fsm for unknown reasons. + OSAlarm fsmAlarm; + + //! Error of last FS command. + FSError lastError; + + bool isLastErrorWithoutVolume; + + //! Message used to send FsCmdHandler message when FSA async callback is received. + FSMessage fsCmdHandlerMsg; + + //! Device name of the last mount source returned by FSGetMountSourceNext. + char lastMountSourceDevice[0x10]; + + //! Mount source type to find with FSGetMountSourceNext. + FSMountSourceType findMountSourceType; + + //! Link used for linked list of clients. + FSClientBodyLink link; + + //! Pointer to unaligned FSClient structure. + FSClient* client; +}; +WUT_CHECK_OFFSET(FSClientBody, 0x1444, clientHandle); +WUT_CHECK_OFFSET(FSClientBody, 0x1448, fsm); +WUT_CHECK_OFFSET(FSClientBody, 0x1480, cmdQueue); +WUT_CHECK_OFFSET(FSClientBody, 0x14C4, lastDequeuedCommand); +WUT_CHECK_OFFSET(FSClientBody, 0x14C8, emulatedError); +WUT_CHECK_OFFSET(FSClientBody, 0x1560, mutex); +WUT_CHECK_OFFSET(FSClientBody, 0x1590, fsmAlarm); +WUT_CHECK_OFFSET(FSClientBody, 0x15E8, lastError); +WUT_CHECK_OFFSET(FSClientBody, 0x15EC, isLastErrorWithoutVolume); +WUT_CHECK_OFFSET(FSClientBody, 0x15F0, fsCmdHandlerMsg); +WUT_CHECK_OFFSET(FSClientBody, 0x1600, lastMountSourceDevice); +WUT_CHECK_OFFSET(FSClientBody, 0x1610, findMountSourceType); +WUT_CHECK_OFFSET(FSClientBody, 0x1614, link); +WUT_CHECK_OFFSET(FSClientBody, 0x161C, client); +WUT_CHECK_SIZE(FSClientBody, 0x1620); + struct FSClient { WUT_UNKNOWN_BYTES(0x1700); }; WUT_CHECK_SIZE(FSClient, 0x1700); +struct FSCmdBlockBody +{ + WUT_UNKNOWN_BYTES(0x9F8); +}; +WUT_CHECK_SIZE(FSCmdBlockBody, 0x9F8); + struct FSCmdBlock { WUT_UNKNOWN_BYTES(0xA80); @@ -224,20 +351,6 @@ struct FSStateChangeParams }; WUT_CHECK_SIZE(FSStateChangeParams, 0xC); -struct FSMessage -{ - //! Message data - void *data; - - WUT_UNKNOWN_BYTES(8); - - //! Type of message - OSFunctionType type; -}; -WUT_CHECK_OFFSET(FSMessage, 0x00, data); -WUT_CHECK_OFFSET(FSMessage, 0x0C, type); -WUT_CHECK_SIZE(FSMessage, 0x10); - struct FSAsyncData { FSAsyncCallback callback; @@ -290,15 +403,55 @@ struct FSMountSource }; WUT_CHECK_SIZE(FSMountSource, 0x300); -struct WUT_PACKED FSVolumeInfo -{ - WUT_UNKNOWN_BYTES(0xAC); - char volumeId[16]; - WUT_UNKNOWN_BYTES(0x100); +struct WUT_PACKED FSVolumeInfo { + uint32_t flags; + FSMediaState mediaState; + WUT_UNKNOWN_BYTES(0x4); + uint32_t unk0x0C; + uint32_t unk0x10; + int32_t unk0x14; + int32_t unk0x18; + WUT_UNKNOWN_BYTES(0x10); + char volumeLabel[128]; + char volumeId[128]; + char devicePath[16]; + char mountPath[128]; }; +WUT_CHECK_OFFSET(FSVolumeInfo, 0x00, flags); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x04, mediaState); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x0C, unk0x0C); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x10, unk0x10); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x14, unk0x14); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x18, unk0x18); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x2C, volumeLabel); WUT_CHECK_OFFSET(FSVolumeInfo, 0xAC, volumeId); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x12C, devicePath); +WUT_CHECK_OFFSET(FSVolumeInfo, 0x13C, mountPath); WUT_CHECK_SIZE(FSVolumeInfo, 444); + +/** + * Get an aligned FSClientBody from an FSClient. + */ +static inline FSClientBody * +FSGetClientBody(FSClient *client) { + if (!client) { + return NULL; + } + return (FSClientBody *) ((((uint32_t) client) + 0x3F) & ~0x3F); +} + +/** + * Get an aligned FSCmdBlockBody from an FSCmdBlock. + */ +static inline FSCmdBlockBody * +FSGetCmdBlockBody(FSCmdBlock *cmdBlock) { + if (!cmdBlock) { + return NULL; + } + return (FSCmdBlockBody *) ((((uint32_t) cmdBlock) + 0x3F) & ~0x3F); +} + void FSInit(); @@ -711,7 +864,7 @@ FSStatus FSMount(FSClient *client, FSCmdBlock *cmd, FSMountSource *source, - const char *target, + char *target, uint32_t bytes, FSErrorFlag errorMask); @@ -729,7 +882,7 @@ FSBindMount(FSClient *client, FSErrorFlag errorMask); FSStatus -FSbindUnmount(FSClient *client, +FSBindUnmount(FSClient *client, FSCmdBlock *cmd, const char *target, FSErrorFlag errorMask); diff --git a/include/coreinit/filesystem_fsa.h b/include/coreinit/filesystem_fsa.h new file mode 100644 index 00000000..20ef4fb3 --- /dev/null +++ b/include/coreinit/filesystem_fsa.h @@ -0,0 +1,612 @@ +#pragma once + +#include "wut.h" +#include "filesystem.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t FSACommand; +typedef uint16_t FSAIpcRequestType; +typedef IOSHandle FSAClientHandle; +typedef uint32_t FSAFileHandle; +typedef uint32_t FSADirectoryHandle; +typedef uint32_t FSAEntryNum; +typedef FSDirectoryEntry FSADirectoryEntry; +typedef FSStat FSAStat; + +typedef struct FSARequestRawOpen FSARequestRawOpen; +typedef struct FSARequestRawClose FSARequestRawClose; +typedef struct FSARequestRawRead FSARequestRawRead; +typedef struct FSARequestRawWrite FSARequestRawWrite; +typedef struct FSARequest FSARequest; +typedef struct FSAResponseRawOpen FSAResponseRawOpen; +typedef struct FSAResponse FSAResponse; +typedef struct FSAAsyncResult FSAAsyncResult; +typedef struct FSAShimBuffer FSAShimBuffer; +typedef struct FSAClientAttachAsyncData FSAClientAttachAsyncData; +typedef struct FSABlockInfo FSABlockInfo; +typedef struct FSADeviceInfo FSADeviceInfo; +typedef struct FSAFileSystemInfo FSAFileSystemInfo; +typedef struct FSVolumeInfo FSAVolumeInfo; + +typedef void (*FSAAsyncCallbackFn)(FSError result, + FSACommand command, + FSARequest *request, + FSAResponse *response, + void *userContext); + +struct FSARequestRawOpen { + char path[0x280]; +}; +WUT_CHECK_OFFSET(FSARequestRawOpen, 0x0, path); +WUT_CHECK_SIZE(FSARequestRawOpen, 0x280); + +struct FSARequestRawClose { + int32_t handle; +}; +WUT_CHECK_OFFSET(FSARequestRawClose, 0x0, handle); +WUT_CHECK_SIZE(FSARequestRawClose, 0x04); + +struct WUT_PACKED FSARequestRawRead { + WUT_UNKNOWN_BYTES(0x4); + uint64_t blocks_offset; + uint32_t count; + uint32_t size; + uint32_t device_handle; +}; +WUT_CHECK_OFFSET(FSARequestRawRead, 0x04, blocks_offset); +WUT_CHECK_OFFSET(FSARequestRawRead, 0x0C, count); +WUT_CHECK_OFFSET(FSARequestRawRead, 0x10, size); +WUT_CHECK_OFFSET(FSARequestRawRead, 0x14, device_handle); +WUT_CHECK_SIZE(FSARequestRawRead, 0x18); + +struct WUT_PACKED FSARequestRawWrite { + WUT_UNKNOWN_BYTES(0x4); + uint64_t blocks_offset; + uint32_t count; + uint32_t size; + uint32_t device_handle; +}; +WUT_CHECK_OFFSET(FSARequestRawWrite, 0x04, blocks_offset); +WUT_CHECK_OFFSET(FSARequestRawWrite, 0x0C, count); +WUT_CHECK_OFFSET(FSARequestRawWrite, 0x10, size); +WUT_CHECK_OFFSET(FSARequestRawWrite, 0x14, device_handle); +WUT_CHECK_SIZE(FSARequestRawWrite, 0x18); + +struct FSARequest { + FSError emulatedError; + + union { + FSARequestRawOpen rawOpen; + FSARequestRawClose rawClose; + FSARequestRawRead rawRead; + FSARequestRawWrite rawWrite; + WUT_UNKNOWN_BYTES(0x51C); + }; +}; +WUT_CHECK_OFFSET(FSARequest, 0x00, emulatedError); +WUT_CHECK_OFFSET(FSARequest, 0x04, rawOpen); +WUT_CHECK_SIZE(FSARequest, 0x520); + + +struct FSAResponseRawOpen { + int handle; +}; +WUT_CHECK_OFFSET(FSAResponseRawOpen, 0x0, handle); +WUT_CHECK_SIZE(FSAResponseRawOpen, 0x4); + +struct WUT_PACKED FSAResponse { + uint32_t word0; + union WUT_PACKED { + FSAResponseRawOpen rawOpen; + WUT_UNKNOWN_BYTES(0x28F); + }; +}; +WUT_CHECK_OFFSET(FSAResponse, 0x0, word0); +WUT_CHECK_OFFSET(FSAResponse, 0x4, rawOpen); +WUT_CHECK_SIZE(FSAResponse, 0x293); + +enum FSACommandEnum { + FSA_COMMAND_INVALID = 0x0, + FSA_COMMAND_MOUNT = 0x1, + FSA_COMMAND_UNMOUNT = 0x2, + FSA_COMMAND_GET_VOLUME_INFO = 0x3, + FSA_COMMAND_GET_ATTACH = 0x4, + FSA_COMMAND_CHANGE_DIR = 0x5, + FSA_COMMAND_GET_CWD = 0x6, + FSA_COMMAND_MAKE_DIR = 0x7, + FSA_COMMAND_REMOVE = 0x8, + FSA_COMMAND_RENAME = 0x9, + FSA_COMMAND_OPEN_DIR = 0xA, + FSA_COMMAND_READ_DIR = 0xB, + FSA_COMMAND_REWIND_DIR = 0xC, + FSA_COMMAND_CLOSE_DIR = 0xD, + FSA_COMMAND_OPEN_FILE = 0xE, + FSA_COMMAND_READ_FILE = 0xF, + FSA_COMMAND_WRITE_FILE = 0x10, + FSA_COMMAND_GET_POS_FILE = 0x11, + FSA_COMMAND_SET_POS_FILE = 0x12, + FSA_COMMAND_IS_EOF = 0x13, + FSA_COMMAND_STAT_FILE = 0x14, + FSA_COMMAND_CLOSE_FILE = 0x15, + FSA_COMMAND_GET_ERROR = 0x16, + FSA_COMMAND_FLUSH_FILE = 0x17, + FSA_COMMAND_GET_INFO_BY_QUERY = 0x18, + FSA_COMMAND_APPEND_FILE = 0x19, + FSA_COMMAND_TRUNCATE_FILE = 0x1A, + FSA_COMMAND_FLUSH_VOLUME = 0x1B, + FSA_COMMAND_ROLLBACK_VOLUME = 0x1C, + FSA_COMMAND_MAKE_QUOTA = 0x1D, + FSA_COMMAND_FLUSH_QUOTA = 0x1E, + FSA_COMMAND_ROLLBACK_QUOTA = 0x1F, + FSA_COMMAND_CHANGE_MODE = 0x20, + FSA_COMMAND_OPEN_FILE_BY_STAT = 0x21, + FSA_COMMAND_REGISTER_FLUSH_QUOTA = 0x22, + FSA_COMMAND_FLUSH_MULTI_QUOTA = 0x23, + FSA_COMMAND_GET_FILE_BLOCK_ADDRESS = 0x25, + FSA_COMMAND_ADD_USER_PROCESS = 0x65, + FSA_COMMAND_DEL_USER_PROCESS = 0x66, + FSA_COMMAND_MOUNT_WITH_PROCESS = 0x67, + FSA_COMMAND_UNMOUNT_WITH_PROCESS = 0x68, + FSA_COMMAND_FORMAT = 0x69, + FSA_COMMAND_RAW_OPEN = 0x6A, + FSA_COMMAND_RAW_READ = 0x6B, + FSA_COMMAND_RAW_WRITE = 0x6C, + FSA_COMMAND_RAW_CLOSE = 0x6D, + GET_LAST_FAILED_VOLUME = 0x6E, + GET_VOLUME_EXISTENCE = 0x6F, + FSA_COMMAND_CHANGE_OWNER = 0x70, + FSA_COMMAND_CANCEL_GET_ATTACH = 0x71, + FSA_COMMAND_REMOVE_QUOTA = 0x72, + FSA_COMMAND_SET_CLIENT_PRIORITY = 0x73, + FSA_COMMAND_APPLY_MEMORY_CACHE = 0x74, + FSA_COMMAND_MAKE_LINK = 0x75, + FSA_COMMAND_XFER_PARAMS = 0x76, + FSA_COMMAND_EXEC_DEBUG_PROC = 0x78, + FSA_COMMAND_DEBUG_SET_TITLE_ID = 0x79, + FSA_COMMAND_DEBUG_SET_CAPABILITY = 0x7A, + FSA_COMMAND_SET_PROCESS_CONFIG = 0x82, + FSA_COMMAND_CONFIG_SET_MEMORY_CACHE = 0x83, + FSA_COMMAND_CONFIG_UNSET_MEMORY_CACHE = 0x84, + FSA_COMMAND_CONFIG_SET_PRF2_CHAR_CODE = 0x85, + FSA_COMMAND_GET_PROC_RESOURCE_USAGE = 0x8C, + FSA_COMMAND_GET_ALL_RESOURCE_USAGE = 0x8D, + FSA_COMMAND_SEND_PROFILE_CMD = 0x8E, +}; + +enum FSAIpcRequestTypeEnum { + FSA_IPC_REQUEST_IOCTL = 0, + FSA_IPC_REQUEST_IOCTLV = 1, +}; + +struct FSAAsyncResult { + //! Queue to put a message on when command is complete. + OSMessageQueue *ioMsgQueue; + + //! Message used for ioMsgQueue. + FSMessage msg; + + //! Callback to call when the command is complete. + FSAAsyncCallbackFn userCallback; + + //! Result. + FSError error; + + //! FSA command. + FSACommand command; + + //! Pointer to allocated FSA IPC Request. + FSARequest *request; + + //! Pointer to allocated FSA IPC Response. + FSAResponse *response; + + //! Callback to call when the command is complete. + void *userContext; +}; +WUT_CHECK_OFFSET(FSAAsyncResult, 0x00, ioMsgQueue); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x04, msg); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x14, userCallback); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x18, error); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x1C, command); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x20, request); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x24, response); +WUT_CHECK_OFFSET(FSAAsyncResult, 0x28, userContext); +WUT_CHECK_SIZE(FSAAsyncResult, 0x2C); + +struct WUT_PACKED FSAShimBuffer { + //! Buffer for FSA IPC request. + FSARequest request; + WUT_UNKNOWN_BYTES(0x60); + + //! Buffer for FSA IPC response. + FSAResponse response; + WUT_UNKNOWN_BYTES(0x880 - 0x813); + + //! Memory to use for ioctlv calls, unknown maximum count - but at least 3. + IOSVec ioctlvVec[3]; + + WUT_UNKNOWN_BYTES(0x900 - 0x8A4); + + //! Command for FSA. + FSACommand command; + + //! Handle to FSA device. + uint32_t clientHandle; + + //! IOS IPC request type to use. + FSAIpcRequestType ipcReqType; + + //! Number of ioctlv input vectors. + uint8_t ioctlvVecIn; + + //! Number of ioctlv output vectors. + uint8_t ioctlvVecOut; + + //! FSAAsyncResult used for FSA* functions. + FSAAsyncResult fsaAsyncResult; +}; +WUT_CHECK_OFFSET(FSAShimBuffer, 0x0, request); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x580, response); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x880, ioctlvVec); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x900, command); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x904, clientHandle); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x908, ipcReqType); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x90A, ioctlvVecIn); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x90B, ioctlvVecOut); +WUT_CHECK_OFFSET(FSAShimBuffer, 0x90C, fsaAsyncResult); +WUT_CHECK_SIZE(FSAShimBuffer, 0x938); + +typedef void (*FSAClientAttachAsyncCallbackFn)(FSError result, + FSACommand command, + FSARequest *request, + FSAResponse *response, + void *userContext); + +struct FSAClientAttachAsyncData { + //! Callback to call when an attach has happened. + FSAClientAttachAsyncCallbackFn userCallback; + + //! Callback context + void *userContext; + + //! Queue to put a message on when command is complete. + OSMessageQueue *ioMsgQueue; +}; +WUT_CHECK_OFFSET(FSAClientAttachAsyncData, 0x00, userCallback); +WUT_CHECK_OFFSET(FSAClientAttachAsyncData, 0x04, userContext); +WUT_CHECK_OFFSET(FSAClientAttachAsyncData, 0x08, ioMsgQueue); +WUT_CHECK_SIZE(FSAClientAttachAsyncData, 0xC); + +typedef enum FSOpenFileFlags { + //! Open file normally + FS_OPEN_FLAG_NONE = (0 << 0), + //! Open (new) encrypted file + FS_OPEN_FLAG_ENCRYPTED = (1 << 0), + //! Preallocates new file size using given size + FS_OPEN_FLAG_PREALLOC_SIZE = (1 << 1) +} FSOpenFileFlags; + +/** + * Block information. + */ +struct FSABlockInfo { + WUT_UNKNOWN_BYTES(0x14); +}; +WUT_CHECK_SIZE(FSABlockInfo, 0x14); + +/** + * Device information. + */ +struct FSADeviceInfo { + WUT_UNKNOWN_BYTES(0x08); + uint64_t deviceSizeInSectors; + uint32_t deviceSectorSize; + WUT_UNKNOWN_BYTES(0x14); +}; +WUT_CHECK_OFFSET(FSADeviceInfo, 0x08, deviceSizeInSectors); +WUT_CHECK_OFFSET(FSADeviceInfo, 0x10, deviceSectorSize); +WUT_CHECK_SIZE(FSADeviceInfo, 0x28); + +/** + * File System information. + */ +struct FSAFileSystemInfo { + WUT_UNKNOWN_BYTES(0x1E); +}; +WUT_CHECK_SIZE(FSAFileSystemInfo, 0x1E); + +typedef enum FSAMountFlags { + FSA_MOUNT_FLAG_LOCAL_MOUNT = 0, + FSA_MOUNT_FLAG_BIND_MOUNT = 1, + FSA_MOUNT_FLAG_GLOBAL_MOUNT = 2, +} FSAMountFlags; + +typedef enum FSAUnmountFlags { + FSA_UNMOUNT_FLAG_NONE = 0x00000000, + FSA_UNMOUNT_FLAG_FORCE = 0x00000002, + FSA_UNMOUNT_FLAG_BIND_MOUNT = 0x80000000, +} FSAUnmountFlags; + +FSError +FSAInit(); + +void +FSAShutdown(); + +uint32_t +FSAGetClientNum(); + +FSAClientHandle +FSAAddClient(FSAClientAttachAsyncData *attachAsyncData); + +FSError +FSADelClient(FSAClientHandle client); + +const char * +FSAGetStatusStr(FSError error); + +FSError +FSAFlushMultiQuota(FSAClientHandle client, + const char *path); + +FSError +FSAFlushQuota(FSAClientHandle client, + const char *path); + +FSError +FSAFlushVolume(FSAClientHandle client, + const char *path); + +/** + * Frees the FSAShimBuffer where the given asyncResult is part of + * @param asyncResult + */ +void +FSAFreeAsyncResult(FSAAsyncResult *asyncResult); + +FSAAsyncResult +FSAGetAsyncResult(OSMessage *asyncResult); + +FSError +FSAMount(FSAClientHandle client, + const char *source, + const char *target, + FSAMountFlags flags, + void *arg_buf, + uint32_t arg_len); + +FSError +FSAUnmount(FSAClientHandle client, + const char *mountedTarget, + FSAUnmountFlags flags); + +FSError +FSAChangeDir(FSAClientHandle client, + const char *path); + +FSError +FSAChangeMode(FSAClientHandle client, + const char *path, + FSMode permission); + +FSError +FSOpenFileEx(FSAClientHandle client, + const char *path, + const char *mode, + FSAFileHandle *outFileHandle); + +FSError +FSAOpenFileEx(FSAClientHandle client, + const char *path, + const char *mode, + FSMode createMode, + FSOpenFileFlags openFlag, + uint32_t preallocSize, + FSAFileHandle *outFileHandle); + +FSError +FSAOpenFileByStat(FSAClientHandle client, + FSAStat *stat, + const char *mode, + const char *path, + FSAFileHandle *outFileHandle); + +FSError +FSAGetStatFile(FSAClientHandle client, + FSAFileHandle fileHandle, + FSAStat *stat); + +FSError +FSAGetStat(FSAClientHandle client, + const char *path, + FSAStat *stat); + +FSError +FSACloseFile(FSAClientHandle client, + FSAFileHandle fileHandle); + +FSError +FSAAppendFile(FSAClientHandle client, + FSAFileHandle fileHandle, + uint32_t size, + uint32_t count); + +FSError +FSAAppendFileEx(FSAClientHandle client, + FSAFileHandle fileHandle, + uint32_t size, + uint32_t count, + uint32_t flags); + +FSError +FSAGetPosFile(FSAClientHandle client, + FSAFileHandle fileHandle, + uint32_t *outPos); + +FSError +FSAFlushFile(FSAClientHandle client, + FSAFileHandle fileHandle); + +FSError +FSASetPosFile(FSAClientHandle client, + FSAFileHandle fileHandle, + uint32_t pos); + +FSError +FSATruncateFile(FSAClientHandle client, + FSAFileHandle handle); + +FSError +FSAWriteFile(FSAClientHandle client, + void *buffer, + uint32_t size, + uint32_t count, + FSAFileHandle handle, + uint32_t flags); + +FSError +FSAWriteFileWithPos(FSAClientHandle client, + void *buffer, + uint32_t size, + uint32_t count, + uint32_t pos, + FSAFileHandle handle, + uint32_t flags); + +FSError +FSAIsEof(FSAClientHandle client, + FSAFileHandle fileHandle); + +FSError +FSAReadFile(FSAClientHandle client, + void *buffer, + uint32_t size, + uint32_t count, + FSAFileHandle handle, + uint32_t flags); + +FSError +FSAReadFileWithPos(FSAClientHandle client, + void *buffer, + uint32_t size, + uint32_t count, + uint32_t pos, + FSAFileHandle handle, + uint32_t flags); + +FSError +FSARemove(FSAClientHandle client, + const char *path); + +FSError +FSARename(FSAClientHandle client, + const char *oldPath, + const char *newPath); + +FSError +FSAOpenDir(FSAClientHandle client, + const char *path, + FSADirectoryHandle *dirHandle); + +FSError +FSAReadDir(FSAClientHandle client, + FSADirectoryHandle dirHandle, + FSADirectoryEntry *directoryEntry); + +FSError +FSARewindDir(FSAClientHandle client, + FSADirectoryHandle dirHandle); + +FSError +FSACloseDir(FSAClientHandle client, + FSADirectoryHandle dirHandle); + +FSError +FSAMakeDir(FSAClientHandle client, + const char *path, + FSMode mode); + +FSError +FSAGetCwd(FSAClientHandle client, + char *outPath, + uint32_t outPathLen); + +FSError +FSAGetTransactionBlockPoolAttributes(uint32_t *messageSize, + uint32_t *poolSize, + uint32_t *numMessages); + +FSError +FSAGetVolumeInfo(FSAClientHandle client, + const char *path, + FSAVolumeInfo *outVolumeInfo); + + +FSError +FSAMakeQuota(FSAClientHandle client, + const char *name, + uint32_t mode, + uint64_t quota); + +FSError +FSARegisterFlushQuota(FSAClientHandle client, + const char *path); + +FSError +FSARollbackQuota(FSAClientHandle client, + const char *path); + +FSError +FSARollbackQuotaForce(FSAClientHandle client, + const char *path); + +FSError +FSARollbackVolume(FSAClientHandle client, + const char *path); + +FSError +FSAGetFreeSpaceSize(FSAClientHandle client, + const char *path, + uint64_t *freeSpaceSize); + +FSError +FSAGetJournalFreeSpaceSize(FSAClientHandle client, + const char *path, + uint64_t *journalFreeSpaceSize); + +FSError +FSAGetDirSize(FSAClientHandle client, + const char *path, + uint64_t *freeDirSize); + +FSError +FSAGetEntryNum(FSAClientHandle client, + const char *path, + FSAEntryNum *entryNum); + +FSError +FSAGetFileSystemInfo(FSAClientHandle client, + const char *path, + FSAFileSystemInfo *fileSystemInfo); + +FSError +FSAGetDeviceInfo(FSAClientHandle client, + const char *path, + FSADeviceInfo *fileSystemInfo); + +FSError +FSAGetBadBlockInfo(FSAClientHandle client, + const char *path, + FSABlockInfo *blockInfo); + +FSError +FSAGetFragmentBlockInfo(FSAClientHandle client, + const char *path, + FSABlockInfo *blockInfo); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/coreinit/ipcbufpool.h b/include/coreinit/ipcbufpool.h new file mode 100644 index 00000000..40065c00 --- /dev/null +++ b/include/coreinit/ipcbufpool.h @@ -0,0 +1,138 @@ +#pragma once + +#include +#include "mutex.h" +#include "ios.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct IPCBufPoolAttributes IPCBufPoolAttributes; +typedef struct IPCBufPoolFIFO IPCBufPoolFIFO; +typedef struct IPCBufPool IPCBufPool; + +/** +* FIFO queue for IPCBufPool. +* +* Functions similar to a ring buffer. +*/ +struct IPCBufPoolFIFO { + //! The current message index to push to. + int32_t pushIndex; + + //! The current message index to pop from. + int32_t popIndex; + + //! The number of messages in the queue. + int32_t count; + + //! Tracks the total number of messages in the count. + int32_t maxCount; + + //! Messages in the queue. + void **messages; +}; +WUT_CHECK_OFFSET(IPCBufPoolFIFO, 0x00, pushIndex); +WUT_CHECK_OFFSET(IPCBufPoolFIFO, 0x04, popIndex); +WUT_CHECK_OFFSET(IPCBufPoolFIFO, 0x08, count); +WUT_CHECK_OFFSET(IPCBufPoolFIFO, 0x0C, maxCount); +WUT_CHECK_OFFSET(IPCBufPoolFIFO, 0x10, messages); +WUT_CHECK_SIZE(IPCBufPoolFIFO, 0x14); + +/** + * Attributes returned by IPCBufPoolGetAttributes. + */ +struct IPCBufPoolAttributes { + //! Size of a message in the buffer pool. + uint32_t messageSize; + + //! Size of the buffer pool. + uint32_t poolSize; + + //! Number of pending messages in the pool fifo. + uint32_t numMessages; +}; +WUT_CHECK_OFFSET(IPCBufPoolAttributes, 0x00, messageSize); +WUT_CHECK_OFFSET(IPCBufPoolAttributes, 0x04, poolSize); +WUT_CHECK_OFFSET(IPCBufPoolAttributes, 0x08, numMessages); +WUT_CHECK_SIZE(IPCBufPoolAttributes, 0x0C); + +#define IPC_BUF_POOL_MAGIC 0x0BADF00Du + +/** +* A simple message buffer pool used for IPC communication. +*/ +struct IPCBufPool { + //! Magic header always set to IPCBufPool::MagicHeader. + uint32_t magic; + + //! Pointer to buffer used for this IPCBufPool. + void *buffer; + + //! Size of buffer. + uint32_t size; + + uint32_t unk0x0C; + uint32_t unk0x10; + + //! Message size from IPCBufPoolCreate. + uint32_t messageSize0x14; + + //! Message size from IPCBufPoolCreate. + uint32_t messageSize0x18; + + //! Number of messages in the IPCBufPoolFIFO. + uint32_t messageCount; + + //! Pointer to start of messages. + void *messages; + + //! Number of bytes used for the message pointers in IPCBufPoolFIFO. + uint32_t *messageIndexSize; + + //! FIFO queue of messages. + IPCBufPoolFIFO fifo; + + //! Mutex used to secure access to fifo. + OSMutex mutex; + + WUT_UNKNOWN_BYTES(0x04); +}; +WUT_CHECK_OFFSET(IPCBufPool, 0x00, magic); +WUT_CHECK_OFFSET(IPCBufPool, 0x04, buffer); +WUT_CHECK_OFFSET(IPCBufPool, 0x08, size); +WUT_CHECK_OFFSET(IPCBufPool, 0x0C, unk0x0C); +WUT_CHECK_OFFSET(IPCBufPool, 0x10, unk0x10); +WUT_CHECK_OFFSET(IPCBufPool, 0x14, messageSize0x14); +WUT_CHECK_OFFSET(IPCBufPool, 0x18, messageSize0x18); +WUT_CHECK_OFFSET(IPCBufPool, 0x1C, messageCount); +WUT_CHECK_OFFSET(IPCBufPool, 0x20, messages); +WUT_CHECK_OFFSET(IPCBufPool, 0x24, messageIndexSize); +WUT_CHECK_OFFSET(IPCBufPool, 0x28, fifo); +WUT_CHECK_OFFSET(IPCBufPool, 0x3C, mutex); +WUT_CHECK_SIZE(IPCBufPool, 0x6C); + +IPCBufPool * +IPCBufPoolCreate(void *buffer, + uint32_t size, + uint32_t messageSize, + uint32_t *outNumMessages, + uint32_t unk0x0c); + +void * +IPCBufPoolAllocate(IPCBufPool *pool, + uint32_t size); + +IOSError +IPCBufPoolFree(IPCBufPool *pool, + void *message); + +IOSError +IPCBufPoolGetAttributes(IPCBufPool *pool, + IPCBufPoolAttributes *attribs); + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/tests/test_compile_headers_common/test_compile_headers_list.h b/tests/test_compile_headers_common/test_compile_headers_list.h index 466df21c..13c4313d 100644 --- a/tests/test_compile_headers_common/test_compile_headers_list.h +++ b/tests/test_compile_headers_common/test_compile_headers_list.h @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include