fwrite problem ? on encrypted fat partitions

chrisel
Posts: 1
Joined: Wed Feb 24, 2021 11:08 am

fwrite problem ? on encrypted fat partitions

Postby chrisel » Wed Feb 24, 2021 11:53 am

Hello all,

I have been trying to write on an encrypted fat partition but I have no success zero bytes are written.
The encrypt option is set to DEVELOPMENT
Have tried esp-idf versions : 4.4-dev 4.3-dev 4.2-stable 4.1.1,
wearleveling is on
I tried also to enable (SPI_FLASH_USE_LEGACY_IMPL) flag on menuconfig.. didnt help

Is there a problem with the fwrite function and encrypted partitions?

partitions.csv line that coresponds to this partition is :
.....
storage, data, fat, 0x3D1000, 0x2F000, encrypted
.....

The code that tries to write to this partition looks like :

Code: Select all

// mounting the partition


static esp_err_t mount_data_partition()
{
    ESP_LOGI(TAG, "Mounting FAT data filesystem");
    // To mount device we need name of device partition, define base_path
    // and allow format partition in case if it is new one and was not formated before
    const esp_vfs_fat_mount_config_t mount_config =
    {
            .max_files = 4,
            .format_if_mount_failed = true,
            .allocation_unit_size = CONFIG_WL_SECTOR_SIZE
    };
	esp_err_t err;
    err = esp_vfs_fat_spiflash_mount(base_path_recs, "storage", &mount_config, &s_wl_handle);

    if (err != ESP_OK)
    {
        ESP_LOGW(TAG, "Failed to mount path : %s - error : (%s)", base_path_recs, esp_err_to_name(err));
        return err;
    }
    ESP_LOGI(TAG, "Done mounting %s ", base_path_recs);
	return ESP_OK;
}


// openning the file

FILE *loadTestFile(char *mode)
{
	FILE *file = NULL;
	ESP_LOGI(TAG, "Opening file with mode : %s", mode); // mounting is done on another function
	file = fopen(TEST_FILE, mode); // 
	if (file == NULL)
	{
		ESP_LOGW(TAG, "Failed to open file");
	}
	else
	{
		ESP_LOGW(TAG, "File opened correctly");
	}
	return file;
}


void saveToFlash()
{


	char* testString = NULL;
	testString = getTestText();

		FILE *testFile = loadTestFile("wb"); // W mode..
		if (testFile != NULL)
		{
			size_t stringLength = strlen(testString);
			size_t savedBytes = fwrite(testString, sizeof(char), stringLength, testFile);
			ESP_LOGI(TAG, "saveToFlash - string length %d - bytes written : %d", stringLength, savedBytes);
			ESP_LOGI(TAG, "saveToFlash - Save to flash finished");
			fclose(testFile);
			testFile = NULL;
		}
}

The output is :


....

I (934) : Opening file with mode : wb
W (946) : File opened correctly
I (1167) : saveToFlash - string length 1018 - bytes written : 0
I (1167) : saveToFlash - Save to flash finished
W (1525) : unmountRecFilesystem - unmount of /records - error : 0


Thank you for your time
chris

Who is online

Users browsing this forum: No registered users and 83 guests