1+ /***************************************************************************
2+ * Copyright (c) 2024 Microsoft Corporation
3+ * Copyright (c) 2025 Eclipse ThreadX contributors
4+ *
5+ * This program and the accompanying materials are made available under the
6+ * terms of the MIT License which is available at
7+ * https://opensource.org/licenses/MIT.
8+ *
9+ * SPDX-License-Identifier: MIT
10+ **************************************************************************/
11+
12+
113/* This is a small demo of the high-performance FileX FAT file system. It includes setup for
214 a small 34KB RAM disk and a loop that writes and reads a small file. */
315#include "fx_api.h"
@@ -29,14 +41,16 @@ void thread_0_entry(ULONG thread_input);
2941
3042
3143/* Define FileX global data structures. */
32-
44+ #define TOTAL_SECTORS 256
45+ #define SECTOR_SIZE 512
3346FX_MEDIA ram_disk ;
3447FX_FILE my_file ;
3548
49+
3650#ifndef FX_STANDALONE_ENABLE
3751CHAR * ram_disk_memory ;
3852#else
39- unsigned char ram_disk_memory [256 * 512 ];
53+ unsigned char ram_disk_memory [TOTAL_SECTORS * SECTOR_SIZE ];
4054#endif
4155
4256/* Define ThreadX global data structures. */
@@ -102,8 +116,12 @@ CHAR local_buffer[30];
102116
103117
104118 /* Format the RAM disk - the memory for the RAM disk was setup in
105- tx_application_define above. */
106- fx_media_format (& ram_disk ,
119+ tx_application_define above.
120+
121+ Important Note: The user must ensure there is enough RAM for the format
122+ specified. Otherwise, memory corruption can occur.
123+ */
124+ status = fx_media_format (& ram_disk ,
107125 _fx_ram_driver , // Driver entry
108126 ram_disk_memory , // RAM disk memory pointer
109127 media_memory , // Media buffer pointer
@@ -112,27 +130,34 @@ CHAR local_buffer[30];
112130 1 , // Number of FATs
113131 32 , // Directory Entries
114132 0 , // Hidden sectors
115- 256 , // Total sectors
116- 512 , // Sector size
133+ TOTAL_SECTORS , // Total sectors
134+ SECTOR_SIZE , // Sector size
117135 8 , // Sectors per cluster
118136 1 , // Heads
119137 1 ); // Sectors per track
120138
139+ /* Determine if the RAM disk format was successful. */
140+ if (status != FX_SUCCESS )
141+ {
142+ /* Error formatting the RAM disk. */
143+ printf ("HTTPS RAM disk format failed, error: %x\n" , status );
144+ return ;
145+ }
121146
122147 /* Loop to repeat the demo over and over! */
123148 do
124149 {
125-
126150 /* Open the RAM disk. */
127151 status = fx_media_open (& ram_disk , "RAM DISK" , _fx_ram_driver , ram_disk_memory , media_memory , sizeof (media_memory ));
128152
129- /* Check the media open status . */
153+ /* Determine if the RAM disk open was successful . */
130154 if (status != FX_SUCCESS )
131155 {
132-
133- /* Error, break the loop! */
134- break ;
156+ /* Error opening the RAM disk. */
157+ printf ( "RAM disk open failed, error: %x\n" , status );
158+ return ;
135159 }
160+
136161
137162#ifdef FX_ENABLE_FAULT_TOLERANT
138163 status = fx_fault_tolerant_enable (& ram_disk , fault_tolerant_memory , sizeof (fault_tolerant_memory ));
0 commit comments