1 /* Test the condition of fat entry broken. */
2 #include "fx_api.h"
3 #include "fx_ram_driver_test.h"
4 #include "fx_utility.h"
5 #include <stdio.h>
6
7 #define DEMO_STACK_SIZE 8192
8 #define CACHE_SIZE 16*128
9
10 #ifndef FX_STANDALONE_ENABLE
11
12 /* Define the ThreadX and FileX object control blocks... */
13
14 static TX_THREAD ftest_0;
15 static FX_MEDIA ram_disk;
16
17 /* Define the counters used in the test application... */
18
19 static UCHAR *ram_disk_memory;
20 static UCHAR *cache_buffer;
21
22 /* Define thread prototypes. */
23
24 void filex_unicode_fat_entry_1_test_application_define(void *first_unused_memory);
25 static void ftest_0_entry(ULONG thread_input);
26
27 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
28 void test_control_return(UINT status);
29
30 /* Define what the initial system looks like. */
31
32 #ifdef CTEST
test_application_define(void * first_unused_memory)33 void test_application_define(void *first_unused_memory)
34 #else
35 void filex_unicode_fat_entry_1_test_application_define(void *first_unused_memory)
36 #endif
37 {
38
39 UCHAR *pointer;
40
41
42 /* Setup the working pointer. */
43 pointer = (UCHAR *) first_unused_memory;
44
45 /* Create the main thread. */
46 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
47 pointer, DEMO_STACK_SIZE,
48 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
49 pointer = pointer + DEMO_STACK_SIZE;
50
51 /* Setup memory for the RAM disk and the sector cache. */
52 cache_buffer = pointer;
53 pointer = pointer + CACHE_SIZE;
54 ram_disk_memory = pointer;
55
56 /* Initialize the FileX system. */
57 fx_system_initialize();
58 }
59
60
61 /* Define the test threads. */
62
ftest_0_entry(ULONG thread_input)63 static void ftest_0_entry(ULONG thread_input)
64 {
65
66 UINT status;
67 UCHAR destination_name[100] = {0};
68 UCHAR destination_name2[100] = {0};
69 UCHAR long_unicode_name[] = {2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 0};
70 ULONG length = 14;
71 FX_LOCAL_PATH local_path;
72
73 FX_PARAMETER_NOT_USED(thread_input);
74
75 /* Print out some test information banners. */
76 printf("FileX Test: Unicode fat entry 1 test...............................");
77
78 /* Format the media. This needs to be done before opening it! */
79 status = fx_media_format(&ram_disk,
80 _fx_ram_driver, // Driver entry
81 ram_disk_memory, // RAM disk memory pointer
82 cache_buffer, // Media buffer pointer
83 CACHE_SIZE, // Media buffer size
84 "MY_RAM_DISK", // Volume Name
85 1, // Number of FATs
86 32, // Directory Entries
87 0, // Hidden sectors
88 512, // Total sectors
89 128, // Sector size
90 1, // Sectors per cluster
91 1, // Heads
92 1); // Sectors per track
93
94 /* Open the ram_disk. */
95 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
96 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
97
98 /* Chdir to the created directory and create a subdirectory. */
99 status += fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
100 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
101 return_value_if_fail( status == FX_SUCCESS, 1);
102
103 /* Fat entry destory. */
104 ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_value = 0xffff;
105 ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_dirty = 1;
106
107 /* Close the media to flush buffer. Now we have a disk with a corrupt dir_entry. */
108 status = fx_media_close(&ram_disk);
109
110 /* Open the ram_disk. */
111 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
112 return_value_if_fail( status == FX_SUCCESS, 2);
113
114 /* Attempt to access our broken directory. */
115 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
116 return_value_if_fail( status == FX_INVALID_PATH, 3);
117 status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *) destination_name);
118 return_value_if_fail( status == FX_FILE_CORRUPT, 4);
119
120 printf("SUCCESS!\n");
121 test_control_return(0);
122 }
123
124 #else
125
126 extern void test_control_return(UINT status);
127 #ifdef CTEST
test_application_define(void * first_unused_memory)128 void test_application_define(void *first_unused_memory)
129 #else
130 void filex_fault_tolerant_enable_4_test_application_define(void *first_unused_memory)
131 #endif
132 {
133
134 FX_PARAMETER_NOT_USED(first_unused_memory);
135
136 /* Print out some test information banners. */
137 printf("FileX Test: Unicode fat entry 1 test...............................N/A\n");
138
139 test_control_return(255);
140 }
141 #endif
142