mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bugfix: fix for fatfs "open("xx",O_CREAT|O_WRONLY,0666)" call failure
fatfs 'open' with only O_CREAT flag fails to creat new file Closes https://github.com/espressif/esp-idf/issues/1817
This commit is contained in:
parent
9cfc9757b9
commit
b31b68fc68
@ -67,6 +67,14 @@ TEST_CASE("(WL) can create and write file", "[fatfs][wear_levelling]")
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can create and open file with O_CREAT flag", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_o_creat_flag("/spiflash/hello.txt");
|
||||
test_fatfs_open_file_with_o_creat_flag("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can read file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
|
@ -32,6 +32,30 @@ void test_fatfs_create_file_with_text(const char* name, const char* text)
|
||||
TEST_ASSERT_EQUAL(0, fclose(f));
|
||||
}
|
||||
|
||||
void test_fatfs_create_file_with_o_creat_flag(const char* filename)
|
||||
{
|
||||
const int fd = open(filename, O_CREAT|O_WRONLY);
|
||||
TEST_ASSERT_NOT_EQUAL(-1, fd);
|
||||
|
||||
const int r = pwrite(fd, fatfs_test_hello_str, strlen(fatfs_test_hello_str), 0); //offset=0
|
||||
TEST_ASSERT_EQUAL(strlen(fatfs_test_hello_str), r);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, close(fd));
|
||||
}
|
||||
|
||||
void test_fatfs_open_file_with_o_creat_flag(const char* filename)
|
||||
{
|
||||
char buf[32] = { 0 };
|
||||
const int fd = open(filename, O_CREAT|O_RDONLY);
|
||||
TEST_ASSERT_NOT_EQUAL(-1, fd);
|
||||
|
||||
int r = pread(fd, buf, sizeof(buf), 0); // it is a regular read() with offset==0
|
||||
TEST_ASSERT_EQUAL(0, strcmp(fatfs_test_hello_str, buf));
|
||||
TEST_ASSERT_EQUAL(strlen(fatfs_test_hello_str), r);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, close(fd));
|
||||
}
|
||||
|
||||
void test_fatfs_overwrite_append(const char* filename)
|
||||
{
|
||||
/* Create new file with 'aaaa' */
|
||||
|
@ -27,6 +27,10 @@ extern const char* fatfs_test_hello_str_utf;
|
||||
|
||||
void test_fatfs_create_file_with_text(const char* name, const char* text);
|
||||
|
||||
void test_fatfs_create_file_with_o_creat_flag(const char* filename);
|
||||
|
||||
void test_fatfs_open_file_with_o_creat_flag(const char* filename);
|
||||
|
||||
void test_fatfs_overwrite_append(const char* filename);
|
||||
|
||||
void test_fatfs_read_file(const char* filename);
|
||||
|
@ -264,7 +264,7 @@ static int fat_mode_conv(int m)
|
||||
res |= FA_CREATE_NEW;
|
||||
} else if ((m & O_CREAT) && (m & O_TRUNC)) {
|
||||
res |= FA_CREATE_ALWAYS;
|
||||
} else if (m & O_APPEND) {
|
||||
} else if ((m & O_APPEND) || (m & O_CREAT)) {
|
||||
res |= FA_OPEN_ALWAYS;
|
||||
} else {
|
||||
res |= FA_OPEN_EXISTING;
|
||||
|
Loading…
Reference in New Issue
Block a user