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