Hi Robin and Pavel,
I tested write into partition on MQX 4.2 – It works.
Unfortunately we cannot simply use read()/write() functions directly. It is necessary handle additional code due to BLOCK_MODE.
In this case we have to work with blocks of data (block size = device sector size). In my case (SD card) it was 512 bytes.
You can use part_mgr.c functions as inspiration…
Here is my test code:
char partition_name2[] = "pm:2";
char c;
uint32_t count=512;
int32_t offset=0;
int32_t seek_mode=0;
_mqx_int bi;
int32_t writesize = 512;
char *buf = NULL;
char *buf2 = NULL;
_mqx_int result;
/* Open partition */
partition_handle2 = fopen(partition_name2, NULL);
if (partition_handle != NULL)
{
printf("Opening partition 2...\n");
/* Validate partition */
error_code = _io_ioctl(partition_handle2, IO_IOCTL_VAL_PART, NULL);
if (error_code != MFS_NO_ERROR)
{
printf("Error validating partition: %s\n", MFS_Error_text((uint32_t)error_code));
continue;
}
}
buf = _mem_alloc(writesize);
buf2 = _mem_alloc(writesize);
/* generate data to buf */
c = '0';
for (bi = 0; (bi < count) && (bi < writesize); bi++) {
buf[bi] = c;
c = (c == 'z') ? '0' : c+1;
}
printf("Writing:\n");
printf("%s\n",buf);
//result = write(partition_handle2, buf, bi);
result = write(partition_handle2, buf, 1); //please check BLOCK_MODE, DEV_SECTOR_SIZE,... in part_mgr.c
if (result != 1) {
/* incomplete write */
printf("Error writing file.\n");
}
printf("\nDone.\n");
printf("Reading:\n");
fseek(partition_handle2, offset, IO_SEEK_SET);
//result = read(partition_handle2, buf2, bi);
result = read(partition_handle2, buf2, 1); //please check BLOCK_MODE, DEV_SECTOR_SIZE,... in part_mgr.c
if (result != 1) {
/* incomplete read */
printf("Error writing file.\n");
}
printf("%s\n",buf2);
printf("\nDone.\n");
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------