filex_unicode_directory_entry_2_test.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <stdio.h>
  7. #include "fx_ram_driver_test.h"
  8. #define DEMO_STACK_SIZE 8192
  9. #define CACHE_SIZE 16*128
  10. /* Define the ThreadX and FileX object control blocks... */
  11. #ifndef FX_STANDALONE_ENABLE
  12. static TX_THREAD ftest_0;
  13. #endif
  14. static FX_MEDIA ram_disk;
  15. /* Define the counters used in the test application... */
  16. #ifndef FX_STANDALONE_ENABLE
  17. static UCHAR *ram_disk_memory;
  18. static UCHAR *cache_buffer;
  19. #else
  20. static UCHAR cache_buffer[CACHE_SIZE];
  21. #endif
  22. /* Define thread prototypes. */
  23. void filex_unicode_directory_entry_2_test_application_define(void *first_unused_memory);
  24. static void ftest_0_entry(ULONG thread_input);
  25. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  26. void test_control_return(UINT status);
  27. /* Define what the initial system looks like. */
  28. #ifdef CTEST
  29. void test_application_define(void *first_unused_memory)
  30. #else
  31. void filex_unicode_directory_entry_2_test_application_define(void *first_unused_memory)
  32. #endif
  33. {
  34. #ifndef FX_STANDALONE_ENABLE
  35. UCHAR *pointer;
  36. /* Setup the working pointer. */
  37. pointer = (UCHAR *) first_unused_memory;
  38. /* Create the main thread. */
  39. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  40. pointer, DEMO_STACK_SIZE,
  41. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  42. pointer = pointer + DEMO_STACK_SIZE;
  43. /* Setup memory for the RAM disk and the sector cache. */
  44. cache_buffer = pointer;
  45. pointer = pointer + CACHE_SIZE;
  46. ram_disk_memory = pointer;
  47. #endif
  48. /* Initialize the FileX system. */
  49. fx_system_initialize();
  50. #ifdef FX_STANDALONE_ENABLE
  51. ftest_0_entry(0);
  52. #endif
  53. }
  54. /* Define the test threads. */
  55. static void ftest_0_entry(ULONG thread_input)
  56. {
  57. UINT status;
  58. UCHAR destination_name[100] = {0};
  59. UCHAR destination_name2[100] = {0};
  60. 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};
  61. ULONG length = 14;
  62. FX_LOCAL_PATH local_path;
  63. FX_PARAMETER_NOT_USED(thread_input);
  64. /* Print out some test information banners. */
  65. printf("FileX Test: Unicode directory entry 2 test.........................");
  66. /* Format the media. This needs to be done before opening it! */
  67. status = fx_media_format(&ram_disk,
  68. _fx_ram_driver, // Driver entry
  69. ram_disk_memory, // RAM disk memory pointer
  70. cache_buffer, // Media buffer pointer
  71. CACHE_SIZE, // Media buffer size
  72. "MY_RAM_DISK", // Volume Name
  73. 1, // Number of FATs
  74. 32, // Directory Entries
  75. 0, // Hidden sectors
  76. 512, // Total sectors
  77. 128, // Sector size
  78. /* To cover the branch, which read mulitple sectors in the same cluster. */
  79. 2, // Sectors per cluster
  80. 1, // Heads
  81. 1); // Sectors per track
  82. /* Open the ram_disk. */
  83. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  84. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
  85. /* Chdir to the created directory and create a subdirectory. */
  86. status += fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
  87. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
  88. /* Fat entry destory. */
  89. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_value = 0;
  90. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_dirty = 1;
  91. /* Close the media to flush buffer. Now we have a disk with a corrupt dir_entry. */
  92. status += fx_media_close(&ram_disk);
  93. /* Open the ram_disk. */
  94. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  95. if (status != FX_SUCCESS)
  96. {
  97. printf("ERROR!\n");
  98. test_control_return(19);
  99. }
  100. status += fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
  101. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *) destination_name);
  102. if (status == FX_FILE_CORRUPT)
  103. {
  104. printf("ERROR!\n");
  105. test_control_return(19);
  106. }
  107. else
  108. {
  109. printf("SUCCESS!\n");
  110. test_control_return(0);
  111. }
  112. }