forked from Mirror/GodMode9
Forbid writing to SD if write locked
This commit is contained in:
parent
915437dac0
commit
3c7ad93d1c
@ -4,6 +4,7 @@
|
|||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "unittype.h"
|
#include "unittype.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
#include "sdmmc.h"
|
||||||
|
|
||||||
#define PATH_SYS_LVL1 "S:/twln.bin", "S:/twlp.bin"
|
#define PATH_SYS_LVL1 "S:/twln.bin", "S:/twlp.bin"
|
||||||
#define PATH_SYS_LVL2 "1:/rw/sys/LocalFriendCodeSeed_B", "1:/rw/sys/LocalFriendCodeSeed_A", \
|
#define PATH_SYS_LVL2 "1:/rw/sys/LocalFriendCodeSeed_B", "1:/rw/sys/LocalFriendCodeSeed_A", \
|
||||||
@ -26,6 +27,12 @@ bool CheckWritePermissions(const char* path) {
|
|||||||
if ((drvtype & DRV_IMAGE) && !CheckWritePermissions(GetMountPath()))
|
if ((drvtype & DRV_IMAGE) && !CheckWritePermissions(GetMountPath()))
|
||||||
return false; // endless loop when mounted file inside image, but not possible
|
return false; // endless loop when mounted file inside image, but not possible
|
||||||
|
|
||||||
|
// SD card write protection check
|
||||||
|
if ((drvtype & (DRV_SDCARD | DRV_EMUNAND | DRV_ALIAS)) && SD_WRITE_PROTECTED) {
|
||||||
|
ShowPrompt(false, "SD card is write protected!\nCan't continue.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// check drive type, get permission type
|
// check drive type, get permission type
|
||||||
if (drvtype & DRV_SYSNAND) {
|
if (drvtype & DRV_SYSNAND) {
|
||||||
u32 perms[] = { PERM_SYS_LVL0, PERM_SYS_LVL1, PERM_SYS_LVL2, PERM_SYS_LVL3 };
|
u32 perms[] = { PERM_SYS_LVL0, PERM_SYS_LVL1, PERM_SYS_LVL2, PERM_SYS_LVL3 };
|
||||||
|
@ -49,6 +49,12 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write protection check
|
||||||
|
if (SD_WRITE_PROTECTED) {
|
||||||
|
ShowPrompt(false, "SD card is write protected!\nCan't continue.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// build the MBR
|
// build the MBR
|
||||||
memcpy(mbrdata + 0x08, &fat_sector, 4);
|
memcpy(mbrdata + 0x08, &fat_sector, 4);
|
||||||
memcpy(mbrdata + 0x0C, &fat_size, 4);
|
memcpy(mbrdata + 0x0C, &fat_size, 4);
|
||||||
|
@ -74,6 +74,8 @@
|
|||||||
#define TMIO_MASK_READOP (TMIO_STAT1_RXRDY | TMIO_STAT1_DATAEND)
|
#define TMIO_MASK_READOP (TMIO_STAT1_RXRDY | TMIO_STAT1_DATAEND)
|
||||||
#define TMIO_MASK_WRITEOP (TMIO_STAT1_TXRQ | TMIO_STAT1_DATAEND)
|
#define TMIO_MASK_WRITEOP (TMIO_STAT1_TXRQ | TMIO_STAT1_DATAEND)
|
||||||
|
|
||||||
|
#define SD_WRITE_PROTECTED (!((*(volatile u16*) (SDMMC_BASE + 0x1C)) & (0x1 << 7)))
|
||||||
|
|
||||||
typedef struct mmcdevice {
|
typedef struct mmcdevice {
|
||||||
u8 *rData;
|
u8 *rData;
|
||||||
const u8 *tData;
|
const u8 *tData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user