filex_unicode_4_test.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. #ifndef FX_STANDALONE_ENABLE
  2. #include "tx_api.h"
  3. #include "tx_thread.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. #include <string.h>
  10. #define DEMO_STACK_SIZE 8192
  11. /* Set the cache size as the size of one sector causing frequently IO operation. */
  12. #define CACHE_SIZE 128
  13. /* Define the global variable we may use in the future. */
  14. extern ULONG _fx_ram_driver_copy_default_format;
  15. extern UCHAR large_file_name_format[];
  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. /* Define the counters used in the test application... */
  22. #ifndef FX_STANDALONE_ENABLE
  23. static UCHAR *ram_disk_memory;
  24. static UCHAR *cache_buffer;
  25. #else
  26. static UCHAR cache_buffer[CACHE_SIZE];
  27. #endif
  28. /* Define thread prototypes. */
  29. void filex_unicode_4_application_define(void *first_unused_memory);
  30. static void ftest_0_entry(ULONG thread_input);
  31. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  32. void test_control_return(UINT status);
  33. /* Define what the initial system looks like. */
  34. #ifdef CTEST
  35. void test_application_define(void *first_unused_memory)
  36. #else
  37. void filex_unicode_4_application_define(void *first_unused_memory)
  38. #endif
  39. {
  40. #ifndef FX_STANDALONE_ENABLE
  41. UCHAR *pointer;
  42. /* Setup the working pointer. */
  43. pointer = (UCHAR *)first_unused_memory;
  44. /* Create the main thread. */
  45. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  46. pointer, DEMO_STACK_SIZE,
  47. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  48. pointer = pointer + DEMO_STACK_SIZE;
  49. /* Setup memory for the RAM disk and the sector cache. */
  50. cache_buffer = pointer;
  51. pointer = pointer + CACHE_SIZE;
  52. ram_disk_memory = pointer;
  53. #endif
  54. /* Initialize the FileX system. */
  55. fx_system_initialize();
  56. #ifdef FX_STANDALONE_ENABLE
  57. ftest_0_entry(0);
  58. #endif
  59. }
  60. static UCHAR long_unicode_name1[] = { 1, 0, 0, 0 };
  61. static UCHAR ascii_file_name[] = { 'a', 'b', 'c', 0 };
  62. static UCHAR specified_ascii_file_name[] = { 'Z', '1', '2', '3', '4', '5', '6', '7', '.', 't', 'x', 't', 0 };
  63. static UCHAR specified_unicode_file_name[] = { 'Z', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, 0 };
  64. static UCHAR specified_unicode_file_name_1[] = { 'a', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, 0 };
  65. #ifndef FX_DISABLE_ERROR_CHECKING
  66. static UCHAR specified_unicode_file_name_2[] = { 'a', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 0, 't', 0, 0 };
  67. #endif /* FX_DISABLE_ERROR_CHECKING */
  68. /* Define the test threads. */
  69. static void ftest_0_entry(ULONG thread_input)
  70. {
  71. UINT status, length, count;
  72. #ifndef FX_DISABLE_ERROR_CHECKING
  73. UINT new_length, old_length;
  74. #endif /* FX_DISABLE_ERROR_CHECKING */
  75. ULONG ulength;
  76. UCHAR destination_name[128];
  77. UCHAR destination_name_1[128];
  78. UCHAR temp, temp_array[32];
  79. FX_LOCAL_PATH local_path;
  80. FX_FILE my_file;
  81. FX_PARAMETER_NOT_USED(thread_input);
  82. /* Print out some test information banners. */
  83. printf("FileX Test: Unicode 4 test.........................................");
  84. /* Format the media. This needs to be done before opening it! */
  85. status = fx_media_format(&ram_disk,
  86. _fx_ram_driver, // Driver entry
  87. ram_disk_memory_large, // RAM disk memory pointer
  88. cache_buffer, // Media buffer pointer
  89. 128, // Media buffer size
  90. "MY_RAM_DISK", // Volume Name
  91. 1, // Number of FATs
  92. 32, // Directory Entries
  93. 0, // Hidden sectors
  94. 70000, // Total sectors
  95. 128, // Sector size
  96. 1, // Sectors per cluster
  97. 1, // Heads
  98. 1); // Sectors per track
  99. return_value_if_fail(status == FX_SUCCESS, 2);
  100. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  101. return_value_if_fail(status == FX_SUCCESS, 3);
  102. // Create a file whose name's first byte is 0xe5.
  103. ascii_file_name[0] = 0xe5;
  104. status = fx_file_create(&ram_disk, (CHAR *)ascii_file_name);
  105. return_value_if_fail(status == FX_SUCCESS, 4);
  106. // Attempt to create a unicode file which make fx_unicode_file_create call fx_unicode_directory_search to scan the directory before creation.
  107. // The file we just created will be read during the scannning so that the branch at Line 290 in fx_unicode_directory_search will be covered.
  108. length = fx_unicode_length_get(long_unicode_name1);
  109. status = fx_unicode_file_create(&ram_disk, long_unicode_name1, length, (CHAR *)destination_name);
  110. return_value_if_fail(status == FX_SUCCESS, 5);
  111. // Attempt to create two 8.3 format file by both fx_file_create and fx_unicode_file_create to cover the branch at Line 324 in fx_unicode_directory_search.c
  112. status = fx_file_create(&ram_disk, (CHAR *)specified_ascii_file_name);
  113. return_value_if_fail(status == FX_SUCCESS, 6);
  114. length = fx_unicode_length_get(specified_unicode_file_name);
  115. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  116. return_value_if_fail(status == FX_ALREADY_CREATED, 7);
  117. // Add test code to cover the branch at Line 146 in fx_unicode_directory_search.c
  118. ascii_file_name[0] = 'a';
  119. status = fx_directory_create(&ram_disk, (CHAR *)ascii_file_name);
  120. #ifndef FX_STANDALONE_ENABLE
  121. status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)ascii_file_name);
  122. #else
  123. status = fx_directory_default_set(&ram_disk, (CHAR *)ascii_file_name);
  124. #endif
  125. return_value_if_fail(status == FX_SUCCESS, 8);
  126. // Clear the name of current directory.
  127. #ifndef FX_STANDALONE_ENABLE
  128. ((FX_PATH*)_tx_thread_current_ptr->tx_thread_filex_ptr)->fx_path_directory.fx_dir_entry_name[0] = 0;
  129. #else
  130. status = fx_directory_default_set(&ram_disk, "\\");
  131. #endif
  132. // The file is attempted to be created in the root directory, so it will fail.
  133. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  134. return_value_if_fail(status == FX_ALREADY_CREATED, 9);
  135. status = fx_media_close(&ram_disk);
  136. return_value_if_fail(status == FX_SUCCESS, 10);
  137. /* Open the ram_disk in fx_ram_dirver_test.c which contain a long file name dir_entry associated with a free short name entry. */
  138. _fx_ram_driver_copy_default_format = 1;
  139. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  140. return_value_if_fail(status == FX_SUCCESS, 11);
  141. _fx_ram_driver_copy_default_format = 0;
  142. /* Cover the branch around Line 608 in fx_unicode_directory_entry_read.c. */
  143. length = fx_unicode_length_get(specified_unicode_file_name);
  144. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  145. return_value_if_fail(status == FX_SUCCESS, 12);
  146. /* Create a 8.3 format volume dirctory entry. */
  147. status = fx_media_volume_set(&ram_disk, " . ");
  148. return_value_if_fail(status == FX_SUCCESS, 13);
  149. /* Access our directory to cover the branch at Line 587 in fx_unicode_direcotry_entry_read. */
  150. length = fx_unicode_length_get(specified_unicode_file_name);
  151. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  152. return_value_if_fail(status == FX_ALREADY_CREATED, 14);
  153. /* Create format volume dirctory entry with 11 blanks. */
  154. status = fx_media_volume_set(&ram_disk, " ");
  155. return_value_if_fail(status == FX_SUCCESS, 15);
  156. /* Access our directory to cover the branch at Line 619 in fx_unicode_direcotry_entry_read. */
  157. length = fx_unicode_length_get(specified_unicode_file_name);
  158. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  159. return_value_if_fail(status == FX_ALREADY_CREATED, 16);
  160. /* Changed first byte as lowercase. */
  161. specified_unicode_file_name[0] = 'z';
  162. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
  163. return_value_if_fail(status == FX_ALREADY_CREATED, 17);
  164. /* Create a file whose name is begin with 'a'. */
  165. length = fx_unicode_length_get(specified_unicode_file_name_1);
  166. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_1, length, (CHAR *)destination_name);
  167. return_value_if_fail(status == FX_SUCCESS, 18);
  168. /* Changed first byte as uppercase. */
  169. specified_unicode_file_name_1[0] = 'A';
  170. length = fx_unicode_length_get(specified_unicode_file_name_1);
  171. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_1, length, (CHAR *)destination_name);
  172. return_value_if_fail(status == FX_ALREADY_CREATED, 19);
  173. /* Reuse our disk in fx_ram_driver_test.c to create a set of corrupt dir_entries include a normal dir_entry associated with a specified one whose first byte is 0. */
  174. status = fx_media_close(&ram_disk);
  175. _fx_ram_driver_copy_default_format = 1;
  176. /* Modify the first byte at Line 1738 in fx_ram_driver_test.c. */
  177. temp = large_file_name_format[(1738 - 852) * 16];
  178. large_file_name_format[(1738 - 852) * 16] = 0x00;
  179. /* Modify the first dir_entry, which used to be the first short name dir_entry in the directory, to be the long name of "NT-FILE~.TXT". */
  180. for (count = 0; count < 32; count++)
  181. {
  182. temp_array[count] = large_file_name_format[(1732 - 852) * 16 + count];
  183. large_file_name_format[(1732 - 852) * 16 + count] = large_file_name_format[(1736 - 852) * 16 + count];
  184. }
  185. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  186. return_value_if_fail(status == FX_SUCCESS, 20);
  187. /* Revert all we done. */
  188. _fx_ram_driver_copy_default_format = 0;
  189. large_file_name_format[(1738 - 852) * 16] = temp;
  190. for (count = 0; count < 32; count++)
  191. {
  192. large_file_name_format[(1732 - 852) * 16 + count] = temp_array[count];
  193. }
  194. /* Access the dir_entry we just modified by fx_unicode_name_get. */
  195. status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TXTa", destination_name_1, &ulength);
  196. return_value_if_fail(status == FX_NOT_FOUND, 21);
  197. status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TXT", destination_name_1, &ulength);
  198. return_value_if_fail(status == FX_SUCCESS, 31);
  199. status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TX", destination_name_1, &ulength);
  200. return_value_if_fail(status == FX_NOT_FOUND, 32);
  201. /* Show special performance in our implement. Althought we assign the first byte of some short name dir_entry as 0, fx_unicode_directory_search consider the long file name return by fx_unicode_directory_entry_read as short name so that we will succeed. */
  202. status = fx_unicode_name_get(&ram_disk, "aBcD~", destination_name_1, &ulength);
  203. return_value_if_fail(status == FX_SUCCESS, 33);
  204. #ifndef FX_DISABLE_ERROR_CHECKING
  205. /* Test unicode name checking. */
  206. length = fx_unicode_length_get(specified_unicode_file_name_2);
  207. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  208. return_value_if_fail(status == FX_SUCCESS, 21);
  209. length++;
  210. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  211. return_value_if_fail(status == FX_INVALID_NAME, 22);
  212. length = fx_unicode_length_get(specified_unicode_file_name_2);
  213. status = fx_unicode_directory_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  214. return_value_if_fail(status == FX_ALREADY_CREATED, 23);
  215. length++;
  216. status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  217. return_value_if_fail(status == FX_INVALID_NAME, 24);
  218. length = fx_unicode_length_get(specified_unicode_file_name_2);
  219. status = fx_unicode_short_name_get(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  220. return_value_if_fail(status == FX_SUCCESS, 25);
  221. length++;
  222. status = fx_unicode_short_name_get(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
  223. return_value_if_fail(status == FX_INVALID_NAME, 26);
  224. status = fx_unicode_short_name_get_extended(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name, sizeof(destination_name));
  225. return_value_if_fail(status == FX_INVALID_NAME, 26);
  226. /* Test invalid old file name */
  227. old_length = fx_unicode_length_get(specified_unicode_file_name_2);
  228. old_length++;
  229. new_length = fx_unicode_length_get(specified_unicode_file_name_1);
  230. status = fx_unicode_file_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
  231. return_value_if_fail(status == FX_INVALID_NAME, 27);
  232. status = fx_unicode_directory_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
  233. return_value_if_fail(status == FX_INVALID_NAME, 28);
  234. /* Test invalid new file name */
  235. old_length = fx_unicode_length_get(specified_unicode_file_name_2);
  236. new_length = fx_unicode_length_get(specified_unicode_file_name_1);
  237. new_length++;
  238. status = fx_unicode_file_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
  239. return_value_if_fail(status == FX_INVALID_NAME, 29);
  240. status = fx_unicode_directory_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
  241. return_value_if_fail(status == FX_INVALID_NAME, 30);
  242. old_length = fx_unicode_length_get(long_unicode_name1);
  243. new_length = fx_unicode_length_get(specified_unicode_file_name_2);
  244. status = fx_unicode_file_rename(&ram_disk, long_unicode_name1, old_length, specified_unicode_file_name_2, new_length, (CHAR *)destination_name);
  245. return_value_if_fail(status == FX_NOT_FOUND, 34);
  246. old_length = fx_unicode_length_get(long_unicode_name1);
  247. new_length = fx_unicode_length_get(specified_unicode_file_name_2);
  248. status = fx_unicode_directory_rename(&ram_disk, long_unicode_name1, old_length, specified_unicode_file_name_2, new_length, (CHAR *)destination_name);
  249. return_value_if_fail(status == FX_NOT_FOUND, 35);
  250. #endif
  251. status = fx_media_close(&ram_disk);
  252. return_value_if_fail(status == FX_SUCCESS, 36);
  253. /* Open the ram_disk in fx_ram_dirver_test.c. */
  254. temp_array[0] = large_file_name_format[(1736 - 852) * 16 + 3];
  255. temp_array[1] = large_file_name_format[(1736 - 852) * 16 + 4];
  256. /* Insert 00FF in a long file dir_entry. */
  257. large_file_name_format[(1736 - 852) * 16 + 3] = 0;
  258. large_file_name_format[(1736 - 852) * 16 + 4] = 0xFF;
  259. _fx_ram_driver_copy_default_format = 1;
  260. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  261. return_value_if_fail(status == FX_SUCCESS, 37);
  262. _fx_ram_driver_copy_default_format = 0;
  263. /* Revert all we done. */
  264. large_file_name_format[(1736 - 852) * 16 + 3] = temp_array[0];
  265. large_file_name_format[(1736 - 852) * 16 + 4] = temp_array[1];
  266. /* Attempt to access our directory. */
  267. length = fx_unicode_length_get(specified_ascii_file_name);
  268. status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
  269. return_value_if_fail(status == FX_SUCCESS, 38);
  270. status = fx_media_close( &ram_disk);
  271. return_if_fail( status == FX_SUCCESS);
  272. /* Format the media. This needs to be done before opening it! */
  273. status = fx_media_format(&ram_disk,
  274. _fx_ram_driver, // Driver entry
  275. ram_disk_memory_large, // RAM disk memory pointer
  276. cache_buffer, // Media buffer pointer
  277. 128, // Media buffer size
  278. "MY_RAM_DISK", // Volume Name
  279. 1, // Number of FATs
  280. 32, // Directory Entries
  281. 0, // Hidden sectors
  282. 70000, // Total sectors
  283. 128, // Sector size
  284. 1, // Sectors per cluster
  285. 1, // Heads
  286. 1); // Sectors per track
  287. return_if_fail( status == FX_SUCCESS);
  288. /* Backup the data which will be modified later. */
  289. temp_array[0] = large_file_name_format[(1734 - 852) * 16];
  290. temp_array[1] = large_file_name_format[(1734 - 852) * 16 + 11];
  291. /* Modfy the first dir_entry's ordinary number as 0x40 to make number of lfns be zero. */
  292. large_file_name_format[(1734 - 852) * 16] = 0x40;
  293. large_file_name_format[(1734 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
  294. _fx_ram_driver_copy_default_format = 1;
  295. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  296. _fx_ram_driver_copy_default_format = 0;
  297. /* Recover the disk. */
  298. large_file_name_format[(1734 - 852) * 16] = temp_array[0];
  299. large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
  300. /* Access root directory. */
  301. status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
  302. return_if_fail( status == FX_SUCCESS);
  303. status = fx_media_close( &ram_disk);
  304. return_if_fail( status == FX_SUCCESS);
  305. /* Format the media. This needs to be done before opening it! */
  306. status = fx_media_format(&ram_disk,
  307. _fx_ram_driver, // Driver entry
  308. ram_disk_memory_large, // RAM disk memory pointer
  309. cache_buffer, // Media buffer pointer
  310. 128, // Media buffer size
  311. "MY_RAM_DISK", // Volume Name
  312. 1, // Number of FATs
  313. 32, // Directory Entries
  314. 0, // Hidden sectors
  315. 70000, // Total sectors
  316. 128, // Sector size
  317. 1, // Sectors per cluster
  318. 1, // Heads
  319. 1); // Sectors per track
  320. return_if_fail( status == FX_SUCCESS);
  321. /* Backup the data which will be modified later. */
  322. temp_array[0] = large_file_name_format[(1734 - 852) * 16];
  323. temp_array[1] = large_file_name_format[(1734 - 852) * 16 + 11];
  324. temp_array[2] = large_file_name_format[(1736 - 852) * 16];
  325. temp_array[3] = large_file_name_format[(1736 - 852) * 16 + 11];
  326. /* Modfy the second dir_entry's ordinary number as 0x40 to make card number be zero. */
  327. large_file_name_format[(1734 - 852) * 16] = 0x42;
  328. large_file_name_format[(1734 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
  329. large_file_name_format[(1736 - 852) * 16] = 0x40;
  330. large_file_name_format[(1736 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
  331. /* Open the disk in fx_ram_driver_test.c */
  332. _fx_ram_driver_copy_default_format = 1;
  333. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  334. return_if_fail( status == FX_SUCCESS);
  335. _fx_ram_driver_copy_default_format = 0;
  336. /* Recover the disk. */
  337. large_file_name_format[(1734 - 852) * 16] = temp_array[0];
  338. large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
  339. large_file_name_format[(1736 - 852) * 16] = temp_array[2];
  340. large_file_name_format[(1736 - 852) * 16 + 11] = temp_array[3];
  341. /* Access root directory. */
  342. status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
  343. return_if_fail( status == FX_SUCCESS);
  344. status = fx_media_close( &ram_disk);
  345. return_if_fail( status == FX_SUCCESS);
  346. /* Format the media. This needs to be done before opening it! */
  347. status = fx_media_format(&ram_disk,
  348. _fx_ram_driver, // Driver entry
  349. ram_disk_memory_large, // RAM disk memory pointer
  350. cache_buffer, // Media buffer pointer
  351. 128, // Media buffer size
  352. "MY_RAM_DISK", // Volume Name
  353. 1, // Number of FATs
  354. 32, // Directory Entries
  355. 0, // Hidden sectors
  356. 70000, // Total sectors
  357. 128, // Sector size
  358. 1, // Sectors per cluster
  359. 1, // Heads
  360. 1); // Sectors per track
  361. return_if_fail( status == FX_SUCCESS);
  362. /* Backup the data which will be modified later. */
  363. temp_array[0] = large_file_name_format[(1736 - 852) * 16];
  364. temp_array[1] = large_file_name_format[(1736 - 852) * 16 + 11];
  365. temp_array[2] = large_file_name_format[(1738 - 852) * 16];
  366. temp_array[3] = large_file_name_format[(1738 - 852) * 16 + 11];
  367. /* Modfy the last two dir_entries in root directory, so we have to access the second sector of root directory. */
  368. large_file_name_format[(1736 - 852) * 16] = 0x43;
  369. large_file_name_format[(1736 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
  370. large_file_name_format[(1738 - 852) * 16] = 0x42;
  371. large_file_name_format[(1738 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
  372. /* Open the disk in fx_ram_driver_test.c */
  373. _fx_ram_driver_copy_default_format = 1;
  374. status += fx_media_open( &ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  375. return_if_fail( status == FX_SUCCESS);
  376. _fx_ram_driver_copy_default_format = 0;
  377. /* Recover the disk. */
  378. large_file_name_format[(1734 - 852) * 16] = temp_array[0];
  379. large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
  380. large_file_name_format[(1736 - 852) * 16] = temp_array[2];
  381. large_file_name_format[(1736 - 852) * 16 + 11] = temp_array[3];
  382. /* Access root directory, but set the size of root directory as zero to make a mistake. */
  383. ram_disk.fx_media_root_sectors = 0;
  384. status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
  385. return_if_fail( status == FX_FILE_CORRUPT);
  386. status = fx_media_close( &ram_disk);
  387. return_if_fail( status == FX_SUCCESS);
  388. status = fx_media_format(&ram_disk,
  389. _fx_ram_driver, // Driver entry
  390. ram_disk_memory_large, // RAM disk memory pointer
  391. cache_buffer, // Media buffer pointer
  392. 128, // Media buffer size
  393. "MY_RAM_DISK", // Volume Name
  394. 1, // Number of FATs
  395. 32, // Directory Entries
  396. 0, // Hidden sectors
  397. 70000, // Total sectors
  398. 128, // Sector size
  399. 1, // Sectors per cluster
  400. 1, // Heads
  401. 1); // Sectors per track
  402. status += fx_media_open( &ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  403. return_if_fail( status == FX_SUCCESS);
  404. status = fx_file_create( &ram_disk, "src");
  405. status += fx_file_open( &ram_disk, &my_file, "src", FX_OPEN_FOR_WRITE);
  406. status += fx_file_write( &my_file, "hello", 5);
  407. return_if_fail( status == FX_SUCCESS);
  408. /* IO error in fx_utility_FAT_map_flush.c while calling fx_utility_logical_sector_read. */
  409. _fx_utility_logical_sector_read_error_request = 2;
  410. status = fx_media_close( &ram_disk);
  411. printf("SUCCESS!\n");
  412. test_control_return(0);
  413. }