1 /* This FileX test concentrates on the Fault-Tolerant fat write interrupt operation.  */
2 /*
3 For FAT 12, 16, 32, one cluster size is 1024 bytes;
4          1024         1024        1024        1024         1024         1024
5     |------------|------------|-----------|------------|------------|------------|
6     |  TEST.TXT  |  TEST1.TXT | TEST1.TXT |  TEST2.TXT |            |            |
7     |------------|------------|-----------|------------|------------|------------|
8                  |      |     |    |    |
9                  |      |     |    |    |
10                Test1    |     |    |    |
11                        Test2  |    |    |
12                             Test3  |    |
13                                  Test4  |
14                                         |
15                                       Test5
16 
17 Check fat interrupt for fx_file_write() :
18 Step1: Format and open the media;
19 Step2: Enable fault tolerant feature;
20 Step3: Create and write 28 bytes into TEST.TXT;
21 Step4: Create and write 1500 bytes into TEST1.TXT, (two cluster);
22 Step5: Create and write 19 bytes into TEST2.TXT;
23 Step6: Create new thread to continue to write 1024 data into TEST1.TXT:
24        Test1: Seek to the file: index 0;
25        Test2: Seek to the file: index 1023;
26        Test3: Seek to the file: index 1024;
27        Test4: Seek to the file: index 1025;
28        Test5: Seek to the file: index 1500;
29 Step7: Terminate the new thread to simulate poweroff when write the fat between undo log generated and redo log not generated.
30 Step8: Open the media;
31 Step9: Enable fault tolerant feature to recover the data(undo operation);
32 Step10: Check the test files.
33 */
34 
35 #ifndef FX_STANDALONE_ENABLE
36 #include   "tx_api.h"
37 #else
38 #define    _GNU_SOURCE
39 #define    _DEFAULT_SOURCE
40 #include   <pthread.h>
41 #include   <unistd.h>
42 #endif
43 #include   "fx_api.h"
44 #include   "fx_system.h"
45 #include   "fx_fault_tolerant.h"
46 #include   <stdio.h>
47 #include   "fx_ram_driver_test.h"
48 extern void    test_control_return(UINT status);
49 void    filex_fault_tolerant_file_write_fat_interrupt_test_application_define(void *first_unused_memory);
50 
51 #if defined (FX_ENABLE_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT_DATA)
52 
53 #define     DEMO_STACK_SIZE         4096
54 #define CACHE_SIZE                  2048
55 #define FAULT_TOLERANT_SIZE         FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
56 
57 
58 /* Define the ThreadX and FileX object control blocks...  */
59 
60 #ifndef FX_STANDALONE_ENABLE
61 static TX_THREAD                ftest_0;
62 static TX_THREAD                ftest_1;
63 #else
64 static pthread_t                ptid1;
65 #endif
66 static FX_MEDIA                 ram_disk;
67 static FX_FILE                  my_file;
68 static UCHAR                    *pointer;
69 
70 /* Define the counters used in the test application...  */
71 
72 #ifndef FX_STANDALONE_ENABLE
73 static UCHAR                    *cache_buffer;
74 static UCHAR                    *fault_tolerant_buffer;
75 static UCHAR                    *thread_buffer;
76 #else
77 static UCHAR                    cache_buffer[CACHE_SIZE];
78 static UCHAR                    fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
79 #endif
80 static UINT                     error_couter = 0;
81 static UINT                     fat_write_interrupt = FX_FALSE;
82 static UINT                     write_index;
83 static UINT                     data_size = 0;
84 static UINT                     i;
85 
86 static CHAR                     write_buffer[2048];
87 static UINT                     write_buffer_size = 2048;
88 static CHAR                     read_buffer[4096];
89 static UINT                     read_buffer_size = 4096;
90 static UCHAR                    data_buffer[4096];
91 
92 #define SEEK_COUNT              5
93 #define FAT_COUNT               3            /* FAT12, 16, 32.  */
94 #define TEST_COUNT              FAT_COUNT * SEEK_COUNT
95 
96 /* Define thread prototypes.  */
97 
98 static void    ftest_0_entry(ULONG thread_input);
99 #ifndef FX_STANDALONE_ENABLE
100 static void    ftest_1_entry(ULONG thread_input);
101 #else
102 static void   * ftest_1_entry(void * thread_input);
103 #endif
104 
105 extern void  _fx_ram_driver(FX_MEDIA *media_ptr);
106 extern void  test_control_return(UINT status);
107 extern UINT  _filex_fault_tolerant_log_check(FX_MEDIA *media_ptr);
108 extern UINT  (*driver_write_callback)(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr);
109 static UINT  my_driver_write(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr);
110 
111 
112 
113 /* Define what the initial system looks like.  */
114 
115 #ifdef CTEST
test_application_define(void * first_unused_memory)116 void test_application_define(void *first_unused_memory)
117 #else
118 void    filex_fault_tolerant_file_write_fat_interrupt_test_application_define(void *first_unused_memory)
119 #endif
120 {
121 
122 
123 #ifndef FX_STANDALONE_ENABLE
124     /* Setup the working pointer.  */
125     pointer =  (UCHAR *) first_unused_memory;
126 
127     /* Create the main thread.  */
128 
129     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
130             pointer, DEMO_STACK_SIZE,
131             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
132 
133     pointer =  pointer + DEMO_STACK_SIZE;
134 
135     /* Setup memory for the RAM disk and the sector cache.  */
136     cache_buffer =  pointer;
137     pointer += CACHE_SIZE;
138     fault_tolerant_buffer = pointer;
139     pointer += FAULT_TOLERANT_SIZE;
140     thread_buffer = pointer;
141     pointer += DEMO_STACK_SIZE;
142 #endif
143 
144     /* Initialize the FileX system.  */
145     fx_system_initialize();
146 #ifdef FX_STANDALONE_ENABLE
147     ftest_0_entry(0);
148 #endif
149 }
150 
151 
152 
153 /* Define the test threads.  */
154 
ftest_0_entry(ULONG thread_input)155 static void    ftest_0_entry(ULONG thread_input)
156 {
157 
158 UINT        status;
159 ULONG       actual;
160 
161     FX_PARAMETER_NOT_USED(thread_input);
162 
163     /* Print out some test information banners.  */
164     printf("FileX Test:   Fault Tolerant File Write FAT Interrupt Test...........");
165 
166     /* Loop to test FAT 12, 16, 32.   */
167     for (i = 0; i < TEST_COUNT; i ++)
168     {
169         if (i < 5)
170         {
171             /* Format the media with FAT12.  This needs to be done before opening it!  */
172             status =  fx_media_format(&ram_disk,
173                                      _fx_ram_driver,         // Driver entry
174                                      ram_disk_memory_large,  // RAM disk memory pointer
175                                      cache_buffer,           // Media buffer pointer
176                                      CACHE_SIZE,             // Media buffer size
177                                      "MY_RAM_DISK",          // Volume Name
178                                      1,                      // Number of FATs
179                                      32,                     // Directory Entries
180                                      0,                      // Hidden sectors
181                                      256,                    // Total sectors
182                                      256,                    // Sector size
183                                      8,                      // Sectors per cluster
184                                      1,                      // Heads
185                                      1);                     // Sectors per track
186         }
187         else if (i < 10)
188         {
189             /* Format the media with FAT16.  This needs to be done before opening it!  */
190             status =  fx_media_format(&ram_disk,
191                                      _fx_ram_driver,         // Driver entry
192                                      ram_disk_memory_large,  // RAM disk memory pointer
193                                      cache_buffer,           // Media buffer pointer
194                                      CACHE_SIZE,             // Media buffer size
195                                      "MY_RAM_DISK",          // Volume Name
196                                      1,                      // Number of FATs
197                                      32,                     // Directory Entries
198                                      0,                      // Hidden sectors
199                                      4200 * 8,               // Total sectors
200                                      256,                    // Sector size
201                                      8,                      // Sectors per cluster
202                                      1,                      // Heads
203                                      1);                     // Sectors per track
204         }
205         else if (i < 15)
206         {
207             /* Format the media with FAT32.  This needs to be done before opening it!  */
208             status =  fx_media_format(&ram_disk,
209                                      _fx_ram_driver,         // Driver entry
210                                      ram_disk_memory_large,  // RAM disk memory pointer
211                                      cache_buffer,           // Media buffer pointer
212                                      CACHE_SIZE,             // Media buffer size
213                                      "MY_RAM_DISK",          // Volume Name
214                                      1,                      // Number of FATs
215                                      32,                     // Directory Entries
216                                      0,                      // Hidden sectors
217                                      70000 * 8,              // Total sectors
218                                      256,                    // Sector size
219                                      8,                      // Sectors per cluster
220                                      1,                      // Heads
221                                      1);                     // Sectors per track
222         }
223 
224         /* Determine if the format had an error.  */
225         if (status)
226         {
227 
228             printf("ERROR!\n");
229             test_control_return(1);
230         }
231 
232         /* Open the ram_disk.  */
233         status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
234 
235         /* Check the status.  */
236         if (status != FX_SUCCESS)
237         {
238 
239             /* Error, return error code.  */
240             printf("ERROR!\n");
241             test_control_return(2);
242         }
243 
244         /* Enable the Fault-tolerant feature.  */
245         status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
246 
247         /* Check status.   */
248         if (status)
249         {
250 
251             printf("ERROR!\n");
252             test_control_return(3);
253         }
254 
255         /* Create a file called TEST.TXT in the root directory.  */
256         status =  fx_file_create(&ram_disk, "TEST.TXT");
257 
258         /* Check the create status.  */
259         if (status != FX_SUCCESS)
260         {
261 
262             printf("ERROR!\n");
263             test_control_return(4);
264         }
265 
266         /* Open the test file.  */
267         status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
268 
269         /* Check the file open status.  */
270         if (status != FX_SUCCESS)
271         {
272 
273             printf("ERROR!\n");
274             test_control_return(5);
275         }
276 
277         /* Write a string to the test file.  */
278         status =  fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
279 
280         /* Check the file write status.  */
281         if (status != FX_SUCCESS)
282         {
283 
284             printf("ERROR!\n");
285             test_control_return(6);
286         }
287 
288         /* Seek to the beginning of the test file.  */
289         status =  fx_file_seek(&my_file, 0);
290 
291         /* Check the file seek status.  */
292         if (status != FX_SUCCESS)
293         {
294 
295             printf("ERROR!\n");
296             test_control_return(7);
297         }
298 
299         /* Read the bytes of the test file.  */
300         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
301 
302         /* Check the file read status.  */
303         if ((status != FX_SUCCESS) || (actual != 28))
304         {
305 
306             printf("ERROR!\n");
307             test_control_return(8);
308         }
309 
310         /* Close the test file.  */
311         status =  fx_file_close(&my_file);
312 
313         /* Check the file close status.  */
314         if (status != FX_SUCCESS)
315         {
316 
317             printf("ERROR!\n");
318             test_control_return(9);
319         }
320 
321         /* Create a file called TEST1.TXT in the root directory.  */
322         status =  fx_file_create(&ram_disk, "TEST1.TXT");
323 
324         /* Check the create status.  */
325         if (status != FX_SUCCESS)
326         {
327 
328             printf("ERROR!\n");
329             test_control_return(10);
330         }
331 
332         /* Open the test file.  */
333         status =  fx_file_open(&ram_disk, &my_file, "TEST1.TXT", FX_OPEN_FOR_WRITE);
334 
335         /* Check the file open status.  */
336         if (status != FX_SUCCESS)
337         {
338 
339             printf("ERROR!\n");
340             test_control_return(11);
341         }
342 
343         /* Write a string to the test file.  */
344 
345         /* Random genearte the write data.  */
346         for (write_index = 0; write_index < 1500; write_index ++)
347         {
348             write_buffer[write_index] = (CHAR)rand();
349 
350             /* Store the write data to compare the new data after Data write interrupt.  */
351             data_buffer[write_index] = (UCHAR)write_buffer[write_index];
352             data_size = 1500;
353         }
354 
355         /* Write the data into file.  */
356         status =  fx_file_write(&my_file, (void *) write_buffer, data_size);
357 
358         /* Check the file write status.  */
359         if (status != FX_SUCCESS)
360         {
361 
362             printf("ERROR!\n");
363             test_control_return(12);
364         }
365 
366         /* Seek to the beginning of the test file.  */
367         status =  fx_file_seek(&my_file, 0);
368 
369         /* Check the file seek status.  */
370         if (status != FX_SUCCESS)
371         {
372 
373             printf("ERROR!\n");
374             test_control_return(13);
375         }
376 
377         /* Read the bytes of the test file.  */
378         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
379 
380         /* Check the file read status.  */
381         if ((status != FX_SUCCESS) || (actual != data_size))
382         {
383 
384             printf("ERROR!\n");
385             test_control_return(14);
386         }
387 
388         /* Close the test file.  */
389         status =  fx_file_close(&my_file);
390 
391         /* Check the file close status.  */
392         if (status != FX_SUCCESS)
393         {
394 
395             printf("ERROR!\n");
396             test_control_return(15);
397         }
398 
399         /* Create a file called TEST2.TXT in the root directory.  */
400         status =  fx_file_create(&ram_disk, "TEST2.TXT");
401 
402         /* Check the create status.  */
403         if (status != FX_SUCCESS)
404         {
405 
406             printf("ERROR!\n");
407             test_control_return(16);
408         }
409 
410         /* Open the test file.  */
411         status =  fx_file_open(&ram_disk, &my_file, "TEST2.TXT", FX_OPEN_FOR_WRITE);
412 
413         /* Check the file open status.  */
414         if (status != FX_SUCCESS)
415         {
416 
417             printf("ERROR!\n");
418             test_control_return(17);
419         }
420 
421         /* Write a string to the test file.  */
422         status =  fx_file_write(&my_file, " EXPRESSLOGIC_TEST\n", 19);
423 
424         /* Check the file write status.  */
425         if (status != FX_SUCCESS)
426         {
427 
428             printf("ERROR!\n");
429             test_control_return(18);
430         }
431 
432         /* Seek to the beginning of the test file.  */
433         status =  fx_file_seek(&my_file, 0);
434 
435         /* Check the file seek status.  */
436         if (status != FX_SUCCESS)
437         {
438 
439             printf("ERROR!\n");
440             test_control_return(19);
441         }
442 
443         /* Read the bytes of the test file.  */
444         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
445 
446         /* Check the file read status.  */
447         if ((status != FX_SUCCESS) || (actual != 19))
448         {
449 
450             printf("ERROR!\n");
451             test_control_return(20);
452         }
453 
454         /* Close the test file.  */
455         status =  fx_file_close(&my_file);
456 
457         /* Check the file close status.  */
458         if (status != FX_SUCCESS)
459         {
460 
461             printf("ERROR!\n");
462             test_control_return(21);
463         }
464 
465         /* Create the main thread.  */
466 #ifndef FX_STANDALONE_ENABLE
467         tx_thread_create(&ftest_1, "thread 1", ftest_1_entry, 0,
468                         thread_buffer, DEMO_STACK_SIZE,
469                         4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
470 #endif
471 
472         /* directory_write_interrupt */
473         fat_write_interrupt = FX_FALSE;
474 
475         /* Let the other thread run.  */
476 #ifndef FX_STANDALONE_ENABLE
477         tx_thread_relinquish();
478 #else
479         pthread_create(&ptid1, NULL, &ftest_1_entry, NULL);
480         usleep(10);
481         pthread_join(ptid1,NULL);
482 #endif
483 
484         /* After write interrupt, reread the files.  */
485 
486         /* Open the ram_disk.  */
487         status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
488 
489         /* Check the status.  */
490         if (status != FX_SUCCESS)
491         {
492 
493             /* Error, return error code.  */
494             printf("ERROR!\n");
495             test_control_return(22);
496         }
497 
498         /* Enable the Fault-tolerant feature to recover the media.  */
499         status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
500 
501         /* Check status.   */
502         if (status)
503         {
504 
505             printf("ERROR!\n");
506             test_control_return(23);
507         }
508 
509         /* Open the test file.  */
510         status =  fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
511 
512         /* Check the file open status.  */
513         if (status != FX_SUCCESS)
514         {
515 
516             printf("ERROR!\n");
517             test_control_return(24);
518         }
519 
520         /* Seek to the beginning of the test file.  */
521         status =  fx_file_seek(&my_file, 0);
522 
523         /* Check the file seek status.  */
524         if (status != FX_SUCCESS)
525         {
526 
527             printf("ERROR!\n");
528             test_control_return(25);
529         }
530 
531         /* Read the bytes of the test file.  */
532         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
533 
534         /* Check the file read status.  */
535         if ((status != FX_SUCCESS) || (actual != 28))
536         {
537 
538             printf("ERROR!\n");
539             test_control_return(26);
540         }
541 
542         /* Close the test file.  */
543         status =  fx_file_close(&my_file);
544 
545         /* Check the file close status.  */
546         if (status != FX_SUCCESS)
547         {
548 
549             printf("ERROR!\n");
550             test_control_return(27);
551         }
552 
553         /* Open the test file.  */
554         status =  fx_file_open(&ram_disk, &my_file, "TEST1.TXT", FX_OPEN_FOR_WRITE);
555 
556         /* Check the file open status.  */
557         if (status != FX_SUCCESS)
558         {
559 
560             printf("ERROR!\n");
561             test_control_return(28);
562         }
563 
564         /* Seek to the beginning of the test file.  */
565         status =  fx_file_seek(&my_file, 0);
566 
567         /* Check the file seek status.  */
568         if (status != FX_SUCCESS)
569         {
570 
571             printf("ERROR!\n");
572             test_control_return(29);
573         }
574 
575         /* Read the bytes of the test file.  */
576         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
577 
578         /* Check the file read status. FAT 12, 16, 32.  */
579         if ((status != FX_SUCCESS) || (actual != data_size) || memcmp(read_buffer, data_buffer, actual))
580         {
581 
582             printf("ERROR!\n");
583             test_control_return(30);
584         }
585 
586         /* Close the test file.  */
587         status =  fx_file_close(&my_file);
588 
589         /* Check the file close status.  */
590         if (status != FX_SUCCESS)
591         {
592 
593             printf("ERROR!\n");
594             test_control_return(31);
595         }
596 
597         /* Open the test file.  */
598         status =  fx_file_open(&ram_disk, &my_file, "TEST2.TXT", FX_OPEN_FOR_WRITE);
599 
600         /* Check the file open status.  */
601         if (status != FX_SUCCESS)
602         {
603 
604             printf("ERROR!\n");
605             test_control_return(32);
606         }
607 
608         /* Seek to the beginning of the test file.  */
609         status =  fx_file_seek(&my_file, 0);
610 
611         /* Check the file seek status.  */
612         if (status != FX_SUCCESS)
613         {
614 
615             printf("ERROR!\n");
616             test_control_return(33);
617         }
618 
619         /* Read the bytes of the test file.  */
620         status =  fx_file_read(&my_file, read_buffer, read_buffer_size, &actual);
621 
622         /* Check the file read status.  */
623         if ((status != FX_SUCCESS) || (actual != 19))
624         {
625 
626             printf("ERROR!\n");
627             test_control_return(34);
628         }
629 
630         /* Close the test file.  */
631         status =  fx_file_close(&my_file);
632 
633         /* Check the file close status.  */
634         if (status != FX_SUCCESS)
635         {
636 
637             printf("ERROR!\n");
638             test_control_return(35);
639         }
640 
641         /* Close the media.  */
642         status =  fx_media_close(&ram_disk);
643 
644         /* Determine if the test was successful.  */
645         if ((status != FX_SUCCESS) || (fat_write_interrupt != FX_TRUE) || (error_couter))
646         {
647 
648             printf("ERROR!\n");
649             test_control_return(36);
650         }
651 
652         /* Delete the thread.  */
653 #ifndef FX_STANDALONE_ENABLE
654         tx_thread_delete(&ftest_1);
655 #else
656         pthread_cancel(ptid1);
657 #endif
658     }
659 
660     /* Output successful.  */
661     printf("SUCCESS!\n");
662     test_control_return(0);
663 }
664 
665 /* Define the test threads.  */
666 
667 #ifndef FX_STANDALONE_ENABLE
ftest_1_entry(ULONG thread_input)668 static void    ftest_1_entry(ULONG thread_input)
669 #else
670  void  *  ftest_1_entry(void * thread_input)
671 #endif
672 {
673 
674 #ifdef FX_STANDALONE_ENABLE
675     UINT oldtype;
676     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
677     pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
678 #endif
679 
680     UINT        status;
681 
682     FX_PARAMETER_NOT_USED(thread_input);
683 
684     /* Set the callback function to simulate poweoff operation when write FAT entry.  */
685 
686     driver_write_callback = my_driver_write;
687 
688     /* Open the test file.  */
689     status =  fx_file_open(&ram_disk, &my_file, "TEST1.TXT", FX_OPEN_FOR_WRITE);
690 
691     /* Check the file open status.  */
692     if (status != FX_SUCCESS)
693     {
694         error_couter ++;
695 #ifndef FX_STANDALONE_ENABLE
696         return;
697 #else
698         return NULL;
699 #endif
700     }
701 
702     /* Seek to the file. FAT 12, 16 and 32.  */
703     if ((i % SEEK_COUNT) == 0)
704     {
705         status = fx_file_seek(&my_file, 0);
706     }
707     else if ((i % SEEK_COUNT) == 1)
708     {
709         status = fx_file_seek(&my_file, 1023);
710     }
711     else if ((i % SEEK_COUNT) == 2)
712     {
713         status = fx_file_seek(&my_file, 1024);
714     }
715     else if ((i % SEEK_COUNT) == 3)
716     {
717         status = fx_file_seek(&my_file, 1025);
718     }
719     else if ((i % SEEK_COUNT) == 4)
720     {
721         status = fx_file_seek(&my_file, 1500);
722     }
723 
724     /* Check the file seek status.  */
725     if (status != FX_SUCCESS)
726     {
727         error_couter ++;
728 #ifndef FX_STANDALONE_ENABLE
729         return;
730 #else
731         return NULL;
732 #endif
733     }
734 
735     /* Random genearte the write data.  */
736     for (write_index = 0; write_index < write_buffer_size; write_index ++)
737     {
738         write_buffer[write_index] = (CHAR)rand();
739     }
740 
741     /* Write 1024 bytes to the file, then update the FAT table.  (bytes should be greate than one cluster).  */
742     fx_file_write(&my_file, (void *) write_buffer, write_buffer_size);
743 }
744 
my_driver_write(FX_MEDIA * media_ptr,UINT sector_type,UCHAR * block_ptr,UINT * operation_ptr)745 static UINT my_driver_write(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr)
746 {
747 
748     FX_PARAMETER_NOT_USED(block_ptr);
749 
750     /* Interrupt the FAT write operation after record the undo log.  */
751     if ((sector_type == FX_FAT_SECTOR) && (_filex_fault_tolerant_log_check(media_ptr) & FX_FAULT_TOLERANT_LOG_UNDO_DONE))
752     {
753 
754         /* Set the write interrupt operation.  */
755         *operation_ptr = FX_OP_WRITE_INTERRUPT;
756 
757         /* Update the flag.  */
758         fat_write_interrupt = FX_TRUE;
759 
760         /* Clean the callback function.  */
761         driver_write_callback = FX_NULL;
762 
763         /* Delete the media protection structure if FX_SINGLE_THREAD is not
764         defined.  */
765 #ifndef FX_SINGLE_THREAD
766 #ifndef FX_DONT_CREATE_MUTEX
767 
768         /* Note that the protection is never released. The mutex delete
769         service will handle all threads waiting access to this media
770         control block.  */
771         tx_mutex_delete(&(media_ptr -> fx_media_protect));
772 #endif
773 #endif
774 
775         /* Clean the media data.  */
776         _fx_system_media_opened_ptr = FX_NULL;
777         _fx_system_media_opened_count = 0;
778 
779         /* Clean the media.  */
780         memset(media_ptr, 0, sizeof(FX_MEDIA));
781 
782         /* Simulate poweroff.  */
783         /* First terminate the thread to ensure it is ready for deletion.  */
784 #ifndef FX_STANDALONE_ENABLE
785         tx_thread_terminate(&ftest_1);
786 #else
787         pthread_cancel(ptid1);
788 #endif
789     }
790 
791     /* Return.  */
792     return FX_SUCCESS;
793 }
794 #else
795 
796 #ifdef CTEST
test_application_define(void * first_unused_memory)797 void test_application_define(void *first_unused_memory)
798 #else
799 void    filex_fault_tolerant_file_write_fat_interrupt_test_application_define(void *first_unused_memory)
800 #endif
801 {
802 
803     FX_PARAMETER_NOT_USED(first_unused_memory);
804 
805     /* Print out some test information banners.  */
806     printf("FileX Test:   Fault Tolerant File Write FAT Interrupt Test...........N/A\n");
807 
808     test_control_return(255);
809 }
810 #endif
811 
812