1 /* This FileX test concentrates on the basic directory create/delete operations. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include "fx_directory.h"
8 #include "fx_ram_driver_test.h"
9 #include "fx_fault_tolerant.h"
10 #include "fx_utility.h"
11 #include <stdio.h>
12
13 #define DEMO_STACK_SIZE 4096
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 DIR_PATH "MYDIR\\"
23 #define DIR_PATH_SIZE (sizeof(DIR_PATH) - 1)
24
25 /* Define the ThreadX and FileX object control blocks... */
26
27 #ifndef FX_STANDALONE_ENABLE
28 static TX_THREAD ftest_0;
29 #endif
30 static FX_MEDIA ram_disk;
31 static CHAR name[FX_MAX_LONG_NAME_LEN+50];
32 static CHAR volume_name[FX_MAX_LONG_NAME_LEN+1];
33 static FX_FILE file_1;
34 static FX_FILE file_2;
35 static FX_FILE file_3;
36 static FX_FILE file_4;
37 static FX_FILE file_5;
38 static FX_FILE file_6;
39 static FX_FILE file_7;
40 static FX_FILE file_8;
41 static FX_FILE file_9;
42 static FX_FILE file_10;
43 static FX_FILE file_11;
44 static FX_FILE file_12;
45 static FX_FILE file_13;
46 static FX_FILE file_14;
47 static FX_FILE file_15;
48 static FX_FILE file_16;
49 static FX_FILE file_17;
50 static FX_FILE file_18;
51 static FX_FILE file_19;
52 static FX_FILE file_20;
53 static FX_FILE file_21;
54 static FX_FILE file_22;
55 static FX_FILE file_23;
56 static FX_FILE file_24;
57 static FX_FILE file_25;
58 static FX_FILE file_26;
59 static FX_FILE file_27;
60 static FX_FILE file_28;
61 static FX_FILE file_29;
62 static FX_FILE file_30;
63 static FX_FILE file_31;
64 static FX_FILE file_32;
65 static FX_FILE file_33;
66 static FX_FILE file_34;
67 static FX_FILE file_35;
68 static FX_FILE file_36;
69 static FX_FILE file_37;
70 static FX_FILE file_38;
71 static FX_FILE file_39;
72 static FX_FILE file_40;
73 static FX_FILE file_41;
74 static FX_FILE file_42;
75 static FX_FILE file_43;
76 static FX_FILE file_44;
77 static UCHAR buffer[128];
78
79
80 static UCHAR my_unicode_name[] =
81 {0xFF,0xC1, 0xFF,0x00, 0xFF,0x00, 0xFF,0x02,
82 0xFF,0xD6, 0xFF,0xC7, 0xFF,0x00, 0xFF,0xC7,
83 0xFF,0xB9, 0xFF,0x00, 0xFF,0xC7, 0xFF,0xB2,
84 0xFF,0xD6, 0xFF,0xC7, 0xFF,0x00, 0x00,0x00};
85
86 static UCHAR my_unicode_name1[] =
87 {0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
88 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
89 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0xFF,
90 0x00,0xFF, 0x00,0xFF, 0x00,0xFF, 0x00,0x00};
91
92
93
94
95 /* Define the counters used in the test application... */
96
97 #ifndef FX_STANDALONE_ENABLE
98 static UCHAR *ram_disk_memory;
99 static UCHAR *cache_buffer;
100 static UCHAR *fault_tolerant_buffer;
101 #else
102 static UCHAR cache_buffer[CACHE_SIZE];
103 static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
104 #endif
105
106
107 extern ULONG _fx_ram_driver_copy_default_format;
108
109
110 /* Define thread prototypes. */
111
112 void filex_directory_create_delete_application_define(void *first_unused_memory);
113 static void ftest_0_entry(ULONG thread_input);
114
115 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
116 void test_control_return(UINT status);
117
118
119
120
121 /* Define what the initial system looks like. */
122
123 #ifdef CTEST
test_application_define(void * first_unused_memory)124 void test_application_define(void *first_unused_memory)
125 #else
126 void filex_directory_create_delete_application_define(void *first_unused_memory)
127 #endif
128 {
129
130 #ifndef FX_STANDALONE_ENABLE
131 UCHAR *pointer;
132
133
134 /* Setup the working pointer. */
135 pointer = (UCHAR *) first_unused_memory;
136
137 /* Create the main thread. */
138 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
139 pointer, DEMO_STACK_SIZE,
140 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
141
142 pointer = pointer + DEMO_STACK_SIZE;
143
144 /* Setup memory for the RAM disk and the sector cache. */
145 cache_buffer = pointer;
146 pointer = pointer + CACHE_SIZE;
147 fault_tolerant_buffer = pointer;
148 pointer += FAULT_TOLERANT_SIZE;
149 ram_disk_memory = pointer;
150
151 #endif
152
153 /* Initialize the FileX system. */
154 fx_system_initialize();
155 #ifdef FX_STANDALONE_ENABLE
156 ftest_0_entry(0);
157 #endif
158 }
159
160
161
162 /* Define the test threads. */
163
ftest_0_entry(ULONG thread_input)164 static void ftest_0_entry(ULONG thread_input)
165 {
166
167 UINT status;
168 ULONG temp;
169 UINT attributes;
170 UINT i;
171 #ifdef EXTENDED_NAME_MANGLE_TEST
172 UINT j, k, l;
173 #endif
174 CHAR *name_ptr;
175 FX_DIR_ENTRY dir_entry;
176 FX_DIR_ENTRY search_directory;
177
178 FX_PARAMETER_NOT_USED(thread_input);
179
180 /* Print out some test information banners. */
181 printf("FileX Test: Directory create/delete test...........................");
182
183 /* Format the media. This needs to be done before opening it! */
184 status = fx_media_format(&ram_disk,
185 _fx_ram_driver, // Driver entry
186 ram_disk_memory, // RAM disk memory pointer
187 cache_buffer, // Media buffer pointer
188 CACHE_SIZE, // Media buffer size
189 "MY_RAM_DISK", // Volume Name
190 1, // Number of FATs
191 32, // Directory Entries
192 0, // Hidden sectors
193
194 /* We need a larger disk to test the feature of fault tolerant. */
195 #ifdef FX_ENABLE_FAULT_TOLERANT
196 512 * 8, // Total sectors
197 256, // Sector size
198 8, // Sectors per cluster
199 #else
200 512, // Total sectors
201 128, // Sector size
202 1, // Sectors per cluster
203 #endif
204
205 1, // Heads
206 1); // Sectors per track
207 return_if_fail( status == FX_SUCCESS);
208
209 /* Attempt to create a directory before the media is opened to generate an error */
210 status = fx_directory_create(&ram_disk, "/A0");
211 return_if_fail( status == FX_MEDIA_NOT_OPEN);
212
213 /* Attempt to delete a directory before the media is opened to generate an error */
214 status = fx_directory_delete(&ram_disk, "/A0");
215 return_if_fail( status == FX_MEDIA_NOT_OPEN);
216
217 /* Open the ram_disk. */
218 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
219 return_if_fail( status == FX_SUCCESS);
220
221 /* We need a larger disk to test the feature of fault tolerant. */
222 #ifdef FX_ENABLE_FAULT_TOLERANT
223 /* Enable fault tolerant if FX_ENABLE_FAULT_TOLERANT is defined. */
224 status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
225 return_if_fail( status == FX_SUCCESS);
226 #endif
227
228 /* Only run this if error checking is enabled */
229 #ifndef FX_DISABLE_ERROR_CHECKING
230
231 /* send null pointer to directory create to generate an error */
232 status = fx_directory_create(FX_NULL, "/A0");
233 return_if_fail( status == FX_PTR_ERROR);
234
235 /* directory delete */
236 status = fx_directory_delete(FX_NULL, "/A0");
237 return_if_fail( status == FX_PTR_ERROR);
238
239 #endif /* FX_DISABLE_ERROR_CHECKING */
240
241 /* Attempt to create a directory with an invalid name to generate an error */
242 status = fx_directory_create(&ram_disk, "");
243 return_if_fail( status == FX_INVALID_NAME);
244
245 /* Attempt to create a directory with an invalid name to generate an error */
246 status = fx_directory_create(&ram_disk, "/A0/error\\error");
247 return_if_fail( status == FX_INVALID_PATH);
248
249 /* Attempt to create a directory while the media is write protected to generate an error */
250 ram_disk.fx_media_driver_write_protect = FX_TRUE;
251 status = fx_directory_create(&ram_disk, "/A0");
252 return_if_fail( status == FX_WRITE_PROTECT);
253
254 /* try to create a directory while the media is write protected to generate an error */
255 status = fx_directory_delete(&ram_disk, "/A0");
256 return_if_fail( status == FX_WRITE_PROTECT);
257 ram_disk.fx_media_driver_write_protect = FX_FALSE;
258
259 /* Attempt to create a directory when there is no space to generate an error */
260 temp = ram_disk.fx_media_available_clusters;
261 ram_disk.fx_media_available_clusters = 0;
262 status = fx_directory_create(&ram_disk, "/A0");
263 return_if_fail( status == FX_NO_MORE_SPACE);
264 ram_disk.fx_media_available_clusters = temp;
265
266 /* Create a series of directories... */
267 status = fx_directory_create(&ram_disk, "/A0");
268 status += fx_directory_create(&ram_disk, "/B0");
269 status += fx_directory_create(&ram_disk, "/C0");
270 status += fx_directory_create(&ram_disk, "/D0");
271 status += fx_directory_create(&ram_disk, "/E0");
272 status += fx_directory_create(&ram_disk, "/F0");
273 status += fx_directory_create(&ram_disk, "/G0");
274 status += fx_directory_create(&ram_disk, "/H0");
275 status += fx_directory_create(&ram_disk, "/I0");
276 status += fx_file_create(&ram_disk, "not_a_dir");
277 return_if_fail( status == FX_SUCCESS);
278
279 /* Attempt to create the same directory again. */
280 status = fx_directory_create(&ram_disk, "/A0");
281 return_if_fail( status == FX_ALREADY_CREATED);
282
283 /* Create the next level of sub-directories. */
284 status = fx_directory_create(&ram_disk, "/A0/A1");
285 status += fx_directory_create(&ram_disk, "/A0/A2");
286 status += fx_directory_create(&ram_disk, "/A0/A3");
287 status += fx_directory_create(&ram_disk, "/A0/A4");
288 status += fx_directory_create(&ram_disk, "/A0/A5");
289
290 status += fx_directory_create(&ram_disk, "/B0/B1");
291 status += fx_directory_create(&ram_disk, "/B0/B2");
292 status += fx_directory_create(&ram_disk, "/B0/B3");
293 status += fx_directory_create(&ram_disk, "/B0/B4");
294 status += fx_directory_create(&ram_disk, "/B0/B5");
295
296 status += fx_directory_create(&ram_disk, "/C0/C1");
297 status += fx_directory_create(&ram_disk, "/C0/C2");
298 status += fx_directory_create(&ram_disk, "/C0/C3");
299 status += fx_directory_create(&ram_disk, "/C0/C4");
300 status += fx_directory_create(&ram_disk, "/C0/C5");
301
302 status += fx_directory_create(&ram_disk, "/D0/D1");
303 status += fx_directory_create(&ram_disk, "/D0/D2");
304 status += fx_directory_create(&ram_disk, "/D0/D3");
305 status += fx_directory_create(&ram_disk, "/D0/D4");
306 status += fx_directory_create(&ram_disk, "/D0/D5");
307
308 status += fx_directory_create(&ram_disk, "/E0/E1");
309 status += fx_directory_create(&ram_disk, "/E0/E2");
310 status += fx_directory_create(&ram_disk, "/E0/E3");
311 status += fx_directory_create(&ram_disk, "/E0/E4");
312 status += fx_directory_create(&ram_disk, "/E0/E5");
313
314 status += fx_directory_create(&ram_disk, "/F0/F1");
315 status += fx_directory_create(&ram_disk, "/F0/F2");
316 status += fx_directory_create(&ram_disk, "/F0/F3");
317 status += fx_directory_create(&ram_disk, "/F0/F4");
318 status += fx_directory_create(&ram_disk, "/F0/F5");
319
320 status += fx_directory_create(&ram_disk, "/G0/G1");
321 status += fx_directory_create(&ram_disk, "/G0/G2");
322 status += fx_directory_create(&ram_disk, "/G0/G3");
323 status += fx_directory_create(&ram_disk, "/G0/G4");
324 status += fx_directory_create(&ram_disk, "/G0/G5");
325
326 status += fx_directory_create(&ram_disk, "/H0/H1");
327 status += fx_directory_create(&ram_disk, "/H0/H2");
328 status += fx_directory_create(&ram_disk, "/H0/H3");
329 status += fx_directory_create(&ram_disk, "/H0/H4");
330 status += fx_directory_create(&ram_disk, "/H0/H5");
331
332 status += fx_directory_create(&ram_disk, "/I0/I1");
333 status += fx_directory_create(&ram_disk, "/I0/I2");
334 status += fx_directory_create(&ram_disk, "/I0/I3");
335 status += fx_directory_create(&ram_disk, "/I0/I4");
336 status += fx_directory_create(&ram_disk, "/I0/I5");
337 return_if_fail( status == FX_SUCCESS);
338
339 /* Now create the third level of sub-directories... */
340 status = fx_directory_create(&ram_disk, "/A0/A1/A00");
341 status += fx_directory_create(&ram_disk, "/B0/B2/B00");
342 status += fx_directory_create(&ram_disk, "/C0/C3/C00");
343 status += fx_directory_create(&ram_disk, "/D0/D4/D00");
344 status += fx_directory_create(&ram_disk, "/E0/E5/E00");
345 status += fx_directory_create(&ram_disk, "/F0/F1/F00");
346 status += fx_directory_create(&ram_disk, "/G0/G1/G00");
347 status += fx_directory_create(&ram_disk, "/H0/H2/H00");
348 status += fx_directory_create(&ram_disk, "/I0/I3/I00");
349 return_if_fail( status == FX_SUCCESS);
350
351 /* Attempt to delete something that is not a directory */
352 status = fx_directory_delete(&ram_disk, "not_a_dir");
353 return_if_fail( status == FX_NOT_DIRECTORY);
354
355 /* Attempt to delete a directory that is not empty */
356 status = fx_directory_delete(&ram_disk, "/A0");
357 return_if_fail( status == FX_DIR_NOT_EMPTY);
358
359 /* Attempt to delete a directory that is read only */
360 status = fx_directory_attributes_read(&ram_disk, "/A0/A1/A00", &attributes);
361 status += fx_directory_attributes_set(&ram_disk, "/A0/A1/A00", FX_READ_ONLY);
362 status += fx_directory_delete(&ram_disk, "/A0/A1/A00");
363 return_if_fail( status == FX_WRITE_PROTECT);
364 status += fx_directory_attributes_set(&ram_disk, "/A0/A1/A00", attributes);
365
366 /* Now delete all the directories. */
367 status = fx_directory_delete(&ram_disk, "/A0/A1/A00");
368 status += fx_directory_delete(&ram_disk, "/B0/B2/B00");
369 status += fx_directory_delete(&ram_disk, "/C0/C3/C00");
370 status += fx_directory_delete(&ram_disk, "/D0/D4/D00");
371 status += fx_directory_delete(&ram_disk, "/E0/E5/E00");
372 status += fx_directory_delete(&ram_disk, "/F0/F1/F00");
373 status += fx_directory_delete(&ram_disk, "/G0/G1/G00");
374 status += fx_directory_delete(&ram_disk, "/H0/H2/H00");
375 status += fx_directory_delete(&ram_disk, "/I0/I3/I00");
376 return_if_fail( status == FX_SUCCESS);
377
378 /* Delete the next level of sub-directories. */
379 status += fx_directory_delete(&ram_disk, "/A0/A1");
380 status += fx_directory_delete(&ram_disk, "/A0/A2");
381 status += fx_directory_delete(&ram_disk, "/A0/A3");
382 status += fx_directory_delete(&ram_disk, "/A0/A4");
383 status += fx_directory_delete(&ram_disk, "/A0/A5");
384
385 status += fx_directory_delete(&ram_disk, "/B0/B1");
386 status += fx_directory_delete(&ram_disk, "/B0/B2");
387 status += fx_directory_delete(&ram_disk, "/B0/B3");
388 status += fx_directory_delete(&ram_disk, "/B0/B4");
389 status += fx_directory_delete(&ram_disk, "/B0/B5");
390
391 status += fx_directory_delete(&ram_disk, "/C0/C1");
392 status += fx_directory_delete(&ram_disk, "/C0/C2");
393 status += fx_directory_delete(&ram_disk, "/C0/C3");
394 status += fx_directory_delete(&ram_disk, "/C0/C4");
395 status += fx_directory_delete(&ram_disk, "/C0/C5");
396
397 status += fx_directory_delete(&ram_disk, "/D0/D1");
398 status += fx_directory_delete(&ram_disk, "/D0/D2");
399 status += fx_directory_delete(&ram_disk, "/D0/D3");
400 status += fx_directory_delete(&ram_disk, "/D0/D4");
401 status += fx_directory_delete(&ram_disk, "/D0/D5");
402
403 status += fx_directory_delete(&ram_disk, "/E0/E1");
404 status += fx_directory_delete(&ram_disk, "/E0/E2");
405 status += fx_directory_delete(&ram_disk, "/E0/E3");
406 status += fx_directory_delete(&ram_disk, "/E0/E4");
407 status += fx_directory_delete(&ram_disk, "/E0/E5");
408
409 status += fx_directory_delete(&ram_disk, "/F0/F1");
410 status += fx_directory_delete(&ram_disk, "/F0/F2");
411 status += fx_directory_delete(&ram_disk, "/F0/F3");
412 status += fx_directory_delete(&ram_disk, "/F0/F4");
413 status += fx_directory_delete(&ram_disk, "/F0/F5");
414
415 status += fx_directory_delete(&ram_disk, "/G0/G1");
416 status += fx_directory_delete(&ram_disk, "/G0/G2");
417 status += fx_directory_delete(&ram_disk, "/G0/G3");
418 status += fx_directory_delete(&ram_disk, "/G0/G4");
419 status += fx_directory_delete(&ram_disk, "/G0/G5");
420
421 status += fx_directory_delete(&ram_disk, "/H0/H1");
422 status += fx_directory_delete(&ram_disk, "/H0/H2");
423 status += fx_directory_delete(&ram_disk, "/H0/H3");
424 status += fx_directory_delete(&ram_disk, "/H0/H4");
425 status += fx_directory_delete(&ram_disk, "/H0/H5");
426
427 status += fx_directory_delete(&ram_disk, "/I0/I1");
428 status += fx_directory_delete(&ram_disk, "/I0/I2");
429 status += fx_directory_delete(&ram_disk, "/I0/I3");
430 status += fx_directory_delete(&ram_disk, "/I0/I4");
431 status += fx_directory_delete(&ram_disk, "/I0/I5");
432 return_if_fail( status == FX_SUCCESS);
433
434 /* Delete a series of directories... */
435 status = fx_directory_delete(&ram_disk, "/A0");
436 status += fx_directory_delete(&ram_disk, "/B0");
437 status += fx_directory_delete(&ram_disk, "/C0");
438 status += fx_directory_delete(&ram_disk, "/D0");
439 status += fx_directory_delete(&ram_disk, "/E0");
440 status += fx_directory_delete(&ram_disk, "/F0");
441 status += fx_directory_delete(&ram_disk, "/G0");
442 status += fx_directory_delete(&ram_disk, "/H0");
443 status += fx_directory_delete(&ram_disk, "/I0");
444 return_if_fail( status == FX_SUCCESS);
445
446 /* Attempt to delete a directory again. */
447 status = fx_directory_delete(&ram_disk, "/A0");
448 return_if_fail( status == FX_NOT_FOUND);
449
450 /* Close the media. */
451 status = fx_media_close(&ram_disk);
452 return_if_fail( status == FX_SUCCESS);
453
454 /* Format the media. This needs to be done before opening it! */
455 status = fx_media_format(&ram_disk,
456 _fx_ram_driver, // Driver entry
457 ram_disk_memory, // RAM disk memory pointer
458 cache_buffer, // Media buffer pointer
459 CACHE_SIZE, // Media buffer size
460 "MY_RAM_DISK", // Volume Name
461 1, // Number of FATs
462 32, // Directory Entries
463 0, // Hidden sectors
464 4096, // Total sectors
465 128, // Sector size
466 2, // Sectors per cluster
467 1, // Heads
468 1); // Sectors per track
469 return_if_fail( status == FX_SUCCESS);
470
471 /* Open the ram_disk. */
472 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
473 return_if_fail( status == FX_SUCCESS);
474
475 /* Create a directory name that is too large. */
476 for (i = 0; i < FX_MAX_LONG_NAME_LEN+1; i++)
477 {
478
479 name[i] = 'a';
480 }
481 name[FX_MAX_LONG_NAME_LEN + 1] = 0;
482
483 /* Attempt to create a directory with too long of a name. */
484 status = fx_directory_create(&ram_disk, name);
485 return_if_fail( status == FX_INVALID_NAME);
486
487 /* Attempt to create a directory with no more clusters. */
488 temp = ram_disk.fx_media_total_clusters;
489 ram_disk.fx_media_total_clusters = 0;
490 status = fx_directory_create(&ram_disk, "sub1");
491 ram_disk.fx_media_total_clusters = temp;
492 return_if_fail( status == FX_NO_MORE_SPACE);
493
494 /* Attempt to create a directory with a FAT read error. */
495 _fx_utility_fat_entry_read_error_request = 1;
496 status = fx_directory_create(&ram_disk, "sub1");
497 _fx_utility_fat_entry_read_error_request = 0;
498 return_if_fail( status == FX_IO_ERROR);
499
500 /* Create a subdirectory with a search pointer that must wrap after the allocation. */
501 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START - 1);
502 status = fx_directory_create(&ram_disk, "sub1");
503 return_if_fail( status == FX_SUCCESS);
504
505 /* Create a subdirectory with a search pointer that must wrap after the allocation. */
506 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START - 1);
507 status = fx_directory_create(&ram_disk, "sub2");
508 return_if_fail( status == FX_SUCCESS);
509
510 /* Create a subdirectory with a search pointer that starts on a non-free cluster. */
511 ram_disk.fx_media_cluster_search_start = FX_FAT_ENTRY_START;
512 status = fx_directory_create(&ram_disk, "sub3");
513 return_if_fail( status == FX_SUCCESS);
514
515 /* Create a subdirectory with a logical sector read error. */
516 _fx_utility_logical_sector_read_error_request = 13;
517 status = fx_directory_create(&ram_disk, "sub4");
518 _fx_utility_logical_sector_read_error_request = 0;
519 return_if_fail( status == FX_IO_ERROR);
520
521 #ifndef FX_DISABLE_CACHE
522 /* Create a subdirectory with a logical flush error. */
523 _fx_utility_logical_sector_flush_error_request = 1;
524 status = fx_directory_create(&ram_disk, "sub5");
525 _fx_utility_logical_sector_flush_error_request = 0;
526 return_if_fail( status == FX_IO_ERROR);
527 #endif
528
529 /* Create a subdirectory with an error clearing the additional sectors of a cluster. */
530 _fx_ram_driver_io_error_request = 8;
531 status = fx_directory_create(&ram_disk, "sub6");
532 _fx_ram_driver_io_error_request = 0;
533 return_if_fail( status == FX_IO_ERROR);
534
535 /* Create a subdirectory with an error on writing the FAT entry. */
536 _fx_utility_fat_entry_write_error_request = 1;
537 status = fx_directory_create(&ram_disk, "sub7");
538 _fx_utility_fat_entry_write_error_request = 0;
539 return_if_fail( status == FX_IO_ERROR);
540
541 /* Create a subdirectory with an error on writing the first director entry. */
542 _fx_directory_entry_write_error_request = 1;
543 status = fx_directory_create(&ram_disk, "sub8");
544 _fx_directory_entry_write_error_request = 0;
545 return_if_fail( status == FX_IO_ERROR);
546
547 /* Create a subdirectory with an error on writing the second director entry. */
548 _fx_directory_entry_write_error_request = 2;
549 status = fx_directory_create(&ram_disk, "sub9");
550 _fx_directory_entry_write_error_request = 0;
551 return_if_fail( status == FX_IO_ERROR);
552
553 /* Close the media. */
554 status = fx_media_close(&ram_disk);
555 return_if_fail( status == FX_SUCCESS);
556
557 /* Format the media. This needs to be done before opening it! */
558 status = fx_media_format(&ram_disk,
559 _fx_ram_driver, // Driver entry
560 ram_disk_memory, // RAM disk memory pointer
561 cache_buffer, // Media buffer pointer
562 CACHE_SIZE, // Media buffer size
563 "MY_RAM_DISK", // Volume Name
564 1, // Number of FATs
565 32, // Directory Entries
566 0, // Hidden sectors
567 4096, // Total sectors
568 128, // Sector size
569 2, // Sectors per cluster
570 1, // Heads
571 1); // Sectors per track
572 return_if_fail( status == FX_SUCCESS);
573
574 /* Open the ram_disk. */
575 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
576 return_if_fail( status == FX_SUCCESS);
577
578 /* Create a series of sub-directories... in preparation for our directory delete checking. */
579 status = fx_directory_create(&ram_disk, "SUB1");
580 status += fx_directory_create(&ram_disk, "SUB2");
581 status += fx_directory_create(&ram_disk, "SUB3");
582 status += fx_directory_create(&ram_disk, "SUB4");
583 status += fx_directory_create(&ram_disk, "SUB5");
584 status += fx_directory_create(&ram_disk, "SUB6");
585 status += fx_directory_create(&ram_disk, "SUB7");
586 status += fx_directory_create(&ram_disk, "SUB8");
587 return_if_fail( status == FX_SUCCESS);
588
589 /* Delete a directory but with a FAT read error on the first cluster. */
590 _fx_utility_fat_entry_read_error_request = 1;
591 status = fx_directory_delete(&ram_disk, "SUB8");
592 _fx_utility_fat_entry_read_error_request = 0;
593 return_if_fail( status == FX_IO_ERROR);
594
595 /* Delete a directory but with a cluster error - bad small value. */
596 _fx_utility_fat_entry_read_error_request = 10001;
597 status = fx_directory_delete(&ram_disk, "SUB8");
598 _fx_utility_fat_entry_read_error_request = 0;
599 return_if_fail( status == FX_FAT_READ_ERROR);
600
601 /* Delete a directory but with a cluster error - bad total clusters. */
602 temp = ram_disk.fx_media_total_clusters;
603 ram_disk.fx_media_total_clusters = 0;
604 status = fx_directory_delete(&ram_disk, "SUB8");
605 ram_disk.fx_media_total_clusters = temp;
606 return_if_fail( status == FX_FAT_READ_ERROR);
607
608 /* Delete a directory but with a cluster error - same value. */
609 _fx_utility_fat_entry_read_error_request = 30001;
610 status = fx_directory_delete(&ram_disk, "SUB8");
611 _fx_utility_fat_entry_read_error_request = 0;
612 return_if_fail( status == FX_FAT_READ_ERROR);
613
614 /* Delete a directory but with a directory entry read error. */
615 _fx_directory_entry_read_error_request = 1;
616 status = fx_directory_delete(&ram_disk, "SUB8");
617 _fx_directory_entry_read_error_request = 0;
618 return_if_fail( status == FX_IO_ERROR);
619
620 /* Delete a directory but with a directory entry write error. */
621 _fx_directory_entry_write_error_request = 1;
622 status = fx_directory_delete(&ram_disk, "SUB8");
623 _fx_directory_entry_write_error_request = 0;
624 return_if_fail( status == FX_IO_ERROR);
625
626 /* Delete a directory wtih large error request values just to exercise those paths - should be successful. */
627 _fx_directory_entry_read_error_request = 10000;
628 _fx_directory_entry_write_error_request = 10000;
629 status = fx_directory_delete(&ram_disk, "SUB8");
630 _fx_directory_entry_read_error_request = 0;
631 _fx_directory_entry_write_error_request = 0;
632 return_if_fail( status == FX_SUCCESS);
633
634 /* Delete a directory with an error in the freeing of the cluster traversal FAT read. */
635 _fx_utility_fat_entry_read_error_request = 2;
636 status = fx_directory_delete(&ram_disk, "SUB7");
637 _fx_utility_fat_entry_read_error_request = 0;
638 return_if_fail( status == FX_IO_ERROR);
639
640 /* Delete a directory but with a cluster error in releasing cluster - bad small value. */
641 _fx_utility_fat_entry_read_error_request = 10002;
642 status = fx_directory_delete(&ram_disk, "SUB6");
643 _fx_utility_fat_entry_read_error_request = 0;
644 return_if_fail( status == FX_FAT_READ_ERROR);
645
646 /* Delete a directory but with a cluster error in releasing cluster - bad total clusters. */
647 temp = ram_disk.fx_media_total_clusters;
648 _fx_utility_fat_entry_read_error_request = 40002;
649 status = fx_directory_delete(&ram_disk, "SUB5");
650 ram_disk.fx_media_total_clusters = temp;
651 return_if_fail( status == FX_FAT_READ_ERROR);
652
653 /* Delete a directory but with a cluster error in releasing cluster - same value. */
654 _fx_utility_fat_entry_read_error_request = 30002;
655 status = fx_directory_delete(&ram_disk, "SUB4");
656 _fx_utility_fat_entry_read_error_request = 0;
657 return_if_fail( status == FX_FAT_READ_ERROR);
658
659 /* Delete a directory but with a FAT write error in releasing cluster. */
660 _fx_utility_fat_entry_write_error_request = 1;
661 status = fx_directory_delete(&ram_disk, "SUB3");
662 _fx_utility_fat_entry_write_error_request = 0;
663 return_if_fail( status == FX_IO_ERROR);
664
665 /* Close the media. */
666 status = fx_media_close(&ram_disk);
667 return_if_fail( status == FX_SUCCESS);
668
669 /* Format the media. This needs to be done before opening it! */
670 status = fx_media_format(&ram_disk,
671 _fx_ram_driver, // Driver entry
672 ram_disk_memory, // RAM disk memory pointer
673 cache_buffer, // Media buffer pointer
674 CACHE_SIZE, // Media buffer size
675 "MY_RAM_DISK", // Volume Name
676 1, // Number of FATs
677 32, // Directory Entries
678 0, // Hidden sectors
679 14000, // Total sectors
680 128, // Sector size
681 2, // Sectors per cluster
682 1, // Heads
683 1); // Sectors per track
684 return_if_fail( status == FX_SUCCESS);
685
686 /* Open the ram_disk. */
687 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
688 return_if_fail( status == FX_SUCCESS);
689
690 /* Create a sub-directory to work from. */
691 status = fx_directory_create(&ram_disk, "SUB1");
692
693 /* Set the default path here. */
694 status += fx_directory_default_set(&ram_disk, "SUB1");
695
696 /* Now try to create some unusual file name to test the internal free search logic. */
697 status += fx_file_create(&ram_disk, "..test");
698 return_if_fail( status == FX_INVALID_NAME);
699
700 /* Create a name with a character greater than 127. */
701 name[0] = 'n';
702 name[1] = 'a';
703 name[2] = 'm';
704 name[3] = 'e';
705 name[4] = '\'';
706 name[5] = ')';
707 name[6] = '(';
708 name[7] = '`';
709 name[8] = (CHAR) 128;
710 name[9] = 0;
711
712 status = fx_file_create(&ram_disk, name);
713 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
714 return_if_fail( status == FX_SUCCESS);
715
716 /* Create a name with a bunch of special characters. */
717 status = fx_file_create(&ram_disk, "name-a_b}{()'!#$&@^%+,;=[]");
718 status += fx_file_open(&ram_disk, &file_2, "name-a_b}{()'!#$&@^%+,;=[]", FX_OPEN_FOR_WRITE);
719 return_if_fail( status == FX_SUCCESS);
720
721 /* Create a name with an invalid character. */
722 name[0] = 'n';
723 name[1] = 'a';
724 name[2] = 'm';
725 name[3] = 'e';
726 name[4] = (CHAR) 5;
727 name[5] = '\'';
728 name[6] = 0;
729
730 status = fx_file_create(&ram_disk, name);
731 return_if_fail( status == FX_INVALID_NAME);
732
733 /* Create a long file name by position of the dot. */
734 status = fx_file_create(&ram_disk, "MYLONGERN.AM");
735 status += fx_file_create(&ram_disk, "MY.TXT");
736 status += fx_file_open(&ram_disk, &file_3, "MYLONGERN.AM", FX_OPEN_FOR_WRITE);
737 status += fx_file_open(&ram_disk, &file_4, "MY.TXT", FX_OPEN_FOR_WRITE);
738 return_if_fail( status == FX_SUCCESS);
739
740 /* Create a set of very short long file name. */
741 status = fx_file_create(&ram_disk, "n");
742 status += fx_file_create(&ram_disk, "nW");
743 status += fx_file_create(&ram_disk, "nWW");
744 status += fx_file_create(&ram_disk, "nWWW");
745 status += fx_file_create(&ram_disk, "nWWWW");
746 status += fx_file_create(&ram_disk, "nWWWWW");
747 status += fx_file_create(&ram_disk, "nWWWWWW");
748 status += fx_file_create(&ram_disk, "nWWWWWWW");
749 status += fx_file_create(&ram_disk, "nWWWWWWWW");
750 status += fx_file_create(&ram_disk, "nWWWWWWWWW");
751 status += fx_file_create(&ram_disk, "nWWWWWWWWWW");
752 status += fx_file_create(&ram_disk, "nWWWWWWWWWWW");
753 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWW");
754 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWW");
755 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWW");
756 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWW");
757 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWW");
758 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWW");
759 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWW");
760 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWW");
761 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWW");
762 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWW");
763 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWW");
764 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWW");
765 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWW");
766 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWW");
767 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWW");
768 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWW");
769 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
770 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
771 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
772 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
773 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
774 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
775 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
776 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
777 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
778 status += fx_file_create(&ram_disk, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
779 status += fx_file_open(&ram_disk, &file_5, "n", FX_OPEN_FOR_WRITE);
780 status += fx_file_open(&ram_disk, &file_6, "nW", FX_OPEN_FOR_WRITE);
781 status += fx_file_open(&ram_disk, &file_7, "nWW", FX_OPEN_FOR_WRITE);
782 status += fx_file_open(&ram_disk, &file_8, "nWWW", FX_OPEN_FOR_WRITE);
783 status += fx_file_open(&ram_disk, &file_9, "nWWWW", FX_OPEN_FOR_WRITE);
784 status += fx_file_open(&ram_disk, &file_10, "nWWWWW", FX_OPEN_FOR_WRITE);
785 status += fx_file_open(&ram_disk, &file_11, "nWWWWWW", FX_OPEN_FOR_WRITE);
786 status += fx_file_open(&ram_disk, &file_12, "nWWWWWWW", FX_OPEN_FOR_WRITE);
787 status += fx_file_open(&ram_disk, &file_13, "nWWWWWWWW", FX_OPEN_FOR_WRITE);
788 status += fx_file_open(&ram_disk, &file_14, "nWWWWWWWWW", FX_OPEN_FOR_WRITE);
789 status += fx_file_open(&ram_disk, &file_15, "nWWWWWWWWWW", FX_OPEN_FOR_WRITE);
790 status += fx_file_open(&ram_disk, &file_16, "nWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
791 status += fx_file_open(&ram_disk, &file_17, "nWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
792 status += fx_file_open(&ram_disk, &file_18, "nWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
793 status += fx_file_open(&ram_disk, &file_19, "nWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
794 status += fx_file_open(&ram_disk, &file_20, "nWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
795 status += fx_file_open(&ram_disk, &file_21, "nWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
796 status += fx_file_open(&ram_disk, &file_22, "nWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
797 status += fx_file_open(&ram_disk, &file_23, "nWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
798 status += fx_file_open(&ram_disk, &file_24, "nWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
799 status += fx_file_open(&ram_disk, &file_25, "nWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
800 status += fx_file_open(&ram_disk, &file_26, "nWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
801 status += fx_file_open(&ram_disk, &file_27, "nWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
802 status += fx_file_open(&ram_disk, &file_28, "nWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
803 status += fx_file_open(&ram_disk, &file_29, "nWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
804 status += fx_file_open(&ram_disk, &file_30, "nWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
805 status += fx_file_open(&ram_disk, &file_31, "nWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
806 status += fx_file_open(&ram_disk, &file_32, "nWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
807 status += fx_file_open(&ram_disk, &file_33, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
808 status += fx_file_open(&ram_disk, &file_34, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
809 status += fx_file_open(&ram_disk, &file_35, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
810 status += fx_file_open(&ram_disk, &file_36, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
811 status += fx_file_open(&ram_disk, &file_37, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
812 status += fx_file_open(&ram_disk, &file_38, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
813 status += fx_file_open(&ram_disk, &file_39, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
814 status += fx_file_open(&ram_disk, &file_40, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
815 status += fx_file_open(&ram_disk, &file_41, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
816 status += fx_file_open(&ram_disk, &file_42, "nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", FX_OPEN_FOR_WRITE);
817 return_if_fail( status == FX_SUCCESS);
818
819 /* Build a super long file name that will require additional cluster allocation in the sub-directory. */
820 for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
821 {
822 name[i] = 'a';
823 }
824 name[FX_MAX_LONG_NAME_LEN-2] = 0;
825
826 /* Test the wrap of the FAT table by allocating at the end. */
827 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
828 status = fx_file_create(&ram_disk, name);
829 status += fx_file_open(&ram_disk, &file_43, name, FX_OPEN_FOR_WRITE);
830 return_if_fail( status == FX_SUCCESS);
831
832 /* Change the name to create a new file name. */
833 name[FX_MAX_LONG_NAME_LEN-3] = '0';
834
835 /* Test the wrap of the FAT table by allocating at the end. */
836 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
837 status += fx_file_create(&ram_disk, name);
838 status += fx_file_open(&ram_disk, &file_44, name, FX_OPEN_FOR_WRITE);
839 return_if_fail( status == FX_SUCCESS);
840
841 name[FX_MAX_LONG_NAME_LEN-3] = '1';
842
843 /* Now try to allocate an entry with no more available clusters. */
844 temp = ram_disk.fx_media_available_clusters;
845 ram_disk.fx_media_available_clusters = 0;
846 status += fx_file_create(&ram_disk, name);
847 ram_disk.fx_media_available_clusters = temp;
848 return_if_fail( status == FX_NO_MORE_SPACE);
849
850 name[FX_MAX_LONG_NAME_LEN-3] = '2';
851
852 /* Now try to allocate an entry with no more total clusters. */
853 temp = ram_disk.fx_media_total_clusters;
854 _fx_utility_fat_entry_read_error_request = 40064;
855 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
856 status = fx_file_create(&ram_disk, name);
857 _fx_utility_fat_entry_read_error_request = 0;
858 ram_disk.fx_media_total_clusters = temp;
859 return_if_fail( status == FX_NO_MORE_SPACE);
860
861 /* Now try to allocate a new cluster with a FAT read error in fx_directory_free_search. */
862 temp = ram_disk.fx_media_total_clusters;
863 _fx_utility_fat_entry_read_error_request = 65;
864 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
865 status = fx_file_create(&ram_disk, name);
866 _fx_utility_fat_entry_read_error_request = 0;
867 ram_disk.fx_media_total_clusters = temp;
868 return_if_fail( status == FX_IO_ERROR);
869
870 /* Now try to allocate a new cluster with a logical sector read error in fx_directory_free_search. */
871 _fx_utility_logical_sector_read_error_request = 172;
872 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
873 status = fx_file_create(&ram_disk, name);
874 _fx_utility_logical_sector_read_error_request = 0;
875 return_if_fail( status == FX_IO_ERROR);
876
877 #ifndef FX_DISABLE_CACHE
878 /* Now try to allocate a new cluster with a logical sector flush error in fx_directory_free_search. */
879 _fx_utility_logical_sector_flush_error_request = 1;
880 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
881 status = fx_file_create(&ram_disk, name);
882 _fx_utility_logical_sector_flush_error_request = 0;
883 return_if_fail( status == FX_IO_ERROR);
884 #endif
885
886 /* Now try to allocate a new cluster with a write error when clearing additional sector clusters from fx_directory_free_search. */
887 _fx_ram_driver_io_error_request = 91;
888 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
889 status = fx_file_create(&ram_disk, name);
890 _fx_ram_driver_io_error_request = 0;
891 return_if_fail( status == FX_IO_ERROR);
892
893 /* Now try to allocate a new cluster with a write error when writing the FAT link from fx_directory_free_search. */
894 _fx_utility_fat_entry_write_error_request = 1;
895 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
896 status = fx_file_create(&ram_disk, name);
897 _fx_utility_fat_entry_write_error_request = 0;
898 return_if_fail( status == FX_IO_ERROR);
899
900 /* Now try to allocate a new cluster with a write error when writing the EOF FAT link from fx_directory_free_search. */
901 _fx_utility_fat_entry_write_error_request = 3;
902 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
903 status = fx_file_create(&ram_disk, name);
904 _fx_utility_fat_entry_write_error_request = 0;
905 return_if_fail( status == FX_IO_ERROR);
906
907 /* Now try to allocate a new cluster with a logical sector write error when writing the new sub-directory sector in fx_directory_free_search. */
908 _fx_utility_logical_sector_write_error_request = 1;
909 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
910 status = fx_file_create(&ram_disk, name);
911 _fx_utility_logical_sector_write_error_request = 0;
912 return_if_fail( status == FX_IO_ERROR);
913
914 /* Now try to allocate a new cluster with a total cluster of 0 in fx_directory_free_search. */
915 _fx_utility_fat_entry_read_error_request = 92;
916 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
917 status = fx_file_create(&ram_disk, name);
918 _fx_utility_fat_entry_read_error_request = 0;
919 return_if_fail( status == FX_IO_ERROR);
920
921 /* Now try to allocate a new cluster with a bad read value (1) of intial cluster in sub-directory in fx_directory_free_search. */
922 _fx_utility_fat_entry_read_error_request = 10095;
923 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
924 status = fx_file_create(&ram_disk, name);
925 _fx_utility_fat_entry_read_error_request = 0;
926 return_if_fail( status == FX_FAT_READ_ERROR);
927
928 /* Now try to allocate a new cluster with a bad read value (same as initial cluster) of intial cluster in sub-directory in fx_directory_free_search. */
929 _fx_utility_fat_entry_read_error_request = 30098;
930 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
931 status = fx_file_create(&ram_disk, name);
932 _fx_utility_fat_entry_read_error_request = 0;
933 return_if_fail( status == FX_FAT_READ_ERROR);
934
935 /* Now try to allocate a new cluster with a bad read value (greater than max) of intial cluster in sub-directory in fx_directory_free_search. */
936 temp = ram_disk.fx_media_total_clusters;
937 _fx_utility_fat_entry_read_error_request = 40101;
938 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
939 status = fx_file_create(&ram_disk, name);
940 _fx_utility_fat_entry_read_error_request = 0;
941 ram_disk.fx_media_total_clusters = temp;
942 return_if_fail( status == FX_FAT_READ_ERROR);
943
944 /* Now try to allocate a new cluster with an error linking the new cluster chain with the old one in sub-directory in fx_directory_free_search. */
945 _fx_utility_fat_entry_write_error_request = 4;
946 ram_disk.fx_media_cluster_search_start = ram_disk.fx_media_total_clusters + (FX_FAT_ENTRY_START-1);
947 status = fx_file_create(&ram_disk, name);
948 _fx_utility_fat_entry_write_error_request = 0;
949 return_if_fail( status == FX_IO_ERROR);
950
951 /* Now write to each file before we close them. */
952 status = fx_file_write(&file_1, "1", 1);
953 status += fx_file_write(&file_2, "1", 1);
954 status += fx_file_write(&file_3, "1", 1);
955 status += fx_file_write(&file_4, "1", 1);
956 status += fx_file_write(&file_5, "1", 1);
957 status += fx_file_write(&file_6, "1", 1);
958 status += fx_file_write(&file_7, "1", 1);
959 status += fx_file_write(&file_8, "1", 1);
960 status += fx_file_write(&file_9, "1", 1);
961 status += fx_file_write(&file_10, "1", 1);
962 status += fx_file_write(&file_11, "1", 1);
963 status += fx_file_write(&file_12, "1", 1);
964 status += fx_file_write(&file_13, "1", 1);
965 status += fx_file_write(&file_14, "1", 1);
966 status += fx_file_write(&file_15, "1", 1);
967 status += fx_file_write(&file_16, "1", 1);
968 status += fx_file_write(&file_17, "1", 1);
969 status += fx_file_write(&file_18, "1", 1);
970 status += fx_file_write(&file_19, "1", 1);
971 status += fx_file_write(&file_20, "1", 1);
972 status += fx_file_write(&file_21, "1", 1);
973 status += fx_file_write(&file_22, "1", 1);
974 status += fx_file_write(&file_23, "1", 1);
975 status += fx_file_write(&file_24, "1", 1);
976 status += fx_file_write(&file_25, "1", 1);
977 status += fx_file_write(&file_26, "1", 1);
978 status += fx_file_write(&file_27, "1", 1);
979 status += fx_file_write(&file_28, "1", 1);
980 status += fx_file_write(&file_29, "1", 1);
981 status += fx_file_write(&file_30, "1", 1);
982 status += fx_file_write(&file_31, "1", 1);
983 status += fx_file_write(&file_32, "1", 1);
984 status += fx_file_write(&file_33, "1", 1);
985 status += fx_file_write(&file_34, "1", 1);
986 status += fx_file_write(&file_35, "1", 1);
987 status += fx_file_write(&file_36, "1", 1);
988 status += fx_file_write(&file_37, "1", 1);
989 status += fx_file_write(&file_38, "1", 1);
990 status += fx_file_write(&file_39, "1", 1);
991 status += fx_file_write(&file_40, "1", 1);
992 status += fx_file_write(&file_41, "1", 1);
993 status += fx_file_write(&file_42, "1", 1);
994 status += fx_file_write(&file_43, "1", 1);
995 status += fx_file_write(&file_44, "1", 1);
996 status += fx_file_close(&file_1);
997 status += fx_file_close(&file_2);
998 status += fx_file_close(&file_3);
999 status += fx_file_close(&file_4);
1000 status += fx_file_close(&file_5);
1001 status += fx_file_close(&file_6);
1002 status += fx_file_close(&file_7);
1003 status += fx_file_close(&file_8);
1004 status += fx_file_close(&file_9);
1005 status += fx_file_close(&file_10);
1006 status += fx_file_close(&file_11);
1007 status += fx_file_close(&file_12);
1008 status += fx_file_close(&file_13);
1009 status += fx_file_close(&file_14);
1010 status += fx_file_close(&file_15);
1011 status += fx_file_close(&file_16);
1012 status += fx_file_close(&file_17);
1013 status += fx_file_close(&file_18);
1014 status += fx_file_close(&file_19);
1015 status += fx_file_close(&file_20);
1016 status += fx_file_close(&file_21);
1017 status += fx_file_close(&file_22);
1018 status += fx_file_close(&file_23);
1019 status += fx_file_close(&file_24);
1020 status += fx_file_close(&file_25);
1021 status += fx_file_close(&file_26);
1022 status += fx_file_close(&file_27);
1023 status += fx_file_close(&file_28);
1024 status += fx_file_close(&file_29);
1025 status += fx_file_close(&file_30);
1026 status += fx_file_close(&file_31);
1027 status += fx_file_close(&file_32);
1028 status += fx_file_close(&file_33);
1029 status += fx_file_close(&file_34);
1030 status += fx_file_close(&file_35);
1031 status += fx_file_close(&file_36);
1032 status += fx_file_close(&file_37);
1033 status += fx_file_close(&file_38);
1034 status += fx_file_close(&file_39);
1035 status += fx_file_close(&file_40);
1036 status += fx_file_close(&file_41);
1037 status += fx_file_close(&file_42);
1038 status += fx_file_close(&file_43);
1039 status += fx_file_close(&file_44);
1040 return_if_fail( status == FX_SUCCESS);
1041
1042 /* Close the media. */
1043 status = fx_media_close(&ram_disk);
1044 return_if_fail( status == FX_SUCCESS);
1045
1046 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1047 _fx_ram_driver_copy_default_format = 1;
1048
1049 /* Open the ram_disk. */
1050 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1051 _fx_ram_driver_copy_default_format = 0;
1052 return_if_fail( status == FX_SUCCESS);
1053
1054 /* Get the first file name, this should be "ntfile" for exercising the NT file name capability. */
1055 status = fx_directory_first_entry_find(&ram_disk, name);
1056 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
1057 status += fx_directory_next_entry_find(&ram_disk, name);
1058 status += fx_directory_next_entry_find(&ram_disk, name);
1059 status += fx_directory_next_entry_find(&ram_disk, name);
1060 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1061 status += fx_directory_next_entry_find(&ram_disk, name);
1062
1063 /* Write to both files, write to them and close them! */
1064 status += fx_file_write(&file_1, "abcd", 4);
1065 status += fx_file_write(&file_2, "abcd", 4);
1066 status += fx_file_close(&file_1);
1067 status += fx_file_close(&file_2);
1068 return_if_fail( status == FX_SUCCESS);
1069
1070 /* Now look move to the first sub-directory. */
1071 status = fx_directory_default_set(&ram_disk, name);
1072 status += fx_directory_first_entry_find(&ram_disk, name); /* . */
1073 status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
1074 status += fx_directory_next_entry_find(&ram_disk, name); /* Too long of a file name. */
1075 status += fx_file_delete(&ram_disk, name);
1076 status += fx_directory_next_entry_find(&ram_disk, name); /* Next too long sub-directory. */
1077 status += fx_directory_default_set(&ram_disk, name); /* Move to next sub-directory. */
1078 return_if_fail( status == FX_SUCCESS);
1079
1080 /* Move back to the root directory. */
1081 status += fx_directory_default_set(&ram_disk, "\\");
1082
1083 /* Set an all blank volume name. */
1084 status += fx_media_volume_set(&ram_disk, " ");
1085 status += fx_media_volume_get(&ram_disk, volume_name, FX_DIRECTORY_SECTOR);
1086 status += fx_directory_first_entry_find(&ram_disk, name); /* ntfile */
1087 status += fx_directory_next_entry_find(&ram_disk, name); /* nt-file~.txt */
1088 status += fx_directory_next_entry_find(&ram_disk, name);
1089 status += fx_directory_next_entry_find(&ram_disk, name);
1090 status += fx_directory_next_entry_find(&ram_disk, name);
1091 status += fx_directory_next_entry_find(&ram_disk, name);
1092 status += fx_directory_next_entry_find(&ram_disk, name);
1093 status += fx_directory_next_entry_find(&ram_disk, name);
1094
1095 /* Close the media. */
1096 status = fx_media_close(&ram_disk);
1097 return_if_fail( status == FX_SUCCESS);
1098
1099 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1100 _fx_ram_driver_copy_default_format = 1;
1101
1102 /* Open the ram_disk. */
1103 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1104 _fx_ram_driver_copy_default_format = 0;
1105 return_if_fail( status == FX_SUCCESS);
1106
1107 /* Get the first shorted file name. */
1108 status = fx_directory_first_entry_find(&ram_disk, name);
1109 status += fx_directory_next_entry_find(&ram_disk, name);
1110 status += fx_directory_next_entry_find(&ram_disk, name);
1111 status += fx_directory_next_entry_find(&ram_disk, name);
1112 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1113
1114 /* Write to the shorted file. */
1115 status += fx_file_write(&file_2, "abcd", 4);
1116
1117 /* Now close the file, which will write the shorted file entry out. */
1118 _fx_utility_logical_sector_write_error_request = 1;
1119 status += fx_file_close(&file_2);
1120 _fx_utility_logical_sector_write_error_request = 0;
1121 return_if_fail( status == FX_IO_ERROR);
1122
1123 /* Close the media. */
1124 status = fx_media_close(&ram_disk);
1125 return_if_fail( status == FX_SUCCESS);
1126
1127 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1128 _fx_ram_driver_copy_default_format = 1;
1129
1130 /* Open the ram_disk. */
1131 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1132 _fx_ram_driver_copy_default_format = 0;
1133 return_if_fail( status == FX_SUCCESS);
1134
1135 /* Get the first shorted file name. */
1136 status = fx_directory_first_entry_find(&ram_disk, name);
1137 status += fx_directory_next_entry_find(&ram_disk, name);
1138 status += fx_directory_next_entry_find(&ram_disk, name);
1139 status += fx_directory_next_entry_find(&ram_disk, name);
1140 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1141
1142 /* Write to the shorted file. */
1143 status += fx_file_write(&file_2, "abcd", 4);
1144
1145 /* Now close the file, which will write the shorted file entry out. */
1146 temp = ram_disk.fx_media_data_sector_start;
1147 ram_disk.fx_media_data_sector_start = ram_disk.fx_media_root_sector_start+2;
1148 status += fx_file_close(&file_2);
1149 ram_disk.fx_media_data_sector_start = temp;
1150 return_if_fail( status == FX_FILE_CORRUPT);
1151
1152 /* Close the media. */
1153 status = fx_media_close(&ram_disk);
1154 return_if_fail( status == FX_SUCCESS);
1155
1156 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1157 _fx_ram_driver_copy_default_format = 1;
1158
1159 /* Open the ram_disk. */
1160 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1161 _fx_ram_driver_copy_default_format = 0;
1162 return_if_fail( status == FX_SUCCESS);
1163
1164 /* Get the first shorted file name. */
1165 status = fx_directory_first_entry_find(&ram_disk, name);
1166 status += fx_directory_next_entry_find(&ram_disk, name);
1167 status += fx_directory_next_entry_find(&ram_disk, name);
1168 status += fx_directory_next_entry_find(&ram_disk, name);
1169 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1170 status += fx_directory_next_entry_find(&ram_disk, name);
1171
1172 /* Write to the shorted file. */
1173 status += fx_file_write(&file_2, "abcd", 4);
1174
1175 /* Now close the file, which will write the shorted file entry out. */
1176 _fx_utility_logical_sector_read_error_request = 2;
1177 status += fx_file_close(&file_2);
1178 _fx_utility_logical_sector_read_error_request = 0;
1179 return_if_fail( status == FX_IO_ERROR);
1180
1181 /* Close the media. */
1182 status = fx_media_close(&ram_disk);
1183 return_if_fail( status == FX_SUCCESS);
1184
1185 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1186 _fx_ram_driver_copy_default_format = 1;
1187
1188 /* Open the ram_disk. */
1189 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1190 _fx_ram_driver_copy_default_format = 0;
1191 return_if_fail( status == FX_SUCCESS);
1192
1193 /* Get the first shorted file name. */
1194 status = fx_directory_first_entry_find(&ram_disk, name);
1195 status += fx_directory_next_entry_find(&ram_disk, name);
1196 status += fx_directory_next_entry_find(&ram_disk, name);
1197 status += fx_directory_next_entry_find(&ram_disk, name);
1198 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1199 status += fx_directory_next_entry_find(&ram_disk, name);
1200 status += fx_media_flush(&ram_disk);
1201 status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start+1, buffer);
1202 buffer[0x40] = 0x1f;
1203 status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start+1, buffer);
1204
1205 /* Write to the shorted file. */
1206 status += fx_file_write(&file_2, "abcd", 4);
1207
1208 /* Now close the file, which will write the shorted file entry out.... not that the shorted flag is not in the actual directory entry. */
1209 status += fx_file_close(&file_2);
1210 return_if_fail( status == FX_SUCCESS);
1211
1212 /* Close the media. */
1213 status = fx_media_close(&ram_disk);
1214 return_if_fail( status == FX_SUCCESS);
1215
1216 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1217 _fx_ram_driver_copy_default_format = 1;
1218
1219 /* Open the ram_disk. */
1220 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1221 _fx_ram_driver_copy_default_format = 0;
1222 return_if_fail( status == FX_SUCCESS);
1223
1224 /* Get the first shorted file name. */
1225 status += fx_directory_next_entry_find(&ram_disk, name);
1226 status += fx_directory_next_entry_find(&ram_disk, name);
1227 status += fx_directory_next_entry_find(&ram_disk, name);
1228 status += fx_directory_next_entry_find(&ram_disk, name);
1229 status += fx_directory_next_entry_find(&ram_disk, name);
1230
1231 /* Switch to this directory. */
1232 status += fx_directory_default_set(&ram_disk, name);
1233 status = fx_directory_first_entry_find(&ram_disk, name); /* . */
1234 status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
1235 status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
1236 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1237
1238 /* Write to the shorted file. */
1239 status += fx_file_write(&file_2, "abcd", 4);
1240
1241 /* Now close the file, which will write the shorted file entry out. */
1242 _fx_utility_fat_entry_read_error_request = 1;
1243 status += fx_file_close(&file_2);
1244 _fx_utility_fat_entry_read_error_request = 0;
1245
1246 /* Check the status - should be an error here. */
1247 if (status != FX_IO_ERROR)
1248 {
1249
1250 /* Error, return error code. */
1251 printf("ERROR!\n");
1252 test_control_return(97);
1253 }
1254
1255 /* Close the media. */
1256 status = fx_media_close(&ram_disk);
1257
1258 /* Determine if the test was successful. */
1259 if (status != FX_SUCCESS)
1260 {
1261
1262 printf("ERROR!\n");
1263 test_control_return(98);
1264 }
1265
1266
1267 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1268 _fx_ram_driver_copy_default_format = 1;
1269
1270 /* Open the ram_disk. */
1271 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1272 _fx_ram_driver_copy_default_format = 0;
1273
1274 /* Check the status. */
1275 if (status != FX_SUCCESS)
1276 {
1277
1278 /* Error, return error code. */
1279 printf("ERROR!\n");
1280 test_control_return(99);
1281 }
1282
1283 /* Get the first shorted file name. */
1284 status += fx_directory_next_entry_find(&ram_disk, name);
1285 status += fx_directory_next_entry_find(&ram_disk, name);
1286 status += fx_directory_next_entry_find(&ram_disk, name);
1287 status += fx_directory_next_entry_find(&ram_disk, name);
1288 status += fx_directory_next_entry_find(&ram_disk, name);
1289
1290 /* Switch to this directory. */
1291 status += fx_directory_default_set(&ram_disk, name);
1292 status = fx_directory_first_entry_find(&ram_disk, name); /* . */
1293 status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
1294 status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
1295 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1296
1297 /* Write to the shorted file. */
1298 status += fx_file_write(&file_2, "abcd", 4);
1299
1300 /* Now close the file, which will write the shorted file entry out. */
1301 _fx_utility_fat_entry_read_error_request = 10001;
1302 status += fx_file_close(&file_2);
1303 _fx_utility_fat_entry_read_error_request = 0;
1304
1305 /* Check the status - should be an error here. */
1306 if (status != FX_FILE_CORRUPT)
1307 {
1308
1309 /* Error, return error code. */
1310 printf("ERROR!\n");
1311 test_control_return(100);
1312 }
1313
1314 /* Close the media. */
1315 status = fx_media_close(&ram_disk);
1316
1317 /* Determine if the test was successful. */
1318 if (status != FX_SUCCESS)
1319 {
1320
1321 printf("ERROR!\n");
1322 test_control_return(101);
1323 }
1324
1325 /* Set the flag to copy the default format to get NT file name, orphan long file name, and super long file names. */
1326 _fx_ram_driver_copy_default_format = 1;
1327
1328 /* Open the ram_disk. */
1329 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1330 _fx_ram_driver_copy_default_format = 0;
1331
1332 /* Check the status. */
1333 if (status != FX_SUCCESS)
1334 {
1335
1336 /* Error, return error code. */
1337 printf("ERROR!\n");
1338 test_control_return(102);
1339 }
1340
1341 /* Get the first shorted file name. */
1342 status += fx_directory_next_entry_find(&ram_disk, name);
1343 status += fx_directory_next_entry_find(&ram_disk, name);
1344 status += fx_directory_next_entry_find(&ram_disk, name);
1345 status += fx_directory_next_entry_find(&ram_disk, name);
1346 status += fx_directory_next_entry_find(&ram_disk, name);
1347
1348 /* Switch to this directory. */
1349 status += fx_directory_default_set(&ram_disk, name);
1350 status = fx_directory_first_entry_find(&ram_disk, name); /* . */
1351 status += fx_directory_next_entry_find(&ram_disk, name); /* .. */
1352 status += fx_directory_next_entry_find(&ram_disk, name); /* shorted long file name! */
1353 status += fx_file_open(&ram_disk, &file_2, name, FX_OPEN_FOR_WRITE);
1354
1355 /* Write to the shorted file. */
1356 status += fx_file_write(&file_2, "abcd", 4);
1357
1358 /* Now close the file, which will write the shorted file entry out. */
1359 _fx_utility_fat_entry_read_error_request = 20001;
1360 status += fx_file_close(&file_2);
1361 _fx_utility_fat_entry_read_error_request = 0;
1362
1363 /* Check the status - should be an error here. */
1364 if (status != FX_FILE_CORRUPT)
1365 {
1366
1367 /* Error, return error code. */
1368 printf("ERROR!\n");
1369 test_control_return(103);
1370 }
1371
1372 /* Close the media. */
1373 status = fx_media_close(&ram_disk);
1374
1375 /* Determine if the test was successful. */
1376 if (status != FX_SUCCESS)
1377 {
1378
1379 printf("ERROR!\n");
1380 test_control_return(104);
1381 }
1382
1383
1384 /* Format the media. This needs to be done before opening it! */
1385 status = fx_media_format(&ram_disk,
1386 _fx_ram_driver, // Driver entry
1387 ram_disk_memory, // RAM disk memory pointer
1388 cache_buffer, // Media buffer pointer
1389 CACHE_SIZE, // Media buffer size
1390 "MY_RAM_DISK", // Volume Name
1391 1, // Number of FATs
1392 32, // Directory Entries
1393 0, // Hidden sectors
1394 14000, // Total sectors
1395 128, // Sector size
1396 2, // Sectors per cluster
1397 1, // Heads
1398 1); // Sectors per track
1399
1400 /* Determine if the format had an error. */
1401 if (status)
1402 {
1403
1404 printf("ERROR!\n");
1405 test_control_return(105);
1406 }
1407
1408 /* Open the ram_disk. */
1409 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1410
1411 /* Check the status. */
1412 if (status != FX_SUCCESS)
1413 {
1414
1415 /* Error, return error code. */
1416 printf("ERROR!\n");
1417 test_control_return(106);
1418 }
1419
1420 /* Build a sub-directory structure to further test diretory entry read. */
1421 status = fx_directory_create(&ram_disk, "SUB1");
1422 status += fx_directory_default_set(&ram_disk, "SUB1");
1423 status += fx_file_create(&ram_disk, "S1_FL1.TXT");
1424 status += fx_file_create(&ram_disk, "S1_FL2.TXT");
1425 status += fx_file_create(&ram_disk, "S1_FL3.TXT");
1426 status += fx_file_create(&ram_disk, "S1_FL4.TXT");
1427 status += fx_file_create(&ram_disk, "S1_FL5.TXT");
1428 status += fx_file_create(&ram_disk, "S1_FL6.TXT");
1429 status += fx_file_create(&ram_disk, "S1_FL7.TXT");
1430 status += fx_file_create(&ram_disk, "S1_FL8.TXT");
1431 status += fx_file_create(&ram_disk, "S1_FL9.TXT");
1432 status += fx_file_create(&ram_disk, "S1_FL10.TXT");
1433 status += fx_file_create(&ram_disk, "S1_FL11.TXT");
1434 status += fx_file_create(&ram_disk, "S1_FL12.TXT");
1435 status += fx_file_create(&ram_disk, "S1_FL13.TXT");
1436 status += fx_file_create(&ram_disk, "S1_FL14.TXT");
1437 status += fx_file_create(&ram_disk, "S1_FL15.TXT");
1438 status += fx_file_create(&ram_disk, "S1_FL16.TXT");
1439 status += fx_file_create(&ram_disk, "S1_FL17.TXT");
1440 status += fx_file_create(&ram_disk, "S1_FL18.TXT");
1441 status += fx_file_create(&ram_disk, "S1_FL19.TXT");
1442 status += fx_file_create(&ram_disk, "S1_FL20.TXT");
1443 status += fx_file_create(&ram_disk, "S1_FL21.TXT");
1444 status += fx_file_create(&ram_disk, "S1_FL22.TXT");
1445 status += fx_file_create(&ram_disk, "S1_FL23.TXT");
1446 status += fx_file_create(&ram_disk, "S1_FL24.TXT");
1447 status += fx_file_create(&ram_disk, "S1_FL25.TXT");
1448 status += fx_file_create(&ram_disk, "S1_FL26.TXT");
1449 status += fx_file_create(&ram_disk, "S1_FL27.TXT");
1450 status += fx_file_create(&ram_disk, "S1_FL28.TXT");
1451 status += fx_file_create(&ram_disk, "S1_FL29.TXT");
1452 status += fx_file_create(&ram_disk, "S1_FL30.TXT");
1453 status += fx_file_create(&ram_disk, "S1_FL31.TXT");
1454 status += fx_file_create(&ram_disk, "S1_FL32.TXT");
1455
1456 /* Now taverse the directory tree and open files. */
1457 status += fx_directory_first_entry_find(&ram_disk, name);
1458 status += fx_directory_next_entry_find(&ram_disk, name);
1459 status += fx_directory_next_entry_find(&ram_disk, name);
1460 status += fx_directory_next_entry_find(&ram_disk, name);
1461 status += fx_directory_next_entry_find(&ram_disk, name);
1462 status += fx_directory_next_entry_find(&ram_disk, name);
1463 status += fx_directory_next_entry_find(&ram_disk, name);
1464 status += fx_directory_next_entry_find(&ram_disk, name);
1465 status += fx_directory_next_entry_find(&ram_disk, name);
1466 status += fx_directory_next_entry_find(&ram_disk, name);
1467 status += fx_directory_next_entry_find(&ram_disk, name);
1468 status += fx_directory_next_entry_find(&ram_disk, name);
1469 status += fx_directory_next_entry_find(&ram_disk, name);
1470 status += fx_directory_next_entry_find(&ram_disk, name);
1471 status += fx_directory_next_entry_find(&ram_disk, name);
1472 status += fx_directory_next_entry_find(&ram_disk, name);
1473 status += fx_directory_next_entry_find(&ram_disk, name);
1474 status += fx_directory_next_entry_find(&ram_disk, name);
1475 status += fx_directory_next_entry_find(&ram_disk, name);
1476 status += fx_directory_next_entry_find(&ram_disk, name);
1477 status += fx_directory_next_entry_find(&ram_disk, name);
1478 status += fx_directory_next_entry_find(&ram_disk, name);
1479 status += fx_directory_next_entry_find(&ram_disk, name);
1480 status += fx_directory_next_entry_find(&ram_disk, name);
1481 status += fx_directory_next_entry_find(&ram_disk, name);
1482 status += fx_directory_next_entry_find(&ram_disk, name);
1483 status += fx_directory_next_entry_find(&ram_disk, name);
1484 status += fx_directory_next_entry_find(&ram_disk, name);
1485 status += fx_directory_next_entry_find(&ram_disk, name);
1486 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_relative_cluster = 100;
1487 status += fx_directory_next_entry_find(&ram_disk, name);
1488 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_log_sector = 1000;
1489 status += fx_directory_next_entry_find(&ram_disk, name);
1490 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_byte_offset = 10000;
1491 status += fx_directory_next_entry_find(&ram_disk, name);
1492
1493 /* Determine if the test was successful. */
1494 if (status != FX_SUCCESS)
1495 {
1496
1497 printf("ERROR!\n");
1498 test_control_return(107);
1499 }
1500
1501 /* Now go back to the beginning of the directory. */
1502 status += fx_directory_first_entry_find(&ram_disk, name);
1503 status += fx_directory_next_entry_find(&ram_disk, name);
1504 status += fx_directory_next_entry_find(&ram_disk, name);
1505 status += fx_directory_next_entry_find(&ram_disk, name);
1506 status += fx_directory_next_entry_find(&ram_disk, name);
1507 status += fx_directory_next_entry_find(&ram_disk, name);
1508 status += fx_directory_next_entry_find(&ram_disk, name);
1509 status += fx_directory_next_entry_find(&ram_disk, name);
1510 status += fx_directory_next_entry_find(&ram_disk, name);
1511 status += fx_directory_next_entry_find(&ram_disk, name);
1512 status += fx_directory_next_entry_find(&ram_disk, name);
1513 status += fx_directory_next_entry_find(&ram_disk, name);
1514 status += fx_directory_next_entry_find(&ram_disk, name);
1515 status += fx_directory_next_entry_find(&ram_disk, name);
1516 status += fx_directory_next_entry_find(&ram_disk, name);
1517 status += fx_directory_next_entry_find(&ram_disk, name);
1518 status += fx_directory_next_entry_find(&ram_disk, name);
1519 status += fx_directory_next_entry_find(&ram_disk, name);
1520 status += fx_directory_next_entry_find(&ram_disk, name);
1521 status += fx_directory_next_entry_find(&ram_disk, name);
1522 status += fx_directory_next_entry_find(&ram_disk, name);
1523
1524 /* Search with I/O read error. */
1525 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
1526 _fx_utility_fat_entry_read_error_request = 1;
1527 status += fx_directory_next_entry_find(&ram_disk, name);
1528 _fx_utility_fat_entry_read_error_request = 0;
1529
1530 /* Determine if the expected I/O error is present. */
1531 if (status != FX_IO_ERROR)
1532 {
1533
1534 printf("ERROR!\n");
1535 test_control_return(108);
1536 }
1537
1538 /* Search with bad FAT error - too small. */
1539 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
1540 _fx_utility_fat_entry_read_error_request = 10001;
1541 status = fx_directory_next_entry_find(&ram_disk, name);
1542 _fx_utility_fat_entry_read_error_request = 0;
1543
1544 /* Determine if the expected I/O error is present. */
1545 if (status != FX_FILE_CORRUPT)
1546 {
1547
1548 printf("ERROR!\n");
1549 test_control_return(109);
1550 }
1551
1552 /* Search with bad FAT error - too small. */
1553 ram_disk.fx_media_default_path.fx_path_directory.fx_dir_entry_last_search_cluster = 0; /* Cause cluster traversal. */
1554 _fx_utility_fat_entry_read_error_request = 20001;
1555 status = fx_directory_next_entry_find(&ram_disk, name);
1556 _fx_utility_fat_entry_read_error_request = 0;
1557
1558 /* Determine if the expected I/O error is present. */
1559 if (status != FX_FILE_CORRUPT)
1560 {
1561
1562 printf("ERROR!\n");
1563 test_control_return(110);
1564 }
1565
1566 /* Corrupt the media to test zero divisor checking. */
1567 ram_disk.fx_media_bytes_per_sector = 0;
1568 status = fx_directory_next_entry_find(&ram_disk, name);
1569
1570 /* Determine if the expected error is present. */
1571 if (status != FX_MEDIA_INVALID)
1572 {
1573
1574 printf("ERROR!\n");
1575 test_control_return(110);
1576 }
1577 ram_disk.fx_media_bytes_per_sector = 128;
1578
1579 /* Build a large file name. */
1580 for (i = 0; i < 255; i++)
1581 {
1582 name[i] = 'a';
1583 }
1584 name[255] = 0;
1585
1586 /* Move back to the root directory. */
1587 status = fx_directory_default_set(&ram_disk, "\\");
1588 status += fx_unicode_file_create(&ram_disk, my_unicode_name, 15, (CHAR *)buffer);
1589 status += fx_unicode_file_create(&ram_disk, my_unicode_name1, 15, (CHAR *)buffer);
1590 status += fx_file_create(&ram_disk, name);
1591
1592 /* Set the search to the beginning of the root directory. */
1593 status += fx_directory_first_entry_find(&ram_disk, name);
1594 status += fx_directory_next_entry_find(&ram_disk, name);
1595 status += fx_directory_next_entry_find(&ram_disk, name);
1596
1597 /* Determine if the test was successful. */
1598 if (status != FX_SUCCESS)
1599 {
1600
1601 printf("ERROR!\n");
1602 test_control_return(111);
1603 }
1604
1605 /* Now generate an error on the root directory size. */
1606 temp = ram_disk.fx_media_root_sectors;
1607 ram_disk.fx_media_root_sectors = 1;
1608 status = fx_directory_next_entry_find(&ram_disk, name);
1609 ram_disk.fx_media_root_sectors = temp;
1610
1611 /* Determine if the expected I/O error is present. */
1612 if (status != FX_FILE_CORRUPT)
1613 {
1614
1615 printf("ERROR!\n");
1616 test_control_return(112);
1617 }
1618
1619 /* Now generate an error with a logical sector read error. */
1620 _fx_utility_logical_sector_read_error_request = 5;
1621 status = fx_directory_next_entry_find(&ram_disk, name);
1622 _fx_utility_logical_sector_read_error_request = 0;
1623
1624 /* Determine if the expected I/O error is present. */
1625 if (status != FX_IO_ERROR)
1626 {
1627
1628 printf("ERROR!\n");
1629 test_control_return(113);
1630 }
1631
1632 /* Close the media. */
1633 status = fx_media_close(&ram_disk);
1634
1635 /* Determine if the test was successful. */
1636 if (status != FX_SUCCESS)
1637 {
1638
1639 printf("ERROR!\n");
1640 test_control_return(114);
1641 }
1642
1643 /* Format the media. This needs to be done before opening it! */
1644 status = fx_media_format(&ram_disk,
1645 _fx_ram_driver, // Driver entry
1646 ram_disk_memory, // RAM disk memory pointer
1647 cache_buffer, // Media buffer pointer
1648 CACHE_SIZE, // Media buffer size
1649 "MY_RAM_DISK", // Volume Name
1650 1, // Number of FATs
1651 32, // Directory Entries
1652 0, // Hidden sectors
1653 14000, // Total sectors
1654 128, // Sector size
1655 1, // Sectors per cluster
1656 1, // Heads
1657 1); // Sectors per track
1658
1659 /* Determine if the format had an error. */
1660 if (status)
1661 {
1662
1663 printf("ERROR!\n");
1664 test_control_return(115);
1665 }
1666
1667 /* Open the ram_disk. */
1668 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1669
1670 /* Check the status. */
1671 if (status != FX_SUCCESS)
1672 {
1673
1674 /* Error, return error code. */
1675 printf("ERROR!\n");
1676 test_control_return(116);
1677 }
1678
1679 /* Build a large file name. */
1680 for (i = 0; i < 255; i++)
1681 {
1682 name[i] = 'a';
1683 }
1684 name[255] = 0;
1685
1686 /* Create a sub-directory. */
1687 status = fx_directory_create(&ram_disk, "SUB1");
1688 status += fx_directory_default_set(&ram_disk, "SUB1");
1689 status += fx_file_create(&ram_disk, name);
1690 status += fx_directory_first_entry_find(&ram_disk, (CHAR *)buffer);
1691 status += fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
1692
1693 /* Check the status. */
1694 if (status != FX_SUCCESS)
1695 {
1696
1697 /* Error, return error code. */
1698 printf("ERROR!\n");
1699 test_control_return(117);
1700 }
1701
1702 /* Read the first entry, but with a FAT entry error. */
1703 _fx_utility_fat_entry_read_error_request = 1;
1704 status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
1705 _fx_utility_fat_entry_read_error_request = 0;
1706
1707 /* Determine if the expected I/O error is present. */
1708 if (status != FX_IO_ERROR)
1709 {
1710
1711 printf("ERROR!\n");
1712 test_control_return(118);
1713 }
1714
1715 /* Read the first entry, but with a FAT entry error - too small. */
1716 _fx_utility_fat_entry_read_error_request = 10001;
1717 status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
1718 _fx_utility_fat_entry_read_error_request = 0;
1719
1720 /* Determine if the expected I/O error is present. */
1721 if (status != FX_FILE_CORRUPT)
1722 {
1723
1724 printf("ERROR!\n");
1725 test_control_return(119);
1726 }
1727
1728 /* Read the first entry, but with a FAT entry error - too big. */
1729 _fx_utility_fat_entry_read_error_request = 20001;
1730 status = fx_directory_next_entry_find(&ram_disk, (CHAR *)buffer);
1731 _fx_utility_fat_entry_read_error_request = 0;
1732
1733 /* Determine if the expected I/O error is present. */
1734 if (status != FX_FILE_CORRUPT)
1735 {
1736
1737 printf("ERROR!\n");
1738 test_control_return(120);
1739 }
1740
1741 /* Close the media. */
1742 status = fx_media_close(&ram_disk);
1743
1744 /* Determine if the test was successful. */
1745 if (status != FX_SUCCESS)
1746 {
1747
1748 printf("ERROR!\n");
1749 test_control_return(121);
1750 }
1751
1752 /* Format the media. This needs to be done before opening it! */
1753 status = fx_media_format(&ram_disk,
1754 _fx_ram_driver, // Driver entry
1755 ram_disk_memory, // RAM disk memory pointer
1756 cache_buffer, // Media buffer pointer
1757 CACHE_SIZE, // Media buffer size
1758 "MY_RAM_DISK", // Volume Name
1759 1, // Number of FATs
1760 512, // Directory Entries
1761 0, // Hidden sectors
1762 14000, // Total sectors
1763 128, // Sector size
1764 1, // Sectors per cluster
1765 1, // Heads
1766 1); // Sectors per track
1767
1768 /* Determine if the format had an error. */
1769 if (status)
1770 {
1771
1772 printf("ERROR!\n");
1773 test_control_return(122);
1774 }
1775
1776 /* Open the ram_disk. */
1777 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1778
1779 /* Check the status. */
1780 if (status != FX_SUCCESS)
1781 {
1782
1783 /* Error, return error code. */
1784 printf("ERROR!\n");
1785 test_control_return(123);
1786 }
1787
1788 /* Build a large file name. */
1789 for (i = 0; i < 255; i++)
1790 {
1791 name[i] = 'a';
1792 }
1793 name[255] = 0;
1794
1795 /* Create a large file name in the root directory. */
1796 _fx_utility_logical_sector_write_error_request = 22;
1797 status = fx_file_create(&ram_disk, name);
1798 _fx_utility_logical_sector_write_error_request = 0;
1799
1800 /* Setup an I/O error on the first logical sectory write of the directory entry. */
1801 status += fx_media_flush(&ram_disk);
1802
1803 /* Determine if have the expected I/O error. */
1804 if (status != FX_IO_ERROR)
1805 {
1806
1807 printf("ERROR!\n");
1808 test_control_return(124);
1809 }
1810
1811 /* Close the media. */
1812 status = fx_media_close(&ram_disk);
1813
1814 /* Determine if the test was successful. */
1815 if (status != FX_SUCCESS)
1816 {
1817
1818 printf("ERROR!\n");
1819 test_control_return(125);
1820 }
1821
1822
1823 /* Format the media. This needs to be done before opening it! */
1824 status = fx_media_format(&ram_disk,
1825 _fx_ram_driver, // Driver entry
1826 ram_disk_memory, // RAM disk memory pointer
1827 cache_buffer, // Media buffer pointer
1828 CACHE_SIZE, // Media buffer size
1829 "MY_RAM_DISK", // Volume Name
1830 1, // Number of FATs
1831 512, // Directory Entries
1832 0, // Hidden sectors
1833 14000, // Total sectors
1834 128, // Sector size
1835 1, // Sectors per cluster
1836 1, // Heads
1837 1); // Sectors per track
1838
1839 /* Determine if the format had an error. */
1840 if (status)
1841 {
1842
1843 printf("ERROR!\n");
1844 test_control_return(126);
1845 }
1846
1847 /* Open the ram_disk. */
1848 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1849
1850 /* Check the status. */
1851 if (status != FX_SUCCESS)
1852 {
1853
1854 /* Error, return error code. */
1855 printf("ERROR!\n");
1856 test_control_return(127);
1857 }
1858
1859 /* Build a large file name. */
1860 for (i = 0; i < 255; i++)
1861 {
1862 name[i] = 'a';
1863 }
1864 name[255] = 0;
1865
1866 /* Create a large file name in the root directory. */
1867 _fx_utility_logical_sector_read_error_request = 45;
1868 status = fx_file_create(&ram_disk, name);
1869 _fx_utility_logical_sector_read_error_request = 0;
1870
1871 /* Setup an I/O error on the first logical sectory write of the directory entry. */
1872 status += fx_media_flush(&ram_disk);
1873
1874 /* Determine if have the expected I/O error. */
1875 if (status != FX_IO_ERROR)
1876 {
1877
1878 printf("ERROR!\n");
1879 test_control_return(128);
1880 }
1881
1882 /* Close the media. */
1883 status = fx_media_close(&ram_disk);
1884
1885 /* Determine if the test was successful. */
1886 if (status != FX_SUCCESS)
1887 {
1888
1889 printf("ERROR!\n");
1890 test_control_return(129);
1891 }
1892
1893 /* Format the media. This needs to be done before opening it! */
1894 status = fx_media_format(&ram_disk,
1895 _fx_ram_driver, // Driver entry
1896 ram_disk_memory, // RAM disk memory pointer
1897 cache_buffer, // Media buffer pointer
1898 CACHE_SIZE, // Media buffer size
1899 "MY_RAM_DISK", // Volume Name
1900 1, // Number of FATs
1901 512, // Directory Entries
1902 0, // Hidden sectors
1903 14000, // Total sectors
1904 128, // Sector size
1905 1, // Sectors per cluster
1906 1, // Heads
1907 1); // Sectors per track
1908
1909 /* Determine if the format had an error. */
1910 if (status)
1911 {
1912
1913 printf("ERROR!\n");
1914 test_control_return(130);
1915 }
1916
1917 /* Open the ram_disk. */
1918 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1919
1920 /* Check the status. */
1921 if (status != FX_SUCCESS)
1922 {
1923
1924 /* Error, return error code. */
1925 printf("ERROR!\n");
1926 test_control_return(131);
1927 }
1928
1929 /* Build a large file name. */
1930 for (i = 0; i < 255; i++)
1931 {
1932 name[i] = 'a';
1933 }
1934 name[255] = 0;
1935
1936 /* Create a large file name in the root directory. */
1937 temp = ram_disk.fx_media_data_sector_start;
1938 ram_disk.fx_media_data_sector_start = ram_disk.fx_media_root_sector_start+1;
1939 status = fx_file_create(&ram_disk, name);
1940 ram_disk.fx_media_data_sector_start = temp;
1941
1942 /* Setup an I/O error on the first logical sectory write of the directory entry. */
1943 status += fx_media_flush(&ram_disk);
1944
1945 /* Determine if have the expected error. */
1946 if (status != FX_FILE_CORRUPT)
1947 {
1948
1949 printf("ERROR!\n");
1950 test_control_return(132);
1951 }
1952
1953 /* Close the media. */
1954 status = fx_media_close(&ram_disk);
1955
1956 /* Determine if the test was successful. */
1957 if (status != FX_SUCCESS)
1958 {
1959
1960 printf("ERROR!\n");
1961 test_control_return(133);
1962 }
1963
1964 /* Format the media. This needs to be done before opening it! */
1965 status = fx_media_format(&ram_disk,
1966 _fx_ram_driver, // Driver entry
1967 ram_disk_memory, // RAM disk memory pointer
1968 cache_buffer, // Media buffer pointer
1969 CACHE_SIZE, // Media buffer size
1970 "MY_RAM_DISK", // Volume Name
1971 1, // Number of FATs
1972 512, // Directory Entries
1973 0, // Hidden sectors
1974 14000, // Total sectors
1975 128, // Sector size
1976 1, // Sectors per cluster
1977 1, // Heads
1978 1); // Sectors per track
1979
1980 /* Determine if the format had an error. */
1981 if (status)
1982 {
1983
1984 printf("ERROR!\n");
1985 test_control_return(134);
1986 }
1987
1988 /* Open the ram_disk. */
1989 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
1990
1991 /* Check the status. */
1992 if (status != FX_SUCCESS)
1993 {
1994
1995 /* Error, return error code. */
1996 printf("ERROR!\n");
1997 test_control_return(135);
1998 }
1999
2000 /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
2001 status = fx_directory_create(&ram_disk, "SUB1");
2002 status += fx_directory_default_set(&ram_disk, "SUB1");
2003
2004 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2005 status += fx_media_flush(&ram_disk);
2006
2007 /* Check the status. */
2008 if (status != FX_SUCCESS)
2009 {
2010
2011 /* Error, return error code. */
2012 printf("ERROR!\n");
2013 test_control_return(136);
2014 }
2015
2016 /* Build a large file name. */
2017 for (i = 0; i < 255; i++)
2018 {
2019 name[i] = 'a';
2020 }
2021 name[255] = 0;
2022
2023 /* Create a large file name in the sub-directory with a FAT entry read error. */
2024 _fx_utility_fat_entry_read_error_request = 14;
2025 status = fx_file_create(&ram_disk, name);
2026 _fx_utility_fat_entry_read_error_request = 0;
2027
2028 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2029 status += fx_media_flush(&ram_disk);
2030
2031 /* Determine if have the expected error. */
2032 if (status != FX_IO_ERROR)
2033 {
2034
2035 printf("ERROR!\n");
2036 test_control_return(137);
2037 }
2038
2039 /* Close the media. */
2040 status = fx_media_close(&ram_disk);
2041
2042 /* Determine if the test was successful. */
2043 if (status != FX_SUCCESS)
2044 {
2045
2046 printf("ERROR!\n");
2047 test_control_return(138);
2048 }
2049
2050 /* Format the media. This needs to be done before opening it! */
2051 status = fx_media_format(&ram_disk,
2052 _fx_ram_driver, // Driver entry
2053 ram_disk_memory, // RAM disk memory pointer
2054 cache_buffer, // Media buffer pointer
2055 CACHE_SIZE, // Media buffer size
2056 "MY_RAM_DISK", // Volume Name
2057 1, // Number of FATs
2058 512, // Directory Entries
2059 0, // Hidden sectors
2060 14000, // Total sectors
2061 128, // Sector size
2062 1, // Sectors per cluster
2063 1, // Heads
2064 1); // Sectors per track
2065
2066 /* Determine if the format had an error. */
2067 if (status)
2068 {
2069
2070 printf("ERROR!\n");
2071 test_control_return(139);
2072 }
2073
2074 /* Open the ram_disk. */
2075 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2076
2077 /* Check the status. */
2078 if (status != FX_SUCCESS)
2079 {
2080
2081 /* Error, return error code. */
2082 printf("ERROR!\n");
2083 test_control_return(140);
2084 }
2085
2086 /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
2087 status = fx_directory_create(&ram_disk, "SUB1");
2088 status += fx_directory_default_set(&ram_disk, "SUB1");
2089
2090 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2091 status += fx_media_flush(&ram_disk);
2092
2093 /* Check the status. */
2094 if (status != FX_SUCCESS)
2095 {
2096
2097 /* Error, return error code. */
2098 printf("ERROR!\n");
2099 test_control_return(141);
2100 }
2101
2102 /* Build a large file name. */
2103 for (i = 0; i < 255; i++)
2104 {
2105 name[i] = 'a';
2106 }
2107 name[255] = 0;
2108
2109 /* Create a large file name in the sub-directory with a FAT entry read error. */
2110 _fx_utility_fat_entry_read_error_request = 10014;
2111 status = fx_file_create(&ram_disk, name);
2112 _fx_utility_fat_entry_read_error_request = 0;
2113
2114 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2115 status += fx_media_flush(&ram_disk);
2116
2117 /* Determine if have the expected error. */
2118 if (status != FX_FILE_CORRUPT)
2119 {
2120
2121 printf("ERROR!\n");
2122 test_control_return(142);
2123 }
2124
2125 /* Close the media. */
2126 status = fx_media_close(&ram_disk);
2127
2128 /* Determine if the test was successful. */
2129 if (status != FX_SUCCESS)
2130 {
2131
2132 printf("ERROR!\n");
2133 test_control_return(143);
2134 }
2135
2136 /* Format the media. This needs to be done before opening it! */
2137 status = fx_media_format(&ram_disk,
2138 _fx_ram_driver, // Driver entry
2139 ram_disk_memory, // RAM disk memory pointer
2140 cache_buffer, // Media buffer pointer
2141 CACHE_SIZE, // Media buffer size
2142 "MY_RAM_DISK", // Volume Name
2143 1, // Number of FATs
2144 512, // Directory Entries
2145 0, // Hidden sectors
2146 14000, // Total sectors
2147 128, // Sector size
2148 1, // Sectors per cluster
2149 1, // Heads
2150 1); // Sectors per track
2151
2152 /* Determine if the format had an error. */
2153 if (status)
2154 {
2155
2156 printf("ERROR!\n");
2157 test_control_return(144);
2158 }
2159
2160 /* Open the ram_disk. */
2161 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2162
2163 /* Check the status. */
2164 if (status != FX_SUCCESS)
2165 {
2166
2167 /* Error, return error code. */
2168 printf("ERROR!\n");
2169 test_control_return(145);
2170 }
2171
2172 /* Create a sub-directory so we can generate errors writing to the sub-directory file entry. */
2173 status = fx_directory_create(&ram_disk, "SUB1");
2174 status += fx_directory_default_set(&ram_disk, "SUB1");
2175
2176 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2177 status += fx_media_flush(&ram_disk);
2178
2179 /* Check the status. */
2180 if (status != FX_SUCCESS)
2181 {
2182
2183 /* Error, return error code. */
2184 printf("ERROR!\n");
2185 test_control_return(146);
2186 }
2187
2188 /* Build a large file name. */
2189 for (i = 0; i < 255; i++)
2190 {
2191 name[i] = 'a';
2192 }
2193 name[255] = 0;
2194
2195 /* Create a large file name in the sub-directory with a FAT entry read error. */
2196 _fx_utility_fat_entry_read_error_request = 20014;
2197 status = fx_file_create(&ram_disk, name);
2198 _fx_utility_fat_entry_read_error_request = 0;
2199
2200 /* Setup an I/O error on the first logical sectory write of the directory entry. */
2201 status += fx_media_flush(&ram_disk);
2202
2203 /* Determine if have the expected error. */
2204 if (status != FX_FILE_CORRUPT)
2205 {
2206
2207 printf("ERROR!\n");
2208 test_control_return(147);
2209 }
2210
2211 /* Close the media. */
2212 status = fx_media_close(&ram_disk);
2213
2214 /* Determine if the test was successful. */
2215 if (status != FX_SUCCESS)
2216 {
2217
2218 printf("ERROR!\n");
2219 test_control_return(148);
2220 }
2221
2222 /* Format the media. This needs to be done before opening it! */
2223 status = fx_media_format(&ram_disk,
2224 _fx_ram_driver, // Driver entry
2225 ram_disk_memory, // RAM disk memory pointer
2226 cache_buffer, // Media buffer pointer
2227 CACHE_SIZE, // Media buffer size
2228 "MY_RAM_DISK", // Volume Name
2229 1, // Number of FATs
2230 10000, // Directory Entries
2231 0, // Hidden sectors
2232 64000, // Total sectors
2233 128, // Sector size
2234 1, // Sectors per cluster
2235 1, // Heads
2236 1); // Sectors per track
2237
2238 /* Determine if the format had an error. */
2239 if (status)
2240 {
2241
2242 printf("ERROR!\n");
2243 test_control_return(149);
2244 }
2245
2246 /* Open the ram_disk. */
2247 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2248
2249 /* Check the status. */
2250 if (status != FX_SUCCESS)
2251 {
2252
2253 /* Error, return error code. */
2254 printf("ERROR!\n");
2255 test_control_return(150);
2256 }
2257
2258 /* Create a file name that execises the short name with a 0xE5 and a dot less than the eighth character. */
2259 status = fx_file_create(&ram_disk, "a.a");
2260 status += fx_media_flush(&ram_disk);
2261 status += fx_media_read(&ram_disk, ram_disk.fx_media_root_sector_start, buffer);
2262 buffer[0x20] = 0x8f;
2263 buffer[0x21] = 0xe5;
2264 buffer[0x22] = '.';
2265 buffer[0x23] = 'a';
2266 buffer[0x24] = '~';
2267 status += fx_media_write(&ram_disk, ram_disk.fx_media_root_sector_start, buffer);
2268 status += fx_media_flush(&ram_disk);
2269 status += fx_directory_short_name_get(&ram_disk, "a.a", name);
2270 status += fx_file_open(&ram_disk, &file_1, "a.a", FX_OPEN_FOR_WRITE);
2271 status += fx_file_write(&file_1, "a", 1);
2272 file_1.fx_file_dir_entry.fx_dir_entry_short_name[0] = (CHAR)0xE5;
2273 status += fx_media_flush(&ram_disk);
2274 status += fx_file_close(&file_1);
2275
2276 /* Check the status. */
2277 if (status != FX_SUCCESS)
2278 {
2279
2280 /* Error, return error code. */
2281 printf("ERROR!\n");
2282 test_control_return(151);
2283 }
2284
2285 /* Create some files to test the logic in fx_directory_entry_read */
2286 status = fx_file_create(&ram_disk, "a");
2287 status += fx_directory_short_name_get(&ram_disk, "a", name);
2288 status += fx_file_create(&ram_disk, "aa");
2289 status += fx_directory_short_name_get(&ram_disk, "aa", name);
2290 status += fx_file_create(&ram_disk, "aaa");
2291 status += fx_directory_short_name_get(&ram_disk, "aaa", name);
2292 status += fx_file_create(&ram_disk, "aaaa");
2293 status += fx_directory_short_name_get(&ram_disk, "aaaa", name);
2294 status += fx_file_create(&ram_disk, "aaaaa");
2295 status += fx_directory_short_name_get(&ram_disk, "aaaaa", name);
2296 status += fx_file_create(&ram_disk, "aaaaaa");
2297 status += fx_directory_short_name_get(&ram_disk, "aaaaaa", name);
2298 status += fx_file_create(&ram_disk, "aaaaaaa");
2299 status += fx_directory_short_name_get(&ram_disk, "aaaaaaa", name);
2300 status += fx_file_create(&ram_disk, "aaaaaaaa");
2301 status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa", name);
2302 status += fx_file_create(&ram_disk, "aaaaaaaa.a");
2303 status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.a", name);
2304 status += fx_file_create(&ram_disk, "aaaaaaaa.aa");
2305 status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.aa", name);
2306 status += fx_file_create(&ram_disk, "aaaaaaaa.aaa");
2307 status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.aaa", name);
2308 status += fx_file_create(&ram_disk, "a.");
2309 status += fx_directory_short_name_get(&ram_disk, "a.", name);
2310 status += fx_file_create(&ram_disk, "aa.");
2311 status += fx_directory_short_name_get(&ram_disk, "aa.", name);
2312 status += fx_file_create(&ram_disk, "aaa.");
2313 status += fx_directory_short_name_get(&ram_disk, "aaa.", name);
2314 status += fx_file_create(&ram_disk, "aaaa.");
2315 status += fx_directory_short_name_get(&ram_disk, "aaaa.", name);
2316 status += fx_file_create(&ram_disk, "aaaaa.");
2317 status += fx_directory_short_name_get(&ram_disk, "aaaaa.", name);
2318 status += fx_file_create(&ram_disk, "aaaaaa.");
2319 status += fx_directory_short_name_get(&ram_disk, "aaaaaa.", name);
2320 status += fx_file_create(&ram_disk, "aaaaaaa.");
2321 status += fx_directory_short_name_get(&ram_disk, "aaaaaaa.", name);
2322 status += fx_file_create(&ram_disk, "aaaaaaaa.");
2323 status += fx_directory_short_name_get(&ram_disk, "aaaaaaaa.", name);
2324 status += fx_file_delete(&ram_disk, "aaaaaa.");
2325 status += fx_file_delete(&ram_disk, "aaaaaaa.");
2326 status += fx_file_delete(&ram_disk, "aaaaaaaa.");
2327
2328 /* Create a name with an 0xe5 in the front. */
2329 name[0] = (CHAR)0xE5;
2330 name[1] = 'a';
2331 name[2] = 'b';
2332 name[3] = '.';
2333 name[4] = 't';
2334 name[5] = 'x';
2335 name[6] = 't';
2336 name[7] = 0;
2337 status += fx_file_create(&ram_disk, name);
2338 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2339 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2340 status += fx_file_write(&file_1, "1", 1);
2341 status += fx_file_close(&file_1);
2342
2343 status += fx_file_create(&ram_disk, "abcdefgh.txt");
2344 status += fx_directory_short_name_get(&ram_disk, "abcdefgh.txt", (CHAR *)buffer);
2345 status += fx_file_open(&ram_disk, &file_1, "abcdefgh.txt", FX_OPEN_FOR_WRITE);
2346 status += fx_file_write(&file_1, "1", 1);
2347 status += fx_file_close(&file_1);
2348
2349 #if EXTENDED_NAME_MANGLE_TEST
2350 name[0] = 'a';
2351 name[1] = 'B';
2352 name[2] = 'C';
2353 name[3] = 'D';
2354 name[4] = 'E';
2355 name[5] = 'F';
2356 name[6] = 'G';
2357 name[7] = '0';
2358 name[8] = '0';
2359 name[9] = '0';
2360 name[10] = '0';
2361 name[11] = 0;
2362 for (i = 0; i < 3; i++)
2363 {
2364
2365 name[7] = '0' + i;
2366
2367 for (j = 0; j < 10; j++)
2368 {
2369
2370 name[8] = '0' + j;
2371
2372 for (k = 0; k < 10; k++)
2373 {
2374
2375 name[9] = '0' + k;
2376
2377 for (l = 0; l < 10; l++)
2378 {
2379 if (status)
2380 break;
2381 name[10] = '0' + l;
2382 status += fx_file_create(&ram_disk, name);
2383 if (status)
2384 break;
2385 status += fx_directory_short_name_get(&ram_disk, name, buffer);
2386 if (status)
2387 break;
2388 }
2389 }
2390 }
2391 }
2392 #endif
2393 /* Check the status. */
2394 if (status != FX_SUCCESS)
2395 {
2396
2397 /* Error, return error code. */
2398 printf("ERROR!\n");
2399 test_control_return(152);
2400 }
2401
2402 /* Close the media. */
2403 status = fx_media_close(&ram_disk);
2404
2405 /* Determine if the test was successful. */
2406 if (status != FX_SUCCESS)
2407 {
2408
2409 printf("ERROR!\n");
2410 test_control_return(153);
2411 }
2412
2413
2414 /* Test corner cases on fx_directory_search. */
2415
2416 /* Format the media. This needs to be done before opening it! */
2417 status = fx_media_format(&ram_disk,
2418 _fx_ram_driver, // Driver entry
2419 ram_disk_memory, // RAM disk memory pointer
2420 cache_buffer, // Media buffer pointer
2421 CACHE_SIZE, // Media buffer size
2422 "MY_RAM_DISK", // Volume Name
2423 1, // Number of FATs
2424 256, // Directory Entries
2425 0, // Hidden sectors
2426 14000, // Total sectors
2427 128, // Sector size
2428 1, // Sectors per cluster
2429 1, // Heads
2430 1); // Sectors per track
2431
2432 /* Determine if the format had an error. */
2433 if (status)
2434 {
2435
2436 printf("ERROR!\n");
2437 test_control_return(154);
2438 }
2439
2440 /* Open the ram_disk. */
2441 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2442
2443 /* Check the status. */
2444 if (status != FX_SUCCESS)
2445 {
2446
2447 /* Error, return error code. */
2448 printf("ERROR!\n");
2449 test_control_return(155);
2450 }
2451
2452 /* Build a long directory structure. */
2453 status = fx_directory_create(&ram_disk, "/sub-directory_depth_00001");
2454 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002");
2455 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003");
2456 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004");
2457 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005");
2458 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006");
2459 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007");
2460 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008");
2461 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009");
2462 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010");
2463 status += fx_directory_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011");
2464 status += fx_file_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt");
2465 status += fx_file_open(&ram_disk, &file_1, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt", FX_OPEN_FOR_WRITE);
2466
2467 /* Now create an invalid path by using a file as a directory entry. */
2468 status += fx_file_create(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file1.txt/baddir");
2469
2470 /* Determine if the test was successful. */
2471 if (status != FX_INVALID_PATH)
2472 {
2473
2474 printf("ERROR!\n");
2475 test_control_return(156);
2476 }
2477
2478 status = fx_file_create(&ram_disk, "/sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file2.txt");
2479 status += fx_file_open(&ram_disk, &file_2, "/sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011/file2.txt", FX_OPEN_FOR_WRITE);
2480 status += fx_directory_default_set(&ram_disk, "sub-directory_depth_00001/sub-directory_depth_00002/sub-directory_depth_00003/sub-directory_depth_00004/sub-directory_depth_00005/sub-directory_depth_00006/sub-directory_depth_00007/sub-directory_depth_00008/sub-directory_depth_00009/sub-directory_depth_00010/sub-directory_depth_00011");
2481 status += fx_directory_first_entry_find(&ram_disk, name);
2482 status += fx_directory_next_entry_find(&ram_disk, name);
2483 status += fx_directory_next_entry_find(&ram_disk, name);
2484 status += fx_directory_next_entry_find(&ram_disk, name);
2485
2486 /* Close the media. */
2487 status += fx_media_close(&ram_disk);
2488
2489 /* Determine if the test was successful. */
2490 if (status != FX_SUCCESS)
2491 {
2492
2493 printf("ERROR!\n");
2494 test_control_return(157);
2495 }
2496
2497 /* Format the media. This needs to be done before opening it! */
2498 status = fx_media_format(&ram_disk,
2499 _fx_ram_driver, // Driver entry
2500 ram_disk_memory, // RAM disk memory pointer
2501 cache_buffer, // Media buffer pointer
2502 CACHE_SIZE, // Media buffer size
2503 "MY_RAM_DISK", // Volume Name
2504 1, // Number of FATs
2505 256, // Directory Entries
2506 0, // Hidden sectors
2507 14000, // Total sectors
2508 128, // Sector size
2509 1, // Sectors per cluster
2510 1, // Heads
2511 1); // Sectors per track
2512
2513 /* Determine if the format had an error. */
2514 if (status)
2515 {
2516
2517 printf("ERROR!\n");
2518 test_control_return(158);
2519 }
2520
2521 /* Open the ram_disk. */
2522 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2523
2524 /* Check the status. */
2525 if (status != FX_SUCCESS)
2526 {
2527
2528 /* Error, return error code. */
2529 printf("ERROR!\n");
2530 test_control_return(159);
2531 }
2532
2533 /* Build a long sub-directory name... This name will be too long to cache in fx_directory_search. */
2534 for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
2535 {
2536 name[i] = 'a';
2537 }
2538 name[0] = '/';
2539 name[256] = 0;
2540
2541 status = fx_directory_create(&ram_disk, name);
2542
2543 name[256] = '/';
2544 name[257] = 'f';
2545 name[258] = 'i';
2546 name[259] = 'l';
2547 name[260] = 'e';
2548 name[261] = 0;
2549
2550 status += fx_file_create(&ram_disk, name);
2551 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2552 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2553 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2554 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2555 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2556 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2557 status += fx_file_close(&file_1);
2558 status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
2559 status += fx_file_close(&file_1);
2560 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2561 status += fx_file_close(&file_1);
2562 status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
2563 status += fx_file_close(&file_1);
2564 status += fx_file_delete(&ram_disk, name);
2565
2566 /* Build a perfect fit long sub-directory name and file name... This name will fit exactly into the fx_directory_search cache. */
2567 for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
2568 {
2569 name[i] = 'a';
2570 }
2571 name[0] = '/';
2572 name[250] = 0;
2573
2574 status += fx_directory_create(&ram_disk, name);
2575
2576 name[250] = '/';
2577 name[251] = 'f';
2578 name[252] = 'i';
2579 name[253] = 'l';
2580 name[254] = 'e';
2581 name[255] = 0;
2582
2583 status = fx_file_create(&ram_disk, name);
2584 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2585 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2586 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2587 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2588 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2589 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2590 status += fx_file_close(&file_1);
2591 status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
2592 status += fx_file_close(&file_1);
2593 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2594 status += fx_file_close(&file_1);
2595 status += fx_file_open(&ram_disk, &file_1, &name[1], FX_OPEN_FOR_WRITE);
2596 status += fx_file_close(&file_1);
2597 status = fx_file_delete(&ram_disk, name);
2598
2599
2600 /* Close the media. */
2601 status = fx_media_close(&ram_disk);
2602
2603 /* Determine if the test was successful. */
2604 if (status != FX_SUCCESS)
2605 {
2606
2607 printf("ERROR!\n");
2608 test_control_return(160);
2609 }
2610
2611
2612 /* Format the media. This needs to be done before opening it! */
2613 status = fx_media_format(&ram_disk,
2614 _fx_ram_driver, // Driver entry
2615 ram_disk_memory, // RAM disk memory pointer
2616 cache_buffer, // Media buffer pointer
2617 CACHE_SIZE, // Media buffer size
2618 "MY_RAM_DISK", // Volume Name
2619 1, // Number of FATs
2620 256, // Directory Entries
2621 0, // Hidden sectors
2622 14000, // Total sectors
2623 128, // Sector size
2624 1, // Sectors per cluster
2625 1, // Heads
2626 1); // Sectors per track
2627
2628 /* Determine if the format had an error. */
2629 if (status)
2630 {
2631
2632 printf("ERROR!\n");
2633 test_control_return(161);
2634 }
2635
2636 /* Open the ram_disk. */
2637 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2638
2639 /* Check the status. */
2640 if (status != FX_SUCCESS)
2641 {
2642
2643 /* Error, return error code. */
2644 printf("ERROR!\n");
2645 test_control_return(162);
2646 }
2647
2648
2649 /* Build a perfect fit long sub-directory name and file name... This name will fit exactly into the fx_directory_search cache. */
2650 for (i = 0; i < FX_MAX_LONG_NAME_LEN; i++)
2651 {
2652 name[i] = 'a';
2653 }
2654 name[0] = '/';
2655 name[255] = 0;
2656 status += fx_directory_create(&ram_disk, name);
2657
2658
2659 name[253] = 0;
2660
2661 status += fx_directory_create(&ram_disk, name);
2662
2663 name[253] = '/';
2664 name[254] = 'a';
2665 name[255] = 0;
2666
2667 status = fx_file_create(&ram_disk, name);
2668 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2669 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2670 status += fx_file_close(&file_1);
2671
2672 /* Setup info for direct call to directory search. */
2673 dir_entry.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
2674 search_directory.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN * 2;
2675 dir_entry.fx_dir_entry_short_name[0] = 0;
2676 search_directory.fx_dir_entry_short_name[0] = 0;
2677
2678 /* Lets make the name bigger than the maximun name. */
2679 name[255] = 'a';
2680 name[256] = 'a';
2681 name[257] = 'a';
2682 name[258] = 'a';
2683 name[259] = 0;
2684 _fx_directory_search(&ram_disk, name, &dir_entry, &search_directory, &name_ptr);
2685
2686
2687 /* Set the name back to the original size. */
2688 name[255] = 0;
2689 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2690 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2691 status += fx_file_close(&file_1);
2692
2693 /* Now make the name long again to test relative, no path. */
2694 name[255] = 'a';
2695
2696 /* Now let's perform a maximum relative search. */
2697 _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
2698
2699
2700 /* Now lets set a path and test that out. */
2701 name[253] = 0;
2702 status += fx_directory_default_set(&ram_disk, name);
2703
2704 /* Now set the name back to the original size. */
2705 name[253] = '/';
2706 name[255] = 0;
2707
2708 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2709 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2710 status += fx_file_close(&file_1);
2711
2712 /* Now make the name long again to test relative, with path. */
2713 name[255] = 'a';
2714
2715 /* Now let's perform a maximum relative search. */
2716 _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
2717
2718 /* Now lets set a path, modify the found path and test that out. */
2719 name[253] = 'a';
2720 name[254] = 'a';
2721 name[255] = 0;
2722 status += fx_directory_default_set(&ram_disk, name);
2723
2724 /* Now set the name back to the original size. */
2725 name[253] = '/';
2726 name[255] = 0;
2727
2728 status += fx_file_open(&ram_disk, &file_1, name, FX_OPEN_FOR_WRITE);
2729 status += fx_directory_short_name_get(&ram_disk, name, (CHAR *)buffer);
2730 status += fx_file_close(&file_1);
2731
2732 /* Test the maximum size of the default path lookup. */
2733 for (i = 0; i < 256; i++)
2734 {
2735 ram_disk.fx_media_last_found_name[i] = ram_disk.fx_media_default_path.fx_path_name_buffer[i];
2736 }
2737 ram_disk.fx_media_last_found_name[0] = '/';
2738 name[255] = 'a';
2739 name[256] = 0;
2740
2741 /* Now let's perform a maximum relative search. */
2742 _fx_directory_search(&ram_disk, &name[1], &dir_entry, &search_directory, &name_ptr);
2743
2744 /* Now let's setup a directory search with a NULL path, a maximum found file name, and alternate directory separators. */
2745 ram_disk.fx_media_default_path.fx_path_name_buffer[0] = 0;
2746 strcpy(&ram_disk.fx_media_last_found_name[0], "\\abc\\def\\ghi\\abc");
2747 for (i = 0; i < 256; i++)
2748 {
2749 ram_disk.fx_media_last_found_file_name[i] = 'a';
2750 ram_disk.fx_media_last_found_directory.fx_dir_entry_name[i] = 'a';
2751 }
2752 ram_disk.fx_media_last_found_file_name[255] = 0;
2753 ram_disk.fx_media_last_found_directory.fx_dir_entry_name[255] = 0;
2754 ram_disk.fx_media_last_found_directory_valid = FX_TRUE;
2755 _fx_directory_search(&ram_disk, "abc\\def\\ghi\\abc", &dir_entry, &search_directory, &name_ptr);
2756
2757 /* Now let's setup a directory search with a NULL path, a medium sized found file name, and alternate directory separators. */
2758 ram_disk.fx_media_default_path.fx_path_name_buffer[0] = 0;
2759 strcpy(&ram_disk.fx_media_last_found_name[0], "\\abc\\def\\ghi\\abc");
2760 for (i = 0; i < 256; i++)
2761 {
2762 ram_disk.fx_media_last_found_file_name[i] = 'a';
2763 ram_disk.fx_media_last_found_directory.fx_dir_entry_name[i] = 'a';
2764 }
2765 ram_disk.fx_media_last_found_file_name[255] = 0;
2766 ram_disk.fx_media_last_found_directory.fx_dir_entry_name[25] = 0;
2767 ram_disk.fx_media_last_found_directory_valid = FX_TRUE;
2768 _fx_directory_search(&ram_disk, "abc\\def\\ghi\\abc", &dir_entry, &search_directory, &name_ptr);
2769
2770
2771 /* Close the media. */
2772 status = fx_media_close(&ram_disk);
2773
2774 /* Determine if the test was successful. */
2775 if (status != FX_SUCCESS)
2776 {
2777
2778 printf("ERROR!\n");
2779 test_control_return(163);
2780 }
2781
2782
2783 /* Format the media. This needs to be done before opening it! */
2784 status = fx_media_format(&ram_disk,
2785 _fx_ram_driver, // Driver entry
2786 ram_disk_memory, // RAM disk memory pointer
2787 cache_buffer, // Media buffer pointer
2788 CACHE_SIZE, // Media buffer size
2789 "MY_RAM_DISK", // Volume Name
2790 1, // Number of FATs
2791 256, // Directory Entries
2792 0, // Hidden sectors
2793 14000, // Total sectors
2794 128, // Sector size
2795 1, // Sectors per cluster
2796 1, // Heads
2797 1); // Sectors per track
2798
2799 /* Determine if the format had an error. */
2800 if (status)
2801 {
2802
2803 printf("ERROR!\n");
2804 test_control_return(164);
2805 }
2806
2807 /* Open the ram_disk. */
2808 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2809
2810 /* Check the status. */
2811 if (status != FX_SUCCESS)
2812 {
2813
2814 /* Error, return error code. */
2815 printf("ERROR!\n");
2816 test_control_return(165);
2817 }
2818
2819 /* Create a directory path. */
2820 status = fx_directory_create(&ram_disk, "/abc");
2821 status += fx_directory_create(&ram_disk, "/abc/def");
2822 status += fx_directory_create(&ram_disk, "/abc/def/ghi");
2823 status += fx_directory_create(&ram_disk, "/abc/def/ghi/jkl");
2824 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file.txt");
2825 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file2.txt");
2826 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file3.txt");
2827 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file4.txt");
2828 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file5.txt");
2829 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file6.txt");
2830 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file7.txt");
2831 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file8.txt");
2832 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file9.txt");
2833 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file10.txt");
2834 status += fx_file_create(&ram_disk, "/abc/def/ghi/jkl/file11.txt");
2835 status += fx_directory_default_set(&ram_disk, "/abc");
2836 status += fx_directory_first_entry_find(&ram_disk, name);
2837
2838 /* Now open the file to get it into the search cache. */
2839 status += fx_file_open(&ram_disk, &file_1, "/abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
2840 status += fx_file_close(&file_1);
2841 status += fx_file_open(&ram_disk, &file_1, "/abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
2842 status += fx_file_close(&file_1);
2843 status += fx_file_open(&ram_disk, &file_1, "def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
2844 status += fx_file_close(&file_1);
2845 status += fx_directory_default_set(&ram_disk, "/");
2846 status += fx_file_open(&ram_disk, &file_1, "abc/def/ghi/jkl/file.txt", FX_OPEN_FOR_WRITE);
2847 status += fx_file_close(&file_1);
2848 status += fx_directory_next_entry_find(&ram_disk, name);
2849
2850 /* Now test for FAT read errors. */
2851 _fx_utility_fat_entry_read_error_request = 1;
2852 status += fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
2853 _fx_utility_fat_entry_read_error_request = 0;
2854
2855 /* Check the status... should be an I/O error at this point. */
2856 if (status != FX_IO_ERROR)
2857 {
2858
2859 /* Error, return error code. */
2860 printf("ERROR!\n");
2861 test_control_return(166);
2862 }
2863
2864 /* Now test a FAT entry value that is too small. */
2865 _fx_utility_fat_entry_read_error_request = 10001;
2866 status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
2867 _fx_utility_fat_entry_read_error_request = 0;
2868
2869 /* Check the status... should be a FAT read error. */
2870 if (status != FX_FAT_READ_ERROR)
2871 {
2872
2873 /* Error, return error code. */
2874 printf("ERROR!\n");
2875 test_control_return(167);
2876 }
2877
2878 /* Now test a FAT entry value that is too large. */
2879 temp = ram_disk.fx_media_total_clusters;
2880 _fx_utility_fat_entry_read_error_request = 40001;
2881 status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
2882 _fx_utility_fat_entry_read_error_request = 0;
2883 ram_disk.fx_media_total_clusters = temp;
2884
2885 /* Check the status... should be a FAT read error. */
2886 if (status != FX_FAT_READ_ERROR)
2887 {
2888
2889 /* Error, return error code. */
2890 printf("ERROR!\n");
2891 test_control_return(168);
2892 }
2893
2894 /* Now test a FAT entry value that is the same as the cluster itself. */
2895 _fx_utility_fat_entry_read_error_request = 30001;
2896 status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
2897 _fx_utility_fat_entry_read_error_request = 0;
2898
2899 /* Check the status... should be a FAT read error. */
2900 if (status != FX_FAT_READ_ERROR)
2901 {
2902
2903 /* Error, return error code. */
2904 printf("ERROR!\n");
2905 test_control_return(169);
2906 }
2907
2908 /* Now perform a good open. */
2909 status = fx_file_open(&ram_disk, &file_2, "abc/def/ghi/jkl/file2.txt", FX_OPEN_FOR_WRITE);
2910 status += fx_file_close(&file_2);
2911
2912 /* Check the status. */
2913 if (status != FX_SUCCESS)
2914 {
2915
2916 /* Error, return error code. */
2917 printf("ERROR!\n");
2918 test_control_return(166);
2919 }
2920
2921 /* Setup info for direct call to directory search. */
2922 dir_entry.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
2923 search_directory.fx_dir_entry_name = ram_disk.fx_media_name_buffer + FX_MAX_LONG_NAME_LEN * 2;
2924 dir_entry.fx_dir_entry_short_name[0] = 0;
2925 search_directory.fx_dir_entry_short_name[0] = 0;
2926
2927 /* Lets perform a search that from the root directory. */
2928 _fx_directory_search(&ram_disk, "/abc/..", &dir_entry, &search_directory, &name_ptr);
2929
2930 /* Now setup a maximum default path. */
2931 for (i = 0; i < FX_MAX_LAST_NAME_LEN; i++)
2932 {
2933 name[i] = 'a';
2934 }
2935 name[255] = 0;
2936
2937 /* Create a sub-directory of maximum lenght. */
2938 status = fx_directory_create(&ram_disk, name);
2939
2940 /* Set the default path to this name. */
2941 status += fx_directory_default_set(&ram_disk, name);
2942
2943 /* Create a file in the sub-directory path. */
2944 status += fx_file_create(&ram_disk, "file1.txt");
2945
2946 /* Open the file to test the directory search cache name build. */
2947 status += fx_file_open(&ram_disk, &file_1, "file1.txt", FX_OPEN_FOR_WRITE);
2948
2949 /* Determine if the test was successful. */
2950 if (status != FX_SUCCESS)
2951 {
2952
2953 printf("ERROR!\n");
2954 test_control_return(167);
2955 }
2956
2957
2958 /* Close the media. */
2959 status = fx_media_close(&ram_disk);
2960 if (status != FX_SUCCESS)
2961 {
2962
2963 printf("ERROR!\n");
2964 test_control_return(168);
2965 }
2966
2967 /* Test for https://github.com/azure-rtos/filex/issues/26 */
2968 /* Format the media. This needs to be done before opening it! */
2969 status = fx_media_format(&ram_disk,
2970 _fx_ram_driver, // Driver entry
2971 ram_disk_memory, // RAM disk memory pointer
2972 cache_buffer, // Media buffer pointer
2973 CACHE_SIZE, // Media buffer size
2974 "MY_RAM_DISK", // Volume Name
2975 1, // Number of FATs
2976 4, // Directory Entries
2977 0, // Hidden sectors
2978 128, // Total sectors
2979 128, // Sector size
2980 1, // Sectors per cluster
2981 1, // Heads
2982 1); // Sectors per track
2983 return_if_fail( status == FX_SUCCESS);
2984
2985 /* Open the ram_disk. */
2986 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
2987 return_if_fail( status == FX_SUCCESS);
2988
2989 FX_FILE my_file;
2990 ULONG available_clusters;
2991 uint8_t buff[128];
2992 int num_of_files = 0;
2993 char dummy_file_path[DIR_PATH_SIZE + 3];
2994 memcpy(dummy_file_path, DIR_PATH, DIR_PATH_SIZE);
2995 /* Create a file called TEST.TXT.*/
2996
2997 status += fx_directory_create(&ram_disk, "/MYDIR");
2998 status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1");
2999 status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2");
3000 status += fx_directory_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3");
3001 return_if_fail( status == FX_SUCCESS);
3002
3003 status = fx_file_create(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT");
3004 return_if_fail( status == FX_SUCCESS);
3005
3006 available_clusters = ram_disk.fx_media_available_clusters;
3007 /*
3008 * Ensure there is no spare space in the cluster used for the directory
3009 */
3010 dummy_file_path[sizeof(DIR_PATH) - 1] = 'A';
3011 dummy_file_path[sizeof(DIR_PATH)] = '\0';
3012 for (num_of_files = 0; available_clusters == ram_disk.fx_media_available_clusters; num_of_files ++)
3013 {
3014 dummy_file_path[sizeof(DIR_PATH) - 1] ++;
3015 status = fx_file_create(&ram_disk, dummy_file_path);
3016 return_if_fail( status == FX_SUCCESS);
3017 }
3018 // remove the file that allocated new cluster
3019 status = fx_file_delete(&ram_disk, dummy_file_path);
3020 return_if_fail( status == FX_SUCCESS);
3021
3022 /* Open the test file. */
3023 status = fx_file_open(&ram_disk, &my_file, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT", FX_OPEN_FOR_WRITE);
3024 return_if_fail( status == FX_SUCCESS);
3025
3026 available_clusters = ram_disk.fx_media_available_clusters;
3027 for (int i = 0; i < available_clusters - 1; i++)
3028 {
3029 /* Write a one cluster size to the test file. */
3030 status = fx_file_write(&my_file, buff, sizeof(buff));
3031 return_if_fail( status == FX_SUCCESS);
3032 }
3033
3034 /* The dir entry should be created on new cluster */
3035 status =fx_file_rename(&ram_disk, "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST.TXT", "MYDIR/MYDIR1/MYDIR2/MYDIR3/TEST_RENAME.TXT");
3036 return_if_fail (status == FX_SUCCESS);
3037
3038 return_if_fail(ram_disk.fx_media_available_clusters == 0);
3039
3040 /* Close the media. */
3041 status = fx_media_close(&ram_disk);
3042 /* Determine if the test was successful. */
3043 if (status != FX_SUCCESS)
3044 {
3045
3046 printf("ERROR!\n");
3047 test_control_return(169);
3048 }
3049 else
3050 {
3051
3052 printf("SUCCESS!\n");
3053 test_control_return(0);
3054 }
3055 }
3056
3057