filex_file_seek_test.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /* This FileX test concentrates on the file seek operation. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include <stdio.h>
  7. #include "fx_ram_driver_test.h"
  8. #define DEMO_STACK_SIZE 4096
  9. #define CACHE_SIZE 128*128
  10. /* Define the ThreadX and FileX object control blocks... */
  11. #ifndef FX_STANDALONE_ENABLE
  12. static TX_THREAD ftest_0;
  13. #endif
  14. static FX_MEDIA ram_disk;
  15. static FX_FILE my_file;
  16. /* Define the counters used in the test application... */
  17. #ifndef FX_STANDALONE_ENABLE
  18. static UCHAR *ram_disk_memory;
  19. static UCHAR *cache_buffer;
  20. #else
  21. static UCHAR cache_buffer[CACHE_SIZE];
  22. #endif
  23. static UCHAR buffer[128];
  24. /* Define thread prototypes. */
  25. void filex_file_seek_application_define(void *first_unused_memory);
  26. static void ftest_0_entry(ULONG thread_input);
  27. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  28. void test_control_return(UINT status);
  29. /* Define what the initial system looks like. */
  30. #ifdef CTEST
  31. void test_application_define(void *first_unused_memory)
  32. #else
  33. void filex_file_seek_application_define(void *first_unused_memory)
  34. #endif
  35. {
  36. #ifndef FX_STANDALONE_ENABLE
  37. UCHAR *pointer;
  38. /* Setup the working pointer. */
  39. pointer = (UCHAR *) first_unused_memory;
  40. /* Create the main thread. */
  41. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  42. pointer, DEMO_STACK_SIZE,
  43. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  44. pointer = pointer + DEMO_STACK_SIZE;
  45. /* Setup memory for the RAM disk and the sector cache. */
  46. cache_buffer = pointer;
  47. pointer = pointer + CACHE_SIZE;
  48. ram_disk_memory = pointer;
  49. #endif
  50. /* Initialize the FileX system. */
  51. fx_system_initialize();
  52. #ifdef FX_STANDALONE_ENABLE
  53. ftest_0_entry(0);
  54. #endif
  55. }
  56. /* Define the test threads. */
  57. static void ftest_0_entry(ULONG thread_input)
  58. {
  59. UINT status;
  60. ULONG actual;
  61. ULONG read_value;
  62. ULONG write_value;
  63. ULONG available_bytes;
  64. ULONG i;
  65. FX_PARAMETER_NOT_USED(thread_input);
  66. /* Print out some test information banners. */
  67. printf("FileX Test: File seek test.........................................");
  68. /* Format the media. This needs to be done before opening it! */
  69. status = fx_media_format(&ram_disk,
  70. _fx_ram_driver, // Driver entry
  71. ram_disk_memory, // RAM disk memory pointer
  72. cache_buffer, // Media buffer pointer
  73. CACHE_SIZE, // Media buffer size
  74. "MY_RAM_DISK", // Volume Name
  75. 1, // Number of FATs
  76. 32, // Directory Entries
  77. 0, // Hidden sectors
  78. 512, // Total sectors
  79. 128, // Sector size
  80. 1, // Sectors per cluster
  81. 1, // Heads
  82. 1); // Sectors per track
  83. /* Determine if the format had an error. */
  84. if (status)
  85. {
  86. printf("ERROR!\n");
  87. test_control_return(2);
  88. }
  89. /* Attempt to seek before the media is opened to generate an error */
  90. status = fx_file_extended_seek(&my_file, 0);
  91. if (status != FX_NOT_OPEN)
  92. {
  93. printf("ERROR!\n");
  94. test_control_return(2);
  95. }
  96. /* Attempt to seek before the media is opened to generate an error */
  97. status = fx_file_extended_relative_seek(&my_file, 0, 0);
  98. if (status != FX_NOT_OPEN)
  99. {
  100. printf("ERROR!\n");
  101. test_control_return(3);
  102. }
  103. /* Open the ram_disk. */
  104. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  105. /* Check the status. */
  106. if (status != FX_SUCCESS)
  107. {
  108. /* Error, return error code. */
  109. printf("ERROR!\n");
  110. test_control_return(4);
  111. }
  112. /* Create a file called TEST.TXT in the root directory. */
  113. status = fx_file_create(&ram_disk, "TEST.TXT");
  114. /* Check the create status. */
  115. if (status != FX_SUCCESS)
  116. {
  117. printf("ERROR!\n");
  118. test_control_return(5);
  119. }
  120. /* Open the test file. */
  121. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  122. /* Check the file open status. */
  123. if (status != FX_SUCCESS)
  124. {
  125. printf("ERROR!\n");
  126. test_control_return(6);
  127. }
  128. /* Attempt to seek before the media is opened to generate an error */
  129. status = fx_file_extended_relative_seek(&my_file, 0xFFFFFFFFFFFFFFFF, FX_SEEK_BACK);
  130. if (status != FX_SUCCESS)
  131. {
  132. printf("ERROR!\n");
  133. test_control_return(7);
  134. }
  135. /* test error checking */
  136. #ifndef FX_DISABLE_ERROR_CHECKING
  137. /* send null pointer to generate an error */
  138. status = fx_media_space_available(FX_NULL, FX_NULL);
  139. if (status != FX_PTR_ERROR)
  140. {
  141. printf("ERROR!\n");
  142. test_control_return(8);
  143. }
  144. /* send an invalid option to generate an error */
  145. status = fx_file_relative_seek(&my_file, 0xFFFFFFFF, 4);
  146. if (status != FX_INVALID_OPTION)
  147. {
  148. printf("ERROR!\n");
  149. test_control_return(9);
  150. }
  151. /* send null pointer to generate an error */
  152. status = fx_file_extended_seek(FX_NULL, 0xFF);
  153. if (status != FX_PTR_ERROR)
  154. {
  155. printf("ERROR!\n");
  156. test_control_return(10);
  157. }
  158. /* send null pointer to generate an error */
  159. status = fx_file_extended_relative_seek(FX_NULL, 0xFF, FX_SEEK_BEGIN);
  160. if (status != FX_PTR_ERROR)
  161. {
  162. printf("ERROR!\n");
  163. test_control_return(11);
  164. }
  165. /* send null pointer to generate an error */
  166. status = fx_file_extended_relative_seek(&my_file, 0xFF, 4);
  167. if (status != FX_INVALID_OPTION)
  168. {
  169. printf("ERROR!\n");
  170. test_control_return(12);
  171. }
  172. #endif /* FX_DISABLE_ERROR_CHECKING */
  173. /* Pickup the available bytes in the media. */
  174. status = fx_media_space_available(&ram_disk, &available_bytes);
  175. /* Check for available bytes error. */
  176. if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
  177. {
  178. printf("ERROR!\n");
  179. test_control_return(13);
  180. }
  181. /* Loop to write successive bytes out to the file.... to fill the media! */
  182. i = 0;
  183. write_value = 0;
  184. while (i < available_bytes)
  185. {
  186. /* Write 4 bytes to the file. */
  187. status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
  188. /* Check the file write status. */
  189. if (status != FX_SUCCESS)
  190. {
  191. printf("ERROR!\n");
  192. test_control_return(14);
  193. }
  194. /* Increment byte count. */
  195. i = i + sizeof(ULONG);
  196. /* Increment write value. */
  197. write_value++;
  198. }
  199. /* Pickup the available bytes in the media again. */
  200. status = fx_media_space_available(&ram_disk, &i);
  201. /* Check for available bytes error. */
  202. if ((status != FX_SUCCESS) || (i != 0))
  203. {
  204. printf("ERROR!\n");
  205. test_control_return(15);
  206. }
  207. #ifndef FX_DISABLE_CACHE
  208. /* At this point, we should invalidate the (which also flushes the cache) media to ensure that all
  209. dirty sectors are written. */
  210. status = fx_media_cache_invalidate(&ram_disk);
  211. /* Check for invalidate errors. */
  212. if ((status != FX_SUCCESS) || (ram_disk.fx_media_sector_cache_dirty_count))
  213. {
  214. printf("ERROR!\n");
  215. test_control_return(16);
  216. }
  217. /* See if any sectors are still valid in the cache. */
  218. for (i = 0; i < FX_MAX_SECTOR_CACHE; i++)
  219. {
  220. /* Determine if this cache entry is still valid. */
  221. if (ram_disk.fx_media_sector_cache[i].fx_cached_sector_valid)
  222. {
  223. printf("ERROR!\n");
  224. test_control_return(17);
  225. }
  226. }
  227. #endif
  228. /* Seek to the beginning of the test file. */
  229. status = fx_file_seek(&my_file, 0);
  230. /* Check the file seek status. */
  231. if (status != FX_SUCCESS)
  232. {
  233. printf("ERROR!\n");
  234. test_control_return(18);
  235. }
  236. /* Read the 4 bytes at the front of the file... should be 0! */
  237. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  238. /* Determine if it is correct. */
  239. if ((status) || (read_value != 0) || (actual != sizeof(ULONG)))
  240. {
  241. printf("ERROR!\n");
  242. test_control_return(19);
  243. }
  244. /* Read the next 4 bytes at the front of the file... should be 1! */
  245. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  246. /* Determine if it is correct. */
  247. if ((status) || (read_value != 1) || (actual != sizeof(ULONG)))
  248. {
  249. printf("ERROR!\n");
  250. test_control_return(20);
  251. }
  252. /* Seek to near the last 4 bytes of the file. */
  253. status = fx_file_seek(&my_file, available_bytes - 4);
  254. /* Read the last 4 bytes of the file... should be available_bytes/sizeof(ULONG)! */
  255. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  256. /* Determine if it is correct. */
  257. if ((status) || (read_value != (available_bytes/sizeof(ULONG) - 1)) || (actual != sizeof(ULONG)))
  258. {
  259. printf("ERROR!\n");
  260. test_control_return(21);
  261. }
  262. /* Read the past the end of the file... should get an error in this case. */
  263. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  264. /* Determine if it is correct. */
  265. if (status != FX_END_OF_FILE)
  266. {
  267. printf("ERROR!\n");
  268. test_control_return(22);
  269. }
  270. /* Seek to the middle of the file. */
  271. status = fx_file_seek(&my_file, available_bytes/2);
  272. /* Read the middle 4 bytes of the file... should be (available_bytes/2)/sizeof(ULONG)! */
  273. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  274. /* Determine if it is correct. */
  275. if ((status) || (read_value != (available_bytes/(2*sizeof(ULONG)))) || (actual != sizeof(ULONG)))
  276. {
  277. printf("ERROR!\n");
  278. test_control_return(23);
  279. }
  280. /* Seek to the end of the file. */
  281. status = fx_file_seek(&my_file, 0xFFFFFFFF);
  282. /* Determine if it is correct. */
  283. if (status != FX_SUCCESS)
  284. {
  285. printf("ERROR!\n");
  286. test_control_return(24);
  287. }
  288. /* Close the file. */
  289. status += fx_file_close(&my_file);
  290. /* Open the test file for fast reading. */
  291. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ_FAST);
  292. /* Check the file open status. */
  293. if (status != FX_SUCCESS)
  294. {
  295. printf("ERROR!\n");
  296. test_control_return(25);
  297. }
  298. /* Read the 4 bytes at the front of the file... should be 0! */
  299. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  300. /* Determine if it is correct. */
  301. if ((status) || (read_value != 0) || (actual != sizeof(ULONG)))
  302. {
  303. printf("ERROR!\n");
  304. test_control_return(26);
  305. }
  306. /* Read the next 4 bytes at the front of the file... should be 1! */
  307. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  308. /* Determine if it is correct. */
  309. if ((status) || (read_value != 1) || (actual != sizeof(ULONG)))
  310. {
  311. printf("ERROR!\n");
  312. test_control_return(27);
  313. }
  314. /* Seek to near the last 4 bytes of the file. */
  315. status = fx_file_seek(&my_file, available_bytes - 4);
  316. /* Read the last 4 bytes of the file... should be available_bytes/sizeof(ULONG)! */
  317. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  318. /* Determine if it is correct. */
  319. if ((status) || (read_value != (available_bytes/sizeof(ULONG) - 1)) || (actual != sizeof(ULONG)))
  320. {
  321. printf("ERROR!\n");
  322. test_control_return(28);
  323. }
  324. /* Read the past the end of the file... should get an error in this case. */
  325. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  326. /* Determine if it is correct. */
  327. if (status != FX_END_OF_FILE)
  328. {
  329. printf("ERROR!\n");
  330. test_control_return(29);
  331. }
  332. /* Seek to the middle of the file. */
  333. status = fx_file_seek(&my_file, available_bytes/2);
  334. /* Read the middle 4 bytes of the file... should be (available_bytes/2)/sizeof(ULONG)! */
  335. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  336. /* Determine if it is correct. */
  337. if ((status) || (read_value != (available_bytes/(2*sizeof(ULONG)))) || (actual != sizeof(ULONG)))
  338. {
  339. printf("ERROR!\n");
  340. test_control_return(30);
  341. }
  342. /* Seek to the end of the file. */
  343. status = fx_file_seek(&my_file, 0xFFFFFFFF);
  344. /* Determine if it is correct. */
  345. if (status != FX_SUCCESS)
  346. {
  347. printf("ERROR!\n");
  348. test_control_return(31);
  349. }
  350. /* Close the file. */
  351. status += fx_file_close(&my_file);
  352. /* Open the test file for reading. */
  353. status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
  354. /* Check the file open status. */
  355. if (status != FX_SUCCESS)
  356. {
  357. printf("ERROR!\n");
  358. test_control_return(32);
  359. }
  360. /* Only run this if error checking is enabled */
  361. #ifndef FX_DISABLE_ERROR_CHECKING
  362. /* send null pointer to generate an error */
  363. status = fx_file_relative_seek(FX_NULL, 0, FX_SEEK_BEGIN);
  364. if (status != FX_PTR_ERROR)
  365. {
  366. printf("ERROR!\n");
  367. test_control_return(33);
  368. }
  369. #endif /* FX_DISABLE_ERROR_CHECKING */
  370. /* Read the 4 bytes at the front of the file... should be 0! */
  371. status = fx_file_relative_seek(&my_file, 0, FX_SEEK_BEGIN);
  372. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  373. /* Determine if it is correct. */
  374. if ((status) || (read_value != 0) || (actual != sizeof(ULONG)))
  375. {
  376. printf("ERROR!\n");
  377. test_control_return(34);
  378. }
  379. /* Read the next 4 bytes at the front of the file... should be 1! */
  380. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  381. /* Determine if it is correct. */
  382. if ((status) || (read_value != 1) || (actual != sizeof(ULONG)))
  383. {
  384. printf("ERROR!\n");
  385. test_control_return(35);
  386. }
  387. /* Seek to near the last 4 bytes of the file. */
  388. status = fx_file_relative_seek(&my_file, 0xFFFFFFFF, FX_SEEK_BEGIN);
  389. status += fx_file_relative_seek(&my_file, 4, FX_SEEK_BACK);
  390. /* Read the last 4 bytes of the file... should be available_bytes/sizeof(ULONG)! */
  391. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  392. /* Determine if it is correct. */
  393. if ((status) || (read_value != (available_bytes/sizeof(ULONG) - 1)) || (actual != sizeof(ULONG)))
  394. {
  395. printf("ERROR!\n");
  396. test_control_return(36);
  397. }
  398. /* Read the past the end of the file... should get an error in this case. */
  399. status = fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  400. /* Determine if it is correct. */
  401. if (status != FX_END_OF_FILE)
  402. {
  403. printf("ERROR!\n");
  404. test_control_return(37);
  405. }
  406. /* Seek to the middle of the file. */
  407. status = fx_file_relative_seek(&my_file, 0xFFFFFFFF, FX_SEEK_END);
  408. status += fx_file_relative_seek(&my_file, available_bytes/2, FX_SEEK_FORWARD);
  409. /* Read the middle 4 bytes of the file... should be (available_bytes/2)/sizeof(ULONG)! */
  410. status += fx_file_read(&my_file, (void *) &read_value, sizeof(ULONG), &actual);
  411. /* Determine if it is correct. */
  412. if ((status) || (read_value != (available_bytes/(2*sizeof(ULONG)))) || (actual != sizeof(ULONG)))
  413. {
  414. printf("ERROR!\n");
  415. test_control_return(38);
  416. }
  417. /* Seek to the end of the file. */
  418. status = fx_file_relative_seek(&my_file, 0, FX_SEEK_END);
  419. /* Determine if it is correct. */
  420. if (status != FX_SUCCESS)
  421. {
  422. printf("ERROR!\n");
  423. test_control_return(39);
  424. }
  425. /* Close the file. */
  426. status += fx_file_close(&my_file);
  427. /* Close the media. */
  428. status += fx_media_close(&ram_disk);
  429. /* Determine if the test was successful. */
  430. if (status != FX_SUCCESS)
  431. {
  432. printf("ERROR!\n");
  433. test_control_return(40);
  434. }
  435. /* Test corner cases of extended seek. */
  436. /* Format the media. This needs to be done before opening it! */
  437. status = fx_media_format(&ram_disk,
  438. _fx_ram_driver, // Driver entry
  439. ram_disk_memory, // RAM disk memory pointer
  440. cache_buffer, // Media buffer pointer
  441. CACHE_SIZE, // Media buffer size
  442. "MY_RAM_DISK", // Volume Name
  443. 1, // Number of FATs
  444. 32, // Directory Entries
  445. 0, // Hidden sectors
  446. 512, // Total sectors
  447. 128, // Sector size
  448. 1, // Sectors per cluster
  449. 1, // Heads
  450. 1); // Sectors per track
  451. /* Determine if the format had an error. */
  452. if (status)
  453. {
  454. printf("ERROR!\n");
  455. test_control_return(41);
  456. }
  457. /* Open the ram_disk. */
  458. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  459. /* Check the status. */
  460. if (status != FX_SUCCESS)
  461. {
  462. /* Error, return error code. */
  463. printf("ERROR!\n");
  464. test_control_return(42);
  465. }
  466. /* Create a file called TEST.TXT in the root directory. */
  467. status = fx_file_create(&ram_disk, "TEST.TXT");
  468. /* Check the create status. */
  469. if (status != FX_SUCCESS)
  470. {
  471. printf("ERROR!\n");
  472. test_control_return(43);
  473. }
  474. /* Open the test file. */
  475. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  476. /* Check the file open status. */
  477. if (status != FX_SUCCESS)
  478. {
  479. printf("ERROR!\n");
  480. test_control_return(44);
  481. }
  482. /* Write data to the file. */
  483. status = fx_file_write(&my_file, buffer, 128);
  484. status += fx_file_write(&my_file, buffer, 128);
  485. status += fx_file_write(&my_file, buffer, 128);
  486. status += fx_file_write(&my_file, buffer, 128);
  487. status += fx_file_write(&my_file, buffer, 128);
  488. status += fx_file_write(&my_file, buffer, 128);
  489. status += fx_file_write(&my_file, buffer, 128);
  490. status += fx_file_write(&my_file, buffer, 128);
  491. /* Check the status. */
  492. if (status != FX_SUCCESS)
  493. {
  494. printf("ERROR!\n");
  495. test_control_return(45);
  496. }
  497. /* Seek to the beginning of the file. */
  498. status = fx_file_extended_seek(&my_file, 0);
  499. if (status != FX_SUCCESS)
  500. {
  501. printf("ERROR!\n");
  502. test_control_return(46);
  503. }
  504. /* Seek to the second to beginning of the last cluster of the file. */
  505. status = fx_file_extended_seek(&my_file, 1024-128);
  506. if (status != FX_SUCCESS)
  507. {
  508. printf("ERROR!\n");
  509. test_control_return(47);
  510. }
  511. /* Seek to the end of the file with an I/O error. */
  512. _fx_utility_fat_entry_read_error_request = 1;
  513. status = fx_file_extended_seek(&my_file, 1024);
  514. _fx_utility_fat_entry_read_error_request = 0;
  515. if (status != FX_IO_ERROR)
  516. {
  517. printf("ERROR!\n");
  518. test_control_return(48);
  519. }
  520. /* Seek to the end of the file with a FAT entry of 1 error. */
  521. status = fx_file_extended_seek(&my_file, 0);
  522. _fx_utility_fat_entry_read_error_request = 10001;
  523. status += fx_file_extended_seek(&my_file, 1024);
  524. _fx_utility_fat_entry_read_error_request = 0;
  525. if (status != FX_FILE_CORRUPT)
  526. {
  527. printf("ERROR!\n");
  528. test_control_return(49);
  529. }
  530. /* Seek to the end of the file with a FAT entry of max fat value error. */
  531. _fx_utility_fat_entry_read_error_request = 20001;
  532. status = fx_file_extended_seek(&my_file, 1024);
  533. _fx_utility_fat_entry_read_error_request = 0;
  534. if (status != FX_FILE_CORRUPT)
  535. {
  536. printf("ERROR!\n");
  537. test_control_return(50);
  538. }
  539. /* Seek to the end of the file with a FAT entry of minimal value error. */
  540. _fx_utility_fat_entry_read_error_request = 10008;
  541. status = fx_file_extended_seek(&my_file, 1024);
  542. _fx_utility_fat_entry_read_error_request = 0;
  543. if (status != FX_SUCCESS)
  544. {
  545. printf("ERROR!\n");
  546. test_control_return(51);
  547. }
  548. /* Close the file and the media. */
  549. status = fx_file_close(&my_file);
  550. status += fx_media_close(&ram_disk);
  551. if (status != FX_SUCCESS)
  552. {
  553. printf("ERROR!\n");
  554. test_control_return(52);
  555. }
  556. /* Test zero divisor checking in fx_file_extended_seek. */
  557. /* Format the media. This needs to be done before opening it! */
  558. status = fx_media_format(&ram_disk,
  559. _fx_ram_driver, // Driver entry
  560. ram_disk_memory, // RAM disk memory pointer
  561. cache_buffer, // Media buffer pointer
  562. CACHE_SIZE, // Media buffer size
  563. "MY_RAM_DISK", // Volume Name
  564. 1, // Number of FATs
  565. 32, // Directory Entries
  566. 0, // Hidden sectors
  567. 512, // Total sectors
  568. 128, // Sector size
  569. 1, // Sectors per cluster
  570. 1, // Heads
  571. 1); // Sectors per track
  572. /* Determine if the format had an error. */
  573. if (status)
  574. {
  575. printf("ERROR!\n");
  576. test_control_return(53);
  577. }
  578. /* Open the ram_disk. */
  579. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  580. /* Check the status. */
  581. if (status != FX_SUCCESS)
  582. {
  583. /* Error, return error code. */
  584. printf("ERROR!\n");
  585. test_control_return(54);
  586. }
  587. /* Create a file called TEST.TXT in the root directory. */
  588. status = fx_file_create(&ram_disk, "TEST.TXT");
  589. /* Check the create status. */
  590. if (status != FX_SUCCESS)
  591. {
  592. printf("ERROR!\n");
  593. test_control_return(55);
  594. }
  595. /* Open the test file. */
  596. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  597. /* Check the file open status. */
  598. if (status != FX_SUCCESS)
  599. {
  600. printf("ERROR!\n");
  601. test_control_return(56);
  602. }
  603. /* Check the status. */
  604. if (status != FX_SUCCESS)
  605. {
  606. printf("ERROR!\n");
  607. test_control_return(57);
  608. }
  609. /* Corrupt the media. */
  610. ram_disk.fx_media_bytes_per_sector = 0;
  611. status = fx_file_extended_seek(&my_file, 1);
  612. if (status != FX_MEDIA_INVALID)
  613. {
  614. printf("ERROR!\n");
  615. test_control_return(58);
  616. }
  617. ram_disk.fx_media_bytes_per_sector = 128;
  618. /* Write data to the file. */
  619. status = fx_file_write(&my_file, buffer, 128);
  620. /* Corrupt the media. */
  621. ram_disk.fx_media_sectors_per_FAT = 0;
  622. status = fx_file_write(&my_file, buffer, 128);
  623. if (status != FX_SUCCESS)
  624. {
  625. printf("ERROR!\n");
  626. test_control_return(59);
  627. }
  628. /* Close the file and the media. */
  629. status = fx_file_close(&my_file);
  630. /* Check the file open status. */
  631. if (status != FX_SUCCESS)
  632. {
  633. printf("ERROR!\n");
  634. test_control_return(60);
  635. }
  636. /* Corrupt the media. */
  637. ram_disk.fx_media_bytes_per_sector = 0;
  638. /* Open the test file. */
  639. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  640. /* Check the file open status. */
  641. if (status != FX_MEDIA_INVALID)
  642. {
  643. printf("ERROR!\n");
  644. test_control_return(56);
  645. }
  646. ram_disk.fx_media_bytes_per_sector = 128;
  647. status = fx_media_close(&ram_disk);
  648. if (status != FX_SUCCESS)
  649. {
  650. printf("ERROR!\n");
  651. test_control_return(60);
  652. }
  653. else
  654. {
  655. printf("SUCCESS!\n");
  656. test_control_return(0);
  657. }
  658. }