diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 43fb0d9..a381c10 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -118,150 +118,6 @@ int main(void) llfs_init(); - - FILE *f = fopen("test.txt", "rw"); - if (f == NULL) { - LOG_INFO(TAG, "File not found test.txt"); - return 1; - } else { - LOG_INFO(TAG, "File found test.txt"); - } - - // Test POSIX file operations - // fgetc - int c; - printf("Printing file:\n"); - while ((c = fgetc(f)) != EOF) { - printf("%c", c); - } - LOG_INFO(TAG, "File printed"); - - // fseek - fseek(f, 0, SEEK_SET); - LOG_INFO(TAG, "File seeked to start"); - - // ftell - long pos = ftell(f); - LOG_INFO(TAG, "File position: %d", pos); - - // fread - char buf[100]; - size_t bytes_read = fread(buf, 1, 100, f); - LOG_INFO(TAG, "Read %d bytes from file", bytes_read); - printf("Read from file:\n"); - for (int i = 0; i < bytes_read; i++) { - printf("%c", buf[i]); - } - - // Rewind the file - LOG_INFO(TAG, "Before File rewinded, pos: %d", ftell(f)); - rewind(f); - LOG_INFO(TAG, "File rewinded, pos: %d", ftell(f)); - - // Get the file size fstat - struct stat st; - fstat(fileno(f), &st); - LOG_INFO(TAG, "File size: %d", st.st_size); - - - // Get a list of all files with the .bmp extension - llfs_file_t file_list[10]; - size_t num_files = llfs_file_list(file_list, 10, "*.bmp"); - LOG_INFO(TAG, "Found %d files with the .bmp extension", num_files); - for (int i = 0; i < num_files; i++) { - LOG_INFO(TAG, "File %d: %s", i, file_list[i].name); - } - - // Get a list of files with .txt or .html - num_files = llfs_file_list(file_list, 10, "*.txt"); - LOG_INFO(TAG, "Found %d files with the .txt or .html extension", num_files); - for (int i = 0; i < num_files; i++) { - LOG_INFO(TAG, "File %d: %s", i, file_list[i].name); - } - - // Loop over all files using the iterator - LOG_INFO(TAG, "Looping over all files, using the iterator"); - void *mem = NULL; - llfs_file_t *file; - while ((file = llfs_next_file(&mem, NULL)) != NULL) { - LOG_INFO(TAG, "File: %s", file->name); - } - - // Loop over all files with the .bmp extension using the iterator - LOG_INFO(TAG, "Looping over all files with the .bmp extension, using the iterator"); - mem = NULL; - while ((file = llfs_next_file(&mem, "*.bmp")) != NULL) { - LOG_INFO(TAG, "File: %s", file->name); - } - - // Get the number of files in the filesystem - size_t num_files_in_fs = llfs_file_count(); - LOG_INFO(TAG, "Number of files in the filesystem: %d", num_files_in_fs); - - - fclose(f); - - // Try opening multiple files - LOG_INFO(TAG, "Opening an closing multiple files"); - FILE * f1 = fopen("test.txt", "rw"); - if (f1 == NULL) { - LOG_INFO(TAG, "File not found f1"); - return 1; - } else { - LOG_INFO(TAG, "File found f1"); - } - // Get the fileno - int fd = fileno(f1); - LOG_INFO(TAG, "File descriptor f1: %d", fd); - - FILE * f2 = fopen("test.txt", "rw"); - if (f2 == NULL) { - LOG_INFO(TAG, "File not found f2"); - return 1; - } else { - LOG_INFO(TAG, "File found f2"); - } - // Get the fileno - fd = fileno(f2); - LOG_INFO(TAG, "File descriptorf2: %d", fd); - - LOG_INFO(TAG, "Closing f1"); - fclose(f1); - - FILE * f3 = fopen("test.txt", "rw"); - if (f3 == NULL) { - LOG_INFO(TAG, "File not found f3"); - return 1; - } else { - LOG_INFO(TAG, "File found f3"); - } - // Get the fileno - fd = fileno(f3); - LOG_INFO(TAG, "File descriptor f3: %d", fd); - - LOG_INFO(TAG, "Closing f2"); - fclose(f2); - - LOG_INFO(TAG, "Closing f3"); - fclose(f3); - - // Try opening a file multiple times, until it fails - int i = 0; - LOG_INFO(TAG, "Opening a file multiple times, until it fails"); - while (1) { - f = fopen("test.txt", "rw"); - LOG_INFO(TAG, "File descriptor: %d", fileno(f)); - if (f == NULL) { - LOG_INFO(TAG, "File not found test.txt"); - break; - } else { - LOG_INFO(TAG, "File found test.txt"); - } - i++; - } - LOG_INFO(TAG, "File opened %d times", i); - - /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */