1 #ifndef FX_STANDALONE_ENABLE
2 #include "tx_api.h"
3 #include "tx_thread.h"
4 #include "tx_timer.h"
5 #endif
6 #include "fx_api.h"
7 #include "fx_directory.h"
8 #include "fx_utility.h"
9 #include "fx_fault_tolerant.h"
10 #include <stdio.h>
11 #include <string.h>
12 #include "fx_ram_driver_test.h"
13 extern void test_control_return(UINT status);
14 void filex_fault_tolerant_enable_3_test_application_define(void *first_unused_memory);
15
16 #if defined (FX_ENABLE_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT)
17
18 #define DEMO_STACK_SIZE 4096
19 #define CACHE_SIZE 2048
20 #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
21
22
23 /* Define the ThreadX and FileX object control blocks... */
24
25 #ifndef FX_STANDALONE_ENABLE
26 static TX_THREAD ftest_0;
27 #endif
28 static FX_MEDIA ram_disk;
29 static UCHAR *pointer;
30
31 /* Define the counters used in the test application... */
32
33 #ifndef FX_STANDALONE_ENABLE
34 static UCHAR *cache_buffer;
35 static UCHAR *fault_tolerant_buffer;
36 static UCHAR *ram_disk_memory;
37 #else
38 static UCHAR cache_buffer[CACHE_SIZE];
39 static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
40 #endif
41 static CHAR read_buffer[10240];
42
43 #define TEST_COUNT 3
44
45 /* Define thread prototypes. */
46
47 static void ftest_0_entry(ULONG thread_input);
48 extern void _fx_ram_driver(FX_MEDIA *media_ptr);
49 extern void test_control_return(UINT status);
50
51
52 /* Define what the initial system looks like. */
53
54 #ifdef CTEST
test_application_define(void * first_unused_memory)55 void test_application_define(void *first_unused_memory)
56 #else
57 void filex_fault_tolerant_enable_3_test_application_define(void *first_unused_memory)
58 #endif
59 {
60
61
62
63 #ifndef FX_STANDALONE_ENABLE
64 /* Setup the working pointer. */
65 pointer = (UCHAR *) first_unused_memory;
66
67 /* Create the main thread. */
68
69 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
70 pointer, DEMO_STACK_SIZE,
71 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
72
73 pointer = pointer + DEMO_STACK_SIZE;
74
75 /* Setup memory for the RAM disk and the sector cache. */
76 cache_buffer = pointer;
77 pointer += CACHE_SIZE;
78 fault_tolerant_buffer = pointer;
79 pointer += FAULT_TOLERANT_SIZE;
80 ram_disk_memory = pointer;
81 pointer += (256 * 128);
82 #endif
83
84 /* Initialize the FileX system. */
85 fx_system_initialize();
86 #ifdef FX_STANDALONE_ENABLE
87 ftest_0_entry(0);
88 #endif
89 }
90
91
92 /* Define the test threads. */
93
ftest_0_entry(ULONG thread_input)94 static void ftest_0_entry(ULONG thread_input)
95 {
96
97 ULONG64 actual_64;
98 UINT status, length, new_length, old_length;
99 ULONG actual;
100 ULONG temp;
101 UCHAR buffer[2048];
102 CHAR destination_name[100];
103 UCHAR unicode_name_A[] = { 'A', 0, 0, 0};
104 UCHAR unicode_name_1[] = { 1, 0, 0, 0};
105 UCHAR unicode_name_2[] = { 1, 0, 1, 0, 0, 0};
106 UCHAR unicode_name_3[] = { 1, 0, 1, 0, 1, 0, 0, 0};
107 UCHAR unicode_name_14[] = { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 0, 0};
108 UCHAR unicode_name_A1[] = { 'A', 0, 1, 0, 0, 0};
109 UCHAR unicode_name_A3[] = { 'A', 1, 2, 1, 0, 0};
110 UCHAR long_unicode_name[300];
111 FX_FILE my_file;
112 FX_LOCAL_PATH local_path;
113 FX_DIR_ENTRY dir_entry;
114
115 FX_PARAMETER_NOT_USED(thread_input);
116
117 /* Print out some test information banners. */
118 printf("FileX Test: Fault Tolerant Enable 3 Test...........................");
119
120 /* Format the media with FAT16. This needs to be done before opening it! */
121 status = fx_media_format(&ram_disk,
122 _fx_ram_driver, // Driver entry
123 ram_disk_memory_large, // RAM disk memory pointer
124 cache_buffer, // Media buffer pointer
125 CACHE_SIZE, // Media buffer size
126 "MY_RAM_DISK", // Volume Name
127 1, // Number of FATs
128 32, // Directory Entries
129 0, // Hidden sectors
130 4200 * 8, // Total sectors
131 256, // Sector size
132 8, // Sectors per cluster
133 1, // Heads
134 1); // Sectors per track
135 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
136 return_if_fail( status == FX_SUCCESS);
137
138 /* Enable fault tolerant. */
139 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
140 return_if_fail( status == FX_SUCCESS);
141
142 /* Prepare a file for our test. */
143 length = fx_unicode_length_get( unicode_name_2);
144 status = fx_unicode_file_create( &ram_disk, unicode_name_2, length, destination_name);
145 status += fx_file_open( &ram_disk, &my_file, destination_name, FX_OPEN_FOR_WRITE);
146 status += fx_file_allocate( &my_file, 2048);
147 status += fx_file_seek( &my_file, 2048);
148 return_if_fail( status == FX_SUCCESS);
149
150 /* Write some data append to the new file, which will call fx_fault_tolerant_cleanup_FAT_chain */
151 /* Make IO error while reading FAT chain. */
152 _fx_utility_fat_entry_read_error_request = 2;
153 status += fx_file_write( &my_file, "1234567890", 10);
154 return_if_fail( status == FX_IO_ERROR);
155
156 status = fx_file_close( &my_file);
157 return_if_fail( status == FX_SUCCESS);
158
159 /* Make IO error while _fx_fault_tolerant_recover is calling _fx_fault_tolerant_cleanup_FAT_chain. */
160 ram_disk.fx_media_driver_write_protect = FX_TRUE;
161 /*_fx_utility_fat_entry_read_error_request = 1;*/
162 status = fx_file_rename(&ram_disk, "MYTEST", "OURTEST");
163 ram_disk.fx_media_driver_write_protect = FX_FALSE;
164 return_if_fail( status == FX_WRITE_PROTECT);
165
166 status = fx_media_close( &ram_disk);
167 return_if_fail( status == FX_SUCCESS);
168
169 /* Format the media. This needs to be done before opening it! */
170 status = fx_media_format(&ram_disk,
171 _fx_ram_driver, // Driver entry
172 ram_disk_memory, // RAM disk memory pointer
173 cache_buffer, // Media buffer pointer
174 CACHE_SIZE, // Media buffer size
175 "MY_RAM_DISK", // Volume Name
176 1, // Number of FATs
177 32, // Directory Entries
178 0, // Hidden sectors
179 70000, // Total sectors - FAT32
180 128, // Sector size
181 1, // Sectors per cluster
182 1, // Heads
183 1); // Sectors per track
184 return_if_fail( status == FX_SUCCESS);
185
186 /* Open the ram_disk. */
187 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
188 return_if_fail( status == FX_SUCCESS);
189
190 /* Now create a series to sub-directories to expand the root directory FAT chain. */
191 status = fx_file_create(&ram_disk, "FILE1");
192
193 /* Open the file. */
194 status += fx_file_open(&ram_disk, &my_file, "FILE1", FX_OPEN_FOR_WRITE);
195
196 /* Write to the file. */
197 status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
198 status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
199 status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
200 status += fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
201 return_if_fail( status == FX_SUCCESS);
202
203 /* Make an IO error while flushing dirty buffer in fx_utility_logical_sector_read.c. */
204 _fx_ram_driver_io_error_request = 4;
205 status = fx_file_write(&my_file, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
206 return_if_fail( status == FX_IO_ERROR);
207
208 status = fx_file_close( &my_file);
209 status += fx_media_close( &ram_disk);
210 return_if_fail( status == FX_SUCCESS);
211
212 /* Format the media. This needs to be done before opening it! */
213 status = fx_media_format(&ram_disk,
214 _fx_ram_driver, // Driver entry
215 ram_disk_memory, // RAM disk memory pointer
216 cache_buffer, // Media buffer pointer
217 CACHE_SIZE, // Media buffer size
218 "MY_RAM_DISK", // Volume Name
219 1, // Number of FATs
220 32, // Directory Entries
221 0, // Hidden sectors
222 4200 * 8, // Total sectors - FAT32
223 256, // Sector size
224 8, // Sectors per cluster
225 1, // Heads
226 1); // Sectors per track
227 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
228 return_if_fail( status == FX_SUCCESS);
229
230 /* Enable fault tolerant. */
231 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
232 return_if_fail( status == FX_SUCCESS);
233
234 /* Attempt to truncate file which is open for read while fault tolerant is enabled. */
235 status = fx_file_create( &ram_disk, "FILE2");
236 status += fx_file_open( &ram_disk, &my_file, "FILE2", FX_OPEN_FOR_READ);
237 status += fx_file_truncate_release( &my_file, 0);
238 return_if_fail( status == FX_ACCESS_ERROR);
239
240 /* Attempt to truncate file while fault tolerant is enabled and the disk is write protected. */
241 status = fx_file_close( &my_file);
242 status += fx_file_open( &ram_disk, &my_file, "FILE2", FX_OPEN_FOR_WRITE);
243 ram_disk.fx_media_driver_write_protect = 1;
244 status += fx_file_truncate_release( &my_file, 0);
245 ram_disk.fx_media_driver_write_protect = 0;
246 return_if_fail( status == FX_WRITE_PROTECT);
247
248 status = fx_file_allocate( &my_file, 2048 * 2);
249 return_if_fail( status == FX_SUCCESS);
250
251 /* Make IO error in _fx_directory_entry_write. */
252 _fx_utility_logical_sector_read_error_request = 1;
253 status = fx_file_truncate_release( &my_file, 1000);
254 return_if_fail( status == FX_IO_ERROR);
255
256 /* Size expected is less the original file size. */
257 status = fx_file_truncate_release( &my_file, 2048 * 3);
258 status += fx_file_seek( &my_file, 2048 * 3);
259 status += fx_file_truncate_release( &my_file, 2048 * 2);
260 status += fx_file_close( &my_file);
261 return_if_fail( status == FX_SUCCESS);
262
263 /* Prepare a file for our test. */
264 status = fx_file_create( &ram_disk, "FILE3");
265 status += fx_file_open( &ram_disk, &my_file, "FILE3", FX_OPEN_FOR_WRITE);
266 status += fx_file_allocate( &my_file, 2048 * 3);
267 return_if_fail( status == FX_SUCCESS);
268
269 /* Make IO error while first reading current cluster entry from FAT chain. */
270 _fx_utility_fat_entry_read_error_request = 3;
271 status = fx_file_truncate_release( &my_file, 2048);
272 return_if_fail( status == FX_IO_ERROR);
273
274 /* Allocate 5 clusters for our new file. */
275 status = fx_file_allocate( &my_file, 5 * 2048);
276 return_if_fail( status == FX_SUCCESS);
277
278 /* Make IO error while reading more cluster entries from FAT chain. */
279 _fx_utility_fat_entry_read_error_request = 4;
280 status = fx_file_truncate_release( &my_file, 2048);
281 return_if_fail( status == FX_IO_ERROR);
282
283 /* Allocate 5 clusters for our new file. */
284 status = fx_file_allocate( &my_file, 5 * 2048);
285 return_if_fail( status == FX_SUCCESS);
286
287 /* Make IO error while setting undo log in FAT chain. */
288 _fx_utility_logical_sector_write_error_request = 1;
289 status = fx_file_truncate_release( &my_file, 2048);
290 return_if_fail( status == FX_IO_ERROR);
291
292 /* Allocate 5 clusters for our new file. */
293 status = fx_file_allocate( &my_file, 5 * 2048);
294 return_if_fail( status == FX_SUCCESS);
295
296 /* Make IO error while setting the end of the FAT chain. */
297 _fx_utility_fat_entry_write_error_request = 1;
298 status = fx_file_truncate_release( &my_file, 2048);
299 return_if_fail( status == FX_IO_ERROR);
300
301 /* Allocate 5 clusters for our new file. */
302 status = fx_file_allocate( &my_file, 5 * 2048);
303 return_if_fail( status == FX_SUCCESS);
304
305 /* Make IO error while flushing cached FAT entries. */
306 _fx_utility_logical_sector_read_error_request = 2;
307 status = fx_file_truncate_release( &my_file, 2048);
308 return_if_fail( status == FX_IO_ERROR);
309
310 /* Allocate 5 clusters for our new file. */
311 status = fx_file_allocate( &my_file, 5 * 2048);
312 return_if_fail( status == FX_SUCCESS);
313
314 /* Make IO error at the end of fx_file_truncate_release while writing directory entries to the media. */
315 _fx_utility_logical_sector_read_error_request = 3;
316 status = fx_file_truncate_release( &my_file, 2048);
317 return_if_fail( status == FX_IO_ERROR);
318
319 /* Allocate 5 clusters for our new file. */
320 status = fx_file_allocate( &my_file, 5 * 2048);
321 return_if_fail( status == FX_SUCCESS);
322
323 /* Make IO error in fx_file_truncate_release while calling _fx_fault_tolerant_transaction_end. */
324 _fx_utility_logical_sector_read_error_request = 4;
325 status = fx_file_truncate_release( &my_file, 2048);
326 return_if_fail( status == FX_IO_ERROR);
327
328 status = fx_file_close( &my_file);
329 status += fx_media_close( &ram_disk);
330
331 /* Format the media. This needs to be done before opening it! */
332 status = fx_media_format(&ram_disk,
333 _fx_ram_driver, // Driver entry
334 ram_disk_memory, // RAM disk memory pointer
335 cache_buffer, // Media buffer pointer
336 CACHE_SIZE, // Media buffer size
337 "MY_RAM_DISK", // Volume Name
338 1, // Number of FATs
339 32, // Directory Entries
340 0, // Hidden sectors
341 4200 * 8, // Total sectors - FAT32
342 256, // Sector size
343 8, // Sectors per cluster
344 1, // Heads
345 1); // Sectors per track
346 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
347 return_if_fail( status == FX_SUCCESS);
348
349 status = fx_file_create( &ram_disk, "TEST");
350 status += fx_file_open( &ram_disk, &my_file, "TEST", FX_OPEN_FOR_WRITE);
351 status += fx_file_allocate( &my_file, 2048 * 5);
352 return_if_fail( status == FX_SUCCESS);
353
354 /* Make an IO error at the end of fx_file_extended_truncate_release while calling _fx_utility_FAT_flush. */
355 /* which can only be reached when FX_FAULT_TOLERANT is defined but not enabled since fat entries will never be set as dirty while fault tolerant is enabled. */
356 /* We add fat log instead of setting fx_fat_cache_entry_dirty while fault tolerant is enabled. */
357 _fx_utility_logical_sector_read_error_request = 3;
358 status = fx_file_truncate_release( &my_file, 2048);
359 return_if_fail( status == FX_IO_ERROR);
360
361 status = fx_file_close( &my_file);
362 status += fx_media_close( &ram_disk);
363 return_if_fail( status == FX_SUCCESS);
364
365 /* Format the media. This needs to be done before opening it! */
366 status = fx_media_format(&ram_disk,
367 _fx_ram_driver, // Driver entry
368 ram_disk_memory, // RAM disk memory pointer
369 cache_buffer, // Media buffer pointer
370 CACHE_SIZE, // Media buffer size
371 "MY_RAM_DISK", // Volume Name
372 1, // Number of FATs
373 32, // Directory Entries
374 0, // Hidden sectors
375 4200 * 8, // Total sectors - FAT32
376 256, // Sector size
377 8, // Sectors per cluster
378 1, // Heads
379 1); // Sectors per track
380 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
381 return_if_fail( status == FX_SUCCESS);
382
383 /* Enable fault tolerant. */
384 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
385 return_if_fail( status == FX_SUCCESS);
386
387 /* Make an IO error in fx_directory_create while writing back directory sectors. */
388 _fx_utility_logical_sector_write_error_request = 1;
389 status = fx_directory_create( &ram_disk, "dev");
390 return_if_fail( status == FX_IO_ERROR);
391
392 #ifndef FX_DISABLE_CACHE
393 /* Make an IO error in fx_directory_create while flushing internal logical sector cache. */
394 _fx_utility_logical_sector_flush_error_request = 1;
395 status = fx_directory_create( &ram_disk, "dev");
396 return_if_fail( status == FX_IO_ERROR);
397 #endif
398
399 /* Make an IO error at the end of fx_directory_create while writing back new directory sector. */
400 _fx_utility_logical_sector_read_error_request = 10;
401 status = fx_directory_create( &ram_disk, "dev");
402 return_if_fail( status == FX_IO_ERROR);
403
404 status = fx_file_create( &ram_disk, "TEST");
405 status += fx_file_open( &ram_disk, &my_file, "TEST", FX_OPEN_FOR_WRITE);
406 status += fx_file_allocate( &my_file, 2048 * 3);
407 return_if_fail( status == FX_SUCCESS);
408
409 /* Make an IO error at the end of fx_file_extended_truncate while calling _fx_directory_entry_write. */
410 _fx_utility_logical_sector_read_error_request = 1;
411 status = fx_file_extended_truncate( &my_file, 2048 * 2);
412 return_if_fail( status == FX_IO_ERROR);
413
414 /* Make an IO error in fx_file_extended_truncate while calling _fx_fault_tolerant_transaction_end. */
415 _fx_utility_logical_sector_read_error_request = 2;
416 status = fx_file_extended_truncate( &my_file, 2048);
417 return_if_fail( status == FX_IO_ERROR);
418
419 status = fx_file_allocate( &my_file, 2048 * 2);
420 status += fx_file_close( &my_file);
421 return_if_fail( status == FX_SUCCESS);
422
423 /* Open the file we just closed which will update fx_file_maximum_size_used of the file. */
424 status = fx_file_open( &ram_disk, &my_file, "TEST", FX_OPEN_FOR_WRITE);
425 return_if_fail( status == FX_SUCCESS);
426
427 /* Truncated the file size less than fx_file_maximum_size_used. */
428 status = fx_file_extended_truncate( &my_file, 1024);
429 return_if_fail( status == FX_SUCCESS);
430
431 status = fx_file_close( &my_file);
432 return_if_fail( status == FX_SUCCESS);
433
434 status = fx_file_create( &ram_disk, "FILE");
435 status += fx_file_open( &ram_disk, &my_file, "FILE", FX_OPEN_FOR_WRITE);
436 status += fx_file_allocate( &my_file, 2048 * 3);
437 status += fx_file_extended_truncate_release( &my_file, 0);
438 return_if_fail( status == FX_SUCCESS);
439
440 /* Extend the file which have no clusters, which need to sep FAT chain. */
441 status = fx_file_extended_best_effort_allocate( &my_file, 2048 * 4, &actual_64);
442 return_if_fail( status == FX_SUCCESS);
443
444 /* Make an IO error while writing the directory back to the media. */
445 _fx_utility_logical_sector_read_error_request = 7;
446 status = fx_file_extended_best_effort_allocate( &my_file, 2048 * 5, &actual_64);
447 return_if_fail( status == FX_IO_ERROR);
448
449 #ifndef FX_DISABLE_CACHE
450 /* Make an IO error at the end of fx_file_extended_best_effort while flushing sectors. */
451 _fx_utility_logical_sector_flush_error_request = 3;
452 status = fx_file_extended_best_effort_allocate( &my_file, 2048 * 5, &actual_64);
453 return_if_fail( status == FX_IO_ERROR);
454 #endif
455
456 /* Make an IO error in fx_unicode_file_create while calling _fx_directory_search. */
457 length = fx_unicode_length_get( unicode_name_A);
458 _fx_utility_logical_sector_read_error_request = 14;
459 status = fx_unicode_file_create( &ram_disk, unicode_name_A, length, destination_name);
460 return_if_fail( status == FX_IO_ERROR);
461
462 /* Make an IO error in fx_unicode_directory_create while calling _fx_directory_search. */
463 length = fx_unicode_length_get( unicode_name_A);
464 _fx_utility_logical_sector_read_error_request = 23;
465 status = fx_unicode_directory_create( &ram_disk, unicode_name_A, length, destination_name);
466 return_if_fail( status == FX_IO_ERROR);
467
468 #ifndef FX_DISABLE_CACHE
469 /* Make an IO error in fx_unicode_file_create while calling _fx_unicode_directory_entry_change. */
470 length = fx_unicode_length_get( unicode_name_A3);
471 _fx_utility_logical_sector_read_error_request = 25;
472 status = fx_unicode_file_create( &ram_disk, unicode_name_A3, length, destination_name);
473 return_if_fail( status == FX_IO_ERROR);
474
475 /* Make an IO error in fx_unicode_directory_create while calling _fx_unicode_directory_entry_change. */
476 unicode_name_A3[0]++;
477 length = fx_unicode_length_get( unicode_name_A3);
478 _fx_utility_logical_sector_read_error_request = 32;
479 status = fx_unicode_directory_create( &ram_disk, unicode_name_A3, length, destination_name);
480 return_if_fail( status == FX_IO_ERROR);
481 #endif
482
483 status = fx_file_close( &my_file);
484 status += fx_file_create( &ram_disk, "HELLO");
485 status += fx_file_open( &ram_disk, &my_file, "HELLO", FX_OPEN_FOR_WRITE);
486 return_if_fail( status == FX_SUCCESS);
487
488 /* Make an IO error in fx_file_extended_allocate while calling _fx_directory_entry_write. */
489 _fx_utility_logical_sector_read_error_request = 2;
490 status = fx_file_extended_allocate( &my_file, 200);
491 return_if_fail( status == FX_IO_ERROR);
492
493 #ifndef FX_DISABLE_CACHE
494 /* Make an IO error in fx_file_extended_allocate while calling _fx_utility_logical_sector_flush. */
495 _fx_utility_logical_sector_flush_error_request = 3;
496 status = fx_file_extended_allocate( &my_file, 200);
497 return_if_fail( status == FX_IO_ERROR);
498 #endif
499
500 status = fx_media_close( &ram_disk);
501 return_if_fail( status == FX_SUCCESS);
502
503 /* Format the media. This needs to be done before opening it! */
504 status = fx_media_format(&ram_disk,
505 _fx_ram_driver, // Driver entry
506 ram_disk_memory, // RAM disk memory pointer
507 cache_buffer, // Media buffer pointer
508 CACHE_SIZE, // Media buffer size
509 "MY_RAM_DISK", // Volume Name
510 1, // Number of FATs
511 32, // Directory Entries
512 0, // Hidden sectors
513 4200 * 8, // Total sectors - FAT32
514 256, // Sector size
515 8, // Sectors per cluster
516 1, // Heads
517 1); // Sectors per track
518 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
519 return_if_fail( status == FX_SUCCESS);
520
521 /* Enable fault tolerant. */
522 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
523 return_if_fail( status == FX_SUCCESS);
524
525 length = fx_unicode_length_get( unicode_name_1);
526 status = fx_unicode_file_create( &ram_disk, unicode_name_1, length , destination_name);
527 return_if_fail( status == FX_SUCCESS);
528
529 old_length = fx_unicode_length_get( unicode_name_1);
530 new_length = fx_unicode_length_get( unicode_name_2);
531
532 /* Make an IO error at the end of fx_unicode_file_rename while calling _fx_directory_search. */
533 _fx_utility_logical_sector_read_error_request = 14;
534 status = fx_unicode_file_rename( &ram_disk, unicode_name_1, old_length, unicode_name_2, new_length, destination_name);
535 return_if_fail( status == FX_IO_ERROR);
536
537 length = fx_unicode_length_get( unicode_name_A);
538 status = fx_unicode_directory_create( &ram_disk, unicode_name_A, length, destination_name);
539 return_if_fail( status == FX_SUCCESS);
540
541 old_length = fx_unicode_length_get( unicode_name_A);
542 new_length = fx_unicode_length_get( unicode_name_A1);
543
544 /* Make an IO error at the end of fx_unicode_directory_rename while calling _fx_directory_search. */
545 _fx_utility_logical_sector_read_error_request = 20;
546 status = fx_unicode_directory_rename( &ram_disk, unicode_name_A, old_length, unicode_name_A1, new_length, destination_name);
547 return_if_fail( status == FX_IO_ERROR);
548
549 status = fx_media_close( &ram_disk);
550 return_if_fail( status == FX_SUCCESS);
551
552 /* Format the media. This needs to be done before opening it! */
553 status = fx_media_format(&ram_disk,
554 _fx_ram_driver, // Driver entry
555 ram_disk_memory, // RAM disk memory pointer
556 cache_buffer, // Media buffer pointer
557 CACHE_SIZE, // Media buffer size
558 "MY_RAM_DISK", // Volume Name
559 1, // Number of FATs
560 32, // Directory Entries
561 0, // Hidden sectors
562 4200 * 8, // Total sectors - FAT32
563 256, // Sector size
564 8, // Sectors per cluster
565 1, // Heads
566 1); // Sectors per track
567 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
568 return_if_fail( status == FX_SUCCESS);
569
570 /* Enable fault tolerant. */
571 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
572 return_if_fail( status == FX_SUCCESS);
573
574 length = fx_unicode_length_get( unicode_name_1);
575 status = fx_unicode_file_create( &ram_disk, unicode_name_1, length , destination_name);
576 return_if_fail( status == FX_SUCCESS);
577
578 old_length = fx_unicode_length_get( unicode_name_1);
579 new_length = fx_unicode_length_get( unicode_name_2);
580
581 /* Make an IO error at the end of fx_unicode_file_rename while calling _fx_unicode_directory_entry_change. */
582 _fx_utility_logical_sector_read_error_request = 17;
583 status = fx_unicode_file_rename( &ram_disk, unicode_name_1, old_length, unicode_name_2, new_length, destination_name);
584 return_if_fail( status == FX_IO_ERROR);
585
586 length = fx_unicode_length_get( unicode_name_A);
587 status = fx_unicode_directory_create( &ram_disk, unicode_name_A, length, destination_name);
588 return_if_fail( status == FX_SUCCESS);
589
590 old_length = fx_unicode_length_get( unicode_name_A);
591 new_length = fx_unicode_length_get( unicode_name_A1);
592
593 #ifndef FX_DISABLE_CACHE
594 /* Make an IO error at the end of fx_unicode_directory_rename while calling _fx_unicode_directory_entry_change. */
595 _fx_utility_logical_sector_read_error_request = 24;
596 status = fx_unicode_directory_rename( &ram_disk, unicode_name_A, old_length, unicode_name_A1, new_length, destination_name);
597 return_if_fail( status == FX_IO_ERROR);
598
599 status = fx_directory_create( &ram_disk, "src");
600 return_if_fail( status == FX_SUCCESS);
601
602 /* Make an IO error at the end of fx_file_delete while calling _fx_utility_logical_sector_flush. */
603 _fx_utility_logical_sector_flush_error_request = 1;
604 status += fx_directory_delete( &ram_disk, "src");
605 return_if_fail( status == FX_IO_ERROR);
606 #endif
607
608 status = fx_directory_create( &ram_disk, "dev");
609 return_if_fail( status == FX_SUCCESS);
610
611 /* Make an IO error at the end of fx_directory_attributes_set while calling _fx_directory_entry_write. */
612 _fx_utility_logical_sector_read_error_request = 2;
613 status = fx_directory_attributes_set( &ram_disk, "dev", FX_DIRECTORY | FX_ARCHIVE | FX_SYSTEM | FX_READ_ONLY | FX_HIDDEN);
614 return_if_fail( status == FX_IO_ERROR);
615
616 status = fx_file_create( &ram_disk, "test.bat");
617 return_if_fail( status == FX_SUCCESS);
618
619 /* Make an IO error at the end of fx_file_attributes_set while calling _fx_directory_entry_write. */
620 _fx_utility_logical_sector_read_error_request = 5;
621 status = fx_file_attributes_set( &ram_disk, "test.bat", FX_READ_ONLY);
622 return_if_fail( status == FX_IO_ERROR);
623
624 status = fx_file_create( &ram_disk, "new_file");
625 status += fx_file_open( &ram_disk, &my_file, "new_file", FX_OPEN_FOR_WRITE);
626 status += fx_file_write( &my_file, "1234567890", 10);
627 return_if_fail( status == FX_SUCCESS);
628
629 /* Make an IO error in fx_media_flush while calling _fx_directory_entry_write. */
630 _fx_utility_logical_sector_read_error_request = 1;
631 status = fx_media_flush( &ram_disk);
632 return_if_fail( status == FX_IO_ERROR);
633
634 #ifndef FX_DISABLE_CACHE
635 /* Make an IO error in fx_media_flush while calling _fx_utility_logical_sector_flush. */
636 _fx_utility_logical_sector_flush_error_request = 1;
637 status = fx_media_flush( &ram_disk);
638 return_if_fail( status == FX_IO_ERROR);
639 #endif
640
641 status = fx_directory_create( &ram_disk, "root");
642 #ifndef FX_STANDALONE_ENABLE
643 status += fx_directory_local_path_set( &ram_disk, &local_path, "root");
644 #else
645 status += fx_directory_default_set(&ram_disk, "/root");
646 #endif
647 return_if_fail( status == FX_SUCCESS);
648
649 /* Create enough directory to overflow one single cluster. */
650 length = fx_unicode_length_get( unicode_name_1);
651 for ( UINT i = 0; i < 26; i++)
652 {
653 status = fx_unicode_directory_create( &ram_disk, unicode_name_1, length, destination_name);
654 unicode_name_1[0]++;
655 return_if_fail( status == FX_SUCCESS);
656 }
657
658 length = fx_unicode_length_get( unicode_name_2);
659 for ( UINT i = 0; i < 6; i++)
660 {
661 status = fx_unicode_directory_create( &ram_disk, unicode_name_2, length, destination_name);
662 unicode_name_2[0]++;
663 return_if_fail( status == FX_SUCCESS);
664 }
665
666 /* Make an IO error in _fx_unicode_directory_entry_read while calling _fx_utility_FAT_entry_read to access fat chain. */
667 _fx_utility_fat_entry_read_error_request = 3;
668 length = fx_unicode_length_get( unicode_name_3);
669 status = fx_unicode_directory_create( &ram_disk, unicode_name_3, length, destination_name);
670 return_if_fail( status == FX_SUCCESS);
671
672 status = fx_directory_create( &ram_disk, "root");
673 #ifndef FX_STANDALONE_ENABLE
674 status += fx_directory_local_path_set( &ram_disk, &local_path, "root");
675 #else
676 status += fx_directory_default_set(&ram_disk, "/root");
677 #endif
678 return_if_fail( status == FX_SUCCESS);
679
680 memset( long_unicode_name, 1, 270);
681 long_unicode_name[270] = 0;
682 long_unicode_name[271] = 0;
683 length = fx_unicode_length_get( long_unicode_name);
684 return_if_fail( length = 135);
685
686 /* Created six directories in a subdir including 12 dir_entries each to overflow a single cluster. */
687 temp = long_unicode_name[0];
688 for ( UINT i = 0; i < 6; i++)
689 {
690 status = fx_unicode_directory_create( &ram_disk, long_unicode_name, length, destination_name);
691 return_if_fail( status == FX_SUCCESS);
692 long_unicode_name[0]++;
693 }
694
695 /* Access the directory divided into two clusters and make an IO error while getting next cluster in _fx_unicode_directory_entry_read. */
696 /* We still create the directory successfully. */
697 _fx_utility_fat_entry_read_error_request = 3;
698 status = fx_unicode_directory_create( &ram_disk, long_unicode_name, length, destination_name);
699 return_if_fail( status == FX_SUCCESS);
700
701 /* Switch to root directory. */
702 #ifndef FX_STANDALONE_ENABLE
703 status += fx_directory_local_path_set( &ram_disk, &local_path, "/");
704 #else
705 status += fx_directory_default_set(&ram_disk, "/");
706 #endif
707 status += fx_unicode_directory_create( &ram_disk, long_unicode_name, length, destination_name);
708 long_unicode_name[0]++;
709 return_if_fail( status == FX_SUCCESS);
710
711 /* There is no sectors in root directory. */
712 temp = ram_disk.fx_media_root_sectors;
713 ram_disk.fx_media_root_sectors = 0;
714 status = fx_unicode_directory_create( &ram_disk, long_unicode_name, length, destination_name);
715 ram_disk.fx_media_root_sectors = temp;
716 return_if_fail( status == FX_FILE_CORRUPT);
717
718 status = fx_file_close( &my_file);
719 return_if_fail( status == FX_SUCCESS);
720
721 status = fx_file_create( &ram_disk, "config.h");
722 status += fx_file_open( &ram_disk, &my_file, "config.h", FX_OPEN_FOR_WRITE);
723 status += fx_file_write( &my_file, read_buffer, 2048 * 2);
724 status += fx_file_seek( &my_file, 2047);
725
726 /* Make an IO error in fx_file_read while calling _fx_utility_FAT_entry_read. */
727 _fx_utility_fat_entry_read_error_request = 1;
728 status += fx_file_read( &my_file, read_buffer, 10, &actual);
729 return_if_fail( status == FX_IO_ERROR);
730
731 status = fx_media_close( &ram_disk);
732 return_if_fail( status == FX_SUCCESS);
733
734 /* Format the media. This needs to be done before opening it! */
735 status = fx_media_format(&ram_disk,
736 _fx_ram_driver, // Driver entry
737 ram_disk_memory, // RAM disk memory pointer
738 cache_buffer, // Media buffer pointer
739 CACHE_SIZE, // Media buffer size
740 "MY_RAM_DISK", // Volume Name
741 1, // Number of FATs
742 32, // Directory Entries
743 0, // Hidden sectors
744 4200 * 8, // Total sectors - FAT32
745 256, // Sector size
746 8, // Sectors per cluster
747 1, // Heads
748 1); // Sectors per track
749 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
750 return_if_fail( status == FX_SUCCESS);
751
752 length = fx_unicode_length_get( unicode_name_14);
753 for ( UINT i = 0; i < 2; i++)
754 {
755 status = fx_unicode_file_create( &ram_disk, unicode_name_14, length, destination_name);
756 return_if_fail( status == FX_SUCCESS);
757 unicode_name_14[0]++;
758 }
759
760 /* Make an IO error in fx_unicode_directory_entry_change while calling _fx_utility_logical_sector_write. */
761 _fx_utility_logical_sector_write_error_request = 6;
762 length = fx_unicode_length_get( unicode_name_14);
763 status = fx_unicode_file_create( &ram_disk, unicode_name_14, length, destination_name);
764 unicode_name_14[0]++;
765 return_if_fail( status == FX_IO_ERROR);
766
767 length = fx_unicode_length_get( unicode_name_14);
768 for ( UINT i = 0; i < 2; i++)
769 {
770 status = fx_unicode_file_create( &ram_disk, unicode_name_14, length, destination_name);
771 return_if_fail( status == FX_SUCCESS);
772 unicode_name_14[0]++;
773 }
774
775 /* Make an IO error in fx_unicode_directory_entry_change while reading next logical sector. */
776 _fx_utility_logical_sector_read_error_request = 38;
777 status = fx_unicode_file_create( &ram_disk, unicode_name_14, length, destination_name);
778 return_if_fail( status == FX_IO_ERROR);
779 unicode_name_14[0]++;
780
781 status = fx_media_close( &ram_disk);
782 return_if_fail( status == FX_SUCCESS);
783
784 /* Format the media. This needs to be done before opening it! */
785 status = fx_media_format(&ram_disk,
786 _fx_ram_driver, // Driver entry
787 ram_disk_memory, // RAM disk memory pointer
788 cache_buffer, // Media buffer pointer
789 CACHE_SIZE, // Media buffer size
790 "MY_RAM_DISK", // Volume Name
791 1, // Number of FATs
792 32, // Directory Entries
793 0, // Hidden sectors
794 4200 * 8, // Total sectors - FAT32
795 256, // Sector size
796 8, // Sectors per cluster
797 1, // Heads
798 1); // Sectors per track
799 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
800 return_if_fail( status == FX_SUCCESS);
801
802 /* Enable fault tolerant. */
803 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
804 return_if_fail( status == FX_SUCCESS);
805
806 status = fx_file_create( &ram_disk, "src");
807 status += fx_file_open( &ram_disk, &my_file, "src", FX_OPEN_FOR_WRITE);
808 status += fx_file_allocate( &my_file, 2048 * 2);
809 status += fx_file_seek( &my_file, 2047);
810 return_if_fail( status == FX_SUCCESS);
811
812 /* Make an IO error in _fx_fault_tolerant_cleanup_FAT_chain while calling _fx_utility_FAT_entry_write. */
813 _fx_utility_fat_entry_write_error_request = 3;
814 status += fx_file_write( &my_file, "hello", 5);
815 status += fx_file_close( &my_file);
816 return_if_fail( status == FX_IO_ERROR);
817
818 status = fx_file_create( &ram_disk, "world");
819 status += fx_file_open( &ram_disk, &my_file, "world", FX_OPEN_FOR_WRITE);
820 return_if_fail( status == FX_SUCCESS);
821
822 /* Make IO error in _fx_fault_tolerant_transaction_end while flushing first cluster. */
823 _fx_ram_driver_io_error_request = 5;
824 status = fx_file_write( &my_file, "hello", 5);
825 return_if_fail( status == FX_IO_ERROR);
826
827 status = fx_file_close( &my_file);
828 return_if_fail( status == FX_SUCCESS);
829
830 #ifndef FX_DISABLE_CACHE
831 /* Make IO error in _fx_fault_tolerant_transaction_end while writing back log file. */
832 _fx_ram_driver_io_error_request = 11;
833 status = fx_directory_create( &ram_disk, "dev");
834 return_if_fail( status == FX_IO_ERROR);
835 #endif
836
837 status = fx_media_close( &ram_disk);
838 return_if_fail( status == FX_SUCCESS);
839
840 /* Format the media. This needs to be done before opening it! */
841 status = fx_media_format(&ram_disk,
842 _fx_ram_driver, // Driver entry
843 ram_disk_memory, // RAM disk memory pointer
844 cache_buffer, // Media buffer pointer
845 CACHE_SIZE, // Media buffer size
846 "MY_RAM_DISK", // Volume Name
847 1, // Number of FATs
848 32, // Directory Entries
849 0, // Hidden sectors
850 4200 * 8, // Total sectors - FAT32
851 256, // Sector size
852 8, // Sectors per cluster
853 1, // Heads
854 1); // Sectors per track
855 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
856 return_if_fail( status == FX_SUCCESS);
857
858 /* Enable fault tolerant. */
859 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
860 return_if_fail( status == FX_SUCCESS);
861
862 status = fx_file_create( &ram_disk, "test.txt");
863 status += fx_file_open( &ram_disk, &my_file, "test.txt", FX_OPEN_FOR_WRITE);
864 status += fx_file_extended_best_effort_allocate( &my_file, 2048 * 4, &actual_64);
865
866 /* Attempt to cover the branch in _fx_file_write which needs file_ptr -> fx_file_current_relative_cluster < file_ptr -> fx_file_consecutive_cluster. */
867 /* Current offset is in the cluster in the middle of some consecutive cluster at the head of file. */
868 status = fx_file_seek( &my_file, 2048 + 20);
869 status += fx_file_write( &my_file, "hello", 5);
870 return_if_fail( status == FX_SUCCESS);
871
872 status = fx_file_close( &my_file);
873 return_if_fail( status == FX_SUCCESS);
874
875 status = fx_file_create( &ram_disk, "test2.txt");
876 status += fx_file_open( &ram_disk, &my_file, "test2.txt", FX_OPEN_FOR_WRITE);
877 status += fx_file_extended_best_effort_allocate( &my_file, 2048 * 4, &actual_64);
878 return_if_fail( status == FX_SUCCESS);
879
880 status = fx_file_close( &my_file);
881 return_if_fail( status == FX_SUCCESS);
882
883 /* Covered the branch in fx_file_write.c while adding dir log. */
884 ram_disk.fx_media_fault_tolerant_state |= FX_FAULT_TOLERANT_STATE_STARTED;
885 dir_entry.fx_dir_entry_long_name_present = 0;
886 dir_entry.fx_dir_entry_short_name[0] = 'A';
887 dir_entry.fx_dir_entry_short_name[1] = 0;
888 dir_entry.fx_dir_entry_name = (CHAR *)buffer;
889 dir_entry.fx_dir_entry_name[0] = 'A';
890 dir_entry.fx_dir_entry_name[1] = 0;
891 dir_entry.fx_dir_entry_byte_offset = 512;
892 dir_entry.fx_dir_entry_log_sector = ram_disk.fx_media_data_sector_start + 1;
893 dir_entry.fx_dir_entry_long_name_shorted = 1;
894 _fx_directory_entry_write( &ram_disk, &dir_entry);
895
896 status += fx_media_close( &ram_disk);
897 return_if_fail( status == FX_SUCCESS);
898
899 /* Format the media. This needs to be done before opening it! */
900 status = fx_media_format(&ram_disk,
901 _fx_ram_driver, // Driver entry
902 ram_disk_memory, // RAM disk memory pointer
903 cache_buffer, // Media buffer pointer
904 CACHE_SIZE, // Media buffer size
905 "MY_RAM_DISK", // Volume Name
906 1, // Number of FATs
907 32, // Directory Entries
908 0, // Hidden sectors
909 70000, // Total sectors - FAT32
910 128, // Sector size
911 1, // Sectors per cluster
912 1, // Heads
913 1); // Sectors per track
914 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
915 return_if_fail( status == FX_SUCCESS);
916
917 status = fx_media_read( &ram_disk, 1, (VOID *)read_buffer);
918 return_if_fail( status == FX_SUCCESS);
919
920 /* Format the disk as FAT32 and assign the FAT entry of root cluster as itself. */
921 read_buffer[8] = 2;
922 read_buffer[9] = 0;
923 read_buffer[10] = 0;
924 read_buffer[11] = 0;
925 status = fx_media_write( &ram_disk, 1, (VOID *)read_buffer);
926 return_if_fail( status == FX_SUCCESS);
927
928 status = fx_media_close( &ram_disk);
929 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
930 return_if_fail( status == FX_FAT_READ_ERROR);
931
932 /* Format the media. This needs to be done before opening it! */
933 status = fx_media_format(&ram_disk,
934 _fx_ram_driver, // Driver entry
935 ram_disk_memory, // RAM disk memory pointer
936 cache_buffer, // Media buffer pointer
937 CACHE_SIZE, // Media buffer size
938 "MY_RAM_DISK", // Volume Name
939 1, // Number of FATs
940 32, // Directory Entries
941 0, // Hidden sectors
942 4200 * 8, // Total sectors
943 256, // Sector size
944 8, // Sectors per cluster
945 1, // Heads
946 1); // Sectors per track
947 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
948 return_if_fail( status == FX_SUCCESS);
949
950 /* Enable fault tolerant. */
951 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
952 return_if_fail( status == FX_SUCCESS);
953
954 status = fx_file_create( &ram_disk, "test");
955 status += fx_file_open( &ram_disk, &my_file, "test", FX_OPEN_FOR_WRITE);
956 status += fx_file_allocate( &my_file, 2048 * 6);
957 status += fx_file_seek( &my_file, 1);
958
959 /* Make a mistake(cluster < FX_FAT_ENTRY_START) while looping the link of FAT to find the previous cluster of copy_head_cluster. */
960 ram_disk.fx_media_fat_cache[12].fx_fat_cache_entry_cluster = 3;
961 ram_disk.fx_media_fat_cache[12].fx_fat_cache_entry_value = 1;
962 status = fx_file_write( &my_file, read_buffer, 2048 * 3);
963
964 status = fx_media_close( &ram_disk);
965 return_if_fail( status == FX_SUCCESS);
966
967 /* Format the media. This needs to be done before opening it! */
968 status = fx_media_format(&ram_disk,
969 _fx_ram_driver, // Driver entry
970 ram_disk_memory, // RAM disk memory pointer
971 cache_buffer, // Media buffer pointer
972 CACHE_SIZE, // Media buffer size
973 "MY_RAM_DISK", // Volume Name
974 1, // Number of FATs
975 32, // Directory Entries
976 0, // Hidden sectors
977 4200 * 8, // Total sectors
978 256, // Sector size
979 8, // Sectors per cluster
980 1, // Heads
981 1); // Sectors per track
982 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
983 return_if_fail( status == FX_SUCCESS);
984
985 /* Enable fault tolerant. */
986 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
987 return_if_fail( status == FX_SUCCESS);
988
989 status = fx_file_create( &ram_disk, "test");
990 status += fx_file_open( &ram_disk, &my_file, "test", FX_OPEN_FOR_WRITE);
991 status += fx_file_allocate( &my_file, 2048 * 6);
992 status += fx_file_seek( &my_file, 1);
993
994 /* Make a mistake(cluster > media_ptr -> fx_media_fat_reserved) while looping the link of FAT to find the previous cluster of copy_head_cluster. */
995 ram_disk.fx_media_fat_cache[12].fx_fat_cache_entry_cluster = 3;
996 ram_disk.fx_media_fat_cache[12].fx_fat_cache_entry_value = ram_disk.fx_media_fat_reserved + 1;
997 status = fx_file_write( &my_file, read_buffer, 2048 * 3);
998
999 /* Make an IO error in fx_file_rename while calling _fx_directory_entry_write. */
1000 _fx_utility_logical_sector_read_error_request = 24;
1001 status = fx_file_create( &ram_disk, "test1");
1002 status += fx_file_rename( &ram_disk, "test1", "test2");
1003 return_if_fail( status == FX_IO_ERROR);
1004
1005 status = fx_media_close( &ram_disk);
1006 return_if_fail( status == FX_SUCCESS);
1007
1008 /* Format a FAT32 disk with 512 bytes sector. */
1009 status = fx_media_format(&ram_disk,
1010 _fx_ram_driver, // Driver entry
1011 ram_disk_memory, // RAM disk memory pointer
1012 cache_buffer, // Media buffer pointer
1013 CACHE_SIZE, // Media buffer size
1014 "MY_RAM_DISK", // Volume Name
1015 1, // Number of FATs
1016 32, // Directory Entries
1017 0, // Hidden sectors
1018 70000 * 8, // Total sectors
1019 512, // Sector size
1020 8, // Sectors per cluster
1021 1, // Heads
1022 1); // Sectors per track
1023 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1024 return_if_fail( status == FX_SUCCESS);
1025
1026 /* Make an IO error while reading FAT chain. */
1027 _fx_ram_driver_io_error_request = 1;
1028 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
1029 _fx_ram_driver_io_error_request = 0;
1030 return_if_fail( status == FX_FAT_READ_ERROR);
1031
1032 status = fx_media_close( &ram_disk);
1033 return_if_fail( status == FX_SUCCESS);
1034
1035 /* Format a FAT16 disk with 512 bytes sector. */
1036 status = fx_media_format(&ram_disk,
1037 _fx_ram_driver, // Driver entry
1038 ram_disk_memory, // RAM disk memory pointer
1039 cache_buffer, // Media buffer pointer
1040 CACHE_SIZE, // Media buffer size
1041 "MY_RAM_DISK", // Volume Name
1042 1, // Number of FATs
1043 32, // Directory Entries
1044 0, // Hidden sectors
1045 70000 * 8, // Total sectors
1046 512, // Sector size
1047 8, // Sectors per cluster
1048 1, // Heads
1049 1); // Sectors per track
1050 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
1051 return_if_fail( status == FX_SUCCESS);
1052
1053 /* Make an IO error while reading FAT chain. */
1054 ram_disk.fx_media_cluster_search_start = 0;
1055 status = fx_fault_tolerant_enable( &ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
1056 return_if_fail( status == FX_SUCCESS);
1057
1058 status = fx_media_close( &ram_disk);
1059 return_if_fail( status == FX_SUCCESS);
1060
1061 /* Output successful. */
1062 printf("SUCCESS!\n");
1063 test_control_return(0);
1064 }
1065
1066 #else
1067
1068 #ifdef CTEST
test_application_define(void * first_unused_memory)1069 void test_application_define(void *first_unused_memory)
1070 #else
1071 void filex_fault_tolerant_enable_3_test_application_define(void *first_unused_memory)
1072 #endif
1073 {
1074
1075 FX_PARAMETER_NOT_USED(first_unused_memory);
1076
1077 /* Print out some test information banners. */
1078 printf("FileX Test: Fault Tolerant Enable 3 Test...........................N/A\n");
1079
1080 test_control_return(255);
1081 }
1082 #endif
1083