1
10
13
14
20
21
22
23
24
25
26
27
28
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
117
118
119
127
128
129
130
131
132
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
161
162
163
164
165
166
167
173
174
180
181
182
188
189
190
191
192
193
194
200
201
202
203
204
205
212
213
214
215
216
217
219
220
221
222
223
224
225
226
227
228
229
231
232
233
235
236
238
239
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_unicode.h"
#include "fx_directory.h"
#include "fx_file.h"
#include "fx_utility.h"
5 includes#ifdef FX_ENABLE_FAULT_TOLERANT
#include "fx_fault_tolerant.h"
#endif
...
...
UINT _fx_unicode_file_rename(FX_MEDIA *media_ptr, UCHAR *old_unicode_name, ULONG old_unicode_length,
UCHAR *new_unicode_name, ULONG new_unicode_length, CHAR *new_short_name)
{
ULONG i;
UINT status;
CHAR alpha, beta;
CHAR old_shortname[13];
CHAR new_shortname[13];
FX_DIR_ENTRY dir_entry;
new_short_name[0] = FX_NULL;
old_shortname[0] = FX_NULL;
new_shortname[0] = FX_NULL;
if (media_ptr -> fx_media_id != FX_MEDIA_ID)
{
return(FX_MEDIA_NOT_OPEN);
}if (media_ptr -> fx_media_id != FX_MEDIA_ID) { ... }
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
return(FX_NOT_IMPLEMENTED);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
/* ... */#endif
status = _fx_unicode_short_name_get(media_ptr, old_unicode_name, old_unicode_length, old_shortname);
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
FX_PROTECT
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
dir_entry.fx_dir_entry_short_name[0] = FX_NULL;
status = _fx_unicode_directory_search(media_ptr, &dir_entry, (UCHAR *)new_shortname, sizeof(new_shortname),
new_unicode_name, &new_unicode_length, 0);
if (status == FX_SUCCESS)
{
if (old_unicode_length == new_unicode_length)
{
/* ... */
i = 0;
do
{
alpha = (CHAR)old_unicode_name[i << 1];
if ((alpha >= 'a') && (alpha <= 'z') && (old_unicode_name[(i << 1) + 1] == 0))
{
alpha = (CHAR)((INT)alpha - 0x20);
}if ((alpha >= 'a') && (alpha <= 'z') && (old_unicode_name[(i << 1) + 1] == 0)) { ... }
beta = (CHAR)new_unicode_name[i << 1];
if ((beta >= 'a') && (beta <= 'z') && (new_unicode_name[(i << 1) + 1] == 0))
{
beta = (CHAR)((INT)beta - 0x20);
}if ((beta >= 'a') && (beta <= 'z') && (new_unicode_name[(i << 1) + 1] == 0)) { ... }
if ((alpha != beta))
{
break;
}if ((alpha != beta)) { ... }
alpha = (CHAR)old_unicode_name[(i << 1) + 1];
beta = (CHAR)new_unicode_name[(i << 1) + 1];
if ((alpha != beta))
{
break;
}if ((alpha != beta)) { ... }
i++;
...} while (i < old_unicode_length);
}if (old_unicode_length == new_unicode_length) { ... }
else
{
alpha = 0;
beta = 1;
}else { ... }
if (alpha != beta)
{
/* ... */
FX_UNPROTECT
return(FX_ALREADY_CREATED);
}if (alpha != beta) { ... }
}if (status == FX_SUCCESS) { ... }
#ifdef FX_ENABLE_FAULT_TOLERANT
_fx_fault_tolerant_transaction_start(media_ptr);/* ... */
#endif
/* ... */
/* ... */
_fx_unicode_temp_long_file_name[0] = 'z';
for (i = 1; i < new_unicode_length; i++)
{
_fx_unicode_temp_long_file_name[i] = (UCHAR)((UINT)'0' + (i % 9));
}for (i = 1; i < new_unicode_length; i++) { ... }
_fx_unicode_temp_long_file_name[i] = FX_NULL;
do
{
status = _fx_file_rename(media_ptr, old_shortname, (CHAR *)_fx_unicode_temp_long_file_name);
if (status == FX_ALREADY_CREATED)
{
_fx_unicode_temp_long_file_name[0]--;
if (_fx_unicode_temp_long_file_name[0] < 0x61)
{
break;
}if (_fx_unicode_temp_long_file_name[0] < 0x61) { ... }
}if (status == FX_ALREADY_CREATED) { ... }
...} while (status == FX_ALREADY_CREATED);
if (status)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status) { ... }
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
dir_entry.fx_dir_entry_short_name[0] = 0;
status = _fx_directory_search(media_ptr, (CHAR *)_fx_unicode_temp_long_file_name, &dir_entry, FX_NULL, FX_NULL);
if (status != FX_SUCCESS)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
status = _fx_unicode_directory_entry_change(media_ptr, &dir_entry, new_unicode_name, new_unicode_length);
if (status == FX_SUCCESS)
{
for (i = 0; i < FX_DIR_NAME_SIZE; i++)
{
new_short_name[i] = dir_entry.fx_dir_entry_short_name[i];
if (new_short_name[i] == FX_NULL)
{
break;
}if (new_short_name[i] == FX_NULL) { ... }
}for (i = 0; i < FX_DIR_NAME_SIZE; i++) { ... }
}if (status == FX_SUCCESS) { ... }
#ifdef FX_ENABLE_FAULT_TOLERANT
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
status = _fx_fault_tolerant_transaction_end(media_ptr);/* ... */
#endif
FX_UNPROTECT
return(status);
}{ ... }