filex_media_format_open_close_test.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /* This FileX test concentrates on the basic media format, open, close 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 16*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. /* Define thread prototypes. */
  24. void filex_media_format_open_close_application_define(void *first_unused_memory);
  25. static void ftest_0_entry(ULONG thread_input);
  26. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  27. void test_control_return(UINT status);
  28. /* Define what the initial system looks like. */
  29. #ifdef CTEST
  30. void test_application_define(void *first_unused_memory)
  31. #else
  32. void filex_media_format_open_close_application_define(void *first_unused_memory)
  33. #endif
  34. {
  35. #ifndef FX_STANDALONE_ENABLE
  36. UCHAR *pointer;
  37. /* Setup the working pointer. */
  38. pointer = (UCHAR *) first_unused_memory;
  39. /* Create the main thread. */
  40. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  41. pointer, DEMO_STACK_SIZE,
  42. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  43. pointer = pointer + DEMO_STACK_SIZE;
  44. /* Setup memory for the RAM disk and the sector cache. */
  45. cache_buffer = pointer;
  46. pointer = pointer + CACHE_SIZE;
  47. ram_disk_memory = pointer;
  48. #endif
  49. /* Initialize the FileX system. */
  50. fx_system_initialize();
  51. #ifdef FX_STANDALONE_ENABLE
  52. ftest_0_entry(0);
  53. #endif
  54. }
  55. /* Define the test threads. */
  56. static void ftest_0_entry(ULONG thread_input)
  57. {
  58. UINT status;
  59. ULONG actual;
  60. UCHAR local_buffer[32];
  61. FX_PARAMETER_NOT_USED(thread_input);
  62. /* Print out some test information banners. */
  63. actual = FX_MAX_LONG_NAME_LEN;
  64. if (actual < 256)
  65. printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LONG_NAME_LEN=256\n");
  66. actual = FX_MAX_LAST_NAME_LEN;
  67. if (actual < 256)
  68. printf("**** ERROR ***** FileX and tests must be built with FX_MAX_LAST_NAME_LEN=256\n");
  69. /* Print out some test information banners. */
  70. printf("FileX Test: Media format, open, and close test.....................");
  71. /* Format the media with invalid parameters. */
  72. status = fx_media_format(&ram_disk,
  73. _fx_ram_driver, // Driver entry
  74. ram_disk_memory, // RAM disk memory pointer
  75. cache_buffer, // Media buffer pointer
  76. CACHE_SIZE, // Media buffer size
  77. "MY_RAM_DISK", // Volume Name
  78. 1, // Number of FATs
  79. 32, // Directory Entries
  80. 0, // Hidden sectors
  81. 256, // Total sectors
  82. 4097, // Sector size
  83. 1, // Sectors per cluster
  84. 1, // Heads
  85. 1); // Sectors per track
  86. /* Check status. */
  87. if (status != FX_SECTOR_INVALID)
  88. {
  89. printf("ERROR!\n");
  90. test_control_return(2);
  91. }
  92. /* Format the media with invalid parameters. */
  93. status = fx_media_format(&ram_disk,
  94. _fx_ram_driver, // Driver entry
  95. ram_disk_memory, // RAM disk memory pointer
  96. cache_buffer, // Media buffer pointer
  97. CACHE_SIZE, // Media buffer size
  98. "MY_RAM_DISK", // Volume Name
  99. 1, // Number of FATs
  100. 32, // Directory Entries
  101. 0, // Hidden sectors
  102. 256, // Total sectors
  103. 0, // Sector size
  104. 1, // Sectors per cluster
  105. 1, // Heads
  106. 1); // Sectors per track
  107. /* Check status. */
  108. if (status != FX_SECTOR_INVALID)
  109. {
  110. printf("ERROR!\n");
  111. test_control_return(2);
  112. }
  113. /* Format the media with invalid parameters. */
  114. status = fx_media_format(&ram_disk,
  115. _fx_ram_driver, // Driver entry
  116. ram_disk_memory, // RAM disk memory pointer
  117. cache_buffer, // Media buffer pointer
  118. CACHE_SIZE, // Media buffer size
  119. "MY_RAM_DISK", // Volume Name
  120. 1, // Number of FATs
  121. 32, // Directory Entries
  122. 0, // Hidden sectors
  123. 256, // Total sectors
  124. 128, // Sector size
  125. 129, // Sectors per cluster
  126. 1, // Heads
  127. 1); // Sectors per track
  128. /* Check status. */
  129. if (status != FX_SECTOR_INVALID)
  130. {
  131. printf("ERROR!\n");
  132. test_control_return(2);
  133. }
  134. /* Format the media with invalid parameters. */
  135. status = fx_media_format(&ram_disk,
  136. _fx_ram_driver, // Driver entry
  137. ram_disk_memory, // RAM disk memory pointer
  138. cache_buffer, // Media buffer pointer
  139. CACHE_SIZE, // Media buffer size
  140. "MY_RAM_DISK", // Volume Name
  141. 1, // Number of FATs
  142. 32, // Directory Entries
  143. 0, // Hidden sectors
  144. 256, // Total sectors
  145. 128, // Sector size
  146. 0, // Sectors per cluster
  147. 1, // Heads
  148. 1); // Sectors per track
  149. /* Check status. */
  150. if (status != FX_SECTOR_INVALID)
  151. {
  152. printf("ERROR!\n");
  153. test_control_return(2);
  154. }
  155. /* Format the media. This needs to be done before opening it! */
  156. status = fx_media_format(&ram_disk,
  157. _fx_ram_driver, // Driver entry
  158. ram_disk_memory, // RAM disk memory pointer
  159. cache_buffer, // Media buffer pointer
  160. CACHE_SIZE, // Media buffer size
  161. "MY_RAM_DISK", // Volume Name
  162. 1, // Number of FATs
  163. 32, // Directory Entries
  164. 0, // Hidden sectors
  165. 256, // Total sectors
  166. 128, // Sector size
  167. 1, // Sectors per cluster
  168. 1, // Heads
  169. 1); // Sectors per track
  170. /* Determine if the format had an error. */
  171. if (status)
  172. {
  173. printf("ERROR!\n");
  174. test_control_return(2);
  175. }
  176. /* Try to close the media before it has been opened */
  177. status = fx_media_close(&ram_disk);
  178. if (status != FX_MEDIA_NOT_OPEN)
  179. {
  180. printf("ERROR!\n");
  181. test_control_return(11);
  182. }
  183. /* Open the ram_disk. */
  184. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  185. /* Check the status. */
  186. if (status != FX_SUCCESS)
  187. {
  188. /* Error, return error code. */
  189. printf("ERROR!\n");
  190. test_control_return(3);
  191. }
  192. /* Create a file called TEST.TXT in the root directory. */
  193. status = fx_file_create(&ram_disk, "TEST.TXT");
  194. /* Check the create status. */
  195. if (status != FX_SUCCESS)
  196. {
  197. /* Check for an already created status. This is not fatal, just
  198. let the user know. */
  199. if (status != FX_ALREADY_CREATED)
  200. {
  201. printf("ERROR!\n");
  202. test_control_return(3);
  203. }
  204. }
  205. /* Open the test file. */
  206. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  207. /* Check the file open status. */
  208. if (status != FX_SUCCESS)
  209. {
  210. printf("ERROR!\n");
  211. test_control_return(4);
  212. }
  213. /* test error checking */
  214. #ifndef FX_DISABLE_ERROR_CHECKING
  215. /* send a null pointer to generate an error */
  216. status = fx_media_close(FX_NULL);
  217. if (status != FX_PTR_ERROR)
  218. {
  219. printf("ERROR!\n");
  220. test_control_return(8);
  221. }
  222. /* send null pointer to generate an error */
  223. status = fx_media_open(FX_NULL, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  224. if (status != FX_PTR_ERROR)
  225. {
  226. printf("ERROR!\n");
  227. test_control_return(11);
  228. }
  229. /* try to open an already open media to generate an error */
  230. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  231. if (status != FX_PTR_ERROR)
  232. {
  233. printf("ERROR!\n");
  234. test_control_return(11);
  235. }
  236. #endif /* FX_DISABLE_ERROR_CHECKING */
  237. /* Seek to the beginning of the test file. */
  238. status = fx_file_seek(&my_file, 0);
  239. /* Check the file seek status. */
  240. if (status != FX_SUCCESS)
  241. {
  242. printf("ERROR!\n");
  243. test_control_return(5);
  244. }
  245. /* Write a string to the test file. */
  246. status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
  247. /* Check the file write status. */
  248. if (status != FX_SUCCESS)
  249. {
  250. printf("ERROR!\n");
  251. test_control_return(6);
  252. }
  253. /* Seek to the beginning of the test file. */
  254. status = fx_file_seek(&my_file, 0);
  255. /* Check the file seek status. */
  256. if (status != FX_SUCCESS)
  257. {
  258. printf("ERROR!\n");
  259. test_control_return(7);
  260. }
  261. /* Read the first 28 bytes of the test file. */
  262. status = fx_file_read(&my_file, local_buffer, 28, &actual);
  263. /* Check the file read status. */
  264. if ((status != FX_SUCCESS) || (actual != 28))
  265. {
  266. printf("ERROR!\n");
  267. test_control_return(8);
  268. }
  269. /* Close the test file. */
  270. status = fx_file_close(&my_file);
  271. /* Check the file close status. */
  272. if (status != FX_SUCCESS)
  273. {
  274. printf("ERROR!\n");
  275. test_control_return(9);
  276. }
  277. /* Close the media. */
  278. status = fx_media_close(&ram_disk);
  279. /* Re-Open the ram_disk. */
  280. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  281. /* Check the status. */
  282. if (status != FX_SUCCESS)
  283. {
  284. /* Error, return error code. */
  285. printf("ERROR!\n");
  286. test_control_return(3);
  287. }
  288. /* Create a file called TEST.TXT in the root directory. */
  289. status = fx_file_create(&ram_disk, "TEST.TXT");
  290. /* Check for an already created status. This is not fatal, just
  291. let the user know. */
  292. if (status != FX_ALREADY_CREATED)
  293. {
  294. printf("ERROR!\n");
  295. test_control_return(3);
  296. }
  297. /* Open the test file. */
  298. status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
  299. /* Check the file open status. */
  300. if (status != FX_SUCCESS)
  301. {
  302. printf("ERROR!\n");
  303. test_control_return(4);
  304. }
  305. /* Seek to the beginning of the test file. */
  306. status = fx_file_seek(&my_file, 0);
  307. /* Check the file seek status. */
  308. if (status != FX_SUCCESS)
  309. {
  310. printf("ERROR!\n");
  311. test_control_return(5);
  312. }
  313. /* Write a string to the test file. */
  314. status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
  315. /* Check the file write status. */
  316. if (status != FX_SUCCESS)
  317. {
  318. printf("ERROR!\n");
  319. test_control_return(6);
  320. }
  321. /* Seek to the beginning of the test file. */
  322. status = fx_file_seek(&my_file, 0);
  323. /* Check the file seek status. */
  324. if (status != FX_SUCCESS)
  325. {
  326. printf("ERROR!\n");
  327. test_control_return(7);
  328. }
  329. /* Read the first 28 bytes of the test file. */
  330. status = fx_file_read(&my_file, local_buffer, 28, &actual);
  331. /* Check the file read status. */
  332. if ((status != FX_SUCCESS) || (actual != 28))
  333. {
  334. printf("ERROR!\n");
  335. test_control_return(8);
  336. }
  337. /* Close the test file. */
  338. status = fx_file_close(&my_file);
  339. /* Check the file close status. */
  340. if (status != FX_SUCCESS)
  341. {
  342. printf("ERROR!\n");
  343. test_control_return(9);
  344. }
  345. /* Close the media. */
  346. status = fx_media_close(&ram_disk);
  347. /* Determine if the test was successful. */
  348. if (status != FX_SUCCESS)
  349. {
  350. printf("ERROR!\n");
  351. test_control_return(10);
  352. }
  353. /* Format the media. This needs to be done before opening it! */
  354. status = fx_media_format(&ram_disk,
  355. _fx_ram_driver, // Driver entry
  356. ram_disk_memory, // RAM disk memory pointer
  357. cache_buffer, // Media buffer pointer
  358. CACHE_SIZE, // Media buffer size
  359. "MY_RAM_DISK", // Volume Name
  360. 1, // Number of FATs
  361. 32, // Directory Entries
  362. 0, // Hidden sectors
  363. 256, // Total sectors
  364. 128, // Sector size
  365. 1, // Sectors per cluster
  366. 1, // Heads
  367. 1); // Sectors per track
  368. /* Determine if the format had an error. */
  369. if (status)
  370. {
  371. printf("ERROR!\n");
  372. test_control_return(11);
  373. }
  374. /* Corrupt the bytes per sector field. */
  375. _fx_utility_16_unsigned_write(&ram_disk_memory[FX_BYTES_SECTOR], 0);
  376. /* Open the ram_disk. */
  377. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  378. /* Check the status. */
  379. if (status != FX_MEDIA_INVALID)
  380. {
  381. /* Error, return error code. */
  382. printf("ERROR!\n");
  383. test_control_return(12);
  384. }
  385. /* Format the media. This needs to be done before opening it! */
  386. status = fx_media_format(&ram_disk,
  387. _fx_ram_driver, // Driver entry
  388. ram_disk_memory, // RAM disk memory pointer
  389. cache_buffer, // Media buffer pointer
  390. CACHE_SIZE, // Media buffer size
  391. "MY_RAM_DISK", // Volume Name
  392. 1, // Number of FATs
  393. 32, // Directory Entries
  394. 0, // Hidden sectors
  395. 256, // Total sectors
  396. 128, // Sector size
  397. 1, // Sectors per cluster
  398. 1, // Heads
  399. 1); // Sectors per track
  400. /* Determine if the format had an error. */
  401. if (status)
  402. {
  403. printf("ERROR!\n");
  404. test_control_return(13);
  405. }
  406. /* Corrupt the total sectors field. */
  407. _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS], 0);
  408. _fx_utility_32_unsigned_write(&ram_disk_memory[FX_HUGE_SECTORS], 0);
  409. /* Open the ram_disk. */
  410. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  411. /* Check the status. */
  412. if (status != FX_MEDIA_INVALID)
  413. {
  414. /* Error, return error code. */
  415. printf("ERROR!\n");
  416. test_control_return(14);
  417. }
  418. /* Format the media. This needs to be done before opening it! */
  419. status = fx_media_format(&ram_disk,
  420. _fx_ram_driver, // Driver entry
  421. ram_disk_memory, // RAM disk memory pointer
  422. cache_buffer, // Media buffer pointer
  423. CACHE_SIZE, // Media buffer size
  424. "MY_RAM_DISK", // Volume Name
  425. 1, // Number of FATs
  426. 32, // Directory Entries
  427. 0, // Hidden sectors
  428. 256, // Total sectors
  429. 128, // Sector size
  430. 1, // Sectors per cluster
  431. 1, // Heads
  432. 1); // Sectors per track
  433. /* Determine if the format had an error. */
  434. if (status)
  435. {
  436. printf("ERROR!\n");
  437. test_control_return(15);
  438. }
  439. /* Corrupt the reserved sectors field. */
  440. _fx_utility_16_unsigned_write(&ram_disk_memory[FX_RESERVED_SECTORS], 0);
  441. /* Open the ram_disk. */
  442. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  443. /* Check the status. */
  444. if (status != FX_MEDIA_INVALID)
  445. {
  446. /* Error, return error code. */
  447. printf("ERROR!\n");
  448. test_control_return(16);
  449. }
  450. /* Format the media. This needs to be done before opening it! */
  451. status = fx_media_format(&ram_disk,
  452. _fx_ram_driver, // Driver entry
  453. ram_disk_memory, // RAM disk memory pointer
  454. cache_buffer, // Media buffer pointer
  455. CACHE_SIZE, // Media buffer size
  456. "MY_RAM_DISK", // Volume Name
  457. 1, // Number of FATs
  458. 32, // Directory Entries
  459. 0, // Hidden sectors
  460. 256, // Total sectors
  461. 128, // Sector size
  462. 1, // Sectors per cluster
  463. 1, // Heads
  464. 1); // Sectors per track
  465. /* Determine if the format had an error. */
  466. if (status)
  467. {
  468. printf("ERROR!\n");
  469. test_control_return(17);
  470. }
  471. /* Corrupt the sectors per cluster field. */
  472. ram_disk_memory[FX_SECTORS_CLUSTER] = 0;
  473. /* Open the ram_disk. */
  474. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  475. /* Check the status. */
  476. if (status != FX_MEDIA_INVALID)
  477. {
  478. /* Error, return error code. */
  479. printf("ERROR!\n");
  480. test_control_return(18);
  481. }
  482. /* Format the media. This needs to be done before opening it! */
  483. status = fx_media_format(&ram_disk,
  484. _fx_ram_driver, // Driver entry
  485. ram_disk_memory, // RAM disk memory pointer
  486. cache_buffer, // Media buffer pointer
  487. CACHE_SIZE, // Media buffer size
  488. "MY_RAM_DISK", // Volume Name
  489. 1, // Number of FATs
  490. 32, // Directory Entries
  491. 0, // Hidden sectors
  492. 256, // Total sectors
  493. 128, // Sector size
  494. 1, // Sectors per cluster
  495. 1, // Heads
  496. 1); // Sectors per track
  497. /* Determine if the format had an error. */
  498. if (status)
  499. {
  500. printf("ERROR!\n");
  501. test_control_return(19);
  502. }
  503. /* Corrupt the sectors per FAT field. */
  504. _fx_utility_16_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT], 0);
  505. _fx_utility_32_unsigned_write(&ram_disk_memory[FX_SECTORS_PER_FAT_32], 0);
  506. /* Open the ram_disk. */
  507. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  508. /* Check the status. */
  509. if (status != FX_MEDIA_INVALID)
  510. {
  511. /* Error, return error code. */
  512. printf("ERROR!\n");
  513. test_control_return(20);
  514. }
  515. /* Format the media. This needs to be done before opening it! */
  516. status = fx_media_format(&ram_disk,
  517. _fx_ram_driver, // Driver entry
  518. ram_disk_memory, // RAM disk memory pointer
  519. cache_buffer, // Media buffer pointer
  520. CACHE_SIZE, // Media buffer size
  521. "MY_RAM_DISK", // Volume Name
  522. 1, // Number of FATs
  523. 32, // Directory Entries
  524. 0, // Hidden sectors
  525. 256, // Total sectors
  526. 128, // Sector size
  527. 1, // Sectors per cluster
  528. 1, // Heads
  529. 1); // Sectors per track
  530. /* Determine if the format had an error. */
  531. if (status)
  532. {
  533. printf("ERROR!\n");
  534. test_control_return(21);
  535. }
  536. /* Corrupt the number of FATs field. */
  537. ram_disk_memory[FX_NUMBER_OF_FATS] = 0;
  538. /* Open the ram_disk. */
  539. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  540. /* Check the status. */
  541. if (status != FX_MEDIA_INVALID)
  542. {
  543. /* Error, return error code. */
  544. printf("ERROR!\n");
  545. test_control_return(22);
  546. }
  547. /* Format the media. This needs to be done before opening it! */
  548. status = fx_media_format(&ram_disk,
  549. _fx_ram_driver, // Driver entry
  550. ram_disk_memory, // RAM disk memory pointer
  551. cache_buffer, // Media buffer pointer
  552. CACHE_SIZE, // Media buffer size
  553. "MY_RAM_DISK", // Volume Name
  554. 1, // Number of FATs
  555. 32, // Directory Entries
  556. 0, // Hidden sectors
  557. 256, // Total sectors
  558. 128, // Sector size
  559. 1, // Sectors per cluster
  560. 1, // Heads
  561. 1); // Sectors per track
  562. /* Determine if the format had an error. */
  563. if (status)
  564. {
  565. printf("ERROR!\n");
  566. test_control_return(21);
  567. }
  568. /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
  569. status = fx_media_format(&ram_disk,
  570. _fx_ram_driver, // Driver entry
  571. ram_disk_memory, // RAM disk memory pointer
  572. cache_buffer, // Media buffer pointer
  573. CACHE_SIZE, // Media buffer size
  574. "MY_RAM_DISK", // Volume Name
  575. 1, // Number of FATs
  576. 32, // Directory Entries
  577. 0, // Hidden sectors
  578. 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
  579. 128, // Sector size
  580. 1, // Sectors per cluster
  581. 1, // Heads
  582. 1); // Sectors per track
  583. /* Determine if the format had an error. */
  584. if (status)
  585. {
  586. printf("ERROR!\n");
  587. test_control_return(23);
  588. }
  589. /* Open the ram_disk. */
  590. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  591. status += fx_media_close(&ram_disk);
  592. /* Check the status. */
  593. if (status != FX_SUCCESS)
  594. {
  595. /* Error, return error code. */
  596. printf("ERROR!\n");
  597. test_control_return(24);
  598. }
  599. /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
  600. status = fx_media_format(&ram_disk,
  601. _fx_ram_driver, // Driver entry
  602. ram_disk_memory, // RAM disk memory pointer
  603. cache_buffer, // Media buffer pointer
  604. CACHE_SIZE, // Media buffer size
  605. "MY_RAM_DISK", // Volume Name
  606. 1, // Number of FATs
  607. 32, // Directory Entries
  608. 0, // Hidden sectors
  609. 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
  610. 128, // Sector size
  611. 1, // Sectors per cluster
  612. 1, // Heads
  613. 1); // Sectors per track
  614. /* Determine if the format had an error. */
  615. if (status)
  616. {
  617. printf("ERROR!\n");
  618. test_control_return(25);
  619. }
  620. /* Open the ram_disk. */
  621. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  622. status += fx_media_close(&ram_disk);
  623. /* Check the status. */
  624. if (status != FX_SUCCESS)
  625. {
  626. /* Error, return error code. */
  627. printf("ERROR!\n");
  628. test_control_return(26);
  629. }
  630. /* Format the media with an even number of FAT12 sectors. This needs to be done before opening it! */
  631. status = fx_media_format(&ram_disk,
  632. _fx_ram_driver, // Driver entry
  633. ram_disk_memory, // RAM disk memory pointer
  634. cache_buffer, // Media buffer pointer
  635. CACHE_SIZE, // Media buffer size
  636. "MY_RAM_DISK", // Volume Name
  637. 1, // Number of FATs
  638. 32, // Directory Entries
  639. 0, // Hidden sectors
  640. 256+9, // Total sectors - need 256 clusters for even FAT table logic to be tested
  641. 128, // Sector size
  642. 1, // Sectors per cluster
  643. 1, // Heads
  644. 1); // Sectors per track
  645. /* Determine if the format had an error. */
  646. if (status)
  647. {
  648. printf("ERROR!\n");
  649. test_control_return(23);
  650. }
  651. /* Clear 480 bytes from offset 30. Verify the compatibility.
  652. * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
  653. memset(&ram_disk_memory[30], 0, 480);
  654. /* Open the ram_disk. */
  655. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  656. status += fx_media_close(&ram_disk);
  657. /* Check the status. */
  658. if (status != FX_SUCCESS)
  659. {
  660. /* Error, return error code. */
  661. printf("ERROR!\n");
  662. test_control_return(24);
  663. }
  664. /* Format the media with an even number of FAT16 sectors. This needs to be done before opening it! */
  665. status = fx_media_format(&ram_disk,
  666. _fx_ram_driver, // Driver entry
  667. ram_disk_memory, // RAM disk memory pointer
  668. cache_buffer, // Media buffer pointer
  669. CACHE_SIZE, // Media buffer size
  670. "MY_RAM_DISK", // Volume Name
  671. 1, // Number of FATs
  672. 32, // Directory Entries
  673. 0, // Hidden sectors
  674. 6144+9, // Total sectors - need 6144 clusters for even FAT table logic to be tested
  675. 128, // Sector size
  676. 1, // Sectors per cluster
  677. 1, // Heads
  678. 1); // Sectors per track
  679. /* Determine if the format had an error. */
  680. if (status)
  681. {
  682. printf("ERROR!\n");
  683. test_control_return(25);
  684. }
  685. /* Clear 480 bytes from offset 30. Verify the compatibility.
  686. * They are reserved for FDC Descriptor. Some of them are defined in Extended FDC Descriptor. */
  687. memset(&ram_disk_memory[30], 0, 480);
  688. /* Open the ram_disk. */
  689. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  690. status += fx_media_close(&ram_disk);
  691. /* Check the status. */
  692. if (status != FX_SUCCESS)
  693. {
  694. /* Error, return error code. */
  695. printf("ERROR!\n");
  696. test_control_return(26);
  697. }
  698. /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
  699. status = fx_media_format(&ram_disk,
  700. _fx_ram_driver, // Driver entry
  701. ram_disk_memory, // RAM disk memory pointer
  702. cache_buffer, // Media buffer pointer
  703. CACHE_SIZE, // Media buffer size
  704. "MY_RAM_DISK", // Volume Name
  705. 1, // Number of FATs
  706. 32, // Directory Entries
  707. 0, // Hidden sectors
  708. 70656+9, // Total sectors - FAT32
  709. 128, // Sector size
  710. 1, // Sectors per cluster
  711. 1, // Heads
  712. 1); // Sectors per track
  713. /* Determine if the format had an error. */
  714. if (status)
  715. {
  716. printf("ERROR!\n");
  717. test_control_return(27);
  718. }
  719. /* Open the ram_disk. */
  720. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  721. status += fx_media_close(&ram_disk);
  722. /* Check the status. */
  723. if (status != FX_SUCCESS)
  724. {
  725. /* Error, return error code. */
  726. printf("ERROR!\n");
  727. test_control_return(28);
  728. }
  729. /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
  730. status = fx_media_format(&ram_disk,
  731. _fx_ram_driver, // Driver entry
  732. ram_disk_memory, // RAM disk memory pointer
  733. cache_buffer, // Media buffer pointer
  734. CACHE_SIZE, // Media buffer size
  735. "MY_RAM_DISK", // Volume Name
  736. 1, // Number of FATs
  737. 32, // Directory Entries
  738. 0, // Hidden sectors
  739. 70656+9, // Total sectors - FAT32
  740. 128, // Sector size
  741. 1, // Sectors per cluster
  742. 1, // Heads
  743. 1); // Sectors per track
  744. /* Determine if the format had an error. */
  745. if (status)
  746. {
  747. printf("ERROR!\n");
  748. test_control_return(27);
  749. }
  750. /* Corrupt the root cluster field. */
  751. ram_disk_memory[FX_ROOT_CLUSTER_32] = 0;
  752. ram_disk_memory[FX_ROOT_CLUSTER_32 + 1] = 0;
  753. ram_disk_memory[FX_ROOT_CLUSTER_32 + 2] = 0;
  754. ram_disk_memory[FX_ROOT_CLUSTER_32 + 3] = 0;
  755. /* Open the ram_disk. */
  756. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  757. /* Check the status. */
  758. if (status != FX_MEDIA_INVALID)
  759. {
  760. /* Error, return error code. */
  761. printf("ERROR!\n");
  762. test_control_return(28);
  763. }
  764. /* Format the media with volume name containing space! */
  765. status = fx_media_format(&ram_disk,
  766. _fx_ram_driver, // Driver entry
  767. ram_disk_memory, // RAM disk memory pointer
  768. cache_buffer, // Media buffer pointer
  769. CACHE_SIZE, // Media buffer size
  770. "NO NAME", // Volume Name
  771. 1, // Number of FATs
  772. 32, // Directory Entries
  773. 0, // Hidden sectors
  774. 512, // Total sectors
  775. 128, // Sector size
  776. 1, // Sectors per cluster
  777. 1, // Heads
  778. 1); // Sectors per track
  779. /* Determine if the format had an error. */
  780. if (status)
  781. {
  782. printf("ERROR!\n");
  783. test_control_return(29);
  784. }
  785. /* Open the ram_disk. */
  786. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  787. status += fx_media_volume_get(&ram_disk, (CHAR *)local_buffer, FX_BOOT_SECTOR);
  788. /* Check for status. */
  789. if ((status != FX_SUCCESS) || (memcmp(local_buffer, "NO NAME", 7)))
  790. {
  791. printf("ERROR!\n");
  792. test_control_return(30);
  793. }
  794. status = fx_media_close(&ram_disk);
  795. /* Check the status. */
  796. if (status != FX_SUCCESS)
  797. {
  798. /* Error, return error code. */
  799. printf("ERROR!\n");
  800. test_control_return(31);
  801. }
  802. memset(ram_disk_memory, 0, sizeof(ram_disk_memory));
  803. /* Format the media with an even number of FAT32 sectors. This needs to be done before opening it! */
  804. status = fx_media_format(&ram_disk,
  805. _fx_ram_driver, // Driver entry
  806. ram_disk_memory, // RAM disk memory pointer
  807. cache_buffer, // Media buffer pointer
  808. CACHE_SIZE, // Media buffer size
  809. "MY_RAM_DISK", // Volume Name
  810. 1, // Number of FATs
  811. 32, // Directory Entries
  812. 0, // Hidden sectors
  813. 70656+9, // Total sectors - FAT32
  814. 128, // Sector size
  815. 1, // Sectors per cluster
  816. 1, // Heads
  817. 1); // Sectors per track
  818. /* Determine if the format had an error. */
  819. if (status)
  820. {
  821. printf("ERROR!\n");
  822. test_control_return(32);
  823. }
  824. unsigned index =0;
  825. /* Check the FAT entry values, first byte starts with 0xF(_fx_media_format_media_type) */
  826. for(index=0; index< ((70656+9)*128);index++)
  827. {
  828. if((ram_disk_memory[index]==0xF8) && (ram_disk_memory[index+1]==0xFF) && (ram_disk_memory[index+2]==0xFF) &&
  829. (ram_disk_memory[index+3]==0x0F) && (ram_disk_memory[index+4]==0xFF) && (ram_disk_memory[index+5]==0xFF) &&
  830. (ram_disk_memory[index+6]==0xFF) && (ram_disk_memory[index+7]==0x0F))
  831. {
  832. break;
  833. }
  834. }
  835. if(index ==(70656+9)*128)
  836. {
  837. printf("ERROR!\n");
  838. test_control_return(33);
  839. }
  840. else
  841. {
  842. printf("SUCCESS!\n");
  843. test_control_return(0);
  844. }
  845. }