From 8112cd45ccdc5a7d60154e8d22137cb47940750e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Mon, 21 Jul 2025 12:38:46 -0400 Subject: [PATCH] Added error handling to the sample. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Frédéric Desbiens --- samples/demo_filex.c | 45 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/samples/demo_filex.c b/samples/demo_filex.c index b7649ba..2429300 100644 --- a/samples/demo_filex.c +++ b/samples/demo_filex.c @@ -1,3 +1,15 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2025 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + + /* This is a small demo of the high-performance FileX FAT file system. It includes setup for a small 34KB RAM disk and a loop that writes and reads a small file. */ #include "fx_api.h" @@ -29,10 +41,12 @@ void thread_0_entry(ULONG thread_input); /* Define FileX global data structures. */ - +#define TOTAL_SECTORS 256 +#define SECTOR_SIZE 512 FX_MEDIA ram_disk; FX_FILE my_file; + #ifndef FX_STANDALONE_ENABLE CHAR *ram_disk_memory; #else @@ -102,8 +116,12 @@ CHAR local_buffer[30]; /* Format the RAM disk - the memory for the RAM disk was setup in - tx_application_define above. */ - fx_media_format(&ram_disk, + tx_application_define above. + + Important Note: The user must ensure there is enough RAM for the format + specified. Otherwise, memory corruption can occur. + */ + status = fx_media_format(&ram_disk, _fx_ram_driver, // Driver entry ram_disk_memory, // RAM disk memory pointer media_memory, // Media buffer pointer @@ -112,27 +130,34 @@ CHAR local_buffer[30]; 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors - 256, // Total sectors - 512, // Sector size + TOTAL_SECTORS, // Total sectors + SECTOR_SIZE, // Sector size 8, // Sectors per cluster 1, // Heads 1); // Sectors per track + /* Determine if the RAM disk format was successful. */ + if (status != FX_SUCCESS) + { + /* Error formatting the RAM disk. */ + printf("HTTPS RAM disk format failed, error: %x\n", status); + return; + } /* Loop to repeat the demo over and over! */ do { - /* Open the RAM disk. */ status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, media_memory, sizeof(media_memory)); - /* Check the media open status. */ + /* Determine if the RAM disk open was successful. */ if (status != FX_SUCCESS) { - - /* Error, break the loop! */ - break; + /* Error opening the RAM disk. */ + printf("RAM disk open failed, error: %x\n", status); + return; } + } #ifdef FX_ENABLE_FAULT_TOLERANT status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_memory, sizeof(fault_tolerant_memory));