1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
112
113
114
115
116
117
118
119
120
121
122
125
126
127
128
129
130
131
134
135
136
137
138
139
140
147
148
149
155
156
157
158
160
161
163
164
165
166
167
168
169
170
171
172
173
174
175
178
179
180
181
182
183
189
190
191
192
193
194
195
196
197
198
199
202
203
204
205
206
207
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
236
237
238
239
240
241
242
243
244
248
252
253
254
260
261
262
263
264
265
266
270
274
275
276
277
278
279
280
281
282
283
284
285
288
289
290
291
292
293
294
295
296
300
304
305
306
312
313
314
315
316
317
318
322
323
324
325
326
327
328
330
331
332
339
345
346
348
349
350
351
352
353
354
355
356
357
361
365
366
367
373
374
375
376
377
378
379
380
384
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
425
426
427
428
429
430
431
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
465
466
467
468
469
475
476
477
480
481
482
483
484
485
486
487
488
489
490
491
494
495
498
499
500
501
502
503
504
505
506
512
513
514
515
516
517
518
519
520
524
525
526
527
528
529
530
531
533
534
535
536
537
538
539
540
541
542
543
544
545
551
552
553
559
560
561
562
563
564
565
566
567
568
570
571
572
573
574
575
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
613
614
615
616
622
623
625
626
627
628
629
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
654
655
656
657
658
659
660
661
664
665
666
670
671
672
673
674
675
676
677
680
681
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
703
704
705
711
712
713
719
720
721
722
723
724
725
727
734
735
736
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
766
767
768
774
775
777
778
779
780
781
782
789
790
791
792
793
799
800
801
802
803
804
805
806
807
808
809
810
811
813
814
816
817
818
819
820
821
824
825
826
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
852
853
854
856
857
858
859
871
872
873
874
875
876
877
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
930
936
937
938
939
940
941
942
943
944
945
946
947
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
979
980
981
982
983
984
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_directory.h"
#include "fx_utility.h"
#ifdef FX_ENABLE_EXFAT
#include "fx_directory_exFAT.h"
#endif
#ifndef FX_NO_LOCAL_PATH
FX_LOCAL_PATH_SETUP
#endif
...
...
UINT _fx_directory_search(FX_MEDIA *media_ptr, CHAR *name_ptr, FX_DIR_ENTRY *entry_ptr,
FX_DIR_ENTRY *last_dir_ptr, CHAR **last_name_ptr)
{
ULONG i, n;
UINT found;
UINT status;
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
UINT v, j;
#endif
ULONG cluster, next_cluster = 0;
ULONG64 directory_size;
CHAR *dir_name_ptr;
CHAR *work_ptr;
CHAR *source_name_ptr;
CHAR *destination_name_ptr;
FX_DIR_ENTRY search_dir;
FX_DIR_ENTRY *search_dir_ptr;
CHAR *name, alpha, name_alpha;
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
UINT index;
CHAR *path_ptr = FX_NULL;
CHAR *original_name = name_ptr;/* ... */
#endif
#ifdef FX_ENABLE_EXFAT
USHORT hash = 0;
#endif
#ifndef FX_MEDIA_STATISTICS_DISABLE
media_ptr -> fx_media_directory_searches++;/* ... */
#endif
name = media_ptr -> fx_media_name_buffer;
if (last_dir_ptr)
{
/* ... */
last_dir_ptr -> fx_dir_entry_name[0] = 0;
}if (last_dir_ptr) { ... }
if ((*name_ptr == '\\') || (*name_ptr == '/'))
{
search_dir_ptr = FX_NULL;
}if ((*name_ptr == '\\') || (*name_ptr == '/')) { ... }
else
{
/* ... */
/* ... */
#ifndef FX_NO_LOCAL_PATH
if (_tx_thread_current_ptr -> tx_thread_filex_ptr)
{
if (((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_directory.fx_dir_entry_name[0])
{
search_dir = ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_directory;
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
path_ptr = ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_string;/* ... */
#endif
search_dir_ptr = &search_dir;
}if (((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_directory.fx_dir_entry_name[0]) { ... }
else
{
search_dir_ptr = FX_NULL;
}else { ... }
}if (_tx_thread_current_ptr -> tx_thread_filex_ptr) { ... }
else/* ... */
#endif
if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0])
{
search_dir = media_ptr -> fx_media_default_path.fx_path_directory;
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
path_ptr = media_ptr -> fx_media_default_path.fx_path_string;/* ... */
#endif
search_dir_ptr = &search_dir;
}else if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0]) { ... }
else
{
/* ... */
search_dir_ptr = FX_NULL;
}else { ... }
}else { ... }
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
if (media_ptr -> fx_media_last_found_name[0])
{
UINT match;
CHAR *temp_ptr, beta;
v = 0;
if ((*name_ptr == '\\') || (*name_ptr == '/'))
{
/* ... */
while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[v]))
{
alpha = name_ptr[v];
beta = media_ptr -> fx_media_last_found_name[v];
if (alpha == '\\')
{
alpha = '/';
}if (alpha == '\\') { ... }
if (beta == '\\')
{
beta = '/';
}if (beta == '\\') { ... }
if (alpha != beta)
{
break;
}if (alpha != beta) { ... }
v++;
}while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[v])) { ... }
if (name_ptr[v] != media_ptr -> fx_media_last_found_name[v])
{
match = FX_FALSE;
}if (name_ptr[v] != media_ptr -> fx_media_last_found_name[v]) { ... }
else
{
match = FX_TRUE;
}else { ... }
}if ((*name_ptr == '\\') || (*name_ptr == '/')) { ... }
else
{
match = FX_TRUE;
if (path_ptr)
{
/* ... */
while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v]))
{
alpha = media_ptr -> fx_media_last_found_name[v];
beta = path_ptr[v];
if (alpha == '\\')
{
alpha = '/';
}if (alpha == '\\') { ... }
if (beta == '\\')
{
beta = '/';
}if (beta == '\\') { ... }
if (alpha != beta)
{
break;
}if (alpha != beta) { ... }
v++;
}while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v])) { ... }
if (path_ptr[v])
{
match = FX_FALSE;
}if (path_ptr[v]) { ... }
}if (path_ptr) { ... }
if (match)
{
/* ... */
if ((media_ptr -> fx_media_last_found_name[v] != '\\') &&
(media_ptr -> fx_media_last_found_name[v] != '/'))
{
match = FX_FALSE;
}if ((media_ptr -> fx_media_last_found_name[v] != '\\') && (media_ptr -> fx_media_last_found_name[v] != '/')) { ... }
else
{
/* ... */
v++;
}else { ... }
/* ... */
j = 0;
while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[j]) && (match))
{
alpha = name_ptr[j];
beta = media_ptr -> fx_media_last_found_name[v];
if (alpha == '\\')
{
alpha = '/';
}if (alpha == '\\') { ... }
if (beta == '\\')
{
beta = '/';
}if (beta == '\\') { ... }
if (alpha != beta)
{
break;
}if (alpha != beta) { ... }
v++;
j++;
}while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[j]) && (match)) { ... }
if (v >= 256)
{
match = FX_FALSE;
}if (v >= 256) { ... }
else if ((match) && (name_ptr[j] != media_ptr -> fx_media_last_found_name[v]))
{
match = FX_FALSE;
}else if ((match) && (name_ptr[j] != media_ptr -> fx_media_last_found_name[v])) { ... }
}if (match) { ... }
}else { ... }
if (match)
{
temp_ptr = entry_ptr -> fx_dir_entry_name;
*entry_ptr = media_ptr -> fx_media_last_found_entry;
entry_ptr -> fx_dir_entry_name = temp_ptr;
for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++)
{
temp_ptr[index] = media_ptr -> fx_media_last_found_file_name[index];
if (temp_ptr[index] == (CHAR)FX_NULL)
{
if (index < (FX_MAX_LONG_NAME_LEN - 1))
{
break;
}if (index < (FX_MAX_LONG_NAME_LEN - 1)) { ... }
}if (temp_ptr[index] == (CHAR)FX_NULL) { ... }
}for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) { ... }
if ((last_dir_ptr) && (media_ptr -> fx_media_last_found_directory_valid))
{
/* ... */
destination_name_ptr = last_dir_ptr -> fx_dir_entry_name;
*last_dir_ptr = media_ptr -> fx_media_last_found_directory;
last_dir_ptr -> fx_dir_entry_name = destination_name_ptr;
source_name_ptr = media_ptr -> fx_media_last_found_directory.fx_dir_entry_name;
for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++)
{
destination_name_ptr[n] = source_name_ptr[n];
if (source_name_ptr[n] == (CHAR)FX_NULL)
{
if (n < (FX_MAX_LONG_NAME_LEN - 1))
{
break;
}if (n < (FX_MAX_LONG_NAME_LEN - 1)) { ... }
}if (source_name_ptr[n] == (CHAR)FX_NULL) { ... }
}for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) { ... }
}if ((last_dir_ptr) && (media_ptr -> fx_media_last_found_directory_valid)) { ... }
if (last_name_ptr)
{
*last_name_ptr = temp_ptr;
}if (last_name_ptr) { ... }
#ifndef FX_MEDIA_STATISTICS_DISABLE
media_ptr -> fx_media_directory_search_cache_hits++;/* ... */
#endif
return(FX_SUCCESS);
}if (match) { ... }
}if (media_ptr -> fx_media_last_found_name[0]) { ... }
media_ptr -> fx_media_last_found_name[0] = FX_NULL;
#ifndef FX_MEDIA_STATISTICS_DISABLE
FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_DIR_CACHE_MISS, media_ptr, media_ptr -> fx_media_directory_searches - media_ptr -> fx_media_directory_search_cache_hits, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0)/* ... */
#else
FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_DIR_CACHE_MISS, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0)/* ... */
#endif/* ... */
#endif
do
{
if (last_name_ptr)
{
*last_name_ptr = name_ptr;
}if (last_name_ptr) { ... }
name_ptr = _fx_directory_name_extract(name_ptr, name);
if (search_dir_ptr)
{
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
directory_size = search_dir_ptr -> fx_dir_entry_file_size / FX_DIR_ENTRY_SIZE;
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
else
{
#endif
search_dir_ptr -> fx_dir_entry_last_search_cluster = 0;
/* ... */
i = 0;
cluster = search_dir_ptr -> fx_dir_entry_cluster;
while (cluster < media_ptr -> fx_media_fat_reserved)
{
i++;
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster);
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
if ((cluster < FX_FAT_ENTRY_START) || (cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters))
{
return(FX_FAT_READ_ERROR);
}if ((cluster < FX_FAT_ENTRY_START) || (cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters)) { ... }
cluster = next_cluster;
}while (cluster < media_ptr -> fx_media_fat_reserved) { ... }
directory_size = (((ULONG64) media_ptr -> fx_media_bytes_per_sector) *
((ULONG64) media_ptr -> fx_media_sectors_per_cluster) * i)
/ (ULONG64) FX_DIR_ENTRY_SIZE;
/* ... */
search_dir_ptr -> fx_dir_entry_file_size = directory_size;
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
/* ... */
if (last_dir_ptr)
{
destination_name_ptr = last_dir_ptr -> fx_dir_entry_name;
*last_dir_ptr = *search_dir_ptr;
last_dir_ptr -> fx_dir_entry_name = destination_name_ptr;
source_name_ptr = search_dir_ptr -> fx_dir_entry_name;
for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++)
{
destination_name_ptr[n] = source_name_ptr[n];
if (source_name_ptr[n] == (CHAR) FX_NULL)
{
if (n < (FX_MAX_LONG_NAME_LEN - 1))
{
break;
}if (n < (FX_MAX_LONG_NAME_LEN - 1)) { ... }
}if (source_name_ptr[n] == (CHAR) FX_NULL) { ... }
}for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) { ... }
}if (last_dir_ptr) { ... }
}if (search_dir_ptr) { ... }
else
{
directory_size = (ULONG)media_ptr -> fx_media_root_directory_entries;
}else { ... }
/* ... */
i = 0;
found = FX_FALSE;
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
hash = _fx_utility_exFAT_name_hash_get(name);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
/* ... */#endif
do
{
#ifdef FX_ENABLE_EXFAT
status = _fx_directory_entry_read_ex(media_ptr, search_dir_ptr, &i, entry_ptr, hash);
#else
status = _fx_directory_entry_read(media_ptr, search_dir_ptr, &i, entry_ptr);
#endif
i++;
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
if (entry_ptr -> fx_dir_entry_type == FX_EXFAT_DIR_ENTRY_TYPE_END_MARKER)
#else
if ((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_DONE)
#endif
{
break;
...}
if ((entry_ptr -> fx_dir_entry_attributes & FX_VOLUME))
{
continue;
}if ((entry_ptr -> fx_dir_entry_attributes & FX_VOLUME)) { ... }
#ifdef FX_ENABLE_EXFAT
if (entry_ptr -> fx_dir_entry_type != FX_EXFAT_DIR_ENTRY_TYPE_FILE_DIRECTORY)
#else
if (((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_FREE) && (entry_ptr -> fx_dir_entry_short_name[0] == 0))
#endif
{
continue;
...}
/* ... */
work_ptr = &name[0];
dir_name_ptr = &(entry_ptr -> fx_dir_entry_name[0]);
do
{
alpha = *dir_name_ptr;
name_alpha = *work_ptr;
if ((alpha >= 'a') && (alpha <= 'z'))
{
alpha = (CHAR)((INT)alpha - 0x20);
}if ((alpha >= 'a') && (alpha <= 'z')) { ... }
if ((name_alpha >= 'a') && (name_alpha <= 'z'))
{
name_alpha = (CHAR)((INT)name_alpha - 0x20);
}if ((name_alpha >= 'a') && (name_alpha <= 'z')) { ... }
if (alpha != name_alpha)
{
break;
}if (alpha != name_alpha) { ... }
work_ptr++;
dir_name_ptr++;
...} while (*dir_name_ptr);
/* ... */
if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr))
{
/* ... */
found = FX_TRUE;
}if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr)) { ... }
#ifdef FX_ENABLE_EXFAT
else if ((media_ptr -> fx_media_FAT_type != FX_exFAT) &&
(entry_ptr -> fx_dir_entry_short_name[0] != 0))/* ... */
#else
else if (entry_ptr -> fx_dir_entry_short_name[0] != 0)
#endif
{
work_ptr = &name[0];
dir_name_ptr = &(entry_ptr -> fx_dir_entry_short_name[0]);
do
{
alpha = *dir_name_ptr;
name_alpha = *work_ptr;
if ((name_alpha >= 'a') && (name_alpha <= 'z'))
{
name_alpha = (CHAR)((INT)name_alpha - 0x20);
}if ((name_alpha >= 'a') && (name_alpha <= 'z')) { ... }
if (alpha != name_alpha)
{
break;
}if (alpha != name_alpha) { ... }
/* ... */
work_ptr++;
dir_name_ptr++;
...} while (*dir_name_ptr);
if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr))
{
/* ... */
found = FX_TRUE;
}if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr)) { ... }
...}
...} while ((i < directory_size) && (!found));
if (!found)
{
return(FX_NOT_FOUND);
}if (!found) { ... }
if (entry_ptr -> fx_dir_entry_attributes & FX_DIRECTORY)
{
search_dir = *entry_ptr;
search_dir_ptr = &search_dir;
search_dir_ptr -> fx_dir_entry_last_search_cluster = 0;
/* ... */
#ifdef FX_ENABLE_EXFAT
if ((!search_dir_ptr -> fx_dir_entry_cluster)
&& (media_ptr -> fx_media_FAT_type != FX_exFAT))/* ... */
#else
if (!search_dir_ptr -> fx_dir_entry_cluster)
#endif
{
/* ... */
search_dir_ptr -> fx_dir_entry_name[0] = 0;
/* ... */
if (last_dir_ptr)
{
destination_name_ptr = last_dir_ptr -> fx_dir_entry_name;
*last_dir_ptr = *search_dir_ptr;
last_dir_ptr -> fx_dir_entry_name = destination_name_ptr;
source_name_ptr = search_dir_ptr -> fx_dir_entry_name;
for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++)
{
destination_name_ptr[n] = source_name_ptr[n];
}for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) { ... }
}if (last_dir_ptr) { ... }
/* ... */
search_dir_ptr = FX_NULL;
...}
}if (entry_ptr -> fx_dir_entry_attributes & FX_DIRECTORY) { ... }
else
{
/* ... */
if (name_ptr)
{
return(FX_NOT_FOUND);
}if (name_ptr) { ... }
}else { ... }
...} while (name_ptr);
#ifndef FX_MEDIA_DISABLE_SEARCH_CACHE
/* ... */
v= 0;
if ((*original_name != '\\') && (*original_name != '/') && (path_ptr))
{
while ((v< (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v]))
{
media_ptr -> fx_media_last_found_name[v] = path_ptr[v];
v++;
}while ((v< (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v])) { ... }
}if ((*original_name != '\\') && (*original_name != '/') && (path_ptr)) { ... }
if ((*original_name != '\\') && (*original_name != '/'))
{
if (v < (FX_MAX_LAST_NAME_LEN - 1))
{
media_ptr -> fx_media_last_found_name[v++] = '/';
}if (v < (FX_MAX_LAST_NAME_LEN - 1)) { ... }
}if ((*original_name != '\\') && (*original_name != '/')) { ... }
j = 0;
while ((v < FX_MAX_LAST_NAME_LEN) && (original_name[j]))
{
media_ptr -> fx_media_last_found_name[v] = original_name[j];
v++;
j++;
}while ((v < FX_MAX_LAST_NAME_LEN) && (original_name[j])) { ... }
if (v< FX_MAX_LAST_NAME_LEN)
{
media_ptr -> fx_media_last_found_name[v] = FX_NULL;
}if (v< FX_MAX_LAST_NAME_LEN) { ... }
else
{
media_ptr -> fx_media_last_found_name[0] = FX_NULL;
}else { ... }
if (search_dir_ptr)
{
media_ptr -> fx_media_last_found_directory = *search_dir_ptr;
media_ptr -> fx_media_last_found_directory_valid = FX_TRUE;
}if (search_dir_ptr) { ... }
else
{
media_ptr -> fx_media_last_found_directory_valid = FX_FALSE;
}else { ... }
media_ptr -> fx_media_last_found_entry = *entry_ptr;
media_ptr -> fx_media_last_found_entry.fx_dir_entry_name = media_ptr -> fx_media_last_found_file_name;
for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++)
{
media_ptr -> fx_media_last_found_file_name[index] = entry_ptr -> fx_dir_entry_name[index];
if (entry_ptr -> fx_dir_entry_name[index] == (CHAR)FX_NULL)
{
if (index < (FX_MAX_LONG_NAME_LEN - 1))
{
break;
}if (index < (FX_MAX_LONG_NAME_LEN - 1)) { ... }
}if (entry_ptr -> fx_dir_entry_name[index] == (CHAR)FX_NULL) { ... }
}for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) { ... }
/* ... */#endif
return(FX_SUCCESS);
}{ ... }