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 <stdio.h>
8 #include "fx_ram_driver_test.h"
9
10 #define DEMO_STACK_SIZE 4096
11 #define CACHE_SIZE 16*128
12
13
14 /* Define the ThreadX and FileX object control blocks... */
15
16 #ifndef FX_STANDALONE_ENABLE
17 static TX_THREAD ftest_0;
18 #endif
19 static FX_MEDIA ram_disk;
20 static FX_FILE my_file;
21
22
23 /* Define the counters used in the test application... */
24
25 #ifndef FX_STANDALONE_ENABLE
26 static UCHAR *ram_disk_memory;
27 static UCHAR *cache_buffer;
28 #else
29 static UCHAR cache_buffer[CACHE_SIZE];
30 #endif
31
32
33 /* Define thread prototypes. */
34
35 void filex_media_format_open_close_application_define(void *first_unused_memory);
36 static void ftest_0_entry(ULONG thread_input);
37
38 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
39 void test_control_return(UINT status);
40
41
42
43 /* Define what the initial system looks like. */
44
45 #ifdef CTEST
test_application_define(void * first_unused_memory)46 void test_application_define(void *first_unused_memory)
47 #else
48 void filex_media_format_open_close_application_define(void *first_unused_memory)
49 #endif
50 {
51
52 #ifndef FX_STANDALONE_ENABLE
53 UCHAR *pointer;
54
55
56 /* Setup the working pointer. */
57 pointer = (UCHAR *) first_unused_memory;
58
59 /* Create the main thread. */
60 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
61 pointer, DEMO_STACK_SIZE,
62 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
63
64 pointer = pointer + DEMO_STACK_SIZE;
65
66 /* Setup memory for the RAM disk and the sector cache. */
67 cache_buffer = pointer;
68 pointer = pointer + CACHE_SIZE;
69 ram_disk_memory = pointer;
70
71 #endif
72
73 /* Initialize the FileX system. */
74 fx_system_initialize();
75 #ifdef FX_STANDALONE_ENABLE
76 ftest_0_entry(0);
77 #endif
78 }
79
80
81
82 /* Define the test threads. */
83
ftest_0_entry(ULONG thread_input)84 static void ftest_0_entry(ULONG thread_input)
85 {
86
87 UINT status;
88 ULONG actual;
89 UCHAR local_buffer[32];
90
91 FX_PARAMETER_NOT_USED(thread_input);
92
93 /* Print out some test information banners. */
94 actual = FX_MAX_LONG_NAME_LEN;
95 if (actual < 256)
96 printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LONG_NAME_LEN=256\n");
97 actual = FX_MAX_LAST_NAME_LEN;
98 if (actual < 256)
99 printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LAST_NAME_LEN=256\n");
100
101 /* Print out some test information banners. */
102 printf("FileX Test: Media format, open, and close test.....................");
103
104 /* Format the media with invalid parameters. */
105 status = fx_media_format(&ram_disk,
106 _fx_ram_driver, // Driver entry
107 ram_disk_memory, // RAM disk memory pointer
108 cache_buffer, // Media buffer pointer
109 CACHE_SIZE, // Media buffer size
110 "MY_RAM_DISK", // Volume Name
111 1, // Number of FATs
112 32, // Directory Entries
113 0, // Hidden sectors
114 256, // Total sectors
115 4097, // Sector size
116 1, // Sectors per cluster
117 1, // Heads
118 1); // Sectors per track
119
120 /* Check status. */
121 if (status != FX_SECTOR_INVALID)
122 {
123
124 printf("ERROR!\n");
125 test_control_return(2);
126 }
127
128 /* Format the media with invalid parameters. */
129 status = fx_media_format(&ram_disk,
130 _fx_ram_driver, // Driver entry
131 ram_disk_memory, // RAM disk memory pointer
132 cache_buffer, // Media buffer pointer
133 CACHE_SIZE, // Media buffer size
134 "MY_RAM_DISK", // Volume Name
135 1, // Number of FATs
136 32, // Directory Entries
137 0, // Hidden sectors
138 256, // Total sectors
139 0, // Sector size
140 1, // Sectors per cluster
141 1, // Heads
142 1); // Sectors per track
143
144 /* Check status. */
145 if (status != FX_SECTOR_INVALID)
146 {
147
148 printf("ERROR!\n");
149 test_control_return(2);
150 }
151
152 /* Format the media with invalid parameters. */
153 status = fx_media_format(&ram_disk,
154 _fx_ram_driver, // Driver entry
155 ram_disk_memory, // RAM disk memory pointer
156 cache_buffer, // Media buffer pointer
157 CACHE_SIZE, // Media buffer size
158 "MY_RAM_DISK", // Volume Name
159 1, // Number of FATs
160 32, // Directory Entries
161 0, // Hidden sectors
162 256, // Total sectors
163 128, // Sector size
164 129, // Sectors per cluster
165 1, // Heads
166 1); // Sectors per track
167
168 /* Check status. */
169 if (status != FX_SECTOR_INVALID)
170 {
171
172 printf("ERROR!\n");
173 test_control_return(2);
174 }
175
176 /* Format the media with invalid parameters. */
177 status = fx_media_format(&ram_disk,
178 _fx_ram_driver, // Driver entry
179 ram_disk_memory, // RAM disk memory pointer
180 cache_buffer, // Media buffer pointer
181 CACHE_SIZE, // Media buffer size
182 "MY_RAM_DISK", // Volume Name
183 1, // Number of FATs
184 32, // Directory Entries
185 0, // Hidden sectors
186 256, // Total sectors
187 128, // Sector size
188 0, // Sectors per cluster
189 1, // Heads
190 1); // Sectors per track
191
192 /* Check status. */
193 if (status != FX_SECTOR_INVALID)
194 {
195
196 printf("ERROR!\n");
197 test_control_return(2);
198 }
199
200 /* Format the media. This needs to be done before opening it! */
201 status = fx_media_format(&ram_disk,
202 _fx_ram_driver, // Driver entry
203 ram_disk_memory, // RAM disk memory pointer
204 cache_buffer, // Media buffer pointer
205 CACHE_SIZE, // Media buffer size
206 "MY_RAM_DISK", // Volume Name
207 1, // Number of FATs
208 32, // Directory Entries
209 0, // Hidden sectors
210 256, // Total sectors
211 128, // Sector size
212 1, // Sectors per cluster
213 1, // Heads
214 1); // Sectors per track
215
216 /* Determine if the format had an error. */
217 if (status)
218 {
219
220 printf("ERROR!\n");
221 test_control_return(2);
222 }
223
224 /* Try to close the media before it has been opened */
225 status = fx_media_close(&ram_disk);
226 if (status != FX_MEDIA_NOT_OPEN)
227 {
228 printf("ERROR!\n");
229 test_control_return(11);
230 }
231
232 /* Open the ram_disk. */
233 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, 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(3);
242 }
243
244 /* Create a file called TEST.TXT in the root directory. */
245 status = fx_file_create(&ram_disk, "TEST.TXT");
246
247 /* Check the create status. */
248 if (status != FX_SUCCESS)
249 {
250
251 /* Check for an already created status. This is not fatal, just
252 let the user know. */
253 if (status != FX_ALREADY_CREATED)
254 {
255
256 printf("ERROR!\n");
257 test_control_return(3);
258 }
259 }
260
261 /* Open the test file. */
262 status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
263
264 /* Check the file open status. */
265 if (status != FX_SUCCESS)
266 {
267
268 printf("ERROR!\n");
269 test_control_return(4);
270 }
271
272 /* test error checking */
273 #ifndef FX_DISABLE_ERROR_CHECKING
274
275 /* send a null pointer to generate an error */
276 status = fx_media_close(FX_NULL);
277 if (status != FX_PTR_ERROR)
278 {
279 printf("ERROR!\n");
280 test_control_return(8);
281 }
282
283 /* send null pointer to generate an error */
284 status = fx_media_open(FX_NULL, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
285 if (status != FX_PTR_ERROR)
286 {
287 printf("ERROR!\n");
288 test_control_return(11);
289 }
290
291 /* try to open an already open media to generate an error */
292 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
293 if (status != FX_PTR_ERROR)
294 {
295 printf("ERROR!\n");
296 test_control_return(11);
297 }
298
299 #endif /* FX_DISABLE_ERROR_CHECKING */
300
301 /* Seek to the beginning of the test file. */
302 status = fx_file_seek(&my_file, 0);
303
304 /* Check the file seek status. */
305 if (status != FX_SUCCESS)
306 {
307
308 printf("ERROR!\n");
309 test_control_return(5);
310 }
311
312 /* Write a string to the test file. */
313 status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
314
315 /* Check the file write status. */
316 if (status != FX_SUCCESS)
317 {
318
319 printf("ERROR!\n");
320 test_control_return(6);
321 }
322
323 /* Seek to the beginning of the test file. */
324 status = fx_file_seek(&my_file, 0);
325
326 /* Check the file seek status. */
327 if (status != FX_SUCCESS)
328 {
329
330 printf("ERROR!\n");
331 test_control_return(7);
332 }
333
334 /* Read the first 28 bytes of the test file. */
335 status = fx_file_read(&my_file, local_buffer, 28, &actual);
336
337 /* Check the file read status. */
338 if ((status != FX_SUCCESS) || (actual != 28))
339 {
340
341 printf("ERROR!\n");
342 test_control_return(8);
343 }
344
345 /* Close the test file. */
346 status = fx_file_close(&my_file);
347
348 /* Check the file close status. */
349 if (status != FX_SUCCESS)
350 {
351
352 printf("ERROR!\n");
353 test_control_return(9);
354 }
355
356 /* Close the media. */
357 status = fx_media_close(&ram_disk);
358
359 /* Re-Open the ram_disk. */
360 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
361
362 /* Check the status. */
363 if (status != FX_SUCCESS)
364 {
365
366 /* Error, return error code. */
367 printf("ERROR!\n");
368 test_control_return(3);
369 }
370
371 /* Create a file called TEST.TXT in the root directory. */
372 status = fx_file_create(&ram_disk, "TEST.TXT");
373
374 /* Check for an already created status. This is not fatal, just
375 let the user know. */
376 if (status != FX_ALREADY_CREATED)
377 {
378
379 printf("ERROR!\n");
380 test_control_return(3);
381 }
382
383 /* Open the test file. */
384 status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
385
386 /* Check the file open status. */
387 if (status != FX_SUCCESS)
388 {
389
390 printf("ERROR!\n");
391 test_control_return(4);
392 }
393
394 /* Seek to the beginning of the test file. */
395 status = fx_file_seek(&my_file, 0);
396
397 /* Check the file seek status. */
398 if (status != FX_SUCCESS)
399 {
400
401 printf("ERROR!\n");
402 test_control_return(5);
403 }
404
405 /* Write a string to the test file. */
406 status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
407
408 /* Check the file write status. */
409 if (status != FX_SUCCESS)
410 {
411
412 printf("ERROR!\n");
413 test_control_return(6);
414 }
415
416 /* Seek to the beginning of the test file. */
417 status = fx_file_seek(&my_file, 0);
418
419 /* Check the file seek status. */
420 if (status != FX_SUCCESS)
421 {
422
423 printf("ERROR!\n");
424 test_control_return(7);
425 }
426
427 /* Read the first 28 bytes of the test file. */
428 status = fx_file_read(&my_file, local_buffer, 28, &actual);
429
430 /* Check the file read status. */
431 if ((status != FX_SUCCESS) || (actual != 28))
432 {
433
434 printf("ERROR!\n");
435 test_control_return(8);
436 }
437
438 /* Close the test file. */
439 status = fx_file_close(&my_file);
440
441 /* Check the file close status. */
442 if (status != FX_SUCCESS)
443 {
444
445 printf("ERROR!\n");
446 test_control_return(9);
447 }
448
449 /* Close the media. */
450 status = fx_media_close(&ram_disk);
451
452 /* Determine if the test was successful. */
453 if (status != FX_SUCCESS)
454 {
455
456 printf("ERROR!\n");
457 test_control_return(10);
458 }
459
460 /* Format the media. This needs to be done before opening it! */
461 status = fx_media_format(&ram_disk,
462 _fx_ram_driver, // Driver entry
463 ram_disk_memory, // RAM disk memory pointer
464 cache_buffer, // Media buffer pointer
465 CACHE_SIZE, // Media buffer size
466 "MY_RAM_DISK", // Volume Name
467 1, // Number of FATs
468 32, // Directory Entries
469 0, // Hidden sectors
470 256, // Total sectors
471 128, // Sector size
472 1, // Sectors per cluster
473 1, // Heads
474 1); // Sectors per track
475
476 /* Determine if the format had an error. */
477 if (status)
478 {
479
480 printf("ERROR!\n");
481 test_control_return(11);
482 }
483
484 /* Corrupt the bytes per sector field. */
485 _fx_utility_16_unsigned_write(&ram_disk_memory[FX_BYTES_SECTOR], 0);
486
487 /* Open the ram_disk. */
488 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
489
490 /* Check the status. */
491 if (status != FX_MEDIA_INVALID)
492 {
493
494 /* Error, return error code. */
495 printf("ERROR!\n");
496 test_control_return(12);
497 }
498
499 /* Format the media. This needs to be done before opening it! */
500 status = fx_media_format(&ram_disk,
501 _fx_ram_driver, // Driver entry
502 ram_disk_memory, // RAM disk memory pointer
503 cache_buffer, // Media buffer pointer
504 CACHE_SIZE, // Media buffer size
505 "MY_RAM_DISK", // Volume Name
506 1, // Number of FATs
507 32, // Directory Entries
508 0, // Hidden sectors
509 256, // Total sectors
510 128, // Sector size
511 1, // Sectors per cluster
512 1, // Heads
513 1); // Sectors per track
514
515 /* Determine if the format had an error. */
516 if (status)
517 {
518
519 printf("ERROR!\n");
520 test_control_return(13);
521 }
522
523 /* Corrupt the total sectors field. */
524 _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS], 0);
525 _fx_utility_32_unsigned_write(&ram_disk_memory[FX_HUGE_SECTORS], 0);
526
527 /* Open the ram_disk. */
528 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
529
530 /* Check the status. */
531 if (status != FX_MEDIA_INVALID)
532 {
533
534 /* Error, return error code. */
535 printf("ERROR!\n");
536 test_control_return(14);
537 }
538
539 /* Format the media. This needs to be done before opening it! */
540 status = fx_media_format(&ram_disk,
541 _fx_ram_driver, // Driver entry
542 ram_disk_memory, // RAM disk memory pointer
543 cache_buffer, // Media buffer pointer
544 CACHE_SIZE, // Media buffer size
545 "MY_RAM_DISK", // Volume Name
546 1, // Number of FATs
547 32, // Directory Entries
548 0, // Hidden sectors
549 256, // Total sectors
550 128, // Sector size
551 1, // Sectors per cluster
552 1, // Heads
553 1); // Sectors per track
554
555 /* Determine if the format had an error. */
556 if (status)
557 {
558
559 printf("ERROR!\n");
560 test_control_return(15);
561 }
562
563 /* Corrupt the reserved sectors field. */
564 _fx_utility_16_unsigned_write(&ram_disk_memory[FX_RESERVED_SECTORS], 0);
565
566 /* Open the ram_disk. */
567 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
568
569 /* Check the status. */
570 if (status != FX_MEDIA_INVALID)
571 {
572
573 /* Error, return error code. */
574 printf("ERROR!\n");
575 test_control_return(16);
576 }
577
578 /* Format the media. This needs to be done before opening it! */
579 status = fx_media_format(&ram_disk,
580 _fx_ram_driver, // Driver entry
581 ram_disk_memory, // RAM disk memory pointer
582 cache_buffer, // Media buffer pointer
583 CACHE_SIZE, // Media buffer size
584 "MY_RAM_DISK", // Volume Name
585 1, // Number of FATs
586 32, // Directory Entries
587 0, // Hidden sectors
588 256, // Total sectors
589 128, // Sector size
590 1, // Sectors per cluster
591 1, // Heads
592 1); // Sectors per track
593
594 /* Determine if the format had an error. */
595 if (status)
596 {
597
598 printf("ERROR!\n");
599 test_control_return(17);
600 }
601
602 /* Corrupt the sectors per cluster field. */
603 ram_disk_memory[FX_SECTORS_CLUSTER] = 0;
604
605 /* Open the ram_disk. */
606 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
607
608 /* Check the status. */
609 if (status != FX_MEDIA_INVALID)
610 {
611
612 /* Error, return error code. */
613 printf("ERROR!\n");
614 test_control_return(18);
615 }
616
617 /* Format the media. This needs to be done before opening it! */
618 status = fx_media_format(&ram_disk,
619 _fx_ram_driver, // Driver entry
620 ram_disk_memory, // RAM disk memory pointer
621 cache_buffer, // Media buffer pointer
622 CACHE_SIZE, // Media buffer size
623 "MY_RAM_DISK", // Volume Name
624 1, // Number of FATs
625 32, // Directory Entries
626 0, // Hidden sectors
627 256, // Total sectors
628 128, // Sector size
629 1, // Sectors per cluster
630 1, // Heads
631 1); // Sectors per track
632
633 /* Determine if the format had an error. */
634 if (status)
635 {
636
637 printf("ERROR!\n");
638 test_control_return(19);
639 }
640
641 /* Corrupt the sectors per FAT field. */
642 _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT], 0);
643 _fx_utility_32_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT_32], 0);
644
645 /* Open the ram_disk. */
646 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
647
648 /* Check the status. */
649 if (status != FX_MEDIA_INVALID)
650 {
651
652 /* Error, return error code. */
653 printf("ERROR!\n");
654 test_control_return(20);
655 }
656
657 /* Format the media. This needs to be done before opening it! */
658 status = fx_media_format(&ram_disk,
659 _fx_ram_driver, // Driver entry
660 ram_disk_memory, // RAM disk memory pointer
661 cache_buffer, // Media buffer pointer
662 CACHE_SIZE, // Media buffer size
663 "MY_RAM_DISK", // Volume Name
664 1, // Number of FATs
665 32, // Directory Entries
666 0, // Hidden sectors
667 256, // Total sectors
668 128, // Sector size
669 1, // Sectors per cluster
670 1, // Heads
671 1); // Sectors per track
672
673 /* Determine if the format had an error. */
674 if (status)
675 {
676
677 printf("ERROR!\n");
678 test_control_return(21);
679 }
680
681 /* Corrupt the number of FATs field. */
682 ram_disk_memory[FX_NUMBER_OF_FATS] = 0;
683
684 /* Open the ram_disk. */
685 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
686
687 /* Check the status. */
688 if (status != FX_MEDIA_INVALID)
689 {
690
691 /* Error, return error code. */
692 printf("ERROR!\n");
693 test_control_return(22);
694 }
695
696 /* Format the media. This needs to be done before opening it! */
697 status = fx_media_format(&ram_disk,
698 _fx_ram_driver, // Driver entry
699 ram_disk_memory, // RAM disk memory pointer
700 cache_buffer, // Media buffer pointer
701 CACHE_SIZE, // Media buffer size
702 "MY_RAM_DISK", // Volume Name
703 1, // Number of FATs
704 32, // Directory Entries
705 0, // Hidden sectors
706 256, // Total sectors
707 128, // Sector size
708 1, // Sectors per cluster
709 1, // Heads
710 1); // Sectors per track
711
712 /* Determine if the format had an error. */
713 if (status)
714 {
715
716 printf("ERROR!\n");
717 test_control_return(21);
718 }
719
720 /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
721 status = fx_media_format(&ram_disk,
722 _fx_ram_driver, // Driver entry
723 ram_disk_memory, // RAM disk memory pointer
724 cache_buffer, // Media buffer pointer
725 CACHE_SIZE, // Media buffer size
726 "MY_RAM_DISK", // Volume Name
727 1, // Number of FATs
728 32, // Directory Entries
729 0, // Hidden sectors
730 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
731 128, // Sector size
732 1, // Sectors per cluster
733 1, // Heads
734 1); // Sectors per track
735
736 /* Determine if the format had an error. */
737 if (status)
738 {
739
740 printf("ERROR!\n");
741 test_control_return(23);
742 }
743
744 /* Open the ram_disk. */
745 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
746 status += fx_media_close(&ram_disk);
747
748 /* Check the status. */
749 if (status != FX_SUCCESS)
750 {
751
752 /* Error, return error code. */
753 printf("ERROR!\n");
754 test_control_return(24);
755 }
756
757 /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
758 status = fx_media_format(&ram_disk,
759 _fx_ram_driver, // Driver entry
760 ram_disk_memory, // RAM disk memory pointer
761 cache_buffer, // Media buffer pointer
762 CACHE_SIZE, // Media buffer size
763 "MY_RAM_DISK", // Volume Name
764 1, // Number of FATs
765 32, // Directory Entries
766 0, // Hidden sectors
767 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
768 128, // Sector size
769 1, // Sectors per cluster
770 1, // Heads
771 1); // Sectors per track
772
773 /* Determine if the format had an error. */
774 if (status)
775 {
776
777 printf("ERROR!\n");
778 test_control_return(25);
779 }
780
781 /* Open the ram_disk. */
782 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
783 status += fx_media_close(&ram_disk);
784
785 /* Check the status. */
786 if (status != FX_SUCCESS)
787 {
788
789 /* Error, return error code. */
790 printf("ERROR!\n");
791 test_control_return(26);
792 }
793
794
795 /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
796 status = fx_media_format(&ram_disk,
797 _fx_ram_driver, // Driver entry
798 ram_disk_memory, // RAM disk memory pointer
799 cache_buffer, // Media buffer pointer
800 CACHE_SIZE, // Media buffer size
801 "MY_RAM_DISK", // Volume Name
802 1, // Number of FATs
803 32, // Directory Entries
804 0, // Hidden sectors
805 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
806 128, // Sector size
807 1, // Sectors per cluster
808 1, // Heads
809 1); // Sectors per track
810
811 /* Determine if the format had an error. */
812 if (status)
813 {
814
815 printf("ERROR!\n");
816 test_control_return(23);
817 }
818
819 /* Clear 480 bytes from offset 30. Verify the compatibility.
820 * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
821 memset(&ram_disk_memory[30], 0, 480);
822
823 /* Open the ram_disk. */
824 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
825 status += fx_media_close(&ram_disk);
826
827 /* Check the status. */
828 if (status != FX_SUCCESS)
829 {
830
831 /* Error, return error code. */
832 printf("ERROR!\n");
833 test_control_return(24);
834 }
835
836 /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
837 status = fx_media_format(&ram_disk,
838 _fx_ram_driver, // Driver entry
839 ram_disk_memory, // RAM disk memory pointer
840 cache_buffer, // Media buffer pointer
841 CACHE_SIZE, // Media buffer size
842 "MY_RAM_DISK", // Volume Name
843 1, // Number of FATs
844 32, // Directory Entries
845 0, // Hidden sectors
846 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
847 128, // Sector size
848 1, // Sectors per cluster
849 1, // Heads
850 1); // Sectors per track
851
852 /* Determine if the format had an error. */
853 if (status)
854 {
855
856 printf("ERROR!\n");
857 test_control_return(25);
858 }
859
860 /* Clear 480 bytes from offset 30. Verify the compatibility.
861 * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
862 memset(&ram_disk_memory[30], 0, 480);
863
864 /* Open the ram_disk. */
865 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
866 status += fx_media_close(&ram_disk);
867
868 /* Check the status. */
869 if (status != FX_SUCCESS)
870 {
871
872 /* Error, return error code. */
873 printf("ERROR!\n");
874 test_control_return(26);
875 }
876
877 /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
878 status = fx_media_format(&ram_disk,
879 _fx_ram_driver, // Driver entry
880 ram_disk_memory, // RAM disk memory pointer
881 cache_buffer, // Media buffer pointer
882 CACHE_SIZE, // Media buffer size
883 "MY_RAM_DISK", // Volume Name
884 1, // Number of FATs
885 32, // Directory Entries
886 0, // Hidden sectors
887 70656+9, // Total sectors - FAT32
888 128, // Sector size
889 1, // Sectors per cluster
890 1, // Heads
891 1); // Sectors per track
892
893 /* Determine if the format had an error. */
894 if (status)
895 {
896
897 printf("ERROR!\n");
898 test_control_return(27);
899 }
900
901 /* Open the ram_disk. */
902 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
903 status += fx_media_close(&ram_disk);
904
905 /* Check the status. */
906 if (status != FX_SUCCESS)
907 {
908
909 /* Error, return error code. */
910 printf("ERROR!\n");
911 test_control_return(28);
912 }
913
914
915 /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
916 status = fx_media_format(&ram_disk,
917 _fx_ram_driver, // Driver entry
918 ram_disk_memory, // RAM disk memory pointer
919 cache_buffer, // Media buffer pointer
920 CACHE_SIZE, // Media buffer size
921 "MY_RAM_DISK", // Volume Name
922 1, // Number of FATs
923 32, // Directory Entries
924 0, // Hidden sectors
925 70656+9, // Total sectors - FAT32
926 128, // Sector size
927 1, // Sectors per cluster
928 1, // Heads
929 1); // Sectors per track
930
931 /* Determine if the format had an error. */
932 if (status)
933 {
934
935 printf("ERROR!\n");
936 test_control_return(27);
937 }
938
939 /* Corrupt the root cluster field. */
940 ram_disk_memory[FX_ROOT_CLUSTER_32] = 0;
941 ram_disk_memory[FX_ROOT_CLUSTER_32 + 1] = 0;
942 ram_disk_memory[FX_ROOT_CLUSTER_32 + 2] = 0;
943 ram_disk_memory[FX_ROOT_CLUSTER_32 + 3] = 0;
944
945 /* Open the ram_disk. */
946 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
947
948 /* Check the status. */
949 if (status != FX_MEDIA_INVALID)
950 {
951
952 /* Error, return error code. */
953 printf("ERROR!\n");
954 test_control_return(28);
955 }
956
957 /* Format the media with volume name containing space! */
958 status = fx_media_format(&ram_disk,
959 _fx_ram_driver, // Driver entry
960 ram_disk_memory, // RAM disk memory pointer
961 cache_buffer, // Media buffer pointer
962 CACHE_SIZE, // Media buffer size
963 "NO NAME", // Volume Name
964 1, // Number of FATs
965 32, // Directory Entries
966 0, // Hidden sectors
967 512, // Total sectors
968 128, // Sector size
969 1, // Sectors per cluster
970 1, // Heads
971 1); // Sectors per track
972
973 /* Determine if the format had an error. */
974 if (status)
975 {
976
977 printf("ERROR!\n");
978 test_control_return(29);
979 }
980
981 /* Open the ram_disk. */
982 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
983
984 status += fx_media_volume_get(&ram_disk, (CHAR *)local_buffer, FX_BOOT_SECTOR);
985
986 /* Check for status. */
987 if ((status != FX_SUCCESS) || (memcmp(local_buffer, "NO NAME", 7)))
988 {
989 printf("ERROR!\n");
990 test_control_return(30);
991 }
992
993 status = fx_media_close(&ram_disk);
994
995 /* Check the status. */
996 if (status != FX_SUCCESS)
997 {
998
999 /* Error, return error code. */
1000 printf("ERROR!\n");
1001 test_control_return(31);
1002 }
1003
1004 memset(ram_disk_memory, 0, sizeof(ram_disk_memory));
1005
1006 /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
1007 status = fx_media_format(&ram_disk,
1008 _fx_ram_driver, // Driver entry
1009 ram_disk_memory, // RAM disk memory pointer
1010 cache_buffer, // Media buffer pointer
1011 CACHE_SIZE, // Media buffer size
1012 "MY_RAM_DISK", // Volume Name
1013 1, // Number of FATs
1014 32, // Directory Entries
1015 0, // Hidden sectors
1016 70656+9, // Total sectors - FAT32
1017 128, // Sector size
1018 1, // Sectors per cluster
1019 1, // Heads
1020 1); // Sectors per track
1021
1022 /* Determine if the format had an error. */
1023 if (status)
1024 {
1025
1026 printf("ERROR!\n");
1027 test_control_return(32);
1028 }
1029
1030 unsigned index =0;
1031 /* Check the FAT entry values, first byte starts with 0xF(_fx_media_format_media_type) */
1032 for(index=0; index< ((70656+9)*128);index++)
1033 {
1034 if((ram_disk_memory[index]==0xF8) && (ram_disk_memory[index+1]==0xFF) && (ram_disk_memory[index+2]==0xFF) &&
1035 (ram_disk_memory[index+3]==0x0F) && (ram_disk_memory[index+4]==0xFF) && (ram_disk_memory[index+5]==0xFF) &&
1036 (ram_disk_memory[index+6]==0xFF) && (ram_disk_memory[index+7]==0x0F))
1037 {
1038 break;
1039 }
1040 }
1041
1042 if(index ==(70656+9)*128)
1043 {
1044
1045 printf("ERROR!\n");
1046 test_control_return(33);
1047 }
1048 else
1049 {
1050 printf("SUCCESS!\n");
1051 test_control_return(0);
1052
1053 }
1054
1055 }
1056
1057