filex_file_read_write_test.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586
  1. /* This FileX test concentrates on the file read/write operation. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.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. #define DEMO_STACK_SIZE 4096
  10. #define CACHE_SIZE 128*128
  11. /* Define the ThreadX and FileX object control blocks... */
  12. #ifndef FX_STANDALONE_ENABLE
  13. static TX_THREAD ftest_0;
  14. #endif
  15. static FX_MEDIA ram_disk;
  16. static FX_FILE my_file;
  17. static FX_FILE my_file1;
  18. static FX_FILE my_file2;
  19. static FX_FILE my_file3;
  20. static FX_FILE my_file4;
  21. static FX_FILE read_only;
  22. static ULONG my_buffer[128];
  23. static UCHAR fat_buffer[128];
  24. static UCHAR buffer[128*3];
  25. /* Define the counters used in the test application... */
  26. #ifndef FX_STANDALONE_ENABLE
  27. static UCHAR *ram_disk_memory;
  28. static UCHAR *cache_buffer;
  29. #else
  30. static UCHAR cache_buffer[CACHE_SIZE];
  31. #endif
  32. /* Define thread prototypes. */
  33. void filex_file_read_write_application_define(void *first_unused_memory);
  34. static void ftest_0_entry(ULONG thread_input);
  35. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  36. void test_control_return(UINT status);
  37. /* Define what the initial system looks like. */
  38. #ifdef CTEST
  39. void test_application_define(void *first_unused_memory)
  40. #else
  41. void filex_file_read_write_application_define(void *first_unused_memory)
  42. #endif
  43. {
  44. #ifndef FX_STANDALONE_ENABLE
  45. UCHAR *pointer;
  46. /* Setup the working pointer. */
  47. pointer = (UCHAR *) first_unused_memory;
  48. /* Create the main thread. */
  49. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  50. pointer, DEMO_STACK_SIZE,
  51. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  52. pointer = pointer + DEMO_STACK_SIZE;
  53. /* Setup memory for the RAM disk and the sector cache. */
  54. cache_buffer = pointer;
  55. pointer = pointer + CACHE_SIZE;
  56. ram_disk_memory = pointer;
  57. #endif
  58. /* Initialize the FileX system. */
  59. fx_system_initialize();
  60. #ifdef FX_STANDALONE_ENABLE
  61. ftest_0_entry(0);
  62. #endif
  63. }
  64. /* Define the test threads. */
  65. static void ftest_0_entry(ULONG thread_input)
  66. {
  67. UINT status;
  68. ULONG actual;
  69. ULONG actual1;
  70. ULONG actual2;
  71. ULONG temp;
  72. ULONG temp1;
  73. ULONG read_value;
  74. ULONG write_value;
  75. ULONG available_bytes;
  76. ULONG i, j;
  77. FX_PARAMETER_NOT_USED(thread_input);
  78. /* Print out some test information banners. */
  79. printf("FileX Test: File read/write test...................................");
  80. /* Format the media. This needs to be done before opening it! */
  81. status = fx_media_format(&ram_disk,
  82. _fx_ram_driver, // Driver entry
  83. ram_disk_memory, // RAM disk memory pointer
  84. cache_buffer, // Media buffer pointer
  85. CACHE_SIZE, // Media buffer size
  86. "MY_RAM_DISK", // Volume Name
  87. 1, // Number of FATs
  88. 32, // Directory Entries
  89. 0, // Hidden sectors
  90. 511, // Total sectors
  91. 128, // Sector size
  92. 1, // Sectors per cluster
  93. 1, // Heads
  94. 1); // Sectors per track
  95. /* Determine if the format had an error. */
  96. if (status)
  97. {
  98. printf("ERROR!\n");
  99. test_control_return(2);
  100. }
  101. /* Open the ram_disk. */
  102. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  103. /* Check the status. */
  104. if (status != FX_SUCCESS)
  105. {
  106. /* Error, return error code. */
  107. printf("ERROR!\n");
  108. test_control_return(21);
  109. }
  110. /* Create a file called TEST.TXT in the root directory. */
  111. status = fx_file_create(&ram_disk, "TEST.TXT");
  112. status += fx_file_create(&ram_disk, "READ_ONLY.TXT");
  113. /* Check the create status. */
  114. if (status != FX_SUCCESS)
  115. {
  116. printf("ERROR!\n");
  117. test_control_return(3);
  118. }
  119. /* try to write to a file before it has been opened */
  120. status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
  121. if (status != FX_NOT_OPEN)
  122. {
  123. printf("ERROR!\n");
  124. test_control_return(23);
  125. }
  126. /* Open the test file. */
  127. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  128. status += fx_file_open(&ram_disk, &read_only, "READ_ONLY.TXT", FX_OPEN_FOR_READ);
  129. /* Check the file open status. */
  130. if (status != FX_SUCCESS)
  131. {
  132. printf("ERROR!\n");
  133. test_control_return(4);
  134. }
  135. /* try to write to a file while it is write protected */
  136. ram_disk.fx_media_driver_write_protect = FX_TRUE;
  137. status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
  138. if (status != FX_WRITE_PROTECT)
  139. {
  140. printf("ERROR!\n");
  141. test_control_return(23);
  142. }
  143. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  144. /* try to write to a file that is not opened for writing */
  145. status = fx_file_write(&read_only, (void *) &write_value, sizeof(ULONG));
  146. if (status != FX_ACCESS_ERROR)
  147. {
  148. printf("ERROR!\n");
  149. test_control_return(23);
  150. }
  151. ram_disk.fx_media_bytes_per_sector = 0;
  152. /* Try to write to a file when media is corrupted. */
  153. status = fx_file_write(&my_file, (void*)& write_value, sizeof(ULONG));
  154. if (status != FX_MEDIA_INVALID)
  155. {
  156. printf("ERROR!\n");
  157. test_control_return(23);
  158. }
  159. ram_disk.fx_media_bytes_per_sector = 128;
  160. /* Pickup the available bytes in the media. */
  161. status = fx_media_space_available(&ram_disk, &available_bytes);
  162. /* Check for available bytes error. */
  163. if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
  164. {
  165. printf("ERROR!\n");
  166. test_control_return(5);
  167. }
  168. /* Only run this if error checking is enabled */
  169. #ifndef FX_DISABLE_ERROR_CHECKING
  170. /* send null pointer to generate an error */
  171. status = fx_file_write(FX_NULL, (void *) &write_value, 0);
  172. if (status != FX_PTR_ERROR)
  173. {
  174. printf("ERROR!\n");
  175. test_control_return(11);
  176. }
  177. #endif /* FX_DISABLE_ERROR_CHECKING */
  178. /* Loop to write successive bytes out to the file.... to fill the media! */
  179. i = 0;
  180. write_value = 0;
  181. while (i < available_bytes)
  182. {
  183. /* Write 4 bytes to the file. */
  184. status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
  185. /* Check the file write status. */
  186. if (status != FX_SUCCESS)
  187. {
  188. printf("ERROR!\n");
  189. test_control_return(6);
  190. }
  191. /* Increment byte count. */
  192. i = i + sizeof(ULONG);
  193. /* Increment write value. */
  194. write_value++;
  195. }
  196. /* Pickup the available bytes in the media again. */
  197. status = fx_media_space_available(&ram_disk, &i);
  198. /* Check for available bytes error. */
  199. if ((status != FX_SUCCESS) || (i != 0))
  200. {
  201. printf("ERROR!\n");
  202. test_control_return(7);
  203. }
  204. #ifndef FX_DISABLE_CACHE
  205. /* At this point, we should invalidate the (which also flushes the cache) media to ensure that all
  206. dirty sectors are written. */
  207. status = fx_media_cache_invalidate(&ram_disk);
  208. /* Check for flush errors. */
  209. if ((status != FX_SUCCESS) || (ram_disk.fx_media_sector_cache_dirty_count))
  210. {
  211. printf("ERROR!\n");
  212. test_control_return(8);
  213. }
  214. /* See if any sectors are still valid in the cache. */
  215. for (i = 0; i < FX_MAX_SECTOR_CACHE; i++)
  216. {
  217. /* Determine if this cache entry is still valid. */
  218. if (ram_disk.fx_media_sector_cache[i].fx_cached_sector_valid)
  219. {
  220. printf("ERROR!\n");
  221. test_control_return(81);
  222. }
  223. }
  224. #endif
  225. /* Seek to the beginning of the test file. */
  226. status = fx_file_seek(&my_file, 0);
  227. /* Check the file seek status. */
  228. if (status != FX_SUCCESS)
  229. {
  230. printf("ERROR!\n");
  231. test_control_return(9);
  232. }
  233. /* Only run this if error checking is enabled */
  234. #ifndef FX_DISABLE_ERROR_CHECKING
  235. /* send null pointer to generate an error */
  236. status = fx_file_seek(FX_NULL, 0);
  237. if (status != FX_PTR_ERROR)
  238. {
  239. printf("ERROR!\n");
  240. test_control_return(11);
  241. }
  242. #endif /* FX_DISABLE_ERROR_CHECKING */
  243. /* Now read in all the bytes again to make sure the file contents are really there. */
  244. i = 0;
  245. read_value = 0;
  246. while (i < available_bytes)
  247. {
  248. /* Read 4 bytes from the file. */
  249. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  250. /* Check the file read status. */
  251. if ((status != FX_SUCCESS) || (actual != 4) || (read_value != i/4))
  252. {
  253. printf("ERROR!\n");
  254. test_control_return(10);
  255. }
  256. /* Increment byte count. */
  257. i = i + sizeof(ULONG);
  258. }
  259. /* Close the test file. */
  260. status = fx_file_close(&my_file);
  261. /* Check the file close status. */
  262. if (status != FX_SUCCESS)
  263. {
  264. printf("ERROR!\n");
  265. test_control_return(11);
  266. }
  267. /* Close the media. */
  268. status = fx_media_close(&ram_disk);
  269. /* Check the media close status. */
  270. if (status != FX_SUCCESS)
  271. {
  272. printf("ERROR!\n");
  273. test_control_return(12);
  274. }
  275. /* Reformat the media. This needs to be done before opening it! */
  276. status = fx_media_format(&ram_disk,
  277. _fx_ram_driver, // Driver entry
  278. ram_disk_memory, // RAM disk memory pointer
  279. cache_buffer, // Media buffer pointer
  280. CACHE_SIZE, // Media buffer size
  281. "MY_RAM_DISK", // Volume Name
  282. 1, // Number of FATs
  283. 32, // Directory Entries
  284. 0, // Hidden sectors
  285. 511, // Total sectors (ensure clusters divisible by 4)
  286. 128, // Sector size
  287. 1, // Sectors per cluster
  288. 1, // Heads
  289. 1); // Sectors per track
  290. /* Determine if the format had an error. */
  291. if (status)
  292. {
  293. printf("ERROR!\n");
  294. test_control_return(13);
  295. }
  296. /* Open the ram_disk, but do so to ensure non-hashed algorithm is used by supplying CACHE_SIZE-1. */
  297. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE-1);
  298. /* Check the status. */
  299. if (status != FX_SUCCESS)
  300. {
  301. /* Error, return error code. */
  302. printf("ERROR!\n");
  303. test_control_return(14);
  304. }
  305. /* Read 4 bytes from the file. */
  306. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  307. if (status != FX_NOT_OPEN)
  308. {
  309. printf("ERROR!\n");
  310. test_control_return(23);
  311. }
  312. /* Create a file called TEST.TXT in the root directory. */
  313. status = fx_file_create(&ram_disk, "TEST.TXT");
  314. /* Check the create status. */
  315. if (status != FX_SUCCESS)
  316. {
  317. printf("ERROR!\n");
  318. test_control_return(15);
  319. }
  320. /* Open the test file. */
  321. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  322. /* Check the file open status. */
  323. if (status != FX_SUCCESS)
  324. {
  325. printf("ERROR!\n");
  326. test_control_return(16);
  327. }
  328. /* Pickup the available bytes in the media. */
  329. status = fx_media_space_available(&ram_disk, &available_bytes);
  330. /* Check for available bytes error. */
  331. if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
  332. {
  333. printf("ERROR!\n");
  334. test_control_return(17);
  335. }
  336. /* Loop to write successive bytes out to the file.... to fill the media! */
  337. i = 0;
  338. write_value = 0;
  339. while (i < available_bytes)
  340. {
  341. /* Write 4 bytes to the file. */
  342. status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
  343. /* Check the file write status. */
  344. if (status != FX_SUCCESS)
  345. {
  346. printf("ERROR!\n");
  347. test_control_return(18);
  348. }
  349. /* Increment byte count. */
  350. i = i + sizeof(ULONG);
  351. /* Increment write value. */
  352. write_value++;
  353. }
  354. /* Pickup the available bytes in the media again. */
  355. status = fx_media_space_available(&ram_disk, &i);
  356. /* Check for available bytes error. */
  357. if ((status != FX_SUCCESS) || (i != 0))
  358. {
  359. printf("ERROR!\n");
  360. test_control_return(19);
  361. }
  362. #ifndef FX_DISABLE_CACHE
  363. /* At this point, we should invalidate the media to ensure that all
  364. dirty sectors are written. */
  365. status = fx_media_cache_invalidate(&ram_disk);
  366. /* Check for flush errors. */
  367. if ((status != FX_SUCCESS) || (ram_disk.fx_media_sector_cache_dirty_count))
  368. {
  369. printf("ERROR!\n");
  370. test_control_return(20);
  371. }
  372. /* See if any sectors are still valid in the cache. */
  373. for (i = 0; i < ram_disk.fx_media_sector_cache_size; i++)
  374. {
  375. /* Determine if this cache entry is still valid. */
  376. if (ram_disk.fx_media_sector_cache[i].fx_cached_sector_valid)
  377. {
  378. printf("ERROR!\n");
  379. test_control_return(81);
  380. }
  381. }
  382. #endif
  383. /* Seek to the beginning of the test file. */
  384. status = fx_file_seek(&my_file, 0);
  385. /* Check the file seek status. */
  386. if (status != FX_SUCCESS)
  387. {
  388. printf("ERROR!\n");
  389. test_control_return(22);
  390. }
  391. /* Now read in all the bytes again to make sure the file contents are really there. */
  392. i = 0;
  393. read_value = 0;
  394. while (i < available_bytes)
  395. {
  396. /* Read 4 bytes from the file. */
  397. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  398. /* Check the file read status. */
  399. if ((status != FX_SUCCESS) || (actual != 4) || (read_value != i/4))
  400. {
  401. printf("ERROR!\n");
  402. test_control_return(23);
  403. }
  404. /* Increment byte count. */
  405. i = i + sizeof(ULONG);
  406. }
  407. /* Close the test file. */
  408. status = fx_file_close(&my_file);
  409. /* Check the file close status. */
  410. if (status != FX_SUCCESS)
  411. {
  412. printf("ERROR!\n");
  413. test_control_return(24);
  414. }
  415. /* Close the media. */
  416. status = fx_media_close(&ram_disk);
  417. /* Open the ram_disk. */
  418. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  419. /* Check the status. */
  420. if (status != FX_SUCCESS)
  421. {
  422. /* Error, return error code. */
  423. printf("ERROR!\n");
  424. test_control_return(25);
  425. }
  426. /* Open the file. */
  427. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
  428. /* Check the file open status. */
  429. if (status != FX_SUCCESS)
  430. {
  431. /* Error opening file. Return to caller. */
  432. printf("ERROR!\n");
  433. test_control_return(26);
  434. }
  435. /* Now read in all the bytes again to make sure the file contents are really there. */
  436. i = 0;
  437. read_value = 0;
  438. while (i < available_bytes)
  439. {
  440. /* Read as much as 4 sectors full of bytes from the file. */
  441. status = fx_file_read(&my_file, (void *) my_buffer, sizeof(my_buffer), &actual);
  442. /* Check the file read status. */
  443. if (status != FX_SUCCESS)
  444. {
  445. printf("ERROR!\n");
  446. test_control_return(27);
  447. }
  448. /* Determine if the contents are what is expected. */
  449. for (j = 0; j < actual/sizeof(ULONG); j++)
  450. {
  451. /* Determine if the buffer is correct. */
  452. if (read_value != my_buffer[j])
  453. {
  454. printf("ERROR!\n");
  455. test_control_return(28);
  456. }
  457. read_value++;
  458. }
  459. /* Increment byte count. */
  460. i = i + actual;
  461. }
  462. /* Close the file. */
  463. status = fx_file_close(&my_file);
  464. /* Open the file again but with the fast option. */
  465. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ_FAST);
  466. /* Check the file open status. */
  467. if (status != FX_SUCCESS)
  468. {
  469. /* Error opening file. Return to caller. */
  470. printf("ERROR!\n");
  471. test_control_return(29);
  472. }
  473. /* Now read in all the bytes again to make sure the file contents are really there. */
  474. i = 0;
  475. read_value = 0;
  476. while (i < available_bytes)
  477. {
  478. /* Read as much as 4 sectors full of bytes from the file. */
  479. status = fx_file_read(&my_file, (void *) my_buffer, sizeof(my_buffer), &actual);
  480. /* Check the file read status. */
  481. if (status != FX_SUCCESS)
  482. {
  483. printf("ERROR!\n");
  484. test_control_return(30);
  485. }
  486. /* Determine if the contents are what is expected. */
  487. for (j = 0; j < actual/sizeof(ULONG); j++)
  488. {
  489. /* Determine if the buffer is correct. */
  490. if (read_value != my_buffer[j])
  491. {
  492. printf("ERROR!\n");
  493. test_control_return(31);
  494. }
  495. read_value++;
  496. }
  497. /* Increment byte count. */
  498. i = i + actual;
  499. }
  500. /* Close the file. */
  501. status = fx_file_close(&my_file);
  502. /* Check the file close status. */
  503. if (status != FX_SUCCESS)
  504. {
  505. printf("ERROR!\n");
  506. test_control_return(32);
  507. }
  508. /* Delete the file. */
  509. status = fx_file_delete(&ram_disk, "TEST.TXT");
  510. /* Check the file delete status. */
  511. if (status != FX_SUCCESS)
  512. {
  513. printf("ERROR!\n");
  514. test_control_return(33);
  515. }
  516. /* Write the file in blocks and then read ulong at a time. */
  517. status = fx_file_create(&ram_disk, "TEST.TXT");
  518. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  519. /* Check the file open status. */
  520. if (status != FX_SUCCESS)
  521. {
  522. printf("ERROR!\n");
  523. test_control_return(34);
  524. }
  525. /* Now write the big buffer at the same time. */
  526. /* Now read in all the bytes again to make sure the file contents are really there. */
  527. i = 0;
  528. read_value = 0;
  529. while (i < available_bytes)
  530. {
  531. /* Build the buffer. */
  532. for (j = 0; j < actual/sizeof(ULONG); j++)
  533. {
  534. /* Build the buffer entry. */
  535. my_buffer[j] = read_value++;
  536. }
  537. /* Write 4 sectors at a time. */
  538. status = fx_file_write(&my_file, (void *) my_buffer, sizeof(my_buffer));
  539. /* Check the file write status. */
  540. if (status != FX_SUCCESS)
  541. {
  542. printf("ERROR!\n");
  543. test_control_return(35);
  544. }
  545. /* Increment byte count. */
  546. i = i + sizeof(my_buffer);
  547. }
  548. /* At this point, seek to the beginning of the file and read every 4 bytes. */
  549. status = fx_file_seek(&my_file, 0);
  550. i = 0;
  551. read_value = 0;
  552. while (i < available_bytes)
  553. {
  554. /* Read 4 bytes from the file. */
  555. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  556. /* Check the file read status. */
  557. if ((status != FX_SUCCESS) || (actual != 4) || (read_value != i/4))
  558. {
  559. printf("ERROR!\n");
  560. test_control_return(36);
  561. }
  562. /* Increment byte count. */
  563. i = i + sizeof(ULONG);
  564. }
  565. /* Close the file. */
  566. status += fx_file_close(&my_file);
  567. /* Close the media. */
  568. status += fx_media_close(&ram_disk);
  569. /* Determine if the test was successful. */
  570. if (status != FX_SUCCESS)
  571. {
  572. printf("ERROR!\n");
  573. test_control_return(37);
  574. }
  575. /* Test the update of files open for reading while the write is happening. */
  576. /* Format the media. This needs to be done before opening it! */
  577. status = fx_media_format(&ram_disk,
  578. _fx_ram_driver, // Driver entry
  579. ram_disk_memory, // RAM disk memory pointer
  580. cache_buffer, // Media buffer pointer
  581. CACHE_SIZE, // Media buffer size
  582. "MY_RAM_DISK", // Volume Name
  583. 1, // Number of FATs
  584. 32, // Directory Entries
  585. 0, // Hidden sectors
  586. 6000, // Total sectors - FAT16
  587. 128, // Sector size
  588. 1, // Sectors per cluster
  589. 1, // Heads
  590. 1); // Sectors per track
  591. /* Determine if the format had an error. */
  592. if (status)
  593. {
  594. printf("ERROR!\n");
  595. test_control_return(38);
  596. }
  597. /* Open the ram_disk. */
  598. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  599. /* Check the status. */
  600. if (status != FX_SUCCESS)
  601. {
  602. /* Error, return error code. */
  603. printf("ERROR!\n");
  604. test_control_return(39);
  605. }
  606. /* Create a file called TEST.TXT in the root directory. */
  607. status = fx_file_create(&ram_disk, "TEST.TXT");
  608. status += fx_file_create(&ram_disk, "TEST1.TXT");
  609. status += fx_file_create(&ram_disk, "TEST2.TXT");
  610. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
  611. status += fx_file_open(&ram_disk, &my_file1, "TEST.TXT", FX_OPEN_FOR_READ);
  612. status += fx_file_open(&ram_disk, &my_file2, "TEST.TXT", FX_OPEN_FOR_WRITE);
  613. status += fx_file_open(&ram_disk, &my_file3, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  614. status += fx_file_open(&ram_disk, &my_file4, "TEST2.TXT", FX_OPEN_FOR_WRITE);
  615. status += fx_file_write(&my_file4, my_buffer, 128);
  616. /* Now loop through the maximum of clusters to fill and read the file. */
  617. i = 0;
  618. while (ram_disk.fx_media_available_clusters)
  619. {
  620. if (i == 4)
  621. {
  622. status += fx_file_close(&my_file4);
  623. status += fx_file_delete(&ram_disk, "TEST2.TXT");
  624. }
  625. /* Write to the writable file. */
  626. status += fx_file_write(&my_file2, my_buffer, 128);
  627. /* Read the data in the file from the other 2 file handles. */
  628. status += fx_file_read(&my_file1, my_buffer, 128, &actual1);
  629. status += fx_file_read(&my_file, my_buffer, 128, &actual2);
  630. /* Check the status. */
  631. if (status)
  632. break;
  633. i++;
  634. }
  635. /* Close the files and the media. */
  636. status += fx_file_close(&my_file);
  637. status += fx_file_close(&my_file1);
  638. status += fx_file_close(&my_file2);
  639. status += fx_media_close(&ram_disk);
  640. /* Check the status. */
  641. if (status != FX_SUCCESS)
  642. {
  643. /* Error, return error code. */
  644. printf("ERROR!\n");
  645. test_control_return(40);
  646. }
  647. /* Test the update of files open for reading while the write is happening with multiple sectors per cluster. */
  648. /* Format the media. This needs to be done before opening it! */
  649. status = fx_media_format(&ram_disk,
  650. _fx_ram_driver, // Driver entry
  651. ram_disk_memory, // RAM disk memory pointer
  652. cache_buffer, // Media buffer pointer
  653. CACHE_SIZE, // Media buffer size
  654. "MY_RAM_DISK", // Volume Name
  655. 1, // Number of FATs
  656. 32, // Directory Entries
  657. 0, // Hidden sectors
  658. 6000, // Total sectors - FAT16
  659. 128, // Sector size
  660. 2, // Sectors per cluster
  661. 1, // Heads
  662. 1); // Sectors per track
  663. /* Determine if the format had an error. */
  664. if (status)
  665. {
  666. printf("ERROR!\n");
  667. test_control_return(41);
  668. }
  669. /* Open the ram_disk. */
  670. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  671. /* Check the status. */
  672. if (status != FX_SUCCESS)
  673. {
  674. /* Error, return error code. */
  675. printf("ERROR!\n");
  676. test_control_return(42);
  677. }
  678. /* Create a file called TEST.TXT in the root directory. */
  679. status = fx_file_create(&ram_disk, "TEST.TXT");
  680. status += fx_file_create(&ram_disk, "TEST1.TXT");
  681. status += fx_file_create(&ram_disk, "TEST2.TXT");
  682. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
  683. status += fx_file_open(&ram_disk, &my_file1, "TEST.TXT", FX_OPEN_FOR_READ);
  684. status += fx_file_open(&ram_disk, &my_file2, "TEST.TXT", FX_OPEN_FOR_WRITE);
  685. status += fx_file_open(&ram_disk, &my_file3, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  686. status += fx_file_open(&ram_disk, &my_file4, "TEST2.TXT", FX_OPEN_FOR_WRITE);
  687. status += fx_file_write(&my_file4, my_buffer, 128);
  688. /* Now loop through the maximum of clusters to fill and read the file. */
  689. i = 0;
  690. while (ram_disk.fx_media_available_clusters)
  691. {
  692. if (i == 4)
  693. {
  694. status += fx_file_close(&my_file4);
  695. status += fx_file_delete(&ram_disk, "TEST2.TXT");
  696. }
  697. /* Write to the writable file. */
  698. status += fx_file_write(&my_file2, my_buffer, 128);
  699. status += fx_file_write(&my_file2, my_buffer, 128);
  700. /* Read the data in the file from the other 2 file handles. */
  701. status += fx_file_read(&my_file1, my_buffer, 128, &actual1);
  702. status += fx_file_read(&my_file, my_buffer, 128, &actual2);
  703. status += fx_file_read(&my_file1, my_buffer, 128, &actual1);
  704. status += fx_file_read(&my_file, my_buffer, 128, &actual2);
  705. /* Check the status. */
  706. if (status)
  707. break;
  708. i++;
  709. }
  710. /* Check the status. */
  711. if (status != FX_SUCCESS)
  712. {
  713. /* Error, return error code. */
  714. printf("ERROR!\n");
  715. test_control_return(43);
  716. }
  717. /* Now force a wrap of the FAT search. */
  718. ram_disk.fx_media_available_clusters++;
  719. status = fx_file_write(&my_file2, my_buffer, 128);
  720. /* Did we get an error? */
  721. if (status != FX_NO_MORE_SPACE)
  722. {
  723. /* Error, return error code. */
  724. printf("ERROR!\n");
  725. test_control_return(44);
  726. }
  727. /* Close the files and the media. */
  728. status = fx_file_close(&my_file);
  729. status += fx_file_close(&my_file1);
  730. status += fx_file_close(&my_file2);
  731. status += fx_media_close(&ram_disk);
  732. /* Check the status. */
  733. if (status != FX_SUCCESS)
  734. {
  735. /* Error, return error code. */
  736. printf("ERROR!\n");
  737. test_control_return(43);
  738. }
  739. /* Test the update of files open for reading while the write is happening - with random errors! */
  740. /* Format the media. This needs to be done before opening it! */
  741. status = fx_media_format(&ram_disk,
  742. _fx_ram_driver, // Driver entry
  743. ram_disk_memory, // RAM disk memory pointer
  744. cache_buffer, // Media buffer pointer
  745. CACHE_SIZE, // Media buffer size
  746. "MY_RAM_DISK", // Volume Name
  747. 1, // Number of FATs
  748. 32, // Directory Entries
  749. 0, // Hidden sectors
  750. 6000, // Total sectors - FAT16
  751. 128, // Sector size
  752. 1, // Sectors per cluster
  753. 1, // Heads
  754. 1); // Sectors per track
  755. /* Determine if the format had an error. */
  756. if (status)
  757. {
  758. printf("ERROR!\n");
  759. test_control_return(44);
  760. }
  761. /* Open the ram_disk. */
  762. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  763. /* Check the status. */
  764. if (status != FX_SUCCESS)
  765. {
  766. /* Error, return error code. */
  767. printf("ERROR!\n");
  768. test_control_return(45);
  769. }
  770. /* Create a file called TEST.TXT in the root directory. */
  771. fx_file_create(&ram_disk, "TEST.TXT");
  772. fx_file_create(&ram_disk, "TEST1.TXT");
  773. fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
  774. fx_file_open(&ram_disk, &my_file1, "TEST.TXT", FX_OPEN_FOR_READ);
  775. fx_file_open(&ram_disk, &my_file2, "TEST.TXT", FX_OPEN_FOR_WRITE);
  776. fx_file_open(&ram_disk, &my_file3, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  777. /* Now loop through the maximum of clusters to fill and read the file. */
  778. i = 0;
  779. while (ram_disk.fx_media_available_clusters)
  780. {
  781. /* Flush the media. */
  782. fx_media_flush(&ram_disk);
  783. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  784. /* Setup the random I/O Error. */
  785. _fx_ram_driver_io_error_request = (rand() & 4);
  786. if (_fx_ram_driver_io_error_request == 0)
  787. _fx_ram_driver_io_error_request = 1;
  788. _fx_utility_fat_entry_write_error_request = _fx_ram_driver_io_error_request;
  789. _fx_utility_fat_entry_read_error_request = _fx_ram_driver_io_error_request;
  790. _fx_utility_logical_sector_write_error_request = _fx_ram_driver_io_error_request;
  791. _fx_utility_logical_sector_read_error_request = _fx_ram_driver_io_error_request;
  792. /* Write to the writable file. */
  793. if (i & 1)
  794. {
  795. fx_file_write(&my_file2, my_buffer, 128);
  796. }
  797. else
  798. {
  799. fx_file_write(&my_file2, my_buffer, 32);
  800. fx_file_write(&my_file2, my_buffer, 32);
  801. fx_file_write(&my_file2, my_buffer, 32);
  802. fx_file_write(&my_file2, my_buffer, 32);
  803. }
  804. /* Setup the random I/O Error. */
  805. _fx_ram_driver_io_error_request = (rand() & 4);
  806. if (_fx_ram_driver_io_error_request == 0)
  807. _fx_ram_driver_io_error_request = 1;
  808. _fx_utility_fat_entry_write_error_request = _fx_ram_driver_io_error_request;
  809. _fx_utility_fat_entry_read_error_request = _fx_ram_driver_io_error_request;
  810. _fx_utility_logical_sector_write_error_request = _fx_ram_driver_io_error_request;
  811. _fx_utility_logical_sector_read_error_request = _fx_ram_driver_io_error_request;
  812. /* Read the data in the file from the other 2 file handles. */
  813. if (i & 1)
  814. {
  815. fx_file_read(&my_file1, my_buffer, 128, &actual1);
  816. }
  817. else
  818. {
  819. fx_file_read(&my_file1, my_buffer, 32, &actual1);
  820. fx_file_read(&my_file1, my_buffer, 32, &actual1);
  821. fx_file_read(&my_file1, my_buffer, 32, &actual1);
  822. fx_file_read(&my_file1, my_buffer, 32, &actual1);
  823. }
  824. /* Setup the random I/O Error. */
  825. _fx_ram_driver_io_error_request = (rand() & 4);
  826. if (_fx_ram_driver_io_error_request == 0)
  827. _fx_ram_driver_io_error_request = 1;
  828. _fx_utility_fat_entry_write_error_request = _fx_ram_driver_io_error_request;
  829. _fx_utility_fat_entry_read_error_request = _fx_ram_driver_io_error_request;
  830. _fx_utility_logical_sector_write_error_request = _fx_ram_driver_io_error_request;
  831. _fx_utility_logical_sector_read_error_request = _fx_ram_driver_io_error_request;
  832. fx_file_read(&my_file, my_buffer, 128, &actual2);
  833. _fx_ram_driver_io_error_request = 0;
  834. _fx_utility_fat_entry_write_error_request = _fx_ram_driver_io_error_request;
  835. _fx_utility_fat_entry_read_error_request = _fx_ram_driver_io_error_request;
  836. _fx_utility_logical_sector_write_error_request = _fx_ram_driver_io_error_request;
  837. _fx_utility_logical_sector_read_error_request = _fx_ram_driver_io_error_request;
  838. i++;
  839. }
  840. /* Close the files and the media. */
  841. fx_file_close(&my_file);
  842. fx_file_close(&my_file1);
  843. fx_file_close(&my_file2);
  844. fx_media_close(&ram_disk);
  845. /* Test the write of partial cluster and direct I/O over non-contigous clusters. */
  846. /* Format the media. This needs to be done before opening it! */
  847. status = fx_media_format(&ram_disk,
  848. _fx_ram_driver, // Driver entry
  849. ram_disk_memory, // RAM disk memory pointer
  850. cache_buffer, // Media buffer pointer
  851. CACHE_SIZE, // Media buffer size
  852. "MY_RAM_DISK", // Volume Name
  853. 1, // Number of FATs
  854. 32, // Directory Entries
  855. 0, // Hidden sectors
  856. 6000, // Total sectors - FAT16
  857. 128, // Sector size
  858. 3, // Sectors per cluster
  859. 1, // Heads
  860. 1); // Sectors per track
  861. /* Determine if the format had an error. */
  862. if (status)
  863. {
  864. printf("ERROR!\n");
  865. test_control_return(46);
  866. }
  867. /* Open the ram_disk. */
  868. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  869. /* Check the status. */
  870. if (status != FX_SUCCESS)
  871. {
  872. /* Error, return error code. */
  873. printf("ERROR!\n");
  874. test_control_return(47);
  875. }
  876. /* Create a file called TEST.TXT in the root directory. */
  877. status = fx_file_create(&ram_disk, "TEST.TXT");
  878. status += fx_file_create(&ram_disk, "TEST1.TXT");
  879. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  880. status += fx_file_open(&ram_disk, &my_file4,"TEST1.TXT", FX_OPEN_FOR_WRITE);
  881. /* Write a small amount of data first to cause an unalignment and partial sector write. */
  882. status += fx_file_write(&my_file, my_buffer, 32);
  883. status += fx_file_write(&my_file4, my_buffer, 32);
  884. status += fx_file_write(&my_file, my_buffer, 128*4);
  885. status += fx_file_write(&my_file, my_buffer, 128*4);
  886. /* Now loop through the maximum of clusters to fill up the rest of the FAT table. */
  887. i = 0;
  888. while (ram_disk.fx_media_available_clusters)
  889. {
  890. /* Write to the writable file. */
  891. status += fx_file_write(&my_file, my_buffer, 32);
  892. status += fx_file_write(&my_file4, my_buffer, 32);
  893. i++;
  894. }
  895. /* Check the status. */
  896. if (status != FX_SUCCESS)
  897. {
  898. /* Error, return error code. */
  899. printf("ERROR!\n");
  900. test_control_return(48);
  901. }
  902. /* Now read the file in as big of chunks as possible to excersise the partial read paths. */
  903. status = fx_file_seek(&my_file, 0);
  904. do
  905. {
  906. /* Read chunks of the file. */
  907. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  908. } while (status != FX_END_OF_FILE);
  909. /* Now delete the second file to leave holes in the FAT table. */
  910. status += fx_file_close(&my_file4);
  911. status += fx_file_delete(&ram_disk, "TEST1.TXT");
  912. /* Finally, perform a direct write with that can't be done with contigous clusters. */
  913. status = fx_file_write(&my_file, my_buffer, 128*4);
  914. /* Did we get an error? */
  915. if (status != FX_SUCCESS)
  916. {
  917. /* Error, return error code. */
  918. printf("ERROR!\n");
  919. test_control_return(49);
  920. }
  921. /* Close the files and the media. */
  922. status = fx_file_close(&my_file);
  923. status += fx_media_close(&ram_disk);
  924. /* Check the status. */
  925. if (status != FX_SUCCESS)
  926. {
  927. /* Error, return error code. */
  928. printf("ERROR!\n");
  929. test_control_return(50);
  930. }
  931. /* Test the write of partial cluster and direct I/O when the FAT chain is broken. */
  932. /* Format the media. This needs to be done before opening it! */
  933. status = fx_media_format(&ram_disk,
  934. _fx_ram_driver, // Driver entry
  935. ram_disk_memory, // RAM disk memory pointer
  936. cache_buffer, // Media buffer pointer
  937. CACHE_SIZE, // Media buffer size
  938. "MY_RAM_DISK", // Volume Name
  939. 1, // Number of FATs
  940. 32, // Directory Entries
  941. 0, // Hidden sectors
  942. 14000, // Total sectors - FAT16
  943. 128, // Sector size
  944. 2, // Sectors per cluster
  945. 1, // Heads
  946. 1); // Sectors per track
  947. /* Determine if the format had an error. */
  948. if (status)
  949. {
  950. printf("ERROR!\n");
  951. test_control_return(51);
  952. }
  953. /* Open the ram_disk. */
  954. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  955. /* Check the status. */
  956. if (status != FX_SUCCESS)
  957. {
  958. /* Error, return error code. */
  959. printf("ERROR!\n");
  960. test_control_return(52);
  961. }
  962. /* Create a file called TEST.TXT in the root directory. */
  963. status = fx_file_create(&ram_disk, "TEST.TXT");
  964. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  965. /* Write a data first to build a FAT chain. */
  966. status += fx_file_write(&my_file, my_buffer, 128*4);
  967. status += fx_file_write(&my_file, my_buffer, 128*4);
  968. status += fx_file_write(&my_file, my_buffer, 128*4);
  969. status += fx_file_write(&my_file, my_buffer, 128*4);
  970. status += fx_file_seek(&my_file, 0);
  971. status += fx_media_flush(&ram_disk);
  972. _fx_utility_FAT_flush(&ram_disk);
  973. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  974. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  975. {
  976. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  977. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  978. }
  979. /* Read the first FAT sector. */
  980. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  981. /* Add a FAT entry randomly in the FAT table. */
  982. fat_buffer[6] = 1;
  983. fat_buffer[7] = 0;
  984. fat_buffer[8] = 1;
  985. fat_buffer[9] = 0;
  986. /* Write the FAT corruption out. */
  987. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  988. /* See if we are okay. */
  989. if (status != FX_SUCCESS)
  990. {
  991. /* Error, return error code. */
  992. printf("ERROR!\n");
  993. test_control_return(53);
  994. }
  995. /* Now attempt to write a partial sector. */
  996. status = fx_file_write(&my_file, my_buffer, 128*4);
  997. /* See if we get the file corrupt error. */
  998. if (status != FX_FILE_CORRUPT)
  999. {
  1000. /* Error, return error code. */
  1001. printf("ERROR!\n");
  1002. test_control_return(54);
  1003. }
  1004. status = fx_file_write(&my_file, my_buffer, 128*4);
  1005. status += fx_file_write(&my_file, my_buffer, 128*4);
  1006. /* See if we get the file corrupt error. */
  1007. if (status != FX_FILE_CORRUPT)
  1008. {
  1009. /* Error, return error code. */
  1010. printf("ERROR!\n");
  1011. test_control_return(55);
  1012. }
  1013. /* Close the files and the media. */
  1014. status = fx_file_close(&my_file);
  1015. status += fx_media_close(&ram_disk);
  1016. /* Check the status. */
  1017. if (status != FX_SUCCESS)
  1018. {
  1019. /* Error, return error code. */
  1020. printf("ERROR!\n");
  1021. test_control_return(56);
  1022. }
  1023. /* Test the maximum write size. */
  1024. /* Format the media. This needs to be done before opening it! */
  1025. status = fx_media_format(&ram_disk,
  1026. _fx_ram_driver, // Driver entry
  1027. ram_disk_memory, // RAM disk memory pointer
  1028. cache_buffer, // Media buffer pointer
  1029. CACHE_SIZE, // Media buffer size
  1030. "MY_RAM_DISK", // Volume Name
  1031. 1, // Number of FATs
  1032. 32, // Directory Entries
  1033. 0, // Hidden sectors
  1034. 1000, // Total sectors - FAT12
  1035. 128, // Sector size
  1036. 1, // Sectors per cluster
  1037. 1, // Heads
  1038. 1); // Sectors per track
  1039. /* Determine if the format had an error. */
  1040. if (status)
  1041. {
  1042. printf("ERROR!\n");
  1043. test_control_return(57);
  1044. }
  1045. /* Open the ram_disk. */
  1046. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1047. /* Check the status. */
  1048. if (status != FX_SUCCESS)
  1049. {
  1050. /* Error, return error code. */
  1051. printf("ERROR!\n");
  1052. test_control_return(58);
  1053. }
  1054. /* Create a file called TEST.TXT in the root directory. */
  1055. status = fx_file_create(&ram_disk, "TEST.TXT");
  1056. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1057. /* Write a data first to build a FAT chain. */
  1058. status += fx_file_write(&my_file, my_buffer, 128);
  1059. /* Check the status. */
  1060. if (status != FX_SUCCESS)
  1061. {
  1062. /* Error, return error code. */
  1063. printf("ERROR!\n");
  1064. test_control_return(59);
  1065. }
  1066. /* Now manually setup the file offset to force an error. */
  1067. temp = (ULONG)my_file.fx_file_current_file_offset;
  1068. my_file.fx_file_current_file_offset = 0xFFFFFFF0;
  1069. /* Write a data first to force the overflow. */
  1070. status = fx_file_write(&my_file, my_buffer, 32);
  1071. /* Check the status. */
  1072. if (status != FX_NO_MORE_SPACE)
  1073. {
  1074. /* Error, return error code. */
  1075. printf("ERROR!\n");
  1076. test_control_return(60);
  1077. }
  1078. /* Also save, adjust the current available so that one new cluster will be written. */
  1079. my_file.fx_file_current_available_size = 0xFFFFFFF0;
  1080. temp1 = (ULONG)my_file.fx_file_current_available_size;
  1081. /* Now attempt to write a massive file to exercise the maximum available file size logic. */
  1082. status = fx_file_write(&my_file, my_buffer, 1);
  1083. /* Check the status. */
  1084. if (status != FX_SUCCESS)
  1085. {
  1086. /* Error, return error code. */
  1087. printf("ERROR!\n");
  1088. test_control_return(61);
  1089. }
  1090. /* Now restore the original offset. */
  1091. my_file.fx_file_current_file_offset = temp;
  1092. my_file.fx_file_current_available_size = temp1;
  1093. /* Close the file. */
  1094. status = fx_file_close(&my_file);
  1095. status += fx_media_close(&ram_disk);
  1096. /* Check the status. */
  1097. if (status != FX_SUCCESS)
  1098. {
  1099. /* Error, return error code. */
  1100. printf("ERROR!\n");
  1101. test_control_return(62);
  1102. }
  1103. /* Test the remaining I/O error paths in file write. */
  1104. /* Format the media. This needs to be done before opening it! */
  1105. status = fx_media_format(&ram_disk,
  1106. _fx_ram_driver, // Driver entry
  1107. ram_disk_memory, // RAM disk memory pointer
  1108. cache_buffer, // Media buffer pointer
  1109. CACHE_SIZE, // Media buffer size
  1110. "MY_RAM_DISK", // Volume Name
  1111. 1, // Number of FATs
  1112. 32, // Directory Entries
  1113. 0, // Hidden sectors
  1114. 1000, // Total sectors - FAT12
  1115. 128, // Sector size
  1116. 3, // Sectors per cluster
  1117. 1, // Heads
  1118. 1); // Sectors per track
  1119. /* Determine if the format had an error. */
  1120. if (status)
  1121. {
  1122. printf("ERROR!\n");
  1123. test_control_return(63);
  1124. }
  1125. /* Open the ram_disk. */
  1126. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1127. /* Check the status. */
  1128. if (status != FX_SUCCESS)
  1129. {
  1130. /* Error, return error code. */
  1131. printf("ERROR!\n");
  1132. test_control_return(64);
  1133. }
  1134. /* Create a file called TEST.TXT in the root directory. */
  1135. status = fx_file_create(&ram_disk, "TEST.TXT");
  1136. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1137. /* Check the status. */
  1138. if (status != FX_SUCCESS)
  1139. {
  1140. /* Error, return error code. */
  1141. printf("ERROR!\n");
  1142. test_control_return(65);
  1143. }
  1144. /* Write a data first to build a FAT chain, with an I/O error on liking the FAT chain. */
  1145. _fx_utility_fat_entry_write_error_request = 1;
  1146. status = fx_file_write(&my_file, my_buffer, 128*4);
  1147. _fx_utility_fat_entry_write_error_request = 0;
  1148. /* Check the status. */
  1149. if (status != FX_IO_ERROR)
  1150. {
  1151. /* Error, return error code. */
  1152. printf("ERROR!\n");
  1153. test_control_return(66);
  1154. }
  1155. /* Close the file. */
  1156. status = fx_file_close(&my_file);
  1157. status += fx_media_close(&ram_disk);
  1158. /* Check the status. */
  1159. if (status != FX_SUCCESS)
  1160. {
  1161. /* Error, return error code. */
  1162. printf("ERROR!\n");
  1163. test_control_return(67);
  1164. }
  1165. /* Format the media. This needs to be done before opening it! */
  1166. status = fx_media_format(&ram_disk,
  1167. _fx_ram_driver, // Driver entry
  1168. ram_disk_memory, // RAM disk memory pointer
  1169. cache_buffer, // Media buffer pointer
  1170. CACHE_SIZE, // Media buffer size
  1171. "MY_RAM_DISK", // Volume Name
  1172. 1, // Number of FATs
  1173. 32, // Directory Entries
  1174. 0, // Hidden sectors
  1175. 1000, // Total sectors - FAT12
  1176. 128, // Sector size
  1177. 3, // Sectors per cluster
  1178. 1, // Heads
  1179. 1); // Sectors per track
  1180. /* Determine if the format had an error. */
  1181. if (status)
  1182. {
  1183. printf("ERROR!\n");
  1184. test_control_return(68);
  1185. }
  1186. /* Open the ram_disk. */
  1187. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1188. /* Check the status. */
  1189. if (status != FX_SUCCESS)
  1190. {
  1191. /* Error, return error code. */
  1192. printf("ERROR!\n");
  1193. test_control_return(69);
  1194. }
  1195. /* Create a file called TEST.TXT in the root directory. */
  1196. status = fx_file_create(&ram_disk, "TEST.TXT");
  1197. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1198. /* Check the status. */
  1199. if (status != FX_SUCCESS)
  1200. {
  1201. /* Error, return error code. */
  1202. printf("ERROR!\n");
  1203. test_control_return(70);
  1204. }
  1205. /* Write a data first to build a FAT chain, with an I/O error on writing EOF at the end of the FAT chain. */
  1206. _fx_utility_fat_entry_write_error_request = 2;
  1207. status = fx_file_write(&my_file, my_buffer, 128*4);
  1208. _fx_utility_fat_entry_write_error_request = 0;
  1209. /* Check the status. */
  1210. if (status != FX_IO_ERROR)
  1211. {
  1212. /* Error, return error code. */
  1213. printf("ERROR!\n");
  1214. test_control_return(71);
  1215. }
  1216. /* Close the file. */
  1217. status = fx_file_close(&my_file);
  1218. status += fx_media_close(&ram_disk);
  1219. /* Check the status. */
  1220. if (status != FX_SUCCESS)
  1221. {
  1222. /* Error, return error code. */
  1223. printf("ERROR!\n");
  1224. test_control_return(72);
  1225. }
  1226. /* Format the media. This needs to be done before opening it! */
  1227. status = fx_media_format(&ram_disk,
  1228. _fx_ram_driver, // Driver entry
  1229. ram_disk_memory, // RAM disk memory pointer
  1230. cache_buffer, // Media buffer pointer
  1231. CACHE_SIZE, // Media buffer size
  1232. "MY_RAM_DISK", // Volume Name
  1233. 1, // Number of FATs
  1234. 32, // Directory Entries
  1235. 0, // Hidden sectors
  1236. 1000, // Total sectors - FAT12
  1237. 128, // Sector size
  1238. 3, // Sectors per cluster
  1239. 1, // Heads
  1240. 1); // Sectors per track
  1241. /* Determine if the format had an error. */
  1242. if (status)
  1243. {
  1244. printf("ERROR!\n");
  1245. test_control_return(73);
  1246. }
  1247. /* Open the ram_disk. */
  1248. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1249. /* Check the status. */
  1250. if (status != FX_SUCCESS)
  1251. {
  1252. /* Error, return error code. */
  1253. printf("ERROR!\n");
  1254. test_control_return(74);
  1255. }
  1256. /* Create a file called TEST.TXT in the root directory. */
  1257. status = fx_file_create(&ram_disk, "TEST.TXT");
  1258. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1259. status += fx_file_write(&my_file, my_buffer, 128*4);
  1260. /* Check the status. */
  1261. if (status != FX_SUCCESS)
  1262. {
  1263. /* Error, return error code. */
  1264. printf("ERROR!\n");
  1265. test_control_return(75);
  1266. }
  1267. /* Write a data first to build a FAT chain, with an I/O error on linking the new FAT chain to existing FAT chain. */
  1268. _fx_utility_fat_entry_write_error_request = 2;
  1269. status = fx_file_write(&my_file, my_buffer, 128*4);
  1270. _fx_utility_fat_entry_write_error_request = 0;
  1271. /* Check the status. */
  1272. if (status != FX_IO_ERROR)
  1273. {
  1274. /* Error, return error code. */
  1275. printf("ERROR!\n");
  1276. test_control_return(76);
  1277. }
  1278. /* Close the file. */
  1279. status = fx_file_close(&my_file);
  1280. status += fx_media_close(&ram_disk);
  1281. /* Check the status. */
  1282. if (status != FX_SUCCESS)
  1283. {
  1284. /* Error, return error code. */
  1285. printf("ERROR!\n");
  1286. test_control_return(77);
  1287. }
  1288. /* Format the media. This needs to be done before opening it! */
  1289. status = fx_media_format(&ram_disk,
  1290. _fx_ram_driver, // Driver entry
  1291. ram_disk_memory, // RAM disk memory pointer
  1292. cache_buffer, // Media buffer pointer
  1293. CACHE_SIZE, // Media buffer size
  1294. "MY_RAM_DISK", // Volume Name
  1295. 1, // Number of FATs
  1296. 32, // Directory Entries
  1297. 0, // Hidden sectors
  1298. 1000, // Total sectors - FAT12
  1299. 128, // Sector size
  1300. 3, // Sectors per cluster
  1301. 1, // Heads
  1302. 1); // Sectors per track
  1303. /* Determine if the format had an error. */
  1304. if (status)
  1305. {
  1306. printf("ERROR!\n");
  1307. test_control_return(78);
  1308. }
  1309. /* Open the ram_disk. */
  1310. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1311. /* Check the status. */
  1312. if (status != FX_SUCCESS)
  1313. {
  1314. /* Error, return error code. */
  1315. printf("ERROR!\n");
  1316. test_control_return(79);
  1317. }
  1318. /* Create a file called TEST.TXT in the root directory. */
  1319. status = fx_file_create(&ram_disk, "TEST.TXT");
  1320. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1321. status += fx_file_write(&my_file, my_buffer, 128+64);
  1322. /* Check the status. */
  1323. if (status != FX_SUCCESS)
  1324. {
  1325. /* Error, return error code. */
  1326. printf("ERROR!\n");
  1327. test_control_return(80);
  1328. }
  1329. /* Write data that will require another cluster, even though we have only written one sector of the first allocated cluster. */
  1330. status = fx_file_write(&my_file, my_buffer, 128*4);
  1331. /* Check the status. */
  1332. if (status != FX_SUCCESS)
  1333. {
  1334. /* Error, return error code. */
  1335. printf("ERROR!\n");
  1336. test_control_return(81);
  1337. }
  1338. /* Close the file. */
  1339. status = fx_file_close(&my_file);
  1340. status += fx_media_close(&ram_disk);
  1341. /* Check the status. */
  1342. if (status != FX_SUCCESS)
  1343. {
  1344. /* Error, return error code. */
  1345. printf("ERROR!\n");
  1346. test_control_return(82);
  1347. }
  1348. /* Test the read of partial cluster and direct I/O when the FAT chain is broken. */
  1349. /* Format the media. This needs to be done before opening it! */
  1350. status = fx_media_format(&ram_disk,
  1351. _fx_ram_driver, // Driver entry
  1352. ram_disk_memory, // RAM disk memory pointer
  1353. cache_buffer, // Media buffer pointer
  1354. CACHE_SIZE, // Media buffer size
  1355. "MY_RAM_DISK", // Volume Name
  1356. 1, // Number of FATs
  1357. 32, // Directory Entries
  1358. 0, // Hidden sectors
  1359. 14000, // Total sectors - FAT16
  1360. 128, // Sector size
  1361. 2, // Sectors per cluster
  1362. 1, // Heads
  1363. 1); // Sectors per track
  1364. /* Determine if the format had an error. */
  1365. if (status)
  1366. {
  1367. printf("ERROR!\n");
  1368. test_control_return(83);
  1369. }
  1370. /* Open the ram_disk. */
  1371. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1372. /* Check the status. */
  1373. if (status != FX_SUCCESS)
  1374. {
  1375. /* Error, return error code. */
  1376. printf("ERROR!\n");
  1377. test_control_return(84);
  1378. }
  1379. /* Create a file called TEST.TXT in the root directory. */
  1380. status = fx_file_create(&ram_disk, "TEST.TXT");
  1381. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1382. /* Write a data first to build a FAT chain. */
  1383. status += fx_file_write(&my_file, my_buffer, 128*4);
  1384. status += fx_file_write(&my_file, my_buffer, 128*4);
  1385. status += fx_file_write(&my_file, my_buffer, 128*4);
  1386. status += fx_file_write(&my_file, my_buffer, 128*4);
  1387. status += fx_file_seek(&my_file, 0);
  1388. status += fx_media_flush(&ram_disk);
  1389. _fx_utility_FAT_flush(&ram_disk);
  1390. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1391. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1392. {
  1393. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1394. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1395. }
  1396. /* Read the first FAT sector. */
  1397. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1398. /* Add a FAT entry randomly in the FAT table. */
  1399. fat_buffer[6] = 1;
  1400. fat_buffer[7] = 0;
  1401. fat_buffer[8] = 1;
  1402. fat_buffer[9] = 0;
  1403. /* Write the FAT corruption out. */
  1404. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1405. /* See if we are okay. */
  1406. if (status != FX_SUCCESS)
  1407. {
  1408. /* Error, return error code. */
  1409. printf("ERROR!\n");
  1410. test_control_return(85);
  1411. }
  1412. /* Read the file to get the file corruption error. */
  1413. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  1414. /* See if the file is corrupted - it should be. */
  1415. if (status != FX_FILE_CORRUPT)
  1416. {
  1417. /* Error, return error code. */
  1418. printf("ERROR!\n");
  1419. test_control_return(86);
  1420. }
  1421. /* Close everything down. */
  1422. fx_file_close(&my_file);
  1423. fx_media_abort(&ram_disk);
  1424. /* Test the read of partial cluster and direct I/O when the FAT chain is broken - at the beginning of the FAT chain! */
  1425. /* Format the media. This needs to be done before opening it! */
  1426. status = fx_media_format(&ram_disk,
  1427. _fx_ram_driver, // Driver entry
  1428. ram_disk_memory, // RAM disk memory pointer
  1429. cache_buffer, // Media buffer pointer
  1430. CACHE_SIZE, // Media buffer size
  1431. "MY_RAM_DISK", // Volume Name
  1432. 1, // Number of FATs
  1433. 32, // Directory Entries
  1434. 0, // Hidden sectors
  1435. 14000, // Total sectors - FAT16
  1436. 128, // Sector size
  1437. 2, // Sectors per cluster
  1438. 1, // Heads
  1439. 1); // Sectors per track
  1440. /* Determine if the format had an error. */
  1441. if (status)
  1442. {
  1443. printf("ERROR!\n");
  1444. test_control_return(87);
  1445. }
  1446. /* Open the ram_disk. */
  1447. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1448. /* Check the status. */
  1449. if (status != FX_SUCCESS)
  1450. {
  1451. /* Error, return error code. */
  1452. printf("ERROR!\n");
  1453. test_control_return(88);
  1454. }
  1455. /* Create a file called TEST.TXT in the root directory. */
  1456. status = fx_file_create(&ram_disk, "TEST.TXT");
  1457. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1458. /* Write a data first to build a FAT chain. */
  1459. status += fx_file_write(&my_file, my_buffer, 128*4);
  1460. status += fx_file_write(&my_file, my_buffer, 128*4);
  1461. status += fx_file_write(&my_file, my_buffer, 128*4);
  1462. status += fx_file_write(&my_file, my_buffer, 128*4);
  1463. status += fx_file_seek(&my_file, 0);
  1464. status += fx_media_flush(&ram_disk);
  1465. _fx_utility_FAT_flush(&ram_disk);
  1466. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1467. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1468. {
  1469. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1470. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1471. }
  1472. /* Read the first FAT sector. */
  1473. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1474. /* Add a FAT entry randomly in the FAT table. */
  1475. fat_buffer[4] = 1;
  1476. fat_buffer[5] = 0;
  1477. fat_buffer[6] = 1;
  1478. fat_buffer[7] = 0;
  1479. fat_buffer[8] = 1;
  1480. fat_buffer[9] = 0;
  1481. /* Write the FAT corruption out. */
  1482. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1483. /* See if we are okay. */
  1484. if (status != FX_SUCCESS)
  1485. {
  1486. /* Error, return error code. */
  1487. printf("ERROR!\n");
  1488. test_control_return(89);
  1489. }
  1490. /* Read the file to get the file corruption error. */
  1491. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  1492. /* See if the file is corrupted - it should be. */
  1493. if (status != FX_FILE_CORRUPT)
  1494. {
  1495. /* Error, return error code. */
  1496. printf("ERROR!\n");
  1497. test_control_return(90);
  1498. }
  1499. /* Close everything down. */
  1500. fx_file_close(&my_file);
  1501. fx_media_abort(&ram_disk);
  1502. /* Test the read of partial cluster and direct I/O when the FAT chain is broken - at the beginning of the FAT chain and with FFs instead of 1! */
  1503. /* Format the media. This needs to be done before opening it! */
  1504. status = fx_media_format(&ram_disk,
  1505. _fx_ram_driver, // Driver entry
  1506. ram_disk_memory, // RAM disk memory pointer
  1507. cache_buffer, // Media buffer pointer
  1508. CACHE_SIZE, // Media buffer size
  1509. "MY_RAM_DISK", // Volume Name
  1510. 1, // Number of FATs
  1511. 32, // Directory Entries
  1512. 0, // Hidden sectors
  1513. 14000, // Total sectors - FAT16
  1514. 128, // Sector size
  1515. 2, // Sectors per cluster
  1516. 1, // Heads
  1517. 1); // Sectors per track
  1518. /* Determine if the format had an error. */
  1519. if (status)
  1520. {
  1521. printf("ERROR!\n");
  1522. test_control_return(91);
  1523. }
  1524. /* Open the ram_disk. */
  1525. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1526. /* Check the status. */
  1527. if (status != FX_SUCCESS)
  1528. {
  1529. /* Error, return error code. */
  1530. printf("ERROR!\n");
  1531. test_control_return(92);
  1532. }
  1533. /* Create a file called TEST.TXT in the root directory. */
  1534. status = fx_file_create(&ram_disk, "TEST.TXT");
  1535. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1536. /* Write a data first to build a FAT chain. */
  1537. status += fx_file_write(&my_file, my_buffer, 128*4);
  1538. status += fx_file_write(&my_file, my_buffer, 128*4);
  1539. status += fx_file_write(&my_file, my_buffer, 128*4);
  1540. status += fx_file_write(&my_file, my_buffer, 128*4);
  1541. status += fx_file_seek(&my_file, 0);
  1542. status += fx_media_flush(&ram_disk);
  1543. _fx_utility_FAT_flush(&ram_disk);
  1544. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1545. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1546. {
  1547. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1548. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1549. }
  1550. /* Read the first FAT sector. */
  1551. status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1552. /* Add a FAT entry randomly in the FAT table. */
  1553. fat_buffer[4] = 0xFF;
  1554. fat_buffer[5] = 0xFF;
  1555. fat_buffer[6] = 0xFF;
  1556. fat_buffer[7] = 0xFF;
  1557. fat_buffer[8] = 0xFF;
  1558. fat_buffer[9] = 0xFF;
  1559. /* Write the FAT corruption out. */
  1560. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1561. /* See if we are okay. */
  1562. if (status != FX_SUCCESS)
  1563. {
  1564. /* Error, return error code. */
  1565. printf("ERROR!\n");
  1566. test_control_return(93);
  1567. }
  1568. /* Read the file to get the file corruption error. */
  1569. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  1570. /* See if the file is corrupted - it should be. */
  1571. if (status != FX_FILE_CORRUPT)
  1572. {
  1573. /* Error, return error code. */
  1574. printf("ERROR!\n");
  1575. test_control_return(94);
  1576. }
  1577. /* Close everything down. */
  1578. fx_file_close(&my_file);
  1579. fx_media_abort(&ram_disk);
  1580. /* Test the read with I/O FAT read error. */
  1581. /* Format the media. This needs to be done before opening it! */
  1582. status = fx_media_format(&ram_disk,
  1583. _fx_ram_driver, // Driver entry
  1584. ram_disk_memory, // RAM disk memory pointer
  1585. cache_buffer, // Media buffer pointer
  1586. CACHE_SIZE, // Media buffer size
  1587. "MY_RAM_DISK", // Volume Name
  1588. 1, // Number of FATs
  1589. 32, // Directory Entries
  1590. 0, // Hidden sectors
  1591. 14000, // Total sectors - FAT16
  1592. 128, // Sector size
  1593. 2, // Sectors per cluster
  1594. 1, // Heads
  1595. 1); // Sectors per track
  1596. /* Determine if the format had an error. */
  1597. if (status)
  1598. {
  1599. printf("ERROR!\n");
  1600. test_control_return(95);
  1601. }
  1602. /* Open the ram_disk. */
  1603. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1604. /* Check the status. */
  1605. if (status != FX_SUCCESS)
  1606. {
  1607. /* Error, return error code. */
  1608. printf("ERROR!\n");
  1609. test_control_return(96);
  1610. }
  1611. /* Create a file called TEST.TXT in the root directory. */
  1612. status = fx_file_create(&ram_disk, "TEST.TXT");
  1613. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1614. /* Write a data first to build a FAT chain. */
  1615. status += fx_file_write(&my_file, my_buffer, 128*4);
  1616. status += fx_file_write(&my_file, my_buffer, 128*4);
  1617. status += fx_file_write(&my_file, my_buffer, 128*4);
  1618. status += fx_file_write(&my_file, my_buffer, 128*4);
  1619. status += fx_file_seek(&my_file, 0);
  1620. status += fx_media_flush(&ram_disk);
  1621. _fx_utility_FAT_flush(&ram_disk);
  1622. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1623. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1624. {
  1625. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1626. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1627. }
  1628. /* Read the file to get the file IO error. */
  1629. _fx_utility_fat_entry_read_error_request = 1;
  1630. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  1631. _fx_utility_fat_entry_read_error_request = 0;
  1632. /* See if the file is corrupted - it should be. */
  1633. if (status != FX_IO_ERROR)
  1634. {
  1635. /* Error, return error code. */
  1636. printf("ERROR!\n");
  1637. test_control_return(97);
  1638. }
  1639. /* Close everything down. */
  1640. fx_file_close(&my_file);
  1641. fx_media_abort(&ram_disk);
  1642. /* Test the read with I/O logical sector read error. */
  1643. /* Format the media. This needs to be done before opening it! */
  1644. status = fx_media_format(&ram_disk,
  1645. _fx_ram_driver, // Driver entry
  1646. ram_disk_memory, // RAM disk memory pointer
  1647. cache_buffer, // Media buffer pointer
  1648. CACHE_SIZE, // Media buffer size
  1649. "MY_RAM_DISK", // Volume Name
  1650. 1, // Number of FATs
  1651. 32, // Directory Entries
  1652. 0, // Hidden sectors
  1653. 14000, // Total sectors - FAT16
  1654. 128, // Sector size
  1655. 2, // Sectors per cluster
  1656. 1, // Heads
  1657. 1); // Sectors per track
  1658. /* Determine if the format had an error. */
  1659. if (status)
  1660. {
  1661. printf("ERROR!\n");
  1662. test_control_return(95);
  1663. }
  1664. /* Open the ram_disk. */
  1665. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1666. /* Check the status. */
  1667. if (status != FX_SUCCESS)
  1668. {
  1669. /* Error, return error code. */
  1670. printf("ERROR!\n");
  1671. test_control_return(96);
  1672. }
  1673. /* Create a file called TEST.TXT in the root directory. */
  1674. status = fx_file_create(&ram_disk, "TEST.TXT");
  1675. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1676. /* Write a data first to build a FAT chain. */
  1677. status += fx_file_write(&my_file, my_buffer, 128*4);
  1678. status += fx_file_write(&my_file, my_buffer, 128*4);
  1679. status += fx_file_write(&my_file, my_buffer, 128*4);
  1680. status += fx_file_write(&my_file, my_buffer, 128*4);
  1681. status += fx_file_seek(&my_file, 0);
  1682. status += fx_media_flush(&ram_disk);
  1683. _fx_utility_FAT_flush(&ram_disk);
  1684. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1685. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1686. {
  1687. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1688. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1689. }
  1690. /* Read the file to get the file IO error. */
  1691. _fx_ram_driver_io_error_request = 2;
  1692. status = fx_file_read(&my_file, my_buffer, 128*4, &actual);
  1693. _fx_ram_driver_io_error_request = 0;
  1694. /* See if the file is corrupted - it should be. */
  1695. if (status != FX_IO_ERROR)
  1696. {
  1697. /* Error, return error code. */
  1698. printf("ERROR!\n");
  1699. test_control_return(97);
  1700. }
  1701. /* Close everything down. */
  1702. fx_file_close(&my_file);
  1703. fx_media_abort(&ram_disk);
  1704. /* Test the file open with I/O read errors when walking the FAT chain. */
  1705. /* Format the media. This needs to be done before opening it! */
  1706. status = fx_media_format(&ram_disk,
  1707. _fx_ram_driver, // Driver entry
  1708. ram_disk_memory, // RAM disk memory pointer
  1709. cache_buffer, // Media buffer pointer
  1710. CACHE_SIZE, // Media buffer size
  1711. "MY_RAM_DISK", // Volume Name
  1712. 1, // Number of FATs
  1713. 32, // Directory Entries
  1714. 0, // Hidden sectors
  1715. 7000, // Total sectors - FAT16
  1716. 128, // Sector size
  1717. 1, // Sectors per cluster
  1718. 1, // Heads
  1719. 1); // Sectors per track
  1720. /* Determine if the format had an error. */
  1721. if (status)
  1722. {
  1723. printf("ERROR!\n");
  1724. test_control_return(98);
  1725. }
  1726. /* Open the ram_disk. */
  1727. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1728. /* Check the status. */
  1729. if (status != FX_SUCCESS)
  1730. {
  1731. /* Error, return error code. */
  1732. printf("ERROR!\n");
  1733. test_control_return(99);
  1734. }
  1735. /* Create a file called TEST.TXT in the root directory. */
  1736. status = fx_file_create(&ram_disk, "TEST.TXT");
  1737. status += fx_file_create(&ram_disk, "TEST1.TXT");
  1738. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1739. status += fx_file_open(&ram_disk, &my_file1, "TEST1.TXT", FX_OPEN_FOR_WRITE);
  1740. /* Write a data first to build a FAT chain. */
  1741. status += fx_file_write(&my_file, my_buffer, 128*4);
  1742. status += fx_file_write(&my_file, my_buffer, 128*4);
  1743. status += fx_file_write(&my_file, my_buffer, 128*4);
  1744. status += fx_file_write(&my_file, my_buffer, 128*4);
  1745. status += fx_file_write(&my_file1, my_buffer, 128*4);
  1746. status += fx_file_write(&my_file, my_buffer, 128*4);
  1747. /* Close the file. */
  1748. status += fx_file_close(&my_file);
  1749. status += fx_file_close(&my_file1);
  1750. /* Check status. */
  1751. if (status != FX_SUCCESS)
  1752. {
  1753. /* Error, return error code. */
  1754. printf("ERROR!\n");
  1755. test_control_return(100);
  1756. }
  1757. /* Now flush everything out. */
  1758. fx_media_flush(&ram_disk);
  1759. _fx_utility_FAT_flush(&ram_disk);
  1760. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1761. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1762. {
  1763. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1764. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1765. }
  1766. /* Now open the file with an I/O error on the FAT entry read when walking the FAT chain. */
  1767. _fx_utility_fat_entry_read_error_request = 1;
  1768. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1769. _fx_utility_fat_entry_read_error_request = 0;
  1770. /* See if we got the I/O Error. */
  1771. if (status != FX_IO_ERROR)
  1772. {
  1773. /* Error, return error code. */
  1774. printf("ERROR!\n");
  1775. test_control_return(101);
  1776. }
  1777. /* Now break the FAT chain and try to open the file. */
  1778. /* Now flush everything out. */
  1779. fx_media_flush(&ram_disk);
  1780. _fx_utility_FAT_flush(&ram_disk);
  1781. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1782. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1783. {
  1784. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1785. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1786. }
  1787. /* Read the first FAT sector. */
  1788. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1789. /* Add a FAT entry randomly in the FAT table. */
  1790. fat_buffer[4] = 2;
  1791. /* Write the FAT corruption out. */
  1792. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1793. /* See if we are okay. */
  1794. if (status != FX_SUCCESS)
  1795. {
  1796. /* Error, return error code. */
  1797. printf("ERROR!\n");
  1798. test_control_return(102);
  1799. }
  1800. /* Now open the file with a corrupted FAT entry which will cause an error when walking the FAT chain. */
  1801. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1802. /* See if we got the FAT chain. */
  1803. if (status != FX_FAT_READ_ERROR)
  1804. {
  1805. /* Error, return error code. */
  1806. printf("ERROR!\n");
  1807. test_control_return(103);
  1808. }
  1809. /* Now flush everything out. */
  1810. fx_media_flush(&ram_disk);
  1811. _fx_utility_FAT_flush(&ram_disk);
  1812. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1813. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1814. {
  1815. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1816. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1817. }
  1818. /* Read the first FAT sector. */
  1819. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1820. /* Add a FAT entry randomly in the FAT table. */
  1821. fat_buffer[4] = 0xF0;
  1822. fat_buffer[5] = 0xFF;
  1823. /* Write the FAT corruption out. */
  1824. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1825. /* See if we are okay. */
  1826. if (status != FX_SUCCESS)
  1827. {
  1828. /* Error, return error code. */
  1829. printf("ERROR!\n");
  1830. test_control_return(104);
  1831. }
  1832. /* Now open the file with a corrupted FAT entry which will cause an error when walking the FAT chain. */
  1833. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1834. /* See if we got the file corrupt error. */
  1835. if (status != FX_FILE_CORRUPT)
  1836. {
  1837. /* Error, return error code. */
  1838. printf("ERROR!\n");
  1839. test_control_return(105);
  1840. }
  1841. /* Now flush everything out. */
  1842. fx_media_flush(&ram_disk);
  1843. _fx_utility_FAT_flush(&ram_disk);
  1844. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1845. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1846. {
  1847. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1848. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1849. }
  1850. /* Read the first FAT sector. */
  1851. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1852. /* Fix the FAT chain. */
  1853. fat_buffer[4] = 3;
  1854. fat_buffer[5] = 0;
  1855. /* Write the FAT corruption out. */
  1856. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1857. /* See if we are okay. */
  1858. if (status != FX_SUCCESS)
  1859. {
  1860. /* Error, return error code. */
  1861. printf("ERROR!\n");
  1862. test_control_return(106);
  1863. }
  1864. /* Now test the total clusters check when traversing the FAT chain. */
  1865. temp = ram_disk.fx_media_total_clusters;
  1866. ram_disk.fx_media_total_clusters = 4;
  1867. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1868. ram_disk.fx_media_total_clusters = temp;
  1869. /* Check status. */
  1870. if (status != FX_FAT_READ_ERROR)
  1871. {
  1872. /* Error, return error code. */
  1873. printf("ERROR!\n");
  1874. test_control_return(107);
  1875. }
  1876. /* Now open the file with a good FAT chain. */
  1877. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1878. /* Check status. */
  1879. if (status != FX_SUCCESS)
  1880. {
  1881. /* Error, return error code. */
  1882. printf("ERROR!\n");
  1883. test_control_return(108);
  1884. }
  1885. /* Now allocate another cluster to the end of the file. */
  1886. status = fx_file_allocate(&my_file, 256);
  1887. status += fx_file_close(&my_file);
  1888. /* Check status. */
  1889. if (status != FX_SUCCESS)
  1890. {
  1891. /* Error, return error code. */
  1892. printf("ERROR!\n");
  1893. test_control_return(109);
  1894. }
  1895. /* Now open the file again with an extra cluster at the end of the file... */
  1896. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1897. /* Check status. */
  1898. if (status != FX_SUCCESS)
  1899. {
  1900. /* Error, return error code. */
  1901. printf("ERROR!\n");
  1902. test_control_return(110);
  1903. }
  1904. /* Close the file again. */
  1905. fx_file_close(&my_file);
  1906. /* Now flush everything out. */
  1907. fx_media_flush(&ram_disk);
  1908. _fx_utility_FAT_flush(&ram_disk);
  1909. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1910. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1911. {
  1912. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1913. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1914. }
  1915. /* Read the first FAT sector. */
  1916. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1917. /* Fix the FAT chain. */
  1918. fat_buffer[4] = 0;
  1919. fat_buffer[5] = 0;
  1920. /* Write the FAT corruption out. */
  1921. status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1922. /* See if we are okay. */
  1923. if (status != FX_SUCCESS)
  1924. {
  1925. /* Error, return error code. */
  1926. printf("ERROR!\n");
  1927. test_control_return(111);
  1928. }
  1929. /* Now open the file again with an invalid last cluster at the end of the file... */
  1930. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1931. /* Check status. */
  1932. if (status != FX_FILE_CORRUPT)
  1933. {
  1934. /* Error, return error code. */
  1935. printf("ERROR!\n");
  1936. test_control_return(112);
  1937. }
  1938. /* Now flush everything out. */
  1939. fx_media_flush(&ram_disk);
  1940. _fx_utility_FAT_flush(&ram_disk);
  1941. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1942. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1943. {
  1944. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1945. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1946. }
  1947. /* Read the first FAT sector. */
  1948. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1949. /* Fix the FAT chain. */
  1950. fat_buffer[4] = 3;
  1951. fat_buffer[5] = 0;
  1952. fat_buffer[0x32] = 0;
  1953. fat_buffer[0x33] = 0;
  1954. /* Write the FAT corruption out. */
  1955. fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1956. /* Now open the file again with an invalid last cluster at the end of the file... */
  1957. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1958. /* Check status. */
  1959. if (status != FX_FILE_CORRUPT)
  1960. {
  1961. /* Error, return error code. */
  1962. printf("ERROR!\n");
  1963. test_control_return(113);
  1964. }
  1965. /* Now flush everything out. */
  1966. fx_media_flush(&ram_disk);
  1967. _fx_utility_FAT_flush(&ram_disk);
  1968. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1969. for (i = 0; i < FX_MAX_FAT_CACHE; i++)
  1970. {
  1971. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
  1972. ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
  1973. }
  1974. /* Read the first FAT sector. */
  1975. status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
  1976. /* Fix the FAT chain. */
  1977. fat_buffer[0x32] = 0xff;
  1978. fat_buffer[0x33] = 0xff;
  1979. /* Write the FAT corruption out. */
  1980. fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
  1981. /* Open the file. */
  1982. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  1983. status += fx_file_write(&my_file, buffer, 128*3);
  1984. status += fx_file_seek(&my_file, 0);
  1985. /* Set the flag to cause the cache update to bypass. */
  1986. _fx_utility_logical_sector_read_1_error_request = 1;
  1987. status += fx_file_read(&my_file, buffer, 128*3, &actual);
  1988. _fx_utility_logical_sector_read_1_error_request = 0;
  1989. /* Set the flag to cause the cache update to bypass - this time with a larger error value to make sure that path is taken. */
  1990. _fx_utility_logical_sector_read_1_error_request = 1000000;
  1991. status += fx_file_read(&my_file, buffer, 128*3, &actual);
  1992. _fx_utility_logical_sector_read_1_error_request = 0;
  1993. #ifndef FX_ENABLE_FAULT_TOLERANT
  1994. /* Call the logical sector flush with a large error value to get that path taken as well. */
  1995. _fx_utility_logical_sector_flush_error_request = 1000000;
  1996. status += _fx_utility_logical_sector_flush(&ram_disk, 0, 60000, FX_FALSE);
  1997. _fx_utility_logical_sector_flush_error_request = 0;
  1998. /* Check status. */
  1999. if (status != FX_SUCCESS)
  2000. {
  2001. /* Error, return error code. */
  2002. printf("ERROR!\n");
  2003. test_control_return(116);
  2004. }
  2005. #endif
  2006. /* Close everything down. */
  2007. fx_file_close(&my_file);
  2008. fx_media_abort(&ram_disk);
  2009. /* FAT32. */
  2010. status = fx_media_format(&ram_disk,
  2011. _fx_ram_driver, // Driver entry
  2012. ram_disk_memory, // RAM disk memory pointer
  2013. cache_buffer, // Media buffer pointer
  2014. CACHE_SIZE, // Media buffer size
  2015. "MY_RAM_DISK", // Volume Name
  2016. 1, // Number of FATs
  2017. 32, // Directory Entries
  2018. 0, // Hidden sectors
  2019. 70000, // Total sectors - FAT16
  2020. 512, // Sector size
  2021. 1, // Sectors per cluster
  2022. 1, // Heads
  2023. 1); // Sectors per track
  2024. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  2025. status += fx_file_create(&ram_disk, "TEST.TXT");
  2026. return_if_fail(FX_SUCCESS == status);
  2027. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  2028. status += fx_file_allocate(&my_file, 512);
  2029. status += fx_file_close(&my_file);
  2030. return_if_fail(FX_SUCCESS == status);
  2031. /* Open the file with a bad FAT chain. */
  2032. _fx_utility_FAT_entry_write(&ram_disk, 3, 0);
  2033. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  2034. return_if_fail(FX_FILE_CORRUPT == status);
  2035. fx_file_close(&my_file);
  2036. fx_media_close(&ram_disk);
  2037. printf("SUCCESS!\n");
  2038. test_control_return(0);
  2039. }