filex_file_name_test.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* This FileX test concentrates on the lowercase is not allowed in 8.3 name. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include <stdio.h>
  7. #include "fx_ram_driver_test.h"
  8. #include "fx_fault_tolerant.h"
  9. #define DEMO_STACK_SIZE 4096
  10. #define CACHE_SIZE 128*128
  11. #ifdef FX_ENABLE_FAULT_TOLERANT
  12. #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
  13. #else
  14. #define FAULT_TOLERANT_SIZE 0
  15. #endif
  16. /* Define the ThreadX and FileX object control blocks... */
  17. #ifndef FX_STANDALONE_ENABLE
  18. static TX_THREAD ftest_0;
  19. #endif
  20. static FX_MEDIA ram_disk;
  21. static FX_FILE my_file;
  22. /* Define the counters used in the test application... */
  23. #ifndef FX_STANDALONE_ENABLE
  24. static UCHAR *ram_disk_memory;
  25. static UCHAR *cache_buffer;
  26. #else
  27. static UCHAR cache_buffer[CACHE_SIZE];
  28. #endif
  29. static UCHAR write_data[65535];
  30. static UCHAR read_data[65535];
  31. #ifdef FX_ENABLE_FAULT_TOLERANT
  32. static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
  33. #endif /* FX_ENABLE_FAULT_TOLERANT */
  34. /* Define thread prototypes. */
  35. void filex_file_name_application_define(void *first_unused_memory);
  36. static void ftest_0_entry(ULONG thread_input);
  37. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  38. void test_control_return(UINT status);
  39. /* Define what the initial system looks like. */
  40. #ifdef CTEST
  41. void test_application_define(void *first_unused_memory)
  42. #else
  43. void filex_file_name_application_define(void *first_unused_memory)
  44. #endif
  45. {
  46. #ifndef FX_STANDALONE_ENABLE
  47. UCHAR *pointer;
  48. /* Setup the working pointer. */
  49. pointer = (UCHAR *) first_unused_memory;
  50. /* Create the main thread. */
  51. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  52. pointer, DEMO_STACK_SIZE,
  53. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  54. pointer = pointer + DEMO_STACK_SIZE;
  55. /* Setup memory for the RAM disk and the sector cache. */
  56. cache_buffer = pointer;
  57. pointer = pointer + CACHE_SIZE;
  58. ram_disk_memory = pointer;
  59. #endif
  60. /* Initialize the FileX system. */
  61. fx_system_initialize();
  62. #ifdef FX_STANDALONE_ENABLE
  63. ftest_0_entry(0);
  64. #endif
  65. }
  66. /* Define the test threads. */
  67. static void ftest_0_entry(ULONG thread_input)
  68. {
  69. UINT status;
  70. ULONG actual;
  71. ULONG i;
  72. FX_PARAMETER_NOT_USED(thread_input);
  73. /* Print out some test information banners. */
  74. printf("FileX Test: File name test.........................................");
  75. /* Format the media. This needs to be done before opening it! */
  76. status = fx_media_format(&ram_disk,
  77. _fx_ram_driver, // Driver entry
  78. ram_disk_memory, // RAM disk memory pointer
  79. cache_buffer, // Media buffer pointer
  80. CACHE_SIZE, // Media buffer size
  81. "MY_RAM_DISK", // Volume Name
  82. 1, // Number of FATs
  83. 32, // Directory Entries
  84. 0, // Hidden sectors
  85. 512, // Total sectors
  86. 512, // Sector size
  87. 8, // Sectors per cluster
  88. 1, // Heads
  89. 1); // Sectors per track
  90. /* Determine if the format had an error. */
  91. return_if_fail( status == FX_SUCCESS);
  92. /* Open the ram_disk. */
  93. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  94. return_if_fail( status == FX_SUCCESS);
  95. #ifdef FX_ENABLE_FAULT_TOLERANT
  96. /* Enable the Fault-tolerant feature. */
  97. status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
  98. return_if_fail( status == FX_SUCCESS);
  99. #endif /* FX_ENABLE_FAULT_TOLERANT */
  100. /* Initialize the data for write. */
  101. for (i = 0; i < sizeof(write_data); i++)
  102. {
  103. write_data[i] = (UCHAR)i;
  104. read_data[i] = 0;
  105. }
  106. /* Create a file called TEST.TXT in the root directory. */
  107. status = fx_file_create(&ram_disk, "TEST.TXT");
  108. return_if_fail( status == FX_SUCCESS);
  109. /* Open the test file. */
  110. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  111. return_if_fail( status == FX_SUCCESS);
  112. /* Set BIT3 to modify the filename to lowercase. */
  113. my_file.fx_file_dir_entry.fx_dir_entry_reserved = 0x08;
  114. /* Write to the file. */
  115. status = fx_file_write(&my_file, write_data, sizeof(write_data));
  116. return_if_fail( status == FX_SUCCESS);
  117. /* Close the file. */
  118. status = fx_file_close(&my_file);
  119. return_if_fail( status == FX_SUCCESS);
  120. /* Close the media. */
  121. fx_media_close(&ram_disk);
  122. /* Verify the filename is upper-case. */
  123. return_if_fail( memcmp(ram_disk_memory + 1024, "TEST TXT", 4) == 0);
  124. /* Open the media. */
  125. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  126. return_if_fail( status == FX_SUCCESS);
  127. /* Open the file as lowercase name. */
  128. status = fx_file_open(&ram_disk, &my_file, "test.txt", FX_OPEN_FOR_WRITE);
  129. return_if_fail( status == FX_SUCCESS);
  130. /* Write to the file. */
  131. status = fx_file_write(&my_file, write_data, sizeof(write_data));
  132. return_if_fail( status == FX_SUCCESS);
  133. /* Close the file. */
  134. status = fx_file_close(&my_file);
  135. return_if_fail( status == FX_SUCCESS);
  136. /* Reopen the media. */
  137. fx_media_close(&ram_disk);
  138. /* Verify the filename is upper-case. */
  139. return_if_fail( memcmp(ram_disk_memory + 1024, "TEST TXT", 4) == 0);
  140. /* Open the media. */
  141. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  142. return_if_fail( status == FX_SUCCESS);
  143. /* Open the file as lowercase name. */
  144. status = fx_file_open(&ram_disk, &my_file, "test.txt", FX_OPEN_FOR_READ);
  145. return_if_fail( status == FX_SUCCESS);
  146. /* Read from the file. */
  147. status = fx_file_read(&my_file, (void *) read_data, sizeof(read_data), &actual);
  148. return_if_fail( status == FX_SUCCESS);
  149. return_if_fail( actual == sizeof(write_data));
  150. return_if_fail( memcmp(read_data, write_data, actual) == 0);
  151. /* Close the file. */
  152. status = fx_file_close(&my_file);
  153. return_if_fail( status == FX_SUCCESS);
  154. /* Reopen the media. */
  155. fx_media_close(&ram_disk);
  156. printf("SUCCESS!\n");
  157. test_control_return(0);
  158. }