1 /* This FileX test concentrates on the unicode operations.  */
2 
3 #ifndef FX_STANDALONE_ENABLE
4 #include   "tx_api.h"
5 #endif
6 #include   "fx_api.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 
14 /* Define the ThreadX and FileX object control blocks...  */
15 
16 #ifndef FX_STANDALONE_ENABLE
17 static TX_THREAD                ftest_0;
18 extern TX_THREAD *_tx_thread_current_ptr;
19 #endif
20 static FX_MEDIA                 ram_disk;
21 
22 /* Define the counters used in the test application...  */
23 
24 #ifndef FX_STANDALONE_ENABLE
25 static UCHAR                    *ram_disk_memory;
26 static UCHAR                    *cache_buffer;
27 #else
28 static UCHAR                     cache_buffer[CACHE_SIZE];
29 #endif
30 
31 /* Define thread prototypes.  */
32 
33 void    filex_unicode_name_string_application_define(void *first_unused_memory);
34 static void    ftest_0_entry(ULONG thread_input);
35 
36 VOID  _fx_ram_driver(FX_MEDIA *media_ptr);
37 void  test_control_return(UINT status);
38 
39 /* Define what the initial system looks like.  */
40 
41 #ifdef CTEST
test_application_define(void * first_unused_memory)42 void test_application_define(void *first_unused_memory)
43 #else
44 void    filex_unicode_name_string_application_define(void *first_unused_memory)
45 #endif
46 {
47 
48 #ifndef FX_STANDALONE_ENABLE
49 UCHAR    *pointer;
50 
51 
52     /* Setup the working pointer.  */
53     pointer =  (UCHAR *) first_unused_memory;
54 
55     /* Create the main thread.  */
56     tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
57             pointer, DEMO_STACK_SIZE,
58             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
59 
60     pointer =  pointer + DEMO_STACK_SIZE;
61 
62     /* Setup memory for the RAM disk and the sector cache.  */
63     cache_buffer =  pointer;
64     pointer =  pointer + CACHE_SIZE;
65     ram_disk_memory =  pointer;
66 
67 #endif
68 
69     /* Initialize the FileX system.  */
70     fx_system_initialize();
71 #ifdef FX_STANDALONE_ENABLE
72     ftest_0_entry(0);
73 #endif
74 }
75 
76 /* Define the test threads.  */
77 
ftest_0_entry(ULONG thread_input)78 static void    ftest_0_entry(ULONG thread_input)
79 {
80 
81 UINT        status;
82 UCHAR       buffer[512];
83 #ifndef FX_DISABLE_ERROR_CHECKING
84 UCHAR       destination_name[300] = {0};
85 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};
86 #endif /* FX_DISABLE_ERROR_CHECKING */
87 
88 #ifndef FX_STANDALONE_ENABLE
89 UCHAR       *path_ptr;
90 #else
91 UCHAR       path_ptr[1024];
92 #endif
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 name string 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                             512,                    // Total sectors
111                             128,                    // Sector size
112                             1,                      // Sectors per cluster
113                             1,                      // Heads
114                             1);                     // Sectors per track
115 
116     /* Open the ram_disk.  */
117     status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
118     return_if_fail( status == FX_SUCCESS);
119 
120 #ifndef FX_DISABLE_ERROR_CHECKING
121 
122     /* Disable write protect */
123     ram_disk.fx_media_driver_write_protect = FX_FALSE;
124 
125     /* lengthen the unicode name to include the last 0 */
126     ULONG       length = 15;
127 
128     /* Test creating directory. */
129     status = fx_unicode_directory_create(&ram_disk,  long_unicode_name, length, (CHAR *) destination_name);
130     return_if_fail( status == FX_INVALID_NAME);
131 
132     /* Test creating file. */
133     status = fx_unicode_file_create(&ram_disk,  long_unicode_name, length, (CHAR *) destination_name);
134     return_if_fail( status == FX_INVALID_NAME);
135 
136 #endif
137 
138     /* Create a directory named a...(254 times). */
139     buffer[0] = '/';
140 
141     for (UINT i = 1; i < 300; i++)
142         buffer[i] = 'a';
143 
144     buffer[255] = 0;
145 
146     /* Chenged to the specified directory and ensure the string related to current position is end as zero. */
147     status = fx_directory_create( &ram_disk, (CHAR *)buffer);
148 #ifndef FX_STANDALONE_ENABLE
149         status =   fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)buffer);
150 #else
151         status =   fx_directory_default_set(&ram_disk, (CHAR *)buffer);
152 #endif
153 #ifndef FX_STANDALONE_ENABLE
154     path_ptr =  (UCHAR *)((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_string;
155 #endif
156     path_ptr[255] = 0;
157     return_if_fail( status == FX_SUCCESS);
158 
159     /* Specify last found name as the directory we just created. */
160     buffer[255] = '/';
161     buffer[256] = 0;
162 
163     for (UINT i = 0; i <= 256; i++)
164         ram_disk.fx_media_last_found_name[i] = (CHAR)buffer[i];
165 
166     /* Access the directory and see what will happen. */
167     status = fx_directory_create( &ram_disk, "a");
168     return_if_fail( status == FX_SUCCESS);
169 
170     status = fx_media_close(&ram_disk);
171     return_if_fail( status == FX_SUCCESS);
172 
173     printf("SUCCESS!\n");
174     test_control_return(0);
175 }
176