Closed
Description
when fwrite() function received a buffer size larger than 1024 then the write is failing
- Type: Bug
- Priority: Major
Bug
Target
K64F
Toolchain:
ARM
Toolchain version:
5.06 (did not test with ARM v6.0)
mbed-cli version:
1.2.0
mbed-os sha:
4c256f0 (HEAD, tag: mbed_lib_rev148, tag: mbed-os-5.5.4, tag: latest) Merge pull request #4824 from ARMmbed/release-candidate
Steps to reproduce
FILE* fd = fopen("/fs/big.txt", "w+");
size_t write_count = 0;
char buff_big[1025] = {0};
write_count = fwrite(buff_big, 1, 1025, fd);
printf("number of written bytes %d\n\r",write_count); <----- write_count is 0 insted of 1025
fclose(fd);
example code
- deploy https://github.com/ARMmbed/mbed-os-example-fat-filesystem
- follow the instruction for use with an SD card
- replace main.c with the following code and compile to ARMCC
#include "mbed.h"
#include "FATFileSystem.h"
#include "SDBlockDevice.h"
#include <stdio.h>
#include <errno.h>
#define BIG_BUFF_SIZE 1025
#define SMALL_BUFF_SIZE 1024
SDBlockDevice bd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
FATFileSystem fs("fs");
void return_error(int ret_val){
if (ret_val)
printf("Failure. %d\r\n", ret_val);
else
printf("done.\r\n");
}
void errno_error(void* ret_val){
if (ret_val == NULL)
printf(" Failure. %d \r\n", errno);
else
printf(" done.\r\n");
}
int main()
{
int error = 0;
printf("Welcome to the filesystem example.\r\n"
"Formatting a FAT, RAM-backed filesystem. ");
error = FATFileSystem::format(&bd);
return_error(error);
printf("Mounting the filesystem on \"/fs\". ");
error = fs.mount(&bd);
return_error(error);
printf("Big Buffer Test.\r\n");
FILE* fd = fopen("/fs/big.txt", "w+");
size_t write_count = 0;
char buff_big[BIG_BUFF_SIZE] = {0};\
char buff_small[SMALL_BUFF_SIZE] = {0};
write_count = fwrite(buff_big, 1, BIG_BUFF_SIZE, fd);
printf("number of written bytes %d\n\r",write_count);
fclose(fd);
printf("Small Buffer Test.\r\n");
fd = fopen("/fs/small.txt", "w+");
write_count = 0;
write_count = fwrite(buff_small, 1, SMALL_BUFF_SIZE, fd);
printf("number of written bytes %d\n\r",write_count);
fclose(fd);
fflush(stdout);
printf("End Big Buffer Test.\r\n");
while (true) {}
}