IOS/Resource request

From WiiBrew
< IOS(Redirected from IOS/struct iovec)
Jump to: navigation, search
// For IPCCommandType, IOSOpenMode and SeekMode:
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+

#include <stddef.h>

typedef int32_t s32;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;

enum IPCCommandType : u32
{
  IPC_CMD_OPEN = 1,
  IPC_CMD_CLOSE = 2,
  IPC_CMD_READ = 3,
  IPC_CMD_WRITE = 4,
  IPC_CMD_SEEK = 5,
  IPC_CMD_IOCTL = 6,
  IPC_CMD_IOCTLV = 7,
  IPC_REPLY = 8,
};

enum IOSOpenMode : s32
{
  IOS_OPEN_READ = 1,
  IOS_OPEN_WRITE = 2,
  IOS_OPEN_RW = (IOS_OPEN_READ | IOS_OPEN_WRITE)
};

struct IOSResourceOpenRequest
{
  const u8* path;
  IOSOpenMode flags;
  u32 uid;  // some sort of ID (UID/PID?)
  u16 gid;  // probably gid based on the SetGid syscall
};

struct IOSResourceReadWriteRequest
{
  u8* data;
  u32 length;
};

enum SeekMode : u32
{
  IOS_SEEK_SET = 0,
  IOS_SEEK_CUR = 1,
  IOS_SEEK_END = 2,
};

struct IOSResourceSeekRequest
{
  u32 offset;
  SeekMode mode;
};

struct IOSResourceIOCtlRequest
{
  u32 request;
  u8* in;
  u32 in_size;
  u8* out;
  u32 out_size;
};

struct IOVector
{
  u8* base;
  u32 length;
};

struct IOSResourceIOCtlVRequest
{
  u32 request;
  u32 in_count;
  u32 io_count;
  IOVector* vectors;
};

union IOSResourceArgs
{
  IOSResourceOpenRequest open;
  IOSResourceReadWriteRequest read;
  IOSResourceReadWriteRequest write;
  IOSResourceSeekRequest seek;
  IOSResourceIOCtlRequest ioctl;
  IOSResourceIOCtlVRequest ioctlv;
};

struct IOSRequest
{
  IPCCommandType cmd;
  s32 ret;
  u32 fd;
  IOSResourceArgs args;
};