filex_media_check_test.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. /* This FileX test concentrates on the basic media check 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 16*128
  11. #define SCRATCH_MEMORY_SIZE 11000
  12. /* Define the ThreadX and FileX object control blocks... */
  13. #ifndef FX_STANDALONE_ENABLE
  14. static TX_THREAD ftest_0;
  15. #endif
  16. static FX_MEDIA ram_disk;
  17. static FX_FILE my_file;
  18. static UCHAR raw_sector_buffer[512];
  19. static UCHAR raw_sector_buffer_check[512];
  20. /* Define the counters used in the test application... */
  21. #ifndef FX_STANDALONE_ENABLE
  22. static UCHAR *ram_disk_memory;
  23. static UCHAR *cache_buffer;
  24. static UCHAR *scratch_memory;
  25. #else
  26. static UCHAR cache_buffer[CACHE_SIZE];
  27. static UCHAR scratch_memory[SCRATCH_MEMORY_SIZE];
  28. #endif
  29. /* Define thread prototypes. */
  30. void filex_media_check_application_define(void *first_unused_memory);
  31. static void ftest_0_entry(ULONG thread_input);
  32. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  33. void test_control_return(UINT status);
  34. /* Define what the initial system looks like. */
  35. #ifdef CTEST
  36. void test_application_define(void *first_unused_memory)
  37. #else
  38. void filex_media_check_application_define(void *first_unused_memory)
  39. #endif
  40. {
  41. #ifndef FX_STANDALONE_ENABLE
  42. UCHAR *pointer;
  43. /* Setup the working pointer. */
  44. pointer = (UCHAR *) first_unused_memory;
  45. /* Create the main thread. */
  46. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  47. pointer, DEMO_STACK_SIZE,
  48. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  49. pointer = pointer + DEMO_STACK_SIZE;
  50. /* Setup memory for the RAM disk and the sector cache. */
  51. cache_buffer = pointer;
  52. pointer = pointer + CACHE_SIZE;
  53. ram_disk_memory = pointer;
  54. pointer = pointer + (256*128);
  55. scratch_memory = pointer;
  56. #endif
  57. /* Initialize the FileX system. */
  58. fx_system_initialize();
  59. #ifdef FX_STANDALONE_ENABLE
  60. ftest_0_entry(0);
  61. #endif
  62. }
  63. /* Define the test threads. */
  64. static void ftest_0_entry(ULONG thread_input)
  65. {
  66. UINT status;
  67. ULONG errors_detected;
  68. UINT i, j;
  69. // A file name whose first byte is 0xe5.
  70. UCHAR specified_ascii_name[] = { 0xe5, 'a', 'b', 'c', 0};
  71. FX_PARAMETER_NOT_USED(thread_input);
  72. /* Print out some test information banners. */
  73. printf("FileX Test: Media check test.......................................");
  74. /* Format the media. This needs to be done before opening it! */
  75. status = fx_media_format(&ram_disk,
  76. _fx_ram_driver, // Driver entry
  77. ram_disk_memory, // RAM disk memory pointer
  78. cache_buffer, // Media buffer pointer
  79. CACHE_SIZE, // Media buffer size
  80. "MY_RAM_DISK", // Volume Name
  81. 1, // Number of FATs
  82. 32, // Directory Entries
  83. 0, // Hidden sectors
  84. 256, // Total sectors
  85. 128, // Sector size
  86. 1, // Sectors per cluster
  87. 1, // Heads
  88. 1); // Sectors per track
  89. return_if_fail( status == FX_SUCCESS);
  90. /* Try to check the media before the media has been opened */
  91. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  92. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  93. /* Open the ram_disk. */
  94. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  95. return_if_fail( status == FX_SUCCESS);
  96. /* Only run this if error checking is enabled */
  97. #ifndef FX_DISABLE_ERROR_CHECKING
  98. /* send null pointer to generate an error */
  99. status = fx_media_check(FX_NULL, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  100. return_if_fail( status == FX_PTR_ERROR);
  101. #endif /* FX_DISABLE_ERROR_CHECKING */
  102. /* Check the media for errors. */
  103. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  104. return_if_fail( (status == FX_SUCCESS) && (errors_detected == 0));
  105. /* Close the media and reopen. */
  106. status = fx_media_close(&ram_disk);
  107. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  108. return_if_fail( status == FX_SUCCESS);
  109. /* Invalidate the cache. */
  110. status = fx_media_cache_invalidate(&ram_disk);
  111. /* Read the first FAT sector. */
  112. status += fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  113. /* Check the status. */
  114. return_if_fail((status == FX_SUCCESS) &&
  115. (raw_sector_buffer[0] == 0xF8) && /* _fx_media_format_media_type value set during media format */
  116. (raw_sector_buffer[1] == 0xFF) &&
  117. (raw_sector_buffer[2] == 0xFF));
  118. /* Change the FAT table to introduce lost clusters! */
  119. raw_sector_buffer[30] = 2;
  120. raw_sector_buffer[31] = 3;
  121. raw_sector_buffer[32] = 4;
  122. /* Write the FAT sector back... with the errors. */
  123. status = fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  124. return_if_fail( status == FX_SUCCESS);
  125. /* Attempt to check the media but give it a bad scratch_memory_size to throw an error */
  126. status = fx_media_check(&ram_disk, scratch_memory, 0, 0, &errors_detected);
  127. return_if_fail( status == FX_NOT_ENOUGH_MEMORY);
  128. /* Attempt to check the media but give it a bad scratch_memory_size to throw an error */
  129. status = fx_media_check(&ram_disk, scratch_memory, (ram_disk.fx_media_total_clusters / 8), 0, &errors_detected);
  130. return_if_fail( status == FX_NOT_ENOUGH_MEMORY);
  131. /* Attempt to check the media but give it another bad scratch_memory_size to throw an error */
  132. status = fx_media_check(&ram_disk, scratch_memory, 977, 0, &errors_detected);
  133. return_if_fail( status == FX_NOT_ENOUGH_MEMORY);
  134. /* Check the media for errors. */
  135. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  136. return_if_fail( (status == FX_SUCCESS) && (errors_detected == FX_LOST_CLUSTER_ERROR));
  137. /* Check the media for errors again, but correct them this time! */
  138. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  139. return_if_fail( (status == FX_SUCCESS) && (errors_detected == FX_LOST_CLUSTER_ERROR));
  140. /* Check the media for errors again, but this time it should be successful. */
  141. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  142. /* Determine if any were found - should not have found any errors at this point. */
  143. return_if_fail( (status == FX_SUCCESS) && (errors_detected == 0));
  144. /* Close the media. */
  145. status = fx_media_close(&ram_disk);
  146. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  147. return_if_fail( status == FX_SUCCESS);
  148. /* Create a file in the root directory. */
  149. status = fx_file_create(&ram_disk, "TEXT.TXT");
  150. // Create the file whose name's first byte is 0xe5.
  151. status += fx_file_create(&ram_disk, (CHAR *)specified_ascii_name);
  152. status += fx_file_create(&ram_disk, "A somewhat long file name.txt");
  153. status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
  154. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  155. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  156. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  157. status += fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected); /* try to check the media while a file is open */
  158. status += fx_file_close(&my_file);
  159. status += fx_media_close(&ram_disk);
  160. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  161. /* Loop to clear the raw sector buffer... */
  162. for (i = 0; i < sizeof(raw_sector_buffer); i++)
  163. {
  164. raw_sector_buffer[i] = 0;
  165. }
  166. /* Setup original FAT table to break the File's cluster! */
  167. raw_sector_buffer[0] = 0x0F;
  168. raw_sector_buffer[1] = 0x0f;
  169. raw_sector_buffer[2] = 0xFF;
  170. /* Write the FAT sector back... with the errors. */
  171. status += fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  172. return_if_fail( status == FX_ACCESS_ERROR);
  173. /* Check the media for errors. */
  174. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  175. /* Determine if any were found - should not have found any errors at this point. */
  176. return_if_fail( (status == FX_SUCCESS) && (errors_detected == (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR)));
  177. /* Check the media for errors... and correct them this time! */
  178. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR), &errors_detected);
  179. /* Determine if any were found - should not have found any errors at this point. */
  180. return_if_fail( (status == FX_SUCCESS) && (errors_detected == (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR)));
  181. /* Check the media for errors... there should be none this time! */
  182. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR), &errors_detected);
  183. /* Determine if any were found - should not have found any errors at this point. */
  184. return_if_fail( (status == FX_SUCCESS) && (errors_detected == 0));
  185. /* Close the media. */
  186. status = fx_media_close(&ram_disk);
  187. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  188. status += fx_file_create(&ram_disk, "TEXT.TXT");
  189. status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
  190. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  191. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  192. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  193. status += fx_file_close(&my_file);
  194. status += fx_media_close(&ram_disk);
  195. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  196. /* Read the root directory's first sector. */
  197. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  198. /* Set the size to 1 to generate a file size error. */
  199. raw_sector_buffer[0x1C] = 1;
  200. raw_sector_buffer[0x1D] = 0;
  201. raw_sector_buffer[0x1E] = 0;
  202. raw_sector_buffer[0x1F] = 0;
  203. /* Write the root directory sector back... with the errors. */
  204. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  205. return_if_fail( status == FX_SUCCESS);
  206. /* Check the media for errors. */
  207. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  208. /* Determine if any were found - should not have found any errors at this point. */
  209. return_if_fail( (status == FX_SUCCESS) && (errors_detected == FX_FILE_SIZE_ERROR));
  210. /* Close the media. */
  211. status = fx_media_close(&ram_disk);
  212. return_if_fail( status == FX_SUCCESS);
  213. /* Clear the initial part of the RAM disk memory. */
  214. for (i = 0; i < 4096; i++)
  215. {
  216. ram_disk_memory[i] = 0;
  217. }
  218. /* Format the media. This needs to be done before opening it! */
  219. status = fx_media_format(&ram_disk,
  220. _fx_ram_driver, // Driver entry
  221. ram_disk_memory, // RAM disk memory pointer
  222. cache_buffer, // Media buffer pointer
  223. CACHE_SIZE, // Media buffer size
  224. "MY_RAM_DISK", // Volume Name
  225. 1, // Number of FATs
  226. 32, // Directory Entries
  227. 0, // Hidden sectors
  228. 256, // Total sectors
  229. 128, // Sector size
  230. 1, // Sectors per cluster
  231. 1, // Heads
  232. 1); // Sectors per track
  233. return_if_fail( status == FX_SUCCESS);
  234. /* Setup a new, more complicated directory structure. */
  235. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  236. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  237. status += fx_media_flush(&ram_disk);
  238. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  239. status += fx_media_flush(&ram_disk);
  240. status += fx_directory_create(&ram_disk, "\\SUB1");
  241. status += fx_media_flush(&ram_disk);
  242. status += fx_file_create(&ram_disk, "\\SUB1\\SUB1F1.TXT");
  243. status += fx_media_flush(&ram_disk);
  244. status += fx_file_create(&ram_disk, "\\SUB1\\SUB1F2.TXT");
  245. status += fx_media_flush(&ram_disk);
  246. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2");
  247. status += fx_media_flush(&ram_disk);
  248. status += fx_file_create(&ram_disk, "\\SUB1\\SUB2\\SUB2F1.TXT");
  249. status += fx_media_flush(&ram_disk);
  250. status += fx_file_create(&ram_disk, "\\SUB1\\SUB2\\SUB2F2.TXT");
  251. return_if_fail( status == FX_SUCCESS);
  252. /* Write data to the files... */
  253. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  254. status += fx_file_write(&my_file, "ROOT1_CONTENTS", 14);
  255. status += fx_file_close(&my_file);
  256. status += fx_media_flush(&ram_disk);
  257. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  258. status += fx_file_write(&my_file, "ROOT2_CONTENTS", 14);
  259. status += fx_file_close(&my_file);
  260. status += fx_media_flush(&ram_disk);
  261. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB1F1.TXT", FX_OPEN_FOR_WRITE);
  262. status += fx_file_write(&my_file, "SUB1F1_CONTENTS", 15);
  263. status += fx_file_close(&my_file);
  264. status += fx_media_flush(&ram_disk);
  265. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB1F2.TXT", FX_OPEN_FOR_WRITE);
  266. status += fx_file_write(&my_file, "SUB1F2_CONTENTS", 15);
  267. status += fx_file_close(&my_file);
  268. status += fx_media_flush(&ram_disk);
  269. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB2\\SUB2F1.TXT", FX_OPEN_FOR_WRITE);
  270. status += fx_file_write(&my_file, "SUB2F1_CONTENTS", 15);
  271. status += fx_file_close(&my_file);
  272. status += fx_media_flush(&ram_disk);
  273. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB2\\SUB2F2.TXT", FX_OPEN_FOR_WRITE);
  274. status += fx_file_write(&my_file, "SUB2F2_CONTENTS", 15);
  275. status += fx_file_close(&my_file);
  276. status += fx_media_flush(&ram_disk);
  277. return_if_fail( status == FX_SUCCESS);
  278. /* Check the media for errors. */
  279. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, 0, &errors_detected);
  280. return_if_fail( status == FX_SUCCESS);
  281. /* Close the media. */
  282. status = fx_media_close(&ram_disk);
  283. return_if_fail( status == FX_SUCCESS);
  284. /* Clear the initial part of the RAM disk memory. */
  285. for (i = 0; i < 4096; i++)
  286. {
  287. ram_disk_memory[i] = 0;
  288. }
  289. /* Format the media. This needs to be done before opening it! */
  290. status = fx_media_format(&ram_disk,
  291. _fx_ram_driver, // Driver entry
  292. ram_disk_memory, // RAM disk memory pointer
  293. cache_buffer, // Media buffer pointer
  294. CACHE_SIZE, // Media buffer size
  295. "MY_RAM_DISK", // Volume Name
  296. 1, // Number of FATs
  297. 32, // Directory Entries
  298. 0, // Hidden sectors
  299. 70000, // Total sectors
  300. 128, // Sector size
  301. 1, // Sectors per cluster
  302. 1, // Heads
  303. 1); // Sectors per track
  304. return_if_fail( status == FX_SUCCESS);
  305. /* Setup a new, more complicated directory structure. */
  306. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  307. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  308. status += fx_media_flush(&ram_disk);
  309. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  310. status += fx_media_flush(&ram_disk);
  311. status += fx_directory_create(&ram_disk, "\\SUB1");
  312. status += fx_media_flush(&ram_disk);
  313. status += fx_file_create(&ram_disk, "\\SUB1\\SUB1F1.TXT");
  314. status += fx_media_flush(&ram_disk);
  315. status += fx_file_create(&ram_disk, "\\SUB1\\SUB1F2.TXT");
  316. status += fx_media_flush(&ram_disk);
  317. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2");
  318. status += fx_media_flush(&ram_disk);
  319. status += fx_file_create(&ram_disk, "\\SUB1\\SUB2\\SUB2F1.TXT");
  320. status += fx_media_flush(&ram_disk);
  321. status += fx_file_create(&ram_disk, "\\SUB1\\SUB2\\SUB2F2.TXT");
  322. return_if_fail( status == FX_SUCCESS);
  323. /* Write data to the files... */
  324. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  325. status += fx_file_write(&my_file, "ROOT1_CONTENTS", 14);
  326. status += fx_file_close(&my_file);
  327. status += fx_media_flush(&ram_disk);
  328. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  329. status += fx_file_write(&my_file, "ROOT2_CONTENTS", 14);
  330. status += fx_file_close(&my_file);
  331. status += fx_media_flush(&ram_disk);
  332. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB1F1.TXT", FX_OPEN_FOR_WRITE);
  333. status += fx_file_write(&my_file, "SUB1F1_CONTENTS", 15);
  334. status += fx_file_close(&my_file);
  335. status += fx_media_flush(&ram_disk);
  336. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB1F2.TXT", FX_OPEN_FOR_WRITE);
  337. status += fx_file_write(&my_file, "SUB1F2_CONTENTS", 15);
  338. status += fx_file_close(&my_file);
  339. status += fx_media_flush(&ram_disk);
  340. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB2\\SUB2F1.TXT", FX_OPEN_FOR_WRITE);
  341. status += fx_file_write(&my_file, "SUB2F1_CONTENTS", 15);
  342. status += fx_file_close(&my_file);
  343. status += fx_media_flush(&ram_disk);
  344. status += fx_file_open(&ram_disk, &my_file, "\\SUB1\\SUB2\\SUB2F2.TXT", FX_OPEN_FOR_WRITE);
  345. status += fx_file_write(&my_file, "SUB2F2_CONTENTS", 15);
  346. status += fx_file_close(&my_file);
  347. status += fx_media_flush(&ram_disk);
  348. return_if_fail( status == FX_SUCCESS);
  349. /* Check the media for errors. */
  350. status = fx_media_check(&ram_disk, scratch_memory, 11000, 0, &errors_detected);
  351. return_if_fail( status == FX_SUCCESS);
  352. /* Close the media. */
  353. status = fx_media_close(&ram_disk);
  354. return_if_fail( status == FX_SUCCESS);
  355. /* Test for two files with the same FAT chain. */
  356. /* Clear the initial part of the RAM disk memory. */
  357. for (i = 0; i < 4096; i++)
  358. {
  359. ram_disk_memory[i] = 0;
  360. }
  361. /* Format the media. This needs to be done before opening it! */
  362. status = fx_media_format(&ram_disk,
  363. _fx_ram_driver, // Driver entry
  364. ram_disk_memory, // RAM disk memory pointer
  365. cache_buffer, // Media buffer pointer
  366. CACHE_SIZE, // Media buffer size
  367. "MY_RAM_DISK", // Volume Name
  368. 1, // Number of FATs
  369. 32, // Directory Entries
  370. 0, // Hidden sectors
  371. 6000, // Total sectors - FAT16
  372. 128, // Sector size
  373. 1, // Sectors per cluster
  374. 1, // Heads
  375. 1); // Sectors per track
  376. return_if_fail( status == FX_SUCCESS);
  377. /* Setup a new, more complicated directory structure. */
  378. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  379. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  380. status += fx_media_flush(&ram_disk);
  381. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  382. status += fx_media_flush(&ram_disk);
  383. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  384. status += fx_media_flush(&ram_disk);
  385. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  386. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  387. status += fx_file_close(&my_file);
  388. status += fx_media_flush(&ram_disk);
  389. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  390. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  391. status += fx_file_close(&my_file);
  392. status += fx_media_flush(&ram_disk);
  393. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  394. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  395. status += fx_file_close(&my_file);
  396. status += fx_media_flush(&ram_disk);
  397. return_if_fail( status == FX_SUCCESS);
  398. /* Read the root directory's first sector. */
  399. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  400. /* Set the second file's FAT chain to the same as the first. */
  401. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  402. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  403. /* Write the root directory sector back... with the errors. */
  404. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  405. status += fx_media_flush(&ram_disk);
  406. /* Read the first FAT sector. */
  407. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  408. /* Break the FAT chain of the ROOTF1.TXT file. */
  409. raw_sector_buffer[14] = 0;
  410. raw_sector_buffer[15] = 0;
  411. /* Write the root directory sector back... with the errors. */
  412. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  413. status += fx_media_flush(&ram_disk);
  414. return_if_fail( status == FX_SUCCESS);
  415. /* Check the media for errors. */
  416. status = fx_media_check(&ram_disk, scratch_memory, 4000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  417. return_if_fail((status == FX_SUCCESS) && (errors_detected == (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR)));
  418. /* Close the media. */
  419. status = fx_media_close(&ram_disk);
  420. return_if_fail( status == FX_SUCCESS);
  421. /* Test I/O errors in the two files with the same FAT chain test.... */
  422. /* Clear the initial part of the RAM disk memory. */
  423. for (i = 0; i < 4096; i++)
  424. {
  425. ram_disk_memory[i] = 0;
  426. }
  427. /* Loop to run through multiple tests... */
  428. for (i = 0; i < 1000; i++)
  429. {
  430. /* Format the media. This needs to be done before opening it! */
  431. status = fx_media_format(&ram_disk,
  432. _fx_ram_driver, // Driver entry
  433. ram_disk_memory, // RAM disk memory pointer
  434. cache_buffer, // Media buffer pointer
  435. CACHE_SIZE, // Media buffer size
  436. "MY_RAM_DISK", // Volume Name
  437. 1, // Number of FATs
  438. 32, // Directory Entries
  439. 0, // Hidden sectors
  440. 6000, // Total sectors - FAT16
  441. 128, // Sector size
  442. 1, // Sectors per cluster
  443. 1, // Heads
  444. 1); // Sectors per track
  445. return_if_fail( status == FX_SUCCESS);
  446. /* Setup a new, more complicated directory structure. */
  447. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128 /*CACHE_SIZE*/);
  448. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  449. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  450. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  451. status += fx_media_flush(&ram_disk);
  452. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  453. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  454. status += fx_file_close(&my_file);
  455. status += fx_media_flush(&ram_disk);
  456. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  457. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  458. status += fx_file_close(&my_file);
  459. status += fx_media_flush(&ram_disk);
  460. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  461. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  462. status += fx_file_close(&my_file);
  463. /* Create some more files and sub-directories to give the media check some more work to do. */
  464. status += fx_file_create(&ram_disk, "ROOTF4.TXT");
  465. status += fx_file_create(&ram_disk, "ROOTF5.TXT");
  466. status += fx_file_create(&ram_disk, "ROOTF6.TXT");
  467. status += fx_file_create(&ram_disk, "ROOTF7.TXT");
  468. status += fx_file_create(&ram_disk, "ROOTF8.TXT");
  469. status += fx_file_create(&ram_disk, "ROOTF9.TXT");
  470. status += fx_file_create(&ram_disk, "ROOTF10.TXT");
  471. status += fx_file_create(&ram_disk, "ROOTF11.TXT");
  472. status += fx_file_create(&ram_disk, "ROOTF12.TXT");
  473. status += fx_file_create(&ram_disk, "ROOTF13.TXT");
  474. status += fx_file_create(&ram_disk, "ROOTF14.TXT");
  475. status += fx_file_create(&ram_disk, "ROOTF15.TXT");
  476. status += fx_file_create(&ram_disk, "ROOTF16.TXT");
  477. status += fx_file_create(&ram_disk, "ROOTF17.TXT");
  478. status += fx_file_create(&ram_disk, "ROOTF18.TXT");
  479. status += fx_file_create(&ram_disk, "ROOTF19.TXT");
  480. status += fx_file_create(&ram_disk, "ROOTF20.TXT");
  481. status += fx_directory_create(&ram_disk, "SUB4");
  482. status += fx_directory_create(&ram_disk, "SUB5");
  483. status += fx_directory_create(&ram_disk, "SUB6");
  484. status += fx_directory_create(&ram_disk, "SUB7");
  485. status += fx_directory_create(&ram_disk, "SUB8");
  486. status += fx_directory_create(&ram_disk, "SUB9");
  487. status += fx_directory_create(&ram_disk, "SUB10");
  488. status += fx_directory_create(&ram_disk, "SUB11");
  489. status += fx_directory_create(&ram_disk, "SUB12");
  490. status += fx_directory_create(&ram_disk, "SUB13");
  491. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF14.TXT");
  492. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF15.TXT");
  493. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF16.TXT");
  494. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF17.TXT");
  495. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF18.TXT");
  496. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF19.TXT");
  497. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF20.TXT");
  498. status += fx_media_flush(&ram_disk);
  499. return_if_fail( status == FX_SUCCESS);
  500. /* Read the root directory's first sector. */
  501. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  502. /* Set the second file's FAT chain starting cluster to the same as the first. */
  503. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  504. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  505. /* Write the root directory sector back... with the errors. */
  506. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  507. status += fx_media_flush(&ram_disk);
  508. /* Read the first FAT sector. */
  509. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  510. /* Break the FAT chain of the ROOTF3.TXT file. */
  511. if (i & 1)
  512. {
  513. /* Break with bad FAT value. */
  514. raw_sector_buffer[14] = 0;
  515. raw_sector_buffer[15] = 0;
  516. }
  517. else
  518. {
  519. /* Break with reserved fAT value. */
  520. raw_sector_buffer[14] = 0xF0;
  521. raw_sector_buffer[15] = 0xFF;
  522. }
  523. /* Write the root directory sector back... with the errors. */
  524. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  525. status += fx_media_flush(&ram_disk);
  526. return_if_fail( status == FX_SUCCESS);
  527. /* Create I/O errors via the RAM driver interface. */
  528. _fx_utility_FAT_flush(&ram_disk);
  529. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  530. j = (UINT)(rand() % 20);
  531. if (j == 0)
  532. j = 1;
  533. _fx_ram_driver_io_error_request = j;
  534. /* Check the media for errors. */
  535. fx_media_check(&ram_disk, scratch_memory, 4000, (((ULONG) i) % 16), &errors_detected);
  536. /* Clear the error generation flags. */
  537. _fx_ram_driver_io_error_request = 0;
  538. /* Abort the media. */
  539. fx_media_abort(&ram_disk);
  540. }
  541. /* FAT32 I/O error check. */
  542. /* Loop to run through multiple tests... */
  543. for (i = 0; i < 1000; i++)
  544. {
  545. /* Format the media. This needs to be done before opening it! */
  546. status = fx_media_format(&ram_disk,
  547. _fx_ram_driver, // Driver entry
  548. ram_disk_memory, // RAM disk memory pointer
  549. cache_buffer, // Media buffer pointer
  550. CACHE_SIZE, // Media buffer size
  551. "MY_RAM_DISK", // Volume Name
  552. 1, // Number of FATs
  553. 32, // Directory Entries
  554. 0, // Hidden sectors
  555. 70000, // Total sectors - FAT32
  556. 128, // Sector size
  557. 1, // Sectors per cluster
  558. 1, // Heads
  559. 1); // Sectors per track
  560. return_if_fail( status == FX_SUCCESS);
  561. /* Setup a new, more complicated directory structure. */
  562. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128 /*CACHE_SIZE*/);
  563. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  564. status += fx_media_flush(&ram_disk);
  565. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  566. status += fx_media_flush(&ram_disk);
  567. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  568. status += fx_media_flush(&ram_disk);
  569. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  570. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  571. status += fx_file_close(&my_file);
  572. status += fx_media_flush(&ram_disk);
  573. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  574. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  575. status += fx_file_close(&my_file);
  576. status += fx_media_flush(&ram_disk);
  577. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  578. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  579. status += fx_file_close(&my_file);
  580. /* Create some more files and sub-directories to give the media check some more work to do. */
  581. status += fx_file_create(&ram_disk, "ROOTF4.TXT");
  582. status += fx_file_create(&ram_disk, "ROOTF5.TXT");
  583. status += fx_file_create(&ram_disk, "ROOTF6.TXT");
  584. status += fx_file_create(&ram_disk, "ROOTF7.TXT");
  585. status += fx_file_create(&ram_disk, "ROOTF8.TXT");
  586. status += fx_file_create(&ram_disk, "ROOTF9.TXT");
  587. status += fx_file_create(&ram_disk, "ROOTF10.TXT");
  588. status += fx_file_create(&ram_disk, "ROOTF11.TXT");
  589. status += fx_file_create(&ram_disk, "ROOTF12.TXT");
  590. status += fx_file_create(&ram_disk, "ROOTF13.TXT");
  591. status += fx_file_create(&ram_disk, "ROOTF14.TXT");
  592. status += fx_file_create(&ram_disk, "ROOTF15.TXT");
  593. status += fx_file_create(&ram_disk, "ROOTF16.TXT");
  594. status += fx_file_create(&ram_disk, "ROOTF17.TXT");
  595. status += fx_file_create(&ram_disk, "ROOTF18.TXT");
  596. status += fx_file_create(&ram_disk, "ROOTF19.TXT");
  597. status += fx_file_create(&ram_disk, "ROOTF20.TXT");
  598. status += fx_directory_create(&ram_disk, "SUB4");
  599. status += fx_directory_create(&ram_disk, "SUB5");
  600. status += fx_directory_create(&ram_disk, "SUB6");
  601. status += fx_directory_create(&ram_disk, "SUB7");
  602. status += fx_directory_create(&ram_disk, "SUB8");
  603. status += fx_directory_create(&ram_disk, "SUB9");
  604. status += fx_directory_create(&ram_disk, "SUB10");
  605. status += fx_directory_create(&ram_disk, "SUB11");
  606. status += fx_directory_create(&ram_disk, "SUB12");
  607. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF14.TXT");
  608. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF15.TXT");
  609. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF16.TXT");
  610. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF17.TXT");
  611. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF18.TXT");
  612. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF19.TXT");
  613. status += fx_file_create(&ram_disk, "\\SUB4\\ROOTF20.TXT");
  614. status += fx_media_flush(&ram_disk);
  615. return_if_fail( status == FX_SUCCESS);
  616. /* Read the root directory's first sector. */
  617. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  618. /* Set the second file's FAT chain starting cluster to the same as the first. */
  619. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  620. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  621. /* Write the root directory sector back... with the errors. */
  622. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  623. status += fx_media_flush(&ram_disk);
  624. /* Read the first FAT sector. */
  625. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  626. /* Break the FAT chain of the ROOTF3.TXT file. */
  627. if (i & 1)
  628. {
  629. /* Break with NULL FAT value. */
  630. raw_sector_buffer[32] = 0;
  631. raw_sector_buffer[33] = 0;
  632. raw_sector_buffer[34] = 0;
  633. raw_sector_buffer[35] = 0;
  634. }
  635. else
  636. {
  637. /* Break with Reserved FAT value. */
  638. raw_sector_buffer[32] = 0xF0;
  639. raw_sector_buffer[33] = 0xFF;
  640. raw_sector_buffer[34] = 0xFF;
  641. raw_sector_buffer[35] = 0xFF;
  642. }
  643. /* Write the root directory sector back... with the errors. */
  644. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  645. status += fx_media_flush(&ram_disk);
  646. return_if_fail( status == FX_SUCCESS);
  647. /* Create I/O errors via the RAM driver interface. */
  648. _fx_utility_FAT_flush(&ram_disk);
  649. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  650. j = (UINT)(rand() % 10);
  651. if (j == 0)
  652. j = 1;
  653. _fx_ram_driver_io_error_request = j;
  654. /* Check the media for errors. */
  655. fx_media_check(&ram_disk, scratch_memory, 4000, (((ULONG) i) % 16), &errors_detected);
  656. /* Clear the error generation flags. */
  657. _fx_ram_driver_io_error_request = 0;
  658. /* Abort the media. */
  659. fx_media_abort(&ram_disk);
  660. }
  661. /* FAT32 Test for two files with the same FAT chain. */
  662. /* Clear the initial part of the RAM disk memory. */
  663. for (i = 0; i < 4096; i++)
  664. {
  665. ram_disk_memory[i] = 0;
  666. }
  667. /* Format the media. This needs to be done before opening it! */
  668. status = fx_media_format(&ram_disk,
  669. _fx_ram_driver, // Driver entry
  670. ram_disk_memory, // RAM disk memory pointer
  671. cache_buffer, // Media buffer pointer
  672. CACHE_SIZE, // Media buffer size
  673. "MY_RAM_DISK", // Volume Name
  674. 1, // Number of FATs
  675. 32, // Directory Entries
  676. 0, // Hidden sectors
  677. 70000, // Total sectors - FAT32
  678. 128, // Sector size
  679. 1, // Sectors per cluster
  680. 1, // Heads
  681. 1); // Sectors per track
  682. /* Determine if the format had an error. */
  683. if (status)
  684. {
  685. printf("ERROR!\n");
  686. test_control_return(33);
  687. }
  688. /* Setup a new, more complicated directory structure. */
  689. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  690. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  691. status += fx_media_flush(&ram_disk);
  692. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  693. status += fx_media_flush(&ram_disk);
  694. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  695. status += fx_media_flush(&ram_disk);
  696. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  697. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  698. status += fx_file_close(&my_file);
  699. status += fx_media_flush(&ram_disk);
  700. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  701. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  702. status += fx_file_close(&my_file);
  703. status += fx_media_flush(&ram_disk);
  704. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  705. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  706. status += fx_file_close(&my_file);
  707. status += fx_media_flush(&ram_disk);
  708. return_if_fail( status == FX_SUCCESS);
  709. /* Read the root directory's first sector. */
  710. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  711. /* Set the second file's FAT chain to the same as the first. */
  712. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  713. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  714. /* Write the root directory sector back... with the errors. */
  715. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  716. status += fx_media_flush(&ram_disk);
  717. /* Read the first FAT sector. */
  718. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  719. /* Break the FAT chain of the ROOTF3.TXT file. */
  720. raw_sector_buffer[32] = 0;
  721. raw_sector_buffer[33] = 0;
  722. raw_sector_buffer[34] = 0;
  723. raw_sector_buffer[35] = 0;
  724. /* Write the root directory sector back... with the errors. */
  725. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  726. status += fx_media_flush(&ram_disk);
  727. return_if_fail( status == FX_SUCCESS);
  728. /* Check the media for errors. */
  729. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  730. /* Determine if any were found - should not have found any errors at this point. */
  731. return_if_fail((status == FX_SUCCESS) && (errors_detected == (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR)));
  732. /* Close the media. */
  733. status = fx_media_close(&ram_disk);
  734. return_if_fail( status == FX_SUCCESS);
  735. /* FAT32 Test for two files with the same FAT chain and a broken root directory FAT chain. */
  736. /* Clear the initial part of the RAM disk memory. */
  737. for (i = 0; i < 4096; i++)
  738. {
  739. ram_disk_memory[i] = 0;
  740. }
  741. /* Format the media. This needs to be done before opening it! */
  742. status = fx_media_format(&ram_disk,
  743. _fx_ram_driver, // Driver entry
  744. ram_disk_memory, // RAM disk memory pointer
  745. cache_buffer, // Media buffer pointer
  746. CACHE_SIZE, // Media buffer size
  747. "MY_RAM_DISK", // Volume Name
  748. 1, // Number of FATs
  749. 32, // Directory Entries
  750. 0, // Hidden sectors
  751. 70000, // Total sectors - FAT32
  752. 128, // Sector size
  753. 1, // Sectors per cluster
  754. 1, // Heads
  755. 1); // Sectors per track
  756. return_if_fail( status == FX_SUCCESS);
  757. /* Setup a new, more complicated directory structure. */
  758. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  759. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  760. status += fx_media_flush(&ram_disk);
  761. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  762. status += fx_media_flush(&ram_disk);
  763. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  764. status += fx_media_flush(&ram_disk);
  765. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  766. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  767. status += fx_file_close(&my_file);
  768. status += fx_media_flush(&ram_disk);
  769. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  770. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  771. status += fx_file_close(&my_file);
  772. status += fx_media_flush(&ram_disk);
  773. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  774. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  775. status += fx_file_close(&my_file);
  776. status += fx_media_flush(&ram_disk);
  777. return_if_fail( status == FX_SUCCESS);
  778. /* Read the root directory's first sector. */
  779. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  780. /* Set the second file's FAT chain to the same as the first. */
  781. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  782. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  783. /* Write the root directory sector back... with the errors. */
  784. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  785. status += fx_media_flush(&ram_disk);
  786. /* Read the first FAT sector. */
  787. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  788. /* Break the FAT chain of the root directory in FAT32. */
  789. raw_sector_buffer[8] = 0;
  790. raw_sector_buffer[9] = 0;
  791. raw_sector_buffer[10] = 0;
  792. raw_sector_buffer[11] = 0;
  793. /* Break the FAT chain of the ROOTF3.TXT file. */
  794. raw_sector_buffer[32] = 0;
  795. raw_sector_buffer[33] = 0;
  796. raw_sector_buffer[34] = 0;
  797. raw_sector_buffer[35] = 0;
  798. /* Write the root directory sector back... with the errors. */
  799. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  800. status += fx_media_flush(&ram_disk);
  801. return_if_fail( status == FX_SUCCESS);
  802. /* Check the media for errors. */
  803. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  804. return_if_fail( status == FX_ERROR_NOT_FIXED);
  805. /* Close the media. */
  806. status = fx_media_close(&ram_disk);
  807. return_if_fail( status == FX_SUCCESS);
  808. /* Test a full disk with a maximum cluster FAT chain. */
  809. /* Clear the initial part of the RAM disk memory. */
  810. for (i = 0; i < 4096; i++)
  811. {
  812. ram_disk_memory[i] = 0;
  813. }
  814. /* Format the media. This needs to be done before opening it! */
  815. status = fx_media_format(&ram_disk,
  816. _fx_ram_driver, // Driver entry
  817. ram_disk_memory, // RAM disk memory pointer
  818. cache_buffer, // Media buffer pointer
  819. CACHE_SIZE, // Media buffer size
  820. "MY_RAM_DISK", // Volume Name
  821. 1, // Number of FATs
  822. 32, // Directory Entries
  823. 0, // Hidden sectors
  824. 6000, // Total sectors - FAT32
  825. 128, // Sector size
  826. 1, // Sectors per cluster
  827. 1, // Heads
  828. 1); // Sectors per track
  829. return_if_fail( status == FX_SUCCESS);
  830. /* Setup a new, more complicated directory structure. */
  831. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  832. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  833. status += fx_media_flush(&ram_disk);
  834. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  835. do
  836. {
  837. status = fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  838. } while (status == FX_SUCCESS);
  839. /* Determine if the write had anything other than a no more space error. */
  840. return_if_fail( status == FX_NO_MORE_SPACE);
  841. status = fx_file_close(&my_file);
  842. status += fx_media_flush(&ram_disk);
  843. return_if_fail( status == FX_SUCCESS);
  844. /* Reduce the amount of clusters just to exercise the branch in the FAT chain search. */
  845. ram_disk.fx_media_total_clusters = ram_disk.fx_media_total_clusters - 4;
  846. /* Check the media for errors. */
  847. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  848. /* Undo the cluster adjustment. */
  849. ram_disk.fx_media_total_clusters = ram_disk.fx_media_total_clusters + 4;
  850. return_if_fail( status == FX_SUCCESS);
  851. /* Close the media. */
  852. status = fx_media_close(&ram_disk);
  853. return_if_fail( status == FX_SUCCESS);
  854. /* Test sub-directory corruption problems. */
  855. /* Clear the initial part of the RAM disk memory. */
  856. for (i = 0; i < 4096; i++)
  857. {
  858. ram_disk_memory[i] = 0;
  859. }
  860. /* Format the media. This needs to be done before opening it! */
  861. status = fx_media_format(&ram_disk,
  862. _fx_ram_driver, // Driver entry
  863. ram_disk_memory, // RAM disk memory pointer
  864. cache_buffer, // Media buffer pointer
  865. CACHE_SIZE, // Media buffer size
  866. "MY_RAM_DISK", // Volume Name
  867. 1, // Number of FATs
  868. 32, // Directory Entries
  869. 0, // Hidden sectors
  870. 6000, // Total sectors - FAT16
  871. 128, // Sector size
  872. 1, // Sectors per cluster
  873. 1, // Heads
  874. 1); // Sectors per track
  875. return_if_fail( status == FX_SUCCESS);
  876. /* Setup a deep directory structure. */
  877. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  878. status += fx_directory_create(&ram_disk, "\\DIR1");
  879. status += fx_file_create(&ram_disk, "\\DIR1\\SUB1");
  880. status += fx_file_create(&ram_disk, "\\DIR1\\SUB2");
  881. status += fx_file_create(&ram_disk, "\\DIR1\\SUB3");
  882. status += fx_file_create(&ram_disk, "\\DIR1\\SUB4");
  883. status += fx_file_create(&ram_disk, "\\DIR1\\SUB5");
  884. status += fx_file_create(&ram_disk, "\\DIR1\\SUB6");
  885. status += fx_file_create(&ram_disk, "\\DIR1\\SUB7");
  886. status += fx_file_create(&ram_disk, "\\DIR1\\SUB8");
  887. status += fx_file_create(&ram_disk, "\\DIR1\\SUB9");
  888. status += fx_file_create(&ram_disk, "\\DIR1\\SUB10");
  889. status += fx_file_create(&ram_disk, "\\DIR1\\SUB11");
  890. status += fx_media_flush(&ram_disk);
  891. return_if_fail( status == FX_SUCCESS);
  892. /* Read the first FAT sector. */
  893. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  894. /* Break the FAT chain of the in the first sub directory. */
  895. raw_sector_buffer[10] = 0;
  896. raw_sector_buffer[11] = 0;
  897. /* Write the root directory sector back... with the errors. */
  898. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  899. status += fx_media_flush(&ram_disk);
  900. return_if_fail( status == FX_SUCCESS);
  901. /* Check the media for errors. */
  902. status = fx_media_check(&ram_disk, scratch_memory, 4000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  903. /* Determine if any were found - should not have found any errors at this point. */
  904. return_if_fail((status == FX_SUCCESS) && (errors_detected == FX_FAT_CHAIN_ERROR));
  905. /* Close the media. */
  906. status = fx_media_close(&ram_disk);
  907. return_if_fail( status == FX_SUCCESS);
  908. /* FAT32 Test for root directory FAT chain recovery. */
  909. /* Clear the initial part of the RAM disk memory. */
  910. for (i = 0; i < 4096; i++)
  911. {
  912. ram_disk_memory[i] = 0;
  913. }
  914. /* Format the media. This needs to be done before opening it! */
  915. status = fx_media_format(&ram_disk,
  916. _fx_ram_driver, // Driver entry
  917. ram_disk_memory, // RAM disk memory pointer
  918. cache_buffer, // Media buffer pointer
  919. CACHE_SIZE, // Media buffer size
  920. "MY_RAM_DISK", // Volume Name
  921. 1, // Number of FATs
  922. 32, // Directory Entries
  923. 0, // Hidden sectors
  924. 70000, // Total sectors - FAT32
  925. 128, // Sector size
  926. 1, // Sectors per cluster
  927. 1, // Heads
  928. 1); // Sectors per track
  929. return_if_fail( status == FX_SUCCESS);
  930. /* Setup a new, more complicated directory structure. */
  931. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  932. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  933. status += fx_media_flush(&ram_disk);
  934. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  935. status += fx_media_flush(&ram_disk);
  936. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  937. status += fx_media_flush(&ram_disk);
  938. status += fx_file_create(&ram_disk, "ROOTF4.TXT");
  939. status += fx_media_flush(&ram_disk);
  940. status += fx_file_create(&ram_disk, "ROOTF5.TXT");
  941. status += fx_media_flush(&ram_disk);
  942. status += fx_file_create(&ram_disk, "ROOTF6.TXT");
  943. status += fx_media_flush(&ram_disk);
  944. status += fx_file_create(&ram_disk, "ROOTF7.TXT");
  945. status += fx_media_flush(&ram_disk);
  946. status += fx_file_create(&ram_disk, "ROOTF8.TXT");
  947. status += fx_media_flush(&ram_disk);
  948. status += fx_file_create(&ram_disk, "ROOTF9.TXT");
  949. status += fx_media_flush(&ram_disk);
  950. status += fx_file_create(&ram_disk, "ROOTF10.TXT");
  951. status += fx_media_flush(&ram_disk);
  952. return_if_fail( status == FX_SUCCESS);
  953. /* Read the first FAT sector. */
  954. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  955. /* Break the FAT chain of the root directory in FAT32. */
  956. raw_sector_buffer[12] = 0;
  957. raw_sector_buffer[13] = 0;
  958. raw_sector_buffer[14] = 0;
  959. raw_sector_buffer[15] = 0;
  960. /* Write the root directory sector back... with the errors. */
  961. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  962. status += fx_media_flush(&ram_disk);
  963. return_if_fail( status == FX_SUCCESS);
  964. /* Check the media for errors. */
  965. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  966. #if 0
  967. return_if_fail( status == FX_SECTOR_INVALID);
  968. #else
  969. return_if_fail( status == FX_SUCCESS);
  970. #endif
  971. /* Close the media. */
  972. status = fx_media_close(&ram_disk);
  973. return_if_fail( status == FX_SUCCESS);
  974. /* Test a full disk with a FAT chain that has a bad pointer to itself. */
  975. /* Clear the initial part of the RAM disk memory. */
  976. for (i = 0; i < 4096; i++)
  977. {
  978. ram_disk_memory[i] = 0;
  979. }
  980. /* Format the media. This needs to be done before opening it! */
  981. status = fx_media_format(&ram_disk,
  982. _fx_ram_driver, // Driver entry
  983. ram_disk_memory, // RAM disk memory pointer
  984. cache_buffer, // Media buffer pointer
  985. CACHE_SIZE, // Media buffer size
  986. "MY_RAM_DISK", // Volume Name
  987. 1, // Number of FATs
  988. 32, // Directory Entries
  989. 0, // Hidden sectors
  990. 6000, // Total sectors - FAT32
  991. 128, // Sector size
  992. 1, // Sectors per cluster
  993. 1, // Heads
  994. 1); // Sectors per track
  995. return_if_fail( status == FX_SUCCESS);
  996. /* Setup a new, more complicated directory structure. */
  997. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  998. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  999. status += fx_media_flush(&ram_disk);
  1000. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  1001. do
  1002. {
  1003. status = fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1004. } while (status == FX_SUCCESS);
  1005. /* Determine if the write had anything other than a no more space error. */
  1006. return_if_fail( status == FX_NO_MORE_SPACE);
  1007. status = fx_file_close(&my_file);
  1008. status += fx_media_flush(&ram_disk);
  1009. return_if_fail( status == FX_SUCCESS);
  1010. /* Read the first FAT sector. */
  1011. status = fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1012. /* Make the FAT chain recursive. */
  1013. raw_sector_buffer[6] = raw_sector_buffer[4];
  1014. raw_sector_buffer[7] = raw_sector_buffer[5];
  1015. /* Write the root directory sector back... with the errors. */
  1016. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1017. status += fx_media_flush(&ram_disk);
  1018. /* Check the media for errors. */
  1019. status += fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1020. return_if_fail( status == FX_SUCCESS);
  1021. /* Close the media. */
  1022. status = fx_media_close(&ram_disk);
  1023. return_if_fail( status == FX_SUCCESS);
  1024. /* Test a full disk with a sub-directory that has a bad FAT chain. */
  1025. /* Clear the initial part of the RAM disk memory. */
  1026. for (i = 0; i < 4096; i++)
  1027. {
  1028. ram_disk_memory[i] = 0;
  1029. }
  1030. /* Format the media. This needs to be done before opening it! */
  1031. status = fx_media_format(&ram_disk,
  1032. _fx_ram_driver, // Driver entry
  1033. ram_disk_memory, // RAM disk memory pointer
  1034. cache_buffer, // Media buffer pointer
  1035. CACHE_SIZE, // Media buffer size
  1036. "MY_RAM_DISK", // Volume Name
  1037. 1, // Number of FATs
  1038. 32, // Directory Entries
  1039. 0, // Hidden sectors
  1040. 6000, // Total sectors - FAT32
  1041. 128, // Sector size
  1042. 1, // Sectors per cluster
  1043. 1, // Heads
  1044. 1); // Sectors per track
  1045. return_if_fail( status == FX_SUCCESS);
  1046. /* Setup a new, more complicated directory structure. */
  1047. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1048. status += fx_directory_create(&ram_disk, "SUB1");
  1049. status += fx_media_flush(&ram_disk);
  1050. return_if_fail( status == FX_SUCCESS);
  1051. /* Read the first FAT sector. */
  1052. status = fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1053. /* Make the FAT chain recursive. */
  1054. raw_sector_buffer[4] = 0;
  1055. raw_sector_buffer[5] = 0;
  1056. /* Write the FAT sector back... with the errors. */
  1057. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1058. status += fx_media_flush(&ram_disk);
  1059. /* Read the root directory's first sector. */
  1060. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1061. /* Check the media for errors. */
  1062. status += fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1063. return_if_fail( status == FX_SUCCESS);
  1064. /* Close the media. */
  1065. status = fx_media_close(&ram_disk);
  1066. return_if_fail( status == FX_SUCCESS);
  1067. /* Test sub-directory depth that exceeds FX_MAX_DIRECTORY_NESTING (which is by default 20). */
  1068. /* Clear the initial part of the RAM disk memory. */
  1069. for (i = 0; i < 4096; i++)
  1070. {
  1071. ram_disk_memory[i] = 0;
  1072. }
  1073. /* Format the media. This needs to be done before opening it! */
  1074. status = fx_media_format(&ram_disk,
  1075. _fx_ram_driver, // Driver entry
  1076. ram_disk_memory, // RAM disk memory pointer
  1077. cache_buffer, // Media buffer pointer
  1078. CACHE_SIZE, // Media buffer size
  1079. "MY_RAM_DISK", // Volume Name
  1080. 1, // Number of FATs
  1081. 32, // Directory Entries
  1082. 0, // Hidden sectors
  1083. 6000, // Total sectors - FAT32
  1084. 128, // Sector size
  1085. 1, // Sectors per cluster
  1086. 1, // Heads
  1087. 1); // Sectors per track
  1088. return_if_fail( status == FX_SUCCESS);
  1089. /* Setup a new, more complicated directory structure. */
  1090. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1091. status += fx_directory_create(&ram_disk, "\\SUB1");
  1092. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2");
  1093. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3");
  1094. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4");
  1095. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5");
  1096. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6");
  1097. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7");
  1098. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8");
  1099. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9");
  1100. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10");
  1101. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11");
  1102. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12");
  1103. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13");
  1104. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14");
  1105. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15");
  1106. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16");
  1107. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16\\SUB17");
  1108. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16\\SUB17\\SUB18");
  1109. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16\\SUB17\\SUB18\\SUB19");
  1110. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16\\SUB17\\SUB18\\SUB19\\SUB20");
  1111. status += fx_directory_create(&ram_disk, "\\SUB1\\SUB2\\SUB3\\SUB4\\SUB5\\SUB6\\SUB7\\SUB8\\SUB9\\SUB10\\SUB11\\SUB12\\SUB13\\SUB14\\SUB15\\SUB16\\SUB17\\SUB18\\SUB19\\SUB20\\SUB21");
  1112. status += fx_media_flush(&ram_disk);
  1113. return_if_fail( status == FX_SUCCESS);
  1114. /* Check the media for errors. */
  1115. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1116. return_if_fail( status == FX_NOT_ENOUGH_MEMORY);
  1117. /* Close the media. */
  1118. status = fx_media_close(&ram_disk);
  1119. return_if_fail( status == FX_SUCCESS);
  1120. /* Test a full disk with a sub-directory that has a bad FAT chain, but without directory correction selected. */
  1121. /* Clear the initial part of the RAM disk memory. */
  1122. for (i = 0; i < 4096; i++)
  1123. {
  1124. ram_disk_memory[i] = 0;
  1125. }
  1126. /* Format the media. This needs to be done before opening it! */
  1127. status = fx_media_format(&ram_disk,
  1128. _fx_ram_driver, // Driver entry
  1129. ram_disk_memory, // RAM disk memory pointer
  1130. cache_buffer, // Media buffer pointer
  1131. CACHE_SIZE, // Media buffer size
  1132. "MY_RAM_DISK", // Volume Name
  1133. 1, // Number of FATs
  1134. 32, // Directory Entries
  1135. 0, // Hidden sectors
  1136. 6000, // Total sectors - FAT32
  1137. 128, // Sector size
  1138. 1, // Sectors per cluster
  1139. 1, // Heads
  1140. 1); // Sectors per track
  1141. return_if_fail( status == FX_SUCCESS);
  1142. /* Setup a new, more complicated directory structure. */
  1143. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1144. status += fx_directory_create(&ram_disk, "SUB1");
  1145. status += fx_media_flush(&ram_disk);
  1146. return_if_fail( status == FX_SUCCESS);
  1147. /* Read the first FAT sector. */
  1148. status = fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1149. /* Make the FAT chain recursive. */
  1150. raw_sector_buffer[4] = 0;
  1151. raw_sector_buffer[5] = 0;
  1152. /* Write the FAT sector back... with the errors. */
  1153. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1154. status += fx_media_flush(&ram_disk);
  1155. /* Read the root directory's first sector. */
  1156. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1157. /* Check the media for errors. */
  1158. status += fx_media_check(&ram_disk, scratch_memory, 11000, (FX_FAT_CHAIN_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1159. return_if_fail( status == FX_SUCCESS);
  1160. /* Close the media. */
  1161. status = fx_media_close(&ram_disk);
  1162. return_if_fail( status == FX_SUCCESS);
  1163. /* FAT32 Test for sixteen files with a broken root directory FAT chain. */
  1164. /* Clear the initial part of the RAM disk memory. */
  1165. for (i = 0; i < 4096; i++)
  1166. {
  1167. ram_disk_memory[i] = 0;
  1168. }
  1169. /* Format the media. This needs to be done before opening it! */
  1170. status = fx_media_format(&ram_disk,
  1171. _fx_ram_driver, // Driver entry
  1172. ram_disk_memory, // RAM disk memory pointer
  1173. cache_buffer, // Media buffer pointer
  1174. CACHE_SIZE, // Media buffer size
  1175. "MY_RAM_DISK", // Volume Name
  1176. 1, // Number of FATs
  1177. 32, // Directory Entries
  1178. 0, // Hidden sectors
  1179. 70000, // Total sectors - FAT32
  1180. 128, // Sector size
  1181. 1, // Sectors per cluster
  1182. 1, // Heads
  1183. 1); // Sectors per track
  1184. return_if_fail( status == FX_SUCCESS);
  1185. /* Setup a new, more complicated directory structure. */
  1186. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1187. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  1188. status += fx_media_flush(&ram_disk);
  1189. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  1190. status += fx_media_flush(&ram_disk);
  1191. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  1192. status += fx_media_flush(&ram_disk);
  1193. status += fx_file_create(&ram_disk, "ROOTF4.TXT");
  1194. status += fx_media_flush(&ram_disk);
  1195. status += fx_file_create(&ram_disk, "ROOTF5.TXT");
  1196. status += fx_media_flush(&ram_disk);
  1197. status += fx_file_create(&ram_disk, "ROOTF6.TXT");
  1198. status += fx_media_flush(&ram_disk);
  1199. status += fx_file_create(&ram_disk, "ROOTF7.TXT");
  1200. status += fx_media_flush(&ram_disk);
  1201. status += fx_file_create(&ram_disk, "ROOTF8.TXT");
  1202. status += fx_media_flush(&ram_disk);
  1203. status += fx_file_create(&ram_disk, "ROOTF9.TXT");
  1204. status += fx_media_flush(&ram_disk);
  1205. status += fx_file_create(&ram_disk, "ROOTF10.TXT");
  1206. status += fx_media_flush(&ram_disk);
  1207. status += fx_file_create(&ram_disk, "ROOTF11.TXT");
  1208. status += fx_media_flush(&ram_disk);
  1209. status += fx_file_create(&ram_disk, "ROOTF12.TXT");
  1210. status += fx_media_flush(&ram_disk);
  1211. status += fx_file_create(&ram_disk, "ROOTF13.TXT");
  1212. status += fx_media_flush(&ram_disk);
  1213. status += fx_file_create(&ram_disk, "ROOTF14.TXT");
  1214. status += fx_media_flush(&ram_disk);
  1215. status += fx_file_create(&ram_disk, "ROOTF15.TXT");
  1216. status += fx_media_flush(&ram_disk);
  1217. status += fx_file_create(&ram_disk, "ROOTF16.TXT");
  1218. status += fx_media_flush(&ram_disk);
  1219. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  1220. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  1221. status += fx_file_close(&my_file);
  1222. status += fx_media_flush(&ram_disk);
  1223. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  1224. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  1225. status += fx_file_close(&my_file);
  1226. status += fx_media_flush(&ram_disk);
  1227. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  1228. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  1229. status += fx_file_close(&my_file);
  1230. status += fx_media_flush(&ram_disk);
  1231. return_if_fail( status == FX_SUCCESS);
  1232. /* Read the root directory's first sector. */
  1233. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1234. /* Set the second file's FAT chain to the same as the first. */
  1235. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  1236. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  1237. /* Write the root directory sector back... with the errors. */
  1238. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1239. status += fx_media_flush(&ram_disk);
  1240. /* Read the first FAT sector. */
  1241. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1242. /* Break the FAT chain of the root directory in FAT32. */
  1243. raw_sector_buffer[12] = 0;
  1244. raw_sector_buffer[13] = 0;
  1245. raw_sector_buffer[14] = 0;
  1246. raw_sector_buffer[15] = 0;
  1247. /* Write the root directory sector back... with the errors. */
  1248. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1249. status += fx_media_flush(&ram_disk);
  1250. return_if_fail( status == FX_SUCCESS);
  1251. /* Check the media for errors. */
  1252. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1253. return_if_fail( status == FX_ERROR_NOT_FIXED);
  1254. /* Close the media. */
  1255. status = fx_media_close(&ram_disk);
  1256. return_if_fail( status == FX_SUCCESS);
  1257. #ifndef FX_DISABLE_ERROR_CHECKING
  1258. /* Test NULL media pointer error checking. */
  1259. status = fx_media_check(FX_NULL, scratch_memory, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1260. return_if_fail( status == FX_PTR_ERROR);
  1261. /* Test NULL media pointer error checking. */
  1262. status = fx_media_check(&ram_disk, FX_NULL, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1263. return_if_fail( status == FX_PTR_ERROR);
  1264. #endif //FX_DISABLE_ERROR_CHECKING
  1265. /* FAT32 Test for sixteen files with a broken root directory FAT chain and 512 byte sectors. */
  1266. /* Clear the initial part of the RAM disk memory. */
  1267. for (i = 0; i < 4096; i++)
  1268. {
  1269. ram_disk_memory[i] = 0;
  1270. }
  1271. /* Format the media. This needs to be done before opening it! */
  1272. status = fx_media_format(&ram_disk,
  1273. _fx_ram_driver, // Driver entry
  1274. ram_disk_memory, // RAM disk memory pointer
  1275. cache_buffer, // Media buffer pointer
  1276. CACHE_SIZE, // Media buffer size
  1277. "MY_RAM_DISK", // Volume Name
  1278. 1, // Number of FATs
  1279. 32, // Directory Entries
  1280. 0, // Hidden sectors
  1281. 70000, // Total sectors - FAT32
  1282. 512, // Sector size
  1283. 1, // Sectors per cluster
  1284. 1, // Heads
  1285. 1); // Sectors per track
  1286. return_if_fail( status == FX_SUCCESS);
  1287. /* Setup a new, more complicated directory structure. */
  1288. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1289. status += fx_file_create(&ram_disk, "ROOTF1.TXT");
  1290. status += fx_media_flush(&ram_disk);
  1291. status += fx_file_create(&ram_disk, "ROOTF2.TXT");
  1292. status += fx_media_flush(&ram_disk);
  1293. status += fx_file_create(&ram_disk, "ROOTF3.TXT");
  1294. status += fx_media_flush(&ram_disk);
  1295. status += fx_file_create(&ram_disk, "ROOTF4.TXT");
  1296. status += fx_media_flush(&ram_disk);
  1297. status += fx_file_create(&ram_disk, "ROOTF5.TXT");
  1298. status += fx_media_flush(&ram_disk);
  1299. status += fx_file_create(&ram_disk, "ROOTF6.TXT");
  1300. status += fx_media_flush(&ram_disk);
  1301. status += fx_file_create(&ram_disk, "ROOTF7.TXT");
  1302. status += fx_media_flush(&ram_disk);
  1303. status += fx_file_create(&ram_disk, "ROOTF8.TXT");
  1304. status += fx_media_flush(&ram_disk);
  1305. status += fx_file_create(&ram_disk, "ROOTF9.TXT");
  1306. status += fx_media_flush(&ram_disk);
  1307. status += fx_file_create(&ram_disk, "ROOTF10.TXT");
  1308. status += fx_media_flush(&ram_disk);
  1309. status += fx_file_create(&ram_disk, "ROOTF11.TXT");
  1310. status += fx_media_flush(&ram_disk);
  1311. status += fx_file_create(&ram_disk, "ROOTF12.TXT");
  1312. status += fx_media_flush(&ram_disk);
  1313. status += fx_file_create(&ram_disk, "ROOTF13.TXT");
  1314. status += fx_media_flush(&ram_disk);
  1315. status += fx_file_create(&ram_disk, "ROOTF14.TXT");
  1316. status += fx_media_flush(&ram_disk);
  1317. status += fx_file_create(&ram_disk, "ROOTF15.TXT");
  1318. status += fx_media_flush(&ram_disk);
  1319. status += fx_file_create(&ram_disk, "ROOTF16.TXT");
  1320. status += fx_media_flush(&ram_disk);
  1321. status += fx_file_create(&ram_disk, "ROOTF17.TXT"); /* Ensure the root directory exceeds the 512 byte sector size and thus has a cluster chain! */
  1322. status += fx_media_flush(&ram_disk);
  1323. status += fx_file_open(&ram_disk, &my_file, "ROOTF1.TXT", FX_OPEN_FOR_WRITE);
  1324. status += fx_file_write(&my_file, "ROOTF1_CONTENTS", 130);
  1325. status += fx_file_close(&my_file);
  1326. status += fx_media_flush(&ram_disk);
  1327. status += fx_file_open(&ram_disk, &my_file, "ROOTF2.TXT", FX_OPEN_FOR_WRITE);
  1328. status += fx_file_write(&my_file, "ROOTF2_CONTENTS", 130);
  1329. status += fx_file_close(&my_file);
  1330. status += fx_media_flush(&ram_disk);
  1331. status += fx_file_open(&ram_disk, &my_file, "ROOTF3.TXT", FX_OPEN_FOR_WRITE);
  1332. status += fx_file_write(&my_file, "ROOTF3_CONTENTS", 130);
  1333. status += fx_file_close(&my_file);
  1334. status += fx_media_flush(&ram_disk);
  1335. return_if_fail( status == FX_SUCCESS);
  1336. /* Read the root directory's first sector. */
  1337. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1338. /* Set the second file's FAT chain to the same as the first. */
  1339. raw_sector_buffer[0x3A] = raw_sector_buffer[0x1A];
  1340. raw_sector_buffer[0x3B] = raw_sector_buffer[0x1B];
  1341. /* Write the root directory sector back... with the errors. */
  1342. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, (VOID *) raw_sector_buffer);
  1343. status += fx_media_flush(&ram_disk);
  1344. /* Read the first FAT sector. */
  1345. status += fx_media_read(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1346. /* Break the FAT chain of the root directory in FAT32. */
  1347. raw_sector_buffer[12] = 0;
  1348. raw_sector_buffer[13] = 0;
  1349. raw_sector_buffer[14] = 0;
  1350. raw_sector_buffer[15] = 0;
  1351. /* Write the root directory sector back... with the errors. */
  1352. status += fx_media_write(&ram_disk, ram_disk.fx_media_reserved_sectors, (VOID *) raw_sector_buffer);
  1353. status += fx_media_flush(&ram_disk);
  1354. return_if_fail( status == FX_SUCCESS);
  1355. /* Check the media for errors. */
  1356. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1357. return_if_fail( status == FX_ERROR_NOT_FIXED);
  1358. /* Close the media. */
  1359. status = fx_media_close(&ram_disk);
  1360. return_if_fail( status == FX_SUCCESS);
  1361. #ifndef FX_DISABLE_ERROR_CHECKING
  1362. /* Test NULL media pointer error checking. */
  1363. status = fx_media_check(FX_NULL, scratch_memory, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1364. return_if_fail( status == FX_PTR_ERROR);
  1365. /* Test NULL media pointer error checking. */
  1366. status = fx_media_check(&ram_disk, FX_NULL, 11000, (FX_DIRECTORY_ERROR | FX_LOST_CLUSTER_ERROR), &errors_detected);
  1367. return_if_fail( status == FX_PTR_ERROR);
  1368. #endif //FX_DISABLE_ERROR_CHECKING
  1369. /* FAT32 Test for formatting with I/O errors. */
  1370. /* Clear the initial part of the RAM disk memory. */
  1371. for (i = 0; i < 4096; i++)
  1372. {
  1373. ram_disk_memory[i] = 0;
  1374. }
  1375. for (i = 0; i < 4000; i++)
  1376. {
  1377. /* Create I/O errors via the RAM driver interface. */
  1378. _fx_utility_FAT_flush(&ram_disk);
  1379. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1380. j = (UINT)(rand() % 10);
  1381. if (j == 0)
  1382. j = 1;
  1383. _fx_ram_driver_io_error_request = j;
  1384. /* Format the media. This needs to be done before opening it! */
  1385. fx_media_format(&ram_disk,
  1386. _fx_ram_driver, // Driver entry
  1387. ram_disk_memory, // RAM disk memory pointer
  1388. cache_buffer, // Media buffer pointer
  1389. CACHE_SIZE, // Media buffer size
  1390. "MYDISK", // Volume Name
  1391. 1, // Number of FATs
  1392. 32, // Directory Entries
  1393. 0, // Hidden sectors
  1394. 70000, // Total sectors - FAT32
  1395. 512, // Sector size
  1396. 1, // Sectors per cluster
  1397. 1, // Heads
  1398. 1); // Sectors per track
  1399. _fx_utility_FAT_flush(&ram_disk);
  1400. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1401. j = (UINT)(rand() % 10);
  1402. if (j == 0)
  1403. j = 1;
  1404. _fx_ram_driver_io_error_request = j;
  1405. /* Open media with errors. */
  1406. fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 512);
  1407. _fx_utility_FAT_flush(&ram_disk);
  1408. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1409. j = (UINT)(rand() % 10);
  1410. if (j == 0)
  1411. j = 1;
  1412. _fx_ram_driver_io_error_request = j;
  1413. /* Attempt to close media with errors. */
  1414. fx_media_close(&ram_disk);
  1415. _fx_utility_FAT_flush(&ram_disk);
  1416. _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
  1417. j = (UINT)(rand() % 10);
  1418. if (j == 0)
  1419. j = 1;
  1420. _fx_ram_driver_io_error_request = j;
  1421. /* Attempt to abort media with errors. */
  1422. fx_media_abort(&ram_disk);
  1423. _fx_ram_driver_io_error_request = 0;
  1424. }
  1425. /* Test I/O errors in _fx_media_check_lost_cluster_check. */
  1426. /* Format the media. This needs to be done before opening it! */
  1427. status = fx_media_format(&ram_disk,
  1428. _fx_ram_driver, // Driver entry
  1429. ram_disk_memory, // RAM disk memory pointer
  1430. cache_buffer, // Media buffer pointer
  1431. CACHE_SIZE, // Media buffer size
  1432. "MY_RAM_DISK", // Volume Name
  1433. 1, // Number of FATs
  1434. 32, // Directory Entries
  1435. 0, // Hidden sectors
  1436. 6000, // Total sectors
  1437. 128, // Sector size
  1438. 1, // Sectors per cluster
  1439. 1, // Heads
  1440. 1); // Sectors per track
  1441. return_if_fail( status == FX_SUCCESS);
  1442. /* Open the ram_disk. */
  1443. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1444. return_if_fail( status == FX_SUCCESS);
  1445. /* Read the first FAT sector. */
  1446. status = fx_media_read(&ram_disk, 2, (VOID *) raw_sector_buffer);
  1447. return_if_fail( status == FX_SUCCESS);
  1448. /* Change the FAT table to introduce lost clusters! */
  1449. raw_sector_buffer[30] = 2;
  1450. raw_sector_buffer[31] = 3;
  1451. raw_sector_buffer[32] = 4;
  1452. /* Write the FAT sector back... with the errors. */
  1453. status = fx_media_write(&ram_disk, 2, (VOID *) raw_sector_buffer);
  1454. return_if_fail( status == FX_SUCCESS);
  1455. /* Read the first FAT sector. */
  1456. status = fx_media_read(&ram_disk, 3, (VOID *) raw_sector_buffer);
  1457. return_if_fail( status == FX_SUCCESS);
  1458. /* Change the FAT table to introduce lost clusters! */
  1459. raw_sector_buffer[30] = 5;
  1460. raw_sector_buffer[31] = 6;
  1461. raw_sector_buffer[32] = 7;
  1462. /* Write the FAT sector back... with the errors. */
  1463. status = fx_media_write(&ram_disk, 3, (VOID *) raw_sector_buffer);
  1464. return_if_fail( status == FX_SUCCESS);
  1465. /* Read the first FAT sector. */
  1466. status = fx_media_read(&ram_disk, 4, (VOID *) raw_sector_buffer);
  1467. return_if_fail( status == FX_SUCCESS);
  1468. /* Change the FAT table to introduce lost clusters! */
  1469. raw_sector_buffer[30] = 8;
  1470. raw_sector_buffer[31] = 9;
  1471. raw_sector_buffer[32] = 10;
  1472. /* Write the FAT sector back... with the errors. */
  1473. status = fx_media_write(&ram_disk, 4, (VOID *) raw_sector_buffer);
  1474. return_if_fail( status == FX_SUCCESS);
  1475. /* Flush and invalidate the cache. */
  1476. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1477. /* Force media errors. */
  1478. _fx_utility_fat_entry_read_error_request = 1;
  1479. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  1480. _fx_utility_fat_entry_read_error_request = 1000;
  1481. fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  1482. _fx_utility_fat_entry_read_error_request = 0;
  1483. return_if_fail( status == FX_IO_ERROR);
  1484. /* Close the media. */
  1485. status = fx_media_close(&ram_disk);
  1486. return_if_fail( status == FX_SUCCESS);
  1487. /* Format the media. This needs to be done before opening it! */
  1488. status = fx_media_format(&ram_disk,
  1489. _fx_ram_driver, // Driver entry
  1490. ram_disk_memory, // RAM disk memory pointer
  1491. cache_buffer, // Media buffer pointer
  1492. CACHE_SIZE, // Media buffer size
  1493. "MY_RAM_DISK", // Volume Name
  1494. 1, // Number of FATs
  1495. 32, // Directory Entries
  1496. 0, // Hidden sectors
  1497. 6000, // Total sectors
  1498. 128, // Sector size
  1499. 1, // Sectors per cluster
  1500. 1, // Heads
  1501. 1); // Sectors per track
  1502. return_if_fail( status == FX_SUCCESS);
  1503. /* Open the ram_disk. */
  1504. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1505. return_if_fail( status == FX_SUCCESS);
  1506. /* Read the first FAT sector. */
  1507. status = fx_media_read(&ram_disk, 2, (VOID *) raw_sector_buffer);
  1508. return_if_fail( status == FX_SUCCESS);
  1509. /* Change the FAT table to introduce lost clusters! */
  1510. raw_sector_buffer[30] = 2;
  1511. raw_sector_buffer[31] = 3;
  1512. raw_sector_buffer[32] = 4;
  1513. /* Write the FAT sector back... with the errors. */
  1514. status = fx_media_write(&ram_disk, 2, (VOID *) raw_sector_buffer);
  1515. return_if_fail( status == FX_SUCCESS);
  1516. /* Read the first FAT sector. */
  1517. status = fx_media_read(&ram_disk, 3, (VOID *) raw_sector_buffer);
  1518. return_if_fail( status == FX_SUCCESS);
  1519. /* Change the FAT table to introduce lost clusters! */
  1520. raw_sector_buffer[30] = 5;
  1521. raw_sector_buffer[31] = 6;
  1522. raw_sector_buffer[32] = 7;
  1523. /* Write the FAT sector back... with the errors. */
  1524. status = fx_media_write(&ram_disk, 3, (VOID *) raw_sector_buffer);
  1525. return_if_fail( status == FX_SUCCESS);
  1526. /* Read the first FAT sector. */
  1527. status = fx_media_read(&ram_disk, 4, (VOID *) raw_sector_buffer);
  1528. return_if_fail( status == FX_SUCCESS);
  1529. /* Change the FAT table to introduce lost clusters! */
  1530. raw_sector_buffer[30] = 8;
  1531. raw_sector_buffer[31] = 9;
  1532. raw_sector_buffer[32] = 10;
  1533. /* Write the FAT sector back... with the errors. */
  1534. status = fx_media_write(&ram_disk, 4, (VOID *) raw_sector_buffer);
  1535. return_if_fail( status == FX_SUCCESS);
  1536. /* Flush and invalidate the cache. */
  1537. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1538. /* Check the media for errors. */
  1539. _fx_utility_fat_entry_write_error_request = 1;
  1540. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  1541. _fx_utility_fat_entry_write_error_request = 10000;
  1542. fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
  1543. _fx_utility_fat_entry_write_error_request = 0;
  1544. return_if_fail( status == FX_IO_ERROR);
  1545. /* Close the media. */
  1546. status = fx_media_close(&ram_disk);
  1547. return_if_fail( status == FX_SUCCESS);
  1548. /* Test the error paths in FAT32 root directory traversal. */
  1549. /* Format the media. This needs to be done before opening it! */
  1550. status = fx_media_format(&ram_disk,
  1551. _fx_ram_driver, // Driver entry
  1552. ram_disk_memory, // RAM disk memory pointer
  1553. cache_buffer, // Media buffer pointer
  1554. CACHE_SIZE, // Media buffer size
  1555. "MY_RAM_DISK", // Volume Name
  1556. 1, // Number of FATs
  1557. 32, // Directory Entries
  1558. 0, // Hidden sectors
  1559. 70000, // Total sectors - FAT32
  1560. 128, // Sector size
  1561. 1, // Sectors per cluster
  1562. 1, // Heads
  1563. 1); // Sectors per track
  1564. return_if_fail( status == FX_SUCCESS);
  1565. /* Open the ram_disk. */
  1566. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1567. return_if_fail( status == FX_SUCCESS);
  1568. /* Now create a series to sub-directories to expand the root directory FAT chain. */
  1569. status = fx_file_create(&ram_disk, "FILE1");
  1570. status += fx_file_create(&ram_disk, "FILE2");
  1571. status += fx_file_create(&ram_disk, "FILE3");
  1572. status += fx_file_create(&ram_disk, "FILE4");
  1573. status += fx_file_create(&ram_disk, "FILE5");
  1574. status += fx_file_create(&ram_disk, "FILE6");
  1575. status += fx_file_create(&ram_disk, "FILE7");
  1576. status += fx_file_create(&ram_disk, "FILE8");
  1577. status += fx_file_create(&ram_disk, "FILE9");
  1578. status += fx_file_create(&ram_disk, "FILE10");
  1579. status += fx_file_create(&ram_disk, "FILE11");
  1580. status += fx_file_create(&ram_disk, "FILE12");
  1581. status += fx_file_create(&ram_disk, "FILE13");
  1582. status += fx_file_create(&ram_disk, "FILE14");
  1583. status += fx_file_create(&ram_disk, "FILE15");
  1584. status += fx_file_create(&ram_disk, "FILE16");
  1585. status += fx_file_create(&ram_disk, "FILE17");
  1586. status += fx_file_create(&ram_disk, "FILE18");
  1587. status += fx_file_create(&ram_disk, "FILE19");
  1588. status += fx_file_create(&ram_disk, "FILE20");
  1589. status += fx_file_create(&ram_disk, "FILE21");
  1590. status += fx_file_create(&ram_disk, "FILE22");
  1591. status += fx_file_create(&ram_disk, "FILE23");
  1592. status += fx_file_create(&ram_disk, "FILE24");
  1593. status += fx_file_create(&ram_disk, "FILE25");
  1594. status += fx_file_create(&ram_disk, "FILE26");
  1595. status += fx_file_create(&ram_disk, "FILE27");
  1596. status += fx_file_create(&ram_disk, "FILE28");
  1597. status += fx_file_create(&ram_disk, "FILE29");
  1598. status += fx_file_create(&ram_disk, "FILE30");
  1599. status += fx_file_create(&ram_disk, "FILE31");
  1600. status += fx_media_flush(&ram_disk);
  1601. /* Read the first FAT sector. */
  1602. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1603. return_if_fail( status == FX_SUCCESS);
  1604. /* Break the FAT chain of the root directory! */
  1605. raw_sector_buffer[36] = 0;
  1606. raw_sector_buffer[37] = 0;
  1607. raw_sector_buffer[38] = 0;
  1608. raw_sector_buffer[39] = 0;
  1609. /* Write the FAT sector back... with the errors. */
  1610. status = fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1611. return_if_fail( status == FX_SUCCESS);
  1612. /* Flush and invalidate the cache. */
  1613. fx_media_flush(&ram_disk);
  1614. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1615. /* Check the media for errors. */
  1616. _fx_utility_fat_entry_read_error_request = 1;
  1617. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_LOST_CLUSTER_ERROR | FX_DIRECTORY_ERROR | FX_FAT_CHAIN_ERROR), &errors_detected);
  1618. _fx_utility_fat_entry_read_error_request = 0;
  1619. return_if_fail( status == FX_IO_ERROR);
  1620. /* Check the media for errors. */
  1621. _fx_utility_fat_entry_write_error_request = 1;
  1622. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_LOST_CLUSTER_ERROR | FX_DIRECTORY_ERROR | FX_FAT_CHAIN_ERROR), &errors_detected);
  1623. _fx_utility_fat_entry_write_error_request = 0;
  1624. return_if_fail( status == FX_IO_ERROR);
  1625. /* Close the media. */
  1626. status = fx_media_close(&ram_disk);
  1627. return_if_fail( status == FX_SUCCESS);
  1628. /* Test the error paths in file FAT traversal. */
  1629. /* Format the media. This needs to be done before opening it! */
  1630. status = fx_media_format(&ram_disk,
  1631. _fx_ram_driver, // Driver entry
  1632. ram_disk_memory, // RAM disk memory pointer
  1633. cache_buffer, // Media buffer pointer
  1634. CACHE_SIZE, // Media buffer size
  1635. "MY_RAM_DISK", // Volume Name
  1636. 1, // Number of FATs
  1637. 32, // Directory Entries
  1638. 0, // Hidden sectors
  1639. 70000, // Total sectors - FAT32
  1640. 128, // Sector size
  1641. 1, // Sectors per cluster
  1642. 1, // Heads
  1643. 1); // Sectors per track
  1644. return_if_fail( status == FX_SUCCESS);
  1645. /* Open the ram_disk. */
  1646. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1647. return_if_fail( status == FX_SUCCESS);
  1648. /* Now create a series to sub-directories to expand the root directory FAT chain. */
  1649. status = fx_file_create(&ram_disk, "FILE1");
  1650. /* Flush and invalidate the cache. */
  1651. fx_media_flush(&ram_disk);
  1652. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1653. /* Read the first FAT sector. */
  1654. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1655. return_if_fail( status == FX_SUCCESS);
  1656. /* Open the file. */
  1657. status += fx_file_open(&ram_disk, &my_file, "FILE1", FX_OPEN_FOR_WRITE);
  1658. /* Write to the file. */
  1659. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1660. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1661. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1662. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1663. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1664. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1665. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1666. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1667. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1668. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1669. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1670. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1671. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1672. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1673. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1674. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1675. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1676. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1677. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1678. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1679. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1680. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1681. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1682. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1683. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1684. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1685. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1686. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1687. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1688. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1689. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1690. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1691. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1692. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1693. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1694. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1695. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1696. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1697. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1698. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1699. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1700. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1701. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1702. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1703. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1704. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1705. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1706. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1707. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1708. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1709. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1710. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1711. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1712. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1713. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1714. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1715. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1716. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1717. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1718. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1719. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1720. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1721. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1722. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1723. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1724. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1725. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1726. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1727. status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
  1728. status += fx_file_close(&my_file);
  1729. status += fx_media_flush(&ram_disk);
  1730. /* Read the first FAT sector. */
  1731. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1732. return_if_fail( status == FX_SUCCESS);
  1733. /* Break the FAT chain of the root directory! */
  1734. raw_sector_buffer[36] = 0;
  1735. raw_sector_buffer[37] = 0;
  1736. raw_sector_buffer[38] = 0;
  1737. raw_sector_buffer[39] = 0;
  1738. /* Write the FAT sector back... with the errors. */
  1739. status = fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1740. return_if_fail( status == FX_SUCCESS);
  1741. /* Flush and invalidate the cache. */
  1742. fx_media_flush(&ram_disk);
  1743. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1744. /* Check the media for errors. */
  1745. _fx_utility_fat_entry_write_error_request = 1;
  1746. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_LOST_CLUSTER_ERROR | FX_DIRECTORY_ERROR | FX_FAT_CHAIN_ERROR), &errors_detected);
  1747. _fx_utility_fat_entry_write_error_request = 0;
  1748. return_if_fail( status == FX_IO_ERROR);
  1749. /* Close the media. */
  1750. status = fx_media_close(&ram_disk);
  1751. return_if_fail( status == FX_SUCCESS);
  1752. /* Test the error paths in sub-directory delete path. */
  1753. /* Format the media. This needs to be done before opening it! */
  1754. status = fx_media_format(&ram_disk,
  1755. _fx_ram_driver, // Driver entry
  1756. ram_disk_memory, // RAM disk memory pointer
  1757. cache_buffer, // Media buffer pointer
  1758. CACHE_SIZE, // Media buffer size
  1759. "MY_RAM_DISK", // Volume Name
  1760. 1, // Number of FATs
  1761. 32, // Directory Entries
  1762. 0, // Hidden sectors
  1763. 70000, // Total sectors - FAT32
  1764. 128, // Sector size
  1765. 1, // Sectors per cluster
  1766. 1, // Heads
  1767. 1); // Sectors per track
  1768. return_if_fail( status == FX_SUCCESS);
  1769. /* Open the ram_disk. */
  1770. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1771. return_if_fail( status == FX_SUCCESS);
  1772. /* Now create a sub-directory. */
  1773. status = fx_directory_create(&ram_disk, "SUB1");
  1774. /* Flush and invalidate the cache. */
  1775. fx_media_flush(&ram_disk);
  1776. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1777. /* Read the first FAT sector. */
  1778. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1779. return_if_fail( status == FX_SUCCESS);
  1780. /* Open the file. */
  1781. status += fx_file_open(&ram_disk, &my_file, "FILE1", FX_OPEN_FOR_WRITE);
  1782. status += fx_media_flush(&ram_disk);
  1783. /* Read the first FAT sector. */
  1784. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1785. return_if_fail( status == FX_SUCCESS);
  1786. /* Break the FAT chain of the sub-directory! */
  1787. raw_sector_buffer[12] = 0;
  1788. raw_sector_buffer[13] = 0;
  1789. raw_sector_buffer[14] = 0;
  1790. raw_sector_buffer[15] = 0;
  1791. /* Write the FAT sector back... with the errors. */
  1792. status = fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1793. return_if_fail( status == FX_SUCCESS);
  1794. /* Flush and invalidate the cache. */
  1795. fx_media_flush(&ram_disk);
  1796. _fx_utility_logical_sector_flush(&ram_disk, 0, 4000, FX_TRUE);
  1797. /* Check the media for errors. */
  1798. _fx_ram_driver_io_error_request = 4;
  1799. status = fx_media_check(&ram_disk, scratch_memory, 11000, (FX_LOST_CLUSTER_ERROR | FX_DIRECTORY_ERROR | FX_FAT_CHAIN_ERROR), &errors_detected);
  1800. _fx_ram_driver_io_error_request = 0;
  1801. return_if_fail( status == FX_IO_ERROR);
  1802. /* Close the media. */
  1803. status = fx_media_close(&ram_disk);
  1804. return_if_fail( status == FX_SUCCESS);
  1805. /* Format the media. This needs to be done before opening it! */
  1806. status = fx_media_format(&ram_disk,
  1807. _fx_ram_driver, // Driver entry
  1808. ram_disk_memory, // RAM disk memory pointer
  1809. cache_buffer, // Media buffer pointer
  1810. CACHE_SIZE, // Media buffer size
  1811. "MY_RAM_DISK", // Volume Name
  1812. 1, // Number of FATs
  1813. 32, // Directory Entries
  1814. 0, // Hidden sectors
  1815. 256, // Total sectors
  1816. 128, // Sector size
  1817. 1, // Sectors per cluster
  1818. 1, // Heads
  1819. 1); // Sectors per track
  1820. return_if_fail( status == FX_SUCCESS);
  1821. /* Open the ram_disk. */
  1822. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1823. return_if_fail( status == FX_SUCCESS);
  1824. /* Create a file in the root directory. */
  1825. status = fx_file_create(&ram_disk, "TEXT.TXT");
  1826. status += fx_file_open(&ram_disk, &my_file, "TEXT.TXT", FX_OPEN_FOR_WRITE);
  1827. status += fx_file_write(&my_file, raw_sector_buffer, 128);
  1828. status += fx_file_close(&my_file);
  1829. return_if_fail( status == FX_SUCCESS);
  1830. status = fx_media_close(&ram_disk);
  1831. return_if_fail( status == FX_SUCCESS);
  1832. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  1833. return_if_fail( status == FX_SUCCESS);
  1834. /* Read the first FAT sector. */
  1835. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1836. return_if_fail( status == FX_SUCCESS);
  1837. /* Change the FAT table to introduce lost clusters! */
  1838. memcpy(raw_sector_buffer_check, raw_sector_buffer, ram_disk.fx_media_bytes_per_sector);
  1839. raw_sector_buffer[3] = (ram_disk.fx_media_total_clusters + FX_FAT_ENTRY_START) & 0xFF;
  1840. raw_sector_buffer[4] = (UCHAR)((ram_disk.fx_media_total_clusters + FX_FAT_ENTRY_START) >> 8);
  1841. /* Write the FAT sector back... with the errors. */
  1842. status = fx_media_write(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1843. return_if_fail( status == FX_SUCCESS);
  1844. /* Attempt to check the media but give it a bad scratch_memory_size to throw an error */
  1845. status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_FAT_CHAIN_ERROR,
  1846. &errors_detected);
  1847. return_if_fail( (status == FX_SUCCESS) &&
  1848. (errors_detected == (FX_FAT_CHAIN_ERROR| FX_DIRECTORY_ERROR| FX_LOST_CLUSTER_ERROR)));
  1849. #if 0
  1850. /* Read the first FAT sector again. */
  1851. status = fx_media_read(&ram_disk, 1, (VOID *) raw_sector_buffer);
  1852. return_if_fail( status == FX_SUCCESS);
  1853. /* Compare the */
  1854. return_if_fail( memcmp(raw_sector_buffer_check,
  1855. raw_sector_buffer,
  1856. ram_disk.fx_media_bytes_per_sector) == 0);
  1857. #endif
  1858. /* Close the media. */
  1859. status = fx_media_close(&ram_disk);
  1860. return_if_fail( status == FX_SUCCESS);
  1861. printf("SUCCESS!\n");
  1862. test_control_return(0);
  1863. }