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_file_directory_rename_extra_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_file_directory_rename_extra_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 static UCHAR                    new_file_name5[] =      {'a', 0, 'b', 0, 'c', 0, 0, 0};
75 static UCHAR                    new_file_name5_bak[] =  {'a', 0, 'b', 0, 'c', 0, 0, 0};
76 static UCHAR                    new_file_name6[] =      {'1', 0, 'b', 0, 'c', 0, 'd', 0, 0, 0};
77 static UCHAR                    destination_name[100];
78 
79 /* Define the test threads.  */
80 
ftest_0_entry(ULONG thread_input)81 static void    ftest_0_entry(ULONG thread_input)
82 {
83 
84 UINT status, length, count, new_length, old_length;
85 UCHAR temp;
86 
87     FX_PARAMETER_NOT_USED(thread_input);
88 
89     /* Print out some test information banners.  */
90     printf("FileX Test:   Unicode file directory rename extra test...............");
91 
92     /* Format the media with FAT32.  This needs to be done before opening it!  */
93     status =  fx_media_format(&ram_disk,
94                               _fx_ram_driver,         // Driver entry
95                               ram_disk_memory_large,  // RAM disk memory pointer
96                               cache_buffer,           // Media buffer pointer
97                               CACHE_SIZE,             // Media buffer size
98                               "MY_RAM_DISK",          // Volume Name
99                               1,                      // Number of FATs
100                               32,                     // Directory Entries
101                               0,                      // Hidden sectors
102                               70000 * 8,              // Total sectors
103                               256,                    // Sector size
104                               8,                      // Sectors per cluster
105                               1,                      // Heads
106                               1);                     // Sectors per track
107 
108     return_value_if_fail( status == FX_SUCCESS, 1);
109     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
110     return_value_if_fail( status == FX_SUCCESS, 2);
111 
112     length = fx_unicode_length_get(new_file_name5);
113     status = fx_unicode_file_create( &ram_disk, new_file_name5, length, (CHAR *)destination_name);
114     return_value_if_fail( status == FX_SUCCESS, 3);
115 
116     temp = new_file_name5[0];
117 
118     /* Attempt to create more than 26 files with unicode names with the same length. */
119     for ( count = 0; count < 28; count++)
120     {
121         new_file_name5[0]++;
122         length = fx_unicode_length_get(new_file_name5);
123         status = fx_unicode_file_create( &ram_disk, new_file_name5, length, (CHAR *)destination_name);
124         if ( count <=24)
125         {
126 
127             /* Succeed while less than 26 files is created. */
128             return_value_if_fail( status == FX_SUCCESS, 4 + count);
129         }
130         else
131         {
132 
133             /* Exceeded the limitation. */
134             return_value_if_fail( status == FX_ALREADY_CREATED, 4 + count);
135         }
136     }
137 
138     length = fx_unicode_length_get(new_file_name6);
139     status = fx_unicode_file_create( &ram_disk, new_file_name6, length, (CHAR *)destination_name);
140     return_value_if_fail( status == FX_SUCCESS, 32);
141 
142     /* Touch the limitation by renaming. */
143     new_length = fx_unicode_length_get(new_file_name5);
144     old_length = fx_unicode_length_get(new_file_name6);
145     status = fx_unicode_file_rename( &ram_disk, new_file_name6, old_length, new_file_name5, new_length, (CHAR *)destination_name);
146     return_value_if_fail( status == FX_ALREADY_CREATED, 33);
147 
148     /* Renaming a file with the same length is premitted. */
149     new_length = fx_unicode_length_get(new_file_name5);
150     old_length = fx_unicode_length_get(new_file_name5_bak);
151     status = fx_unicode_file_rename( &ram_disk, new_file_name5_bak, old_length, new_file_name5, new_length, (CHAR *)destination_name);
152     return_value_if_fail( status == FX_SUCCESS, 34);
153 
154     /* Recover new_file_name5 for the test for renaming directory. */
155     new_file_name5[0] = temp;
156 
157     /* Abort the disk to reuse memory. */
158     fx_media_abort( &ram_disk);
159 
160     /* Format the media with FAT32.  This needs to be done before opening it!  */
161     status =  fx_media_format(&ram_disk,
162                               _fx_ram_driver,         // Driver entry
163                               ram_disk_memory_large,  // RAM disk memory pointer
164                               cache_buffer,           // Media buffer pointer
165                               CACHE_SIZE,             // Media buffer size
166                               "MY_RAM_DISK",          // Volume Name
167                               1,                      // Number of FATs
168                               32,                     // Directory Entries
169                               0,                      // Hidden sectors
170                               70000 * 8,              // Total sectors
171                               256,                    // Sector size
172                               8,                      // Sectors per cluster
173                               1,                      // Heads
174                               1);                     // Sectors per track
175 
176     return_value_if_fail( status == FX_SUCCESS, 1);
177     status =  fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
178     return_value_if_fail( status == FX_SUCCESS, 2);
179 
180     length = fx_unicode_length_get(new_file_name5);
181     status = fx_unicode_directory_create( &ram_disk, new_file_name5, length, (CHAR *)destination_name);
182     return_value_if_fail( status == FX_SUCCESS, 3);
183 
184     temp = new_file_name5[0];
185 
186     /* Attempt to create more than 26 files with unicode names with the same length. */
187     for ( count = 0; count < 28; count++)
188     {
189         new_file_name5[0]++;
190         length = fx_unicode_length_get(new_file_name5);
191         status = fx_unicode_directory_create( &ram_disk, new_file_name5, length, (CHAR *)destination_name);
192         if ( count <=24)
193         {
194 
195             /* Succeed while less than 26 files is created. */
196             return_value_if_fail( status == FX_SUCCESS, 4 + count);
197         }
198         else
199         {
200 
201             /* Exceeded the limitation. */
202             return_value_if_fail( status == FX_ALREADY_CREATED, 4 + count);
203         }
204     }
205 
206     length = fx_unicode_length_get(new_file_name6);
207     status = fx_unicode_directory_create( &ram_disk, new_file_name6, length, (CHAR *)destination_name);
208     return_value_if_fail( status == FX_SUCCESS, 32);
209 
210     /* Touch the limitation by renaming. */
211     new_length = fx_unicode_length_get(new_file_name5);
212     old_length = fx_unicode_length_get(new_file_name6);
213     status = fx_unicode_directory_rename( &ram_disk, new_file_name6, old_length, new_file_name5, new_length, (CHAR *)destination_name);
214     return_value_if_fail( status == FX_ALREADY_CREATED, 33);
215 
216     /* Renaming a file with the same length is premitted. */
217     new_length = fx_unicode_length_get(new_file_name5);
218     old_length = fx_unicode_length_get(new_file_name5_bak);
219     status = fx_unicode_directory_rename( &ram_disk, new_file_name5_bak, old_length, new_file_name5, new_length, (CHAR *)destination_name);
220     return_value_if_fail( status == FX_SUCCESS, 34);
221     printf("SUCCESS!\n");
222     test_control_return(0);
223 }
224