Skip to content

Commit

Permalink
Added mount/unmount partition functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Apr 1, 2021
1 parent 1660126 commit 59ae6a8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
36 changes: 36 additions & 0 deletions doc/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ enum DlgState{
CANCELED //!< Dialog canceled by user.
};

/**
* Mount permissions for partition mounting.
* \ingroup System
*/
enum MntPerm{
READ_ONLY, //!< Read only permissions.
READ_WRITE //!< Read/Write permissions.
};

class System{

public:
Expand Down Expand Up @@ -1033,5 +1042,32 @@ class System{
* @endcode
*/
void closeMessage(void);

/**
* Unmount an already mounted partition.
* \ingroup System
*
* @par Usage example:
* @code
* System.unmountPartition(3)
* @endcode
*
* @param idx - The index number of the partition.
*/
void unmountPartition(int idx);

/**
* Mount an unmounted partition.
* \ingroup System
*
* @par Usage example:
* @code
* System.mountPartition(3, READ_WRITE)
* @endcode
*
* @param idx - The index number of the partition.
* @param perms - Permissions to set for the mounted partition.
*/
void mountPartition(int idx, MntPerm perms);

}
34 changes: 33 additions & 1 deletion source/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ static int lua_getmsg(lua_State *L){
if (argc != 0) return luaL_error(L, "wrong number of arguments");
#endif
SceCommonDialogStatus status = sceMsgDialogGetStatus();
if (!messageStarted) status = SCE_COMMON_DIALOG_STATUS_FINISHED; // FINISHED status, look at luaKeyboard.cpp
if (!messageStarted) status = SCE_COMMON_DIALOG_STATUS_FINISHED;
if (status == SCE_COMMON_DIALOG_STATUS_FINISHED) {
SceMsgDialogResult result;
memset(&result, 0, sizeof(SceMsgDialogResult));
Expand Down Expand Up @@ -1162,6 +1162,32 @@ static int lua_firmware3(lua_State *L){
return 1;
}

static int lua_unmount(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
if (!unsafe_mode) return luaL_error(L, "this function requires unsafe mode");
#endif
int idx = luaL_checkinteger(L, 1);
vshIoUmount(idx * 0x100, 0, 0, 0);
vshIoUmount(idx * 0x100, 1, 0, 0);
return 0;
}

static int lua_mount(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 2) return luaL_error(L, "wrong number of arguments");
if (!unsafe_mode) return luaL_error(L, "this function requires unsafe mode");
#endif
int idx = luaL_checkinteger(L, 1);
int perm = luaL_checkinteger(L, 2);
void *buf = malloc(0x100);
_vshIoMount(idx * 0x100, 0, perm, buf);
free(buf);
return 0;
}

//Register our System Functions
static const luaL_Reg System_functions[] = {
{"openFile", lua_openfile},
Expand Down Expand Up @@ -1231,6 +1257,8 @@ static const luaL_Reg System_functions[] = {
{"getFirmware", lua_firmware},
{"getSpoofedFirmware", lua_firmware2},
{"getFactoryFirmware", lua_firmware3},
{"unmountPartition", lua_unmount},
{"mountPartition", lua_mount},
{0, 0}
};

Expand All @@ -1243,6 +1271,8 @@ void luaSystem_init(lua_State *L) {
int BUTTON_NONE = 2;
int BUTTON_OK_CANCEL = 3;
int BUTTON_CANCEL = 4;
int READ_ONLY = 1;
int READ_WRITE = 2;
VariableRegister(L,BUTTON_OK);
VariableRegister(L,BUTTON_YES_NO);
VariableRegister(L,BUTTON_NONE);
Expand All @@ -1258,4 +1288,6 @@ void luaSystem_init(lua_State *L) {
VariableRegister(L,SET);
VariableRegister(L,END);
VariableRegister(L,CUR);
VariableRegister(L,READ_ONLY);
VariableRegister(L,READ_WRITE);
}

0 comments on commit 59ae6a8

Please sign in to comment.