1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-26 05:42:17 +00:00

[stage2] Fix some FS bugs

This commit is contained in:
TuxSH 2018-05-17 19:53:42 +02:00
parent 5b5d3c69c2
commit 9ed2f92cdc
3 changed files with 28 additions and 16 deletions

View file

@ -9,7 +9,7 @@ int device_partition_read_data(device_partition_t *devpart, void *dst, uint64_t
return rc;
}
}
if (devpart->read_cipher != NULL) {
if (devpart->read_cipher != NULL && devpart->crypto_mode != DevicePartitionCryptoMode_None) {
for (uint64_t i = 0; i < num_sectors; i += devpart->crypto_work_buffer_num_sectors) {
uint64_t n = (i + devpart->crypto_work_buffer_num_sectors > num_sectors) ? (num_sectors - i) : devpart->crypto_work_buffer_num_sectors;
rc = devpart->reader(devpart, devpart->crypto_work_buffer, sector + i, n);
@ -38,7 +38,7 @@ int device_partition_write_data(device_partition_t *devpart, const void *src, ui
}
}
if (devpart->read_cipher != NULL) {
if (devpart->read_cipher != NULL && devpart->crypto_mode != DevicePartitionCryptoMode_None) {
for (uint64_t i = 0; i < num_sectors; i += devpart->crypto_work_buffer_num_sectors) {
uint64_t n = (i + devpart->crypto_work_buffer_num_sectors > num_sectors) ? (num_sectors - i) : devpart->crypto_work_buffer_num_sectors;
memcpy(devpart->crypto_work_buffer, src + (size_t)(devpart->sector_size * i), (size_t)(devpart->sector_size * n));

View file

@ -46,8 +46,8 @@ typedef struct device_partition_t {
void *crypto_work_buffer; /* Work buffer for crypto. */
uint64_t crypto_work_buffer_num_sectors; /* Size of the crypto work buffer in sectors. */
uint8_t keys[DEVPART_KEY_MAX][DEVPART_KEY_MAX_SIZE]; /* Key. */
uint8_t iv[DEVPART_IV_MAX_SIZE]; /* IV. */
uint8_t __attribute__((aligned(16))) keys[DEVPART_KEY_MAX][DEVPART_KEY_MAX_SIZE]; /* Key. */
uint8_t __attribute__((aligned(16))) iv[DEVPART_IV_MAX_SIZE]; /* IV. */
bool initialized;
} device_partition_t;

View file

@ -41,19 +41,30 @@ static int mmc_partition_initialize(device_partition_t *devpart) {
g_ahb_redirect_enabled = true;
}
if (mmcpart->mmc == &g_sd_mmc && !g_sd_mmc_initialized) {
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
if (rc == 0) {
sdmmc_set_write_enable(mmcpart->mmc, SDMMC_WRITE_ENABLED);
devpart->initialized = g_sd_mmc_initialized = true;
if (mmcpart->mmc == &g_sd_mmc) {
if (!g_sd_mmc_initialized) {
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
if (rc == 0) {
sdmmc_set_write_enable(mmcpart->mmc, SDMMC_WRITE_ENABLED);
g_sd_mmc_initialized = true;
}
else {
return rc;
}
}
return rc;
} else if (mmcpart->mmc == &g_nand_mmc && !g_nand_mmc_initialized) {
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
if (rc == 0) {
devpart->initialized = g_nand_mmc_initialized = true;
devpart->initialized = true;
return 0;
} else if (mmcpart->mmc == &g_nand_mmc) {
if (!g_nand_mmc_initialized) {
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
if (rc == 0) {
g_nand_mmc_initialized = true;
} else {
return rc;
}
}
return rc;
devpart->initialized = true;
return 0;
}
return 0;
@ -63,7 +74,7 @@ static void mmc_partition_finalize(device_partition_t *devpart) {
free(devpart->crypto_work_buffer);
}
static enum sdmmc_partition g_current_emmc_partition = SDMMC_PARTITION_USER;
static enum sdmmc_partition g_current_emmc_partition = (enum sdmmc_partition)-1;
static int mmc_partition_read(device_partition_t *devpart, void *dst, uint64_t sector, uint64_t num_sectors) {
mmc_partition_info_t *mmcpart = (mmc_partition_info_t *)devpart->device_struct;
@ -192,6 +203,7 @@ static int switchfs_mount_partition_gpt_callback(const efi_entry_t *entry, void
if (known_partitions[i].is_encrypted) {
devpart.read_cipher = switchfs_bis_crypto_decrypt;
devpart.write_cipher = switchfs_bis_crypto_encrypt;
devpart.crypto_mode = DevicePartitionCryptoMode_Xts;
}
if (known_partitions[i].is_fat) {