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