1 /* This FileX test concentrates on the basic file naming operations. */
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
10 #define DEMO_STACK_SIZE 4096
11 #define CACHE_SIZE 16*128
12
13
14 /* Define the ThreadX and FileX object control blocks... */
15
16 #ifndef FX_STANDALONE_ENABLE
17 static TX_THREAD ftest_0;
18 #endif
19 static FX_MEDIA ram_disk;
20
21
22 /* Define the counters used in the test application... */
23
24 #ifndef FX_STANDALONE_ENABLE
25 static UCHAR *ram_disk_memory;
26 static UCHAR *cache_buffer;
27 #else
28 static UCHAR cache_buffer[CACHE_SIZE];
29 #endif
30
31
32 /* Define thread prototypes. */
33
34 void filex_file_naming_application_define(void *first_unused_memory);
35 static void ftest_0_entry(ULONG thread_input);
36
37 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
38 void test_control_return(UINT status);
39
40
41
42 /* Define what the initial system looks like. */
43
44 #ifdef CTEST
test_application_define(void * first_unused_memory)45 void test_application_define(void *first_unused_memory)
46 #else
47 void filex_file_naming_application_define(void *first_unused_memory)
48 #endif
49 {
50
51 #ifndef FX_STANDALONE_ENABLE
52 UCHAR *pointer;
53
54
55 /* Setup the working pointer. */
56 pointer = (UCHAR *) first_unused_memory;
57
58 /* Create the main thread. */
59 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
60 pointer, DEMO_STACK_SIZE,
61 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
62
63 pointer = pointer + DEMO_STACK_SIZE;
64
65 /* Setup memory for the RAM disk and the sector cache. */
66 cache_buffer = pointer;
67 pointer = pointer + CACHE_SIZE;
68 ram_disk_memory = pointer;
69
70 #endif
71
72 /* Initialize the FileX system. */
73 fx_system_initialize();
74 #ifdef FX_STANDALONE_ENABLE
75 ftest_0_entry(0);
76 #endif
77 }
78
79
80
81 /* Define the test threads. */
82
ftest_0_entry(ULONG thread_input)83 static void ftest_0_entry(ULONG thread_input)
84 {
85
86 UINT status;
87 CHAR *path_ptr;
88 CHAR special_name[10];
89
90 FX_PARAMETER_NOT_USED(thread_input);
91
92 /* Print out some test information banners. */
93 printf("FileX Test: File naming test.......................................");
94
95 /* Format the media. This needs to be done before opening it! */
96 status = fx_media_format(&ram_disk,
97 _fx_ram_driver, // Driver entry
98 ram_disk_memory, // RAM disk memory pointer
99 cache_buffer, // Media buffer pointer
100 CACHE_SIZE, // Media buffer size
101 "MY_RAM_DISK", // Volume Name
102 1, // Number of FATs
103 32, // Directory Entries
104 0, // Hidden sectors
105 512, // Total sectors
106 128, // Sector size
107 1, // Sectors per cluster
108 1, // Heads
109 1); // Sectors per track
110
111 /* Determine if the format had an error. */
112 if (status)
113 {
114
115 printf("ERROR!\n");
116 test_control_return(2);
117 }
118
119 /* Open the ram_disk. */
120 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
121
122 /* Check the status. */
123 if (status != FX_SUCCESS)
124 {
125
126 /* Error, return error code. */
127 printf("ERROR!\n");
128 test_control_return(3);
129 }
130
131 /* Get the current path. This should be / or NULL. */
132 status = fx_directory_default_get(&ram_disk, &path_ptr);
133
134 /* Check the status. */
135 if ((status != FX_SUCCESS) || (path_ptr[0]))
136 {
137
138 /* Error getting the path. Return to caller. */
139 printf("ERROR!\n");
140 test_control_return(4);
141 }
142
143 /* Create a series of directories... */
144 status = fx_directory_create(&ram_disk, "A0");
145 status += fx_directory_create(&ram_disk, ".b0");
146 status += fx_directory_create(&ram_disk, "C0");
147 status += fx_directory_create(&ram_disk, ".d0.dir");
148 status += fx_file_create(&ram_disk, ".FOO.BAR");
149
150 /* Check for errors... */
151 if (status != FX_SUCCESS)
152 {
153
154 /* Error creating directories. Return to caller. */
155 printf("ERROR!\n");
156 test_control_return(4);
157 }
158
159 /* Attempt to create the same directory again. */
160 status = fx_directory_create(&ram_disk, "/a0");
161
162 /* Check for errors... */
163 if (status != FX_ALREADY_CREATED)
164 {
165
166 /* Error creating same directory twice. Return to caller. */
167 printf("ERROR!\n");
168 test_control_return(5);
169 }
170
171 /* Create files with the E5 character. */
172 special_name[0] = (CHAR)0xE5;
173 special_name[1] = 0x2E;
174 special_name[2] = 0x54;
175 special_name[3] = 0x58;
176 special_name[4] = 0x54;
177 special_name[5] = 0;
178 status = fx_file_create(&ram_disk, special_name);
179 status += fx_media_flush(&ram_disk);
180 status += fx_file_delete(&ram_disk, special_name);
181
182 /* Check for errors. */
183 if (status != FX_SUCCESS)
184 {
185
186 /* Error creating special name. Return to caller. */
187 printf("ERROR!\n");
188 test_control_return(5);
189 }
190
191 /* Create another special file name. */
192 special_name[0] = (CHAR)0xE5;
193 special_name[1] = 0x31;
194 special_name[2] = 0x2E;
195 special_name[3] = 0x54;
196 special_name[4] = 0x58;
197 special_name[5] = 0x54;
198 special_name[6] = 0;
199 status = fx_file_create(&ram_disk, special_name);
200 status += fx_media_flush(&ram_disk);
201 status += fx_file_delete(&ram_disk, special_name);
202
203 /* Check for errors. */
204 if (status != FX_SUCCESS)
205 {
206
207 /* Error creating special name. Return to caller. */
208 printf("ERROR!\n");
209 test_control_return(6);
210 }
211
212 /* Create the next level of sub-directories.... with the interesting names... */
213 status = fx_directory_default_set(&ram_disk, "/A0");
214
215 status = fx_file_create(&ram_disk, ".a.a.a.");
216 status += fx_file_create(&ram_disk, "this...ismytestfile");
217 status += fx_file_create(&ram_disk, "this ... is my test file");
218 status += fx_file_create(&ram_disk, "ThisIsTheFirstVeryLongFileNameForThisTestABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZfirstfile11111111111111110000000000000000000000000000000000000000000000000000000");
219 status += fx_directory_create(&ram_disk, " c");
220 status += fx_directory_create(&ram_disk, " c/ e");
221 status += fx_directory_create(&ram_disk, " c/ e/ f");
222 status += fx_file_create(&ram_disk, "/A0 / c/ e/ f/test.txt");
223 status += fx_file_create(&ram_disk, "/.d0.dir/test.txt");
224 status += fx_file_create(&ram_disk, "/.b0/TEST.TXT");
225 status += fx_media_flush(&ram_disk);
226
227 /* Check for errors. */
228 if (status != FX_SUCCESS)
229 {
230
231 /* Error creating interesting file names. Return to caller. */
232 printf("ERROR!\n");
233 test_control_return(7);
234 }
235
236 /* Now attempt to delete the files in each of these sub-directories. */
237 status = fx_file_delete(&ram_disk, "/A0/.a.a.a.");
238 status += fx_file_delete(&ram_disk, "/A0/this...ismytestfile");
239 status += fx_file_delete(&ram_disk, "/A0/this ... is my test file");
240 status += fx_file_delete(&ram_disk, "/A0/ThisIsTheFirstVeryLongFileNameForThisTestABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZfirstfile11111111111111110000000000000000000000000000000000000000000000000000000");
241 status += fx_file_delete(&ram_disk, "/A0 / c/ e/ f/test.txt");
242 status += fx_directory_delete(&ram_disk, "/A0 /c /e/ f");
243 status += fx_directory_delete(&ram_disk, "/A0 /c /e");
244 status += fx_directory_delete(&ram_disk, "/A0 /c ");
245 status += fx_file_delete(&ram_disk, "/.d0.dir/test.txt");
246 status += fx_file_delete(&ram_disk, "/.b0/TEST.TXT");
247 status += fx_directory_delete(&ram_disk, "/A0");
248 status += fx_directory_delete(&ram_disk, "/ .b0");
249 status += fx_directory_delete(&ram_disk, "/C0 ");
250 status += fx_directory_delete(&ram_disk, "/.d0.dir");
251 status += fx_file_delete(&ram_disk, "/.FOO.BAR");
252 status += fx_media_flush(&ram_disk);
253
254 /* Check for errors. */
255 if (status != FX_SUCCESS)
256 {
257
258 /* Error deleting test files in the interesting sub-directories. Return to caller. */
259 printf("ERROR!\n");
260 test_control_return(8);
261 }
262
263 /* Set default to root directory. */
264 status = fx_directory_default_set(&ram_disk, "/");
265
266 /* Flush the media... should be empty at this point. */
267 status += fx_media_flush(&ram_disk);
268
269 /* Now fill the media's root directory until we get an error... We will use 8.3 names
270 to attempt to create 32 names. */
271 status += fx_file_create(&ram_disk, "A01");
272 status += fx_file_create(&ram_disk, "A02");
273 status += fx_file_create(&ram_disk, "A03");
274 status += fx_file_create(&ram_disk, "A04");
275 status += fx_file_create(&ram_disk, "A05");
276 status += fx_file_create(&ram_disk, "A06");
277 status += fx_file_create(&ram_disk, "A07");
278 status += fx_file_create(&ram_disk, "A08");
279 status += fx_file_create(&ram_disk, "A09");
280 status += fx_file_create(&ram_disk, "A10");
281 status += fx_file_create(&ram_disk, "A11");
282 status += fx_file_create(&ram_disk, "A12");
283 status += fx_file_create(&ram_disk, "A13");
284 status += fx_file_create(&ram_disk, "A14");
285 status += fx_file_create(&ram_disk, "A15");
286 status += fx_file_create(&ram_disk, "A16");
287 status += fx_file_create(&ram_disk, "A17");
288 status += fx_file_create(&ram_disk, "A18");
289 status += fx_file_create(&ram_disk, "A19");
290 status += fx_file_create(&ram_disk, "A20");
291 status += fx_file_create(&ram_disk, "A21");
292 status += fx_file_create(&ram_disk, "A22");
293 status += fx_file_create(&ram_disk, "A23");
294 status += fx_file_create(&ram_disk, "A24");
295 status += fx_file_create(&ram_disk, "A25");
296 status += fx_file_create(&ram_disk, "A26");
297 status += fx_file_create(&ram_disk, "A27");
298 status += fx_file_create(&ram_disk, "A28");
299 status += fx_file_create(&ram_disk, "A29");
300 status += fx_file_create(&ram_disk, "A30");
301 status += fx_file_create(&ram_disk, "A31");
302 status += fx_file_create(&ram_disk, "A32");
303
304 fx_media_flush(&ram_disk);
305
306 /* Check for errors... */
307 if (status != FX_SUCCESS)
308 {
309
310 /* Error creating files. Return to caller. */
311 printf("ERROR!\n");
312 test_control_return(9);
313 }
314
315 /* Attempt to create 33rd name... this should fail. */
316 status = fx_file_create(&ram_disk, "A33");
317
318 /* Check for errors... */
319 if (status != FX_NO_MORE_SPACE)
320 {
321
322 /* Error creating files. Return to caller. */
323 printf("ERROR!\n");
324 test_control_return(10);
325 }
326
327 /* Flush the media. */
328 status = fx_media_flush(&ram_disk);
329
330 /* Now delete all the names. */
331 status += fx_file_delete(&ram_disk, "A01");
332 status += fx_file_delete(&ram_disk, "A02");
333 status += fx_file_delete(&ram_disk, "A03");
334 status += fx_file_delete(&ram_disk, "A04");
335 status += fx_file_delete(&ram_disk, "A05");
336 status += fx_file_delete(&ram_disk, "A06");
337 status += fx_file_delete(&ram_disk, "A07");
338 status += fx_file_delete(&ram_disk, "A08");
339 status += fx_file_delete(&ram_disk, "A09");
340 status += fx_file_delete(&ram_disk, "A10");
341 status += fx_file_delete(&ram_disk, "A11");
342 status += fx_file_delete(&ram_disk, "A12");
343 status += fx_file_delete(&ram_disk, "A13");
344 status += fx_file_delete(&ram_disk, "A14");
345 status += fx_file_delete(&ram_disk, "A15");
346 status += fx_file_delete(&ram_disk, "A16");
347 status += fx_file_delete(&ram_disk, "A17");
348 status += fx_file_delete(&ram_disk, "A18");
349 status += fx_file_delete(&ram_disk, "A19");
350 status += fx_file_delete(&ram_disk, "A20");
351 status += fx_file_delete(&ram_disk, "A21");
352 status += fx_file_delete(&ram_disk, "A22");
353 status += fx_file_delete(&ram_disk, "A23");
354 status += fx_file_delete(&ram_disk, "A24");
355 status += fx_file_delete(&ram_disk, "A25");
356 status += fx_file_delete(&ram_disk, "A26");
357 status += fx_file_delete(&ram_disk, "A27");
358 status += fx_file_delete(&ram_disk, "A28");
359 status += fx_file_delete(&ram_disk, "A29");
360 status += fx_file_delete(&ram_disk, "A30");
361 status += fx_file_delete(&ram_disk, "A31");
362 status += fx_file_delete(&ram_disk, "A32");
363
364 /* Check for errors... */
365 if (status != FX_SUCCESS)
366 {
367
368 /* Error deleting files. Return to caller. */
369 printf("ERROR!\n");
370 test_control_return(11);
371 }
372
373 /* Flush the media. */
374 status = fx_media_flush(&ram_disk);
375
376 /* Now do the same thing, except with 2 entry long names. */
377 status += fx_file_create(&ram_disk, "b01");
378 status += fx_file_create(&ram_disk, "b02");
379 status += fx_file_create(&ram_disk, "b03");
380 status += fx_file_create(&ram_disk, "b04");
381 status += fx_file_create(&ram_disk, "b05");
382 status += fx_file_create(&ram_disk, "b06");
383 status += fx_file_create(&ram_disk, "b07");
384 status += fx_file_create(&ram_disk, "b08");
385 status += fx_file_create(&ram_disk, "b09");
386 status += fx_file_create(&ram_disk, "b10");
387 status += fx_file_create(&ram_disk, "b11");
388 status += fx_file_create(&ram_disk, "b12");
389 status += fx_file_create(&ram_disk, "b13");
390 status += fx_file_create(&ram_disk, "b14");
391 status += fx_file_create(&ram_disk, "b15");
392 status += fx_file_create(&ram_disk, "b16");
393
394 /* Check for errors... */
395 if (status != FX_SUCCESS)
396 {
397
398 /* Error creating files. Return to caller. */
399 printf("ERROR!\n");
400 test_control_return(12);
401 }
402
403 /* Attempt to create 17th long name... this should fail. */
404 status = fx_file_create(&ram_disk, "b17");
405
406 /* Check for errors... */
407 if (status != FX_NO_MORE_SPACE)
408 {
409
410 /* Error creating files. Return to caller. */
411 printf("ERROR!\n");
412 test_control_return(13);
413 }
414
415 /* Flush the media. */
416 status = fx_media_flush(&ram_disk);
417
418 /* Now delete all the names. */
419 status += fx_file_delete(&ram_disk, "b01");
420 status += fx_file_delete(&ram_disk, "b02");
421 status += fx_file_delete(&ram_disk, "b03");
422 status += fx_file_delete(&ram_disk, "b04");
423 status += fx_file_delete(&ram_disk, "b05");
424 status += fx_file_delete(&ram_disk, "b06");
425 status += fx_file_delete(&ram_disk, "b07");
426 status += fx_file_delete(&ram_disk, "b08");
427 status += fx_file_delete(&ram_disk, "b09");
428 status += fx_file_delete(&ram_disk, "b10");
429 status += fx_file_delete(&ram_disk, "b11");
430 status += fx_file_delete(&ram_disk, "b12");
431 status += fx_file_delete(&ram_disk, "b13");
432 status += fx_file_delete(&ram_disk, "b14");
433 status += fx_file_delete(&ram_disk, "b15");
434 status += fx_file_delete(&ram_disk, "b16");
435
436 /* Check for errors... */
437 if (status != FX_SUCCESS)
438 {
439
440 /* Error deleting files. Return to caller. */
441 printf("ERROR!\n");
442 test_control_return(14);
443 }
444
445 /* Create a file with non alphabet character and space. */
446 status = fx_file_create(&ram_disk, "TEST.T~ ");
447
448 /* Now delete this file. */
449 status += fx_file_delete(&ram_disk, "TEST.T~ ");
450
451 /* Check for errors... */
452 if (status != FX_SUCCESS)
453 {
454
455 /* Error deleting files. Return to caller. */
456 printf("ERROR!\n");
457 test_control_return(14);
458 }
459
460 /* Close the media. */
461 status = fx_media_close(&ram_disk);
462
463 /* Determine if the test was successful. */
464 if (status != FX_SUCCESS)
465 {
466
467 printf("ERROR!\n");
468 test_control_return(15);
469 }
470 else
471 {
472
473 printf("SUCCESS!\n");
474 test_control_return(0);
475 }
476 }
477
478