filex_unicode_fat_entry_3_test.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* Test the condition of fat entry broken. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_utility.h"
  7. #include "fx_ram_driver_test.h"
  8. #include <stdio.h>
  9. #define DEMO_STACK_SIZE 8192
  10. #define CACHE_SIZE 16*128
  11. /* Define the ThreadX and FileX object control blocks... */
  12. #ifndef FX_STANDALONE_ENABLE
  13. static TX_THREAD ftest_0;
  14. #endif
  15. static FX_MEDIA ram_disk;
  16. /* Define the counters used in the test application... */
  17. #ifndef FX_STANDALONE_ENABLE
  18. static UCHAR *ram_disk_memory;
  19. static UCHAR *cache_buffer;
  20. #else
  21. static UCHAR cache_buffer[CACHE_SIZE];
  22. #endif
  23. /* Define thread prototypes. */
  24. void filex_unicode_fat_entry_3_test_application_define(void *first_unused_memory);
  25. static void ftest_0_entry(ULONG thread_input);
  26. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  27. void test_control_return(UINT status);
  28. /* Define what the initial system looks like. */
  29. #ifdef CTEST
  30. void test_application_define(void *first_unused_memory)
  31. #else
  32. void filex_unicode_fat_entry_3_test_application_define(void *first_unused_memory)
  33. #endif
  34. {
  35. #ifndef FX_STANDALONE_ENABLE
  36. UCHAR *pointer;
  37. /* Setup the working pointer. */
  38. pointer = (UCHAR *) first_unused_memory;
  39. /* Create the main thread. */
  40. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  41. pointer, DEMO_STACK_SIZE,
  42. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  43. pointer = pointer + DEMO_STACK_SIZE;
  44. /* Setup memory for the RAM disk and the sector cache. */
  45. cache_buffer = pointer;
  46. pointer = pointer + CACHE_SIZE;
  47. ram_disk_memory = pointer;
  48. #endif
  49. /* Initialize the FileX system. */
  50. fx_system_initialize();
  51. #ifdef FX_STANDALONE_ENABLE
  52. ftest_0_entry(0);
  53. #endif
  54. }
  55. /* Define the test threads. */
  56. static void ftest_0_entry(ULONG thread_input)
  57. {
  58. UINT status;
  59. UCHAR destination_name[100] = {0};
  60. UCHAR destination_name1[20] = {0};
  61. UCHAR destination_name2[20] = {0};
  62. UCHAR destination_name3[20] = {0};
  63. UCHAR destination_name4[20] = {0};
  64. UCHAR destination_name5[20] = {0};
  65. UCHAR destination_name6[20] = {0};
  66. UCHAR destination_name7[20] = {0};
  67. UCHAR destination_name8[20] = {0};
  68. UCHAR long_unicode_name[] = {2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 0};
  69. ULONG length = 14;
  70. UCHAR fat_buffer[128] = {0};
  71. FX_LOCAL_PATH local_path;
  72. FX_PARAMETER_NOT_USED(thread_input);
  73. /* Print out some test information banners. */
  74. printf("FileX Test: Unicode fat entry 3 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. 7000, // Total sectors - FAT16
  86. 128, // Sector size
  87. 1, // Sectors per cluster
  88. 1, // Heads
  89. 1); // Sectors per track
  90. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  91. return_if_fail( status == FX_SUCCESS);
  92. /* Create a directory and many subdirectories to build fat chain. */
  93. status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
  94. #ifndef FX_STANDALONE_ENABLE
  95. status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
  96. #else
  97. status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
  98. #endif
  99. long_unicode_name[0]++;
  100. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name1);
  101. long_unicode_name[0]++;
  102. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
  103. long_unicode_name[0]++;
  104. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name3);
  105. long_unicode_name[0]++;
  106. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name4);
  107. long_unicode_name[0]++;
  108. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name5);
  109. long_unicode_name[0]++;
  110. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name6);
  111. return_if_fail( status == FX_SUCCESS);
  112. /* Flush everything out. */
  113. fx_media_flush(&ram_disk);
  114. _fx_utility_FAT_flush(&ram_disk);
  115. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  116. for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
  117. {
  118. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  119. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  120. }
  121. /* Read the first FAT sector. */
  122. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  123. /* Add a FAT entry randomly in the FAT table. */
  124. fat_buffer[6] = 0x32;
  125. fat_buffer[7] = 0x00;
  126. /* Write the FAT corruption out. */
  127. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  128. return_if_fail( status == FX_SUCCESS);
  129. long_unicode_name[0]++;
  130. status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
  131. return_if_fail( status == FX_FAT_READ_ERROR);
  132. /* Flush everything out. */
  133. fx_media_flush(&ram_disk);
  134. _fx_utility_FAT_flush(&ram_disk);
  135. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  136. for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
  137. {
  138. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  139. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  140. }
  141. /* Read the first FAT sector. */
  142. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  143. /* Add a FAT entry randomly in the FAT table. */
  144. fat_buffer[6] = 0x03;
  145. fat_buffer[7] = 0x00;
  146. /* Write the FAT corruption out. */
  147. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  148. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
  149. return_if_fail( status == FX_FAT_READ_ERROR);
  150. /* Flush everything out. */
  151. fx_media_flush(&ram_disk);
  152. _fx_utility_FAT_flush(&ram_disk);
  153. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  154. for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
  155. {
  156. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  157. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  158. }
  159. /* Read the first FAT sector. */
  160. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  161. /* Recovery FAT chain. */
  162. fat_buffer[6] = 0x06;
  163. fat_buffer[7] = 0x00;
  164. /* Write the FAT corruption out. */
  165. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  166. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
  167. return_if_fail( status == FX_SUCCESS);
  168. /* Flush everything out. */
  169. fx_media_flush(&ram_disk);
  170. _fx_utility_FAT_flush(&ram_disk);
  171. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  172. for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
  173. {
  174. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  175. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  176. }
  177. /* Read the first FAT sector. */
  178. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  179. /* Make FAT chain a circle. */
  180. fat_buffer[12] = 0x03;
  181. fat_buffer[13] = 0x00;
  182. /* Write the FAT corruption out. */
  183. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  184. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name8);
  185. return_if_fail( status == FX_FAT_READ_ERROR);
  186. printf("SUCCESS!\n");
  187. test_control_return(0);
  188. }