filex_unicode_fat_entry_1_test.c 5.0 KB

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