1 /* This FileX test concentrates on the local path operations.  */
2 
3 #ifndef FX_STANDALONE_ENABLE
4 #include   "tx_api.h"
5 #include   "fx_api.h"
6 #include   "fx_ram_driver_test.h"
7 #include   <stdio.h>
8 
9 #define     DEMO_STACK_SIZE         8192
10 #define     CACHE_SIZE              16*128
11 
12 
13 /* Define the ThreadX and FileX object control blocks...  */
14 
15 static TX_THREAD                ftest_0;
16 static FX_MEDIA                 ram_disk;
17 static UINT                     error_counter =  0;
18 
19 
20 /* Define the counters used in the test application...  */
21 
22 static UCHAR                    *ram_disk_memory;
23 static UCHAR                    *cache_buffer;
24 
25 static UINT                     expected_index =  0;
26 static CHAR *                   expected_name[] =  {
27 
28                         "RootFile01",
29                         "RootFile02",
30                         "RootDir03",
31                         ".",
32                         "..",
33                         "RootDir03_SubDir01",
34                         ".",
35                         "..",
36                         "RootDir03_File02",
37                         "RootDir03_SubDir03",
38                         ".",
39                         "..",
40                         "RootDir03_File04",
41                         "RootDir03_SubDir05",
42                         ".",
43                         "..",
44                         "RootDir03_File06",
45                         "RootDir03_SubDir07",
46                         ".",
47                         "..",
48                         "RootDir03_File08",
49                         "RootDir04",
50                         ".",
51                         "..",
52                         "RootDir04_File01",
53                         "RootDir04_File02",
54                         "RootDir04_SubDir03",
55                         ".",
56                         "..",
57                         "RootDir04_SubDir03_SubSubDir01",
58                         ".",
59                         "..",
60                         "RootDir04_SubDir03_SubSubDir02",
61                         ".",
62                         "..",
63                         "RootDir04_SubDir03_SubSubDir03",
64                         ".",
65                         "..",
66                         "RootDir04_SubDir03_SubSubFile04",
67                         "RootDir04_SubDir04",
68                         ".",
69                         "..",
70                         "RootDir04_SubDir04_SubSubDir01",
71                         ".",
72                         "..",
73                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir01",
74                         ".",
75                         "..",
76                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir02",
77                         ".",
78                         "..",
79                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir03",
80                         ".",
81                         "..",
82                         "RootDir04_SubDir04_SubSubDir01_SubSubSubFile04",
83                         "RootDir04_SubDir04_SubSubDir02",
84                         ".",
85                         "..",
86                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir01",
87                         ".",
88                         "..",
89                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir02",
90                         ".",
91                         "..",
92                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir03",
93                         ".",
94                         "..",
95                         "RootDir04_SubDir04_SubSubDir01_SubSubSubFile04",
96                         "RootDir04_SubDir04_SubSubDir03",
97                         ".",
98                         "..",
99                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir01",
100                         ".",
101                         "..",
102                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir02",
103                         ".",
104                         "..",
105                         "RootDir04_SubDir04_SubSubDir01_SubSubSubDir03",
106                         ".",
107                         "..",
108                         "RootDir04_SubDir04_SubSubDir01_SubSubSubFile04",
109                         "RootDir04_SubDir04_SubSubFile04",
110                         "RootDir04_SubDir05",
111                         ".",
112                         "..",
113                         "RootDir04_SubDir05_SubSubDir01",
114                         ".",
115                         "..",
116                         "RootDir04_SubDir05_SubSubDir02",
117                         ".",
118                         "..",
119                         "RootDir04_SubDir05_SubSubDir03",
120                         ".",
121                         "..",
122                         "RootDir04_SubDir05_SubSubFile04",
123                         "RootDir04_SubDir08_SubSubFile04",
124                         "RootDir04_File06",
125                         "RootDir04_File07",
126                         "RootDir04_SubDir08",
127                         ".",
128                         "..",
129                         "RootDir04_SubDir08_SubSubDir01",
130                         ".",
131                         "..",
132                         "RootDir04_SubDir08_SubSubDir02",
133                         ".",
134                         "..",
135                         "RootDir04_SubDir08_SubSubDir03",
136                         ".",
137                         "..",
138                         "RootDir05",
139                         ".",
140                         "..",
141                         "RootDir05_File02",
142                         "RootDir05_File03",
143                         "RootDir05_File04",
144                         "RootDir05_SubDir05",
145                         ".",
146                         "..",
147                         "RootDir05_SubDir06",
148                         ".",
149                         "..",
150                         "RootDir05_SubDir07",
151                         ".",
152                         "..",
153                         "RootDir05_File08",
154                         "RootDir05_SubDir09",
155                         ".",
156                         "..",
157                         "RootDir06",
158                         ".",
159                         "..",
160                         "RootDir06_SubDir01",
161                         ".",
162                         "..",
163                         "RootDir06_SubDir02",
164                         ".",
165                         "..",
166                         "RootDir06_SubDir03",
167                         ".",
168                         "..",
169                         "RootDir06_File04",
170                         "RootDir06_File05",
171                         "RootDir06_File06",
172                         "RootDir06_File07",
173                         "RootDir06_SubDir08",
174                         ".",
175                         "..",
176                         "RootDir07",
177                         ".",
178                         "..",
179                         "RootDir07_SubDir01",
180                         ".",
181                         "..",
182                         "RootDir07_SubDir02",
183                         ".",
184                         "..",
185                         "RootDir07_SubDir03",
186                         ".",
187                         "..",
188                         "RootDir07_SubDir04",
189                         ".",
190                         "..",
191                         "RootDir07_File05",
192                         "RootDir07_File06",
193                         "RootDir07_File07",
194                         "RootDir07_File08",
195                         "RootDir08",
196                         ".",
197                         "..",
198                         "RootDir08_File01",
199                         "RootDir08_File02",
200                         "RootDir08_File03",
201                         "RootDir08_File04",
202                         "RootDir08_SubDir05",
203                         ".",
204                         "..",
205                         "RootDir08_SubDir06",
206                         ".",
207                         "..",
208                         "RootDir08_SubDir07",
209                         ".",
210                         "..",
211                         "RootDir08_SubDir08",
212                         ".",
213                         "..",
214                         "RootFile09",
215                         "RootFile10",
216                         "RootDir11",
217                         ".",
218                         "..",
219                         "RootDir11_File01",
220                         "RootDir11_File02",
221                         "RootDir11_SubDir03",
222                         ".",
223                         "..",
224                         "RootDir11_SubDir04",
225                         ".",
226                         "..",
227                         "RootDir11_File05",
228                         "RootDir11_File06",
229                         "RootDir11_SubDir07",
230                         ".",
231                         "..",
232                         "RootDir11_SubDir08",
233                         ".",
234                         "..",
235                         "RootDir12",
236                         ".",
237                         "..",
238                         "RootDir12_File01",
239                         "RootDir12_File02",
240                         "RootDir12_SubDir03",
241                         ".",
242                         "..",
243                         "RootDir12_SubDir04",
244                         ".",
245                         "..",
246                         "RootDir12_File05",
247                         "RootDir12_File06",
248                         "RootDir12_SubDir07",
249                         ".",
250                         "..",
251                         "RootDir12_SubDir08",
252                         ".",
253                         "..",
254                         "RootDir13",
255                         ".",
256                         "..",
257                         "RootDir13_File01",
258                         "RootDir13_File02",
259                         "RootDir13_SubDir03",
260                         ".",
261                         "..",
262                         "RootDir13_SubDir04",
263                         ".",
264                         "..",
265                         "RootDir13_File05",
266                         "RootDir13_File06",
267                         "RootDir13_SubDir07",
268                         ".",
269                         "..",
270                         "RootDir13_SubDir08",
271                         ".",
272                         "..",
273                         "RootDir14",
274                         ".",
275                         "..",
276                         "RootFile15",
277                         "END"};
278 
279 
280 
281 /* Define thread prototypes.  */
282 
283 void    filex_directory_local_path_application_define(void *first_unused_memory);
284 static void    ftest_0_entry(ULONG thread_input);
285 static void    traverse_directory(CHAR *directory_name);
286 static void    last_character_compare_test();
287 
288 VOID  _fx_ram_driver(FX_MEDIA *media_ptr);
289 void  test_control_return(UINT status);
290 
291 
292 
293 /* Define what the initial system looks like.  */
294 
295 #ifdef CTEST
test_application_define(void * first_unused_memory)296 void test_application_define(void *first_unused_memory)
297 #else
298 void    filex_directory_local_path_application_define(void *first_unused_memory)
299 #endif
300 {
301 
302 UCHAR    *pointer;
303 
304 
305     /* Setup the working pointer.  */
306     pointer =  (UCHAR *) first_unused_memory;
307 
308     /* Create the main thread.  */
309     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
310             pointer, DEMO_STACK_SIZE,
311             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
312     pointer =  pointer + DEMO_STACK_SIZE;
313 
314     /* Setup memory for the RAM disk and the sector cache.  */
315     cache_buffer =  pointer;
316     pointer =  pointer + CACHE_SIZE;
317     ram_disk_memory =  pointer;
318 
319 memset(ram_disk_memory, 0xbf, 512*128);
320 
321     /* Initialize the FileX system.  */
322     fx_system_initialize();
323 }
324 
325 
326 
327 /* Define the test threads.  */
328 
ftest_0_entry(ULONG thread_input)329 static void    ftest_0_entry(ULONG thread_input)
330 {
331 
332 UINT        status;
333 FX_LOCAL_PATH   local_path;
334 CHAR        *path_name;
335 CHAR        path_name_buffer[32];
336 
337     FX_PARAMETER_NOT_USED(thread_input);
338 
339     /* Print out some test information banners.  */
340     printf("FileX Test:   Directory local path test..............................");
341 
342     /* Format the media.  This needs to be done before opening it!  */
343     status =  fx_media_format(&ram_disk,
344                             _fx_ram_driver,         // Driver entry
345                             ram_disk_memory,        // RAM disk memory pointer
346                             cache_buffer,           // Media buffer pointer
347                             CACHE_SIZE,             // Media buffer size
348                             "MY_RAM_DISK",          // Volume Name
349                             1,                      // Number of FATs
350                             32,                     // Directory Entries
351                             0,                      // Hidden sectors
352                             512,                    // Total sectors
353                             128,                    // Sector size
354                             1,                      // Sectors per cluster
355                             1,                      // Heads
356                             1);                     // Sectors per track
357 
358     /* Determine if the format had an error.  */
359     if (status)
360     {
361 
362         printf("ERROR!\n");
363         test_control_return(1);
364     }
365 
366     /* Attempt to clear the local path before the media has been opened to generate an error */
367     status = fx_directory_local_path_clear(&ram_disk);
368     if (status != FX_MEDIA_NOT_OPEN)
369     {
370         printf("ERROR!\n");
371         test_control_return(2);
372     }
373 
374     /* Attempt to restore the local path before the media has been opened to generate an error */
375     status = fx_directory_local_path_restore(&ram_disk, &local_path);
376     if (status != FX_MEDIA_NOT_OPEN)
377     {
378         printf("ERROR!\n");
379         test_control_return(3);
380     }
381 
382     /* Attempt to set the local path before the media has been opened to generate an error */
383     status = fx_directory_local_path_set(&ram_disk, &local_path, "/A0");
384     if (status != FX_MEDIA_NOT_OPEN)
385     {
386         printf("ERROR!\n");
387         test_control_return(4);
388     }
389 
390 
391     /* Open the ram_disk.  */
392     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
393 
394     /* Check the status.  */
395     if (status != FX_SUCCESS)
396     {
397 
398         /* Error, return error code.  */
399         printf("ERROR!\n");
400         test_control_return(5);
401     }
402 
403     /* Attempt to set the local path to somewhere that does not exist to generate an error */
404     status = fx_directory_local_path_set(&ram_disk, &local_path, "/DOES_NOT_EXIST");
405     if (status != FX_INVALID_PATH)
406     {
407         printf("ERROR!\n");
408         test_control_return(6);
409     }
410 
411     /* Create a hiearchy of files and sub-directories.   */
412     status =   fx_file_create(&ram_disk,      "RootFile01");
413     status +=  fx_file_create(&ram_disk,      "RootFile02");
414     status +=  fx_directory_create(&ram_disk, "RootDir03");
415     status +=  fx_directory_create(&ram_disk, "RootDir04");
416     status +=  fx_directory_create(&ram_disk, "RootDir05");
417     status +=  fx_directory_create(&ram_disk, "RootDir06");
418     status +=  fx_directory_create(&ram_disk, "RootDir07");
419     status +=  fx_directory_create(&ram_disk, "RootDir08");
420     status +=  fx_file_create(&ram_disk,      "RootFile09");
421     status +=  fx_file_create(&ram_disk,      "RootFile10");
422     status +=  fx_directory_create(&ram_disk, "RootDir11");
423     status +=  fx_directory_create(&ram_disk, "RootDir12");
424     status +=  fx_directory_create(&ram_disk, "RootDir13");
425     status +=  fx_directory_create(&ram_disk, "RootDir14");
426     status +=  fx_file_create(&ram_disk,      "RootFile15");
427 
428     /* Create the sub-directories for RootDir03.  */
429     status +=  fx_directory_create(&ram_disk, "/RootDir03/RootDir03_SubDir01");
430     status +=  fx_file_create(&ram_disk,      "/RootDir03/RootDir03_File02");
431     status +=  fx_directory_create(&ram_disk, "/RootDir03/RootDir03_SubDir03");
432     status +=  fx_file_create(&ram_disk,      "/RootDir03/RootDir03_File04");
433     status +=  fx_directory_create(&ram_disk, "/RootDir03/RootDir03_SubDir05");
434     status +=  fx_file_create(&ram_disk,      "/RootDir03/RootDir03_File06");
435     status +=  fx_directory_create(&ram_disk, "/RootDir03/RootDir03_SubDir07");
436     status +=  fx_file_create(&ram_disk,      "/RootDir03/RootDir03_File08");
437 
438     /* Create the sub-directories for RootDir04.  */
439     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_File01");
440     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_File02");
441     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir03");
442     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04");
443     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir05");
444     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_File06");
445     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_File07");
446     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir08");
447 
448     /* Create the sub-directories for RootDir05.  */
449     status +=  fx_file_create(&ram_disk,      "/RootDir05/RootDir05_File02");
450     status +=  fx_file_create(&ram_disk,      "/RootDir05/RootDir05_File03");
451     status +=  fx_file_create(&ram_disk,      "/RootDir05/RootDir05_File04");
452     status +=  fx_directory_create(&ram_disk, "/RootDir05/RootDir05_SubDir05");
453     status +=  fx_directory_create(&ram_disk, "/RootDir05/RootDir05_SubDir06");
454     status +=  fx_directory_create(&ram_disk, "/RootDir05/RootDir05_SubDir07");
455     status +=  fx_file_create(&ram_disk,      "/RootDir05/RootDir05_File08");
456     status +=  fx_directory_create(&ram_disk, "/RootDir05/RootDir05_SubDir09");
457 
458 
459     /* Create the sub-directories for RootDir06.  */
460     status +=  fx_directory_create(&ram_disk, "/RootDir06/RootDir06_SubDir01");
461     status +=  fx_directory_create(&ram_disk, "/RootDir06/RootDir06_SubDir02");
462     status +=  fx_directory_create(&ram_disk, "/RootDir06/RootDir06_SubDir03");
463     status +=  fx_file_create(&ram_disk,      "/RootDir06/RootDir06_File04");
464     status +=  fx_file_create(&ram_disk,      "/RootDir06/RootDir06_File05");
465     status +=  fx_file_create(&ram_disk,      "/RootDir06/RootDir06_File06");
466     status +=  fx_file_create(&ram_disk,      "/RootDir06/RootDir06_File07");
467     status +=  fx_directory_create(&ram_disk, "/RootDir06/RootDir06_SubDir08");
468 
469 
470     /* Create the sub-directories for RootDir07.  */
471     status +=  fx_directory_create(&ram_disk, "/RootDir07/RootDir07_SubDir01");
472     status +=  fx_directory_create(&ram_disk, "/RootDir07/RootDir07_SubDir02");
473     status +=  fx_directory_create(&ram_disk, "/RootDir07/RootDir07_SubDir03");
474     status +=  fx_directory_create(&ram_disk, "/RootDir07/RootDir07_SubDir04");
475     status +=  fx_file_create(&ram_disk,      "/RootDir07/RootDir07_File05");
476     status +=  fx_file_create(&ram_disk,      "/RootDir07/RootDir07_File06");
477     status +=  fx_file_create(&ram_disk,      "/RootDir07/RootDir07_File07");
478     status +=  fx_file_create(&ram_disk,      "/RootDir07/RootDir07_File08");
479 
480     /* Create the sub-directories for RootDir08.  */
481     status +=  fx_file_create(&ram_disk,      "/RootDir08/RootDir08_File01");
482     status +=  fx_file_create(&ram_disk,      "/RootDir08/RootDir08_File02");
483     status +=  fx_file_create(&ram_disk,      "/RootDir08/RootDir08_File03");
484     status +=  fx_file_create(&ram_disk,      "/RootDir08/RootDir08_File04");
485     status +=  fx_directory_create(&ram_disk, "/RootDir08/RootDir08_SubDir05");
486     status +=  fx_directory_create(&ram_disk, "/RootDir08/RootDir08_SubDir06");
487     status +=  fx_directory_create(&ram_disk, "/RootDir08/RootDir08_SubDir07");
488     status +=  fx_directory_create(&ram_disk, "/RootDir08/RootDir08_SubDir08");
489 
490     /* Create the sub-directories for RootDir11.  */
491     status +=  fx_file_create(&ram_disk,      "/RootDir11/RootDir11_File01");
492     status +=  fx_file_create(&ram_disk,      "/RootDir11/RootDir11_File02");
493     status +=  fx_directory_create(&ram_disk, "/RootDir11/RootDir11_SubDir03");
494     status +=  fx_directory_create(&ram_disk, "/RootDir11/RootDir11_SubDir04");
495     status +=  fx_file_create(&ram_disk,      "/RootDir11/RootDir11_File05");
496     status +=  fx_file_create(&ram_disk,      "/RootDir11/RootDir11_File06");
497     status +=  fx_directory_create(&ram_disk, "/RootDir11/RootDir11_SubDir07");
498     status +=  fx_directory_create(&ram_disk, "/RootDir11/RootDir11_SubDir08");
499 
500 
501     /* Create the sub-directories for RootDir12.  */
502     status +=  fx_file_create(&ram_disk,      "/RootDir12/RootDir12_File01");
503     status +=  fx_file_create(&ram_disk,      "/RootDir12/RootDir12_File02");
504     status +=  fx_directory_create(&ram_disk, "/RootDir12/RootDir12_SubDir03");
505     status +=  fx_directory_create(&ram_disk, "/RootDir12/RootDir12_SubDir04");
506     status +=  fx_file_create(&ram_disk,      "/RootDir12/RootDir12_File05");
507     status +=  fx_file_create(&ram_disk,      "/RootDir12/RootDir12_File06");
508     status +=  fx_directory_create(&ram_disk, "/RootDir12/RootDir12_SubDir07");
509     status +=  fx_directory_create(&ram_disk, "/RootDir12/RootDir12_SubDir08");
510 
511     /* Create the sub-directories for RootDir13.  */
512     status +=  fx_file_create(&ram_disk,      "/RootDir13/RootDir13_File01");
513     status +=  fx_file_create(&ram_disk,      "/RootDir13/RootDir13_File02");
514     status +=  fx_directory_create(&ram_disk, "/RootDir13/RootDir13_SubDir03");
515     status +=  fx_directory_create(&ram_disk, "/RootDir13/RootDir13_SubDir04");
516     status +=  fx_file_create(&ram_disk,      "/RootDir13/RootDir13_File05");
517     status +=  fx_file_create(&ram_disk,      "/RootDir13/RootDir13_File06");
518     status +=  fx_directory_create(&ram_disk, "/RootDir13/RootDir13_SubDir07");
519     status +=  fx_directory_create(&ram_disk, "/RootDir13/RootDir13_SubDir08");
520 
521     /* Create the Sub-sub directories under RootDir04.  */
522     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir03/RootDir04_SubDir03_SubSubDir01");
523     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir03/RootDir04_SubDir03_SubSubDir02");
524     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir03/RootDir04_SubDir03_SubSubDir03");
525     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir03/RootDir04_SubDir03_SubSubFile04");
526 
527     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir01");
528     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir02");
529     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir03");
530     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubFile04");
531 
532     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir05/RootDir04_SubDir05_SubSubDir01");
533     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir05/RootDir04_SubDir05_SubSubDir02");
534     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir05/RootDir04_SubDir05_SubSubDir03");
535     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir05/RootDir04_SubDir05_SubSubFile04");
536 
537     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir08/RootDir04_SubDir08_SubSubDir01");
538     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir08/RootDir04_SubDir08_SubSubDir02");
539     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir08/RootDir04_SubDir08_SubSubDir03");
540     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir05/RootDir04_SubDir08_SubSubFile04");
541 
542     /* Create the sub-sub-sub directories under RootDir04.  */
543     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir01/RootDir04_SubDir04_SubSubDir01_SubSubSubDir01");
544     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir01/RootDir04_SubDir04_SubSubDir01_SubSubSubDir02");
545     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir01/RootDir04_SubDir04_SubSubDir01_SubSubSubDir03");
546     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir01/RootDir04_SubDir04_SubSubDir01_SubSubSubFile04");
547 
548     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir02/RootDir04_SubDir04_SubSubDir01_SubSubSubDir01");
549     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir02/RootDir04_SubDir04_SubSubDir01_SubSubSubDir02");
550     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir02/RootDir04_SubDir04_SubSubDir01_SubSubSubDir03");
551     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir02/RootDir04_SubDir04_SubSubDir01_SubSubSubFile04");
552 
553     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir03/RootDir04_SubDir04_SubSubDir01_SubSubSubDir01");
554     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir03/RootDir04_SubDir04_SubSubDir01_SubSubSubDir02");
555     status +=  fx_directory_create(&ram_disk, "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir03/RootDir04_SubDir04_SubSubDir01_SubSubSubDir03");
556     status +=  fx_file_create(&ram_disk,      "/RootDir04/RootDir04_SubDir04/RootDir04_SubDir04_SubSubDir03/RootDir04_SubDir04_SubSubDir01_SubSubSubFile04");
557 
558 
559     /* Check the status.  */
560     if (status != FX_SUCCESS)
561     {
562 
563         /* Error creating directory structure.  Return to caller.  */
564         printf("ERROR!\n");
565         test_control_return(7);
566     }
567 
568     /* Traverse the directory structure recursively.  */
569     traverse_directory(FX_NULL);
570 
571     /* Determine if the traversal matched what was expected.  */
572     if (error_counter)
573     {
574 
575         /* Nope, error traversing the directory structure!  */
576         printf("ERROR!\n");
577         test_control_return(8);
578     }
579 
580     status  = fx_directory_local_path_clear(&ram_disk);
581     status += fx_directory_local_path_set(&ram_disk, &local_path, "RootDir04");
582     status += fx_directory_local_path_set(&ram_disk, &local_path, "../RootDir03");
583     if (status != FX_SUCCESS)
584     {
585         printf("ERROR!\n");
586         test_control_return(9);
587     }
588 
589     fx_directory_local_path_get_copy(&ram_disk, path_name_buffer, sizeof(path_name_buffer));
590     if (strcmp(path_name_buffer, "/RootDir03"))
591     {
592         printf("ERROR!\n");
593         test_control_return(233);
594     }
595 
596     /* Close the media.  */
597     status =  fx_media_close(&ram_disk);
598     return_if_fail(status == FX_SUCCESS);
599 
600     /* Format the media.  This needs to be done before opening it!  */
601     status =  fx_media_format(&ram_disk,
602                             _fx_ram_driver,         // Driver entry
603                             ram_disk_memory,        // RAM disk memory pointer
604                             cache_buffer,           // Media buffer pointer
605                             CACHE_SIZE,             // Media buffer size
606                             "MY_RAM_DISK",          // Volume Name
607                             1,                      // Number of FATs
608                             32,                     // Directory Entries
609                             0,                      // Hidden sectors
610                             512,                    // Total sectors
611                             128,                    // Sector size
612                             1,                      // Sectors per cluster
613                             1,                      // Heads
614                             1);                     // Sectors per track
615     return_if_fail(status == FX_SUCCESS);
616 
617     /* Try getting directory local path before media open. */
618     status = fx_directory_local_path_get(&ram_disk, &path_name);
619     return_if_fail(status == FX_MEDIA_NOT_OPEN);
620 
621     /* Open the ram_disk.  */
622     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
623     return_if_fail(status == FX_SUCCESS);
624 
625     /* Get local path. */
626     status = fx_directory_local_path_get(&ram_disk, &path_name);
627     return_if_fail(status == FX_SUCCESS);
628 
629     status = fx_directory_local_path_clear(&ram_disk);
630     return_if_fail(status == FX_SUCCESS);
631 
632     /* Get local path after clearing. */
633     status = fx_directory_local_path_get(&ram_disk, &path_name);
634     return_if_fail(status == FX_SUCCESS);
635 
636     /* Test corner case where last character of fx_media_last_found_name is different from current path. */
637     last_character_compare_test();
638 
639     printf("SUCCESS!\n");
640     test_control_return(0);
641 }
642 
643 
644 /* Define the directory traversal routine for the local path test.  */
traverse_directory(CHAR * directory_name)645 void  traverse_directory(CHAR *directory_name)
646 {
647 
648 FX_LOCAL_PATH   local_path;
649 FX_FILE         file;
650 UINT            status;
651 CHAR            name[300];
652 UINT            skip;
653 
654 
655     /* Determine if we are at the start.  */
656     if (directory_name == FX_NULL)
657     {
658         status =  fx_directory_local_path_set(&ram_disk, &local_path, "\\");
659         skip =  0;
660     }
661     else
662     {
663         status =  fx_directory_local_path_set(&ram_disk, &local_path, directory_name);
664         skip =  2;
665     }
666 
667     /* Get the first directory entry in the root path.  */
668     status =  fx_directory_first_entry_find(&ram_disk, name);
669 
670     /* Loop through the directory entries for this path.  */
671     while (status == FX_SUCCESS)
672     {
673 
674         /* Compare with what is expected.  */
675         if (strcmp(name, expected_name[expected_index++]))
676             error_counter++;
677 
678         /* Determine if this name is a directory or a file.  */
679         status =  fx_directory_name_test(&ram_disk, name);
680 
681         /* What is it?  */
682         if (status == FX_NOT_DIRECTORY)
683         {
684 
685             /* This is a file, open it to test its integrity.  */
686             status =  fx_file_open(&ram_disk, &file, name, FX_OPEN_FOR_READ);
687             if (status != FX_SUCCESS)
688                 error_counter++;
689             status =  fx_file_close(&file);
690             if (status != FX_SUCCESS)
691                 error_counter++;
692 
693             /* Pickup the next directory entry.  */
694             status =  fx_directory_next_entry_find(&ram_disk, name);
695         }
696         else if (status == FX_SUCCESS)
697         {
698 
699             /* Skip the first two entries...  */
700             if (skip)
701                 skip--;
702             else
703             {
704                 /* Recursive call to traverse directory.  */
705                 traverse_directory(name);
706 
707                 /* Restore path.  */
708                 status =  fx_directory_local_path_restore(&ram_disk, &local_path);
709             }
710 
711             status =  fx_directory_next_entry_find(&ram_disk, name);
712         }
713     }
714 
715     fx_directory_local_path_clear(&ram_disk);
716 
717 /* Only run this if error checking is enabled */
718 #ifndef FX_DISABLE_ERROR_CHECKING
719     /* send null pointer to generate an error */
720     status = fx_directory_local_path_clear(FX_NULL);
721     if (status != FX_PTR_ERROR)
722     {
723         printf("ERROR!\n");
724         test_control_return(11);
725     }
726 
727     /* send null pointer to generate an error */
728     status = fx_directory_local_path_restore(FX_NULL, FX_NULL);
729     if (status != FX_PTR_ERROR)
730     {
731         printf("ERROR!\n");
732         test_control_return(12);
733     }
734 
735     /* send null pointer to generate an error */
736     status = fx_directory_local_path_set(FX_NULL, FX_NULL, "\\");
737     if (status != FX_PTR_ERROR)
738     {
739         printf("ERROR!\n");
740         test_control_return(13);
741     }
742 
743     /* send null pointer to generate an error */
744     status = fx_directory_name_test(FX_NULL, name);
745     if (status != FX_PTR_ERROR)
746     {
747         printf("ERROR!\n");
748         test_control_return(14);
749     }
750 #endif /* FX_DISABLE_ERROR_CHECKING */
751 }
752 
753 
754 /* Test corner case where last character of fx_media_last_found_name is different from current path.  */
last_character_compare_test()755 static void    last_character_compare_test()
756 {
757 FX_FILE my_file;
758 FX_LOCAL_PATH root_path, test1_path, test2_path;
759 
760     return_if_fail(fx_directory_local_path_set(&ram_disk, &root_path, "/") == FX_SUCCESS);
761     return_if_fail(fx_directory_create(&ram_disk, "test_1") == FX_SUCCESS);
762     return_if_fail(fx_directory_create(&ram_disk, "test_2") == FX_SUCCESS);
763     return_if_fail(fx_directory_local_path_set(&ram_disk, &test1_path, "test_1") == FX_SUCCESS);
764     return_if_fail(fx_directory_local_path_set(&ram_disk, &root_path, "/") == FX_SUCCESS);
765     return_if_fail(fx_directory_local_path_set(&ram_disk, &test2_path, "test_2") == FX_SUCCESS);
766 
767     return_if_fail(fx_directory_local_path_restore(&ram_disk, &test1_path) == FX_SUCCESS);
768     return_if_fail(fx_file_create(&ram_disk, "file_0001.txt") == FX_SUCCESS);
769     return_if_fail(fx_file_open(&ram_disk, &my_file, "/test_1/file_0001.txt", FX_OPEN_FOR_READ) == FX_SUCCESS);
770     return_if_fail(fx_file_close(&my_file) == FX_SUCCESS);
771     return_if_fail(fx_directory_local_path_restore(&ram_disk, &test2_path) == FX_SUCCESS);
772     return_if_fail(fx_file_create(&ram_disk, "file_0001.txt") == FX_SUCCESS);
773     return_if_fail(fx_file_open(&ram_disk, &my_file, "/test_2/file_0001.txt", FX_OPEN_FOR_READ) == FX_SUCCESS);
774     return_if_fail(fx_file_close(&my_file) == FX_SUCCESS);
775 }
776 
777 #else
778 
779 #include "fx_api.h"
780 #include   "fx_ram_driver_test.h"
781 #include   <stdio.h>
782 
783 
784 void  test_control_return(UINT status);
785 
786 /* Define what the initial system looks like.  */
787 
788 #ifdef CTEST
test_application_define(void * first_unused_memory)789 void test_application_define(void *first_unused_memory)
790 #else
791 void    filex_directory_local_path_application_define(void *first_unused_memory)
792 #endif
793 {
794 
795     FX_PARAMETER_NOT_USED(first_unused_memory);
796 
797     /* Print out some test information banners.  */
798     printf("FileX Test:   Directory local path test..............................N/A\n");
799 
800     test_control_return(255);
801 }
802 
803 #endif
804