1 #ifndef FX_STANDALONE_ENABLE
2 #include "tx_api.h"
3 #include "tx_thread.h"
4 #endif
5 #include "fx_api.h"
6 #include "fx_utility.h"
7 #include "fx_ram_driver_test.h"
8 #include <stdio.h>
9 #include <string.h>
10
11 #define DEMO_STACK_SIZE 8192
12 /* Set the cache size as the size of one sector causing frequently IO operation. */
13 #define CACHE_SIZE 128
14
15 /* Define the global variable we may use in the future. */
16 extern ULONG _fx_ram_driver_copy_default_format;
17 extern UCHAR large_file_name_format[];
18
19 /* Define the ThreadX and FileX object control blocks... */
20
21 #ifndef FX_STANDALONE_ENABLE
22 static TX_THREAD ftest_0;
23 #endif
24 static FX_MEDIA ram_disk;
25
26 /* Define the counters used in the test application... */
27
28 #ifndef FX_STANDALONE_ENABLE
29 static UCHAR *ram_disk_memory;
30 static UCHAR *cache_buffer;
31 #else
32 static UCHAR cache_buffer[CACHE_SIZE];
33 #endif
34
35 /* Define thread prototypes. */
36
37 void filex_unicode_4_application_define(void *first_unused_memory);
38 static void ftest_0_entry(ULONG thread_input);
39
40 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
41 void test_control_return(UINT status);
42
43 /* Define what the initial system looks like. */
44
45 #ifdef CTEST
test_application_define(void * first_unused_memory)46 void test_application_define(void *first_unused_memory)
47 #else
48 void filex_unicode_4_application_define(void *first_unused_memory)
49 #endif
50 {
51
52 #ifndef FX_STANDALONE_ENABLE
53 UCHAR *pointer;
54
55
56 /* Setup the working pointer. */
57 pointer = (UCHAR *)first_unused_memory;
58
59 /* Create the main thread. */
60 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
61 pointer, DEMO_STACK_SIZE,
62 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
63
64 pointer = pointer + DEMO_STACK_SIZE;
65
66 /* Setup memory for the RAM disk and the sector cache. */
67 cache_buffer = pointer;
68 pointer = pointer + CACHE_SIZE;
69 ram_disk_memory = pointer;
70
71 #endif
72
73 /* Initialize the FileX system. */
74 fx_system_initialize();
75 #ifdef FX_STANDALONE_ENABLE
76 ftest_0_entry(0);
77 #endif
78 }
79
80 static UCHAR long_unicode_name1[] = { 1, 0, 0, 0 };
81 static UCHAR ascii_file_name[] = { 'a', 'b', 'c', 0 };
82 static UCHAR specified_ascii_file_name[] = { 'Z', '1', '2', '3', '4', '5', '6', '7', '.', 't', 'x', 't', 0 };
83 static UCHAR specified_unicode_file_name[] = { 'Z', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, 0 };
84 static UCHAR specified_unicode_file_name_1[] = { 'a', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, 0 };
85
86 #ifndef FX_DISABLE_ERROR_CHECKING
87 static UCHAR specified_unicode_file_name_2[] = { 'a', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 0, 't', 0, 0 };
88 #endif /* FX_DISABLE_ERROR_CHECKING */
89
90 /* Define the test threads. */
91
ftest_0_entry(ULONG thread_input)92 static void ftest_0_entry(ULONG thread_input)
93 {
94
95 UINT status, length, count;
96 #ifndef FX_DISABLE_ERROR_CHECKING
97 UINT new_length, old_length;
98 #endif /* FX_DISABLE_ERROR_CHECKING */
99 ULONG ulength;
100 UCHAR destination_name[128];
101 UCHAR destination_name_1[128];
102 UCHAR temp, temp_array[32];
103 FX_LOCAL_PATH local_path;
104 FX_FILE my_file;
105
106 FX_PARAMETER_NOT_USED(thread_input);
107
108 /* Print out some test information banners. */
109 printf("FileX Test: Unicode 4 test.........................................");
110
111 /* Format the media. This needs to be done before opening it! */
112 status = fx_media_format(&ram_disk,
113 _fx_ram_driver, // Driver entry
114 ram_disk_memory_large, // RAM disk memory pointer
115 cache_buffer, // Media buffer pointer
116 128, // Media buffer size
117 "MY_RAM_DISK", // Volume Name
118 1, // Number of FATs
119 32, // Directory Entries
120 0, // Hidden sectors
121 70000, // Total sectors
122 128, // Sector size
123 1, // Sectors per cluster
124 1, // Heads
125 1); // Sectors per track
126
127 return_value_if_fail(status == FX_SUCCESS, 2);
128 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
129 return_value_if_fail(status == FX_SUCCESS, 3);
130
131 // Create a file whose name's first byte is 0xe5.
132 ascii_file_name[0] = 0xe5;
133 status = fx_file_create(&ram_disk, (CHAR *)ascii_file_name);
134 return_value_if_fail(status == FX_SUCCESS, 4);
135
136 // Attempt to create a unicode file which make fx_unicode_file_create call fx_unicode_directory_search to scan the directory before creation.
137 // The file we just created will be read during the scannning so that the branch at Line 290 in fx_unicode_directory_search will be covered.
138 length = fx_unicode_length_get(long_unicode_name1);
139 status = fx_unicode_file_create(&ram_disk, long_unicode_name1, length, (CHAR *)destination_name);
140 return_value_if_fail(status == FX_SUCCESS, 5);
141
142 // Attempt to create two 8.3 format file by both fx_file_create and fx_unicode_file_create to cover the branch at Line 324 in fx_unicode_directory_search.c
143 status = fx_file_create(&ram_disk, (CHAR *)specified_ascii_file_name);
144 return_value_if_fail(status == FX_SUCCESS, 6);
145
146 length = fx_unicode_length_get(specified_unicode_file_name);
147 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
148 return_value_if_fail(status == FX_ALREADY_CREATED, 7);
149
150 // Add test code to cover the branch at Line 146 in fx_unicode_directory_search.c
151 ascii_file_name[0] = 'a';
152 status = fx_directory_create(&ram_disk, (CHAR *)ascii_file_name);
153 #ifndef FX_STANDALONE_ENABLE
154 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)ascii_file_name);
155 #else
156 status = fx_directory_default_set(&ram_disk, (CHAR *)ascii_file_name);
157 #endif
158 return_value_if_fail(status == FX_SUCCESS, 8);
159
160 // Clear the name of current directory.
161 #ifndef FX_STANDALONE_ENABLE
162 ((FX_PATH*)_tx_thread_current_ptr->tx_thread_filex_ptr)->fx_path_directory.fx_dir_entry_name[0] = 0;
163 #else
164 status = fx_directory_default_set(&ram_disk, "\\");
165 #endif
166
167 // The file is attempted to be created in the root directory, so it will fail.
168 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
169 return_value_if_fail(status == FX_ALREADY_CREATED, 9);
170
171 status = fx_media_close(&ram_disk);
172 return_value_if_fail(status == FX_SUCCESS, 10);
173
174 /* Open the ram_disk in fx_ram_dirver_test.c which contain a long file name dir_entry associated with a free short name entry. */
175 _fx_ram_driver_copy_default_format = 1;
176 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
177 return_value_if_fail(status == FX_SUCCESS, 11);
178 _fx_ram_driver_copy_default_format = 0;
179
180 /* Cover the branch around Line 608 in fx_unicode_directory_entry_read.c. */
181 length = fx_unicode_length_get(specified_unicode_file_name);
182 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
183 return_value_if_fail(status == FX_SUCCESS, 12);
184
185 /* Create a 8.3 format volume dirctory entry. */
186 status = fx_media_volume_set(&ram_disk, " . ");
187 return_value_if_fail(status == FX_SUCCESS, 13);
188
189 /* Access our directory to cover the branch at Line 587 in fx_unicode_direcotry_entry_read. */
190 length = fx_unicode_length_get(specified_unicode_file_name);
191 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
192 return_value_if_fail(status == FX_ALREADY_CREATED, 14);
193
194 /* Create format volume dirctory entry with 11 blanks. */
195 status = fx_media_volume_set(&ram_disk, " ");
196 return_value_if_fail(status == FX_SUCCESS, 15);
197
198 /* Access our directory to cover the branch at Line 619 in fx_unicode_direcotry_entry_read. */
199 length = fx_unicode_length_get(specified_unicode_file_name);
200 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
201 return_value_if_fail(status == FX_ALREADY_CREATED, 16);
202
203 /* Changed first byte as lowercase. */
204 specified_unicode_file_name[0] = 'z';
205 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name, length, (CHAR *)destination_name);
206 return_value_if_fail(status == FX_ALREADY_CREATED, 17);
207
208 /* Create a file whose name is begin with 'a'. */
209 length = fx_unicode_length_get(specified_unicode_file_name_1);
210 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_1, length, (CHAR *)destination_name);
211 return_value_if_fail(status == FX_SUCCESS, 18);
212
213 /* Changed first byte as uppercase. */
214 specified_unicode_file_name_1[0] = 'A';
215 length = fx_unicode_length_get(specified_unicode_file_name_1);
216 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_1, length, (CHAR *)destination_name);
217 return_value_if_fail(status == FX_ALREADY_CREATED, 19);
218
219 /* Reuse our disk in fx_ram_driver_test.c to create a set of corrupt dir_entries include a normal dir_entry associated with a specified one whose first byte is 0. */
220 status = fx_media_close(&ram_disk);
221 _fx_ram_driver_copy_default_format = 1;
222
223 /* Modify the first byte at Line 1738 in fx_ram_driver_test.c. */
224 temp = large_file_name_format[(1738 - 852) * 16];
225 large_file_name_format[(1738 - 852) * 16] = 0x00;
226
227 /* Modify the first dir_entry, which used to be the first short name dir_entry in the directory, to be the long name of "NT-FILE~.TXT". */
228 for (count = 0; count < 32; count++)
229 {
230 temp_array[count] = large_file_name_format[(1732 - 852) * 16 + count];
231 large_file_name_format[(1732 - 852) * 16 + count] = large_file_name_format[(1736 - 852) * 16 + count];
232 }
233 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
234 return_value_if_fail(status == FX_SUCCESS, 20);
235
236 /* Revert all we done. */
237 _fx_ram_driver_copy_default_format = 0;
238 large_file_name_format[(1738 - 852) * 16] = temp;
239 for (count = 0; count < 32; count++)
240 {
241 large_file_name_format[(1732 - 852) * 16 + count] = temp_array[count];
242 }
243
244 /* Access the dir_entry we just modified by fx_unicode_name_get. */
245 status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TXTa", destination_name_1, &ulength);
246 return_value_if_fail(status == FX_NOT_FOUND, 21);
247 status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TXT", destination_name_1, &ulength);
248 return_value_if_fail(status == FX_SUCCESS, 31);
249 status = fx_unicode_name_get(&ram_disk, "NT-FILE~.TX", destination_name_1, &ulength);
250 return_value_if_fail(status == FX_NOT_FOUND, 32);
251
252 /* Show special performance in our implement. Althought we assign the first byte of some short name dir_entry as 0, fx_unicode_directory_search consider the long file name return by fx_unicode_directory_entry_read as short name so that we will succeed. */
253 status = fx_unicode_name_get(&ram_disk, "aBcD~", destination_name_1, &ulength);
254 return_value_if_fail(status == FX_SUCCESS, 33);
255
256 #ifndef FX_DISABLE_ERROR_CHECKING
257 /* Test unicode name checking. */
258 length = fx_unicode_length_get(specified_unicode_file_name_2);
259 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
260 return_value_if_fail(status == FX_SUCCESS, 21);
261 length++;
262 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
263 return_value_if_fail(status == FX_INVALID_NAME, 22);
264
265 length = fx_unicode_length_get(specified_unicode_file_name_2);
266 status = fx_unicode_directory_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
267 return_value_if_fail(status == FX_ALREADY_CREATED, 23);
268 length++;
269 status = fx_unicode_file_create(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
270 return_value_if_fail(status == FX_INVALID_NAME, 24);
271
272 length = fx_unicode_length_get(specified_unicode_file_name_2);
273 status = fx_unicode_short_name_get(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
274 return_value_if_fail(status == FX_SUCCESS, 25);
275 length++;
276 status = fx_unicode_short_name_get(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name);
277 return_value_if_fail(status == FX_INVALID_NAME, 26);
278
279 status = fx_unicode_short_name_get_extended(&ram_disk, specified_unicode_file_name_2, length, (CHAR *)destination_name, sizeof(destination_name));
280 return_value_if_fail(status == FX_INVALID_NAME, 26);
281
282 /* Test invalid old file name */
283 old_length = fx_unicode_length_get(specified_unicode_file_name_2);
284 old_length++;
285 new_length = fx_unicode_length_get(specified_unicode_file_name_1);
286 status = fx_unicode_file_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
287 return_value_if_fail(status == FX_INVALID_NAME, 27);
288 status = fx_unicode_directory_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
289 return_value_if_fail(status == FX_INVALID_NAME, 28);
290
291 /* Test invalid new file name */
292 old_length = fx_unicode_length_get(specified_unicode_file_name_2);
293 new_length = fx_unicode_length_get(specified_unicode_file_name_1);
294 new_length++;
295 status = fx_unicode_file_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
296 return_value_if_fail(status == FX_INVALID_NAME, 29);
297 status = fx_unicode_directory_rename(&ram_disk, specified_unicode_file_name_2, old_length, specified_unicode_file_name_1, new_length, (CHAR *)destination_name);
298 return_value_if_fail(status == FX_INVALID_NAME, 30);
299
300 old_length = fx_unicode_length_get(long_unicode_name1);
301 new_length = fx_unicode_length_get(specified_unicode_file_name_2);
302 status = fx_unicode_file_rename(&ram_disk, long_unicode_name1, old_length, specified_unicode_file_name_2, new_length, (CHAR *)destination_name);
303 return_value_if_fail(status == FX_NOT_FOUND, 34);
304
305 old_length = fx_unicode_length_get(long_unicode_name1);
306 new_length = fx_unicode_length_get(specified_unicode_file_name_2);
307 status = fx_unicode_directory_rename(&ram_disk, long_unicode_name1, old_length, specified_unicode_file_name_2, new_length, (CHAR *)destination_name);
308 return_value_if_fail(status == FX_NOT_FOUND, 35);
309
310 #endif
311
312 status = fx_media_close(&ram_disk);
313 return_value_if_fail(status == FX_SUCCESS, 36);
314
315 /* Open the ram_disk in fx_ram_dirver_test.c. */
316 temp_array[0] = large_file_name_format[(1736 - 852) * 16 + 3];
317 temp_array[1] = large_file_name_format[(1736 - 852) * 16 + 4];
318
319 /* Insert 00FF in a long file dir_entry. */
320 large_file_name_format[(1736 - 852) * 16 + 3] = 0;
321 large_file_name_format[(1736 - 852) * 16 + 4] = 0xFF;
322 _fx_ram_driver_copy_default_format = 1;
323 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, 128);
324 return_value_if_fail(status == FX_SUCCESS, 37);
325 _fx_ram_driver_copy_default_format = 0;
326
327 /* Revert all we done. */
328 large_file_name_format[(1736 - 852) * 16 + 3] = temp_array[0];
329 large_file_name_format[(1736 - 852) * 16 + 4] = temp_array[1];
330
331 /* Attempt to access our directory. */
332 length = fx_unicode_length_get(specified_ascii_file_name);
333 status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
334 return_value_if_fail(status == FX_SUCCESS, 38);
335
336 status = fx_media_close( &ram_disk);
337 return_if_fail( status == FX_SUCCESS);
338
339 /* Format the media. This needs to be done before opening it! */
340 status = fx_media_format(&ram_disk,
341 _fx_ram_driver, // Driver entry
342 ram_disk_memory_large, // RAM disk memory pointer
343 cache_buffer, // Media buffer pointer
344 128, // Media buffer size
345 "MY_RAM_DISK", // Volume Name
346 1, // Number of FATs
347 32, // Directory Entries
348 0, // Hidden sectors
349 70000, // Total sectors
350 128, // Sector size
351 1, // Sectors per cluster
352 1, // Heads
353 1); // Sectors per track
354 return_if_fail( status == FX_SUCCESS);
355
356 /* Backup the data which will be modified later. */
357 temp_array[0] = large_file_name_format[(1734 - 852) * 16];
358 temp_array[1] = large_file_name_format[(1734 - 852) * 16 + 11];
359
360 /* Modfy the first dir_entry's ordinary number as 0x40 to make number of lfns be zero. */
361 large_file_name_format[(1734 - 852) * 16] = 0x40;
362 large_file_name_format[(1734 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
363 _fx_ram_driver_copy_default_format = 1;
364 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
365 _fx_ram_driver_copy_default_format = 0;
366
367 /* Recover the disk. */
368 large_file_name_format[(1734 - 852) * 16] = temp_array[0];
369 large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
370
371 /* Access root directory. */
372 status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
373 return_if_fail( status == FX_SUCCESS);
374
375 status = fx_media_close( &ram_disk);
376 return_if_fail( status == FX_SUCCESS);
377
378 /* Format the media. This needs to be done before opening it! */
379 status = fx_media_format(&ram_disk,
380 _fx_ram_driver, // Driver entry
381 ram_disk_memory_large, // RAM disk memory pointer
382 cache_buffer, // Media buffer pointer
383 128, // Media buffer size
384 "MY_RAM_DISK", // Volume Name
385 1, // Number of FATs
386 32, // Directory Entries
387 0, // Hidden sectors
388 70000, // Total sectors
389 128, // Sector size
390 1, // Sectors per cluster
391 1, // Heads
392 1); // Sectors per track
393 return_if_fail( status == FX_SUCCESS);
394
395 /* Backup the data which will be modified later. */
396 temp_array[0] = large_file_name_format[(1734 - 852) * 16];
397 temp_array[1] = large_file_name_format[(1734 - 852) * 16 + 11];
398 temp_array[2] = large_file_name_format[(1736 - 852) * 16];
399 temp_array[3] = large_file_name_format[(1736 - 852) * 16 + 11];
400
401 /* Modfy the second dir_entry's ordinary number as 0x40 to make card number be zero. */
402 large_file_name_format[(1734 - 852) * 16] = 0x42;
403 large_file_name_format[(1734 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
404 large_file_name_format[(1736 - 852) * 16] = 0x40;
405 large_file_name_format[(1736 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
406
407 /* Open the disk in fx_ram_driver_test.c */
408 _fx_ram_driver_copy_default_format = 1;
409 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
410 return_if_fail( status == FX_SUCCESS);
411 _fx_ram_driver_copy_default_format = 0;
412
413 /* Recover the disk. */
414 large_file_name_format[(1734 - 852) * 16] = temp_array[0];
415 large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
416 large_file_name_format[(1736 - 852) * 16] = temp_array[2];
417 large_file_name_format[(1736 - 852) * 16 + 11] = temp_array[3];
418
419 /* Access root directory. */
420 status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
421 return_if_fail( status == FX_SUCCESS);
422
423 status = fx_media_close( &ram_disk);
424 return_if_fail( status == FX_SUCCESS);
425
426 /* Format the media. This needs to be done before opening it! */
427 status = fx_media_format(&ram_disk,
428 _fx_ram_driver, // Driver entry
429 ram_disk_memory_large, // RAM disk memory pointer
430 cache_buffer, // Media buffer pointer
431 128, // Media buffer size
432 "MY_RAM_DISK", // Volume Name
433 1, // Number of FATs
434 32, // Directory Entries
435 0, // Hidden sectors
436 70000, // Total sectors
437 128, // Sector size
438 1, // Sectors per cluster
439 1, // Heads
440 1); // Sectors per track
441 return_if_fail( status == FX_SUCCESS);
442
443 /* Backup the data which will be modified later. */
444 temp_array[0] = large_file_name_format[(1736 - 852) * 16];
445 temp_array[1] = large_file_name_format[(1736 - 852) * 16 + 11];
446 temp_array[2] = large_file_name_format[(1738 - 852) * 16];
447 temp_array[3] = large_file_name_format[(1738 - 852) * 16 + 11];
448
449 /* Modfy the last two dir_entries in root directory, so we have to access the second sector of root directory. */
450 large_file_name_format[(1736 - 852) * 16] = 0x43;
451 large_file_name_format[(1736 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
452 large_file_name_format[(1738 - 852) * 16] = 0x42;
453 large_file_name_format[(1738 - 852) * 16 + 11] = (UCHAR)FX_LONG_NAME;
454
455 /* Open the disk in fx_ram_driver_test.c */
456 _fx_ram_driver_copy_default_format = 1;
457 status += fx_media_open( &ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
458 return_if_fail( status == FX_SUCCESS);
459 _fx_ram_driver_copy_default_format = 0;
460
461 /* Recover the disk. */
462 large_file_name_format[(1734 - 852) * 16] = temp_array[0];
463 large_file_name_format[(1734 - 852) * 16 + 11] = temp_array[1];
464 large_file_name_format[(1736 - 852) * 16] = temp_array[2];
465 large_file_name_format[(1736 - 852) * 16 + 11] = temp_array[3];
466
467 /* Access root directory, but set the size of root directory as zero to make a mistake. */
468 ram_disk.fx_media_root_sectors = 0;
469 status = fx_unicode_file_create(&ram_disk, specified_ascii_file_name, length, (CHAR *)destination_name);
470 return_if_fail( status == FX_FILE_CORRUPT);
471
472 status = fx_media_close( &ram_disk);
473 return_if_fail( status == FX_SUCCESS);
474
475 status = fx_media_format(&ram_disk,
476 _fx_ram_driver, // Driver entry
477 ram_disk_memory_large, // RAM disk memory pointer
478 cache_buffer, // Media buffer pointer
479 128, // Media buffer size
480 "MY_RAM_DISK", // Volume Name
481 1, // Number of FATs
482 32, // Directory Entries
483 0, // Hidden sectors
484 70000, // Total sectors
485 128, // Sector size
486 1, // Sectors per cluster
487 1, // Heads
488 1); // Sectors per track
489 status += fx_media_open( &ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
490 return_if_fail( status == FX_SUCCESS);
491
492 status = fx_file_create( &ram_disk, "src");
493 status += fx_file_open( &ram_disk, &my_file, "src", FX_OPEN_FOR_WRITE);
494 status += fx_file_write( &my_file, "hello", 5);
495 return_if_fail( status == FX_SUCCESS);
496
497 /* IO error in fx_utility_FAT_map_flush.c while calling fx_utility_logical_sector_read. */
498 _fx_utility_logical_sector_read_error_request = 2;
499 status = fx_media_close( &ram_disk);
500
501 printf("SUCCESS!\n");
502 test_control_return(0);
503 }
504