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