1 /* This FileX test concentrates on the basic media format, open, close operation.  */
2 
3 #ifndef FX_STANDALONE_ENABLE
4 #include   "tx_api.h"
5 #endif
6 #include   "fx_api.h"
7 #include   "fx_system.h"
8 #include   "fx_utility.h"
9 #include   <stdio.h>
10 #include   "fx_ram_driver_test.h"
11 
12 #define     DEMO_STACK_SIZE         4096
13 #define     CACHE_SIZE              256*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 static FX_FILE                 my_file;
23 static FX_MEDIA                ram_disk1;
24 static FX_FILE                 my_file1;
25 static FX_FILE                 my_file2;
26 static FX_FILE                 my_file3;
27 static FX_FILE                 my_file4;
28 static FX_FILE                 my_file5;
29 static FX_FILE                 my_file6;
30 static FX_FILE                 my_file7;
31 static FX_FILE                 my_file8;
32 static FX_FILE                 my_file9;
33 static FX_FILE                 my_file10;
34 static FX_FILE                 my_file11;
35 
36 
37 /* Define the counters used in the test application...  */
38 
39 #ifndef FX_STANDALONE_ENABLE
40 static UCHAR                  *ram_disk_memory;
41 static UCHAR                  *ram_disk_memory1;
42 static UCHAR                  *cache_buffer;
43 static UCHAR                  *cache_buffer1;
44 #else
45 static UCHAR                   cache_buffer[CACHE_SIZE];
46 static UCHAR                   cache_buffer1[CACHE_SIZE];
47 #endif
48 
49 
50 /* Define thread prototypes.  */
51 
52 void    filex_media_multiple_format_open_close_application_define(void *first_unused_memory);
53 static void    ftest_0_entry(ULONG thread_input);
54 
55 VOID  _fx_ram_driver(FX_MEDIA *media_ptr);
56 void  test_control_return(UINT status);
57 
58 
59 static ULONG open_count;
60 static ULONG close_count;
61 
ram_disk_open(FX_MEDIA * media_ptr)62 static void  ram_disk_open(FX_MEDIA *media_ptr)
63 {
64 
65     FX_PARAMETER_NOT_USED(media_ptr);
66 
67     open_count++;
68 }
69 
ram_disk_close(FX_MEDIA * media_ptr)70 static void  ram_disk_close(FX_MEDIA *media_ptr)
71 {
72 
73     FX_PARAMETER_NOT_USED(media_ptr);
74 
75     close_count++;
76 }
77 
78 
79 
80 /* Define what the initial system looks like.  */
81 
82 #ifdef CTEST
test_application_define(void * first_unused_memory)83 void test_application_define(void *first_unused_memory)
84 #else
85 void    filex_media_multiple_format_open_close_application_define(void *first_unused_memory)
86 #endif
87 {
88 
89 #ifndef FX_STANDALONE_ENABLE
90 UCHAR    *pointer;
91 
92 
93     /* Setup the working pointer.  */
94     pointer =  (UCHAR *) first_unused_memory;
95 
96     /* Create the main thread.  */
97     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
98             pointer, DEMO_STACK_SIZE,
99             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
100 
101     pointer =  pointer + DEMO_STACK_SIZE;
102 
103     /* Setup memory for the RAM disk and the sector cache.  */
104     cache_buffer =  pointer;
105     pointer =  pointer + (256*128) /* CACHE_SIZE */;
106     cache_buffer1 =  pointer;
107     pointer =  pointer + CACHE_SIZE;
108     ram_disk_memory =  pointer;
109     pointer =  pointer + (256*128);
110     ram_disk_memory1 =  pointer;
111 
112 #endif
113 
114     /* Initialize the FileX system.  */
115     fx_system_initialize();
116 #ifdef FX_STANDALONE_ENABLE
117     ftest_0_entry(0);
118 #endif
119 }
120 
121 
122 
123 /* Define the test threads.  */
124 
ftest_0_entry(ULONG thread_input)125 static void    ftest_0_entry(ULONG thread_input)
126 {
127 
128 UINT        status, status1;
129 ULONG       actual;
130 UINT        i, j;
131 UCHAR       local_buffer[32];
132 UCHAR       raw_sector_buffer[512];
133 UCHAR       volume_buffer[100];
134 ULONG       temp;
135 ULONG       temp1;
136 ULONG       temp2;
137 ULONG       temp3;
138 
139     FX_PARAMETER_NOT_USED(thread_input);
140 
141     /* Print out some test information banners.  */
142     printf("FileX Test:   Multiple Media format, open and close test.............");
143 
144     /* Format the media.  This needs to be done before opening it!  */
145     status =  fx_media_format(&ram_disk,
146                             _fx_ram_driver,         // Driver entry
147                             ram_disk_memory,        // RAM disk memory pointer
148                             cache_buffer,           // Media buffer pointer
149                             CACHE_SIZE,             // Media buffer size
150                             "MY_RAM_DISK",          // Volume Name
151                             1,                      // Number of FATs
152                             32,                     // Directory Entries
153                             0,                      // Hidden sectors
154                             256,                    // Total sectors
155                             128,                    // Sector size
156                             1,                      // Sectors per cluster
157                             1,                      // Heads
158                             1);                     // Sectors per track
159 
160     /* Format the second media. This needs to be done before opening it!  */
161     status +=  fx_media_format(&ram_disk,
162                             _fx_ram_driver,         // Driver entry
163                             ram_disk_memory1,        // RAM disk memory pointer
164                             cache_buffer1,           // Media buffer pointer
165                             CACHE_SIZE,             // Media buffer size
166                             "MY_RAM_DISK",          // Volume Name
167                             1,                      // Number of FATs
168                             32,                     // Directory Entries
169                             0,                      // Hidden sectors
170                             256,                    // Total sectors
171                             128,                    // Sector size
172                             1,                      // Sectors per cluster
173                             1,                      // Heads
174                             1);                     // Sectors per track
175 
176 
177     /* Determine if the format had an error.  */
178     if (status)
179     {
180 
181         printf("ERROR!\n");
182         test_control_return(2);
183     }
184 
185     /* Open each ram_disk.  */
186     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
187     status += fx_media_open(&ram_disk1,"RAM DISK", _fx_ram_driver, ram_disk_memory1,cache_buffer1,CACHE_SIZE);
188 
189     /* Check the status.  */
190     if (status != FX_SUCCESS)
191     {
192 
193         /* Error, return error code.  */
194         printf("ERROR!\n");
195         test_control_return(3);
196     }
197 
198     /* Create a file called TEST.TXT in the root directory.  */
199     status =  fx_file_create(&ram_disk, "TEST.TXT");
200     status1=  fx_file_create(&ram_disk1, "TEST.TXT");
201 
202     /* Check the first create status.  */
203     if (status != FX_SUCCESS)
204     {
205 
206         printf("ERROR!\n");
207         test_control_return(3);
208     }
209 
210     /* Check the second create status.  */
211     if (status1 != FX_SUCCESS)
212     {
213 
214         printf("ERROR!\n");
215         test_control_return(31);
216     }
217 
218     /* Open the test files.  */
219     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
220     status += fx_file_open(&ram_disk1, &my_file1, "TEST.TXT", FX_OPEN_FOR_WRITE);
221 
222     /* Check the file open status.  */
223     if (status != FX_SUCCESS)
224     {
225 
226         printf("ERROR!\n");
227         test_control_return(4);
228     }
229 
230     /* Seek to the beginning of the test files.  */
231     status =  fx_file_seek(&my_file, 0);
232     status += fx_file_seek(&my_file1, 0);
233 
234     /* Check the file seek status.  */
235     if (status != FX_SUCCESS)
236     {
237 
238         printf("ERROR!\n");
239         test_control_return(5);
240     }
241 
242     /* Write a string to the test files.  */
243     status =  fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
244     status += fx_file_write(&my_file1, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
245 
246     /* Check the file write status.  */
247     if (status != FX_SUCCESS)
248     {
249 
250         printf("ERROR!\n");
251         test_control_return(6);
252     }
253 
254     /* Seek to the beginning of the test files.  */
255     status =  fx_file_seek(&my_file, 0);
256     status += fx_file_seek(&my_file1, 0);
257 
258     /* Check the file seek status.  */
259     if (status != FX_SUCCESS)
260     {
261 
262         printf("ERROR!\n");
263         test_control_return(7);
264     }
265 
266     /* Read the first 28 bytes of the test files.  */
267     status =  fx_file_read(&my_file, local_buffer, 28, &actual);
268     status += fx_file_read(&my_file1, local_buffer, 28, &actual);
269 
270     /* Check the file read status.  */
271     if ((status != FX_SUCCESS) || (actual != 28))
272     {
273 
274         printf("ERROR!\n");
275         test_control_return(8);
276     }
277 
278     /* Close the test files.  */
279     status =  fx_file_close(&my_file);
280     status += fx_file_close(&my_file1);
281 
282     /* Check the file close status.  */
283     if (status != FX_SUCCESS)
284     {
285 
286         printf("ERROR!\n");
287         test_control_return(9);
288     }
289 
290     /* Close the medias.  */
291     status =  fx_media_close(&ram_disk);
292     status += fx_media_close(&ram_disk1);
293 
294     /* Only run this if error checking is enabled */
295 #ifndef FX_DISABLE_ERROR_CHECKING
296     /* send null pointer to generate an error */
297     status = fx_media_close(FX_NULL);
298     if (status != FX_PTR_ERROR)
299     {
300         printf("ERROR!\n");
301         test_control_return(11);
302     }
303 #endif /* FX_DISABLE_ERROR_CHECKING */
304 
305     /* Re-Open the ram_disk.  */
306     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
307     status += fx_media_open(&ram_disk1,"RAM DISK", _fx_ram_driver, ram_disk_memory1,cache_buffer1,CACHE_SIZE);
308 
309     /* Check the status.  */
310     if (status != FX_SUCCESS)
311     {
312 
313         /* Error, return error code.  */
314         printf("ERROR!\n");
315         test_control_return(3);
316     }
317 
318     /* Create a file called TEST.TXT in the root directory.  */
319     status =  fx_file_create(&ram_disk, "TEST.TXT");
320     status1=  fx_file_create(&ram_disk1, "TEST.TXT");
321 
322     /* Check for an already created status.  This is not fatal, just
323        let the user know.  */
324     if (status != FX_ALREADY_CREATED)
325     {
326 
327         printf("ERROR!\n");
328         test_control_return(3);
329     }
330 
331     /* Check for an already created status.  This is not fatal, just
332        let the user know.  */
333     if (status1 != FX_ALREADY_CREATED)
334     {
335 
336         printf("ERROR!\n");
337         test_control_return(31);
338     }
339 
340     /* Open the test files.  */
341     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
342     status += fx_file_open(&ram_disk1, &my_file1, "TEST.TXT", FX_OPEN_FOR_WRITE);
343 
344     /* Check the file open status.  */
345     if (status != FX_SUCCESS)
346     {
347 
348         printf("ERROR!\n");
349         test_control_return(4);
350     }
351 
352     /* Seek to the beginning of the test files.  */
353     status =  fx_file_seek(&my_file, 0);
354     status += fx_file_seek(&my_file1, 0);
355 
356     /* Check the file seek status.  */
357     if (status != FX_SUCCESS)
358     {
359 
360         printf("ERROR!\n");
361         test_control_return(5);
362     }
363 
364     /* Write a string to the test files.  */
365     status =  fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
366     status += fx_file_write(&my_file1, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
367 
368     /* Check the file write status.  */
369     if (status != FX_SUCCESS)
370     {
371 
372         printf("ERROR!\n");
373         test_control_return(6);
374     }
375 
376     /* Seek to the beginning of the test files.  */
377     status =  fx_file_seek(&my_file, 0);
378     status += fx_file_seek(&my_file1, 0);
379 
380     /* Check the file seek status.  */
381     if (status != FX_SUCCESS)
382     {
383 
384         printf("ERROR!\n");
385         test_control_return(7);
386     }
387 
388     /* Read the first 28 bytes of the test files.  */
389     status =  fx_file_read(&my_file, local_buffer, 28, &actual);
390     status += fx_file_read(&my_file1, local_buffer, 28, &actual);
391 
392     /* Check the file read status.  */
393     if ((status != FX_SUCCESS) || (actual != 28))
394     {
395 
396         printf("ERROR!\n");
397         test_control_return(8);
398     }
399 
400     /* Close the test files.  */
401     status =  fx_file_close(&my_file);
402     status += fx_file_close(&my_file1);
403 
404     /* Check the file close status.  */
405     if (status != FX_SUCCESS)
406     {
407 
408         printf("ERROR!\n");
409         test_control_return(9);
410     }
411 
412     /* Close the medias.  */
413     status =  fx_media_close(&ram_disk);
414     status += fx_media_close(&ram_disk1);
415 
416     /* Determine if the test was successful.  */
417     if (status != FX_SUCCESS)
418     {
419 
420         printf("ERROR!\n");
421         test_control_return(10);
422     }
423 
424     /* Test multiple files open at time of close.  */
425 
426     /* Re-Open the ram_disk.  */
427     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
428     status += fx_media_open(&ram_disk1,"RAM DISK", _fx_ram_driver, ram_disk_memory1,cache_buffer1,CACHE_SIZE);
429 
430     /* Check the status.  */
431     if (status != FX_SUCCESS)
432     {
433 
434         /* Error, return error code.  */
435         printf("ERROR!\n");
436         test_control_return(10);
437     }
438 
439     /* Create a file called TEST.TXT in the root directory.  */
440     status =  fx_file_create(&ram_disk, "TEST.TXT");
441     status1=  fx_file_create(&ram_disk1, "TEST.TXT");
442 
443     /* Check for an already created status.  This is not fatal, just
444        let the user know.  */
445     if (status != FX_ALREADY_CREATED)
446     {
447 
448         printf("ERROR!\n");
449         test_control_return(11);
450     }
451 
452     /* Check for an already created status.  This is not fatal, just
453        let the user know.  */
454     if (status1 != FX_ALREADY_CREATED)
455     {
456 
457         printf("ERROR!\n");
458         test_control_return(12);
459     }
460 
461     /* Open the test files.  */
462     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
463     status += fx_file_open(&ram_disk1, &my_file1, "TEST.TXT", FX_OPEN_FOR_WRITE);
464 
465     /* Check the file open status.  */
466     if (status != FX_SUCCESS)
467     {
468 
469         printf("ERROR!\n");
470         test_control_return(13);
471     }
472 
473     /* Seek to the beginning of the test files.  */
474     status =  fx_file_seek(&my_file, 0);
475     status += fx_file_seek(&my_file1, 0);
476 
477     /* Check the file seek status.  */
478     if (status != FX_SUCCESS)
479     {
480 
481         printf("ERROR!\n");
482         test_control_return(14);
483     }
484 
485     /* Write a string to the test files.  */
486     status = fx_file_write(&my_file1, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
487 
488     /* Check the file write status.  */
489     if (status != FX_SUCCESS)
490     {
491 
492         printf("ERROR!\n");
493         test_control_return(15);
494     }
495 
496     /* Seek to the beginning of the test files.  */
497     status =  fx_file_seek(&my_file, 0);
498     status += fx_file_seek(&my_file1, 0);
499 
500     /* Check the file seek status.  */
501     if (status != FX_SUCCESS)
502     {
503 
504         printf("ERROR!\n");
505         test_control_return(16);
506     }
507 
508     /* Read the first 28 bytes of the test files.  */
509     status =  fx_file_read(&my_file, local_buffer, 28, &actual);
510     status += fx_file_read(&my_file1, local_buffer, 28, &actual);
511 
512     /* Check the file read status.  */
513     if ((status != FX_SUCCESS) || (actual != 28))
514     {
515 
516         printf("ERROR!\n");
517         test_control_return(17);
518     }
519 
520     /* Close the medias.  */
521     status =  fx_media_close(&ram_disk1);
522     status += fx_media_close(&ram_disk);
523 
524     /* Determine if the test was successful.  */
525     if (status != FX_SUCCESS)
526     {
527 
528         printf("ERROR!\n");
529         test_control_return(18);
530     }
531 
532     /* FAT32 Test for sixteen files and multiple open/close calls.  */
533 
534     /* Format the media.  This needs to be done before opening it!  */
535     status =  fx_media_format(&ram_disk,
536             _fx_ram_driver,         // Driver entry
537             ram_disk_memory,        // RAM disk memory pointer
538             cache_buffer,           // Media buffer pointer
539             CACHE_SIZE,             // Media buffer size
540             "MY_RAM_DISK",          // Volume Name
541             1,                      // Number of FATs
542             32,                     // Directory Entries
543             0,                      // Hidden sectors
544             70000,                  // Total sectors  - FAT32
545             128,                    // Sector size
546             1,                      // Sectors per cluster
547             1,                      // Heads
548             1);                     // Sectors per track
549 
550     /* Determine if the format had an error.  */
551     if (status)
552     {
553 
554         printf("ERROR!\n");
555         test_control_return(19);
556     }
557 
558     /* Setup a new, more complicated directory structure.  */
559     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
560     status += fx_file_create(&ram_disk, "ROOTF1.TXT");
561     status += fx_media_flush(&ram_disk);
562     status += fx_file_create(&ram_disk, "ROOTF2.TXT");
563     status += fx_media_flush(&ram_disk);
564     status += fx_file_create(&ram_disk, "ROOTF3.TXT");
565     status += fx_media_flush(&ram_disk);
566     status += fx_file_create(&ram_disk, "ROOTF4.TXT");
567     status += fx_media_flush(&ram_disk);
568     status += fx_file_create(&ram_disk, "ROOTF5.TXT");
569     status += fx_media_flush(&ram_disk);
570     status += fx_file_create(&ram_disk, "ROOTF6.TXT");
571     status += fx_media_flush(&ram_disk);
572     status += fx_file_create(&ram_disk, "ROOTF7.TXT");
573     status += fx_media_flush(&ram_disk);
574     status += fx_file_create(&ram_disk, "ROOTF8.TXT");
575     status += fx_media_flush(&ram_disk);
576     status += fx_file_create(&ram_disk, "ROOTF9.TXT");
577     status += fx_media_flush(&ram_disk);
578     status += fx_file_create(&ram_disk, "ROOTF10.TXT");
579     status += fx_media_flush(&ram_disk);
580     status += fx_file_create(&ram_disk, "ROOTF11.TXT");
581     status += fx_media_flush(&ram_disk);
582     status += fx_file_create(&ram_disk, "ROOTF12.TXT");
583     status += fx_media_flush(&ram_disk);
584     status += fx_file_create(&ram_disk, "ROOTF13.TXT");
585     status += fx_media_flush(&ram_disk);
586     status += fx_file_create(&ram_disk, "ROOTF14.TXT");
587     status += fx_media_flush(&ram_disk);
588     status += fx_file_create(&ram_disk, "ROOTF15.TXT");
589     status += fx_media_flush(&ram_disk);
590     status += fx_file_create(&ram_disk, "ROOTF16.TXT");
591     status += fx_media_flush(&ram_disk);
592 
593     status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
594     status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
595     status += fx_file_close(&my_file);
596     status += fx_media_flush(&ram_disk);
597 
598     status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
599     status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
600     status += fx_file_close(&my_file);
601     status += fx_media_flush(&ram_disk);
602 
603     status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
604     status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
605     status += fx_file_close(&my_file);
606     status += fx_media_flush(&ram_disk);
607 
608     /* Determine if the files were written properly.  */
609     if (status)
610     {
611 
612         printf("ERROR!\n");
613         test_control_return(20);
614     }
615 
616     /* Close the media.  */
617     status =  fx_media_close(&ram_disk);
618 
619     /* Open the media again.  */
620     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
621 
622     /* And close it again.  */
623     status +=  fx_media_close(&ram_disk);
624 
625     /* Determine if the test was successful.  */
626     if (status != FX_SUCCESS)
627     {
628 
629         printf("ERROR!\n");
630         test_control_return(21);
631     }
632 
633     /* Test the notify registration functions.  */
634 
635     /* Setup notify routines for open and close.  */
636     status =  fx_media_open_notify_set(&ram_disk, ram_disk_open);
637     status += fx_media_close_notify_set(&ram_disk,ram_disk_close);
638 
639     /* Determine if the format had an error.  */
640     if (status)
641     {
642 
643         printf("ERROR!\n");
644         test_control_return(22);
645     }
646 
647     /* Setup a new, more complicated directory structure.  */
648     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
649 
650     /* Determine if the files were written properly.  */
651     if ((status) || (open_count != 1))
652     {
653 
654         printf("ERROR!\n");
655         test_control_return(23);
656     }
657 
658     /* Close the media.  */
659     status =  fx_media_close(&ram_disk);
660     status += fx_media_open_notify_set(&ram_disk,  FX_NULL);
661     status += fx_media_close_notify_set(&ram_disk, FX_NULL);
662 
663     /* Determine if the test was successful.  */
664     if ((status != FX_SUCCESS) || (close_count != 1))
665     {
666 
667         printf("ERROR!\n");
668         test_control_return(24);
669     }
670 
671     /* FAT32 Test for the additional information sector.  */
672 
673     /* Format the media.  This needs to be done before opening it!  */
674     status =  fx_media_format(&ram_disk,
675             _fx_ram_driver,         // Driver entry
676             ram_disk_memory,        // RAM disk memory pointer
677             cache_buffer,           // Media buffer pointer
678             CACHE_SIZE,             // Media buffer size
679             "MY_RAM_DISK",          // Volume Name
680             1,                      // Number of FATs
681             32,                     // Directory Entries
682             0,                      // Hidden sectors
683             6000,                   // Total sectors  - FAT16
684             512,                    // Sector size
685             1,                      // Sectors per cluster
686             1,                      // Heads
687             1);                     // Sectors per track
688 
689     /* Determine if the format had an error.  */
690     if (status != FX_SUCCESS)
691     {
692 
693         printf("ERROR!\n");
694         test_control_return(24);
695     }
696 
697     /* Clear the raw sector buffer.  */
698     for (i = 0; i < 512; i++)
699     {
700         raw_sector_buffer[i] =  0;
701     }
702 
703     /* Setup a new file that we will use for the additional information sector.  */
704     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
705     status += fx_file_create(&ram_disk, "TEXT.TXT");
706     status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
707     status += fx_file_write(&my_file, raw_sector_buffer, 512);
708     status += fx_media_flush(&ram_disk);
709 
710     /* Determine if the files were written properly.  */
711     if (status)
712     {
713 
714         printf("ERROR!\n");
715         test_control_return(25);
716     }
717 
718     /* Now setup the media's additional information sector.  */
719     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
720 
721     /* Now set the last available clusters to the current available clusters.  */
722     ram_disk.fx_media_FAT32_additional_info_last_available =  ram_disk.fx_media_available_clusters;
723 
724     /* Flush the media.  */
725     status +=  fx_media_flush(&ram_disk);
726 
727     /* Now setup the media's additional information sector.  */
728     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
729 
730     /* Now set the last available clusters to the current available clusters.  */
731     ram_disk.fx_media_FAT32_additional_info_last_available =  ram_disk.fx_media_available_clusters;
732 
733     /* Close the media.  */
734     status +=  fx_media_close(&ram_disk);
735 
736     /* Determine if the test was successful.  */
737     if (status != FX_SUCCESS)
738     {
739 
740         printf("ERROR!\n");
741         test_control_return(26);
742     }
743 
744     /* Open the media again.  */
745     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
746     status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
747 
748     /* Determine if the test was successful.  */
749     if (status != FX_SUCCESS)
750     {
751 
752         printf("ERROR!\n");
753         test_control_return(27);
754     }
755 
756     /* Now setup the media's additional information sector.  */
757     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
758 
759     /* Now clear the last available clusters to the current available clusters.  */
760     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
761 
762     /* Now temporarily set the write protect flag.  */
763     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
764 
765     /* Flush the media.  */
766     status +=  fx_media_flush(&ram_disk);
767 
768     /* Now setup the media's additional information sector.  */
769     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
770 
771     /* Now clear the last available clusters to the current available clusters.  */
772     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
773 
774     /* Now temporarily set the write protect flag.  */
775     ram_disk.fx_media_driver_write_protect =  FX_TRUE;
776 
777     /* Close the media.  */
778     status +=  fx_media_close(&ram_disk);
779 
780     /* Determine if the test was successful.  */
781     if (status != FX_SUCCESS)
782     {
783 
784         printf("ERROR!\n");
785         test_control_return(28);
786     }
787 
788     /* Open the media again.  */
789     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
790     status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
791 
792     /* Determine if the test was successful.  */
793     if (status != FX_SUCCESS)
794     {
795 
796         printf("ERROR!\n");
797         test_control_return(27);
798     }
799 
800     /* Now setup the media's additional information sector.  */
801     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
802 
803     /* Now clear the last available clusters to the current available clusters.  */
804     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
805 
806     /* Clear the write protect flag.  */
807     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
808 
809     /* Flush the media.  */
810     status +=  fx_media_flush(&ram_disk);
811 
812     /* Now setup the media's additional information sector.  */
813     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
814 
815     /* Now clear the last available clusters to the current available clusters.  */
816     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
817 
818     /* Clear the write protect flag.  */
819     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
820 
821     /* Close the media... This will attempt to look for the additional information sector but fail since the signature is not present.  */
822     status +=  fx_media_close(&ram_disk);
823 
824     /* Determine if the test was successful.  */
825     if (status != FX_SUCCESS)
826     {
827 
828         printf("ERROR!\n");
829         test_control_return(29);
830     }
831 
832     /* Open the media again.  */
833     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
834     status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
835     status += fx_file_seek(&my_file, 0);
836 
837     /* Determine if the test was successful.  */
838     if (status != FX_SUCCESS)
839     {
840 
841         printf("ERROR!\n");
842         test_control_return(30);
843     }
844 
845     /* Now setup the media's additional information sector.  */
846     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
847 
848     /* Now clear the last available clusters to the current available clusters.  */
849     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
850 
851     /* Now temporarily set the write protect flag.  */
852     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
853 
854     /* Read the file contents.  */
855     status =  fx_file_read(&my_file, raw_sector_buffer, 512, &actual);
856 
857     /* Write the first signature.  */
858     _fx_utility_32_unsigned_write(&raw_sector_buffer[0], 0x41615252);
859 
860     /* Write the signature back to the file.  */
861     status += fx_file_seek(&my_file, 0);
862     status += fx_file_write(&my_file, raw_sector_buffer, 512);
863 
864     /* Flush the media.  */
865     status +=  fx_media_flush(&ram_disk);
866 
867     /* Now setup the media's additional information sector.  */
868     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
869 
870     /* Now clear the last available clusters to the current available clusters.  */
871     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
872 
873     /* Now temporarily set the write protect flag.  */
874     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
875 
876     /* Close the media... This will attempt to look for the additional information sector but fail since the second signature is not present.  */
877     status +=  fx_media_close(&ram_disk);
878 
879     /* Determine if the test was successful.  */
880     if (status != FX_SUCCESS)
881     {
882 
883         printf("ERROR!\n");
884         test_control_return(31);
885     }
886 
887     /* Open the media again.  */
888     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
889     status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
890     status += fx_file_seek(&my_file, 0);
891 
892     /* Determine if the test was successful.  */
893     if (status != FX_SUCCESS)
894     {
895 
896         printf("ERROR!\n");
897         test_control_return(32);
898     }
899 
900     /* Now setup the media's additional information sector.  */
901     ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
902 
903     /* Now clear the last available clusters to the current available clusters.  */
904     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
905 
906     /* Now clear the write protect flag.  */
907     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
908 
909     /* Read the file contents.  */
910     status =  fx_file_read(&my_file, raw_sector_buffer, 512, &actual);
911 
912     /* Write the last signature.  */
913     fx_file_seek(&my_file, 0);
914     _fx_utility_32_unsigned_write(&raw_sector_buffer[484], 0x61417272);
915 
916     /* Write the signature back to the file.  */
917     status += fx_file_seek(&my_file, 0);
918     status += fx_file_write(&my_file, raw_sector_buffer, 512);
919 
920     /* Flush the media.  */
921     status +=  fx_media_flush(&ram_disk);
922 
923     /* Now clear the last available clusters to the current available clusters.  */
924     ram_disk.fx_media_FAT32_additional_info_last_available =  0;
925 
926     /* Now clear the write protect flag.  */
927     ram_disk.fx_media_driver_write_protect =  FX_FALSE;
928 
929     /* Close the media... This will attempt to look for the additional information sector and succeed in updating the additional sector. */
930     status +=  fx_media_close(&ram_disk);
931 
932     /* Determine if the test was successful.  */
933     if (status != FX_SUCCESS)
934     {
935 
936         printf("ERROR!\n");
937         test_control_return(33);
938     }
939 
940     /* Create some additional files.  */
941     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
942     status += fx_file_create(&ram_disk, "TEXT1.TXT");
943     status += fx_file_create(&ram_disk, "TEXT2.TXT");
944     status += fx_file_create(&ram_disk, "TEXT3.TXT");
945     status += fx_file_create(&ram_disk, "TEXT4.TXT");
946     status += fx_file_create(&ram_disk, "TEXT5.TXT");
947     status += fx_file_create(&ram_disk, "TEXT6.TXT");
948     status += fx_file_create(&ram_disk, "TEXT7.TXT");
949     status += fx_file_create(&ram_disk, "TEXT8.TXT");
950     status += fx_file_create(&ram_disk, "TEXT9.TXT");
951     status += fx_file_create(&ram_disk, "TEXT10.TXT");
952     status += fx_file_create(&ram_disk, "TEXT11.TXT");
953     status += fx_media_close(&ram_disk);
954 
955     /* Determine if the test was successful.  */
956     if (status != FX_SUCCESS)
957     {
958 
959         printf("ERROR!\n");
960         test_control_return(34);
961     }
962 
963     /* Loop to create the environment for I/O errors...  */
964     for (i = 0; i < 1000; i++)
965     {
966 
967         /* Open the media again.  */
968         status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
969         status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_READ);
970         status += fx_file_open(&ram_disk, &my_file1, "TEXT1.TXT", FX_OPEN_FOR_WRITE);
971         status += fx_file_open(&ram_disk, &my_file2, "TEXT2.TXT", FX_OPEN_FOR_WRITE);
972         status += fx_file_open(&ram_disk, &my_file3, "TEXT3.TXT", FX_OPEN_FOR_WRITE);
973         status += fx_file_open(&ram_disk, &my_file4, "TEXT4.TXT", FX_OPEN_FOR_WRITE);
974         status += fx_file_open(&ram_disk, &my_file5, "TEXT5.TXT", FX_OPEN_FOR_WRITE);
975         status += fx_file_open(&ram_disk, &my_file6, "TEXT6.TXT", FX_OPEN_FOR_WRITE);
976         status += fx_file_open(&ram_disk, &my_file7, "TEXT7.TXT", FX_OPEN_FOR_WRITE);
977         status += fx_file_open(&ram_disk, &my_file8, "TEXT8.TXT", FX_OPEN_FOR_WRITE);
978         status += fx_file_open(&ram_disk, &my_file9, "TEXT9.TXT", FX_OPEN_FOR_WRITE);
979         status += fx_file_open(&ram_disk, &my_file10, "TEXT10.TXT", FX_OPEN_FOR_WRITE);
980         status += fx_file_open(&ram_disk, &my_file11, "TEXT11.TXT", FX_OPEN_FOR_WRITE);
981         raw_sector_buffer[0] = (UCHAR)i;
982         status += fx_file_write(&my_file1, raw_sector_buffer, 1);
983         status += fx_file_write(&my_file2, raw_sector_buffer, 1);
984         status += fx_file_write(&my_file3, raw_sector_buffer, 1);
985         status += fx_file_write(&my_file4, raw_sector_buffer, 1);
986         status += fx_file_write(&my_file5, raw_sector_buffer, 1);
987         status += fx_file_write(&my_file6, raw_sector_buffer, 1);
988         status += fx_file_write(&my_file7, raw_sector_buffer, 1);
989         status += fx_file_write(&my_file8, raw_sector_buffer, 1);
990         status += fx_file_write(&my_file9, raw_sector_buffer, 1);
991         status += fx_file_write(&my_file10, raw_sector_buffer, 1);
992         status += fx_file_write(&my_file11, raw_sector_buffer, 1);
993 
994         /* Determine if the test was successful.  */
995         if (status != FX_SUCCESS)
996         {
997 
998             printf("ERROR!\n");
999             test_control_return(34);
1000         }
1001 
1002         /* Now temporarily set the write protect flag.  */
1003         ram_disk.fx_media_driver_write_protect =  FX_FALSE;
1004         status = fx_media_flush(&ram_disk);
1005         status += fx_media_cache_invalidate(&ram_disk);
1006 
1007         /* Determine if the test was successful.  */
1008         if (status != FX_SUCCESS)
1009         {
1010 
1011             printf("ERROR!\n");
1012             test_control_return(34);
1013         }
1014 
1015         /* Now setup the media's additional information sector.  */
1016         ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
1017 
1018         /* Now clear the last available clusters to the current available clusters.  */
1019         ram_disk.fx_media_FAT32_additional_info_last_available =  0;
1020 
1021         /* Create I/O errors via the RAM driver interface.  */
1022         j = (UINT)(rand() % 10);
1023         if (j == 0)
1024             j =  1;
1025         _fx_ram_driver_io_error_request =  j;
1026 
1027         fx_media_flush(&ram_disk);
1028 
1029         /* Now setup the media's additional information sector.  */
1030         ram_disk.fx_media_FAT32_additional_info_sector =  (my_file.fx_file_first_physical_cluster - 2) + ram_disk.fx_media_data_sector_start;
1031 
1032         /* Now clear the last available clusters to the current available clusters.  */
1033         ram_disk.fx_media_FAT32_additional_info_last_available =  0;
1034 
1035         /* Create I/O errors via the RAM driver interface.  */
1036         j = (UINT)(rand() % 10);
1037         if (j == 0)
1038             j =  1;
1039         _fx_ram_driver_io_error_request =  j;
1040 
1041         /* Close the media... This will attempt to look for the additional information sector and succeed in updating the additional sector. */
1042         fx_media_close(&ram_disk);
1043 
1044         /* Create I/O errors via the RAM driver interface.  */
1045         j = (UINT)(rand() % 10);
1046         if (j == 0)
1047             j =  1;
1048         _fx_ram_driver_io_error_request =  j;
1049 
1050         /* Set the volume.  */
1051         fx_media_volume_set(&ram_disk, "MYDISK");
1052 
1053         /* Create I/O errors via the RAM driver interface.  */
1054         j = (UINT)(rand() % 10);
1055         if (j == 0)
1056             j =  1;
1057         _fx_ram_driver_io_error_request =  j;
1058 
1059         /* Get the volume.  */
1060         if (i & 1)
1061             fx_media_volume_get(&ram_disk, (CHAR *)volume_buffer, FX_BOOT_SECTOR);
1062         else
1063             fx_media_volume_get(&ram_disk, (CHAR *)volume_buffer, FX_DIRECTORY_SECTOR);
1064 
1065         _fx_ram_driver_io_error_request =  0;
1066     }
1067 
1068     /* Determine if the test was successful.  */
1069     if (status != FX_SUCCESS)
1070     {
1071 
1072         printf("ERROR!\n");
1073         test_control_return(33);
1074     }
1075 
1076 
1077     /* Additional media open/close corner case tests... including I/O errors.  */
1078 
1079     /* Format the media.  This needs to be done before opening it!  */
1080     status =  fx_media_format(&ram_disk,
1081             _fx_ram_driver,         // Driver entry
1082             ram_disk_memory,        // RAM disk memory pointer
1083             cache_buffer,           // Media buffer pointer
1084             CACHE_SIZE,             // Media buffer size
1085             "MY_RAM_DISK",          // Volume Name
1086             1,                      // Number of FATs
1087             32,                     // Directory Entries
1088             0,                      // Hidden sectors
1089             6000,                   // Total sectors  - FAT16
1090             128,                    // Sector size
1091             1,                      // Sectors per cluster
1092             1,                      // Heads
1093             1);                     // Sectors per track
1094 
1095     /* Determine if the format had an error.  */
1096     if (status != FX_SUCCESS)
1097     {
1098 
1099         printf("ERROR!\n");
1100         test_control_return(34);
1101     }
1102 
1103     /* Clear the raw sector buffer.  */
1104     for (i = 0; i < 512; i++)
1105     {
1106         raw_sector_buffer[i] =  0;
1107     }
1108 
1109     /* Save the options.  */
1110     temp =  _fx_system_build_options_1;
1111     temp1 = _fx_system_build_options_2;
1112     temp2 = _fx_system_build_options_3;
1113     temp3 = (ULONG)_fx_version_id[0];
1114 
1115     /* Set all these to 0 to cause the error.  */
1116     _fx_system_build_options_1 =  0;
1117     _fx_system_build_options_2 =  0;
1118     _fx_system_build_options_3 =  0;
1119 
1120     /* Setup a new file that we will use for the additional information sector.  */
1121     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1122 
1123     /* Check for the not implemented error, which is expected.  */
1124     if (status != FX_NOT_IMPLEMENTED)
1125     {
1126 
1127         printf("ERROR!\n");
1128         test_control_return(35);
1129     }
1130 
1131     /* Restore build options and set version_id to 0 to cause the error.  */
1132     _fx_system_build_options_1 =  temp;
1133     _fx_system_build_options_2 =  temp1;
1134     _fx_system_build_options_3 =  temp2;
1135     _fx_version_id[0] =           0;
1136 
1137     /* Setup a new file that we will use for the additional information sector.  */
1138     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1139 
1140     /* Check for the not implemented error, which is expected.  */
1141     if (status != FX_NOT_IMPLEMENTED)
1142     {
1143 
1144         printf("ERROR!\n");
1145         test_control_return(35);
1146     }
1147 
1148     /* Restore version id.  */
1149     _fx_version_id[0] =           (CHAR) temp3;
1150 
1151 
1152 #ifndef FX_DISABLE_CACHE
1153     /* Now attempt to call media open with a 0 sized cache.  */
1154     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 0);
1155 
1156     /* Check for the buffer error, which is expected.  */
1157     if (status != FX_BUFFER_ERROR)
1158     {
1159 
1160         printf("ERROR!\n");
1161         test_control_return(36);
1162     }
1163 #endif
1164 
1165     /* Now attempt to call media open with an over-sized cache... this will be reduced automatically and should open fine.  */
1166     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 257*128);
1167 
1168     /* Check for error.  */
1169     if (status != FX_SUCCESS)
1170     {
1171 
1172         printf("ERROR!\n");
1173         test_control_return(37);
1174     }
1175 
1176     /* Abort the media since it wasn't opened properly.  */
1177     fx_media_abort(&ram_disk);
1178 
1179     /* Format the media.  This needs to be done before opening it!  */
1180     status =  fx_media_format(&ram_disk,
1181             _fx_ram_driver,         // Driver entry
1182             ram_disk_memory,        // RAM disk memory pointer
1183             cache_buffer,           // Media buffer pointer
1184             CACHE_SIZE,             // Media buffer size
1185             "MY_RAM_DISK",          // Volume Name
1186             1,                      // Number of FATs
1187             32,                     // Directory Entries
1188             0,                      // Hidden sectors
1189             70000,                  // Total sectors  - FAT32
1190             512,                    // Sector size
1191             1,                      // Sectors per cluster
1192             1,                      // Heads
1193             1);                     // Sectors per track
1194 
1195     /* Determine if the format had an error.  */
1196     if (status != FX_SUCCESS)
1197     {
1198 
1199         printf("ERROR!\n");
1200         test_control_return(38);
1201     }
1202 
1203     /* Setup a new file that we will use for the additional information sector.  */
1204     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1205 
1206     /* Check for error.  */
1207     if (status != FX_SUCCESS)
1208     {
1209 
1210         printf("ERROR!\n");
1211         test_control_return(39);
1212     }
1213 
1214     /* Loop to create a bogus FAT chain for the root directory to test the total cluster logic in root directory total entries calculation.  */
1215     for (i = 2; i < ram_disk.fx_media_total_clusters+10; i++)
1216     {
1217         /* Write a FAT chain link that exceeds the FAT area. */
1218         status += _fx_utility_FAT_entry_write(&ram_disk, i, i+1);
1219     }
1220 
1221     /* Now close the media.  */
1222     status =  fx_media_close(&ram_disk);
1223 
1224     /* Check for error.  */
1225     if (status != FX_SUCCESS)
1226     {
1227 
1228         printf("ERROR!\n");
1229         test_control_return(40);
1230     }
1231 
1232     /* Open the media again to get the FAT read error.  */
1233     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1234 
1235     /* Check for error.  */
1236     if (status != FX_FAT_READ_ERROR)
1237     {
1238 
1239         printf("ERROR!\n");
1240         test_control_return(41);
1241     }
1242 
1243     /* Abort the media.  */
1244     fx_media_abort(&ram_disk);
1245 
1246 
1247     /* Format the media.  This needs to be done before opening it!  */
1248     status =  fx_media_format(&ram_disk,
1249             _fx_ram_driver,         // Driver entry
1250             ram_disk_memory,        // RAM disk memory pointer
1251             cache_buffer,           // Media buffer pointer
1252             CACHE_SIZE,             // Media buffer size
1253             "MY_RAM_DISK",          // Volume Name
1254             1,                      // Number of FATs
1255             32,                     // Directory Entries
1256             0,                      // Hidden sectors
1257             70000,                  // Total sectors  - FAT32
1258             512,                    // Sector size
1259             1,                      // Sectors per cluster
1260             1,                      // Heads
1261             1);                     // Sectors per track
1262 
1263     /* Determine if the format had an error.  */
1264     if (status != FX_SUCCESS)
1265     {
1266 
1267         printf("ERROR!\n");
1268         test_control_return(42);
1269     }
1270 
1271     /* Open the media again.  */
1272     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1273 
1274     /* Check for error.  */
1275     if (status != FX_SUCCESS)
1276     {
1277 
1278         printf("ERROR!\n");
1279         test_control_return(43);
1280     }
1281 
1282      /* Write a FAT chain link to check (cluster_number == FAT_entry). */
1283     status = _fx_utility_FAT_entry_write(&ram_disk, 2, 2+1);
1284 
1285     /* Check for error.  */
1286     if (status != FX_SUCCESS)
1287     {
1288 
1289         printf("ERROR!\n");
1290         test_control_return(46);
1291     }
1292 
1293     /* Now close the media.  */
1294     status =  fx_media_close(&ram_disk);
1295 
1296     /* Check for error.  */
1297     if (status != FX_SUCCESS)
1298     {
1299 
1300         printf("ERROR!\n");
1301         test_control_return(40);
1302     }
1303 
1304     /* Open the media again to get the FAT read error.  */
1305     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1306 
1307     /* Check for error.  */
1308     if (status != FX_FAT_READ_ERROR)
1309     {
1310 
1311         printf("ERROR!\n");
1312         test_control_return(41);
1313     }
1314 
1315     /* Abort the media.  */
1316     fx_media_abort(&ram_disk);
1317 
1318     /* Format the media.  This needs to be done before opening it!  */
1319     status =  fx_media_format(&ram_disk,
1320             _fx_ram_driver,         // Driver entry
1321             ram_disk_memory,        // RAM disk memory pointer
1322             cache_buffer,           // Media buffer pointer
1323             CACHE_SIZE,             // Media buffer size
1324             "MY_RAM_DISK",          // Volume Name
1325             1,                      // Number of FATs
1326             32,                     // Directory Entries
1327             0,                      // Hidden sectors
1328             70000,                  // Total sectors  - FAT32
1329             512,                    // Sector size
1330             1,                      // Sectors per cluster
1331             1,                      // Heads
1332             1);                     // Sectors per track
1333 
1334     /* Determine if the format had an error.  */
1335     if (status != FX_SUCCESS)
1336     {
1337 
1338         printf("ERROR!\n");
1339         test_control_return(42);
1340     }
1341 
1342     /* Open the media again.  */
1343     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1344 
1345     /* Check for error.  */
1346     if (status != FX_SUCCESS)
1347     {
1348 
1349         printf("ERROR!\n");
1350         test_control_return(43);
1351     }
1352 
1353     /* Pickup the additional information sector.  */
1354     temp =  ram_disk.fx_media_FAT32_additional_info_sector;
1355 
1356     /* Read the additional information sector.  */
1357     fx_media_read(&ram_disk, temp, raw_sector_buffer);
1358 
1359     /* Modify the second signature to exercise the error logic in media open.  */
1360     _fx_utility_32_unsigned_write(&raw_sector_buffer[484], 0);
1361 
1362     /* Write the second signature back.  */
1363     fx_media_write(&ram_disk, temp, raw_sector_buffer);
1364 
1365     /* Close the media.  */
1366     status =  fx_media_close(&ram_disk);
1367 
1368     /* Check for error.  */
1369     if (status != FX_SUCCESS)
1370     {
1371 
1372         printf("ERROR!\n");
1373         test_control_return(44);
1374     }
1375 
1376     /* Now try to re-open with the second signature bad.  */
1377     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1378 
1379     /* Check for error.  */
1380     if (status != FX_SUCCESS)
1381     {
1382 
1383         printf("ERROR!\n");
1384         test_control_return(45);
1385     }
1386 
1387     /* Fix the signature, but corrupt the available clusters.  */
1388 
1389     /* Read the additional information sector.  */
1390     fx_media_read(&ram_disk, temp, raw_sector_buffer);
1391 
1392     /* Modify the second signature to exercise the error logic in media open.  */
1393     _fx_utility_32_unsigned_write(&raw_sector_buffer[484], 0x61417272);
1394 
1395     /* Save the search start and available clusters.  */
1396     temp1 =  _fx_utility_32_unsigned_read(&raw_sector_buffer[488]);
1397     temp2 =  _fx_utility_32_unsigned_read(&raw_sector_buffer[492]);
1398 
1399     /* Modify the search start... beyond the total clusters */
1400     _fx_utility_32_unsigned_write(&raw_sector_buffer[492], 0xF0F0F0F0);
1401 
1402     /* Write the search start back.  */
1403     fx_media_write(&ram_disk, temp, raw_sector_buffer);
1404 
1405     /* Close the media.  */
1406     status =  fx_media_close(&ram_disk);
1407 
1408     /* Check for error.  */
1409     if (status != FX_SUCCESS)
1410     {
1411 
1412         printf("ERROR!\n");
1413         test_control_return(46);
1414     }
1415 
1416     /* Now try to re-open with a bad search cluster value - greater than total.  */
1417     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1418 
1419     /* Check for error.  */
1420     if (status != FX_SUCCESS)
1421     {
1422 
1423         printf("ERROR!\n");
1424         test_control_return(47);
1425     }
1426 
1427     /* Read the additional information sector.  */
1428     fx_media_read(&ram_disk, temp, raw_sector_buffer);
1429 
1430     /* Modify the search start... before the starting cluster. */
1431     _fx_utility_32_unsigned_write(&raw_sector_buffer[492], 0);
1432 
1433     /* Write the search start back.  */
1434     fx_media_write(&ram_disk, temp, raw_sector_buffer);
1435 
1436     /* Close the media.  */
1437     status =  fx_media_close(&ram_disk);
1438 
1439     /* Check for error.  */
1440     if (status != FX_SUCCESS)
1441     {
1442 
1443         printf("ERROR!\n");
1444         test_control_return(48);
1445     }
1446 
1447     /* Now try to re-open with a bad search cluster value - less than the total.  */
1448     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1449 
1450     /* Check for error.  */
1451     if (status != FX_SUCCESS)
1452     {
1453 
1454         printf("ERROR!\n");
1455         test_control_return(49);
1456     }
1457 
1458     /* Read the additional information sector.  */
1459     fx_media_read(&ram_disk, temp, raw_sector_buffer);
1460 
1461     /* Restore the search start... before the starting cluster. */
1462     _fx_utility_32_unsigned_write(&raw_sector_buffer[492], temp2);
1463 
1464     /* Make the available clusters too big.  */
1465     _fx_utility_32_unsigned_write(&raw_sector_buffer[488], ram_disk.fx_media_total_clusters+1);
1466 
1467     /* Write the search start back.  */
1468     fx_media_write(&ram_disk, temp, raw_sector_buffer);
1469 
1470     /* Close the media.  */
1471     status =  fx_media_close(&ram_disk);
1472 
1473     /* Check for error.  */
1474     if (status != FX_SUCCESS)
1475     {
1476 
1477         printf("ERROR!\n");
1478         test_control_return(50);
1479     }
1480 
1481     /* Now try to re-open with a bad available clusters value - more than the total.  */
1482     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
1483 
1484     /* Check for error.  */
1485     if (status != FX_SUCCESS)
1486     {
1487 
1488         printf("ERROR!\n");
1489         test_control_return(51);
1490     }
1491 
1492     /* Close the media.  */
1493     status =  fx_media_close(&ram_disk);
1494 
1495     /* Check for error.  */
1496     if (status != FX_SUCCESS)
1497     {
1498 
1499         printf("ERROR!\n");
1500         test_control_return(52);
1501     }
1502 
1503     /* Format the media in FAT12 for testing I/O error on available clusters in media open.  */
1504     status =  fx_media_format(&ram_disk,
1505             _fx_ram_driver,         // Driver entry
1506             ram_disk_memory,        // RAM disk memory pointer
1507             cache_buffer,           // Media buffer pointer
1508             CACHE_SIZE,             // Media buffer size
1509             "MY_RAM_DISK",          // Volume Name
1510             1,                      // Number of FATs
1511             32,                     // Directory Entries
1512             0,                      // Hidden sectors
1513             2000,                   // Total sectors  - FAT12
1514             128,                    // Sector size
1515             1,                      // Sectors per cluster
1516             1,                      // Heads
1517             1);                     // Sectors per track
1518 
1519     /* Determine if the format had an error.  */
1520     if (status != FX_SUCCESS)
1521     {
1522 
1523         printf("ERROR!\n");
1524         test_control_return(53);
1525     }
1526 
1527     /* Open the media again, but this time introduce an I/O error to cause the FAT read to fail.  */
1528     _fx_ram_driver_io_error_request =  5;
1529     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1530     _fx_ram_driver_io_error_request =  0;
1531 
1532     /* Check for error.  */
1533     if (status != FX_FAT_READ_ERROR)
1534     {
1535 
1536         printf("ERROR!\n");
1537         test_control_return(54);
1538     }
1539 
1540     /* Abort the media.  */
1541     fx_media_abort(&ram_disk);
1542 
1543     /* Format the media in FAT16 for testing I/O error on available clusters in media open.  */
1544     status =  fx_media_format(&ram_disk,
1545             _fx_ram_driver,         // Driver entry
1546             ram_disk_memory,        // RAM disk memory pointer
1547             cache_buffer,           // Media buffer pointer
1548             CACHE_SIZE,             // Media buffer size
1549             "MY_RAM_DISK",          // Volume Name
1550             1,                      // Number of FATs
1551             32,                     // Directory Entries
1552             0,                      // Hidden sectors
1553             7000,                   // Total sectors  - FAT16
1554             128,                    // Sector size
1555             1,                      // Sectors per cluster
1556             1,                      // Heads
1557             1);                     // Sectors per track
1558 
1559     /* Determine if the format had an error.  */
1560     if (status != FX_SUCCESS)
1561     {
1562 
1563         printf("ERROR!\n");
1564         test_control_return(55);
1565     }
1566 
1567     /* Open the media again, but this time introduce an I/O error to cause the FAT read to fail.  */
1568     _fx_ram_driver_io_error_request =  5;
1569     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1570     _fx_ram_driver_io_error_request =  0;
1571 
1572     /* Check for error.  */
1573     if (status != FX_FAT_READ_ERROR)
1574     {
1575 
1576         printf("ERROR!\n");
1577         test_control_return(56);
1578     }
1579 
1580     /* Abort the media.  */
1581     fx_media_abort(&ram_disk);
1582 
1583     /* Open the media again to setup for a media close I/O error.  */
1584     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1585 
1586     /* Check for error.  */
1587     if (status != FX_SUCCESS)
1588     {
1589 
1590         printf("ERROR!\n");
1591         test_control_return(57);
1592     }
1593 
1594     /* Create a file.  */
1595     status =  fx_file_create(&ram_disk, "TEST.TXT");
1596 
1597     /* Check for error.  */
1598     if (status != FX_SUCCESS)
1599     {
1600 
1601         printf("ERROR!\n");
1602         test_control_return(58);
1603     }
1604 
1605     /* Open the test files.  */
1606     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
1607 
1608     /* Check for error.  */
1609     if (status != FX_SUCCESS)
1610     {
1611 
1612         printf("ERROR!\n");
1613         test_control_return(59);
1614     }
1615 
1616     /* Write to the file.  */
1617     status =  fx_file_write(&my_file, "1234567890", 10);
1618 
1619     /* Check for error.  */
1620     if (status != FX_SUCCESS)
1621     {
1622 
1623         printf("ERROR!\n");
1624         test_control_return(60);
1625     }
1626 
1627     /* Now attemp to close the media, but with an I/O error introduced so the close will fail trying to write out the directory entry of the open file.  */
1628     _fx_ram_driver_io_error_request =  1;
1629     status =  fx_media_close(&ram_disk);
1630     _fx_ram_driver_io_error_request =  0;
1631 
1632     /* Check for the I/O error.  */
1633     if (status != FX_IO_ERROR)
1634     {
1635 
1636         printf("ERROR!\n");
1637         test_control_return(61);
1638     }
1639 
1640     /* Abort media.  */
1641     fx_media_abort(&ram_disk);
1642 
1643     /* Format the media in FAT16 for testing I/O error in media close.  */
1644     status =  fx_media_format(&ram_disk,
1645             _fx_ram_driver,         // Driver entry
1646             ram_disk_memory,        // RAM disk memory pointer
1647             cache_buffer,           // Media buffer pointer
1648             CACHE_SIZE,             // Media buffer size
1649             "MY_RAM_DISK",          // Volume Name
1650             1,                      // Number of FATs
1651             32,                     // Directory Entries
1652             0,                      // Hidden sectors
1653             7000,                   // Total sectors  - FAT16
1654             128,                    // Sector size
1655             1,                      // Sectors per cluster
1656             1,                      // Heads
1657             1);                     // Sectors per track
1658 
1659     /* Determine if the format had an error.  */
1660     if (status != FX_SUCCESS)
1661     {
1662 
1663         printf("ERROR!\n");
1664         test_control_return(62);
1665     }
1666 
1667     /* Open the media again to setup for a media close I/O error.  */
1668     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1669 
1670     /* Check for error.  */
1671     if (status != FX_SUCCESS)
1672     {
1673 
1674         printf("ERROR!\n");
1675         test_control_return(63);
1676     }
1677 
1678     /* Create a file.  */
1679     status =  fx_file_create(&ram_disk, "TEST.TXT");
1680 
1681     /* Check for error.  */
1682     if (status != FX_SUCCESS)
1683     {
1684 
1685         printf("ERROR!\n");
1686         test_control_return(64);
1687     }
1688 
1689     /* Open the test files.  */
1690     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
1691 
1692     /* Check for error.  */
1693     if (status != FX_SUCCESS)
1694     {
1695 
1696         printf("ERROR!\n");
1697         test_control_return(65);
1698     }
1699 
1700     /* Write to the file.  */
1701     status +=  fx_file_write(&my_file, "1234567890", 10);
1702     status +=  fx_file_write(&my_file, "1234567890", 10);
1703     status +=  fx_file_write(&my_file, "1234567890", 10);
1704     status +=  fx_file_write(&my_file, "1234567890", 10);
1705     status +=  fx_file_write(&my_file, "1234567890", 10);
1706     status +=  fx_file_write(&my_file, "1234567890", 10);
1707     status +=  fx_file_write(&my_file, "1234567890", 10);
1708     status +=  fx_file_write(&my_file, "1234567890", 10);
1709     status +=  fx_file_write(&my_file, "1234567890", 10);
1710     status +=  fx_file_write(&my_file, "1234567890", 10);
1711     status +=  fx_file_write(&my_file, "1234567890", 10);
1712     status +=  fx_file_write(&my_file, "1234567890", 10);
1713     status +=  fx_file_write(&my_file, "1234567890", 10);
1714     status +=  fx_file_write(&my_file, "1234567890", 10);
1715     status +=  fx_file_write(&my_file, "1234567890", 10);
1716     status +=  fx_file_write(&my_file, "1234567890", 10);
1717     status +=  fx_file_write(&my_file, "1234567890", 10);
1718     status +=  fx_file_write(&my_file, "1234567890", 10);
1719     status +=  fx_file_write(&my_file, "1234567890", 10);
1720     status +=  fx_file_write(&my_file, "1234567890", 10);
1721     status +=  fx_file_write(&my_file, "1234567890", 10);
1722     status +=  fx_file_write(&my_file, "1234567890", 10);
1723     status +=  fx_file_write(&my_file, "1234567890", 10);
1724     status +=  fx_file_write(&my_file, "1234567890", 10);
1725     status +=  fx_media_read(&ram_disk, 2000, raw_sector_buffer);
1726     status +=  fx_media_write(&ram_disk, 2000, raw_sector_buffer);
1727 
1728     /* Check for error.  */
1729     if (status != FX_SUCCESS)
1730     {
1731 
1732         printf("ERROR!\n");
1733         test_control_return(66);
1734     }
1735 
1736 #ifndef FX_DISABLE_CACHE
1737 #ifdef FX_FAULT_TOLERANT
1738     /* While FX__FAULT_TOLERANT is defined, non data sector will flush directly in _fx_utility_logical_sector_write rather than set dirty flag. */
1739     /* For this reason, driver won't be called in _fx_utility_logical_sector_flush which is different from non FAULT_TOLERANT code. */
1740     _fx_utility_logical_sector_flush_error_request = 1;
1741     status =  fx_media_close(&ram_disk);
1742 #else
1743     /* Now attemp to close the media, but with an I/O error introduced so the close will fail trying to write out the directory entry of the open file.  */
1744     _fx_ram_driver_io_error_request =  17;
1745     status =  fx_media_close(&ram_disk);
1746     _fx_ram_driver_io_error_request =  0;
1747 #endif
1748 
1749     /* Check for the I/O error.  */
1750     if (status != FX_IO_ERROR)
1751     {
1752 
1753         printf("ERROR!\n");
1754         test_control_return(67);
1755     }
1756 #endif
1757 
1758     /* Finallay, abort the media.  */
1759     fx_media_abort(&ram_disk);
1760 
1761     /* Format the media in FAT16 for testing I/O error in media flush.  */
1762     status =  fx_media_format(&ram_disk,
1763                             _fx_ram_driver,         // Driver entry
1764                             ram_disk_memory,        // RAM disk memory pointer
1765                             cache_buffer,           // Media buffer pointer
1766                             CACHE_SIZE,             // Media buffer size
1767                             "MY_RAM_DISK",          // Volume Name
1768                             1,                      // Number of FATs
1769                             32,                     // Directory Entries
1770                             0,                      // Hidden sectors
1771                             7000,                   // Total sectors  - FAT16
1772                             128,                    // Sector size
1773                             1,                      // Sectors per cluster
1774                             1,                      // Heads
1775                             1);                     // Sectors per track
1776 
1777     /* Determine if the format had an error.  */
1778     if (status != FX_SUCCESS)
1779     {
1780 
1781         printf("ERROR!\n");
1782         test_control_return(68);
1783     }
1784 
1785     /* Open the media again to setup for a media close I/O error.  */
1786     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1787 
1788     /* Check for error.  */
1789     if (status != FX_SUCCESS)
1790     {
1791 
1792         printf("ERROR!\n");
1793         test_control_return(69);
1794     }
1795 
1796     /* Create a file.  */
1797     status =  fx_file_create(&ram_disk, "TEST.TXT");
1798 
1799     /* Check for error.  */
1800     if (status != FX_SUCCESS)
1801     {
1802 
1803         printf("ERROR!\n");
1804         test_control_return(70);
1805     }
1806 
1807     /* Open the test files.  */
1808     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
1809 
1810     /* Check for error.  */
1811     if (status != FX_SUCCESS)
1812     {
1813 
1814         printf("ERROR!\n");
1815         test_control_return(71);
1816     }
1817 
1818     /* Write to the file.  */
1819     status +=  fx_file_write(&my_file, "1234567890", 10);
1820     status +=  fx_file_write(&my_file, "1234567890", 10);
1821     status +=  fx_file_write(&my_file, "1234567890", 10);
1822     status +=  fx_file_write(&my_file, "1234567890", 10);
1823     status +=  fx_file_write(&my_file, "1234567890", 10);
1824     status +=  fx_file_write(&my_file, "1234567890", 10);
1825     status +=  fx_file_write(&my_file, "1234567890", 10);
1826     status +=  fx_file_write(&my_file, "1234567890", 10);
1827     status +=  fx_file_write(&my_file, "1234567890", 10);
1828     status +=  fx_file_write(&my_file, "1234567890", 10);
1829     status +=  fx_file_write(&my_file, "1234567890", 10);
1830     status +=  fx_file_write(&my_file, "1234567890", 10);
1831     status +=  fx_file_write(&my_file, "1234567890", 10);
1832     status +=  fx_file_write(&my_file, "1234567890", 10);
1833     status +=  fx_file_write(&my_file, "1234567890", 10);
1834     status +=  fx_file_write(&my_file, "1234567890", 10);
1835     status +=  fx_file_write(&my_file, "1234567890", 10);
1836     status +=  fx_file_write(&my_file, "1234567890", 10);
1837     status +=  fx_file_write(&my_file, "1234567890", 10);
1838     status +=  fx_file_write(&my_file, "1234567890", 10);
1839     status +=  fx_file_write(&my_file, "1234567890", 10);
1840     status +=  fx_file_write(&my_file, "1234567890", 10);
1841     status +=  fx_file_write(&my_file, "1234567890", 10);
1842     status +=  fx_file_write(&my_file, "1234567890", 10);
1843     status +=  fx_media_read(&ram_disk, 2000, raw_sector_buffer);
1844     status +=  fx_media_write(&ram_disk, 2000, raw_sector_buffer);
1845 
1846     /* Check for error.  */
1847     if (status != FX_SUCCESS)
1848     {
1849 
1850         printf("ERROR!\n");
1851         test_control_return(72);
1852     }
1853 
1854 #if defined(FX_FAULT_TOLERANT) && !defined(FX_DISABLE_CACHE)
1855     /* While FX__FAULT_TOLERANT is defined, non data sector will flush directly in _fx_utility_logical_sector_write rather than set dirty flag. */
1856     /* For this reason, driver won't be called in _fx_utility_logical_sector_flush which is different from non FAULT_TOLERANT code. */
1857     _fx_utility_logical_sector_flush_error_request = 1;
1858     status =  fx_media_close(&ram_disk);
1859 #else
1860     /* Now attemp to flush the media, but with an I/O error introduced so the close will fail trying to write out the directory entry of the open file.  */
1861     _fx_ram_driver_io_error_request =  1;
1862     status =  fx_media_flush(&ram_disk);
1863     _fx_ram_driver_io_error_request =  0;
1864 #endif
1865     /* Check for the I/O error.  */
1866     if (status != FX_IO_ERROR)
1867     {
1868 
1869         printf("ERROR!\n");
1870         test_control_return(73);
1871     }
1872 
1873     /* Finallay, abort the media.  */
1874     fx_media_abort(&ram_disk);
1875 
1876 
1877     /* Format the media in FAT16 for testing I/O error in media flush.  */
1878     status =  fx_media_format(&ram_disk,
1879                             _fx_ram_driver,         // Driver entry
1880                             ram_disk_memory,        // RAM disk memory pointer
1881                             cache_buffer,           // Media buffer pointer
1882                             CACHE_SIZE,             // Media buffer size
1883                             "MY_RAM_DISK",          // Volume Name
1884                             1,                      // Number of FATs
1885                             32,                     // Directory Entries
1886                             0,                      // Hidden sectors
1887                             7000,                   // Total sectors  - FAT16
1888                             128,                    // Sector size
1889                             1,                      // Sectors per cluster
1890                             1,                      // Heads
1891                             1);                     // Sectors per track
1892 
1893     /* Determine if the format had an error.  */
1894     if (status != FX_SUCCESS)
1895     {
1896 
1897         printf("ERROR!\n");
1898         test_control_return(68);
1899     }
1900 
1901     /* Open the media again to setup for a media close I/O error.  */
1902     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1903 
1904     /* Check for error.  */
1905     if (status != FX_SUCCESS)
1906     {
1907 
1908         printf("ERROR!\n");
1909         test_control_return(69);
1910     }
1911 
1912     /* Create a file.  */
1913     status =  fx_file_create(&ram_disk, "TEST.TXT");
1914 
1915     /* Check for error.  */
1916     if (status != FX_SUCCESS)
1917     {
1918 
1919         printf("ERROR!\n");
1920         test_control_return(70);
1921     }
1922 
1923     /* Open the test files.  */
1924     status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
1925 
1926     /* Check for error.  */
1927     if (status != FX_SUCCESS)
1928     {
1929 
1930         printf("ERROR!\n");
1931         test_control_return(71);
1932     }
1933 
1934     /* Write to the file.  */
1935     status +=  fx_file_write(&my_file, "1234567890", 10);
1936     status +=  fx_file_write(&my_file, "1234567890", 10);
1937     status +=  fx_file_write(&my_file, "1234567890", 10);
1938     status +=  fx_file_write(&my_file, "1234567890", 10);
1939     status +=  fx_file_write(&my_file, "1234567890", 10);
1940     status +=  fx_file_write(&my_file, "1234567890", 10);
1941     status +=  fx_file_write(&my_file, "1234567890", 10);
1942     status +=  fx_file_write(&my_file, "1234567890", 10);
1943     status +=  fx_file_write(&my_file, "1234567890", 10);
1944     status +=  fx_file_write(&my_file, "1234567890", 10);
1945     status +=  fx_file_write(&my_file, "1234567890", 10);
1946     status +=  fx_file_write(&my_file, "1234567890", 10);
1947     status +=  fx_file_write(&my_file, "1234567890", 10);
1948     status +=  fx_file_write(&my_file, "1234567890", 10);
1949     status +=  fx_file_write(&my_file, "1234567890", 10);
1950     status +=  fx_file_write(&my_file, "1234567890", 10);
1951     status +=  fx_file_write(&my_file, "1234567890", 10);
1952     status +=  fx_file_write(&my_file, "1234567890", 10);
1953     status +=  fx_file_write(&my_file, "1234567890", 10);
1954     status +=  fx_file_write(&my_file, "1234567890", 10);
1955     status +=  fx_file_write(&my_file, "1234567890", 10);
1956     status +=  fx_file_write(&my_file, "1234567890", 10);
1957     status +=  fx_file_write(&my_file, "1234567890", 10);
1958     status +=  fx_file_write(&my_file, "1234567890", 10);
1959     status +=  fx_media_read(&ram_disk, 2000, raw_sector_buffer);
1960     status +=  fx_media_write(&ram_disk, 2000, raw_sector_buffer);
1961 
1962     /* Check for error.  */
1963     if (status != FX_SUCCESS)
1964     {
1965 
1966         printf("ERROR!\n");
1967         test_control_return(72);
1968     }
1969 
1970 #ifndef FX_DISABLE_CACHE
1971 #ifdef FX_FAULT_TOLERANT
1972     /* While FX__FAULT_TOLERANT is defined, non data sector will flush directly in _fx_utility_logical_sector_write rather than set dirty flag. */
1973     /* For this reason, driver won't be called in _fx_utility_logical_sector_flush which is different from non FAULT_TOLERANT code. */
1974     _fx_utility_logical_sector_flush_error_request = 1;
1975     status =  fx_media_close(&ram_disk);
1976 #else
1977     /* Now attemp to flush the media, but with an I/O error introduced so the close will fail trying to flush logical sectors out.  */
1978     _fx_ram_driver_io_error_request =  17;
1979     status =  fx_media_flush(&ram_disk);
1980     _fx_ram_driver_io_error_request =  0;
1981 #endif
1982 
1983     /* Check for the I/O error.  */
1984     if (status != FX_IO_ERROR)
1985     {
1986 
1987         printf("ERROR!\n");
1988         test_control_return(73);
1989     }
1990 #endif
1991 
1992     /* Finallay, abort the media.  */
1993     fx_media_abort(&ram_disk);
1994 
1995     /* Now see if we can test the FAT32 format with I/O corner cases.  */
1996     _fx_ram_driver_io_error_request =  2211;
1997     status =  fx_media_format(&ram_disk,
1998                             _fx_ram_driver,         // Driver entry
1999                             ram_disk_memory,        // RAM disk memory pointer
2000                             cache_buffer,           // Media buffer pointer
2001                             CACHE_SIZE,             // Media buffer size
2002                             "MY_RAM_DISK",          // Volume Name
2003                             1,                      // Number of FATs
2004                             32,                     // Directory Entries
2005                             0,                      // Hidden sectors
2006                             70657,                  // Total sectors  - FAT32
2007                             128,                    // Sector size
2008                             1,                      // Sectors per cluster
2009                             1,                      // Heads
2010                             1);                     // Sectors per track
2011 
2012     _fx_ram_driver_io_error_request =  0;
2013 
2014     /* Determine if the format had an error.  */
2015     if (status != FX_IO_ERROR)
2016     {
2017 
2018         printf("ERROR!\n");
2019         test_control_return(74);
2020     }
2021 
2022 
2023 
2024     printf("SUCCESS!\n");
2025     test_control_return(0);
2026 }
2027 
2028