mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-12 02:52:32 +00:00
[stage2] Fix some FS bugs
This commit is contained in:
parent
5b5d3c69c2
commit
9ed2f92cdc
3 changed files with 28 additions and 16 deletions
|
@ -9,7 +9,7 @@ int device_partition_read_data(device_partition_t *devpart, void *dst, uint64_t
|
||||||
return rc;
|
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) {
|
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;
|
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);
|
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) {
|
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;
|
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));
|
memcpy(devpart->crypto_work_buffer, src + (size_t)(devpart->sector_size * i), (size_t)(devpart->sector_size * n));
|
||||||
|
|
|
@ -46,8 +46,8 @@ typedef struct device_partition_t {
|
||||||
void *crypto_work_buffer; /* Work buffer for crypto. */
|
void *crypto_work_buffer; /* Work buffer for crypto. */
|
||||||
uint64_t crypto_work_buffer_num_sectors; /* Size of the crypto work buffer in sectors. */
|
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 __attribute__((aligned(16))) keys[DEVPART_KEY_MAX][DEVPART_KEY_MAX_SIZE]; /* Key. */
|
||||||
uint8_t iv[DEVPART_IV_MAX_SIZE]; /* IV. */
|
uint8_t __attribute__((aligned(16))) iv[DEVPART_IV_MAX_SIZE]; /* IV. */
|
||||||
bool initialized;
|
bool initialized;
|
||||||
} device_partition_t;
|
} device_partition_t;
|
||||||
|
|
||||||
|
|
|
@ -41,20 +41,31 @@ static int mmc_partition_initialize(device_partition_t *devpart) {
|
||||||
g_ahb_redirect_enabled = true;
|
g_ahb_redirect_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmcpart->mmc == &g_sd_mmc && !g_sd_mmc_initialized) {
|
if (mmcpart->mmc == &g_sd_mmc) {
|
||||||
|
if (!g_sd_mmc_initialized) {
|
||||||
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
|
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
sdmmc_set_write_enable(mmcpart->mmc, SDMMC_WRITE_ENABLED);
|
sdmmc_set_write_enable(mmcpart->mmc, SDMMC_WRITE_ENABLED);
|
||||||
devpart->initialized = g_sd_mmc_initialized = true;
|
g_sd_mmc_initialized = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return rc;
|
return rc;
|
||||||
} else if (mmcpart->mmc == &g_nand_mmc && !g_nand_mmc_initialized) {
|
}
|
||||||
|
}
|
||||||
|
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);
|
int rc = sdmmc_init(mmcpart->mmc, mmcpart->controller);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
devpart->initialized = g_nand_mmc_initialized = true;
|
g_nand_mmc_initialized = true;
|
||||||
}
|
} else {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
devpart->initialized = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +74,7 @@ static void mmc_partition_finalize(device_partition_t *devpart) {
|
||||||
free(devpart->crypto_work_buffer);
|
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) {
|
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;
|
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) {
|
if (known_partitions[i].is_encrypted) {
|
||||||
devpart.read_cipher = switchfs_bis_crypto_decrypt;
|
devpart.read_cipher = switchfs_bis_crypto_decrypt;
|
||||||
devpart.write_cipher = switchfs_bis_crypto_encrypt;
|
devpart.write_cipher = switchfs_bis_crypto_encrypt;
|
||||||
|
devpart.crypto_mode = DevicePartitionCryptoMode_Xts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (known_partitions[i].is_fat) {
|
if (known_partitions[i].is_fat) {
|
||||||
|
|
Loading…
Reference in a new issue