filex_directory_create_delete_test.c 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056
  1. /* This FileX test concentrates on the basic directory create/delete operations. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_directory.h"
  7. #include "fx_ram_driver_test.h"
  8. #include "fx_fault_tolerant.h"
  9. #include "fx_utility.h"
  10. #include <stdio.h>
  11. #define DEMO_STACK_SIZE 4096
  12. #define CACHE_SIZE 16*128
  13. #ifdef FX_ENABLE_FAULT_TOLERANT
  14. #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
  15. #else
  16. #define FAULT_TOLERANT_SIZE 0
  17. #endif
  18. #define DIR_PATH "MYDIR\\"
  19. #define DIR_PATH_SIZE (sizeof(DIR_PATH) - 1)
  20. /* Define the ThreadX and FileX object control blocks... */
  21. #ifndef FX_STANDALONE_ENABLE
  22. static TX_THREAD ftest_0;
  23. #endif
  24. static FX_MEDIA ram_disk;
  25. static CHAR name[FX_MAX_LONG_NAME_LEN+50];
  26. static CHAR volume_name[FX_MAX_LONG_NAME_LEN+1];
  27. static FX_FILE file_1;
  28. static FX_FILE file_2;
  29. static FX_FILE file_3;
  30. static FX_FILE file_4;
  31. static FX_FILE file_5;
  32. static FX_FILE file_6;
  33. static FX_FILE file_7;
  34. static FX_FILE file_8;
  35. static FX_FILE file_9;
  36. static FX_FILE file_10;
  37. static FX_FILE file_11;
  38. static FX_FILE file_12;
  39. static FX_FILE file_13;
  40. static FX_FILE file_14;
  41. static FX_FILE file_15;
  42. static FX_FILE file_16;
  43. static FX_FILE file_17;
  44. static FX_FILE file_18;
  45. static FX_FILE file_19;
  46. static FX_FILE file_20;
  47. static FX_FILE file_21;
  48. static FX_FILE file_22;
  49. static FX_FILE file_23;
  50. static FX_FILE file_24;
  51. static FX_FILE file_25;
  52. static FX_FILE file_26;
  53. static FX_FILE file_27;
  54. static FX_FILE file_28;
  55. static FX_FILE file_29;
  56. static FX_FILE file_30;
  57. static FX_FILE file_31;
  58. static FX_FILE file_32;
  59. static FX_FILE file_33;
  60. static FX_FILE file_34;
  61. static FX_FILE file_35;
  62. static FX_FILE file_36;
  63. static FX_FILE file_37;
  64. static FX_FILE file_38;
  65. static FX_FILE file_39;
  66. static FX_FILE file_40;
  67. static FX_FILE file_41;
  68. static FX_FILE file_42;
  69. static FX_FILE file_43;
  70. static FX_FILE file_44;
  71. static UCHAR buffer[128];
  72. static UCHAR my_unicode_name[] =
  73. {0xFF,0xC1, 0xFF,0x00, 0xFF,0x00, 0xFF,0x02,
  74. 0xFF,0xD6, 0xFF,0xC7, 0xFF,0x00, 0xFF,0xC7,
  75. 0xFF,0xB9, 0xFF,0x00, 0xFF,0xC7, 0xFF,0xB2,
  76. 0xFF,0xD6, 0xFF,0xC7, 0xFF,0x00, 0x00,0x00};
  77. static UCHAR my_unicode_name1[] =
  78. {0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
  79. 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
  80. 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
  81. 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0x00};
  82. /* Define the counters used in the test application... */
  83. #ifndef FX_STANDALONE_ENABLE
  84. static UCHAR *ram_disk_memory;
  85. static UCHAR *cache_buffer;
  86. static UCHAR *fault_tolerant_buffer;
  87. #else
  88. static UCHAR cache_buffer[CACHE_SIZE];
  89. static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
  90. #endif
  91. extern ULONG _fx_ram_driver_copy_default_format;
  92. /* Define thread prototypes. */
  93. void filex_directory_create_delete_application_define(void *first_unused_memory);
  94. static void ftest_0_entry(ULONG thread_input);
  95. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  96. void test_control_return(UINT status);
  97. /* Define what the initial system looks like. */
  98. #ifdef CTEST
  99. void test_application_define(void *first_unused_memory)
  100. #else
  101. void filex_directory_create_delete_application_define(void *first_unused_memory)
  102. #endif
  103. {
  104. #ifndef FX_STANDALONE_ENABLE
  105. UCHAR *pointer;
  106. /* Setup the working pointer. */
  107. pointer = (UCHAR *) first_unused_memory;
  108. /* Create the main thread. */
  109. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  110. pointer, DEMO_STACK_SIZE,
  111. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  112. pointer = pointer + DEMO_STACK_SIZE;
  113. /* Setup memory for the RAM disk and the sector cache. */
  114. cache_buffer = pointer;
  115. pointer = pointer + CACHE_SIZE;
  116. fault_tolerant_buffer = pointer;
  117. pointer += FAULT_TOLERANT_SIZE;
  118. ram_disk_memory = pointer;
  119. #endif
  120. /* Initialize the FileX system. */
  121. fx_system_initialize();
  122. #ifdef FX_STANDALONE_ENABLE
  123. ftest_0_entry(0);
  124. #endif
  125. }
  126. /* Define the test threads. */
  127. static void ftest_0_entry(ULONG thread_input)
  128. {
  129. UINT status;
  130. ULONG temp;
  131. UINT attributes;
  132. UINT i;
  133. #ifdef EXTENDED_NAME_MANGLE_TEST
  134. UINT j, k, l;
  135. #endif
  136. CHAR *name_ptr;
  137. FX_DIR_ENTRY dir_entry;
  138. FX_DIR_ENTRY search_directory;
  139. FX_PARAMETER_NOT_USED(thread_input);
  140. /* Print out some test information banners. */
  141. printf("FileX Test: Directory create/delete test...........................");
  142. /* Format the media. This needs to be done before opening it! */
  143. status = fx_media_format(&ram_disk,
  144. _fx_ram_driver, // Driver entry
  145. ram_disk_memory, // RAM disk memory pointer
  146. cache_buffer, // Media buffer pointer
  147. CACHE_SIZE, // Media buffer size
  148. "MY_RAM_DISK", // Volume Name
  149. 1, // Number of FATs
  150. 32, // Directory Entries
  151. 0, // Hidden sectors
  152. /* We need a larger disk to test the feature of fault tolerant. */
  153. #ifdef FX_ENABLE_FAULT_TOLERANT
  154. 512 * 8, // Total sectors
  155. 256, // Sector size
  156. 8, // Sectors per cluster
  157. #else
  158. 512, // Total sectors
  159. 128, // Sector size
  160. 1, // Sectors per cluster
  161. #endif
  162. 1, // Heads
  163. 1); // Sectors per track
  164. return_if_fail( status == FX_SUCCESS);
  165. /* Attempt to create a directory before the media is opened to generate an error */
  166. status = fx_directory_create(&ram_disk, "/A0");
  167. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  168. /* Attempt to delete a directory before the media is opened to generate an error */
  169. status = fx_directory_delete(&ram_disk, "/A0");
  170. return_if_fail( status == FX_MEDIA_NOT_OPEN);
  171. /* Open the ram_disk. */
  172. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  173. return_if_fail( status == FX_SUCCESS);
  174. /* We need a larger disk to test the feature of fault tolerant. */
  175. #ifdef FX_ENABLE_FAULT_TOLERANT
  176. /* Enable fault tolerant if FX_ENABLE_FAULT_TOLERANT is defined. */
  177. status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
  178. return_if_fail( status == FX_SUCCESS);
  179. #endif
  180. /* Only run this if error checking is enabled */
  181. #ifndef FX_DISABLE_ERROR_CHECKING
  182. /* send null pointer to directory create to generate an error */
  183. status = fx_directory_create(FX_NULL, "/A0");
  184. return_if_fail( status == FX_PTR_ERROR);
  185. /* directory delete */
  186. status = fx_directory_delete(FX_NULL, "/A0");
  187. return_if_fail( status == FX_PTR_ERROR);
  188. #endif /* FX_DISABLE_ERROR_CHECKING */
  189. /* Attempt to create a directory with an invalid name to generate an error */
  190. status = fx_directory_create(&ram_disk, "");
  191. return_if_fail( status == FX_INVALID_NAME);
  192. /* Attempt to create a directory with an invalid name to generate an error */
  193. status = fx_directory_create(&ram_disk, "/A0/error\\error");
  194. return_if_fail( status == FX_INVALID_PATH);
  195. /* Attempt to create a directory while the media is write protected to generate an error */
  196. ram_disk.fx_media_driver_write_protect = FX_TRUE;
  197. status = fx_directory_create(&ram_disk, "/A0");
  198. return_if_fail( status == FX_WRITE_PROTECT);
  199. /* try to create a directory while the media is write protected to generate an error */
  200. status = fx_directory_delete(&ram_disk, "/A0");
  201. return_if_fail( status == FX_WRITE_PROTECT);
  202. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  203. /* Attempt to create a directory when there is no space to generate an error */
  204. temp = ram_disk.fx_media_available_clusters;
  205. ram_disk.fx_media_available_clusters = 0;
  206. status = fx_directory_create(&ram_disk, "/A0");
  207. return_if_fail( status == FX_NO_MORE_SPACE);
  208. ram_disk.fx_media_available_clusters = temp;
  209. /* Create a series of directories... */
  210. status = fx_directory_create(&ram_disk, "/A0");
  211. status += fx_directory_create(&ram_disk, "/B0");
  212. status += fx_directory_create(&ram_disk, "/C0");
  213. status += fx_directory_create(&ram_disk, "/D0");
  214. status += fx_directory_create(&ram_disk, "/E0");
  215. status += fx_directory_create(&ram_disk, "/F0");
  216. status += fx_directory_create(&ram_disk, "/G0");
  217. status += fx_directory_create(&ram_disk, "/H0");
  218. status += fx_directory_create(&ram_disk, "/I0");
  219. status += fx_file_create(&ram_disk, "not_a_dir");
  220. return_if_fail( status == FX_SUCCESS);
  221. /* Attempt to create the same directory again. */
  222. status = fx_directory_create(&ram_disk, "/A0");
  223. return_if_fail( status == FX_ALREADY_CREATED);
  224. /* Create the next level of sub-directories. */
  225. status = fx_directory_create(&ram_disk, "/A0/A1");
  226. status += fx_directory_create(&ram_disk, "/A0/A2");
  227. status += fx_directory_create(&ram_disk, "/A0/A3");
  228. status += fx_directory_create(&ram_disk, "/A0/A4");
  229. status += fx_directory_create(&ram_disk, "/A0/A5");
  230. status += fx_directory_create(&ram_disk, "/B0/B1");
  231. status += fx_directory_create(&ram_disk, "/B0/B2");
  232. status += fx_directory_create(&ram_disk, "/B0/B3");
  233. status += fx_directory_create(&ram_disk, "/B0/B4");
  234. status += fx_directory_create(&ram_disk, "/B0/B5");
  235. status += fx_directory_create(&ram_disk, "/C0/C1");
  236. status += fx_directory_create(&ram_disk, "/C0/C2");
  237. status += fx_directory_create(&ram_disk, "/C0/C3");
  238. status += fx_directory_create(&ram_disk, "/C0/C4");
  239. status += fx_directory_create(&ram_disk, "/C0/C5");
  240. status += fx_directory_create(&ram_disk, "/D0/D1");
  241. status += fx_directory_create(&ram_disk, "/D0/D2");
  242. status += fx_directory_create(&ram_disk, "/D0/D3");
  243. status += fx_directory_create(&ram_disk, "/D0/D4");
  244. status += fx_directory_create(&ram_disk, "/D0/D5");
  245. status += fx_directory_create(&ram_disk, "/E0/E1");
  246. status += fx_directory_create(&ram_disk, "/E0/E2");
  247. status += fx_directory_create(&ram_disk, "/E0/E3");
  248. status += fx_directory_create(&ram_disk, "/E0/E4");
  249. status += fx_directory_create(&ram_disk, "/E0/E5");
  250. status += fx_directory_create(&ram_disk, "/F0/F1");
  251. status += fx_directory_create(&ram_disk, "/F0/F2");
  252. status += fx_directory_create(&ram_disk, "/F0/F3");
  253. status += fx_directory_create(&ram_disk, "/F0/F4");
  254. status += fx_directory_create(&ram_disk, "/F0/F5");
  255. status += fx_directory_create(&ram_disk, "/G0/G1");
  256. status += fx_directory_create(&ram_disk, "/G0/G2");
  257. status += fx_directory_create(&ram_disk, "/G0/G3");
  258. status += fx_directory_create(&ram_disk, "/G0/G4");
  259. status += fx_directory_create(&ram_disk, "/G0/G5");
  260. status += fx_directory_create(&ram_disk, "/H0/H1");
  261. status += fx_directory_create(&ram_disk, "/H0/H2");
  262. status += fx_directory_create(&ram_disk, "/H0/H3");
  263. status += fx_directory_create(&ram_disk, "/H0/H4");
  264. status += fx_directory_create(&ram_disk, "/H0/H5");
  265. status += fx_directory_create(&ram_disk, "/I0/I1");
  266. status += fx_directory_create(&ram_disk, "/I0/I2");
  267. status += fx_directory_create(&ram_disk, "/I0/I3");
  268. status += fx_directory_create(&ram_disk, "/I0/I4");
  269. status += fx_directory_create(&ram_disk, "/I0/I5");
  270. return_if_fail( status == FX_SUCCESS);
  271. /* Now create the third level of sub-directories... */
  272. status = fx_directory_create(&ram_disk, "/A0/A1/A00");
  273. status += fx_directory_create(&ram_disk, "/B0/B2/B00");
  274. status += fx_directory_create(&ram_disk, "/C0/C3/C00");
  275. status += fx_directory_create(&ram_disk, "/D0/D4/D00");
  276. status += fx_directory_create(&ram_disk, "/E0/E5/E00");
  277. status += fx_directory_create(&ram_disk, "/F0/F1/F00");
  278. status += fx_directory_create(&ram_disk, "/G0/G1/G00");
  279. status += fx_directory_create(&ram_disk, "/H0/H2/H00");
  280. status += fx_directory_create(&ram_disk, "/I0/I3/I00");
  281. return_if_fail( status == FX_SUCCESS);
  282. /* Attempt to delete something that is not a directory */
  283. status = fx_directory_delete(&ram_disk, "not_a_dir");
  284. return_if_fail( status == FX_NOT_DIRECTORY);
  285. /* Attempt to delete a directory that is not empty */
  286. status = fx_directory_delete(&ram_disk, "/A0");
  287. return_if_fail( status == FX_DIR_NOT_EMPTY);
  288. /* Attempt to delete a directory that is read only */
  289. status = fx_directory_attributes_read(&ram_disk, "/A0/A1/A00", &attributes);
  290. status += fx_directory_attributes_set(&ram_disk, "/A0/A1/A00", FX_READ_ONLY);
  291. status += fx_directory_delete(&ram_disk, "/A0/A1/A00");
  292. return_if_fail( status == FX_WRITE_PROTECT);
  293. status += fx_directory_attributes_set(&ram_disk, "/A0/A1/A00", attributes);
  294. /* Now delete all the directories. */
  295. status = fx_directory_delete(&ram_disk, "/A0/A1/A00");
  296. status += fx_directory_delete(&ram_disk, "/B0/B2/B00");
  297. status += fx_directory_delete(&ram_disk, "/C0/C3/C00");
  298. status += fx_directory_delete(&ram_disk, "/D0/D4/D00");
  299. status += fx_directory_delete(&ram_disk, "/E0/E5/E00");
  300. status += fx_directory_delete(&ram_disk, "/F0/F1/F00");
  301. status += fx_directory_delete(&ram_disk, "/G0/G1/G00");
  302. status += fx_directory_delete(&ram_disk, "/H0/H2/H00");
  303. status += fx_directory_delete(&ram_disk, "/I0/I3/I00");
  304. return_if_fail( status == FX_SUCCESS);
  305. /* Delete the next level of sub-directories. */
  306. status += fx_directory_delete(&ram_disk, "/A0/A1");
  307. status += fx_directory_delete(&ram_disk, "/A0/A2");
  308. status += fx_directory_delete(&ram_disk, "/A0/A3");
  309. status += fx_directory_delete(&ram_disk, "/A0/A4");
  310. status += fx_directory_delete(&ram_disk, "/A0/A5");
  311. status += fx_directory_delete(&ram_disk, "/B0/B1");
  312. status += fx_directory_delete(&ram_disk, "/B0/B2");
  313. status += fx_directory_delete(&ram_disk, "/B0/B3");
  314. status += fx_directory_delete(&ram_disk, "/B0/B4");
  315. status += fx_directory_delete(&ram_disk, "/B0/B5");
  316. status += fx_directory_delete(&ram_disk, "/C0/C1");
  317. status += fx_directory_delete(&ram_disk, "/C0/C2");
  318. status += fx_directory_delete(&ram_disk, "/C0/C3");
  319. status += fx_directory_delete(&ram_disk, "/C0/C4");
  320. status += fx_directory_delete(&ram_disk, "/C0/C5");
  321. status += fx_directory_delete(&ram_disk, "/D0/D1");
  322. status += fx_directory_delete(&ram_disk, "/D0/D2");
  323. status += fx_directory_delete(&ram_disk, "/D0/D3");
  324. status += fx_directory_delete(&ram_disk, "/D0/D4");
  325. status += fx_directory_delete(&ram_disk, "/D0/D5");
  326. status += fx_directory_delete(&ram_disk, "/E0/E1");
  327. status += fx_directory_delete(&ram_disk, "/E0/E2");
  328. status += fx_directory_delete(&ram_disk, "/E0/E3");
  329. status += fx_directory_delete(&ram_disk, "/E0/E4");
  330. status += fx_directory_delete(&ram_disk, "/E0/E5");
  331. status += fx_directory_delete(&ram_disk, "/F0/F1");
  332. status += fx_directory_delete(&ram_disk, "/F0/F2");
  333. status += fx_directory_delete(&ram_disk, "/F0/F3");
  334. status += fx_directory_delete(&ram_disk, "/F0/F4");
  335. status += fx_directory_delete(&ram_disk, "/F0/F5");
  336. status += fx_directory_delete(&ram_disk, "/G0/G1");
  337. status += fx_directory_delete(&ram_disk, "/G0/G2");
  338. status += fx_directory_delete(&ram_disk, "/G0/G3");
  339. status += fx_directory_delete(&ram_disk, "/G0/G4");
  340. status += fx_directory_delete(&ram_disk, "/G0/G5");
  341. status += fx_directory_delete(&ram_disk, "/H0/H1");
  342. status += fx_directory_delete(&ram_disk, "/H0/H2");
  343. status += fx_directory_delete(&ram_disk, "/H0/H3");
  344. status += fx_directory_delete(&ram_disk, "/H0/H4");
  345. status += fx_directory_delete(&ram_disk, "/H0/H5");
  346. status += fx_directory_delete(&ram_disk, "/I0/I1");
  347. status += fx_directory_delete(&ram_disk, "/I0/I2");
  348. status += fx_directory_delete(&ram_disk, "/I0/I3");
  349. status += fx_directory_delete(&ram_disk, "/I0/I4");
  350. status += fx_directory_delete(&ram_disk, "/I0/I5");
  351. return_if_fail( status == FX_SUCCESS);
  352. /* Delete a series of directories... */
  353. status = fx_directory_delete(&ram_disk, "/A0");
  354. status += fx_directory_delete(&ram_disk, "/B0");
  355. status += fx_directory_delete(&ram_disk, "/C0");
  356. status += fx_directory_delete(&ram_disk, "/D0");
  357. status += fx_directory_delete(&ram_disk, "/E0");
  358. status += fx_directory_delete(&ram_disk, "/F0");
  359. status += fx_directory_delete(&ram_disk, "/G0");
  360. status += fx_directory_delete(&ram_disk, "/H0");
  361. status += fx_directory_delete(&ram_disk, "/I0");
  362. return_if_fail( status == FX_SUCCESS);
  363. /* Attempt to delete a directory again. */
  364. status = fx_directory_delete(&ram_disk, "/A0");
  365. return_if_fail( status == FX_NOT_FOUND);
  366. /* Close the media. */
  367. status = fx_media_close(&ram_disk);
  368. return_if_fail( status == FX_SUCCESS);
  369. /* Format the media. This needs to be done before opening it! */
  370. status = fx_media_format(&ram_disk,
  371. _fx_ram_driver, // Driver entry
  372. ram_disk_memory, // RAM disk memory pointer
  373. cache_buffer, // Media buffer pointer
  374. CACHE_SIZE, // Media buffer size
  375. "MY_RAM_DISK", // Volume Name
  376. 1, // Number of FATs
  377. 32, // Directory Entries
  378. 0, // Hidden sectors
  379. 4096, // Total sectors
  380. 128, // Sector size
  381. 2, // Sectors per cluster
  382. 1, // Heads
  383. 1); // Sectors per track
  384. return_if_fail( status == FX_SUCCESS);
  385. /* Open the ram_disk. */
  386. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  387. return_if_fail( status == FX_SUCCESS);
  388. /* Create a directory name that is too large. */
  389. for (i = 0; i < FX_MAX_LONG_NAME_LEN+1; i++)
  390. {
  391. name[i] = 'a';
  392. }
  393. name[FX_MAX_LONG_NAME_LEN + 1] = 0;
  394. /* Attempt to create a directory with too long of a name. */
  395. status = fx_directory_create(&ram_disk, name);
  396. return_if_fail( status == FX_INVALID_NAME);
  397. /* Attempt to create a directory with no more clusters. */
  398. temp = ram_disk.fx_media_total_clusters;
  399. ram_disk.fx_media_total_clusters = 0;
  400. status = fx_directory_create(&ram_disk, "sub1");
  401. ram_disk.fx_media_total_clusters = temp;
  402. return_if_fail( status == FX_NO_MORE_SPACE);
  403. /* Attempt to create a directory with a FAT read error. */
  404. _fx_utility_fat_entry_read_error_request = 1;
  405. status = fx_directory_create(&ram_disk, "sub1");
  406. _fx_utility_fat_entry_read_error_request = 0;
  407. return_if_fail( status == FX_IO_ERROR);
  408. /* Create a subdirectory with a search pointer that must wrap after the allocation. */
  409. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START - 1);
  410. status = fx_directory_create(&ram_disk, "sub1");
  411. return_if_fail( status == FX_SUCCESS);
  412. /* Create a subdirectory with a search pointer that must wrap after the allocation. */
  413. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START - 1);
  414. status = fx_directory_create(&ram_disk, "sub2");
  415. return_if_fail( status == FX_SUCCESS);
  416. /* Create a subdirectory with a search pointer that starts on a non-free cluster. */
  417. ram_disk.fx_media_cluster_search_start = FX_FAT_ENTRY_START;
  418. status = fx_directory_create(&ram_disk, "sub3");
  419. return_if_fail( status == FX_SUCCESS);
  420. /* Create a subdirectory with a logical sector read error. */
  421. _fx_utility_logical_sector_read_error_request = 13;
  422. status = fx_directory_create(&ram_disk, "sub4");
  423. _fx_utility_logical_sector_read_error_request = 0;
  424. return_if_fail( status == FX_IO_ERROR);
  425. #ifndef FX_DISABLE_CACHE
  426. /* Create a subdirectory with a logical flush error. */
  427. _fx_utility_logical_sector_flush_error_request = 1;
  428. status = fx_directory_create(&ram_disk, "sub5");
  429. _fx_utility_logical_sector_flush_error_request = 0;
  430. return_if_fail( status == FX_IO_ERROR);
  431. #endif
  432. /* Create a subdirectory with an error clearing the additional sectors of a cluster. */
  433. _fx_ram_driver_io_error_request = 8;
  434. status = fx_directory_create(&ram_disk, "sub6");
  435. _fx_ram_driver_io_error_request = 0;
  436. return_if_fail( status == FX_IO_ERROR);
  437. /* Create a subdirectory with an error on writing the FAT entry. */
  438. _fx_utility_fat_entry_write_error_request = 1;
  439. status = fx_directory_create(&ram_disk, "sub7");
  440. _fx_utility_fat_entry_write_error_request = 0;
  441. return_if_fail( status == FX_IO_ERROR);
  442. /* Create a subdirectory with an error on writing the first director entry. */
  443. _fx_directory_entry_write_error_request = 1;
  444. status = fx_directory_create(&ram_disk, "sub8");
  445. _fx_directory_entry_write_error_request = 0;
  446. return_if_fail( status == FX_IO_ERROR);
  447. /* Create a subdirectory with an error on writing the second director entry. */
  448. _fx_directory_entry_write_error_request = 2;
  449. status = fx_directory_create(&ram_disk, "sub9");
  450. _fx_directory_entry_write_error_request = 0;
  451. return_if_fail( status == FX_IO_ERROR);
  452. /* Close the media. */
  453. status = fx_media_close(&ram_disk);
  454. return_if_fail( status == FX_SUCCESS);
  455. /* Format the media. This needs to be done before opening it! */
  456. status = fx_media_format(&ram_disk,
  457. _fx_ram_driver, // Driver entry
  458. ram_disk_memory, // RAM disk memory pointer
  459. cache_buffer, // Media buffer pointer
  460. CACHE_SIZE, // Media buffer size
  461. "MY_RAM_DISK", // Volume Name
  462. 1, // Number of FATs
  463. 32, // Directory Entries
  464. 0, // Hidden sectors
  465. 4096, // Total sectors
  466. 128, // Sector size
  467. 2, // Sectors per cluster
  468. 1, // Heads
  469. 1); // Sectors per track
  470. return_if_fail( status == FX_SUCCESS);
  471. /* Open the ram_disk. */
  472. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  473. return_if_fail( status == FX_SUCCESS);
  474. /* Create a series of sub-directories... in preparation for our directory delete checking. */
  475. status = fx_directory_create(&ram_disk, "SUB1");
  476. status += fx_directory_create(&ram_disk, "SUB2");
  477. status += fx_directory_create(&ram_disk, "SUB3");
  478. status += fx_directory_create(&ram_disk, "SUB4");
  479. status += fx_directory_create(&ram_disk, "SUB5");
  480. status += fx_directory_create(&ram_disk, "SUB6");
  481. status += fx_directory_create(&ram_disk, "SUB7");
  482. status += fx_directory_create(&ram_disk, "SUB8");
  483. return_if_fail( status == FX_SUCCESS);
  484. /* Delete a directory but with a FAT read error on the first cluster. */
  485. _fx_utility_fat_entry_read_error_request = 1;
  486. status = fx_directory_delete(&ram_disk, "SUB8");
  487. _fx_utility_fat_entry_read_error_request = 0;
  488. return_if_fail( status == FX_IO_ERROR);
  489. /* Delete a directory but with a cluster error - bad small value. */
  490. _fx_utility_fat_entry_read_error_request = 10001;
  491. status = fx_directory_delete(&ram_disk, "SUB8");
  492. _fx_utility_fat_entry_read_error_request = 0;
  493. return_if_fail( status == FX_FAT_READ_ERROR);
  494. /* Delete a directory but with a cluster error - bad total clusters. */
  495. temp = ram_disk.fx_media_total_clusters;
  496. ram_disk.fx_media_total_clusters = 0;
  497. status = fx_directory_delete(&ram_disk, "SUB8");
  498. ram_disk.fx_media_total_clusters = temp;
  499. return_if_fail( status == FX_FAT_READ_ERROR);
  500. /* Delete a directory but with a cluster error - same value. */
  501. _fx_utility_fat_entry_read_error_request = 30001;
  502. status = fx_directory_delete(&ram_disk, "SUB8");
  503. _fx_utility_fat_entry_read_error_request = 0;
  504. return_if_fail( status == FX_FAT_READ_ERROR);
  505. /* Delete a directory but with a directory entry read error. */
  506. _fx_directory_entry_read_error_request = 1;
  507. status = fx_directory_delete(&ram_disk, "SUB8");
  508. _fx_directory_entry_read_error_request = 0;
  509. return_if_fail( status == FX_IO_ERROR);
  510. /* Delete a directory but with a directory entry write error. */
  511. _fx_directory_entry_write_error_request = 1;
  512. status = fx_directory_delete(&ram_disk, "SUB8");
  513. _fx_directory_entry_write_error_request = 0;
  514. return_if_fail( status == FX_IO_ERROR);
  515. /* Delete a directory wtih large error request values just to exercise those paths - should be successful. */
  516. _fx_directory_entry_read_error_request = 10000;
  517. _fx_directory_entry_write_error_request = 10000;
  518. status = fx_directory_delete(&ram_disk, "SUB8");
  519. _fx_directory_entry_read_error_request = 0;
  520. _fx_directory_entry_write_error_request = 0;
  521. return_if_fail( status == FX_SUCCESS);
  522. /* Delete a directory with an error in the freeing of the cluster traversal FAT read. */
  523. _fx_utility_fat_entry_read_error_request = 2;
  524. status = fx_directory_delete(&ram_disk, "SUB7");
  525. _fx_utility_fat_entry_read_error_request = 0;
  526. return_if_fail( status == FX_IO_ERROR);
  527. /* Delete a directory but with a cluster error in releasing cluster - bad small value. */
  528. _fx_utility_fat_entry_read_error_request = 10002;
  529. status = fx_directory_delete(&ram_disk, "SUB6");
  530. _fx_utility_fat_entry_read_error_request = 0;
  531. return_if_fail( status == FX_FAT_READ_ERROR);
  532. /* Delete a directory but with a cluster error in releasing cluster - bad total clusters. */
  533. temp = ram_disk.fx_media_total_clusters;
  534. _fx_utility_fat_entry_read_error_request = 40002;
  535. status = fx_directory_delete(&ram_disk, "SUB5");
  536. ram_disk.fx_media_total_clusters = temp;
  537. return_if_fail( status == FX_FAT_READ_ERROR);
  538. /* Delete a directory but with a cluster error in releasing cluster - same value. */
  539. _fx_utility_fat_entry_read_error_request = 30002;
  540. status = fx_directory_delete(&ram_disk, "SUB4");
  541. _fx_utility_fat_entry_read_error_request = 0;
  542. return_if_fail( status == FX_FAT_READ_ERROR);
  543. /* Delete a directory but with a FAT write error in releasing cluster. */
  544. _fx_utility_fat_entry_write_error_request = 1;
  545. status = fx_directory_delete(&ram_disk, "SUB3");
  546. _fx_utility_fat_entry_write_error_request = 0;
  547. return_if_fail( status == FX_IO_ERROR);
  548. /* Close the media. */
  549. status = fx_media_close(&ram_disk);
  550. return_if_fail( status == FX_SUCCESS);
  551. /* Format the media. This needs to be done before opening it! */
  552. status = fx_media_format(&ram_disk,
  553. _fx_ram_driver, // Driver entry
  554. ram_disk_memory, // RAM disk memory pointer
  555. cache_buffer, // Media buffer pointer
  556. CACHE_SIZE, // Media buffer size
  557. "MY_RAM_DISK", // Volume Name
  558. 1, // Number of FATs
  559. 32, // Directory Entries
  560. 0, // Hidden sectors
  561. 14000, // Total sectors
  562. 128, // Sector size
  563. 2, // Sectors per cluster
  564. 1, // Heads
  565. 1); // Sectors per track
  566. return_if_fail( status == FX_SUCCESS);
  567. /* Open the ram_disk. */
  568. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  569. return_if_fail( status == FX_SUCCESS);
  570. /* Create a sub-directory to work from. */
  571. status = fx_directory_create(&ram_disk, "SUB1");
  572. /* Set the default path here. */
  573. status += fx_directory_default_set(&ram_disk, "SUB1");
  574. /* Now try to create some unusual file name to test the internal free search logic. */
  575. status += fx_file_create(&ram_disk, "..test");
  576. return_if_fail( status == FX_INVALID_NAME);
  577. /* Create a name with a character greater than 127. */
  578. name[0] = 'n';
  579. name[1] = 'a';
  580. name[2] = 'm';
  581. name[3] = 'e';
  582. name[4] = '\'';
  583. name[5] = ')';
  584. name[6] = '(';
  585. name[7] = '`';
  586. name[8] = (CHAR) 128;
  587. name[9] = 0;
  588. status = fx_file_create(&ram_disk, name);
  589. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  590. return_if_fail( status == FX_SUCCESS);
  591. /* Create a name with a bunch of special characters. */
  592. status = fx_file_create(&ram_disk, "name-a_b}{()'!#$&@^%+,;=[]");
  593. status += fx_file_open(&ram_disk, &file_2, "name-a_b}{()'!#$&@^%+,;=[]", FX_OPEN_FOR_WRITE);
  594. return_if_fail( status == FX_SUCCESS);
  595. /* Create a name with an invalid character. */
  596. name[0] = 'n';
  597. name[1] = 'a';
  598. name[2] = 'm';
  599. name[3] = 'e';
  600. name[4] = (CHAR) 5;
  601. name[5] = '\'';
  602. name[6] = 0;
  603. status = fx_file_create(&ram_disk, name);
  604. return_if_fail( status == FX_INVALID_NAME);
  605. /* Create a long file name by position of the dot. */
  606. status = fx_file_create(&ram_disk, "MYLONGERN.AM");
  607. status += fx_file_create(&ram_disk, "MY.TXT");
  608. status += fx_file_open(&ram_disk, &file_3, "MYLONGERN.AM", FX_OPEN_FOR_WRITE);
  609. status += fx_file_open(&ram_disk, &file_4, "MY.TXT", FX_OPEN_FOR_WRITE);
  610. return_if_fail( status == FX_SUCCESS);
  611. /* Create a set of very short long file name. */
  612. status = fx_file_create(&ram_disk, "n");
  613. status += fx_file_create(&ram_disk, "nW");
  614. status += fx_file_create(&ram_disk, "nWW");
  615. status += fx_file_create(&ram_disk, "nWWW");
  616. status += fx_file_create(&ram_disk, "nWWWW");
  617. status += fx_file_create(&ram_disk, "nWWWWW");
  618. status += fx_file_create(&ram_disk, "nWWWWWW");
  619. status += fx_file_create(&ram_disk, "nWWWWWWW");
  620. status += fx_file_create(&ram_disk, "nWWWWWWWW");
  621. status += fx_file_create(&ram_disk, "nWWWWWWWWW");
  622. status += fx_file_create(&ram_disk, "nWWWWWWWWWW");
  623. status += fx_file_create(&ram_disk, "nWWWWWWWWWWW");
  624. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWW");
  625. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWW");
  626. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWW");
  627. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWW");
  628. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWW");
  629. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWW");
  630. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWW");
  631. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWW");
  632. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWW");
  633. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWW");
  634. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWW");
  635. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWW");
  636. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWW");
  637. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWW");
  638. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWW");
  639. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  640. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  641. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  642. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  643. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  644. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  645. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  646. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  647. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  648. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  649. status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
  650. status += fx_file_open(&ram_disk, &file_5, "n", FX_OPEN_FOR_WRITE);
  651. status += fx_file_open(&ram_disk, &file_6, "nW", FX_OPEN_FOR_WRITE);
  652. status += fx_file_open(&ram_disk, &file_7, "nWW", FX_OPEN_FOR_WRITE);
  653. status += fx_file_open(&ram_disk, &file_8, "nWWW", FX_OPEN_FOR_WRITE);
  654. status += fx_file_open(&ram_disk, &file_9, "nWWWW", FX_OPEN_FOR_WRITE);
  655. status += fx_file_open(&ram_disk, &file_10, "nWWWWW", FX_OPEN_FOR_WRITE);
  656. status += fx_file_open(&ram_disk, &file_11, "nWWWWWW", FX_OPEN_FOR_WRITE);
  657. status += fx_file_open(&ram_disk, &file_12, "nWWWWWWW", FX_OPEN_FOR_WRITE);
  658. status += fx_file_open(&ram_disk, &file_13, "nWWWWWWWW", FX_OPEN_FOR_WRITE);
  659. status += fx_file_open(&ram_disk, &file_14, "nWWWWWWWWW", FX_OPEN_FOR_WRITE);
  660. status += fx_file_open(&ram_disk, &file_15, "nWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  661. status += fx_file_open(&ram_disk, &file_16, "nWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  662. status += fx_file_open(&ram_disk, &file_17, "nWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  663. status += fx_file_open(&ram_disk, &file_18, "nWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  664. status += fx_file_open(&ram_disk, &file_19, "nWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  665. status += fx_file_open(&ram_disk, &file_20, "nWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  666. status += fx_file_open(&ram_disk, &file_21, "nWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  667. status += fx_file_open(&ram_disk, &file_22, "nWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  668. status += fx_file_open(&ram_disk, &file_23, "nWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  669. status += fx_file_open(&ram_disk, &file_24, "nWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  670. status += fx_file_open(&ram_disk, &file_25, "nWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  671. status += fx_file_open(&ram_disk, &file_26, "nWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  672. status += fx_file_open(&ram_disk, &file_27, "nWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  673. status += fx_file_open(&ram_disk, &file_28, "nWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  674. status += fx_file_open(&ram_disk, &file_29, "nWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  675. status += fx_file_open(&ram_disk, &file_30, "nWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  676. status += fx_file_open(&ram_disk, &file_31, "nWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  677. status += fx_file_open(&ram_disk, &file_32, "nWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  678. status += fx_file_open(&ram_disk, &file_33, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  679. status += fx_file_open(&ram_disk, &file_34, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  680. status += fx_file_open(&ram_disk, &file_35, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  681. status += fx_file_open(&ram_disk, &file_36, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  682. status += fx_file_open(&ram_disk, &file_37, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  683. status += fx_file_open(&ram_disk, &file_38, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  684. status += fx_file_open(&ram_disk, &file_39, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  685. status += fx_file_open(&ram_disk, &file_40, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  686. status += fx_file_open(&ram_disk, &file_41, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  687. status += fx_file_open(&ram_disk, &file_42, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
  688. return_if_fail( status == FX_SUCCESS);
  689. /* Build a super long file name that will require additional cluster allocation in the sub-directory. */
  690. for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
  691. {
  692. name[i] = 'a';
  693. }
  694. name[FX_MAX_LONG_NAME_LEN-2] = 0;
  695. /* Test the wrap of the FAT table by allocating at the end. */
  696. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  697. status = fx_file_create(&ram_disk, name);
  698. status += fx_file_open(&ram_disk, &file_43, name, FX_OPEN_FOR_WRITE);
  699. return_if_fail( status == FX_SUCCESS);
  700. /* Change the name to create a new file name. */
  701. name[FX_MAX_LONG_NAME_LEN-3] = '0';
  702. /* Test the wrap of the FAT table by allocating at the end. */
  703. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  704. status += fx_file_create(&ram_disk, name);
  705. status += fx_file_open(&ram_disk, &file_44, name, FX_OPEN_FOR_WRITE);
  706. return_if_fail( status == FX_SUCCESS);
  707. name[FX_MAX_LONG_NAME_LEN-3] = '1';
  708. /* Now try to allocate an entry with no more available clusters. */
  709. temp = ram_disk.fx_media_available_clusters;
  710. ram_disk.fx_media_available_clusters = 0;
  711. status += fx_file_create(&ram_disk, name);
  712. ram_disk.fx_media_available_clusters = temp;
  713. return_if_fail( status == FX_NO_MORE_SPACE);
  714. name[FX_MAX_LONG_NAME_LEN-3] = '2';
  715. /* Now try to allocate an entry with no more total clusters. */
  716. temp = ram_disk.fx_media_total_clusters;
  717. _fx_utility_fat_entry_read_error_request = 40064;
  718. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  719. status = fx_file_create(&ram_disk, name);
  720. _fx_utility_fat_entry_read_error_request = 0;
  721. ram_disk.fx_media_total_clusters = temp;
  722. return_if_fail( status == FX_NO_MORE_SPACE);
  723. /* Now try to allocate a new cluster with a FAT read error in fx_directory_free_search. */
  724. temp = ram_disk.fx_media_total_clusters;
  725. _fx_utility_fat_entry_read_error_request = 65;
  726. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  727. status = fx_file_create(&ram_disk, name);
  728. _fx_utility_fat_entry_read_error_request = 0;
  729. ram_disk.fx_media_total_clusters = temp;
  730. return_if_fail( status == FX_IO_ERROR);
  731. /* Now try to allocate a new cluster with a logical sector read error in fx_directory_free_search. */
  732. _fx_utility_logical_sector_read_error_request = 172;
  733. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  734. status = fx_file_create(&ram_disk, name);
  735. _fx_utility_logical_sector_read_error_request = 0;
  736. return_if_fail( status == FX_IO_ERROR);
  737. #ifndef FX_DISABLE_CACHE
  738. /* Now try to allocate a new cluster with a logical sector flush error in fx_directory_free_search. */
  739. _fx_utility_logical_sector_flush_error_request = 1;
  740. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  741. status = fx_file_create(&ram_disk, name);
  742. _fx_utility_logical_sector_flush_error_request = 0;
  743. return_if_fail( status == FX_IO_ERROR);
  744. #endif
  745. /* Now try to allocate a new cluster with a write error when clearing additional sector clusters from fx_directory_free_search. */
  746. _fx_ram_driver_io_error_request = 91;
  747. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  748. status = fx_file_create(&ram_disk, name);
  749. _fx_ram_driver_io_error_request = 0;
  750. return_if_fail( status == FX_IO_ERROR);
  751. /* Now try to allocate a new cluster with a write error when writing the FAT link from fx_directory_free_search. */
  752. _fx_utility_fat_entry_write_error_request = 1;
  753. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  754. status = fx_file_create(&ram_disk, name);
  755. _fx_utility_fat_entry_write_error_request = 0;
  756. return_if_fail( status == FX_IO_ERROR);
  757. /* Now try to allocate a new cluster with a write error when writing the EOF FAT link from fx_directory_free_search. */
  758. _fx_utility_fat_entry_write_error_request = 3;
  759. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  760. status = fx_file_create(&ram_disk, name);
  761. _fx_utility_fat_entry_write_error_request = 0;
  762. return_if_fail( status == FX_IO_ERROR);
  763. /* Now try to allocate a new cluster with a logical sector write error when writing the new sub-directory sector in fx_directory_free_search. */
  764. _fx_utility_logical_sector_write_error_request = 1;
  765. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  766. status = fx_file_create(&ram_disk, name);
  767. _fx_utility_logical_sector_write_error_request = 0;
  768. return_if_fail( status == FX_IO_ERROR);
  769. /* Now try to allocate a new cluster with a total cluster of 0 in fx_directory_free_search. */
  770. _fx_utility_fat_entry_read_error_request = 92;
  771. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  772. status = fx_file_create(&ram_disk, name);
  773. _fx_utility_fat_entry_read_error_request = 0;
  774. return_if_fail( status == FX_IO_ERROR);
  775. /* Now try to allocate a new cluster with a bad read value (1) of intial cluster in sub-directory in fx_directory_free_search. */
  776. _fx_utility_fat_entry_read_error_request = 10095;
  777. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  778. status = fx_file_create(&ram_disk, name);
  779. _fx_utility_fat_entry_read_error_request = 0;
  780. return_if_fail( status == FX_FAT_READ_ERROR);
  781. /* Now try to allocate a new cluster with a bad read value (same as initial cluster) of intial cluster in sub-directory in fx_directory_free_search. */
  782. _fx_utility_fat_entry_read_error_request = 30098;
  783. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  784. status = fx_file_create(&ram_disk, name);
  785. _fx_utility_fat_entry_read_error_request = 0;
  786. return_if_fail( status == FX_FAT_READ_ERROR);
  787. /* Now try to allocate a new cluster with a bad read value (greater than max) of intial cluster in sub-directory in fx_directory_free_search. */
  788. temp = ram_disk.fx_media_total_clusters;
  789. _fx_utility_fat_entry_read_error_request = 40101;
  790. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  791. status = fx_file_create(&ram_disk, name);
  792. _fx_utility_fat_entry_read_error_request = 0;
  793. ram_disk.fx_media_total_clusters = temp;
  794. return_if_fail( status == FX_FAT_READ_ERROR);
  795. /* Now try to allocate a new cluster with an error linking the new cluster chain with the old one in sub-directory in fx_directory_free_search. */
  796. _fx_utility_fat_entry_write_error_request = 4;
  797. ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
  798. status = fx_file_create(&ram_disk, name);
  799. _fx_utility_fat_entry_write_error_request = 0;
  800. return_if_fail( status == FX_IO_ERROR);
  801. /* Now write to each file before we close them. */
  802. status = fx_file_write(&file_1, "1", 1);
  803. status += fx_file_write(&file_2, "1", 1);
  804. status += fx_file_write(&file_3, "1", 1);
  805. status += fx_file_write(&file_4, "1", 1);
  806. status += fx_file_write(&file_5, "1", 1);
  807. status += fx_file_write(&file_6, "1", 1);
  808. status += fx_file_write(&file_7, "1", 1);
  809. status += fx_file_write(&file_8, "1", 1);
  810. status += fx_file_write(&file_9, "1", 1);
  811. status += fx_file_write(&file_10, "1", 1);
  812. status += fx_file_write(&file_11, "1", 1);
  813. status += fx_file_write(&file_12, "1", 1);
  814. status += fx_file_write(&file_13, "1", 1);
  815. status += fx_file_write(&file_14, "1", 1);
  816. status += fx_file_write(&file_15, "1", 1);
  817. status += fx_file_write(&file_16, "1", 1);
  818. status += fx_file_write(&file_17, "1", 1);
  819. status += fx_file_write(&file_18, "1", 1);
  820. status += fx_file_write(&file_19, "1", 1);
  821. status += fx_file_write(&file_20, "1", 1);
  822. status += fx_file_write(&file_21, "1", 1);
  823. status += fx_file_write(&file_22, "1", 1);
  824. status += fx_file_write(&file_23, "1", 1);
  825. status += fx_file_write(&file_24, "1", 1);
  826. status += fx_file_write(&file_25, "1", 1);
  827. status += fx_file_write(&file_26, "1", 1);
  828. status += fx_file_write(&file_27, "1", 1);
  829. status += fx_file_write(&file_28, "1", 1);
  830. status += fx_file_write(&file_29, "1", 1);
  831. status += fx_file_write(&file_30, "1", 1);
  832. status += fx_file_write(&file_31, "1", 1);
  833. status += fx_file_write(&file_32, "1", 1);
  834. status += fx_file_write(&file_33, "1", 1);
  835. status += fx_file_write(&file_34, "1", 1);
  836. status += fx_file_write(&file_35, "1", 1);
  837. status += fx_file_write(&file_36, "1", 1);
  838. status += fx_file_write(&file_37, "1", 1);
  839. status += fx_file_write(&file_38, "1", 1);
  840. status += fx_file_write(&file_39, "1", 1);
  841. status += fx_file_write(&file_40, "1", 1);
  842. status += fx_file_write(&file_41, "1", 1);
  843. status += fx_file_write(&file_42, "1", 1);
  844. status += fx_file_write(&file_43, "1", 1);
  845. status += fx_file_write(&file_44, "1", 1);
  846. status += fx_file_close(&file_1);
  847. status += fx_file_close(&file_2);
  848. status += fx_file_close(&file_3);
  849. status += fx_file_close(&file_4);
  850. status += fx_file_close(&file_5);
  851. status += fx_file_close(&file_6);
  852. status += fx_file_close(&file_7);
  853. status += fx_file_close(&file_8);
  854. status += fx_file_close(&file_9);
  855. status += fx_file_close(&file_10);
  856. status += fx_file_close(&file_11);
  857. status += fx_file_close(&file_12);
  858. status += fx_file_close(&file_13);
  859. status += fx_file_close(&file_14);
  860. status += fx_file_close(&file_15);
  861. status += fx_file_close(&file_16);
  862. status += fx_file_close(&file_17);
  863. status += fx_file_close(&file_18);
  864. status += fx_file_close(&file_19);
  865. status += fx_file_close(&file_20);
  866. status += fx_file_close(&file_21);
  867. status += fx_file_close(&file_22);
  868. status += fx_file_close(&file_23);
  869. status += fx_file_close(&file_24);
  870. status += fx_file_close(&file_25);
  871. status += fx_file_close(&file_26);
  872. status += fx_file_close(&file_27);
  873. status += fx_file_close(&file_28);
  874. status += fx_file_close(&file_29);
  875. status += fx_file_close(&file_30);
  876. status += fx_file_close(&file_31);
  877. status += fx_file_close(&file_32);
  878. status += fx_file_close(&file_33);
  879. status += fx_file_close(&file_34);
  880. status += fx_file_close(&file_35);
  881. status += fx_file_close(&file_36);
  882. status += fx_file_close(&file_37);
  883. status += fx_file_close(&file_38);
  884. status += fx_file_close(&file_39);
  885. status += fx_file_close(&file_40);
  886. status += fx_file_close(&file_41);
  887. status += fx_file_close(&file_42);
  888. status += fx_file_close(&file_43);
  889. status += fx_file_close(&file_44);
  890. return_if_fail( status == FX_SUCCESS);
  891. /* Close the media. */
  892. status = fx_media_close(&ram_disk);
  893. return_if_fail( status == FX_SUCCESS);
  894. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  895. _fx_ram_driver_copy_default_format = 1;
  896. /* Open the ram_disk. */
  897. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  898. _fx_ram_driver_copy_default_format = 0;
  899. return_if_fail( status == FX_SUCCESS);
  900. /* Get the first file name, this should be "ntfile" for exercising the NT file name capability. */
  901. status = fx_directory_first_entry_find(&ram_disk, name);
  902. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  903. status += fx_directory_next_entry_find(&ram_disk, name);
  904. status += fx_directory_next_entry_find(&ram_disk, name);
  905. status += fx_directory_next_entry_find(&ram_disk, name);
  906. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  907. status += fx_directory_next_entry_find(&ram_disk, name);
  908. /* Write to both files, write to them and close them! */
  909. status += fx_file_write(&file_1, "abcd", 4);
  910. status += fx_file_write(&file_2, "abcd", 4);
  911. status += fx_file_close(&file_1);
  912. status += fx_file_close(&file_2);
  913. return_if_fail( status == FX_SUCCESS);
  914. /* Now look move to the first sub-directory. */
  915. status = fx_directory_default_set(&ram_disk, name);
  916. status += fx_directory_first_entry_find(&ram_disk, name); /* . */
  917. status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
  918. status += fx_directory_next_entry_find(&ram_disk, name); /* Too long of a file name. */
  919. status += fx_file_delete(&ram_disk, name);
  920. status += fx_directory_next_entry_find(&ram_disk, name); /* Next too long sub-directory. */
  921. status += fx_directory_default_set(&ram_disk, name); /* Move to next sub-directory. */
  922. return_if_fail( status == FX_SUCCESS);
  923. /* Move back to the root directory. */
  924. status += fx_directory_default_set(&ram_disk, "\\");
  925. /* Set an all blank volume name. */
  926. status += fx_media_volume_set(&ram_disk, " ");
  927. status += fx_media_volume_get(&ram_disk, volume_name, FX_DIRECTORY_SECTOR);
  928. status += fx_directory_first_entry_find(&ram_disk, name); /* ntfile */
  929. status += fx_directory_next_entry_find(&ram_disk, name); /* nt-file~.txt */
  930. status += fx_directory_next_entry_find(&ram_disk, name);
  931. status += fx_directory_next_entry_find(&ram_disk, name);
  932. status += fx_directory_next_entry_find(&ram_disk, name);
  933. status += fx_directory_next_entry_find(&ram_disk, name);
  934. status += fx_directory_next_entry_find(&ram_disk, name);
  935. status += fx_directory_next_entry_find(&ram_disk, name);
  936. /* Close the media. */
  937. status = fx_media_close(&ram_disk);
  938. return_if_fail( status == FX_SUCCESS);
  939. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  940. _fx_ram_driver_copy_default_format = 1;
  941. /* Open the ram_disk. */
  942. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  943. _fx_ram_driver_copy_default_format = 0;
  944. return_if_fail( status == FX_SUCCESS);
  945. /* Get the first shorted file name. */
  946. status = fx_directory_first_entry_find(&ram_disk, name);
  947. status += fx_directory_next_entry_find(&ram_disk, name);
  948. status += fx_directory_next_entry_find(&ram_disk, name);
  949. status += fx_directory_next_entry_find(&ram_disk, name);
  950. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  951. /* Write to the shorted file. */
  952. status += fx_file_write(&file_2, "abcd", 4);
  953. /* Now close the file, which will write the shorted file entry out. */
  954. _fx_utility_logical_sector_write_error_request = 1;
  955. status += fx_file_close(&file_2);
  956. _fx_utility_logical_sector_write_error_request = 0;
  957. return_if_fail( status == FX_IO_ERROR);
  958. /* Close the media. */
  959. status = fx_media_close(&ram_disk);
  960. return_if_fail( status == FX_SUCCESS);
  961. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  962. _fx_ram_driver_copy_default_format = 1;
  963. /* Open the ram_disk. */
  964. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  965. _fx_ram_driver_copy_default_format = 0;
  966. return_if_fail( status == FX_SUCCESS);
  967. /* Get the first shorted file name. */
  968. status = fx_directory_first_entry_find(&ram_disk, name);
  969. status += fx_directory_next_entry_find(&ram_disk, name);
  970. status += fx_directory_next_entry_find(&ram_disk, name);
  971. status += fx_directory_next_entry_find(&ram_disk, name);
  972. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  973. /* Write to the shorted file. */
  974. status += fx_file_write(&file_2, "abcd", 4);
  975. /* Now close the file, which will write the shorted file entry out. */
  976. temp = ram_disk.fx_media_data_sector_start;
  977. ram_disk.fx_media_data_sector_start = ram_disk.fx_media_root_sector_start+2;
  978. status += fx_file_close(&file_2);
  979. ram_disk.fx_media_data_sector_start = temp;
  980. return_if_fail( status == FX_FILE_CORRUPT);
  981. /* Close the media. */
  982. status = fx_media_close(&ram_disk);
  983. return_if_fail( status == FX_SUCCESS);
  984. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  985. _fx_ram_driver_copy_default_format = 1;
  986. /* Open the ram_disk. */
  987. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  988. _fx_ram_driver_copy_default_format = 0;
  989. return_if_fail( status == FX_SUCCESS);
  990. /* Get the first shorted file name. */
  991. status = fx_directory_first_entry_find(&ram_disk, name);
  992. status += fx_directory_next_entry_find(&ram_disk, name);
  993. status += fx_directory_next_entry_find(&ram_disk, name);
  994. status += fx_directory_next_entry_find(&ram_disk, name);
  995. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  996. status += fx_directory_next_entry_find(&ram_disk, name);
  997. /* Write to the shorted file. */
  998. status += fx_file_write(&file_2, "abcd", 4);
  999. /* Now close the file, which will write the shorted file entry out. */
  1000. _fx_utility_logical_sector_read_error_request = 2;
  1001. status += fx_file_close(&file_2);
  1002. _fx_utility_logical_sector_read_error_request = 0;
  1003. return_if_fail( status == FX_IO_ERROR);
  1004. /* Close the media. */
  1005. status = fx_media_close(&ram_disk);
  1006. return_if_fail( status == FX_SUCCESS);
  1007. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  1008. _fx_ram_driver_copy_default_format = 1;
  1009. /* Open the ram_disk. */
  1010. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1011. _fx_ram_driver_copy_default_format = 0;
  1012. return_if_fail( status == FX_SUCCESS);
  1013. /* Get the first shorted file name. */
  1014. status = fx_directory_first_entry_find(&ram_disk, name);
  1015. status += fx_directory_next_entry_find(&ram_disk, name);
  1016. status += fx_directory_next_entry_find(&ram_disk, name);
  1017. status += fx_directory_next_entry_find(&ram_disk, name);
  1018. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  1019. status += fx_directory_next_entry_find(&ram_disk, name);
  1020. status += fx_media_flush(&ram_disk);
  1021. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start+1, buffer);
  1022. buffer[0x40] = 0x1f;
  1023. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start+1, buffer);
  1024. /* Write to the shorted file. */
  1025. status += fx_file_write(&file_2, "abcd", 4);
  1026. /* Now close the file, which will write the shorted file entry out.... not that the shorted flag is not in the actual directory entry. */
  1027. status += fx_file_close(&file_2);
  1028. return_if_fail( status == FX_SUCCESS);
  1029. /* Close the media. */
  1030. status = fx_media_close(&ram_disk);
  1031. return_if_fail( status == FX_SUCCESS);
  1032. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  1033. _fx_ram_driver_copy_default_format = 1;
  1034. /* Open the ram_disk. */
  1035. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1036. _fx_ram_driver_copy_default_format = 0;
  1037. return_if_fail( status == FX_SUCCESS);
  1038. /* Get the first shorted file name. */
  1039. status += fx_directory_next_entry_find(&ram_disk, name);
  1040. status += fx_directory_next_entry_find(&ram_disk, name);
  1041. status += fx_directory_next_entry_find(&ram_disk, name);
  1042. status += fx_directory_next_entry_find(&ram_disk, name);
  1043. status += fx_directory_next_entry_find(&ram_disk, name);
  1044. /* Switch to this directory. */
  1045. status += fx_directory_default_set(&ram_disk, name);
  1046. status = fx_directory_first_entry_find(&ram_disk, name); /* . */
  1047. status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
  1048. status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
  1049. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  1050. /* Write to the shorted file. */
  1051. status += fx_file_write(&file_2, "abcd", 4);
  1052. /* Now close the file, which will write the shorted file entry out. */
  1053. _fx_utility_fat_entry_read_error_request = 1;
  1054. status += fx_file_close(&file_2);
  1055. _fx_utility_fat_entry_read_error_request = 0;
  1056. /* Check the status - should be an error here. */
  1057. if (status != FX_IO_ERROR)
  1058. {
  1059. /* Error, return error code. */
  1060. printf("ERROR!\n");
  1061. test_control_return(97);
  1062. }
  1063. /* Close the media. */
  1064. status = fx_media_close(&ram_disk);
  1065. /* Determine if the test was successful. */
  1066. if (status != FX_SUCCESS)
  1067. {
  1068. printf("ERROR!\n");
  1069. test_control_return(98);
  1070. }
  1071. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  1072. _fx_ram_driver_copy_default_format = 1;
  1073. /* Open the ram_disk. */
  1074. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1075. _fx_ram_driver_copy_default_format = 0;
  1076. /* Check the status. */
  1077. if (status != FX_SUCCESS)
  1078. {
  1079. /* Error, return error code. */
  1080. printf("ERROR!\n");
  1081. test_control_return(99);
  1082. }
  1083. /* Get the first shorted file name. */
  1084. status += fx_directory_next_entry_find(&ram_disk, name);
  1085. status += fx_directory_next_entry_find(&ram_disk, name);
  1086. status += fx_directory_next_entry_find(&ram_disk, name);
  1087. status += fx_directory_next_entry_find(&ram_disk, name);
  1088. status += fx_directory_next_entry_find(&ram_disk, name);
  1089. /* Switch to this directory. */
  1090. status += fx_directory_default_set(&ram_disk, name);
  1091. status = fx_directory_first_entry_find(&ram_disk, name); /* . */
  1092. status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
  1093. status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
  1094. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  1095. /* Write to the shorted file. */
  1096. status += fx_file_write(&file_2, "abcd", 4);
  1097. /* Now close the file, which will write the shorted file entry out. */
  1098. _fx_utility_fat_entry_read_error_request = 10001;
  1099. status += fx_file_close(&file_2);
  1100. _fx_utility_fat_entry_read_error_request = 0;
  1101. /* Check the status - should be an error here. */
  1102. if (status != FX_FILE_CORRUPT)
  1103. {
  1104. /* Error, return error code. */
  1105. printf("ERROR!\n");
  1106. test_control_return(100);
  1107. }
  1108. /* Close the media. */
  1109. status = fx_media_close(&ram_disk);
  1110. /* Determine if the test was successful. */
  1111. if (status != FX_SUCCESS)
  1112. {
  1113. printf("ERROR!\n");
  1114. test_control_return(101);
  1115. }
  1116. /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
  1117. _fx_ram_driver_copy_default_format = 1;
  1118. /* Open the ram_disk. */
  1119. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1120. _fx_ram_driver_copy_default_format = 0;
  1121. /* Check the status. */
  1122. if (status != FX_SUCCESS)
  1123. {
  1124. /* Error, return error code. */
  1125. printf("ERROR!\n");
  1126. test_control_return(102);
  1127. }
  1128. /* Get the first shorted file name. */
  1129. status += fx_directory_next_entry_find(&ram_disk, name);
  1130. status += fx_directory_next_entry_find(&ram_disk, name);
  1131. status += fx_directory_next_entry_find(&ram_disk, name);
  1132. status += fx_directory_next_entry_find(&ram_disk, name);
  1133. status += fx_directory_next_entry_find(&ram_disk, name);
  1134. /* Switch to this directory. */
  1135. status += fx_directory_default_set(&ram_disk, name);
  1136. status = fx_directory_first_entry_find(&ram_disk, name); /* . */
  1137. status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
  1138. status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
  1139. status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
  1140. /* Write to the shorted file. */
  1141. status += fx_file_write(&file_2, "abcd", 4);
  1142. /* Now close the file, which will write the shorted file entry out. */
  1143. _fx_utility_fat_entry_read_error_request = 20001;
  1144. status += fx_file_close(&file_2);
  1145. _fx_utility_fat_entry_read_error_request = 0;
  1146. /* Check the status - should be an error here. */
  1147. if (status != FX_FILE_CORRUPT)
  1148. {
  1149. /* Error, return error code. */
  1150. printf("ERROR!\n");
  1151. test_control_return(103);
  1152. }
  1153. /* Close the media. */
  1154. status = fx_media_close(&ram_disk);
  1155. /* Determine if the test was successful. */
  1156. if (status != FX_SUCCESS)
  1157. {
  1158. printf("ERROR!\n");
  1159. test_control_return(104);
  1160. }
  1161. /* Format the media. This needs to be done before opening it! */
  1162. status = fx_media_format(&ram_disk,
  1163. _fx_ram_driver, // Driver entry
  1164. ram_disk_memory, // RAM disk memory pointer
  1165. cache_buffer, // Media buffer pointer
  1166. CACHE_SIZE, // Media buffer size
  1167. "MY_RAM_DISK", // Volume Name
  1168. 1, // Number of FATs
  1169. 32, // Directory Entries
  1170. 0, // Hidden sectors
  1171. 14000, // Total sectors
  1172. 128, // Sector size
  1173. 2, // Sectors per cluster
  1174. 1, // Heads
  1175. 1); // Sectors per track
  1176. /* Determine if the format had an error. */
  1177. if (status)
  1178. {
  1179. printf("ERROR!\n");
  1180. test_control_return(105);
  1181. }
  1182. /* Open the ram_disk. */
  1183. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1184. /* Check the status. */
  1185. if (status != FX_SUCCESS)
  1186. {
  1187. /* Error, return error code. */
  1188. printf("ERROR!\n");
  1189. test_control_return(106);
  1190. }
  1191. /* Build a sub-directory structure to further test diretory entry read. */
  1192. status = fx_directory_create(&ram_disk, "SUB1");
  1193. status += fx_directory_default_set(&ram_disk, "SUB1");
  1194. status += fx_file_create(&ram_disk, "S1_FL1.TXT");
  1195. status += fx_file_create(&ram_disk, "S1_FL2.TXT");
  1196. status += fx_file_create(&ram_disk, "S1_FL3.TXT");
  1197. status += fx_file_create(&ram_disk, "S1_FL4.TXT");
  1198. status += fx_file_create(&ram_disk, "S1_FL5.TXT");
  1199. status += fx_file_create(&ram_disk, "S1_FL6.TXT");
  1200. status += fx_file_create(&ram_disk, "S1_FL7.TXT");
  1201. status += fx_file_create(&ram_disk, "S1_FL8.TXT");
  1202. status += fx_file_create(&ram_disk, "S1_FL9.TXT");
  1203. status += fx_file_create(&ram_disk, "S1_FL10.TXT");
  1204. status += fx_file_create(&ram_disk, "S1_FL11.TXT");
  1205. status += fx_file_create(&ram_disk, "S1_FL12.TXT");
  1206. status += fx_file_create(&ram_disk, "S1_FL13.TXT");
  1207. status += fx_file_create(&ram_disk, "S1_FL14.TXT");
  1208. status += fx_file_create(&ram_disk, "S1_FL15.TXT");
  1209. status += fx_file_create(&ram_disk, "S1_FL16.TXT");
  1210. status += fx_file_create(&ram_disk, "S1_FL17.TXT");
  1211. status += fx_file_create(&ram_disk, "S1_FL18.TXT");
  1212. status += fx_file_create(&ram_disk, "S1_FL19.TXT");
  1213. status += fx_file_create(&ram_disk, "S1_FL20.TXT");
  1214. status += fx_file_create(&ram_disk, "S1_FL21.TXT");
  1215. status += fx_file_create(&ram_disk, "S1_FL22.TXT");
  1216. status += fx_file_create(&ram_disk, "S1_FL23.TXT");
  1217. status += fx_file_create(&ram_disk, "S1_FL24.TXT");
  1218. status += fx_file_create(&ram_disk, "S1_FL25.TXT");
  1219. status += fx_file_create(&ram_disk, "S1_FL26.TXT");
  1220. status += fx_file_create(&ram_disk, "S1_FL27.TXT");
  1221. status += fx_file_create(&ram_disk, "S1_FL28.TXT");
  1222. status += fx_file_create(&ram_disk, "S1_FL29.TXT");
  1223. status += fx_file_create(&ram_disk, "S1_FL30.TXT");
  1224. status += fx_file_create(&ram_disk, "S1_FL31.TXT");
  1225. status += fx_file_create(&ram_disk, "S1_FL32.TXT");
  1226. /* Now taverse the directory tree and open files. */
  1227. status += fx_directory_first_entry_find(&ram_disk, name);
  1228. status += fx_directory_next_entry_find(&ram_disk, name);
  1229. status += fx_directory_next_entry_find(&ram_disk, name);
  1230. status += fx_directory_next_entry_find(&ram_disk, name);
  1231. status += fx_directory_next_entry_find(&ram_disk, name);
  1232. status += fx_directory_next_entry_find(&ram_disk, name);
  1233. status += fx_directory_next_entry_find(&ram_disk, name);
  1234. status += fx_directory_next_entry_find(&ram_disk, name);
  1235. status += fx_directory_next_entry_find(&ram_disk, name);
  1236. status += fx_directory_next_entry_find(&ram_disk, name);
  1237. status += fx_directory_next_entry_find(&ram_disk, name);
  1238. status += fx_directory_next_entry_find(&ram_disk, name);
  1239. status += fx_directory_next_entry_find(&ram_disk, name);
  1240. status += fx_directory_next_entry_find(&ram_disk, name);
  1241. status += fx_directory_next_entry_find(&ram_disk, name);
  1242. status += fx_directory_next_entry_find(&ram_disk, name);
  1243. status += fx_directory_next_entry_find(&ram_disk, name);
  1244. status += fx_directory_next_entry_find(&ram_disk, name);
  1245. status += fx_directory_next_entry_find(&ram_disk, name);
  1246. status += fx_directory_next_entry_find(&ram_disk, name);
  1247. status += fx_directory_next_entry_find(&ram_disk, name);
  1248. status += fx_directory_next_entry_find(&ram_disk, name);
  1249. status += fx_directory_next_entry_find(&ram_disk, name);
  1250. status += fx_directory_next_entry_find(&ram_disk, name);
  1251. status += fx_directory_next_entry_find(&ram_disk, name);
  1252. status += fx_directory_next_entry_find(&ram_disk, name);
  1253. status += fx_directory_next_entry_find(&ram_disk, name);
  1254. status += fx_directory_next_entry_find(&ram_disk, name);
  1255. status += fx_directory_next_entry_find(&ram_disk, name);
  1256. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_relative_cluster = 100;
  1257. status += fx_directory_next_entry_find(&ram_disk, name);
  1258. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_log_sector = 1000;
  1259. status += fx_directory_next_entry_find(&ram_disk, name);
  1260. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_byte_offset = 10000;
  1261. status += fx_directory_next_entry_find(&ram_disk, name);
  1262. /* Determine if the test was successful. */
  1263. if (status != FX_SUCCESS)
  1264. {
  1265. printf("ERROR!\n");
  1266. test_control_return(107);
  1267. }
  1268. /* Now go back to the beginning of the directory. */
  1269. status += fx_directory_first_entry_find(&ram_disk, name);
  1270. status += fx_directory_next_entry_find(&ram_disk, name);
  1271. status += fx_directory_next_entry_find(&ram_disk, name);
  1272. status += fx_directory_next_entry_find(&ram_disk, name);
  1273. status += fx_directory_next_entry_find(&ram_disk, name);
  1274. status += fx_directory_next_entry_find(&ram_disk, name);
  1275. status += fx_directory_next_entry_find(&ram_disk, name);
  1276. status += fx_directory_next_entry_find(&ram_disk, name);
  1277. status += fx_directory_next_entry_find(&ram_disk, name);
  1278. status += fx_directory_next_entry_find(&ram_disk, name);
  1279. status += fx_directory_next_entry_find(&ram_disk, name);
  1280. status += fx_directory_next_entry_find(&ram_disk, name);
  1281. status += fx_directory_next_entry_find(&ram_disk, name);
  1282. status += fx_directory_next_entry_find(&ram_disk, name);
  1283. status += fx_directory_next_entry_find(&ram_disk, name);
  1284. status += fx_directory_next_entry_find(&ram_disk, name);
  1285. status += fx_directory_next_entry_find(&ram_disk, name);
  1286. status += fx_directory_next_entry_find(&ram_disk, name);
  1287. status += fx_directory_next_entry_find(&ram_disk, name);
  1288. status += fx_directory_next_entry_find(&ram_disk, name);
  1289. status += fx_directory_next_entry_find(&ram_disk, name);
  1290. /* Search with I/O read error. */
  1291. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
  1292. _fx_utility_fat_entry_read_error_request = 1;
  1293. status += fx_directory_next_entry_find(&ram_disk, name);
  1294. _fx_utility_fat_entry_read_error_request = 0;
  1295. /* Determine if the expected I/O error is present. */
  1296. if (status != FX_IO_ERROR)
  1297. {
  1298. printf("ERROR!\n");
  1299. test_control_return(108);
  1300. }
  1301. /* Search with bad FAT error - too small. */
  1302. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
  1303. _fx_utility_fat_entry_read_error_request = 10001;
  1304. status = fx_directory_next_entry_find(&ram_disk, name);
  1305. _fx_utility_fat_entry_read_error_request = 0;
  1306. /* Determine if the expected I/O error is present. */
  1307. if (status != FX_FILE_CORRUPT)
  1308. {
  1309. printf("ERROR!\n");
  1310. test_control_return(109);
  1311. }
  1312. /* Search with bad FAT error - too small. */
  1313. ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
  1314. _fx_utility_fat_entry_read_error_request = 20001;
  1315. status = fx_directory_next_entry_find(&ram_disk, name);
  1316. _fx_utility_fat_entry_read_error_request = 0;
  1317. /* Determine if the expected I/O error is present. */
  1318. if (status != FX_FILE_CORRUPT)
  1319. {
  1320. printf("ERROR!\n");
  1321. test_control_return(110);
  1322. }
  1323. /* Corrupt the media to test zero divisor checking. */
  1324. ram_disk.fx_media_bytes_per_sector = 0;
  1325. status = fx_directory_next_entry_find(&ram_disk, name);
  1326. /* Determine if the expected error is present. */
  1327. if (status != FX_MEDIA_INVALID)
  1328. {
  1329. printf("ERROR!\n");
  1330. test_control_return(110);
  1331. }
  1332. ram_disk.fx_media_bytes_per_sector = 128;
  1333. /* Build a large file name. */
  1334. for (i = 0; i < 255; i++)
  1335. {
  1336. name[i] = 'a';
  1337. }
  1338. name[255] = 0;
  1339. /* Move back to the root directory. */
  1340. status = fx_directory_default_set(&ram_disk, "\\");
  1341. status += fx_unicode_file_create(&ram_disk, my_unicode_name, 15, (CHAR *)buffer);
  1342. status += fx_unicode_file_create(&ram_disk, my_unicode_name1, 15, (CHAR *)buffer);
  1343. status += fx_file_create(&ram_disk, name);
  1344. /* Set the search to the beginning of the root directory. */
  1345. status += fx_directory_first_entry_find(&ram_disk, name);
  1346. status += fx_directory_next_entry_find(&ram_disk, name);
  1347. status += fx_directory_next_entry_find(&ram_disk, name);
  1348. /* Determine if the test was successful. */
  1349. if (status != FX_SUCCESS)
  1350. {
  1351. printf("ERROR!\n");
  1352. test_control_return(111);
  1353. }
  1354. /* Now generate an error on the root directory size. */
  1355. temp = ram_disk.fx_media_root_sectors;
  1356. ram_disk.fx_media_root_sectors = 1;
  1357. status = fx_directory_next_entry_find(&ram_disk, name);
  1358. ram_disk.fx_media_root_sectors = temp;
  1359. /* Determine if the expected I/O error is present. */
  1360. if (status != FX_FILE_CORRUPT)
  1361. {
  1362. printf("ERROR!\n");
  1363. test_control_return(112);
  1364. }
  1365. /* Now generate an error with a logical sector read error. */
  1366. _fx_utility_logical_sector_read_error_request = 5;
  1367. status = fx_directory_next_entry_find(&ram_disk, name);
  1368. _fx_utility_logical_sector_read_error_request = 0;
  1369. /* Determine if the expected I/O error is present. */
  1370. if (status != FX_IO_ERROR)
  1371. {
  1372. printf("ERROR!\n");
  1373. test_control_return(113);
  1374. }
  1375. /* Close the media. */
  1376. status = fx_media_close(&ram_disk);
  1377. /* Determine if the test was successful. */
  1378. if (status != FX_SUCCESS)
  1379. {
  1380. printf("ERROR!\n");
  1381. test_control_return(114);
  1382. }
  1383. /* Format the media. This needs to be done before opening it! */
  1384. status = fx_media_format(&ram_disk,
  1385. _fx_ram_driver, // Driver entry
  1386. ram_disk_memory, // RAM disk memory pointer
  1387. cache_buffer, // Media buffer pointer
  1388. CACHE_SIZE, // Media buffer size
  1389. "MY_RAM_DISK", // Volume Name
  1390. 1, // Number of FATs
  1391. 32, // Directory Entries
  1392. 0, // Hidden sectors
  1393. 14000, // Total sectors
  1394. 128, // Sector size
  1395. 1, // Sectors per cluster
  1396. 1, // Heads
  1397. 1); // Sectors per track
  1398. /* Determine if the format had an error. */
  1399. if (status)
  1400. {
  1401. printf("ERROR!\n");
  1402. test_control_return(115);
  1403. }
  1404. /* Open the ram_disk. */
  1405. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1406. /* Check the status. */
  1407. if (status != FX_SUCCESS)
  1408. {
  1409. /* Error, return error code. */
  1410. printf("ERROR!\n");
  1411. test_control_return(116);
  1412. }
  1413. /* Build a large file name. */
  1414. for (i = 0; i < 255; i++)
  1415. {
  1416. name[i] = 'a';
  1417. }
  1418. name[255] = 0;
  1419. /* Create a sub-directory. */
  1420. status = fx_directory_create(&ram_disk, "SUB1");
  1421. status += fx_directory_default_set(&ram_disk, "SUB1");
  1422. status += fx_file_create(&ram_disk, name);
  1423. status += fx_directory_first_entry_find(&ram_disk, (CHAR *)buffer);
  1424. status += fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
  1425. /* Check the status. */
  1426. if (status != FX_SUCCESS)
  1427. {
  1428. /* Error, return error code. */
  1429. printf("ERROR!\n");
  1430. test_control_return(117);
  1431. }
  1432. /* Read the first entry, but with a FAT entry error. */
  1433. _fx_utility_fat_entry_read_error_request = 1;
  1434. status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
  1435. _fx_utility_fat_entry_read_error_request = 0;
  1436. /* Determine if the expected I/O error is present. */
  1437. if (status != FX_IO_ERROR)
  1438. {
  1439. printf("ERROR!\n");
  1440. test_control_return(118);
  1441. }
  1442. /* Read the first entry, but with a FAT entry error - too small. */
  1443. _fx_utility_fat_entry_read_error_request = 10001;
  1444. status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
  1445. _fx_utility_fat_entry_read_error_request = 0;
  1446. /* Determine if the expected I/O error is present. */
  1447. if (status != FX_FILE_CORRUPT)
  1448. {
  1449. printf("ERROR!\n");
  1450. test_control_return(119);
  1451. }
  1452. /* Read the first entry, but with a FAT entry error - too big. */
  1453. _fx_utility_fat_entry_read_error_request = 20001;
  1454. status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
  1455. _fx_utility_fat_entry_read_error_request = 0;
  1456. /* Determine if the expected I/O error is present. */
  1457. if (status != FX_FILE_CORRUPT)
  1458. {
  1459. printf("ERROR!\n");
  1460. test_control_return(120);
  1461. }
  1462. /* Close the media. */
  1463. status = fx_media_close(&ram_disk);
  1464. /* Determine if the test was successful. */
  1465. if (status != FX_SUCCESS)
  1466. {
  1467. printf("ERROR!\n");
  1468. test_control_return(121);
  1469. }
  1470. /* Format the media. This needs to be done before opening it! */
  1471. status = fx_media_format(&ram_disk,
  1472. _fx_ram_driver, // Driver entry
  1473. ram_disk_memory, // RAM disk memory pointer
  1474. cache_buffer, // Media buffer pointer
  1475. CACHE_SIZE, // Media buffer size
  1476. "MY_RAM_DISK", // Volume Name
  1477. 1, // Number of FATs
  1478. 512, // Directory Entries
  1479. 0, // Hidden sectors
  1480. 14000, // Total sectors
  1481. 128, // Sector size
  1482. 1, // Sectors per cluster
  1483. 1, // Heads
  1484. 1); // Sectors per track
  1485. /* Determine if the format had an error. */
  1486. if (status)
  1487. {
  1488. printf("ERROR!\n");
  1489. test_control_return(122);
  1490. }
  1491. /* Open the ram_disk. */
  1492. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1493. /* Check the status. */
  1494. if (status != FX_SUCCESS)
  1495. {
  1496. /* Error, return error code. */
  1497. printf("ERROR!\n");
  1498. test_control_return(123);
  1499. }
  1500. /* Build a large file name. */
  1501. for (i = 0; i < 255; i++)
  1502. {
  1503. name[i] = 'a';
  1504. }
  1505. name[255] = 0;
  1506. /* Create a large file name in the root directory. */
  1507. _fx_utility_logical_sector_write_error_request = 22;
  1508. status = fx_file_create(&ram_disk, name);
  1509. _fx_utility_logical_sector_write_error_request = 0;
  1510. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1511. status += fx_media_flush(&ram_disk);
  1512. /* Determine if have the expected I/O error. */
  1513. if (status != FX_IO_ERROR)
  1514. {
  1515. printf("ERROR!\n");
  1516. test_control_return(124);
  1517. }
  1518. /* Close the media. */
  1519. status = fx_media_close(&ram_disk);
  1520. /* Determine if the test was successful. */
  1521. if (status != FX_SUCCESS)
  1522. {
  1523. printf("ERROR!\n");
  1524. test_control_return(125);
  1525. }
  1526. /* Format the media. This needs to be done before opening it! */
  1527. status = fx_media_format(&ram_disk,
  1528. _fx_ram_driver, // Driver entry
  1529. ram_disk_memory, // RAM disk memory pointer
  1530. cache_buffer, // Media buffer pointer
  1531. CACHE_SIZE, // Media buffer size
  1532. "MY_RAM_DISK", // Volume Name
  1533. 1, // Number of FATs
  1534. 512, // Directory Entries
  1535. 0, // Hidden sectors
  1536. 14000, // Total sectors
  1537. 128, // Sector size
  1538. 1, // Sectors per cluster
  1539. 1, // Heads
  1540. 1); // Sectors per track
  1541. /* Determine if the format had an error. */
  1542. if (status)
  1543. {
  1544. printf("ERROR!\n");
  1545. test_control_return(126);
  1546. }
  1547. /* Open the ram_disk. */
  1548. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1549. /* Check the status. */
  1550. if (status != FX_SUCCESS)
  1551. {
  1552. /* Error, return error code. */
  1553. printf("ERROR!\n");
  1554. test_control_return(127);
  1555. }
  1556. /* Build a large file name. */
  1557. for (i = 0; i < 255; i++)
  1558. {
  1559. name[i] = 'a';
  1560. }
  1561. name[255] = 0;
  1562. /* Create a large file name in the root directory. */
  1563. _fx_utility_logical_sector_read_error_request = 45;
  1564. status = fx_file_create(&ram_disk, name);
  1565. _fx_utility_logical_sector_read_error_request = 0;
  1566. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1567. status += fx_media_flush(&ram_disk);
  1568. /* Determine if have the expected I/O error. */
  1569. if (status != FX_IO_ERROR)
  1570. {
  1571. printf("ERROR!\n");
  1572. test_control_return(128);
  1573. }
  1574. /* Close the media. */
  1575. status = fx_media_close(&ram_disk);
  1576. /* Determine if the test was successful. */
  1577. if (status != FX_SUCCESS)
  1578. {
  1579. printf("ERROR!\n");
  1580. test_control_return(129);
  1581. }
  1582. /* Format the media. This needs to be done before opening it! */
  1583. status = fx_media_format(&ram_disk,
  1584. _fx_ram_driver, // Driver entry
  1585. ram_disk_memory, // RAM disk memory pointer
  1586. cache_buffer, // Media buffer pointer
  1587. CACHE_SIZE, // Media buffer size
  1588. "MY_RAM_DISK", // Volume Name
  1589. 1, // Number of FATs
  1590. 512, // Directory Entries
  1591. 0, // Hidden sectors
  1592. 14000, // Total sectors
  1593. 128, // Sector size
  1594. 1, // Sectors per cluster
  1595. 1, // Heads
  1596. 1); // Sectors per track
  1597. /* Determine if the format had an error. */
  1598. if (status)
  1599. {
  1600. printf("ERROR!\n");
  1601. test_control_return(130);
  1602. }
  1603. /* Open the ram_disk. */
  1604. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1605. /* Check the status. */
  1606. if (status != FX_SUCCESS)
  1607. {
  1608. /* Error, return error code. */
  1609. printf("ERROR!\n");
  1610. test_control_return(131);
  1611. }
  1612. /* Build a large file name. */
  1613. for (i = 0; i < 255; i++)
  1614. {
  1615. name[i] = 'a';
  1616. }
  1617. name[255] = 0;
  1618. /* Create a large file name in the root directory. */
  1619. temp = ram_disk.fx_media_data_sector_start;
  1620. ram_disk.fx_media_data_sector_start = ram_disk.fx_media_root_sector_start+1;
  1621. status = fx_file_create(&ram_disk, name);
  1622. ram_disk.fx_media_data_sector_start = temp;
  1623. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1624. status += fx_media_flush(&ram_disk);
  1625. /* Determine if have the expected error. */
  1626. if (status != FX_FILE_CORRUPT)
  1627. {
  1628. printf("ERROR!\n");
  1629. test_control_return(132);
  1630. }
  1631. /* Close the media. */
  1632. status = fx_media_close(&ram_disk);
  1633. /* Determine if the test was successful. */
  1634. if (status != FX_SUCCESS)
  1635. {
  1636. printf("ERROR!\n");
  1637. test_control_return(133);
  1638. }
  1639. /* Format the media. This needs to be done before opening it! */
  1640. status = fx_media_format(&ram_disk,
  1641. _fx_ram_driver, // Driver entry
  1642. ram_disk_memory, // RAM disk memory pointer
  1643. cache_buffer, // Media buffer pointer
  1644. CACHE_SIZE, // Media buffer size
  1645. "MY_RAM_DISK", // Volume Name
  1646. 1, // Number of FATs
  1647. 512, // Directory Entries
  1648. 0, // Hidden sectors
  1649. 14000, // Total sectors
  1650. 128, // Sector size
  1651. 1, // Sectors per cluster
  1652. 1, // Heads
  1653. 1); // Sectors per track
  1654. /* Determine if the format had an error. */
  1655. if (status)
  1656. {
  1657. printf("ERROR!\n");
  1658. test_control_return(134);
  1659. }
  1660. /* Open the ram_disk. */
  1661. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1662. /* Check the status. */
  1663. if (status != FX_SUCCESS)
  1664. {
  1665. /* Error, return error code. */
  1666. printf("ERROR!\n");
  1667. test_control_return(135);
  1668. }
  1669. /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
  1670. status = fx_directory_create(&ram_disk, "SUB1");
  1671. status += fx_directory_default_set(&ram_disk, "SUB1");
  1672. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1673. status += fx_media_flush(&ram_disk);
  1674. /* Check the status. */
  1675. if (status != FX_SUCCESS)
  1676. {
  1677. /* Error, return error code. */
  1678. printf("ERROR!\n");
  1679. test_control_return(136);
  1680. }
  1681. /* Build a large file name. */
  1682. for (i = 0; i < 255; i++)
  1683. {
  1684. name[i] = 'a';
  1685. }
  1686. name[255] = 0;
  1687. /* Create a large file name in the sub-directory with a FAT entry read error. */
  1688. _fx_utility_fat_entry_read_error_request = 14;
  1689. status = fx_file_create(&ram_disk, name);
  1690. _fx_utility_fat_entry_read_error_request = 0;
  1691. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1692. status += fx_media_flush(&ram_disk);
  1693. /* Determine if have the expected error. */
  1694. if (status != FX_IO_ERROR)
  1695. {
  1696. printf("ERROR!\n");
  1697. test_control_return(137);
  1698. }
  1699. /* Close the media. */
  1700. status = fx_media_close(&ram_disk);
  1701. /* Determine if the test was successful. */
  1702. if (status != FX_SUCCESS)
  1703. {
  1704. printf("ERROR!\n");
  1705. test_control_return(138);
  1706. }
  1707. /* Format the media. This needs to be done before opening it! */
  1708. status = fx_media_format(&ram_disk,
  1709. _fx_ram_driver, // Driver entry
  1710. ram_disk_memory, // RAM disk memory pointer
  1711. cache_buffer, // Media buffer pointer
  1712. CACHE_SIZE, // Media buffer size
  1713. "MY_RAM_DISK", // Volume Name
  1714. 1, // Number of FATs
  1715. 512, // Directory Entries
  1716. 0, // Hidden sectors
  1717. 14000, // Total sectors
  1718. 128, // Sector size
  1719. 1, // Sectors per cluster
  1720. 1, // Heads
  1721. 1); // Sectors per track
  1722. /* Determine if the format had an error. */
  1723. if (status)
  1724. {
  1725. printf("ERROR!\n");
  1726. test_control_return(139);
  1727. }
  1728. /* Open the ram_disk. */
  1729. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1730. /* Check the status. */
  1731. if (status != FX_SUCCESS)
  1732. {
  1733. /* Error, return error code. */
  1734. printf("ERROR!\n");
  1735. test_control_return(140);
  1736. }
  1737. /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
  1738. status = fx_directory_create(&ram_disk, "SUB1");
  1739. status += fx_directory_default_set(&ram_disk, "SUB1");
  1740. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1741. status += fx_media_flush(&ram_disk);
  1742. /* Check the status. */
  1743. if (status != FX_SUCCESS)
  1744. {
  1745. /* Error, return error code. */
  1746. printf("ERROR!\n");
  1747. test_control_return(141);
  1748. }
  1749. /* Build a large file name. */
  1750. for (i = 0; i < 255; i++)
  1751. {
  1752. name[i] = 'a';
  1753. }
  1754. name[255] = 0;
  1755. /* Create a large file name in the sub-directory with a FAT entry read error. */
  1756. _fx_utility_fat_entry_read_error_request = 10014;
  1757. status = fx_file_create(&ram_disk, name);
  1758. _fx_utility_fat_entry_read_error_request = 0;
  1759. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1760. status += fx_media_flush(&ram_disk);
  1761. /* Determine if have the expected error. */
  1762. if (status != FX_FILE_CORRUPT)
  1763. {
  1764. printf("ERROR!\n");
  1765. test_control_return(142);
  1766. }
  1767. /* Close the media. */
  1768. status = fx_media_close(&ram_disk);
  1769. /* Determine if the test was successful. */
  1770. if (status != FX_SUCCESS)
  1771. {
  1772. printf("ERROR!\n");
  1773. test_control_return(143);
  1774. }
  1775. /* Format the media. This needs to be done before opening it! */
  1776. status = fx_media_format(&ram_disk,
  1777. _fx_ram_driver, // Driver entry
  1778. ram_disk_memory, // RAM disk memory pointer
  1779. cache_buffer, // Media buffer pointer
  1780. CACHE_SIZE, // Media buffer size
  1781. "MY_RAM_DISK", // Volume Name
  1782. 1, // Number of FATs
  1783. 512, // Directory Entries
  1784. 0, // Hidden sectors
  1785. 14000, // Total sectors
  1786. 128, // Sector size
  1787. 1, // Sectors per cluster
  1788. 1, // Heads
  1789. 1); // Sectors per track
  1790. /* Determine if the format had an error. */
  1791. if (status)
  1792. {
  1793. printf("ERROR!\n");
  1794. test_control_return(144);
  1795. }
  1796. /* Open the ram_disk. */
  1797. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1798. /* Check the status. */
  1799. if (status != FX_SUCCESS)
  1800. {
  1801. /* Error, return error code. */
  1802. printf("ERROR!\n");
  1803. test_control_return(145);
  1804. }
  1805. /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
  1806. status = fx_directory_create(&ram_disk, "SUB1");
  1807. status += fx_directory_default_set(&ram_disk, "SUB1");
  1808. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1809. status += fx_media_flush(&ram_disk);
  1810. /* Check the status. */
  1811. if (status != FX_SUCCESS)
  1812. {
  1813. /* Error, return error code. */
  1814. printf("ERROR!\n");
  1815. test_control_return(146);
  1816. }
  1817. /* Build a large file name. */
  1818. for (i = 0; i < 255; i++)
  1819. {
  1820. name[i] = 'a';
  1821. }
  1822. name[255] = 0;
  1823. /* Create a large file name in the sub-directory with a FAT entry read error. */
  1824. _fx_utility_fat_entry_read_error_request = 20014;
  1825. status = fx_file_create(&ram_disk, name);
  1826. _fx_utility_fat_entry_read_error_request = 0;
  1827. /* Setup an I/O error on the first logical sectory write of the directory entry. */
  1828. status += fx_media_flush(&ram_disk);
  1829. /* Determine if have the expected error. */
  1830. if (status != FX_FILE_CORRUPT)
  1831. {
  1832. printf("ERROR!\n");
  1833. test_control_return(147);
  1834. }
  1835. /* Close the media. */
  1836. status = fx_media_close(&ram_disk);
  1837. /* Determine if the test was successful. */
  1838. if (status != FX_SUCCESS)
  1839. {
  1840. printf("ERROR!\n");
  1841. test_control_return(148);
  1842. }
  1843. /* Format the media. This needs to be done before opening it! */
  1844. status = fx_media_format(&ram_disk,
  1845. _fx_ram_driver, // Driver entry
  1846. ram_disk_memory, // RAM disk memory pointer
  1847. cache_buffer, // Media buffer pointer
  1848. CACHE_SIZE, // Media buffer size
  1849. "MY_RAM_DISK", // Volume Name
  1850. 1, // Number of FATs
  1851. 10000, // Directory Entries
  1852. 0, // Hidden sectors
  1853. 64000, // Total sectors
  1854. 128, // Sector size
  1855. 1, // Sectors per cluster
  1856. 1, // Heads
  1857. 1); // Sectors per track
  1858. /* Determine if the format had an error. */
  1859. if (status)
  1860. {
  1861. printf("ERROR!\n");
  1862. test_control_return(149);
  1863. }
  1864. /* Open the ram_disk. */
  1865. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  1866. /* Check the status. */
  1867. if (status != FX_SUCCESS)
  1868. {
  1869. /* Error, return error code. */
  1870. printf("ERROR!\n");
  1871. test_control_return(150);
  1872. }
  1873. /* Create a file name that execises the short name with a 0xE5 and a dot less than the eighth character. */
  1874. status = fx_file_create(&ram_disk, "a.a");
  1875. status += fx_media_flush(&ram_disk);
  1876. status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, buffer);
  1877. buffer[0x20] = 0x8f;
  1878. buffer[0x21] = 0xe5;
  1879. buffer[0x22] = '.';
  1880. buffer[0x23] = 'a';
  1881. buffer[0x24] = '~';
  1882. status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, buffer);
  1883. status += fx_media_flush(&ram_disk);
  1884. status += fx_directory_short_name_get(&ram_disk, "a.a", name);
  1885. status += fx_file_open(&ram_disk, &file_1, "a.a", FX_OPEN_FOR_WRITE);
  1886. status += fx_file_write(&file_1, "a", 1);
  1887. file_1.fx_file_dir_entry.fx_dir_entry_short_name[0] = (CHAR)0xE5;
  1888. status += fx_media_flush(&ram_disk);
  1889. status += fx_file_close(&file_1);
  1890. /* Check the status. */
  1891. if (status != FX_SUCCESS)
  1892. {
  1893. /* Error, return error code. */
  1894. printf("ERROR!\n");
  1895. test_control_return(151);
  1896. }
  1897. /* Create some files to test the logic in fx_directory_entry_read */
  1898. status = fx_file_create(&ram_disk, "a");
  1899. status += fx_directory_short_name_get(&ram_disk, "a", name);
  1900. status += fx_file_create(&ram_disk, "aa");
  1901. status += fx_directory_short_name_get(&ram_disk, "aa", name);
  1902. status += fx_file_create(&ram_disk, "aaa");
  1903. status += fx_directory_short_name_get(&ram_disk, "aaa", name);
  1904. status += fx_file_create(&ram_disk, "aaaa");
  1905. status += fx_directory_short_name_get(&ram_disk, "aaaa", name);
  1906. status += fx_file_create(&ram_disk, "aaaaa");
  1907. status += fx_directory_short_name_get(&ram_disk, "aaaaa", name);
  1908. status += fx_file_create(&ram_disk, "aaaaaa");
  1909. status += fx_directory_short_name_get(&ram_disk, "aaaaaa", name);
  1910. status += fx_file_create(&ram_disk, "aaaaaaa");
  1911. status += fx_directory_short_name_get(&ram_disk, "aaaaaaa", name);
  1912. status += fx_file_create(&ram_disk, "aaaaaaaa");
  1913. status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa", name);
  1914. status += fx_file_create(&ram_disk, "aaaaaaaa.a");
  1915. status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.a", name);
  1916. status += fx_file_create(&ram_disk, "aaaaaaaa.aa");
  1917. status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.aa", name);
  1918. status += fx_file_create(&ram_disk, "aaaaaaaa.aaa");
  1919. status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.aaa", name);
  1920. status += fx_file_create(&ram_disk, "a.");
  1921. status += fx_directory_short_name_get(&ram_disk, "a.", name);
  1922. status += fx_file_create(&ram_disk, "aa.");
  1923. status += fx_directory_short_name_get(&ram_disk, "aa.", name);
  1924. status += fx_file_create(&ram_disk, "aaa.");
  1925. status += fx_directory_short_name_get(&ram_disk, "aaa.", name);
  1926. status += fx_file_create(&ram_disk, "aaaa.");
  1927. status += fx_directory_short_name_get(&ram_disk, "aaaa.", name);
  1928. status += fx_file_create(&ram_disk, "aaaaa.");
  1929. status += fx_directory_short_name_get(&ram_disk, "aaaaa.", name);
  1930. status += fx_file_create(&ram_disk, "aaaaaa.");
  1931. status += fx_directory_short_name_get(&ram_disk, "aaaaaa.", name);
  1932. status += fx_file_create(&ram_disk, "aaaaaaa.");
  1933. status += fx_directory_short_name_get(&ram_disk, "aaaaaaa.", name);
  1934. status += fx_file_create(&ram_disk, "aaaaaaaa.");
  1935. status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.", name);
  1936. status += fx_file_delete(&ram_disk, "aaaaaa.");
  1937. status += fx_file_delete(&ram_disk, "aaaaaaa.");
  1938. status += fx_file_delete(&ram_disk, "aaaaaaaa.");
  1939. /* Create a name with an 0xe5 in the front. */
  1940. name[0] = (CHAR)0xE5;
  1941. name[1] = 'a';
  1942. name[2] = 'b';
  1943. name[3] = '.';
  1944. name[4] = 't';
  1945. name[5] = 'x';
  1946. name[6] = 't';
  1947. name[7] = 0;
  1948. status += fx_file_create(&ram_disk, name);
  1949. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  1950. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  1951. status += fx_file_write(&file_1, "1", 1);
  1952. status += fx_file_close(&file_1);
  1953. status += fx_file_create(&ram_disk, "abcdefgh.txt");
  1954. status += fx_directory_short_name_get(&ram_disk, "abcdefgh.txt", (CHAR *)buffer);
  1955. status += fx_file_open(&ram_disk, &file_1, "abcdefgh.txt", FX_OPEN_FOR_WRITE);
  1956. status += fx_file_write(&file_1, "1", 1);
  1957. status += fx_file_close(&file_1);
  1958. #if EXTENDED_NAME_MANGLE_TEST
  1959. name[0] = 'a';
  1960. name[1] = 'B';
  1961. name[2] = 'C';
  1962. name[3] = 'D';
  1963. name[4] = 'E';
  1964. name[5] = 'F';
  1965. name[6] = 'G';
  1966. name[7] = '0';
  1967. name[8] = '0';
  1968. name[9] = '0';
  1969. name[10] = '0';
  1970. name[11] = 0;
  1971. for (i = 0; i < 3; i++)
  1972. {
  1973. name[7] = '0' + i;
  1974. for (j = 0; j < 10; j++)
  1975. {
  1976. name[8] = '0' + j;
  1977. for (k = 0; k < 10; k++)
  1978. {
  1979. name[9] = '0' + k;
  1980. for (l = 0; l < 10; l++)
  1981. {
  1982. if (status)
  1983. break;
  1984. name[10] = '0' + l;
  1985. status += fx_file_create(&ram_disk, name);
  1986. if (status)
  1987. break;
  1988. status += fx_directory_short_name_get(&ram_disk, name, buffer);
  1989. if (status)
  1990. break;
  1991. }
  1992. }
  1993. }
  1994. }
  1995. #endif
  1996. /* Check the status. */
  1997. if (status != FX_SUCCESS)
  1998. {
  1999. /* Error, return error code. */
  2000. printf("ERROR!\n");
  2001. test_control_return(152);
  2002. }
  2003. /* Close the media. */
  2004. status = fx_media_close(&ram_disk);
  2005. /* Determine if the test was successful. */
  2006. if (status != FX_SUCCESS)
  2007. {
  2008. printf("ERROR!\n");
  2009. test_control_return(153);
  2010. }
  2011. /* Test corner cases on fx_directory_search. */
  2012. /* Format the media. This needs to be done before opening it! */
  2013. status = fx_media_format(&ram_disk,
  2014. _fx_ram_driver, // Driver entry
  2015. ram_disk_memory, // RAM disk memory pointer
  2016. cache_buffer, // Media buffer pointer
  2017. CACHE_SIZE, // Media buffer size
  2018. "MY_RAM_DISK", // Volume Name
  2019. 1, // Number of FATs
  2020. 256, // Directory Entries
  2021. 0, // Hidden sectors
  2022. 14000, // Total sectors
  2023. 128, // Sector size
  2024. 1, // Sectors per cluster
  2025. 1, // Heads
  2026. 1); // Sectors per track
  2027. /* Determine if the format had an error. */
  2028. if (status)
  2029. {
  2030. printf("ERROR!\n");
  2031. test_control_return(154);
  2032. }
  2033. /* Open the ram_disk. */
  2034. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  2035. /* Check the status. */
  2036. if (status != FX_SUCCESS)
  2037. {
  2038. /* Error, return error code. */
  2039. printf("ERROR!\n");
  2040. test_control_return(155);
  2041. }
  2042. /* Build a long directory structure. */
  2043. status = fx_directory_create(&ram_disk, "/sub-directory_depth_00001");
  2044. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002");
  2045. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003");
  2046. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004");
  2047. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005");
  2048. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006");
  2049. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007");
  2050. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008");
  2051. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009");
  2052. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010");
  2053. status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011");
  2054. status += fx_file_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt");
  2055. status += fx_file_open(&ram_disk, &file_1, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt", FX_OPEN_FOR_WRITE);
  2056. /* Now create an invalid path by using a file as a directory entry. */
  2057. status += fx_file_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt/baddir");
  2058. /* Determine if the test was successful. */
  2059. if (status != FX_INVALID_PATH)
  2060. {
  2061. printf("ERROR!\n");
  2062. test_control_return(156);
  2063. }
  2064. status = fx_file_create(&ram_disk, "/sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file2.txt");
  2065. status += fx_file_open(&ram_disk, &file_2, "/sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file2.txt", FX_OPEN_FOR_WRITE);
  2066. status += fx_directory_default_set(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011");
  2067. status += fx_directory_first_entry_find(&ram_disk, name);
  2068. status += fx_directory_next_entry_find(&ram_disk, name);
  2069. status += fx_directory_next_entry_find(&ram_disk, name);
  2070. status += fx_directory_next_entry_find(&ram_disk, name);
  2071. /* Close the media. */
  2072. status += fx_media_close(&ram_disk);
  2073. /* Determine if the test was successful. */
  2074. if (status != FX_SUCCESS)
  2075. {
  2076. printf("ERROR!\n");
  2077. test_control_return(157);
  2078. }
  2079. /* Format the media. This needs to be done before opening it! */
  2080. status = fx_media_format(&ram_disk,
  2081. _fx_ram_driver, // Driver entry
  2082. ram_disk_memory, // RAM disk memory pointer
  2083. cache_buffer, // Media buffer pointer
  2084. CACHE_SIZE, // Media buffer size
  2085. "MY_RAM_DISK", // Volume Name
  2086. 1, // Number of FATs
  2087. 256, // Directory Entries
  2088. 0, // Hidden sectors
  2089. 14000, // Total sectors
  2090. 128, // Sector size
  2091. 1, // Sectors per cluster
  2092. 1, // Heads
  2093. 1); // Sectors per track
  2094. /* Determine if the format had an error. */
  2095. if (status)
  2096. {
  2097. printf("ERROR!\n");
  2098. test_control_return(158);
  2099. }
  2100. /* Open the ram_disk. */
  2101. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  2102. /* Check the status. */
  2103. if (status != FX_SUCCESS)
  2104. {
  2105. /* Error, return error code. */
  2106. printf("ERROR!\n");
  2107. test_control_return(159);
  2108. }
  2109. /* Build a long sub-directory name... This name will be too long to cache in fx_directory_search. */
  2110. for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
  2111. {
  2112. name[i] = 'a';
  2113. }
  2114. name[0] = '/';
  2115. name[256] = 0;
  2116. status = fx_directory_create(&ram_disk, name);
  2117. name[256] = '/';
  2118. name[257] = 'f';
  2119. name[258] = 'i';
  2120. name[259] = 'l';
  2121. name[260] = 'e';
  2122. name[261] = 0;
  2123. status += fx_file_create(&ram_disk, name);
  2124. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2125. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2126. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2127. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2128. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2129. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2130. status += fx_file_close(&file_1);
  2131. status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
  2132. status += fx_file_close(&file_1);
  2133. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2134. status += fx_file_close(&file_1);
  2135. status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
  2136. status += fx_file_close(&file_1);
  2137. status += fx_file_delete(&ram_disk, name);
  2138. /* Build a perfect fit long sub-directory name and file name... This name will fit exactly into the fx_directory_search cache. */
  2139. for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
  2140. {
  2141. name[i] = 'a';
  2142. }
  2143. name[0] = '/';
  2144. name[250] = 0;
  2145. status += fx_directory_create(&ram_disk, name);
  2146. name[250] = '/';
  2147. name[251] = 'f';
  2148. name[252] = 'i';
  2149. name[253] = 'l';
  2150. name[254] = 'e';
  2151. name[255] = 0;
  2152. status = fx_file_create(&ram_disk, name);
  2153. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2154. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2155. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2156. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2157. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2158. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2159. status += fx_file_close(&file_1);
  2160. status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
  2161. status += fx_file_close(&file_1);
  2162. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2163. status += fx_file_close(&file_1);
  2164. status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
  2165. status += fx_file_close(&file_1);
  2166. status = fx_file_delete(&ram_disk, name);
  2167. /* Close the media. */
  2168. status = fx_media_close(&ram_disk);
  2169. /* Determine if the test was successful. */
  2170. if (status != FX_SUCCESS)
  2171. {
  2172. printf("ERROR!\n");
  2173. test_control_return(160);
  2174. }
  2175. /* Format the media. This needs to be done before opening it! */
  2176. status = fx_media_format(&ram_disk,
  2177. _fx_ram_driver, // Driver entry
  2178. ram_disk_memory, // RAM disk memory pointer
  2179. cache_buffer, // Media buffer pointer
  2180. CACHE_SIZE, // Media buffer size
  2181. "MY_RAM_DISK", // Volume Name
  2182. 1, // Number of FATs
  2183. 256, // Directory Entries
  2184. 0, // Hidden sectors
  2185. 14000, // Total sectors
  2186. 128, // Sector size
  2187. 1, // Sectors per cluster
  2188. 1, // Heads
  2189. 1); // Sectors per track
  2190. /* Determine if the format had an error. */
  2191. if (status)
  2192. {
  2193. printf("ERROR!\n");
  2194. test_control_return(161);
  2195. }
  2196. /* Open the ram_disk. */
  2197. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  2198. /* Check the status. */
  2199. if (status != FX_SUCCESS)
  2200. {
  2201. /* Error, return error code. */
  2202. printf("ERROR!\n");
  2203. test_control_return(162);
  2204. }
  2205. /* Build a perfect fit long sub-directory name and file name... This name will fit exactly into the fx_directory_search cache. */
  2206. for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
  2207. {
  2208. name[i] = 'a';
  2209. }
  2210. name[0] = '/';
  2211. name[255] = 0;
  2212. status += fx_directory_create(&ram_disk, name);
  2213. name[253] = 0;
  2214. status += fx_directory_create(&ram_disk, name);
  2215. name[253] = '/';
  2216. name[254] = 'a';
  2217. name[255] = 0;
  2218. status = fx_file_create(&ram_disk, name);
  2219. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2220. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2221. status += fx_file_close(&file_1);
  2222. /* Setup info for direct call to directory search. */
  2223. dir_entry.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
  2224. search_directory.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN * 2;
  2225. dir_entry.fx_dir_entry_short_name[0] = 0;
  2226. search_directory.fx_dir_entry_short_name[0] = 0;
  2227. /* Lets make the name bigger than the maximun name. */
  2228. name[255] = 'a';
  2229. name[256] = 'a';
  2230. name[257] = 'a';
  2231. name[258] = 'a';
  2232. name[259] = 0;
  2233. _fx_directory_search(&ram_disk, name, &dir_entry, &search_directory, &name_ptr);
  2234. /* Set the name back to the original size. */
  2235. name[255] = 0;
  2236. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2237. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2238. status += fx_file_close(&file_1);
  2239. /* Now make the name long again to test relative, no path. */
  2240. name[255] = 'a';
  2241. /* Now let's perform a maximum relative search. */
  2242. _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
  2243. /* Now lets set a path and test that out. */
  2244. name[253] = 0;
  2245. status += fx_directory_default_set(&ram_disk, name);
  2246. /* Now set the name back to the original size. */
  2247. name[253] = '/';
  2248. name[255] = 0;
  2249. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2250. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2251. status += fx_file_close(&file_1);
  2252. /* Now make the name long again to test relative, with path. */
  2253. name[255] = 'a';
  2254. /* Now let's perform a maximum relative search. */
  2255. _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
  2256. /* Now lets set a path, modify the found path and test that out. */
  2257. name[253] = 'a';
  2258. name[254] = 'a';
  2259. name[255] = 0;
  2260. status += fx_directory_default_set(&ram_disk, name);
  2261. /* Now set the name back to the original size. */
  2262. name[253] = '/';
  2263. name[255] = 0;
  2264. status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
  2265. status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
  2266. status += fx_file_close(&file_1);
  2267. /* Test the maximum size of the default path lookup. */
  2268. for (i = 0; i < 256; i++)
  2269. {
  2270. ram_disk.fx_media_last_found_name[i] = ram_disk.fx_media_default_path.fx_path_name_buffer[i];
  2271. }
  2272. ram_disk.fx_media_last_found_name[0] = '/';
  2273. name[255] = 'a';
  2274. name[256] = 0;
  2275. /* Now let's perform a maximum relative search. */
  2276. _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
  2277. /* Now let's setup a directory search with a NULL path, a maximum found file name, and alternate directory separators. */
  2278. ram_disk.fx_media_default_path.fx_path_name_buffer[0] = 0;
  2279. strcpy(&ram_disk.fx_media_last_found_name[0], "\\abc\\def\\ghi\\abc");
  2280. for (i = 0; i < 256; i++)
  2281. {
  2282. ram_disk.fx_media_last_found_file_name[i] = 'a';
  2283. ram_disk.fx_media_last_found_directory.fx_dir_entry_name[i] = 'a';
  2284. }
  2285. ram_disk.fx_media_last_found_file_name[255] = 0;
  2286. ram_disk.fx_media_last_found_directory.fx_dir_entry_name[255] = 0;
  2287. ram_disk.fx_media_last_found_directory_valid = FX_TRUE;
  2288. _fx_directory_search(&ram_disk, "abc\\def\\ghi\\abc", &dir_entry, &search_directory, &name_ptr);
  2289. /* Now let's setup a directory search with a NULL path, a medium sized found file name, and alternate directory separators. */
  2290. ram_disk.fx_media_default_path.fx_path_name_buffer[0] = 0;
  2291. strcpy(&ram_disk.fx_media_last_found_name[0], "\\abc\\def\\ghi\\abc");
  2292. for (i = 0; i < 256; i++)
  2293. {
  2294. ram_disk.fx_media_last_found_file_name[i] = 'a';
  2295. ram_disk.fx_media_last_found_directory.fx_dir_entry_name[i] = 'a';
  2296. }
  2297. ram_disk.fx_media_last_found_file_name[255] = 0;
  2298. ram_disk.fx_media_last_found_directory.fx_dir_entry_name[25] = 0;
  2299. ram_disk.fx_media_last_found_directory_valid = FX_TRUE;
  2300. _fx_directory_search(&ram_disk, "abc\\def\\ghi\\abc", &dir_entry, &search_directory, &name_ptr);
  2301. /* Close the media. */
  2302. status = fx_media_close(&ram_disk);
  2303. /* Determine if the test was successful. */
  2304. if (status != FX_SUCCESS)
  2305. {
  2306. printf("ERROR!\n");
  2307. test_control_return(163);
  2308. }
  2309. /* Format the media. This needs to be done before opening it! */
  2310. status = fx_media_format(&ram_disk,
  2311. _fx_ram_driver, // Driver entry
  2312. ram_disk_memory, // RAM disk memory pointer
  2313. cache_buffer, // Media buffer pointer
  2314. CACHE_SIZE, // Media buffer size
  2315. "MY_RAM_DISK", // Volume Name
  2316. 1, // Number of FATs
  2317. 256, // Directory Entries
  2318. 0, // Hidden sectors
  2319. 14000, // Total sectors
  2320. 128, // Sector size
  2321. 1, // Sectors per cluster
  2322. 1, // Heads
  2323. 1); // Sectors per track
  2324. /* Determine if the format had an error. */
  2325. if (status)
  2326. {
  2327. printf("ERROR!\n");
  2328. test_control_return(164);
  2329. }
  2330. /* Open the ram_disk. */
  2331. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  2332. /* Check the status. */
  2333. if (status != FX_SUCCESS)
  2334. {
  2335. /* Error, return error code. */
  2336. printf("ERROR!\n");
  2337. test_control_return(165);
  2338. }
  2339. /* Create a directory path. */
  2340. status = fx_directory_create(&ram_disk, "/abc");
  2341. status += fx_directory_create(&ram_disk, "/abc/def");
  2342. status += fx_directory_create(&ram_disk, "/abc/def/ghi");
  2343. status += fx_directory_create(&ram_disk, "/abc/def/ghi/jkl");
  2344. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file.txt");
  2345. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file2.txt");
  2346. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file3.txt");
  2347. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file4.txt");
  2348. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file5.txt");
  2349. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file6.txt");
  2350. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file7.txt");
  2351. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file8.txt");
  2352. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file9.txt");
  2353. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file10.txt");
  2354. status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file11.txt");
  2355. status += fx_directory_default_set(&ram_disk, "/abc");
  2356. status += fx_directory_first_entry_find(&ram_disk, name);
  2357. /* Now open the file to get it into the search cache. */
  2358. status += fx_file_open(&ram_disk, &file_1, "/abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
  2359. status += fx_file_close(&file_1);
  2360. status += fx_file_open(&ram_disk, &file_1, "/abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
  2361. status += fx_file_close(&file_1);
  2362. status += fx_file_open(&ram_disk, &file_1, "def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
  2363. status += fx_file_close(&file_1);
  2364. status += fx_directory_default_set(&ram_disk, "/");
  2365. status += fx_file_open(&ram_disk, &file_1, "abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
  2366. status += fx_file_close(&file_1);
  2367. status += fx_directory_next_entry_find(&ram_disk, name);
  2368. /* Now test for FAT read errors. */
  2369. _fx_utility_fat_entry_read_error_request = 1;
  2370. status += fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
  2371. _fx_utility_fat_entry_read_error_request = 0;
  2372. /* Check the status... should be an I/O error at this point. */
  2373. if (status != FX_IO_ERROR)
  2374. {
  2375. /* Error, return error code. */
  2376. printf("ERROR!\n");
  2377. test_control_return(166);
  2378. }
  2379. /* Now test a FAT entry value that is too small. */
  2380. _fx_utility_fat_entry_read_error_request = 10001;
  2381. status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
  2382. _fx_utility_fat_entry_read_error_request = 0;
  2383. /* Check the status... should be a FAT read error. */
  2384. if (status != FX_FAT_READ_ERROR)
  2385. {
  2386. /* Error, return error code. */
  2387. printf("ERROR!\n");
  2388. test_control_return(167);
  2389. }
  2390. /* Now test a FAT entry value that is too large. */
  2391. temp = ram_disk.fx_media_total_clusters;
  2392. _fx_utility_fat_entry_read_error_request = 40001;
  2393. status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
  2394. _fx_utility_fat_entry_read_error_request = 0;
  2395. ram_disk.fx_media_total_clusters = temp;
  2396. /* Check the status... should be a FAT read error. */
  2397. if (status != FX_FAT_READ_ERROR)
  2398. {
  2399. /* Error, return error code. */
  2400. printf("ERROR!\n");
  2401. test_control_return(168);
  2402. }
  2403. /* Now test a FAT entry value that is the same as the cluster itself. */
  2404. _fx_utility_fat_entry_read_error_request = 30001;
  2405. status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
  2406. _fx_utility_fat_entry_read_error_request = 0;
  2407. /* Check the status... should be a FAT read error. */
  2408. if (status != FX_FAT_READ_ERROR)
  2409. {
  2410. /* Error, return error code. */
  2411. printf("ERROR!\n");
  2412. test_control_return(169);
  2413. }
  2414. /* Now perform a good open. */
  2415. status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
  2416. status += fx_file_close(&file_2);
  2417. /* Check the status. */
  2418. if (status != FX_SUCCESS)
  2419. {
  2420. /* Error, return error code. */
  2421. printf("ERROR!\n");
  2422. test_control_return(166);
  2423. }
  2424. /* Setup info for direct call to directory search. */
  2425. dir_entry.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
  2426. search_directory.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN * 2;
  2427. dir_entry.fx_dir_entry_short_name[0] = 0;
  2428. search_directory.fx_dir_entry_short_name[0] = 0;
  2429. /* Lets perform a search that from the root directory. */
  2430. _fx_directory_search(&ram_disk, "/abc/..", &dir_entry, &search_directory, &name_ptr);
  2431. /* Now setup a maximum default path. */
  2432. for (i = 0; i < FX_MAX_LAST_NAME_LEN; i++)
  2433. {
  2434. name[i] = 'a';
  2435. }
  2436. name[255] = 0;
  2437. /* Create a sub-directory of maximum lenght. */
  2438. status = fx_directory_create(&ram_disk, name);
  2439. /* Set the default path to this name. */
  2440. status += fx_directory_default_set(&ram_disk, name);
  2441. /* Create a file in the sub-directory path. */
  2442. status += fx_file_create(&ram_disk, "file1.txt");
  2443. /* Open the file to test the directory search cache name build. */
  2444. status += fx_file_open(&ram_disk, &file_1, "file1.txt", FX_OPEN_FOR_WRITE);
  2445. /* Determine if the test was successful. */
  2446. if (status != FX_SUCCESS)
  2447. {
  2448. printf("ERROR!\n");
  2449. test_control_return(167);
  2450. }
  2451. /* Close the media. */
  2452. status = fx_media_close(&ram_disk);
  2453. if (status != FX_SUCCESS)
  2454. {
  2455. printf("ERROR!\n");
  2456. test_control_return(168);
  2457. }
  2458. /* Test for https://github.com/azure-rtos/filex/issues/26 */
  2459. /* Format the media. This needs to be done before opening it! */
  2460. status = fx_media_format(&ram_disk,
  2461. _fx_ram_driver, // Driver entry
  2462. ram_disk_memory, // RAM disk memory pointer
  2463. cache_buffer, // Media buffer pointer
  2464. CACHE_SIZE, // Media buffer size
  2465. "MY_RAM_DISK", // Volume Name
  2466. 1, // Number of FATs
  2467. 4, // Directory Entries
  2468. 0, // Hidden sectors
  2469. 128, // Total sectors
  2470. 128, // Sector size
  2471. 1, // Sectors per cluster
  2472. 1, // Heads
  2473. 1); // Sectors per track
  2474. return_if_fail( status == FX_SUCCESS);
  2475. /* Open the ram_disk. */
  2476. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
  2477. return_if_fail( status == FX_SUCCESS);
  2478. FX_FILE my_file;
  2479. ULONG available_clusters;
  2480. uint8_t buff[128];
  2481. int num_of_files = 0;
  2482. char dummy_file_path[DIR_PATH_SIZE + 3];
  2483. memcpy(dummy_file_path, DIR_PATH, DIR_PATH_SIZE);
  2484. /* Create a file called TEST.TXT.*/
  2485. status += fx_directory_create(&ram_disk, "/MYDIR");
  2486. status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1");
  2487. status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2");
  2488. status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3");
  2489. return_if_fail( status == FX_SUCCESS);
  2490. status = fx_file_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT");
  2491. return_if_fail( status == FX_SUCCESS);
  2492. available_clusters = ram_disk.fx_media_available_clusters;
  2493. /*
  2494. * Ensure there is no spare space in the cluster used for the directory
  2495. */
  2496. dummy_file_path[sizeof(DIR_PATH) - 1] = 'A';
  2497. dummy_file_path[sizeof(DIR_PATH)] = '\0';
  2498. for (num_of_files = 0; available_clusters == ram_disk.fx_media_available_clusters; num_of_files ++)
  2499. {
  2500. dummy_file_path[sizeof(DIR_PATH) - 1] ++;
  2501. status = fx_file_create(&ram_disk, dummy_file_path);
  2502. return_if_fail( status == FX_SUCCESS);
  2503. }
  2504. // remove the file that allocated new cluster
  2505. status = fx_file_delete(&ram_disk, dummy_file_path);
  2506. return_if_fail( status == FX_SUCCESS);
  2507. /* Open the test file. */
  2508. status = fx_file_open(&ram_disk, &my_file, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT", FX_OPEN_FOR_WRITE);
  2509. return_if_fail( status == FX_SUCCESS);
  2510. available_clusters = ram_disk.fx_media_available_clusters;
  2511. for (int i = 0; i < available_clusters - 1; i++)
  2512. {
  2513. /* Write a one cluster size to the test file. */
  2514. status = fx_file_write(&my_file, buff, sizeof(buff));
  2515. return_if_fail( status == FX_SUCCESS);
  2516. }
  2517. /* The dir entry should be created on new cluster */
  2518. status =fx_file_rename(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT", "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST_RENAME.TXT");
  2519. return_if_fail (status == FX_SUCCESS);
  2520. return_if_fail(ram_disk.fx_media_available_clusters == 0);
  2521. /* Close the media. */
  2522. status = fx_media_close(&ram_disk);
  2523. /* Determine if the test was successful. */
  2524. if (status != FX_SUCCESS)
  2525. {
  2526. printf("ERROR!\n");
  2527. test_control_return(169);
  2528. }
  2529. else
  2530. {
  2531. printf("SUCCESS!\n");
  2532. test_control_return(0);
  2533. }
  2534. }