1 /* This FileX test concentrates on the basic media volume get/set operation.  */
2 
3 #ifndef FX_STANDALONE_ENABLE
4 #include   "tx_api.h"
5 #endif
6 #include   "fx_api.h"
7 #include   "fx_media.h"
8 #include   "fx_utility.h"
9 #include   "fx_ram_driver_test.h"
10 #include   <stdio.h>
11 
12 #define     DEMO_STACK_SIZE         4096
13 #define     CACHE_SIZE              16*128
14 
15 
16 /* Define the ThreadX and FileX object control blocks...  */
17 
18 #ifndef FX_STANDALONE_ENABLE
19 static TX_THREAD               ftest_0;
20 #endif
21 static FX_MEDIA                ram_disk;
22 
23 
24 /* Define the counters used in the test application...  */
25 
26 #ifndef FX_STANDALONE_ENABLE
27 static UCHAR                  *ram_disk_memory;
28 static UCHAR                  *cache_buffer;
29 #else
30 static UCHAR                   cache_buffer[CACHE_SIZE];
31 #endif
32 
33 
34 /* Define thread prototypes.  */
35 
36 void    filex_media_volume_get_set_application_define(void *first_unused_memory);
37 static void    ftest_0_entry(ULONG thread_input);
38 
39 VOID  _fx_ram_driver(FX_MEDIA *media_ptr);
40 void  test_control_return(UINT status);
41 
42 
43 
44 /* Define what the initial system looks like.  */
45 
46 #ifdef CTEST
test_application_define(void * first_unused_memory)47 void test_application_define(void *first_unused_memory)
48 #else
49 void    filex_media_volume_get_set_application_define(void *first_unused_memory)
50 #endif
51 {
52 
53 #ifndef FX_STANDALONE_ENABLE
54 UCHAR    *pointer;
55 
56 
57     /* Setup the working pointer.  */
58     pointer =  (UCHAR *) first_unused_memory;
59 
60     /* Create the main thread.  */
61     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
62             pointer, DEMO_STACK_SIZE,
63             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
64 
65     pointer =  pointer + DEMO_STACK_SIZE;
66 
67     /* Setup memory for the RAM disk and the sector cache.  */
68     cache_buffer =  pointer;
69     pointer =  pointer + CACHE_SIZE;
70     ram_disk_memory =  pointer;
71 
72 #endif
73 
74     /* Initialize the FileX system.  */
75     fx_system_initialize();
76 #ifdef FX_STANDALONE_ENABLE
77     ftest_0_entry(0);
78 #endif
79 }
80 
81 
82 
83 /* Define the test threads.  */
84 
ftest_0_entry(ULONG thread_input)85 static void    ftest_0_entry(ULONG thread_input)
86 {
87 
88 UINT        status;
89 CHAR        volume_buffer[32];
90 
91     FX_PARAMETER_NOT_USED(thread_input);
92 
93     /* Print out some test information banners.  */
94     printf("FileX Test:   Media volume get/set test..............................");
95 
96     /* Format the media.  This needs to be done before opening it!  */
97     status =  fx_media_format(&ram_disk,
98                             _fx_ram_driver,         // Driver entry
99                             ram_disk_memory,        // RAM disk memory pointer
100                             cache_buffer,           // Media buffer pointer
101                             CACHE_SIZE,             // Media buffer size
102                             "MY_RAM_DISK",          // Volume Name
103                             1,                      // Number of FATs
104                             32,                     // Directory Entries
105                             0,                      // Hidden sectors
106                             256,                    // Total sectors
107                             128,                    // Sector size
108                             1,                      // Sectors per cluster
109                             1,                      // Heads
110                             1);                     // Sectors per track
111 
112     /* Determine if the format had an error.  */
113     if (status)
114     {
115 
116         printf("ERROR!\n");
117         test_control_return(2);
118     }
119 
120     /* try to set the media volume name before the media is opened */
121     status =  fx_media_volume_set(&ram_disk, "NEW");
122     if (status != FX_MEDIA_NOT_OPEN)
123     {
124         printf("ERROR!\n");
125         test_control_return(11);
126     }
127 
128     /* try to get the media volume name before the media is opened */
129     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
130     if (status != FX_MEDIA_NOT_OPEN)
131     {
132         printf("ERROR!\n");
133         test_control_return(11);
134     }
135 
136     /* Open the ram_disk.  */
137     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
138 
139     /* Check the status.  */
140     if (status != FX_SUCCESS)
141     {
142 
143         /* Error, return error code.  */
144         printf("ERROR!\n");
145         test_control_return(3);
146     }
147 
148 /* Only run this if error checking is enabled */
149 #ifndef FX_DISABLE_ERROR_CHECKING
150     /* send null pointer to generate an error */
151     status = fx_media_volume_get(FX_NULL, volume_buffer, FX_DIRECTORY_SECTOR);
152     if (status != FX_PTR_ERROR)
153     {
154         printf("ERROR!\n");
155         test_control_return(11);
156     }
157 
158     /* send null pointer to generate an error for extended version */
159     status = fx_media_volume_get_extended(FX_NULL, volume_buffer, 0, FX_DIRECTORY_SECTOR);
160     if (status != FX_PTR_ERROR)
161     {
162         printf("ERROR!\n");
163         test_control_return(11);
164     }
165 
166     /* send null pointer to generate an error */
167     status = fx_media_volume_set(FX_NULL, "");
168     if (status != FX_PTR_ERROR)
169     {
170         printf("ERROR!\n");
171         test_control_return(11);
172     }
173 #else
174     /* try to set the media volume name to something invalid */
175     status =  fx_media_volume_set(&ram_disk, "");
176     if (status != FX_INVALID_NAME)
177     {
178         printf("ERROR!\n");
179         test_control_return(11);
180     }
181 #endif /* FX_DISABLE_ERROR_CHECKING */
182 
183     /* Get the current volume name - from boot record.  */
184     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
185 
186     /* Determine if there was an error getting the volume name.  */
187     if ((status != FX_SUCCESS) ||
188         (volume_buffer[0] != 'M') ||
189         (volume_buffer[1] != 'Y') ||
190         (volume_buffer[2] != '_') ||
191         (volume_buffer[3] != 'R') ||
192         (volume_buffer[4] != 'A') ||
193         (volume_buffer[5] != 'M') ||
194         (volume_buffer[6] != '_') ||
195         (volume_buffer[7] != 'D') ||
196         (volume_buffer[8] != 'I') ||
197         (volume_buffer[9] != 'S') ||
198         (volume_buffer[10] != 'K'))
199     {
200 
201         /* Error getting the volume name.  */
202         printf("ERROR!\n");
203         test_control_return(4);
204     }
205 
206     /* Set volume_buffer to known state.  */
207     memcpy(volume_buffer, "ORIGINALSTRING", 15);
208 
209     /* Get the current volume name - from boot record, using extended version.  */
210     status = fx_media_volume_get_extended(&ram_disk, volume_buffer, 2, FX_BOOT_SECTOR);
211 
212     /* Determine if there was an error getting the volume name.  */
213     if ((status != FX_BUFFER_ERROR) ||
214         (volume_buffer[0] != 'M') ||
215         (volume_buffer[1] != '\0') ||
216         (volume_buffer[2] != 'I') ||
217         (volume_buffer[3] != 'G'))
218     {
219 
220         /* Error getting the volume name.  */
221         printf("ERROR!\n");
222         test_control_return(4);
223     }
224 
225 
226     /* Get the current volume name - from root directory.  */
227     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
228 
229     /* Determine if we found a volume name in the root directory.
230      * When not, the value from boot sector will be returned. */
231     if ((status != FX_SUCCESS) ||
232         (volume_buffer[0] != 'M') ||
233         (volume_buffer[1] != 'Y') ||
234         (volume_buffer[2] != '_') ||
235         (volume_buffer[3] != 'R') ||
236         (volume_buffer[4] != 'A') ||
237         (volume_buffer[5] != 'M') ||
238         (volume_buffer[6] != '_') ||
239         (volume_buffer[7] != 'D') ||
240         (volume_buffer[8] != 'I') ||
241         (volume_buffer[9] != 'S') ||
242         (volume_buffer[10] != 'K'))
243     {
244 
245         /* Error getting the volume name.  */
246         printf("ERROR!\n");
247         test_control_return(5);
248     }
249 
250     /* It is now time to set the volume name.  */
251     status =  fx_media_volume_set(&ram_disk, "NEW");
252 
253     /* Determine if the volume name set was successful...  */
254     if (status != FX_SUCCESS)
255     {
256 
257         /* Error setting the volume name.  */
258         printf("ERROR!\n");
259         test_control_return(6);
260     }
261 
262     /* Flush and invalidate the media...   */
263     fx_media_cache_invalidate(&ram_disk);
264 
265     /* Get the current volume name - from boot record.  */
266     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
267 
268     /* Determine if there was an error getting the volume name.  */
269     if ((status != FX_SUCCESS) ||
270         (volume_buffer[0] != 'N') ||
271         (volume_buffer[1] != 'E') ||
272         (volume_buffer[2] != 'W') ||
273         (volume_buffer[3] != (CHAR) 0))
274     {
275 
276         /* Error getting the volume name.  */
277         printf("ERROR!\n");
278         test_control_return(7);
279     }
280 
281     /* Get the current volume name - from root directory.  */
282     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
283 
284     /* Determine if we found a volume name in the root directory... should not since our
285        format doesn't do that!  */
286     if ((status != FX_SUCCESS) ||
287         (volume_buffer[0] != 'N') ||
288         (volume_buffer[1] != 'E') ||
289         (volume_buffer[2] != 'W') ||
290         (volume_buffer[3] != (CHAR) 0))
291     {
292 
293         /* Error getting the volume name.  */
294         printf("ERROR!\n");
295         test_control_return(8);
296     }
297 
298     /* Close the media.  */
299     status =  fx_media_close(&ram_disk);
300 
301     /* Determine if the test was successful.  */
302     if (status != FX_SUCCESS)
303     {
304 
305         printf("ERROR!\n");
306         test_control_return(10);
307     }
308 
309     /* Format the media in FAT32.  This needs to be done before opening it!  */
310     status =  fx_media_format(&ram_disk,
311                             _fx_ram_driver,         // Driver entry
312                             ram_disk_memory,        // RAM disk memory pointer
313                             cache_buffer,           // Media buffer pointer
314                             CACHE_SIZE,             // Media buffer size
315                             "MY_RAM_DISK",          // Volume Name
316                             1,                      // Number of FATs
317                             32,                     // Directory Entries
318                             0,                      // Hidden sectors
319                             70000,                   // Total sectors - FAT 32
320                             128,                    // Sector size
321                             1,                      // Sectors per cluster
322                             1,                      // Heads
323                             1);                     // Sectors per track
324 
325     /* Determine if the format had an error.  */
326     if (status)
327     {
328 
329         printf("ERROR!\n");
330         test_control_return(11);
331     }
332 
333 
334     /* Open the ram_disk.  */
335     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
336 
337     /* Check the status.  */
338     if (status != FX_SUCCESS)
339     {
340 
341         /* Error, return error code.  */
342         printf("ERROR!\n");
343         test_control_return(12);
344     }
345 
346     /* Set the volume name to a NULL volume name.   */
347     volume_buffer[0] =  0;
348     status =  _fx_media_volume_set(&ram_disk, volume_buffer);
349     if (status != FX_INVALID_NAME)
350     {
351         printf("ERROR!\n");
352         test_control_return(13);
353     }
354 
355     /* Now set the volume name to something longer than 11 characters that are lower case.  */
356     status =  fx_media_volume_set(&ram_disk, "thisisareallylongvolumename");
357     if (status != FX_SUCCESS)
358     {
359         printf("ERROR!\n");
360         test_control_return(14);
361     }
362 
363     /* Now set the volume name to something small with lower case.  */
364     status =  fx_media_volume_set(&ram_disk, "sm");
365     if (status != FX_SUCCESS)
366     {
367         printf("ERROR!\n");
368         test_control_return(15);
369     }
370 
371     /* Now get the volume name from the boot sector.  */
372     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
373     if ((status != FX_SUCCESS) || (volume_buffer[0] != 'S') || (volume_buffer[1] != 'M') || (volume_buffer[2] != 0))
374     {
375         printf("ERROR!\n");
376         test_control_return(16);
377     }
378 
379     /* Now get the volume name from the directory sector.  */
380     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
381     if ((status != FX_SUCCESS) || (volume_buffer[0] != 'S') || (volume_buffer[1] != 'M') || (volume_buffer[2] != 0))
382     {
383         printf("ERROR!\n");
384         test_control_return(17);
385     }
386 
387     /* Set volume_buffer to known state.  */
388     memcpy(volume_buffer, "ORIGINALSTRING", 15);
389 
390     /* Get the current volume name - from root directory.  */
391     status = fx_media_volume_get_extended(&ram_disk, volume_buffer, 2, FX_DIRECTORY_SECTOR);
392 
393     /* Determine if we found a volume name in the root directory.
394      * When not, the value from boot sector will be returned. */
395     if ((status != FX_BUFFER_ERROR) ||
396         (volume_buffer[0] != 'S') ||
397         (volume_buffer[1] != '\0') ||
398         (volume_buffer[2] != 'I') ||
399         (volume_buffer[3] != 'G'))
400     {
401 
402         /* Error getting the volume name.  */
403         printf("ERROR!\n");
404         test_control_return(17);
405     }
406     /* Close the media.  */
407     status =  fx_media_close(&ram_disk);
408 
409     if (status != FX_SUCCESS)
410     {
411         printf("ERROR!\n");
412         test_control_return(18);
413     }
414 
415 
416     /* Format the media in FAT16.  This needs to be done before opening it!  */
417     status =  fx_media_format(&ram_disk,
418                             _fx_ram_driver,         // Driver entry
419                             ram_disk_memory,        // RAM disk memory pointer
420                             cache_buffer,           // Media buffer pointer
421                             CACHE_SIZE,             // Media buffer size
422                             "MY_RAM_DISK",          // Volume Name
423                             1,                      // Number of FATs
424                             16,                     // Directory Entries
425                             0,                      // Hidden sectors
426                             7000,                   // Total sectors - FAT 16
427                             128,                    // Sector size
428                             1,                      // Sectors per cluster
429                             1,                      // Heads
430                             1);                     // Sectors per track
431 
432     /* Determine if the format had an error.  */
433     if (status)
434     {
435 
436         printf("ERROR!\n");
437         test_control_return(19);
438     }
439 
440     /* Open the ram_disk.  */
441     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
442 
443     /* Check the status.  */
444     if (status != FX_SUCCESS)
445     {
446 
447         /* Error, return error code.  */
448         printf("ERROR!\n");
449         test_control_return(20);
450     }
451 
452     /* Fill up the root directory (16 entries), so the volume set won't find an empty entry.  */
453     status =   fx_file_create(&ram_disk, "FILE1.TXT");
454     status +=  fx_file_create(&ram_disk, "FILE2.TXT");
455     status +=  fx_file_create(&ram_disk, "FILE3.TXT");
456     status +=  fx_file_create(&ram_disk, "FILE4.TXT");
457     status +=  fx_file_create(&ram_disk, "FILE5.TXT");
458     status +=  fx_file_create(&ram_disk, "FILE6.TXT");
459     status +=  fx_file_create(&ram_disk, "FILE7.TXT");
460     status +=  fx_file_create(&ram_disk, "FILE8.TXT");
461     status +=  fx_file_create(&ram_disk, "FILE9.TXT");
462     status +=  fx_file_create(&ram_disk, "FILE10.TXT");
463     status +=  fx_file_create(&ram_disk, "FILE11.TXT");
464     status +=  fx_file_create(&ram_disk, "FILE12.TXT");
465     status +=  fx_file_create(&ram_disk, "FILE13.TXT");
466     status +=  fx_file_create(&ram_disk, "FILE14.TXT");
467     status +=  fx_file_create(&ram_disk, "FILE15.TXT");
468     status +=  fx_file_create(&ram_disk, "FILE16.TXT");
469 
470     /* Check the status.  */
471     if (status != FX_SUCCESS)
472     {
473 
474         /* Error, return error code.  */
475         printf("ERROR!\n");
476         test_control_return(21);
477     }
478 
479     /* Now set the volume name.  */
480     status =  fx_media_volume_set(&ram_disk, "MINE ");
481     if (status != FX_MEDIA_INVALID)
482     {
483         printf("ERROR!\n");
484         test_control_return(22);
485     }
486 
487     /* Now delete the first entry so we can find it.  */
488     status =  fx_file_delete(&ram_disk, "FILE1.TXT");
489 
490     /* And set the volume name again.  */
491     status +=  fx_media_volume_set(&ram_disk, "MINE ");
492     if (status != FX_SUCCESS)
493     {
494         printf("ERROR!\n");
495         test_control_return(23);
496     }
497 
498     /* Set the volume name again - should just use the same directory entry.  */
499     status =  fx_media_volume_set(&ram_disk, "MINE1 ");
500     if (status != FX_SUCCESS)
501     {
502         printf("ERROR!\n");
503         test_control_return(24);
504     }
505 
506     /* Close the media.  */
507     status =  fx_media_close(&ram_disk);
508 
509     if (status != FX_SUCCESS)
510     {
511         printf("ERROR!\n");
512         test_control_return(25);
513     }
514 
515     /* Format the media in FAT16.  This needs to be done before opening it!  */
516     status =  fx_media_format(&ram_disk,
517                             _fx_ram_driver,         // Driver entry
518                             ram_disk_memory,        // RAM disk memory pointer
519                             cache_buffer,           // Media buffer pointer
520                             CACHE_SIZE,             // Media buffer size
521                             "MY_RAM_DISK",          // Volume Name
522                             1,                      // Number of FATs
523                             16,                     // Directory Entries
524                             0,                      // Hidden sectors
525                             7000,                   // Total sectors - FAT 16
526                             128,                    // Sector size
527                             1,                      // Sectors per cluster
528                             1,                      // Heads
529                             1);                     // Sectors per track
530 
531     /* Determine if the format had an error.  */
532     if (status)
533     {
534 
535         printf("ERROR!\n");
536         test_control_return(26);
537     }
538 
539     /* Open the ram_disk.  */
540     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
541 
542     /* Check the status.  */
543     if (status != FX_SUCCESS)
544     {
545 
546         /* Error, return error code.  */
547         printf("ERROR!\n");
548         test_control_return(27);
549     }
550 
551     /* Fill up the root directory (16 entries), so the volume set won't find an empty entry.  */
552     status =   fx_file_create(&ram_disk, "FILE1.TXT");
553     status +=  fx_file_create(&ram_disk, "FILE2.TXT");
554     status +=  fx_file_create(&ram_disk, "FILE3.TXT");
555     status +=  fx_file_create(&ram_disk, "FILE4.TXT");
556     status +=  fx_file_create(&ram_disk, "FILE5.TXT");
557     status +=  fx_file_create(&ram_disk, "FILE6.TXT");
558     status +=  fx_file_create(&ram_disk, "FILE7.TXT");
559     status +=  fx_file_create(&ram_disk, "FILE8.TXT");
560     status +=  fx_file_create(&ram_disk, "FILE9.TXT");
561     status +=  fx_file_create(&ram_disk, "FILE10.TXT");
562     status +=  fx_file_create(&ram_disk, "FILE11.TXT");
563     status +=  fx_file_create(&ram_disk, "FILE12.TXT");
564     status +=  fx_file_create(&ram_disk, "FILE13.TXT");
565     status +=  fx_file_create(&ram_disk, "FILE14.TXT");
566     status +=  fx_file_create(&ram_disk, "FILE15.TXT");
567     status +=  fx_file_create(&ram_disk, "FILE16.TXT");
568 
569     /* Check the status.  */
570     if (status != FX_SUCCESS)
571     {
572 
573         /* Error, return error code.  */
574         printf("ERROR!\n");
575         test_control_return(28);
576     }
577 
578     /* Now delete the first entry so we can find it.  */
579     status =  fx_file_delete(&ram_disk, "FILE16.TXT");
580 
581     /* And set the volume name again.  */
582     status +=  fx_media_volume_set(&ram_disk, "mine~ ");
583     if (status != FX_SUCCESS)
584     {
585         printf("ERROR!\n");
586         test_control_return(29);
587     }
588 
589     /* Set the volume name again - should just use the same directory entry.  */
590     status =  fx_media_volume_set(&ram_disk, "MINE1 ");
591     if (status != FX_SUCCESS)
592     {
593         printf("ERROR!\n");
594         test_control_return(30);
595     }
596 
597     /* Close the media.  */
598     status =  fx_media_close(&ram_disk);
599 
600     if (status != FX_SUCCESS)
601     {
602         printf("ERROR!\n");
603         test_control_return(31);
604     }
605 
606     /* Format the media in FAT16.  This needs to be done before opening it!  */
607     status =  fx_media_format(&ram_disk,
608                             _fx_ram_driver,         // Driver entry
609                             ram_disk_memory,        // RAM disk memory pointer
610                             cache_buffer,           // Media buffer pointer
611                             CACHE_SIZE,             // Media buffer size
612                             "MY_RAM_DISK",          // Volume Name
613                             1,                      // Number of FATs
614                             16,                     // Directory Entries
615                             0,                      // Hidden sectors
616                             7000,                   // Total sectors - FAT 16
617                             128,                    // Sector size
618                             1,                      // Sectors per cluster
619                             1,                      // Heads
620                             1);                     // Sectors per track
621 
622     /* Determine if the format had an error.  */
623     if (status)
624     {
625 
626         printf("ERROR!\n");
627         test_control_return(32);
628     }
629 
630     /* Open the ram_disk.  */
631     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
632 
633     /* Check the status.  */
634     if (status != FX_SUCCESS)
635     {
636 
637         /* Error, return error code.  */
638         printf("ERROR!\n");
639         test_control_return(33);
640     }
641 
642     /* Almost fill up the root directory (15 entries), so the volume set won't find an empty entry.  */
643     status =   fx_file_create(&ram_disk, "FILE1.TXT");
644     status +=  fx_file_create(&ram_disk, "FILE2.TXT");
645     status +=  fx_file_create(&ram_disk, "FILE3.TXT");
646     status +=  fx_file_create(&ram_disk, "FILE4.TXT");
647     status +=  fx_file_create(&ram_disk, "FILE5.TXT");
648     status +=  fx_file_create(&ram_disk, "FILE6.TXT");
649     status +=  fx_file_create(&ram_disk, "FILE7.TXT");
650     status +=  fx_file_create(&ram_disk, "FILE8.TXT");
651     status +=  fx_file_create(&ram_disk, "FILE9.TXT");
652     status +=  fx_file_create(&ram_disk, "FILE10.TXT");
653     status +=  fx_file_create(&ram_disk, "FILE11.TXT");
654     status +=  fx_file_create(&ram_disk, "FILE12.TXT");
655     status +=  fx_file_create(&ram_disk, "FILE13.TXT");
656     status +=  fx_file_create(&ram_disk, "FILE14.TXT");
657     status +=  fx_file_create(&ram_disk, "FILE15.TXT");
658 
659     /* Leave the last entry free for search test.  */
660 
661     /* Check the status.  */
662     if (status != FX_SUCCESS)
663     {
664 
665         /* Error, return error code.  */
666         printf("ERROR!\n");
667         test_control_return(34);
668     }
669 
670     /* Set the volume name.  */
671     status +=  fx_media_volume_set(&ram_disk, "MY ");
672     if (status != FX_SUCCESS)
673     {
674         printf("ERROR!\n");
675         test_control_return(35);
676     }
677 
678     /* Close the media.  */
679     status =  fx_media_close(&ram_disk);
680 
681     if (status != FX_SUCCESS)
682     {
683         printf("ERROR!\n");
684         test_control_return(36);
685     }
686 
687     /* Format the media in FAT16.  This needs to be done before opening it!  */
688     status =  fx_media_format(&ram_disk,
689                             _fx_ram_driver,         // Driver entry
690                             ram_disk_memory,        // RAM disk memory pointer
691                             cache_buffer,           // Media buffer pointer
692                             CACHE_SIZE,             // Media buffer size
693                             "MY_RAM_DISK",          // Volume Name
694                             1,                      // Number of FATs
695                             16,                     // Directory Entries
696                             0,                      // Hidden sectors
697                             7000,                   // Total sectors - FAT 16
698                             128,                    // Sector size
699                             1,                      // Sectors per cluster
700                             1,                      // Heads
701                             1);                     // Sectors per track
702 
703     /* Determine if the format had an error.  */
704     if (status)
705     {
706 
707         printf("ERROR!\n");
708         test_control_return(37);
709     }
710 
711     /* Open the ram_disk.  */
712     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
713 
714     /* Check the status.  */
715     if (status != FX_SUCCESS)
716     {
717 
718         /* Error, return error code.  */
719         printf("ERROR!\n");
720         test_control_return(38);
721     }
722 
723     /* Almost fill up the root directory (15 entries), so the volume set won't find an empty entry.  */
724     status =   fx_file_create(&ram_disk, "FILE1.TXT");
725     status +=  fx_file_create(&ram_disk, "FILE2.TXT");
726     status +=  fx_file_create(&ram_disk, "FILE3.TXT");
727     status +=  fx_file_create(&ram_disk, "FILE4.TXT");
728     status +=  fx_file_create(&ram_disk, "FILE5.TXT");
729     status +=  fx_file_create(&ram_disk, "FILE6.TXT");
730     status +=  fx_file_create(&ram_disk, "FILE7.TXT");
731     status +=  fx_file_create(&ram_disk, "FILE8.TXT");
732     status +=  fx_file_create(&ram_disk, "FILE9.TXT");
733     status +=  fx_file_create(&ram_disk, "FILE10.TXT");
734     status +=  fx_file_create(&ram_disk, "FILE11.TXT");
735     status +=  fx_file_create(&ram_disk, "FILE12.TXT");
736     status +=  fx_file_create(&ram_disk, "FILE13.TXT");
737     status +=  fx_file_create(&ram_disk, "FILE14.TXT");
738     status +=  fx_file_create(&ram_disk, "FILE15.TXT");
739 
740     /* Leave the last entry free for search test... and delete file 5 and 6 to create some available slots.  */
741     status +=  fx_file_delete(&ram_disk, "FILE6.TXT");
742     status +=  fx_file_delete(&ram_disk, "FILE7.TXT");
743 
744     /* Check the status.  */
745     if (status != FX_SUCCESS)
746     {
747 
748         /* Error, return error code.  */
749         printf("ERROR!\n");
750         test_control_return(39);
751     }
752 
753     /* Set the volume name.  */
754     status =  fx_media_volume_set(&ram_disk, "MY ");
755     if (status != FX_SUCCESS)
756     {
757         printf("ERROR!\n");
758         test_control_return(40);
759     }
760 
761     /* Set the volume name again.  */
762     status =  fx_media_volume_set(&ram_disk, "MY ");
763     if (status != FX_SUCCESS)
764     {
765         printf("ERROR!\n");
766         test_control_return(41);
767     }
768 
769     /* Test the I/O errors.  */
770 
771     /* Cause an error reading sector 0.  */
772     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
773     _fx_ram_driver_io_error_request =  1;
774     status =  fx_media_volume_set(&ram_disk, "MY ");
775     _fx_ram_driver_io_error_request =  0;
776     if (status != FX_IO_ERROR)
777     {
778         printf("ERROR!\n");
779         test_control_return(42);
780     }
781 
782     /* Cause an error reading the boot sector.  */
783     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
784     _fx_ram_driver_io_error_request =  2;
785     status =  fx_media_volume_set(&ram_disk, "MY ");
786     _fx_ram_driver_io_error_request =  0;
787     if (status != FX_IO_ERROR)
788     {
789         printf("ERROR!\n");
790         test_control_return(43);
791     }
792 
793     /* Cause an error writing the boot sector.  */
794     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
795     _fx_ram_driver_io_error_request =  2;
796     status =  fx_media_volume_set(&ram_disk, "MY ");
797     _fx_ram_driver_io_error_request =  0;
798     if (status != FX_IO_ERROR)
799     {
800         printf("ERROR!\n");
801         test_control_return(44);
802     }
803 
804     /* Cause an error reading the first directory entry.  */
805     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
806     _fx_ram_driver_io_error_request =  4;
807     status =  fx_media_volume_set(&ram_disk, "MY ");
808     _fx_ram_driver_io_error_request =  0;
809     if (status != FX_IO_ERROR)
810     {
811         printf("ERROR!\n");
812         test_control_return(45);
813     }
814 
815     /* Cause an error reading the logical directory sector.  */
816     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
817     _fx_utility_logical_sector_read_error_request =  8;
818     status =  fx_media_volume_set(&ram_disk, "MY ");
819     _fx_utility_logical_sector_write_error_request =  0;
820     if (status != FX_IO_ERROR)
821     {
822         printf("ERROR!\n");
823         test_control_return(46);
824     }
825 
826     /* Cause an error reading sector 0.  */
827     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
828     _fx_ram_driver_io_error_request =  1;
829     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
830     _fx_ram_driver_io_error_request =  0;
831     if (status != FX_IO_ERROR)
832     {
833         printf("ERROR!\n");
834         test_control_return(47);
835     }
836 
837     /* Cause an error reading the boot sector.  */
838     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
839     _fx_ram_driver_io_error_request =  2;
840     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
841     _fx_ram_driver_io_error_request =  0;
842     if (status != FX_IO_ERROR)
843     {
844         printf("ERROR!\n");
845         test_control_return(48);
846     }
847 
848     /* Cause an error reading the directory sector.  */
849     _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_TRUE);
850     _fx_ram_driver_io_error_request =  1;
851     status =  fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
852     _fx_ram_driver_io_error_request =  0;
853     if (status != FX_IO_ERROR)
854     {
855         printf("ERROR!\n");
856         test_control_return(49);
857     }
858 
859     /* Set a maximum length VOLUME NAME and retrieve it.  */
860     status =  fx_media_volume_set(&ram_disk, "MYVOLUME123");
861     status += fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
862 
863     /* Check for status.  */
864     if (status != FX_SUCCESS)
865     {
866         printf("ERROR!\n");
867         test_control_return(50);
868     }
869 
870     /* Set a maximum length VOLUME NAME and retrieve it.  */
871     status =  fx_media_volume_set(&ram_disk, "           ");
872     status += fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
873 
874     /* Check for status.  */
875     if (status != FX_SUCCESS)
876     {
877         printf("ERROR!\n");
878         test_control_return(53);
879     }
880 
881     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
882     if (status != FX_SUCCESS)
883     {
884         printf("ERROR!\n");
885         test_control_return(51);
886     }
887 
888     /* Close the media.  */
889     status =  fx_media_close(&ram_disk);
890 
891     if (status != FX_SUCCESS)
892     {
893         printf("ERROR!\n");
894         test_control_return(52);
895     }
896 
897     /* Format the media.  This needs to be done before opening it!  */
898     status =  fx_media_format(&ram_disk,
899                             _fx_ram_driver,         // Driver entry
900                             ram_disk_memory,        // RAM disk memory pointer
901                             cache_buffer,           // Media buffer pointer
902                             CACHE_SIZE,             // Media buffer size
903                             "MY_RAM_DISK",          // Volume Name
904                             1,                      // Number of FATs
905                             32,                     // Directory Entries
906                             0,                      // Hidden sectors
907                             256,                    // Total sectors
908                             128,                    // Sector size
909                             1,                      // Sectors per cluster
910                             1,                      // Heads
911                             1);                     // Sectors per track
912     return_if_fail(status == FX_SUCCESS);
913 
914     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
915     return_if_fail(status == FX_SUCCESS);
916 
917     status =  fx_media_volume_set(&ram_disk, "NEW");
918     return_if_fail(status == FX_SUCCESS);
919 
920     /* Fail to read the directory entry of the volume. */
921     _fx_utility_logical_sector_read_error_request = 2;
922     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
923     return_if_fail(status == FX_IO_ERROR);
924 
925     /* Close the media.  */
926     status =  fx_media_close(&ram_disk);
927 
928     if (status != FX_SUCCESS)
929     {
930         printf("ERROR!\n");
931         test_control_return(53);
932     }
933 
934     /* This test is added to check if fx_media_volume_get() returns volume entry that was marked free */
935     memset(ram_disk_memory,'\0',sizeof(ram_disk_memory));
936 
937     /* Format the media.  This needs to be done before opening it!  */
938     status =  fx_media_format(&ram_disk,
939                             _fx_ram_driver,         // Driver entry
940                             ram_disk_memory,        // RAM disk memory pointer
941                             cache_buffer,           // Media buffer pointer
942                             CACHE_SIZE,             // Media buffer size
943                             "NO NAME",              // Volume Name
944                             1,                      // Number of FATs
945                             32,                     // Directory Entries
946                             0,                      // Hidden sectors
947                             70000 * 8,              // Total sectors
948                             512,                    // Sector size
949                             1,                      // Sectors per cluster
950                             1,                      // Heads
951                             1);                     // Sectors per track
952     return_if_fail(status == FX_SUCCESS);
953 
954     status =  fx_media_open(&ram_disk, "RAMDISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
955     return_if_fail(status == FX_SUCCESS);;
956 
957     /* volume_buffer will contain "NO NAME" */
958     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
959     return_if_fail(status == FX_SUCCESS);
960 
961     status =  fx_media_volume_set(&ram_disk, "56781234");
962     return_if_fail(status == FX_SUCCESS);
963     fx_media_cache_invalidate(&ram_disk);
964 
965     /* volume_buffer will contain "56781234" */
966     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_BOOT_SECTOR);
967     return_if_fail(status == FX_SUCCESS);
968 
969     /* volume_buffer will contain "56781234" */
970     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
971     return_if_fail(status == FX_SUCCESS);
972 
973     /* Close the media.  */
974     status =  fx_media_close(&ram_disk);
975 
976     if (status != FX_SUCCESS)
977     {
978         printf("ERROR!\n");
979         test_control_return(54);
980     }
981 
982     /* Modify first character of the volume label entry in boot sector. This is done to verify
983     if the volume entry marked free is returned or not */
984     ram_disk_memory[71] = 0x39;
985 
986     /* First Character of Volume label in data section
987     The absolute address was found by looping accross the ram_disk_memory to find the Volume name in data section */
988     ram_disk_memory[2241024] = FX_DIR_ENTRY_FREE;
989 
990     memset(cache_buffer,'\0',sizeof(cache_buffer));
991 
992     status =  fx_media_open(&ram_disk, "RAMDISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
993     return_if_fail(status == FX_SUCCESS);;
994     status = fx_media_volume_get(&ram_disk, volume_buffer, FX_DIRECTORY_SECTOR);
995     return_if_fail(status == FX_SUCCESS);
996 
997     if ((status != FX_SUCCESS) || (volume_buffer[0] != '9'))
998     {
999         printf("ERROR!\n");
1000         test_control_return(55);
1001     }
1002 
1003     printf("SUCCESS!\n");
1004     test_control_return(0);
1005 }
1006 
1007