1 /* This FileX test concentrates on the lowercase is not allowed in 8.3 name.  */
2 
3 #ifndef FX_STANDALONE_ENABLE
4 #include   "tx_api.h"
5 #endif
6 #include   "fx_api.h"
7 #include   <stdio.h>
8 #include   "fx_ram_driver_test.h"
9 #include   "fx_fault_tolerant.h"
10 
11 #define     DEMO_STACK_SIZE         4096
12 #define     CACHE_SIZE              128*128
13 #ifdef FX_ENABLE_FAULT_TOLERANT
14 #define     FAULT_TOLERANT_SIZE     FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
15 #else
16 #define     FAULT_TOLERANT_SIZE     0
17 #endif
18 
19 
20 /* Define the ThreadX and FileX object control blocks...  */
21 
22 #ifndef FX_STANDALONE_ENABLE
23 static TX_THREAD               ftest_0;
24 #endif
25 static FX_MEDIA                ram_disk;
26 static FX_FILE                 my_file;
27 
28 /* Define the counters used in the test application...  */
29 
30 #ifndef FX_STANDALONE_ENABLE
31 static UCHAR                  *ram_disk_memory;
32 static UCHAR                  *cache_buffer;
33 #else
34 static UCHAR                   cache_buffer[CACHE_SIZE];
35 #endif
36 static UCHAR                   write_data[65535];
37 static UCHAR                   read_data[65535];
38 #ifdef FX_ENABLE_FAULT_TOLERANT
39 static UCHAR                   fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
40 #endif /* FX_ENABLE_FAULT_TOLERANT */
41 
42 
43 /* Define thread prototypes.  */
44 
45 void    filex_file_name_application_define(void *first_unused_memory);
46 static void    ftest_0_entry(ULONG thread_input);
47 
48 VOID  _fx_ram_driver(FX_MEDIA *media_ptr);
49 void  test_control_return(UINT status);
50 
51 
52 
53 /* Define what the initial system looks like.  */
54 
55 #ifdef CTEST
test_application_define(void * first_unused_memory)56 void test_application_define(void *first_unused_memory)
57 #else
58 void    filex_file_name_application_define(void *first_unused_memory)
59 #endif
60 {
61 
62 #ifndef FX_STANDALONE_ENABLE
63 UCHAR    *pointer;
64 
65 
66     /* Setup the working pointer.  */
67     pointer =  (UCHAR *) first_unused_memory;
68 
69     /* Create the main thread.  */
70     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
71             pointer, DEMO_STACK_SIZE,
72             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
73 
74     pointer =  pointer + DEMO_STACK_SIZE;
75 
76     /* Setup memory for the RAM disk and the sector cache.  */
77     cache_buffer =  pointer;
78     pointer =  pointer + CACHE_SIZE;
79     ram_disk_memory =  pointer;
80 
81 #endif
82 
83     /* Initialize the FileX system.  */
84     fx_system_initialize();
85 #ifdef FX_STANDALONE_ENABLE
86     ftest_0_entry(0);
87 #endif
88 }
89 
90 
91 
92 /* Define the test threads.  */
93 
ftest_0_entry(ULONG thread_input)94 static void    ftest_0_entry(ULONG thread_input)
95 {
96 
97 UINT        status;
98 ULONG       actual;
99 ULONG       i;
100 
101     FX_PARAMETER_NOT_USED(thread_input);
102 
103     /* Print out some test information banners.  */
104     printf("FileX Test:   File name test.........................................");
105 
106     /* Format the media.  This needs to be done before opening it!  */
107     status =  fx_media_format(&ram_disk,
108                             _fx_ram_driver,         // Driver entry
109                             ram_disk_memory,        // RAM disk memory pointer
110                             cache_buffer,           // Media buffer pointer
111                             CACHE_SIZE,             // Media buffer size
112                             "MY_RAM_DISK",          // Volume Name
113                             1,                      // Number of FATs
114                             32,                     // Directory Entries
115                             0,                      // Hidden sectors
116                             512,                    // Total sectors
117                             512,                    // Sector size
118                             8,                      // Sectors per cluster
119                             1,                      // Heads
120                             1);                     // Sectors per track
121 
122     /* Determine if the format had an error.  */
123     return_if_fail( status == FX_SUCCESS);
124 
125     /* Open the ram_disk.  */
126     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
127     return_if_fail( status == FX_SUCCESS);
128 
129 #ifdef FX_ENABLE_FAULT_TOLERANT
130     /* Enable the Fault-tolerant feature.  */
131     status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
132     return_if_fail( status == FX_SUCCESS);
133 #endif /* FX_ENABLE_FAULT_TOLERANT */
134 
135     /* Initialize the data for write. */
136     for (i = 0; i < sizeof(write_data); i++)
137     {
138         write_data[i] = (UCHAR)i;
139         read_data[i] = 0;
140     }
141 
142     /* Create a file called TEST.TXT in the root directory.  */
143     status =  fx_file_create(&ram_disk, "TEST.TXT");
144     return_if_fail( status == FX_SUCCESS);
145 
146     /* Open the test file.  */
147     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
148     return_if_fail( status == FX_SUCCESS);
149 
150     /* Set BIT3 to modify the filename to lowercase. */
151     my_file.fx_file_dir_entry.fx_dir_entry_reserved = 0x08;
152 
153     /* Write to the file.  */
154     status =  fx_file_write(&my_file, write_data, sizeof(write_data));
155     return_if_fail( status == FX_SUCCESS);
156 
157     /* Close the file.  */
158     status =  fx_file_close(&my_file);
159     return_if_fail( status == FX_SUCCESS);
160 
161     /* Close the media. */
162     fx_media_close(&ram_disk);
163 
164     /* Verify the filename is upper-case. */
165     return_if_fail( memcmp(ram_disk_memory + 1024, "TEST    TXT", 4) == 0);
166 
167     /* Open the media. */
168     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
169     return_if_fail( status == FX_SUCCESS);
170 
171     /* Open the file as lowercase name.  */
172     status =  fx_file_open(&ram_disk, &my_file, "test.txt", FX_OPEN_FOR_WRITE);
173     return_if_fail( status == FX_SUCCESS);
174 
175     /* Write to the file.  */
176     status =  fx_file_write(&my_file, write_data, sizeof(write_data));
177     return_if_fail( status == FX_SUCCESS);
178 
179     /* Close the file.  */
180     status =  fx_file_close(&my_file);
181     return_if_fail( status == FX_SUCCESS);
182 
183     /* Reopen the media. */
184     fx_media_close(&ram_disk);
185 
186     /* Verify the filename is upper-case. */
187     return_if_fail( memcmp(ram_disk_memory + 1024, "TEST    TXT", 4) == 0);
188 
189     /* Open the media. */
190     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
191     return_if_fail( status == FX_SUCCESS);
192 
193     /* Open the file as lowercase name.  */
194     status =  fx_file_open(&ram_disk, &my_file, "test.txt", FX_OPEN_FOR_READ);
195     return_if_fail( status == FX_SUCCESS);
196 
197     /* Read from the file.  */
198     status =  fx_file_read(&my_file, (void *) read_data, sizeof(read_data), &actual);
199     return_if_fail( status == FX_SUCCESS);
200     return_if_fail( actual == sizeof(write_data));
201     return_if_fail( memcmp(read_data, write_data, actual) == 0);
202 
203     /* Close the file.  */
204     status =  fx_file_close(&my_file);
205     return_if_fail( status == FX_SUCCESS);
206 
207     /* Reopen the media. */
208     fx_media_close(&ram_disk);
209 
210     printf("SUCCESS!\n");
211     test_control_return(0);
212 }
213 
214