filex_file_create_delete_test.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. /* This FileX test concentrates on the file create/delete operations. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_fault_tolerant.h"
  7. #include "fx_media.h"
  8. #include "fx_ram_driver_test.h"
  9. #include "fx_utility.h"
  10. #include <stdio.h>
  11. #define DEMO_STACK_SIZE 8192
  12. #define CACHE_SIZE 16*128
  13. #ifdef FX_ENABLE_FAULT_TOLERANT
  14. #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
  15. #else
  16. #define FAULT_TOLERANT_SIZE 0
  17. #endif
  18. /* Define the ThreadX and FileX object control blocks... */
  19. #ifndef FX_STANDALONE_ENABLE
  20. static TX_THREAD ftest_0;
  21. #endif
  22. static FX_MEDIA ram_disk;
  23. static FX_FILE file_1;
  24. static FX_FILE file_2;
  25. static FX_FILE file_3;
  26. static FX_FILE file_4;
  27. static FX_FILE file_5;
  28. static FX_FILE file_6;
  29. static FX_FILE file_7;
  30. /* Define the counters used in the test application... */
  31. #ifndef FX_STANDALONE_ENABLE
  32. static UCHAR *ram_disk_memory;
  33. static UCHAR *cache_buffer;
  34. static UCHAR *fault_tolerant_buffer;
  35. #else
  36. static UCHAR cache_buffer[CACHE_SIZE];
  37. static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
  38. #endif
  39. static UCHAR fat_buffer[128];
  40. static UCHAR name_buffer[FX_MAX_LONG_NAME_LEN+1];
  41. /* Define thread prototypes. */
  42. void filex_file_create_delete_application_define(void *first_unused_memory);
  43. static void ftest_0_entry(ULONG thread_input);
  44. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  45. void test_control_return(UINT status);
  46. /* Define what the initial system looks like. */
  47. #ifdef CTEST
  48. void test_application_define(void *first_unused_memory)
  49. #else
  50. void filex_file_create_delete_application_define(void *first_unused_memory)
  51. #endif
  52. {
  53. #ifndef FX_STANDALONE_ENABLE
  54. UCHAR *pointer;
  55. /* Setup the working pointer. */
  56. pointer = (UCHAR *) first_unused_memory;
  57. /* Create the main thread. */
  58. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  59. pointer, DEMO_STACK_SIZE,
  60. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  61. pointer = pointer + DEMO_STACK_SIZE;
  62. /* Setup memory for the RAM disk and the sector cache. */
  63. cache_buffer = pointer;
  64. pointer = pointer + CACHE_SIZE;
  65. fault_tolerant_buffer = pointer;
  66. pointer += FAULT_TOLERANT_SIZE;
  67. ram_disk_memory = pointer;
  68. #endif
  69. /* Initialize the FileX system. */
  70. fx_system_initialize();
  71. #ifdef FX_STANDALONE_ENABLE
  72. ftest_0_entry(0);
  73. #endif
  74. }
  75. /* Define the test threads. */
  76. static void ftest_0_entry(ULONG thread_input)
  77. {
  78. UINT status;
  79. UCHAR buffer[30];
  80. ULONG actual;
  81. ULONG64 actual64;
  82. UINT i;
  83. ULONG64 temp;
  84. UINT temp_attr;
  85. FX_PARAMETER_NOT_USED(thread_input);
  86. /* Print out some test information banners. */
  87. printf("FileX Test: File create/delete test................................");
  88. /* Format the media. This needs to be done before opening it! */
  89. status = fx_media_format(&ram_disk,
  90. _fx_ram_driver, // Driver entry
  91. ram_disk_memory, // RAM disk memory pointer
  92. cache_buffer, // Media buffer pointer
  93. CACHE_SIZE, // Media buffer size
  94. "MY_RAM_DISK", // Volume Name
  95. 1, // Number of FATs
  96. 32, // Directory Entries
  97. 0, // Hidden sectors
  98. 512, // Total sectors
  99. 256, // Sector size
  100. 8, // Sectors per cluster
  101. 1, // Heads
  102. 1); // Sectors per track
  103. return_if_fail( status == FX_SUCCESS);
  104. /* Attempt to invalidate the media cache before the media is opened to generate an error */
  105. status = fx_media_cache_invalidate(&ram_disk);
  106. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  107. /* Attempt to get space available information before the media is opened to generate an error */
  108. status = fx_media_extended_space_available(&ram_disk, &temp);
  109. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  110. /* Attempt to allocate space before the media is opened to generate an error */
  111. status = fx_file_extended_allocate(&file_1, 0);
  112. return_if_fail( status == FX_NOT_OPEN);
  113. /* Attempt to allocate space before the media is opened to generate an error */
  114. status = fx_file_extended_best_effort_allocate(&file_1, 0, &temp);
  115. return_if_fail( status == FX_NOT_OPEN);
  116. /* try to create a file before the media has been opened to generate an error */
  117. status = fx_file_create(&ram_disk, "asdf");
  118. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  119. /* try to close a file before the file has been opened to generate an error */
  120. status = fx_file_close(&file_1);
  121. return_if_fail( status == FX_NOT_OPEN);
  122. /* try to delete a file before the media has been opened to generate an error */
  123. status = fx_file_delete(&ram_disk, "asdf");
  124. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  125. /* this will be caught by _fxe_file_open instead of _fx_file_open if DISABLE_ERROR_CHECKING is not defined */
  126. /* Attempt to open a file before the media has been opened to generate an error */
  127. status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_WRITE);
  128. return_if_fail( (status == FX_MEDIA_NOT_OPEN) || (status == FX_PTR_ERROR));
  129. /* Open the ram_disk. */
  130. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  131. return_if_fail( status == FX_SUCCESS);
  132. #ifdef FX_ENABLE_FAULT_TOLERANT
  133. /* Enable fault tolerant if FX_ENABLE_FAULT_TOLERANT is defined. */
  134. status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
  135. return_if_fail( status == FX_SUCCESS);
  136. #endif
  137. /* try to create a file with an illegal name to generate an error */
  138. status = fx_file_create(&ram_disk, "");
  139. return_if_fail( status == FX_INVALID_NAME);
  140. /* try to create a file with an illegal path to generate an error */
  141. status = fx_file_create(&ram_disk, "/subdir/root");
  142. return_if_fail( status == FX_INVALID_PATH);
  143. /* Simple 8.3 rename in the root directory. */
  144. status = fx_directory_create(&ram_disk, "subdir");
  145. status += fx_file_create(&ram_disk, "rootname");
  146. status += fx_file_create(&ram_disk, "rootname1");
  147. status += fx_file_create(&ram_disk, "rootname2");
  148. status += fx_file_create(&ram_disk, "/subdir/rootname");
  149. status += fx_file_create(&ram_disk, "/subdir/rootname1");
  150. return_if_fail( status == FX_SUCCESS);
  151. /* Attempt to open a file that is not a file to generate an error */
  152. status = fx_file_open(&ram_disk, &file_5, "subdir", FX_OPEN_FOR_WRITE);
  153. return_if_fail( status == FX_NOT_A_FILE);
  154. /* try to create and delete a file when the media is write protected to generate an error */
  155. ram_disk.fx_media_driver_write_protect = FX_TRUE;
  156. status = fx_file_create(&ram_disk, "asdf");
  157. return_if_fail( status == FX_WRITE_PROTECT);
  158. status = fx_file_delete(&ram_disk, "rootname");
  159. return_if_fail( status == FX_WRITE_PROTECT);
  160. /* Attempt to open a file while the media is write protected to generate an error */
  161. status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_WRITE);
  162. return_if_fail( status == FX_WRITE_PROTECT);
  163. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  164. /* Attempt to create the same file again. This should cause an error! */
  165. status = fx_file_create(&ram_disk, "rootname");
  166. return_if_fail( status == FX_ALREADY_CREATED);
  167. /* attempt to open a file with an invalid open type to generate an error */
  168. /* This code is executing differently on local vs server. Disabled until cause is explored
  169. status = fx_file_open(&ram_disk, &file_5, "rootname2", 3);
  170. return_if_fail( status == FX_ACCESS_ERROR);
  171. */
  172. /* try to delete a file in a directory that is read only */
  173. status = fx_file_attributes_read(&ram_disk, "rootname2", &temp_attr);
  174. status += fx_file_attributes_set(&ram_disk, "rootname2", FX_READ_ONLY);
  175. status += fx_file_delete(&ram_disk, "rootname2");
  176. status += fx_file_attributes_set(&ram_disk, "rootname2", temp_attr);
  177. return_if_fail( status == FX_WRITE_PROTECT);
  178. /* Open all the files. */
  179. status = fx_file_open(&ram_disk, &file_1, "rootname", FX_OPEN_FOR_WRITE);
  180. status += fx_file_open(&ram_disk, &file_2, "rootname1", FX_OPEN_FOR_WRITE);
  181. status += fx_file_open(&ram_disk, &file_3, "/subdir/rootname", FX_OPEN_FOR_WRITE);
  182. status += fx_file_open(&ram_disk, &file_4, "/subdir/rootname1", FX_OPEN_FOR_WRITE);
  183. status += fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_READ);
  184. return_if_fail( status == FX_SUCCESS);
  185. /* attempt to open a file that is already open */
  186. status = fx_file_open(&ram_disk, &file_6, "rootname", FX_OPEN_FOR_WRITE);
  187. return_if_fail( status == FX_ACCESS_ERROR);
  188. /* try to create and delete a file when the media is write protected to generate an error */
  189. ram_disk.fx_media_driver_write_protect = FX_TRUE;
  190. status = fx_file_create(&ram_disk, "asdf");
  191. return_if_fail( status == FX_WRITE_PROTECT);
  192. status = fx_file_delete(&ram_disk, "asdf");
  193. return_if_fail( status == FX_WRITE_PROTECT);
  194. /* Attempt to allocate space while the media is write protected to generate an error */
  195. status = fx_file_extended_allocate(&file_1, 1);
  196. return_if_fail( status == FX_WRITE_PROTECT);
  197. status = fx_file_extended_best_effort_allocate(&file_1, 1, &temp);
  198. return_if_fail( status == FX_WRITE_PROTECT);
  199. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  200. /* test the error checking */
  201. #ifndef FX_DISABLE_ERROR_CHECKING
  202. /* send a null pointer to generate an error */
  203. status = fx_media_extended_space_available(FX_NULL, FX_NULL);
  204. return_if_fail( status == FX_PTR_ERROR);
  205. /* send a null pointer to generate an error */
  206. status = fx_file_extended_best_effort_allocate(FX_NULL, 0, FX_NULL);
  207. /* send null pointer to generate an error */
  208. status = fx_file_create(FX_NULL, "rootname");
  209. return_if_fail( status == FX_PTR_ERROR);
  210. /* send null pointer to generate an error */
  211. status = fx_file_open(FX_NULL, FX_NULL, "rootname", 0);
  212. return_if_fail( status == FX_PTR_ERROR);
  213. /* attempt to open an already open file to generate an error */
  214. status = fx_file_open(&ram_disk, &file_1, "rootname", FX_OPEN_FOR_WRITE);
  215. return_if_fail( status == FX_PTR_ERROR);
  216. /* Attempt to allocate space for a file that is not open to write to generate an error */
  217. status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_READ);
  218. status = fx_file_extended_allocate(&file_5, 1);
  219. return_if_fail( status == FX_ACCESS_ERROR);
  220. /* Attempt to allocate space for a file that is not open to write to generate an error */
  221. status = fx_file_extended_best_effort_allocate(&file_5, 0, &temp);
  222. return_if_fail( status == FX_ACCESS_ERROR);
  223. /* Allocate 0 space for a file */
  224. status = fx_file_extended_allocate(&file_1, 0);
  225. return_if_fail( status == FX_SUCCESS);
  226. /* Allocate 0 space for a file */
  227. status = fx_file_extended_best_effort_allocate(&file_1, 0, &temp);
  228. return_if_fail( status == FX_SUCCESS);
  229. /* Attempt to allocate too much space for a file */
  230. status = fx_file_extended_allocate(&file_1, 0xFFFFFFFFFFFFFFFF);
  231. return_if_fail( status == FX_NO_MORE_SPACE);
  232. /* Corrupt the media. */
  233. ram_disk.fx_media_bytes_per_sector = 0;
  234. status = fx_file_extended_allocate(&file_1, 1);
  235. return_if_fail(status == FX_MEDIA_INVALID);
  236. status = fx_file_extended_best_effort_allocate(&file_1, 1, &actual64);
  237. return_if_fail(status == FX_MEDIA_INVALID);
  238. ram_disk.fx_media_bytes_per_sector = 256;
  239. #endif /* FX_DISABLE_ERROR_CHECKING */
  240. /* try to delete an open file to generate an error */
  241. status = fx_file_delete(&ram_disk, "rootname");
  242. return_if_fail( status == FX_ACCESS_ERROR);
  243. /* try to delete something that is not a file to generate an error */
  244. status = fx_file_delete(&ram_disk, "subdir");
  245. return_if_fail( status == FX_NOT_A_FILE);
  246. /* Now write a buffer to each file. */
  247. status = fx_file_write(&file_1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  248. status += fx_file_write(&file_2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  249. status += fx_file_write(&file_3, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  250. status += fx_file_write(&file_4, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  251. return_if_fail( status == FX_SUCCESS);
  252. /* Seek to the beginning of each file. */
  253. status += fx_file_seek(&file_1, 0);
  254. status += fx_file_seek(&file_2, 0);
  255. status += fx_file_seek(&file_3, 0);
  256. status += fx_file_seek(&file_4, 0);
  257. return_if_fail( status == FX_SUCCESS);
  258. /* Now read the buffer. */
  259. status = fx_file_read(&file_1, buffer, 30, &actual);
  260. return_if_fail( (status == FX_SUCCESS) && (actual == 26));
  261. /* Only run this if error checking is enabled */
  262. #ifndef FX_DISABLE_ERROR_CHECKING
  263. /* send null pointer to generate an error */
  264. status = fx_file_read(FX_NULL, buffer, 30, &actual);
  265. return_if_fail(status == FX_PTR_ERROR);
  266. #endif /* FX_DISABLE_ERROR_CHECKING */
  267. /* Now read the buffer. */
  268. status = fx_file_read(&file_2, buffer, 30, &actual);
  269. return_if_fail( (status == FX_SUCCESS) && (actual == 26));
  270. /* Now read the buffer. */
  271. status = fx_file_read(&file_3, buffer, 30, &actual);
  272. return_if_fail( (status == FX_SUCCESS) && (actual == 26));
  273. /* Now read the buffer. */
  274. status = fx_file_read(&file_4, buffer, 30, &actual);
  275. return_if_fail( (status == FX_SUCCESS) && (actual == 26));
  276. /* Close all files. */
  277. status = fx_file_close(&file_1);
  278. status += fx_file_close(&file_2);
  279. status += fx_file_close(&file_3);
  280. status += fx_file_close(&file_4);
  281. status += fx_file_close(&file_5);
  282. return_if_fail( status == FX_SUCCESS);
  283. /* Only run this if error checking is enabled */
  284. #ifndef FX_DISABLE_ERROR_CHECKING
  285. /* send null pointer to generate an error */
  286. status = fx_file_close(FX_NULL);
  287. return_if_fail(status == FX_PTR_ERROR);
  288. /* send null pointer to generate an error */
  289. status = fx_file_delete(FX_NULL, "rootname");
  290. return_if_fail(status == FX_PTR_ERROR);
  291. #endif /* FX_DISABLE_ERROR_CHECKING */
  292. /* Delete all files. */
  293. status = fx_file_delete(&ram_disk, "rootname");
  294. status += fx_file_delete(&ram_disk, "rootname1");
  295. status += fx_file_delete(&ram_disk, "/subdir/rootname");
  296. status += fx_file_delete(&ram_disk, "/subdir/rootname1");
  297. status += fx_file_delete(&ram_disk, "rootname2");
  298. status += fx_directory_delete(&ram_disk, "/subdir");
  299. return_if_fail( status == FX_SUCCESS);
  300. /* Attempt to delete an already deleted file. */
  301. status += fx_file_delete(&ram_disk, "rootname");
  302. return_if_fail( status == FX_NOT_FOUND);
  303. /* Close the media. */
  304. status = fx_media_close(&ram_disk);
  305. return_if_fail( status == FX_SUCCESS);
  306. /* Test corner cases in extended best effort allocate. */
  307. /* Format the media. This needs to be done before opening it! */
  308. status = fx_media_format(&ram_disk,
  309. _fx_ram_driver, // Driver entry
  310. ram_disk_memory, // RAM disk memory pointer
  311. cache_buffer, // Media buffer pointer
  312. CACHE_SIZE, // Media buffer size
  313. "MY_RAM_DISK", // Volume Name
  314. 1, // Number of FATs
  315. 32, // Directory Entries
  316. 0, // Hidden sectors
  317. 7000, // Total sectors - FAT 16
  318. 128, // Sector size
  319. 1, // Sectors per cluster
  320. 1, // Heads
  321. 1); // Sectors per track
  322. return_if_fail( status == FX_SUCCESS);
  323. /* Open the ram_disk. */
  324. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  325. return_if_fail( status == FX_SUCCESS);
  326. /* Create a file. */
  327. status = fx_file_create(&ram_disk, "TEST.TXT");
  328. /* Create a secondary file. */
  329. status += fx_file_create(&ram_disk, "TEST1.TXT");
  330. return_if_fail( status == FX_SUCCESS);
  331. /* Open the file. */
  332. status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
  333. status += fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  334. return_if_fail( status == FX_SUCCESS);
  335. /* Write one cluster of information to the TEST1.TXT file. */
  336. status = fx_file_write(&file_5, buffer, 128);
  337. /* Close the secondary file. */
  338. status += fx_file_close(&file_5);
  339. /* Loop to take up the entire ram disk by writing to this file. */
  340. while (ram_disk.fx_media_available_clusters)
  341. {
  342. /* Write a one cluster block. */
  343. status += fx_file_write(&file_6, buffer, 128);
  344. }
  345. return_if_fail( status == FX_SUCCESS);
  346. /* Attempt to allocate when there is nothing available. */
  347. status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
  348. return_if_fail( status == FX_NO_MORE_SPACE);
  349. /* Now release the first cluster to create a hole at the front. */
  350. status = fx_file_delete(&ram_disk, "TEST1.TXT");
  351. /* Now flush everything out. */
  352. fx_media_flush(&ram_disk);
  353. _fx_utility_FAT_flush(&ram_disk);
  354. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  355. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  356. {
  357. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  358. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  359. }
  360. /* Read the first FAT sector. */
  361. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  362. /* Add a FAT entry randomly in the FAT table. */
  363. fat_buffer[4] = 0x03;
  364. fat_buffer[5] = 0x00;
  365. /* Write the FAT corruption out. */
  366. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  367. return_if_fail( status == FX_SUCCESS);
  368. /* Attempt to allocate when there is nothing available - with a lost cluster. */
  369. status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
  370. return_if_fail( status == FX_NO_MORE_SPACE);
  371. /* Attempt to allocate when there is an I/O error. */
  372. _fx_utility_fat_entry_read_error_request = 1;
  373. status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
  374. _fx_utility_fat_entry_read_error_request = 0;
  375. return_if_fail( status == FX_IO_ERROR);
  376. /* Now flush everything out. */
  377. fx_media_flush(&ram_disk);
  378. _fx_utility_FAT_flush(&ram_disk);
  379. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  380. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  381. {
  382. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  383. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  384. }
  385. /* Read the first FAT sector. */
  386. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  387. /* Make the first entry available. */
  388. fat_buffer[4] = 0x00;
  389. fat_buffer[5] = 0x00;
  390. /* Write the FAT corruption out. */
  391. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  392. return_if_fail( status == FX_SUCCESS);
  393. /* Allocate with an exact fit. */
  394. status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
  395. return_if_fail( status == FX_SUCCESS);
  396. /* Release all the clusters for this file. */
  397. status = fx_file_extended_truncate_release(&file_6, 0);
  398. status += fx_file_write(&file_6, fat_buffer, 128);
  399. status += fx_file_write(&file_6, fat_buffer, 128);
  400. status += fx_file_write(&file_6, fat_buffer, 128);
  401. status += fx_file_write(&file_6, fat_buffer, 128);
  402. /* Allocate 4 clusters. */
  403. status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  404. return_if_fail( status == FX_SUCCESS);
  405. /* Release all the clusters for this file. */
  406. status = fx_file_extended_truncate_release(&file_6, 0);
  407. /* Allocate 4 clusters with no clusters in the file. */
  408. status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  409. return_if_fail( status == FX_SUCCESS);
  410. /* Write 512 bytes of data out. */
  411. status += fx_file_write(&file_6, fat_buffer, 128);
  412. status += fx_file_write(&file_6, fat_buffer, 128);
  413. status += fx_file_write(&file_6, fat_buffer, 128);
  414. status += fx_file_write(&file_6, fat_buffer, 128);
  415. /* Now allocate perform allocations with I/O errors on building the new FAT chain. */
  416. _fx_utility_fat_entry_write_error_request = 1;
  417. status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  418. _fx_utility_fat_entry_write_error_request = 0;
  419. return_if_fail( status == FX_IO_ERROR);
  420. /* Now allocate perform allocations with I/O error on writing the EOF. */
  421. _fx_utility_fat_entry_write_error_request = 4;
  422. status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  423. _fx_utility_fat_entry_write_error_request = 0;
  424. return_if_fail( status == FX_IO_ERROR);
  425. /* Now allocate perform allocations with I/O error on linking to last cluster. */
  426. _fx_utility_fat_entry_write_error_request = 5;
  427. status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  428. _fx_utility_fat_entry_write_error_request = 0;
  429. return_if_fail( status == FX_IO_ERROR);
  430. /* Release all the clusters for this file. */
  431. status = fx_file_extended_truncate_release(&file_6, 0);
  432. /* Now flush everything out. */
  433. fx_media_flush(&ram_disk);
  434. _fx_utility_FAT_flush(&ram_disk);
  435. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  436. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  437. {
  438. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  439. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  440. }
  441. #ifndef FX_ENABLE_FAULT_TOLERANT
  442. /* Now allocate perform allocations with I/O error on the directory write request. */
  443. _fx_utility_logical_sector_write_error_request = 1;
  444. status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
  445. _fx_utility_logical_sector_write_error_request = 0;
  446. return_if_fail( status == FX_IO_ERROR);
  447. #endif
  448. /* Close the file and the media. */
  449. status = fx_file_close(&file_6);
  450. status += fx_media_close(&ram_disk);
  451. return_if_fail( status == FX_SUCCESS);
  452. /* Format the media. This needs to be done before opening it! */
  453. status = fx_media_format(&ram_disk,
  454. _fx_ram_driver, // Driver entry
  455. ram_disk_memory, // RAM disk memory pointer
  456. cache_buffer, // Media buffer pointer
  457. CACHE_SIZE, // Media buffer size
  458. "MY_RAM_DISK", // Volume Name
  459. 1, // Number of FATs
  460. 32, // Directory Entries
  461. 0, // Hidden sectors
  462. 21000, // Total sectors - FAT 16
  463. 128, // Sector size
  464. 3, // Sectors per cluster
  465. 1, // Heads
  466. 1); // Sectors per track
  467. return_if_fail( status == FX_SUCCESS);
  468. /* Open the ram_disk. */
  469. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  470. return_if_fail( status == FX_SUCCESS);
  471. /* Create a file. */
  472. status = fx_file_create(&ram_disk, "TEST.TXT");
  473. return_if_fail( status == FX_SUCCESS);
  474. /* Open the file. */
  475. status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
  476. return_if_fail( status == FX_SUCCESS);
  477. /* Write data to the TEST.TXT file. */
  478. status = fx_file_write(&file_6, buffer, 128);
  479. status += fx_file_write(&file_6, buffer, 128);
  480. status += fx_file_write(&file_6, buffer, 64);
  481. /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
  482. status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  483. return_if_fail( status == FX_SUCCESS);
  484. /* Truncate the file. */
  485. status = fx_file_extended_truncate_release(&file_6, 0);
  486. /* Write data to the TEST.TXT file. */
  487. status += fx_file_write(&file_6, buffer, 128);
  488. /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
  489. status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  490. return_if_fail( status == FX_SUCCESS);
  491. /* Close the file and the media. */
  492. status = fx_file_close(&file_6);
  493. status += fx_media_close(&ram_disk);
  494. return_if_fail( status == FX_SUCCESS);
  495. /* Test corner cases in extended allocate. */
  496. /* Format the media. This needs to be done before opening it! */
  497. status = fx_media_format(&ram_disk,
  498. _fx_ram_driver, // Driver entry
  499. ram_disk_memory, // RAM disk memory pointer
  500. cache_buffer, // Media buffer pointer
  501. CACHE_SIZE, // Media buffer size
  502. "MY_RAM_DISK", // Volume Name
  503. 1, // Number of FATs
  504. 32, // Directory Entries
  505. 0, // Hidden sectors
  506. 7000, // Total sectors - FAT 16
  507. 128, // Sector size
  508. 1, // Sectors per cluster
  509. 1, // Heads
  510. 1); // Sectors per track
  511. return_if_fail( status == FX_SUCCESS);
  512. /* Open the ram_disk. */
  513. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  514. return_if_fail( status == FX_SUCCESS);
  515. /* Create a file. */
  516. status = fx_file_create(&ram_disk, "TEST.TXT");
  517. /* Create a secondary file. */
  518. status += fx_file_create(&ram_disk, "TEST1.TXT");
  519. return_if_fail( status == FX_SUCCESS);
  520. /* Open the file. */
  521. status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
  522. status = fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  523. return_if_fail( status == FX_SUCCESS);
  524. /* Write one cluster of information to the TEST1.TXT file. */
  525. status = fx_file_write(&file_5, buffer, 128);
  526. /* Close the secondary file. */
  527. status += fx_file_close(&file_5);
  528. /* Loop to take up the entire ram disk by writing to this file. */
  529. while (ram_disk.fx_media_available_clusters)
  530. {
  531. /* Write a one cluster block. */
  532. status += fx_file_write(&file_6, buffer, 128);
  533. }
  534. return_if_fail( status == FX_SUCCESS);
  535. /* Attempt to allocate when there is nothing available. */
  536. status = fx_file_extended_allocate(&file_6, 128);
  537. return_if_fail( status == FX_NO_MORE_SPACE);
  538. /* Now release the first cluster to create a hole at the front. */
  539. status = fx_file_delete(&ram_disk, "TEST1.TXT");
  540. /* Now flush everything out. */
  541. fx_media_flush(&ram_disk);
  542. _fx_utility_FAT_flush(&ram_disk);
  543. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  544. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  545. {
  546. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  547. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  548. }
  549. /* Read the first FAT sector. */
  550. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  551. /* Add a FAT entry randomly in the FAT table. */
  552. fat_buffer[4] = 0x03;
  553. fat_buffer[5] = 0x00;
  554. /* Write the FAT corruption out. */
  555. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  556. return_if_fail( status == FX_SUCCESS);
  557. /* Attempt to allocate when there is nothing available - with a lost cluster. */
  558. status = fx_file_extended_allocate(&file_6, 128);
  559. return_if_fail( status == FX_NO_MORE_SPACE);
  560. /* Attempt to allocate when there is an I/O error. */
  561. _fx_utility_fat_entry_read_error_request = 1;
  562. status = fx_file_extended_allocate(&file_6, 128);
  563. _fx_utility_fat_entry_read_error_request = 0;
  564. return_if_fail( status == FX_IO_ERROR);
  565. /* Now flush everything out. */
  566. fx_media_flush(&ram_disk);
  567. _fx_utility_FAT_flush(&ram_disk);
  568. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  569. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  570. {
  571. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  572. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  573. }
  574. /* Read the first FAT sector. */
  575. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  576. /* Make the first entry available. */
  577. fat_buffer[4] = 0x00;
  578. fat_buffer[5] = 0x00;
  579. /* Write the FAT corruption out. */
  580. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  581. return_if_fail( status == FX_SUCCESS);
  582. /* Allocate with an exact fit. */
  583. status = fx_file_extended_allocate(&file_6, 128);
  584. return_if_fail( status == FX_SUCCESS);
  585. /* Release all the clusters for this file. */
  586. status = fx_file_extended_truncate_release(&file_6, 0);
  587. status += fx_file_write(&file_6, fat_buffer, 128);
  588. status += fx_file_write(&file_6, fat_buffer, 128);
  589. status += fx_file_write(&file_6, fat_buffer, 128);
  590. status += fx_file_write(&file_6, fat_buffer, 128);
  591. /* Allocate 4 clusters. */
  592. status += fx_file_extended_allocate(&file_6, 512);
  593. return_if_fail( status == FX_SUCCESS);
  594. /* Release all the clusters for this file. */
  595. status = fx_file_extended_truncate_release(&file_6, 0);
  596. /* Allocate 4 clusters with no clusters in the file. */
  597. status += fx_file_extended_allocate(&file_6, 512);
  598. return_if_fail( status == FX_SUCCESS);
  599. /* Write 512 bytes of data out. */
  600. status += fx_file_write(&file_6, fat_buffer, 128);
  601. status += fx_file_write(&file_6, fat_buffer, 128);
  602. status += fx_file_write(&file_6, fat_buffer, 128);
  603. status += fx_file_write(&file_6, fat_buffer, 128);
  604. /* Now allocate perform allocations with I/O errors on building the new FAT chain. */
  605. _fx_utility_fat_entry_write_error_request = 1;
  606. status += fx_file_extended_allocate(&file_6, 512);
  607. _fx_utility_fat_entry_write_error_request = 0;
  608. return_if_fail( status == FX_IO_ERROR);
  609. /* Now allocate perform allocations with I/O error on writing the EOF. */
  610. _fx_utility_fat_entry_write_error_request = 4;
  611. status = fx_file_extended_allocate(&file_6, 512);
  612. _fx_utility_fat_entry_write_error_request = 0;
  613. return_if_fail( status == FX_IO_ERROR);
  614. /* Now allocate perform allocations with I/O error on linking to last cluster. */
  615. _fx_utility_fat_entry_write_error_request = 5;
  616. status = fx_file_extended_allocate(&file_6, 512);
  617. _fx_utility_fat_entry_write_error_request = 0;
  618. return_if_fail( status == FX_IO_ERROR);
  619. /* Release all the clusters for this file. */
  620. status = fx_file_extended_truncate_release(&file_6, 0);
  621. /* Now flush everything out. */
  622. fx_media_flush(&ram_disk);
  623. _fx_utility_FAT_flush(&ram_disk);
  624. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  625. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  626. {
  627. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  628. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  629. }
  630. #ifndef FX_ENABLE_FAULT_TOLERANT
  631. /* Now allocate perform allocations with I/O error on the directory write request. */
  632. _fx_utility_logical_sector_write_error_request = 1;
  633. status = fx_file_extended_allocate(&file_6, 128);
  634. _fx_utility_logical_sector_write_error_request = 0;
  635. return_if_fail( status == FX_IO_ERROR);
  636. #endif
  637. /* Close the file and the media. */
  638. status = fx_file_close(&file_6);
  639. status += fx_media_close(&ram_disk);
  640. return_if_fail( status == FX_SUCCESS);
  641. /* Format the media. This needs to be done before opening it! */
  642. status = fx_media_format(&ram_disk,
  643. _fx_ram_driver, // Driver entry
  644. ram_disk_memory, // RAM disk memory pointer
  645. cache_buffer, // Media buffer pointer
  646. CACHE_SIZE, // Media buffer size
  647. "MY_RAM_DISK", // Volume Name
  648. 1, // Number of FATs
  649. 32, // Directory Entries
  650. 0, // Hidden sectors
  651. 21000, // Total sectors - FAT 16
  652. 128, // Sector size
  653. 3, // Sectors per cluster
  654. 1, // Heads
  655. 1); // Sectors per track
  656. return_if_fail( status == FX_SUCCESS);
  657. /* Open the ram_disk. */
  658. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  659. return_if_fail( status == FX_SUCCESS);
  660. /* Create a file. */
  661. status = fx_file_create(&ram_disk, "TEST.TXT");
  662. return_if_fail( status == FX_SUCCESS);
  663. /* Open the file. */
  664. status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
  665. return_if_fail( status == FX_SUCCESS);
  666. /* Write one cluster of information to the TEST1.TXT file. */
  667. status = fx_file_write(&file_6, buffer, 128);
  668. status += fx_file_write(&file_6, buffer, 128);
  669. status += fx_file_write(&file_6, buffer, 64);
  670. /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
  671. status = fx_file_extended_allocate(&file_6, 512);
  672. return_if_fail( status == FX_SUCCESS);
  673. /* Truncate the file. */
  674. status = fx_file_extended_truncate_release(&file_6, 0);
  675. /* Write data to the TEST.TXT file. */
  676. status += fx_file_write(&file_6, buffer, 128);
  677. /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
  678. status += fx_file_extended_allocate(&file_6, 512);
  679. return_if_fail( status == FX_SUCCESS);
  680. /* Now test the maximum allocate size. */
  681. actual64 = file_6.fx_file_current_available_size;
  682. file_6.fx_file_current_available_size = 0xFFFFFFF8;
  683. /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
  684. status = fx_file_extended_allocate(&file_6, 512);
  685. file_6.fx_file_current_available_size = actual64;
  686. return_if_fail( status == FX_NO_MORE_SPACE);
  687. /* Now test the maximum allocate size. */
  688. actual64 = file_6.fx_file_current_available_size;
  689. file_6.fx_file_current_available_size = 0xFFFFFFFFFFFFFFF8;
  690. /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
  691. status = fx_file_extended_allocate(&file_6, 512);
  692. file_6.fx_file_current_available_size = actual64;
  693. return_if_fail( status == FX_NO_MORE_SPACE);
  694. /* Now test the maximum allocate size. */
  695. actual64 = file_6.fx_file_current_available_size;
  696. file_6.fx_file_current_available_size = 0xFFFFFFF8;
  697. /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
  698. status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  699. file_6.fx_file_current_available_size = actual64;
  700. return_if_fail( status == FX_NO_MORE_SPACE);
  701. /* Now test the maximum allocate size. */
  702. actual64 = file_6.fx_file_current_available_size;
  703. file_6.fx_file_current_available_size = 0xFFFFFFFFFFFFFFF8;
  704. /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
  705. status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
  706. file_6.fx_file_current_available_size = actual64;
  707. return_if_fail( status == FX_NO_MORE_SPACE);
  708. /* Now test a maximium size allocation. */
  709. status = fx_file_extended_best_effort_allocate(&file_6, 0xFFFFFFFFFFFFFFF8ULL, &actual64);
  710. return_if_fail( status == FX_NO_MORE_SPACE);
  711. /* Close the file and the media. */
  712. status = fx_file_close(&file_6);
  713. status += fx_media_close(&ram_disk);
  714. return_if_fail( status == FX_SUCCESS);
  715. /* Check the corner cases of file delete. */
  716. /* Format the media. This needs to be done before opening it! */
  717. status = fx_media_format(&ram_disk,
  718. _fx_ram_driver, // Driver entry
  719. ram_disk_memory, // RAM disk memory pointer
  720. cache_buffer, // Media buffer pointer
  721. CACHE_SIZE, // Media buffer size
  722. "MY_RAM_DISK", // Volume Name
  723. 1, // Number of FATs
  724. 32, // Directory Entries
  725. 0, // Hidden sectors
  726. 7000, // Total sectors - FAT 16
  727. 128, // Sector size
  728. 1, // Sectors per cluster
  729. 1, // Heads
  730. 1); // Sectors per track
  731. return_if_fail( status == FX_SUCCESS);
  732. /* Open the ram_disk. */
  733. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  734. return_if_fail( status == FX_SUCCESS);
  735. /* Create a set of files. */
  736. status = fx_file_create(&ram_disk, "TEST.TXT");
  737. status += fx_file_create(&ram_disk, "TEST1.TXT");
  738. status += fx_file_create(&ram_disk, "TEST2.TXT");
  739. status += fx_file_create(&ram_disk, "TEST3.TXT");
  740. status += fx_file_create(&ram_disk, "TEST4.TXT");
  741. status += fx_file_create(&ram_disk, "TEST5.TXT");
  742. status += fx_file_create(&ram_disk, "TEST6.TXT");
  743. status += fx_file_create(&ram_disk, "TEST7.TXT");
  744. status += fx_file_create(&ram_disk, "TEST8.TXT");
  745. status += fx_file_create(&ram_disk, "TEST9.TXT");
  746. status += fx_file_create(&ram_disk, "TEST10.TXT");
  747. status += fx_file_create(&ram_disk, "TEST11.TXT");
  748. status += fx_file_create(&ram_disk, "TEST12.TXT");
  749. status += fx_file_create(&ram_disk, "TEST13.TXT");
  750. status += fx_file_create(&ram_disk, "TEST14.TXT");
  751. status += fx_file_create(&ram_disk, "TEST15.TXT");
  752. status += fx_file_create(&ram_disk, "TEST16.TXT");
  753. status += fx_file_create(&ram_disk, "TEST17.TXT");
  754. status += fx_file_create(&ram_disk, "TEST18.TXT");
  755. status += fx_file_create(&ram_disk, "TEST19.TXT");
  756. status += fx_file_create(&ram_disk, "TEST20.TXT");
  757. status += fx_file_create(&ram_disk, "TEST21.TXT");
  758. status += fx_file_create(&ram_disk, "TEST22.TXT");
  759. status += fx_file_create(&ram_disk, "TEST23.TXT");
  760. status += fx_file_create(&ram_disk, "TEST24.TXT");
  761. status += fx_file_create(&ram_disk, "TEST25.TXT");
  762. status += fx_file_create(&ram_disk, "TEST26.TXT");
  763. status += fx_file_create(&ram_disk, "TEST27.TXT");
  764. status += fx_file_create(&ram_disk, "TEST28.TXT");
  765. status += fx_file_create(&ram_disk, "TEST29.TXT");
  766. status += fx_file_create(&ram_disk, "TEST30.TXT");
  767. return_if_fail( status == FX_SUCCESS);
  768. /* Open a couple files.... */
  769. status = fx_file_open(&ram_disk, &file_4, "TEST.TXT", FX_OPEN_FOR_WRITE);
  770. status = fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  771. status += fx_file_open(&ram_disk, &file_6, "TEST30.TXT", FX_OPEN_FOR_WRITE);
  772. status += fx_file_open(&ram_disk, &file_7, "TEST29.TXT", FX_OPEN_FOR_WRITE);
  773. status += fx_file_write(&file_4, fat_buffer, 128);
  774. status += fx_file_write(&file_4, fat_buffer, 128);
  775. status += fx_file_write(&file_4, fat_buffer, 128);
  776. status += fx_file_write(&file_4, fat_buffer, 128);
  777. status += fx_file_write(&file_5, fat_buffer, 128);
  778. status += fx_file_write(&file_5, fat_buffer, 128);
  779. status += fx_file_write(&file_5, fat_buffer, 128);
  780. status += fx_file_write(&file_5, fat_buffer, 128);
  781. status += fx_file_write(&file_6, fat_buffer, 128);
  782. status += fx_file_write(&file_6, fat_buffer, 128);
  783. status += fx_file_write(&file_6, fat_buffer, 128);
  784. status += fx_file_write(&file_6, fat_buffer, 128);
  785. status += fx_file_write(&file_7, fat_buffer, 128);
  786. status += fx_file_write(&file_7, fat_buffer, 128);
  787. status += fx_file_write(&file_7, fat_buffer, 128);
  788. status += fx_file_write(&file_7, fat_buffer, 128);
  789. return_if_fail( status == FX_SUCCESS);
  790. /* Now flush everything out. */
  791. fx_media_flush(&ram_disk);
  792. _fx_utility_FAT_flush(&ram_disk);
  793. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  794. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  795. {
  796. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  797. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  798. }
  799. /* Close TEST.TXT. */
  800. status = fx_file_close(&file_4);
  801. /* Attempt to delete the file, but with open files on a different offset/sector and a write I/O error. */
  802. _fx_utility_logical_sector_read_error_request = 2;
  803. status += fx_file_delete(&ram_disk, "TEST.TXT");
  804. _fx_utility_logical_sector_read_error_request = 0;
  805. return_if_fail( status == FX_IO_ERROR);
  806. /* Close all the open files. */
  807. status = fx_file_close(&file_5);
  808. status += fx_file_close(&file_6);
  809. status += fx_file_close(&file_7);
  810. /* Now flush everything out. */
  811. fx_media_flush(&ram_disk);
  812. _fx_utility_FAT_flush(&ram_disk);
  813. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  814. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  815. {
  816. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  817. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  818. }
  819. /* Attempt to delete the file, but with a FAT read error. */
  820. _fx_utility_fat_entry_read_error_request = 1;
  821. status += fx_file_delete(&ram_disk, "TEST1.TXT");
  822. _fx_utility_fat_entry_read_error_request = 0;
  823. return_if_fail( status == FX_IO_ERROR);
  824. /* Now flush everything out. */
  825. fx_media_flush(&ram_disk);
  826. _fx_utility_FAT_flush(&ram_disk);
  827. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  828. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  829. {
  830. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  831. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  832. }
  833. /* Attempt to delete the file, but with a FAT write error. */
  834. _fx_utility_fat_entry_write_error_request = 1;
  835. status = fx_file_delete(&ram_disk, "TEST30.TXT");
  836. _fx_utility_fat_entry_write_error_request = 0;
  837. return_if_fail( status == FX_IO_ERROR);
  838. /* Now flush everything out. */
  839. fx_media_flush(&ram_disk);
  840. _fx_utility_FAT_flush(&ram_disk);
  841. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  842. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  843. {
  844. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  845. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  846. }
  847. /* Read the first FAT sector. */
  848. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  849. /* Make the first entry available. */
  850. fat_buffer[4] = 0x02;
  851. fat_buffer[5] = 0x00;
  852. /* Write the FAT corruption out. */
  853. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  854. return_if_fail( status == FX_SUCCESS);
  855. /* Attempt to delete the file, but with a bad FAT chain. */
  856. status = fx_file_delete(&ram_disk, "TEST.TXT");
  857. return_if_fail( status == FX_FAT_READ_ERROR);
  858. /* Attempt to delete the file that exceeds the cluster clount (that we modify to be small). */
  859. actual = ram_disk.fx_media_total_clusters;
  860. ram_disk.fx_media_total_clusters = 1;
  861. status = fx_file_delete(&ram_disk, "TEST29.TXT");
  862. ram_disk.fx_media_total_clusters = actual;
  863. return_if_fail( status == FX_FAT_READ_ERROR);
  864. /* Build a long file name, exceeding FX_MAX_LONG_NAME_LEN. */
  865. for (i = 0; i < (FX_MAX_LONG_NAME_LEN+1); i++)
  866. {
  867. name_buffer[i] = 'a';
  868. }
  869. name_buffer[FX_MAX_LONG_NAME_LEN] = 0;
  870. /* Attempt to create a file with this extra long name... this is expected to fail. */
  871. status = fx_file_create(&ram_disk, (CHAR *)name_buffer);
  872. return_if_fail( status == FX_INVALID_NAME);
  873. /* Now open and write to a file so we can test file close I/O error condition. */
  874. status = fx_file_open(&ram_disk, &file_7, "TEST20.TXT", FX_OPEN_FOR_WRITE);
  875. status += fx_file_write(&file_7, fat_buffer, 128);
  876. /* Close the file with an I/O error. */
  877. _fx_utility_logical_sector_read_error_request = 1;
  878. status += fx_file_close(&file_7);
  879. _fx_utility_logical_sector_read_error_request = 0;
  880. return_if_fail( status == FX_IO_ERROR);
  881. /* Now call the best effort allocate with a closed file handle. */
  882. status = fx_file_best_effort_allocate(&file_7, 1, &actual);
  883. return_if_fail( status == FX_NOT_OPEN);
  884. /* Close the media. */
  885. status = fx_media_close(&ram_disk);
  886. return_if_fail( status == FX_SUCCESS);
  887. printf("SUCCESS!\n");
  888. test_control_return(0);
  889. }