1 /* Test the condition of fat entry broken. */
2 #ifndef FX_STANDALONE_ENABLE
3 #include "tx_api.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
10 #define DEMO_STACK_SIZE 8192
11 #define CACHE_SIZE 16*128
12
13 /* Define the ThreadX and FileX object control blocks... */
14
15 #ifndef FX_STANDALONE_ENABLE
16 static TX_THREAD ftest_0;
17 #endif
18 static FX_MEDIA ram_disk;
19
20 /* Define the counters used in the test application... */
21
22 #ifndef FX_STANDALONE_ENABLE
23 static UCHAR *ram_disk_memory;
24 static UCHAR *cache_buffer;
25 #else
26 static UCHAR cache_buffer[CACHE_SIZE];
27 #endif
28
29 /* Define thread prototypes. */
30
31 void filex_unicode_fat_entry_3_test_application_define(void *first_unused_memory);
32 static void ftest_0_entry(ULONG thread_input);
33
34 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
35 void test_control_return(UINT status);
36
37 /* Define what the initial system looks like. */
38
39 #ifdef CTEST
test_application_define(void * first_unused_memory)40 void test_application_define(void *first_unused_memory)
41 #else
42 void filex_unicode_fat_entry_3_test_application_define(void *first_unused_memory)
43 #endif
44 {
45
46 #ifndef FX_STANDALONE_ENABLE
47 UCHAR *pointer;
48
49
50 /* Setup the working pointer. */
51 pointer = (UCHAR *) first_unused_memory;
52
53 /* Create the main thread. */
54 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
55 pointer, DEMO_STACK_SIZE,
56 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
57
58 pointer = pointer + DEMO_STACK_SIZE;
59
60 /* Setup memory for the RAM disk and the sector cache. */
61 cache_buffer = pointer;
62 pointer = pointer + CACHE_SIZE;
63 ram_disk_memory = pointer;
64
65 #endif
66
67 /* Initialize the FileX system. */
68 fx_system_initialize();
69 #ifdef FX_STANDALONE_ENABLE
70 ftest_0_entry(0);
71 #endif
72 }
73
74
75 /* Define the test threads. */
76
ftest_0_entry(ULONG thread_input)77 static void ftest_0_entry(ULONG thread_input)
78 {
79
80 UINT status;
81 UCHAR destination_name[100] = {0};
82 UCHAR destination_name1[20] = {0};
83 UCHAR destination_name2[20] = {0};
84 UCHAR destination_name3[20] = {0};
85 UCHAR destination_name4[20] = {0};
86 UCHAR destination_name5[20] = {0};
87 UCHAR destination_name6[20] = {0};
88 UCHAR destination_name7[20] = {0};
89 UCHAR destination_name8[20] = {0};
90 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};
91 ULONG length = 14;
92 UCHAR fat_buffer[128] = {0};
93 FX_LOCAL_PATH local_path;
94
95 FX_PARAMETER_NOT_USED(thread_input);
96
97 /* Print out some test information banners. */
98 printf("FileX Test: Unicode fat entry 3 test...............................");
99
100 /* Format the media. This needs to be done before opening it! */
101 status = fx_media_format(&ram_disk,
102 _fx_ram_driver, // Driver entry
103 ram_disk_memory, // RAM disk memory pointer
104 cache_buffer, // Media buffer pointer
105 CACHE_SIZE, // Media buffer size
106 "MY_RAM_DISK", // Volume Name
107 1, // Number of FATs
108 32, // Directory Entries
109 0, // Hidden sectors
110 7000, // Total sectors - FAT16
111 128, // Sector size
112 1, // Sectors per cluster
113 1, // Heads
114 1); // Sectors per track
115 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
116 return_if_fail( status == FX_SUCCESS);
117
118 /* Create a directory and many subdirectories to build fat chain. */
119 status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
120 #ifndef FX_STANDALONE_ENABLE
121 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
122 #else
123 status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
124 #endif
125
126 long_unicode_name[0]++;
127 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name1);
128 long_unicode_name[0]++;
129 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
130 long_unicode_name[0]++;
131 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name3);
132 long_unicode_name[0]++;
133 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name4);
134 long_unicode_name[0]++;
135 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name5);
136 long_unicode_name[0]++;
137 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name6);
138 return_if_fail( status == FX_SUCCESS);
139
140 /* Flush everything out. */
141 fx_media_flush(&ram_disk);
142 _fx_utility_FAT_flush(&ram_disk);
143 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
144 for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
145 {
146 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
147 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
148 }
149
150 /* Read the first FAT sector. */
151 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
152
153 /* Add a FAT entry randomly in the FAT table. */
154 fat_buffer[6] = 0x32;
155 fat_buffer[7] = 0x00;
156
157 /* Write the FAT corruption out. */
158 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
159 return_if_fail( status == FX_SUCCESS);
160
161 long_unicode_name[0]++;
162 status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
163 return_if_fail( status == FX_FAT_READ_ERROR);
164
165 /* Flush everything out. */
166 fx_media_flush(&ram_disk);
167 _fx_utility_FAT_flush(&ram_disk);
168 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
169 for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
170 {
171 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
172 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
173 }
174
175 /* Read the first FAT sector. */
176 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
177
178 /* Add a FAT entry randomly in the FAT table. */
179 fat_buffer[6] = 0x03;
180 fat_buffer[7] = 0x00;
181
182 /* Write the FAT corruption out. */
183 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
184 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
185 return_if_fail( status == FX_FAT_READ_ERROR);
186
187 /* Flush everything out. */
188 fx_media_flush(&ram_disk);
189 _fx_utility_FAT_flush(&ram_disk);
190 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
191 for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
192 {
193 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
194 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
195 }
196
197 /* Read the first FAT sector. */
198 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
199
200 /* Recovery FAT chain. */
201 fat_buffer[6] = 0x06;
202 fat_buffer[7] = 0x00;
203
204 /* Write the FAT corruption out. */
205 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
206 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name7);
207 return_if_fail( status == FX_SUCCESS);
208
209 /* Flush everything out. */
210 fx_media_flush(&ram_disk);
211 _fx_utility_FAT_flush(&ram_disk);
212 _fx_utility_logical_sector_flush(&ram_disk, 1, 60000, FX_TRUE);
213 for (int i = 0; i < FX_MAX_FAT_CACHE; i++)
214 {
215 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
216 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
217 }
218
219 /* Read the first FAT sector. */
220 status = fx_media_read(&ram_disk, 1, (VOID *) fat_buffer);
221
222 /* Make FAT chain a circle. */
223 fat_buffer[12] = 0x03;
224 fat_buffer[13] = 0x00;
225
226 /* Write the FAT corruption out. */
227 status += fx_media_write(&ram_disk, 1, (VOID *) fat_buffer);
228 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name8);
229 return_if_fail( status == FX_FAT_READ_ERROR);
230
231 printf("SUCCESS!\n");
232 test_control_return(0);
233 }
234