| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056 |
- /* This FileX test concentrates on the basic media format, open, close operation. */
- #ifndef FX_STANDALONE_ENABLE
- #include "tx_api.h"
- #endif
- #include "fx_api.h"
- #include <stdio.h>
- #include "fx_ram_driver_test.h"
- #define DEMO_STACK_SIZE 4096
- #define CACHE_SIZE 16*128
- /* Define the ThreadX and FileX object control blocks... */
- #ifndef FX_STANDALONE_ENABLE
- static TX_THREAD ftest_0;
- #endif
- static FX_MEDIA ram_disk;
- static FX_FILE my_file;
- /* Define the counters used in the test application... */
- #ifndef FX_STANDALONE_ENABLE
- static UCHAR *ram_disk_memory;
- static UCHAR *cache_buffer;
- #else
- static UCHAR cache_buffer[CACHE_SIZE];
- #endif
- /* Define thread prototypes. */
- void filex_media_format_open_close_application_define(void *first_unused_memory);
- static void ftest_0_entry(ULONG thread_input);
- VOID _fx_ram_driver(FX_MEDIA *media_ptr);
- void test_control_return(UINT status);
- /* Define what the initial system looks like. */
- #ifdef CTEST
- void test_application_define(void *first_unused_memory)
- #else
- void filex_media_format_open_close_application_define(void *first_unused_memory)
- #endif
- {
- #ifndef FX_STANDALONE_ENABLE
- UCHAR *pointer;
-
- /* Setup the working pointer. */
- pointer = (UCHAR *) first_unused_memory;
- /* Create the main thread. */
- tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
- pointer, DEMO_STACK_SIZE,
- 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
- pointer = pointer + DEMO_STACK_SIZE;
- /* Setup memory for the RAM disk and the sector cache. */
- cache_buffer = pointer;
- pointer = pointer + CACHE_SIZE;
- ram_disk_memory = pointer;
- #endif
- /* Initialize the FileX system. */
- fx_system_initialize();
- #ifdef FX_STANDALONE_ENABLE
- ftest_0_entry(0);
- #endif
- }
- /* Define the test threads. */
- static void ftest_0_entry(ULONG thread_input)
- {
- UINT status;
- ULONG actual;
- UCHAR local_buffer[32];
- FX_PARAMETER_NOT_USED(thread_input);
- /* Print out some test information banners. */
- actual = FX_MAX_LONG_NAME_LEN;
- if (actual < 256)
- printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LONG_NAME_LEN=256\n");
- actual = FX_MAX_LAST_NAME_LEN;
- if (actual < 256)
- printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LAST_NAME_LEN=256\n");
- /* Print out some test information banners. */
- printf("FileX Test: Media format, open, and close test.....................");
- /* Format the media with invalid parameters. */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 4097, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Check status. */
- if (status != FX_SECTOR_INVALID)
- {
- printf("ERROR!\n");
- test_control_return(2);
- }
- /* Format the media with invalid parameters. */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 0, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Check status. */
- if (status != FX_SECTOR_INVALID)
- {
- printf("ERROR!\n");
- test_control_return(2);
- }
- /* Format the media with invalid parameters. */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 129, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Check status. */
- if (status != FX_SECTOR_INVALID)
- {
- printf("ERROR!\n");
- test_control_return(2);
- }
- /* Format the media with invalid parameters. */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 0, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Check status. */
- if (status != FX_SECTOR_INVALID)
- {
- printf("ERROR!\n");
- test_control_return(2);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(2);
- }
-
- /* Try to close the media before it has been opened */
- status = fx_media_close(&ram_disk);
- if (status != FX_MEDIA_NOT_OPEN)
- {
- printf("ERROR!\n");
- test_control_return(11);
- }
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(3);
- }
- /* Create a file called TEST.TXT in the root directory. */
- status = fx_file_create(&ram_disk, "TEST.TXT");
- /* Check the create status. */
- if (status != FX_SUCCESS)
- {
- /* Check for an already created status. This is not fatal, just
- let the user know. */
- if (status != FX_ALREADY_CREATED)
- {
- printf("ERROR!\n");
- test_control_return(3);
- }
- }
- /* Open the test file. */
- status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
- /* Check the file open status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(4);
- }
-
- /* test error checking */
- #ifndef FX_DISABLE_ERROR_CHECKING
-
- /* send a null pointer to generate an error */
- status = fx_media_close(FX_NULL);
- if (status != FX_PTR_ERROR)
- {
- printf("ERROR!\n");
- test_control_return(8);
- }
-
- /* send null pointer to generate an error */
- status = fx_media_open(FX_NULL, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- if (status != FX_PTR_ERROR)
- {
- printf("ERROR!\n");
- test_control_return(11);
- }
-
- /* try to open an already open media to generate an error */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- if (status != FX_PTR_ERROR)
- {
- printf("ERROR!\n");
- test_control_return(11);
- }
-
- #endif /* FX_DISABLE_ERROR_CHECKING */
- /* Seek to the beginning of the test file. */
- status = fx_file_seek(&my_file, 0);
- /* Check the file seek status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(5);
- }
- /* Write a string to the test file. */
- status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
- /* Check the file write status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(6);
- }
- /* Seek to the beginning of the test file. */
- status = fx_file_seek(&my_file, 0);
- /* Check the file seek status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(7);
- }
- /* Read the first 28 bytes of the test file. */
- status = fx_file_read(&my_file, local_buffer, 28, &actual);
- /* Check the file read status. */
- if ((status != FX_SUCCESS) || (actual != 28))
- {
- printf("ERROR!\n");
- test_control_return(8);
- }
- /* Close the test file. */
- status = fx_file_close(&my_file);
- /* Check the file close status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(9);
- }
- /* Close the media. */
- status = fx_media_close(&ram_disk);
- /* Re-Open the ram_disk. */
- status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(3);
- }
- /* Create a file called TEST.TXT in the root directory. */
- status = fx_file_create(&ram_disk, "TEST.TXT");
- /* Check for an already created status. This is not fatal, just
- let the user know. */
- if (status != FX_ALREADY_CREATED)
- {
- printf("ERROR!\n");
- test_control_return(3);
- }
- /* Open the test file. */
- status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
- /* Check the file open status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(4);
- }
- /* Seek to the beginning of the test file. */
- status = fx_file_seek(&my_file, 0);
- /* Check the file seek status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(5);
- }
- /* Write a string to the test file. */
- status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
- /* Check the file write status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(6);
- }
- /* Seek to the beginning of the test file. */
- status = fx_file_seek(&my_file, 0);
- /* Check the file seek status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(7);
- }
- /* Read the first 28 bytes of the test file. */
- status = fx_file_read(&my_file, local_buffer, 28, &actual);
- /* Check the file read status. */
- if ((status != FX_SUCCESS) || (actual != 28))
- {
- printf("ERROR!\n");
- test_control_return(8);
- }
- /* Close the test file. */
- status = fx_file_close(&my_file);
- /* Check the file close status. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(9);
- }
- /* Close the media. */
- status = fx_media_close(&ram_disk);
- /* Determine if the test was successful. */
- if (status != FX_SUCCESS)
- {
- printf("ERROR!\n");
- test_control_return(10);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(11);
- }
- /* Corrupt the bytes per sector field. */
- _fx_utility_16_unsigned_write(&ram_disk_memory[FX_BYTES_SECTOR], 0);
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(12);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(13);
- }
- /* Corrupt the total sectors field. */
- _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS], 0);
- _fx_utility_32_unsigned_write(&ram_disk_memory[FX_HUGE_SECTORS], 0);
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(14);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(15);
- }
- /* Corrupt the reserved sectors field. */
- _fx_utility_16_unsigned_write(&ram_disk_memory[FX_RESERVED_SECTORS], 0);
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(16);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(17);
- }
- /* Corrupt the sectors per cluster field. */
- ram_disk_memory[FX_SECTORS_CLUSTER] = 0;
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(18);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(19);
- }
- /* Corrupt the sectors per FAT field. */
- _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT], 0);
- _fx_utility_32_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT_32], 0);
-
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(20);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(21);
- }
- /* Corrupt the number of FATs field. */
- ram_disk_memory[FX_NUMBER_OF_FATS] = 0;
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(22);
- }
- /* Format the media. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(21);
- }
- /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(23);
- }
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(24);
- }
- /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(25);
- }
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(26);
- }
- /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(23);
- }
- /* Clear 480 bytes from offset 30. Verify the compatibility.
- * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
- memset(&ram_disk_memory[30], 0, 480);
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(24);
- }
- /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(25);
- }
- /* Clear 480 bytes from offset 30. Verify the compatibility.
- * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
- memset(&ram_disk_memory[30], 0, 480);
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(26);
- }
- /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 70656+9, // Total sectors - FAT32
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(27);
- }
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(28);
- }
- /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 70656+9, // Total sectors - FAT32
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(27);
- }
- /* Corrupt the root cluster field. */
- ram_disk_memory[FX_ROOT_CLUSTER_32] = 0;
- ram_disk_memory[FX_ROOT_CLUSTER_32 + 1] = 0;
- ram_disk_memory[FX_ROOT_CLUSTER_32 + 2] = 0;
- ram_disk_memory[FX_ROOT_CLUSTER_32 + 3] = 0;
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- /* Check the status. */
- if (status != FX_MEDIA_INVALID)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(28);
- }
- /* Format the media with volume name containing space! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "NO NAME", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 512, // Total sectors
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(29);
- }
- /* Open the ram_disk. */
- status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
- status += fx_media_volume_get(&ram_disk, (CHAR *)local_buffer, FX_BOOT_SECTOR);
- /* Check for status. */
- if ((status != FX_SUCCESS) || (memcmp(local_buffer, "NO NAME", 7)))
- {
- printf("ERROR!\n");
- test_control_return(30);
- }
- status = fx_media_close(&ram_disk);
- /* Check the status. */
- if (status != FX_SUCCESS)
- {
- /* Error, return error code. */
- printf("ERROR!\n");
- test_control_return(31);
- }
- memset(ram_disk_memory, 0, sizeof(ram_disk_memory));
- /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
- status = fx_media_format(&ram_disk,
- _fx_ram_driver, // Driver entry
- ram_disk_memory, // RAM disk memory pointer
- cache_buffer, // Media buffer pointer
- CACHE_SIZE, // Media buffer size
- "MY_RAM_DISK", // Volume Name
- 1, // Number of FATs
- 32, // Directory Entries
- 0, // Hidden sectors
- 70656+9, // Total sectors - FAT32
- 128, // Sector size
- 1, // Sectors per cluster
- 1, // Heads
- 1); // Sectors per track
- /* Determine if the format had an error. */
- if (status)
- {
- printf("ERROR!\n");
- test_control_return(32);
- }
- unsigned index =0;
- /* Check the FAT entry values, first byte starts with 0xF(_fx_media_format_media_type) */
- for(index=0; index< ((70656+9)*128);index++)
- {
- if((ram_disk_memory[index]==0xF8) && (ram_disk_memory[index+1]==0xFF) && (ram_disk_memory[index+2]==0xFF) &&
- (ram_disk_memory[index+3]==0x0F) && (ram_disk_memory[index+4]==0xFF) && (ram_disk_memory[index+5]==0xFF) &&
- (ram_disk_memory[index+6]==0xFF) && (ram_disk_memory[index+7]==0x0F))
- {
- break;
- }
- }
- if(index ==(70656+9)*128)
- {
- printf("ERROR!\n");
- test_control_return(33);
- }
- else
- {
- printf("SUCCESS!\n");
- test_control_return(0);
- }
-
- }
|