diff --git a/components/fs/fat/event.c b/components/fs/fat/event.c index 7c52703c..9e053573 100644 --- a/components/fs/fat/event.c +++ b/components/fs/fat/event.c @@ -124,6 +124,11 @@ void print_sector_data(uint8_t *buffer, unsigned long size) { _Static_assert(BLK_QUEUE_SIZE_CLI_FAT >= FAT_WORKER_THREAD_NUM, "The size of queue between fs and blk should be at least the size of FAT_WORKER_THREAD_NUM"); +// TODO: The FF_FS_LOCK is meant to prevent illegal behavior from the client, e.g. open a file and remove the file before closing it +// However, the illegal operations can ideatically be sanitized on an upper layer +_Static_assert(FF_FS_LOCK >= (FAT_MAX_OPENED_DIRNUM + FAT_MAX_OPENED_FILENUM), + "FF_FS_LOCK should be equal or larger than max opened dir number and max opened file number combined"); + void init(void) { // Init the block device queue // Have to make sure who initialize this SDDF queue diff --git a/dep/ff15/ffconf.h b/dep/ff15/ffconf.h index 9079b31d..7609778c 100644 --- a/dep/ff15/ffconf.h +++ b/dep/ff15/ffconf.h @@ -269,7 +269,7 @@ */ -#define FF_FS_LOCK 0 +#define FF_FS_LOCK 48 /* The option FF_FS_LOCK switches file lock function to control duplicated file open / and illegal operation to open objects. This option must be 0 when FF_FS_READONLY / is 1. diff --git a/examples/fileio/fs_test.py b/examples/fileio/fs_test.py index 7281f46a..9a497fc8 100644 --- a/examples/fileio/fs_test.py +++ b/examples/fileio/fs_test.py @@ -42,7 +42,6 @@ def test_environment(path): raise AssertionError(f"Test failed: Directory '{final_dir}' already exists.") else: os.mkdir(final_dir) - print(f"Test environment set up: '{final_dir}' created successfully.") return final_dir @@ -112,21 +111,21 @@ def test_write_and_read_back_complex(directory): ] try: - # Write the poem to the file line by line and read back each line to verify + # Step 1: Write the poem to the file line by line with open(test_file, "w") as f: - for index, line in enumerate(poem_lines): + for line in poem_lines: f.write(line + "\n") - # print(f"Line {index + 1} written to file.") + f.flush() # Ensure all content is written to disk - # Read the line back immediately to verify - f.flush() # Ensure the content is written to the file - with open(test_file, "r") as fr: - lines = fr.readlines() - read_back_line = lines[-1].strip() # Read the last line written + # Step 2: Open the file for reading after writing is complete + with open(test_file, "r") as f: + read_back_lines = [line.strip() for line in f.readlines()] # Read all lines and strip newlines - assert read_back_line == line, ( - f"Test failed at line {index + 1}: Expected: '{line}', Got: '{read_back_line}'" - ) + # Step 3: Verify each line matches the expected poem lines + for index, line in enumerate(poem_lines): + assert read_back_lines[index] == line, ( + f"Test failed at line {index + 1}: Expected: '{line}', Got: '{read_back_lines[index]}'" + ) # Increment success count if all lines are verified success_count += 1 @@ -136,10 +135,11 @@ def test_write_and_read_back_complex(directory): fail_count += 1 finally: - # Cleanup + # Cleanup: Remove the test file if path_exists(test_file): os.remove(test_file) + def test_mkdir_and_remove(directory): """Test creating directories with various names and removing them.""" global success_count, fail_count