1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00
TegraExplorer/source/storage/mountmanager.c

86 lines
2.4 KiB
C
Raw Normal View History

2020-12-26 22:41:25 +00:00
#include "mountmanager.h"
#include "emummc.h"
#include "../tegraexplorer/tconf.h"
#include "nx_emmc.h"
#include "../keys/keys.h"
#include <sec/se.h>
#include <libs/fatfs/ff.h>
#include "nx_emmc_bis.h"
2020-12-27 22:33:23 +00:00
#include "../config.h"
extern hekate_config h_cfg;
2020-12-26 22:41:25 +00:00
void SetKeySlots(){
if (TConf.keysDumped){
se_aes_key_set(0, dumpedKeys.bis_key[0], AES_128_KEY_SIZE);
se_aes_key_set(1, dumpedKeys.bis_key[0] + AES_128_KEY_SIZE, AES_128_KEY_SIZE);
se_aes_key_set(2, dumpedKeys.bis_key[1], AES_128_KEY_SIZE);
se_aes_key_set(3, dumpedKeys.bis_key[1] + AES_128_KEY_SIZE, AES_128_KEY_SIZE);
se_aes_key_set(4, dumpedKeys.bis_key[2], AES_128_KEY_SIZE);
se_aes_key_set(5, dumpedKeys.bis_key[2] + AES_128_KEY_SIZE, AES_128_KEY_SIZE);
}
}
2020-12-26 23:44:48 +00:00
LIST_INIT(curGpt);
2020-12-26 22:41:25 +00:00
void disconnectMMC(){
if (TConf.connectedMMCMounted)
f_unmount("bis:");
2020-12-26 23:44:48 +00:00
if (TConf.currentMMCConnected != MMC_CONN_None){
TConf.connectedMMCMounted = 0;
TConf.currentMMCConnected = MMC_CONN_None;
emummc_storage_end(&emmc_storage);
nx_emmc_gpt_free(&curGpt);
list_empty(&curGpt);
}
2020-12-26 22:41:25 +00:00
}
2020-12-26 23:44:48 +00:00
2020-12-26 22:41:25 +00:00
int connectMMC(u8 mmcType){
if (mmcType == TConf.currentMMCConnected)
return 0;
2020-12-26 23:44:48 +00:00
disconnectMMC();
2020-12-27 22:33:23 +00:00
h_cfg.emummc_force_disable = (mmcType == MMC_CONN_EMMC) ? 1 : 0;
2020-12-26 22:41:25 +00:00
int res = emummc_storage_init_mmc(&emmc_storage, &emmc_sdmmc);
2020-12-27 22:33:23 +00:00
if (!res){
2020-12-26 22:41:25 +00:00
TConf.currentMMCConnected = mmcType;
2020-12-27 22:33:23 +00:00
emummc_storage_set_mmc_partition(&emmc_storage, 0);
nx_emmc_gpt_parse(&curGpt, &emmc_storage);
}
2020-12-26 22:41:25 +00:00
return res; // deal with the errors later lol
}
ErrCode_t mountMMCPart(const char *partition){
2020-12-27 22:33:23 +00:00
if (!TConf.connectedMMCMounted){
emummc_storage_set_mmc_partition(&emmc_storage, 0); // why i have to do this twice beats me
emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition);
if (!system_part)
return newErrCode(TE_ERR_PARTITION_NOT_FOUND);
nx_emmc_bis_init(system_part);
2020-12-26 23:44:48 +00:00
2020-12-27 22:33:23 +00:00
int res = 0;
if ((res = f_mount(&emmc_fs, "bis:", 1)))
return newErrCode(res);
2020-12-26 22:41:25 +00:00
2020-12-27 22:33:23 +00:00
TConf.connectedMMCMounted = 1;
}
2020-12-26 22:41:25 +00:00
return newErrCode(0);
2020-12-27 22:33:23 +00:00
}
link_t *GetCurGPT(){
if (TConf.currentMMCConnected != MMC_CONN_None)
return &curGpt;
return NULL;
}
void unmountMMCPart(){
if (TConf.connectedMMCMounted)
f_unmount("bis:");
TConf.connectedMMCMounted = 0;
2020-12-26 22:41:25 +00:00
}