filex_unicode_fat_entry_test.c 5.0 KB

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