1 /* This FileX test concentrates on the file create/delete operations. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include "fx_fault_tolerant.h"
8 #include "fx_media.h"
9 #include "fx_ram_driver_test.h"
10 #include "fx_utility.h"
11 #include <stdio.h>
12
13 #define DEMO_STACK_SIZE 8192
14 #define CACHE_SIZE 16*128
15 #ifdef FX_ENABLE_FAULT_TOLERANT
16 #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
17 #else
18 #define FAULT_TOLERANT_SIZE 0
19 #endif
20
21
22 /* Define the ThreadX and FileX object control blocks... */
23
24 #ifndef FX_STANDALONE_ENABLE
25 static TX_THREAD ftest_0;
26 #endif
27 static FX_MEDIA ram_disk;
28 static FX_FILE file_1;
29 static FX_FILE file_2;
30 static FX_FILE file_3;
31 static FX_FILE file_4;
32 static FX_FILE file_5;
33 static FX_FILE file_6;
34 static FX_FILE file_7;
35
36
37
38 /* Define the counters used in the test application... */
39
40 #ifndef FX_STANDALONE_ENABLE
41 static UCHAR *ram_disk_memory;
42 static UCHAR *cache_buffer;
43 static UCHAR *fault_tolerant_buffer;
44 #else
45 static UCHAR cache_buffer[CACHE_SIZE];
46 static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
47 #endif
48 static UCHAR fat_buffer[128];
49 static UCHAR name_buffer[FX_MAX_LONG_NAME_LEN+1];
50
51
52 /* Define thread prototypes. */
53
54 void filex_file_create_delete_application_define(void *first_unused_memory);
55 static void ftest_0_entry(ULONG thread_input);
56
57 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
58 void test_control_return(UINT status);
59
60
61
62 /* Define what the initial system looks like. */
63
64 #ifdef CTEST
test_application_define(void * first_unused_memory)65 void test_application_define(void *first_unused_memory)
66 #else
67 void filex_file_create_delete_application_define(void *first_unused_memory)
68 #endif
69 {
70
71 #ifndef FX_STANDALONE_ENABLE
72 UCHAR *pointer;
73
74
75 /* Setup the working pointer. */
76 pointer = (UCHAR *) first_unused_memory;
77
78 /* Create the main thread. */
79 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
80 pointer, DEMO_STACK_SIZE,
81 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
82
83 pointer = pointer + DEMO_STACK_SIZE;
84
85 /* Setup memory for the RAM disk and the sector cache. */
86 cache_buffer = pointer;
87 pointer = pointer + CACHE_SIZE;
88 fault_tolerant_buffer = pointer;
89 pointer += FAULT_TOLERANT_SIZE;
90 ram_disk_memory = pointer;
91
92 #endif
93
94 /* Initialize the FileX system. */
95 fx_system_initialize();
96 #ifdef FX_STANDALONE_ENABLE
97 ftest_0_entry(0);
98 #endif
99 }
100
101
102 /* Define the test threads. */
103
ftest_0_entry(ULONG thread_input)104 static void ftest_0_entry(ULONG thread_input)
105 {
106
107 UINT status;
108 UCHAR buffer[30];
109 ULONG actual;
110 ULONG64 actual64;
111 UINT i;
112 ULONG64 temp;
113 UINT temp_attr;
114
115 FX_PARAMETER_NOT_USED(thread_input);
116
117 /* Print out some test information banners. */
118 printf("FileX Test: File create/delete test................................");
119
120 /* Format the media. 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, // 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 512, // Total sectors
131 256, // Sector size
132 8, // Sectors per cluster
133 1, // Heads
134 1); // Sectors per track
135 return_if_fail( status == FX_SUCCESS);
136
137 /* Attempt to invalidate the media cache before the media is opened to generate an error */
138 status = fx_media_cache_invalidate(&ram_disk);
139 return_if_fail( status == FX_MEDIA_NOT_OPEN);
140
141 /* Attempt to get space available information before the media is opened to generate an error */
142 status = fx_media_extended_space_available(&ram_disk, &temp);
143 return_if_fail( status == FX_MEDIA_NOT_OPEN);
144
145 /* Attempt to allocate space before the media is opened to generate an error */
146 status = fx_file_extended_allocate(&file_1, 0);
147 return_if_fail( status == FX_NOT_OPEN);
148
149 /* Attempt to allocate space before the media is opened to generate an error */
150 status = fx_file_extended_best_effort_allocate(&file_1, 0, &temp);
151 return_if_fail( status == FX_NOT_OPEN);
152
153 /* try to create a file before the media has been opened to generate an error */
154 status = fx_file_create(&ram_disk, "asdf");
155 return_if_fail( status == FX_MEDIA_NOT_OPEN);
156
157 /* try to close a file before the file has been opened to generate an error */
158 status = fx_file_close(&file_1);
159 return_if_fail( status == FX_NOT_OPEN);
160
161 /* try to delete a file before the media has been opened to generate an error */
162 status = fx_file_delete(&ram_disk, "asdf");
163 return_if_fail( status == FX_MEDIA_NOT_OPEN);
164
165 /* this will be caught by _fxe_file_open instead of _fx_file_open if DISABLE_ERROR_CHECKING is not defined */
166 /* Attempt to open a file before the media has been opened to generate an error */
167 status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_WRITE);
168 return_if_fail( (status == FX_MEDIA_NOT_OPEN) || (status == FX_PTR_ERROR));
169
170 /* Open the ram_disk. */
171 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
172 return_if_fail( status == FX_SUCCESS);
173
174 #ifdef FX_ENABLE_FAULT_TOLERANT
175 /* Enable fault tolerant if FX_ENABLE_FAULT_TOLERANT is defined. */
176 status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
177 return_if_fail( status == FX_SUCCESS);
178 #endif
179
180 /* try to create a file with an illegal name to generate an error */
181 status = fx_file_create(&ram_disk, "");
182 return_if_fail( status == FX_INVALID_NAME);
183
184 /* try to create a file with an illegal path to generate an error */
185 status = fx_file_create(&ram_disk, "/subdir/root");
186 return_if_fail( status == FX_INVALID_PATH);
187
188 /* Simple 8.3 rename in the root directory. */
189 status = fx_directory_create(&ram_disk, "subdir");
190 status += fx_file_create(&ram_disk, "rootname");
191 status += fx_file_create(&ram_disk, "rootname1");
192 status += fx_file_create(&ram_disk, "rootname2");
193 status += fx_file_create(&ram_disk, "/subdir/rootname");
194 status += fx_file_create(&ram_disk, "/subdir/rootname1");
195 return_if_fail( status == FX_SUCCESS);
196
197 /* Attempt to open a file that is not a file to generate an error */
198 status = fx_file_open(&ram_disk, &file_5, "subdir", FX_OPEN_FOR_WRITE);
199 return_if_fail( status == FX_NOT_A_FILE);
200
201 /* try to create and delete a file when the media is write protected to generate an error */
202 ram_disk.fx_media_driver_write_protect = FX_TRUE;
203 status = fx_file_create(&ram_disk, "asdf");
204 return_if_fail( status == FX_WRITE_PROTECT);
205
206 status = fx_file_delete(&ram_disk, "rootname");
207 return_if_fail( status == FX_WRITE_PROTECT);
208
209 /* Attempt to open a file while the media is write protected to generate an error */
210 status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_WRITE);
211 return_if_fail( status == FX_WRITE_PROTECT);
212 ram_disk.fx_media_driver_write_protect = FX_FALSE;
213
214 /* Attempt to create the same file again. This should cause an error! */
215 status = fx_file_create(&ram_disk, "rootname");
216 return_if_fail( status == FX_ALREADY_CREATED);
217
218 /* attempt to open a file with an invalid open type to generate an error */
219 /* This code is executing differently on local vs server. Disabled until cause is explored
220 status = fx_file_open(&ram_disk, &file_5, "rootname2", 3);
221 return_if_fail( status == FX_ACCESS_ERROR);
222 */
223
224 /* try to delete a file in a directory that is read only */
225 status = fx_file_attributes_read(&ram_disk, "rootname2", &temp_attr);
226 status += fx_file_attributes_set(&ram_disk, "rootname2", FX_READ_ONLY);
227 status += fx_file_delete(&ram_disk, "rootname2");
228 status += fx_file_attributes_set(&ram_disk, "rootname2", temp_attr);
229 return_if_fail( status == FX_WRITE_PROTECT);
230
231 /* Open all the files. */
232 status = fx_file_open(&ram_disk, &file_1, "rootname", FX_OPEN_FOR_WRITE);
233 status += fx_file_open(&ram_disk, &file_2, "rootname1", FX_OPEN_FOR_WRITE);
234 status += fx_file_open(&ram_disk, &file_3, "/subdir/rootname", FX_OPEN_FOR_WRITE);
235 status += fx_file_open(&ram_disk, &file_4, "/subdir/rootname1", FX_OPEN_FOR_WRITE);
236 status += fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_READ);
237 return_if_fail( status == FX_SUCCESS);
238
239 /* attempt to open a file that is already open */
240 status = fx_file_open(&ram_disk, &file_6, "rootname", FX_OPEN_FOR_WRITE);
241 return_if_fail( status == FX_ACCESS_ERROR);
242
243 /* try to create and delete a file when the media is write protected to generate an error */
244 ram_disk.fx_media_driver_write_protect = FX_TRUE;
245 status = fx_file_create(&ram_disk, "asdf");
246 return_if_fail( status == FX_WRITE_PROTECT);
247 status = fx_file_delete(&ram_disk, "asdf");
248 return_if_fail( status == FX_WRITE_PROTECT);
249
250 /* Attempt to allocate space while the media is write protected to generate an error */
251 status = fx_file_extended_allocate(&file_1, 1);
252 return_if_fail( status == FX_WRITE_PROTECT);
253 status = fx_file_extended_best_effort_allocate(&file_1, 1, &temp);
254 return_if_fail( status == FX_WRITE_PROTECT);
255 ram_disk.fx_media_driver_write_protect = FX_FALSE;
256
257 /* test the error checking */
258 #ifndef FX_DISABLE_ERROR_CHECKING
259
260 /* send a null pointer to generate an error */
261 status = fx_media_extended_space_available(FX_NULL, FX_NULL);
262 return_if_fail( status == FX_PTR_ERROR);
263
264 /* send a null pointer to generate an error */
265 status = fx_file_extended_best_effort_allocate(FX_NULL, 0, FX_NULL);
266
267 /* send null pointer to generate an error */
268 status = fx_file_create(FX_NULL, "rootname");
269 return_if_fail( status == FX_PTR_ERROR);
270
271 /* send null pointer to generate an error */
272 status = fx_file_open(FX_NULL, FX_NULL, "rootname", 0);
273 return_if_fail( status == FX_PTR_ERROR);
274
275 /* attempt to open an already open file to generate an error */
276 status = fx_file_open(&ram_disk, &file_1, "rootname", FX_OPEN_FOR_WRITE);
277 return_if_fail( status == FX_PTR_ERROR);
278
279 /* Attempt to allocate space for a file that is not open to write to generate an error */
280 status = fx_file_open(&ram_disk, &file_5, "rootname2", FX_OPEN_FOR_READ);
281 status = fx_file_extended_allocate(&file_5, 1);
282 return_if_fail( status == FX_ACCESS_ERROR);
283
284 /* Attempt to allocate space for a file that is not open to write to generate an error */
285 status = fx_file_extended_best_effort_allocate(&file_5, 0, &temp);
286 return_if_fail( status == FX_ACCESS_ERROR);
287
288 /* Allocate 0 space for a file */
289 status = fx_file_extended_allocate(&file_1, 0);
290 return_if_fail( status == FX_SUCCESS);
291
292 /* Allocate 0 space for a file */
293 status = fx_file_extended_best_effort_allocate(&file_1, 0, &temp);
294 return_if_fail( status == FX_SUCCESS);
295
296 /* Attempt to allocate too much space for a file */
297 status = fx_file_extended_allocate(&file_1, 0xFFFFFFFFFFFFFFFF);
298 return_if_fail( status == FX_NO_MORE_SPACE);
299
300 /* Corrupt the media. */
301 ram_disk.fx_media_bytes_per_sector = 0;
302 status = fx_file_extended_allocate(&file_1, 1);
303 return_if_fail(status == FX_MEDIA_INVALID);
304
305 status = fx_file_extended_best_effort_allocate(&file_1, 1, &actual64);
306 return_if_fail(status == FX_MEDIA_INVALID);
307
308 ram_disk.fx_media_bytes_per_sector = 256;
309
310 #endif /* FX_DISABLE_ERROR_CHECKING */
311
312 /* try to delete an open file to generate an error */
313 status = fx_file_delete(&ram_disk, "rootname");
314 return_if_fail( status == FX_ACCESS_ERROR);
315
316 /* try to delete something that is not a file to generate an error */
317 status = fx_file_delete(&ram_disk, "subdir");
318 return_if_fail( status == FX_NOT_A_FILE);
319
320 /* Now write a buffer to each file. */
321 status = fx_file_write(&file_1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
322 status += fx_file_write(&file_2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
323 status += fx_file_write(&file_3, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
324 status += fx_file_write(&file_4, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
325 return_if_fail( status == FX_SUCCESS);
326
327 /* Seek to the beginning of each file. */
328 status += fx_file_seek(&file_1, 0);
329 status += fx_file_seek(&file_2, 0);
330 status += fx_file_seek(&file_3, 0);
331 status += fx_file_seek(&file_4, 0);
332 return_if_fail( status == FX_SUCCESS);
333
334 /* Now read the buffer. */
335 status = fx_file_read(&file_1, buffer, 30, &actual);
336 return_if_fail( (status == FX_SUCCESS) && (actual == 26));
337
338 /* Only run this if error checking is enabled */
339 #ifndef FX_DISABLE_ERROR_CHECKING
340 /* send null pointer to generate an error */
341 status = fx_file_read(FX_NULL, buffer, 30, &actual);
342 return_if_fail(status == FX_PTR_ERROR);
343 #endif /* FX_DISABLE_ERROR_CHECKING */
344
345 /* Now read the buffer. */
346 status = fx_file_read(&file_2, buffer, 30, &actual);
347 return_if_fail( (status == FX_SUCCESS) && (actual == 26));
348
349 /* Now read the buffer. */
350 status = fx_file_read(&file_3, buffer, 30, &actual);
351 return_if_fail( (status == FX_SUCCESS) && (actual == 26));
352
353 /* Now read the buffer. */
354 status = fx_file_read(&file_4, buffer, 30, &actual);
355 return_if_fail( (status == FX_SUCCESS) && (actual == 26));
356
357 /* Close all files. */
358 status = fx_file_close(&file_1);
359 status += fx_file_close(&file_2);
360 status += fx_file_close(&file_3);
361 status += fx_file_close(&file_4);
362 status += fx_file_close(&file_5);
363 return_if_fail( status == FX_SUCCESS);
364
365 /* Only run this if error checking is enabled */
366 #ifndef FX_DISABLE_ERROR_CHECKING
367 /* send null pointer to generate an error */
368 status = fx_file_close(FX_NULL);
369 return_if_fail(status == FX_PTR_ERROR);
370
371 /* send null pointer to generate an error */
372 status = fx_file_delete(FX_NULL, "rootname");
373 return_if_fail(status == FX_PTR_ERROR);
374 #endif /* FX_DISABLE_ERROR_CHECKING */
375
376 /* Delete all files. */
377 status = fx_file_delete(&ram_disk, "rootname");
378 status += fx_file_delete(&ram_disk, "rootname1");
379 status += fx_file_delete(&ram_disk, "/subdir/rootname");
380 status += fx_file_delete(&ram_disk, "/subdir/rootname1");
381 status += fx_file_delete(&ram_disk, "rootname2");
382 status += fx_directory_delete(&ram_disk, "/subdir");
383 return_if_fail( status == FX_SUCCESS);
384
385 /* Attempt to delete an already deleted file. */
386 status += fx_file_delete(&ram_disk, "rootname");
387 return_if_fail( status == FX_NOT_FOUND);
388
389 /* Close the media. */
390 status = fx_media_close(&ram_disk);
391 return_if_fail( status == FX_SUCCESS);
392
393 /* Test corner cases in extended best effort allocate. */
394
395 /* Format the media. This needs to be done before opening it! */
396 status = fx_media_format(&ram_disk,
397 _fx_ram_driver, // Driver entry
398 ram_disk_memory, // RAM disk memory pointer
399 cache_buffer, // Media buffer pointer
400 CACHE_SIZE, // Media buffer size
401 "MY_RAM_DISK", // Volume Name
402 1, // Number of FATs
403 32, // Directory Entries
404 0, // Hidden sectors
405 7000, // Total sectors - FAT 16
406 128, // Sector size
407 1, // Sectors per cluster
408 1, // Heads
409 1); // Sectors per track
410 return_if_fail( status == FX_SUCCESS);
411
412 /* Open the ram_disk. */
413 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
414 return_if_fail( status == FX_SUCCESS);
415
416 /* Create a file. */
417 status = fx_file_create(&ram_disk, "TEST.TXT");
418
419 /* Create a secondary file. */
420 status += fx_file_create(&ram_disk, "TEST1.TXT");
421 return_if_fail( status == FX_SUCCESS);
422
423 /* Open the file. */
424 status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
425 status += fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
426 return_if_fail( status == FX_SUCCESS);
427
428 /* Write one cluster of information to the TEST1.TXT file. */
429 status = fx_file_write(&file_5, buffer, 128);
430
431 /* Close the secondary file. */
432 status += fx_file_close(&file_5);
433
434 /* Loop to take up the entire ram disk by writing to this file. */
435 while (ram_disk.fx_media_available_clusters)
436 {
437 /* Write a one cluster block. */
438 status += fx_file_write(&file_6, buffer, 128);
439 }
440 return_if_fail( status == FX_SUCCESS);
441
442 /* Attempt to allocate when there is nothing available. */
443 status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
444 return_if_fail( status == FX_NO_MORE_SPACE);
445
446 /* Now release the first cluster to create a hole at the front. */
447 status = fx_file_delete(&ram_disk, "TEST1.TXT");
448
449 /* Now flush everything out. */
450 fx_media_flush(&ram_disk);
451 _fx_utility_FAT_flush(&ram_disk);
452 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
453 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
454 {
455 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
456 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
457 }
458
459 /* Read the first FAT sector. */
460 status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
461
462 /* Add a FAT entry randomly in the FAT table. */
463 fat_buffer[4] = 0x03;
464 fat_buffer[5] = 0x00;
465
466 /* Write the FAT corruption out. */
467 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
468 return_if_fail( status == FX_SUCCESS);
469
470 /* Attempt to allocate when there is nothing available - with a lost cluster. */
471 status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
472 return_if_fail( status == FX_NO_MORE_SPACE);
473
474 /* Attempt to allocate when there is an I/O error. */
475 _fx_utility_fat_entry_read_error_request = 1;
476 status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
477 _fx_utility_fat_entry_read_error_request = 0;
478 return_if_fail( status == FX_IO_ERROR);
479
480 /* Now flush everything out. */
481 fx_media_flush(&ram_disk);
482 _fx_utility_FAT_flush(&ram_disk);
483 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
484 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
485 {
486 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
487 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
488 }
489
490 /* Read the first FAT sector. */
491 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
492
493 /* Make the first entry available. */
494 fat_buffer[4] = 0x00;
495 fat_buffer[5] = 0x00;
496
497 /* Write the FAT corruption out. */
498 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
499 return_if_fail( status == FX_SUCCESS);
500
501 /* Allocate with an exact fit. */
502 status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
503 return_if_fail( status == FX_SUCCESS);
504
505 /* Release all the clusters for this file. */
506 status = fx_file_extended_truncate_release(&file_6, 0);
507 status += fx_file_write(&file_6, fat_buffer, 128);
508 status += fx_file_write(&file_6, fat_buffer, 128);
509 status += fx_file_write(&file_6, fat_buffer, 128);
510 status += fx_file_write(&file_6, fat_buffer, 128);
511
512 /* Allocate 4 clusters. */
513 status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
514 return_if_fail( status == FX_SUCCESS);
515
516 /* Release all the clusters for this file. */
517 status = fx_file_extended_truncate_release(&file_6, 0);
518
519 /* Allocate 4 clusters with no clusters in the file. */
520 status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
521 return_if_fail( status == FX_SUCCESS);
522
523 /* Write 512 bytes of data out. */
524 status += fx_file_write(&file_6, fat_buffer, 128);
525 status += fx_file_write(&file_6, fat_buffer, 128);
526 status += fx_file_write(&file_6, fat_buffer, 128);
527 status += fx_file_write(&file_6, fat_buffer, 128);
528
529 /* Now allocate perform allocations with I/O errors on building the new FAT chain. */
530 _fx_utility_fat_entry_write_error_request = 1;
531 status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
532 _fx_utility_fat_entry_write_error_request = 0;
533 return_if_fail( status == FX_IO_ERROR);
534
535 /* Now allocate perform allocations with I/O error on writing the EOF. */
536 _fx_utility_fat_entry_write_error_request = 4;
537 status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
538 _fx_utility_fat_entry_write_error_request = 0;
539 return_if_fail( status == FX_IO_ERROR);
540
541 /* Now allocate perform allocations with I/O error on linking to last cluster. */
542 _fx_utility_fat_entry_write_error_request = 5;
543 status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
544 _fx_utility_fat_entry_write_error_request = 0;
545 return_if_fail( status == FX_IO_ERROR);
546
547 /* Release all the clusters for this file. */
548 status = fx_file_extended_truncate_release(&file_6, 0);
549
550 /* Now flush everything out. */
551 fx_media_flush(&ram_disk);
552 _fx_utility_FAT_flush(&ram_disk);
553 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
554 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
555 {
556 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
557 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
558 }
559
560 #ifndef FX_ENABLE_FAULT_TOLERANT
561 /* Now allocate perform allocations with I/O error on the directory write request. */
562 _fx_utility_logical_sector_write_error_request = 1;
563 status = fx_file_extended_best_effort_allocate(&file_6, 128, &actual64);
564 _fx_utility_logical_sector_write_error_request = 0;
565 return_if_fail( status == FX_IO_ERROR);
566 #endif
567
568 /* Close the file and the media. */
569 status = fx_file_close(&file_6);
570 status += fx_media_close(&ram_disk);
571 return_if_fail( status == FX_SUCCESS);
572
573 /* Format the media. This needs to be done before opening it! */
574 status = fx_media_format(&ram_disk,
575 _fx_ram_driver, // Driver entry
576 ram_disk_memory, // RAM disk memory pointer
577 cache_buffer, // Media buffer pointer
578 CACHE_SIZE, // Media buffer size
579 "MY_RAM_DISK", // Volume Name
580 1, // Number of FATs
581 32, // Directory Entries
582 0, // Hidden sectors
583 21000, // Total sectors - FAT 16
584 128, // Sector size
585 3, // Sectors per cluster
586 1, // Heads
587 1); // Sectors per track
588 return_if_fail( status == FX_SUCCESS);
589
590 /* Open the ram_disk. */
591 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
592 return_if_fail( status == FX_SUCCESS);
593
594 /* Create a file. */
595 status = fx_file_create(&ram_disk, "TEST.TXT");
596 return_if_fail( status == FX_SUCCESS);
597
598 /* Open the file. */
599 status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
600 return_if_fail( status == FX_SUCCESS);
601
602 /* Write data to the TEST.TXT file. */
603 status = fx_file_write(&file_6, buffer, 128);
604 status += fx_file_write(&file_6, buffer, 128);
605 status += fx_file_write(&file_6, buffer, 64);
606
607 /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
608 status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
609 return_if_fail( status == FX_SUCCESS);
610
611 /* Truncate the file. */
612 status = fx_file_extended_truncate_release(&file_6, 0);
613
614 /* Write data to the TEST.TXT file. */
615 status += fx_file_write(&file_6, buffer, 128);
616
617 /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
618 status += fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
619 return_if_fail( status == FX_SUCCESS);
620
621 /* Close the file and the media. */
622 status = fx_file_close(&file_6);
623 status += fx_media_close(&ram_disk);
624 return_if_fail( status == FX_SUCCESS);
625
626 /* Test corner cases in extended allocate. */
627
628 /* Format the media. This needs to be done before opening it! */
629 status = fx_media_format(&ram_disk,
630 _fx_ram_driver, // Driver entry
631 ram_disk_memory, // RAM disk memory pointer
632 cache_buffer, // Media buffer pointer
633 CACHE_SIZE, // Media buffer size
634 "MY_RAM_DISK", // Volume Name
635 1, // Number of FATs
636 32, // Directory Entries
637 0, // Hidden sectors
638 7000, // Total sectors - FAT 16
639 128, // Sector size
640 1, // Sectors per cluster
641 1, // Heads
642 1); // Sectors per track
643 return_if_fail( status == FX_SUCCESS);
644
645 /* Open the ram_disk. */
646 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
647 return_if_fail( status == FX_SUCCESS);
648
649 /* Create a file. */
650 status = fx_file_create(&ram_disk, "TEST.TXT");
651
652 /* Create a secondary file. */
653 status += fx_file_create(&ram_disk, "TEST1.TXT");
654 return_if_fail( status == FX_SUCCESS);
655
656 /* Open the file. */
657 status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
658 status = fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
659 return_if_fail( status == FX_SUCCESS);
660
661 /* Write one cluster of information to the TEST1.TXT file. */
662 status = fx_file_write(&file_5, buffer, 128);
663
664 /* Close the secondary file. */
665 status += fx_file_close(&file_5);
666
667 /* Loop to take up the entire ram disk by writing to this file. */
668 while (ram_disk.fx_media_available_clusters)
669 {
670
671 /* Write a one cluster block. */
672 status += fx_file_write(&file_6, buffer, 128);
673 }
674 return_if_fail( status == FX_SUCCESS);
675
676 /* Attempt to allocate when there is nothing available. */
677 status = fx_file_extended_allocate(&file_6, 128);
678 return_if_fail( status == FX_NO_MORE_SPACE);
679
680 /* Now release the first cluster to create a hole at the front. */
681 status = fx_file_delete(&ram_disk, "TEST1.TXT");
682
683 /* Now flush everything out. */
684 fx_media_flush(&ram_disk);
685 _fx_utility_FAT_flush(&ram_disk);
686 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
687 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
688 {
689 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
690 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
691 }
692
693 /* Read the first FAT sector. */
694 status += fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
695
696 /* Add a FAT entry randomly in the FAT table. */
697 fat_buffer[4] = 0x03;
698 fat_buffer[5] = 0x00;
699
700 /* Write the FAT corruption out. */
701 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
702 return_if_fail( status == FX_SUCCESS);
703
704 /* Attempt to allocate when there is nothing available - with a lost cluster. */
705 status = fx_file_extended_allocate(&file_6, 128);
706 return_if_fail( status == FX_NO_MORE_SPACE);
707
708 /* Attempt to allocate when there is an I/O error. */
709 _fx_utility_fat_entry_read_error_request = 1;
710 status = fx_file_extended_allocate(&file_6, 128);
711 _fx_utility_fat_entry_read_error_request = 0;
712 return_if_fail( status == FX_IO_ERROR);
713
714 /* Now flush everything out. */
715 fx_media_flush(&ram_disk);
716 _fx_utility_FAT_flush(&ram_disk);
717 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
718 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
719 {
720 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
721 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
722 }
723
724 /* Read the first FAT sector. */
725 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
726
727 /* Make the first entry available. */
728 fat_buffer[4] = 0x00;
729 fat_buffer[5] = 0x00;
730
731 /* Write the FAT corruption out. */
732 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
733 return_if_fail( status == FX_SUCCESS);
734
735 /* Allocate with an exact fit. */
736 status = fx_file_extended_allocate(&file_6, 128);
737 return_if_fail( status == FX_SUCCESS);
738
739 /* Release all the clusters for this file. */
740 status = fx_file_extended_truncate_release(&file_6, 0);
741 status += fx_file_write(&file_6, fat_buffer, 128);
742 status += fx_file_write(&file_6, fat_buffer, 128);
743 status += fx_file_write(&file_6, fat_buffer, 128);
744 status += fx_file_write(&file_6, fat_buffer, 128);
745
746 /* Allocate 4 clusters. */
747 status += fx_file_extended_allocate(&file_6, 512);
748 return_if_fail( status == FX_SUCCESS);
749
750 /* Release all the clusters for this file. */
751 status = fx_file_extended_truncate_release(&file_6, 0);
752
753 /* Allocate 4 clusters with no clusters in the file. */
754 status += fx_file_extended_allocate(&file_6, 512);
755 return_if_fail( status == FX_SUCCESS);
756
757 /* Write 512 bytes of data out. */
758 status += fx_file_write(&file_6, fat_buffer, 128);
759 status += fx_file_write(&file_6, fat_buffer, 128);
760 status += fx_file_write(&file_6, fat_buffer, 128);
761 status += fx_file_write(&file_6, fat_buffer, 128);
762
763 /* Now allocate perform allocations with I/O errors on building the new FAT chain. */
764 _fx_utility_fat_entry_write_error_request = 1;
765 status += fx_file_extended_allocate(&file_6, 512);
766 _fx_utility_fat_entry_write_error_request = 0;
767 return_if_fail( status == FX_IO_ERROR);
768
769 /* Now allocate perform allocations with I/O error on writing the EOF. */
770 _fx_utility_fat_entry_write_error_request = 4;
771 status = fx_file_extended_allocate(&file_6, 512);
772 _fx_utility_fat_entry_write_error_request = 0;
773 return_if_fail( status == FX_IO_ERROR);
774
775 /* Now allocate perform allocations with I/O error on linking to last cluster. */
776 _fx_utility_fat_entry_write_error_request = 5;
777 status = fx_file_extended_allocate(&file_6, 512);
778 _fx_utility_fat_entry_write_error_request = 0;
779 return_if_fail( status == FX_IO_ERROR);
780
781 /* Release all the clusters for this file. */
782 status = fx_file_extended_truncate_release(&file_6, 0);
783
784 /* Now flush everything out. */
785 fx_media_flush(&ram_disk);
786 _fx_utility_FAT_flush(&ram_disk);
787 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
788 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
789 {
790 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
791 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
792 }
793
794 #ifndef FX_ENABLE_FAULT_TOLERANT
795
796 /* Now allocate perform allocations with I/O error on the directory write request. */
797 _fx_utility_logical_sector_write_error_request = 1;
798 status = fx_file_extended_allocate(&file_6, 128);
799 _fx_utility_logical_sector_write_error_request = 0;
800 return_if_fail( status == FX_IO_ERROR);
801 #endif
802
803 /* Close the file and the media. */
804 status = fx_file_close(&file_6);
805 status += fx_media_close(&ram_disk);
806 return_if_fail( status == FX_SUCCESS);
807
808 /* Format the media. This needs to be done before opening it! */
809 status = fx_media_format(&ram_disk,
810 _fx_ram_driver, // Driver entry
811 ram_disk_memory, // RAM disk memory pointer
812 cache_buffer, // Media buffer pointer
813 CACHE_SIZE, // Media buffer size
814 "MY_RAM_DISK", // Volume Name
815 1, // Number of FATs
816 32, // Directory Entries
817 0, // Hidden sectors
818 21000, // Total sectors - FAT 16
819 128, // Sector size
820 3, // Sectors per cluster
821 1, // Heads
822 1); // Sectors per track
823 return_if_fail( status == FX_SUCCESS);
824
825 /* Open the ram_disk. */
826 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
827 return_if_fail( status == FX_SUCCESS);
828
829 /* Create a file. */
830 status = fx_file_create(&ram_disk, "TEST.TXT");
831 return_if_fail( status == FX_SUCCESS);
832
833 /* Open the file. */
834 status = fx_file_open(&ram_disk, &file_6, "TEST.TXT", FX_OPEN_FOR_WRITE);
835 return_if_fail( status == FX_SUCCESS);
836
837 /* Write one cluster of information to the TEST1.TXT file. */
838 status = fx_file_write(&file_6, buffer, 128);
839 status += fx_file_write(&file_6, buffer, 128);
840 status += fx_file_write(&file_6, buffer, 64);
841
842 /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
843 status = fx_file_extended_allocate(&file_6, 512);
844 return_if_fail( status == FX_SUCCESS);
845
846 /* Truncate the file. */
847 status = fx_file_extended_truncate_release(&file_6, 0);
848
849 /* Write data to the TEST.TXT file. */
850 status += fx_file_write(&file_6, buffer, 128);
851
852 /* Allocate more clusters but with the offset on a sector boundary rather than a cluster boundary. */
853 status += fx_file_extended_allocate(&file_6, 512);
854 return_if_fail( status == FX_SUCCESS);
855
856 /* Now test the maximum allocate size. */
857 actual64 = file_6.fx_file_current_available_size;
858 file_6.fx_file_current_available_size = 0xFFFFFFF8;
859
860 /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
861 status = fx_file_extended_allocate(&file_6, 512);
862 file_6.fx_file_current_available_size = actual64;
863 return_if_fail( status == FX_NO_MORE_SPACE);
864
865 /* Now test the maximum allocate size. */
866 actual64 = file_6.fx_file_current_available_size;
867 file_6.fx_file_current_available_size = 0xFFFFFFFFFFFFFFF8;
868
869 /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
870 status = fx_file_extended_allocate(&file_6, 512);
871 file_6.fx_file_current_available_size = actual64;
872 return_if_fail( status == FX_NO_MORE_SPACE);
873
874 /* Now test the maximum allocate size. */
875 actual64 = file_6.fx_file_current_available_size;
876 file_6.fx_file_current_available_size = 0xFFFFFFF8;
877
878 /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
879 status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
880 file_6.fx_file_current_available_size = actual64;
881 return_if_fail( status == FX_NO_MORE_SPACE);
882
883 /* Now test the maximum allocate size. */
884 actual64 = file_6.fx_file_current_available_size;
885 file_6.fx_file_current_available_size = 0xFFFFFFFFFFFFFFF8;
886
887 /* Allocate more clusters but with the file near maximum size to test the maximum size logic. */
888 status = fx_file_extended_best_effort_allocate(&file_6, 512, &actual64);
889 file_6.fx_file_current_available_size = actual64;
890 return_if_fail( status == FX_NO_MORE_SPACE);
891
892 /* Now test a maximium size allocation. */
893 status = fx_file_extended_best_effort_allocate(&file_6, 0xFFFFFFFFFFFFFFF8ULL, &actual64);
894 return_if_fail( status == FX_NO_MORE_SPACE);
895
896 /* Close the file and the media. */
897 status = fx_file_close(&file_6);
898 status += fx_media_close(&ram_disk);
899 return_if_fail( status == FX_SUCCESS);
900
901 /* Check the corner cases of file delete. */
902
903 /* Format the media. This needs to be done before opening it! */
904 status = fx_media_format(&ram_disk,
905 _fx_ram_driver, // Driver entry
906 ram_disk_memory, // RAM disk memory pointer
907 cache_buffer, // Media buffer pointer
908 CACHE_SIZE, // Media buffer size
909 "MY_RAM_DISK", // Volume Name
910 1, // Number of FATs
911 32, // Directory Entries
912 0, // Hidden sectors
913 7000, // Total sectors - FAT 16
914 128, // Sector size
915 1, // Sectors per cluster
916 1, // Heads
917 1); // Sectors per track
918 return_if_fail( status == FX_SUCCESS);
919
920 /* Open the ram_disk. */
921 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
922 return_if_fail( status == FX_SUCCESS);
923
924 /* Create a set of files. */
925 status = fx_file_create(&ram_disk, "TEST.TXT");
926 status += fx_file_create(&ram_disk, "TEST1.TXT");
927 status += fx_file_create(&ram_disk, "TEST2.TXT");
928 status += fx_file_create(&ram_disk, "TEST3.TXT");
929 status += fx_file_create(&ram_disk, "TEST4.TXT");
930 status += fx_file_create(&ram_disk, "TEST5.TXT");
931 status += fx_file_create(&ram_disk, "TEST6.TXT");
932 status += fx_file_create(&ram_disk, "TEST7.TXT");
933 status += fx_file_create(&ram_disk, "TEST8.TXT");
934 status += fx_file_create(&ram_disk, "TEST9.TXT");
935 status += fx_file_create(&ram_disk, "TEST10.TXT");
936 status += fx_file_create(&ram_disk, "TEST11.TXT");
937 status += fx_file_create(&ram_disk, "TEST12.TXT");
938 status += fx_file_create(&ram_disk, "TEST13.TXT");
939 status += fx_file_create(&ram_disk, "TEST14.TXT");
940 status += fx_file_create(&ram_disk, "TEST15.TXT");
941 status += fx_file_create(&ram_disk, "TEST16.TXT");
942 status += fx_file_create(&ram_disk, "TEST17.TXT");
943 status += fx_file_create(&ram_disk, "TEST18.TXT");
944 status += fx_file_create(&ram_disk, "TEST19.TXT");
945 status += fx_file_create(&ram_disk, "TEST20.TXT");
946 status += fx_file_create(&ram_disk, "TEST21.TXT");
947 status += fx_file_create(&ram_disk, "TEST22.TXT");
948 status += fx_file_create(&ram_disk, "TEST23.TXT");
949 status += fx_file_create(&ram_disk, "TEST24.TXT");
950 status += fx_file_create(&ram_disk, "TEST25.TXT");
951 status += fx_file_create(&ram_disk, "TEST26.TXT");
952 status += fx_file_create(&ram_disk, "TEST27.TXT");
953 status += fx_file_create(&ram_disk, "TEST28.TXT");
954 status += fx_file_create(&ram_disk, "TEST29.TXT");
955 status += fx_file_create(&ram_disk, "TEST30.TXT");
956 return_if_fail( status == FX_SUCCESS);
957
958 /* Open a couple files.... */
959 status = fx_file_open(&ram_disk, &file_4, "TEST.TXT", FX_OPEN_FOR_WRITE);
960 status = fx_file_open(&ram_disk, &file_5, "TEST1.TXT", FX_OPEN_FOR_WRITE);
961 status += fx_file_open(&ram_disk, &file_6, "TEST30.TXT", FX_OPEN_FOR_WRITE);
962 status += fx_file_open(&ram_disk, &file_7, "TEST29.TXT", FX_OPEN_FOR_WRITE);
963 status += fx_file_write(&file_4, fat_buffer, 128);
964 status += fx_file_write(&file_4, fat_buffer, 128);
965 status += fx_file_write(&file_4, fat_buffer, 128);
966 status += fx_file_write(&file_4, fat_buffer, 128);
967 status += fx_file_write(&file_5, fat_buffer, 128);
968 status += fx_file_write(&file_5, fat_buffer, 128);
969 status += fx_file_write(&file_5, fat_buffer, 128);
970 status += fx_file_write(&file_5, fat_buffer, 128);
971 status += fx_file_write(&file_6, fat_buffer, 128);
972 status += fx_file_write(&file_6, fat_buffer, 128);
973 status += fx_file_write(&file_6, fat_buffer, 128);
974 status += fx_file_write(&file_6, fat_buffer, 128);
975 status += fx_file_write(&file_7, fat_buffer, 128);
976 status += fx_file_write(&file_7, fat_buffer, 128);
977 status += fx_file_write(&file_7, fat_buffer, 128);
978 status += fx_file_write(&file_7, fat_buffer, 128);
979 return_if_fail( status == FX_SUCCESS);
980
981 /* Now flush everything out. */
982 fx_media_flush(&ram_disk);
983 _fx_utility_FAT_flush(&ram_disk);
984 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
985 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
986 {
987 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
988 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
989 }
990
991 /* Close TEST.TXT. */
992 status = fx_file_close(&file_4);
993
994 /* Attempt to delete the file, but with open files on a different offset/sector and a write I/O error. */
995 _fx_utility_logical_sector_read_error_request = 2;
996 status += fx_file_delete(&ram_disk, "TEST.TXT");
997 _fx_utility_logical_sector_read_error_request = 0;
998 return_if_fail( status == FX_IO_ERROR);
999
1000 /* Close all the open files. */
1001 status = fx_file_close(&file_5);
1002 status += fx_file_close(&file_6);
1003 status += fx_file_close(&file_7);
1004
1005 /* Now flush everything out. */
1006 fx_media_flush(&ram_disk);
1007 _fx_utility_FAT_flush(&ram_disk);
1008 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
1009 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
1010 {
1011 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
1012 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
1013 }
1014
1015 /* Attempt to delete the file, but with a FAT read error. */
1016 _fx_utility_fat_entry_read_error_request = 1;
1017 status += fx_file_delete(&ram_disk, "TEST1.TXT");
1018 _fx_utility_fat_entry_read_error_request = 0;
1019 return_if_fail( status == FX_IO_ERROR);
1020
1021 /* Now flush everything out. */
1022 fx_media_flush(&ram_disk);
1023 _fx_utility_FAT_flush(&ram_disk);
1024 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
1025 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
1026 {
1027 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
1028 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
1029 }
1030
1031 /* Attempt to delete the file, but with a FAT write error. */
1032 _fx_utility_fat_entry_write_error_request = 1;
1033 status = fx_file_delete(&ram_disk, "TEST30.TXT");
1034 _fx_utility_fat_entry_write_error_request = 0;
1035 return_if_fail( status == FX_IO_ERROR);
1036
1037 /* Now flush everything out. */
1038 fx_media_flush(&ram_disk);
1039 _fx_utility_FAT_flush(&ram_disk);
1040 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
1041 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
1042 {
1043 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
1044 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
1045 }
1046
1047 /* Read the first FAT sector. */
1048 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
1049
1050 /* Make the first entry available. */
1051 fat_buffer[4] = 0x02;
1052 fat_buffer[5] = 0x00;
1053
1054 /* Write the FAT corruption out. */
1055 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
1056 return_if_fail( status == FX_SUCCESS);
1057
1058 /* Attempt to delete the file, but with a bad FAT chain. */
1059 status = fx_file_delete(&ram_disk, "TEST.TXT");
1060 return_if_fail( status == FX_FAT_READ_ERROR);
1061
1062 /* Attempt to delete the file that exceeds the cluster clount (that we modify to be small). */
1063 actual = ram_disk.fx_media_total_clusters;
1064 ram_disk.fx_media_total_clusters = 1;
1065 status = fx_file_delete(&ram_disk, "TEST29.TXT");
1066 ram_disk.fx_media_total_clusters = actual;
1067 return_if_fail( status == FX_FAT_READ_ERROR);
1068
1069 /* Build a long file name, exceeding FX_MAX_LONG_NAME_LEN. */
1070 for (i = 0; i < (FX_MAX_LONG_NAME_LEN+1); i++)
1071 {
1072 name_buffer[i] = 'a';
1073 }
1074 name_buffer[FX_MAX_LONG_NAME_LEN] = 0;
1075
1076 /* Attempt to create a file with this extra long name... this is expected to fail. */
1077 status = fx_file_create(&ram_disk, (CHAR *)name_buffer);
1078 return_if_fail( status == FX_INVALID_NAME);
1079
1080 /* Now open and write to a file so we can test file close I/O error condition. */
1081 status = fx_file_open(&ram_disk, &file_7, "TEST20.TXT", FX_OPEN_FOR_WRITE);
1082 status += fx_file_write(&file_7, fat_buffer, 128);
1083
1084 /* Close the file with an I/O error. */
1085 _fx_utility_logical_sector_read_error_request = 1;
1086 status += fx_file_close(&file_7);
1087 _fx_utility_logical_sector_read_error_request = 0;
1088 return_if_fail( status == FX_IO_ERROR);
1089
1090 /* Now call the best effort allocate with a closed file handle. */
1091 status = fx_file_best_effort_allocate(&file_7, 1, &actual);
1092 return_if_fail( status == FX_NOT_OPEN);
1093
1094 /* Close the media. */
1095 status = fx_media_close(&ram_disk);
1096 return_if_fail( status == FX_SUCCESS);
1097
1098 printf("SUCCESS!\n");
1099 test_control_return(0);
1100 }
1101