Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_directory.h"
#include "fx_utility.h"
#include "fx_directory_exFAT.h"
...
...
_fx_directory_next_entry_find(FX_MEDIA *, CHAR *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesfilexcommon/src/fx_directory_next_entry_find.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
323
324
325
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** FileX Component */ /** */ /** Directory */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE /* Include necessary system files. */ #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 /* FX_ENABLE_EXFAT */ #ifndef FX_NO_LOCAL_PATH FX_LOCAL_PATH_SETUP #endif ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_directory_next_entry_find PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function returns the name of the next entry in the current */ /* working directory. The function that returns the first name in the */ /* current directory must be called prior to this function. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* directory_name Destination for directory */ /* name */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_directory_entry_read Read entries from root dir */ /* _fx_utility_FAT_entry_read Read FAT entries to calculate */ /* the sub-directory size */ /* */ /* CALLED BY */ /* */ /* Application Code and */ /* FileX System Functions */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 William E. Lamie Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _fx_directory_next_entry_find(FX_MEDIA *media_ptr, CHAR *directory_name) { ULONG i; UINT status; UINT temp_status; ULONG cluster, next_cluster = 0; ULONG64 directory_size; FX_DIR_ENTRY entry; FX_DIR_ENTRY *search_dir_ptr; FX_PATH *path_ptr; #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE UINT index; CHAR *path_string_ptr = FX_NULL;/* ... */ #endif #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of times this service has been called. */ media_ptr -> fx_media_directory_next_entry_finds++;/* ... */ #endif /* Setup pointer to media name buffer. */ entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN; /* Clear the short name string. */ entry.fx_dir_entry_short_name[0] = 0; /* Check the media to make sure it is open. */ if (media_ptr -> fx_media_id != FX_MEDIA_ID) { /* Return the media not opened error. */ return(FX_MEDIA_NOT_OPEN); }if (media_ptr -> fx_media_id != FX_MEDIA_ID) { ... } /* If trace is enabled, insert this event into the trace buffer. */ FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_NEXT_ENTRY_FIND, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0) /* Protect against other threads accessing the media. */ FX_PROTECT /* First check for a local path pointer stored in the thread control block. This is only available in ThreadX Version 4 and above. *//* ... */ #ifndef FX_NO_LOCAL_PATH if (_tx_thread_current_ptr -> tx_thread_filex_ptr) { /* Setup the default path pointer. */ path_ptr = (FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr; /* Determine if we are at the root directory. */ if (path_ptr -> fx_path_directory.fx_dir_entry_name[0]) { /* No, we are not at the root directory. */ #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE /* Setup pointer to the path. */ path_string_ptr = ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_string;/* ... */ #endif /* Set the internal pointer to the search directory as well. */ search_dir_ptr = &(path_ptr -> fx_path_directory); }if (path_ptr -> fx_path_directory.fx_dir_entry_name[0]) { ... } else { /* The current default directory is the root so just set the search directory pointer to NULL. *//* ... */ search_dir_ptr = FX_NULL; }else { ... } }if (_tx_thread_current_ptr -> tx_thread_filex_ptr) { ... } else/* ... */ #endif /* Set the initial search directory to the current working directory - if there is one. *//* ... */ if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0]) { /* Setup the path pointer to the global media path. */ path_ptr = &media_ptr -> fx_media_default_path; #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE /* Setup pointer to the path. */ path_string_ptr = media_ptr -> fx_media_default_path.fx_path_string;/* ... */ #endif /* Set the internal pointer to the search directory as well. */ search_dir_ptr = &(path_ptr -> fx_path_directory); }else if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0]) { ... } else { /* Setup the path pointer to the global media path. */ path_ptr = &media_ptr -> fx_media_default_path; /* The current default directory is the root so just set the search directory pointer to NULL. *//* ... */ search_dir_ptr = FX_NULL; }else { ... } /* Calculate the directory size. */ 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 /* FX_ENABLE_EXFAT */ /* Determine the directory size. */ if (path_ptr -> fx_path_current_entry != 0) { /* Pickup the previously saved directory size. */ directory_size = search_dir_ptr -> fx_dir_entry_file_size; }if (path_ptr -> fx_path_current_entry != 0) { ... } else { /* This should only be done on the first time into next directory find. */ /* Ensure that the search directory's last search cluster is cleared. */ search_dir_ptr -> fx_dir_entry_last_search_cluster = 0; /* Calculate the directory size by counting the allocated clusters for it. *//* ... */ i = 0; cluster = search_dir_ptr -> fx_dir_entry_cluster; while (cluster < media_ptr -> fx_media_fat_reserved) { /* Increment the cluster count. */ i++; /* Read the next FAT entry. */ status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster); /* Check the return status. */ if (status != FX_SUCCESS) { /* Release media protection. */ FX_UNPROTECT /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } if ((cluster < FX_FAT_ENTRY_START) || (cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters)) { /* Release media protection. */ FX_UNPROTECT /* Return the bad status. */ 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) { ... } /* Now we can calculate the directory size. */ directory_size = (((ULONG64)media_ptr -> fx_media_bytes_per_sector) * ((ULONG64)media_ptr -> fx_media_sectors_per_cluster) * i) / (ULONG64)FX_DIR_ENTRY_SIZE; /* Save how many entries there are in the directory. */ search_dir_ptr -> fx_dir_entry_file_size = directory_size; }else { ... } #ifdef FX_ENABLE_EXFAT }else { ... } #endif /* FX_ENABLE_EXFAT */ }if (search_dir_ptr) { ... } else { /* Directory size is the number of entries in the root directory. */ directory_size = (ULONG)media_ptr -> fx_media_root_directory_entries; }else { ... } /* Preset status with an error return. */ status = FX_NO_MORE_ENTRIES; /* Determine if the current entry is inside of the directory's range. */ while (path_ptr -> fx_path_current_entry < directory_size) { /* Read an entry from the directory. */ temp_status = _fx_directory_entry_read(media_ptr, search_dir_ptr, &(path_ptr -> fx_path_current_entry), &entry); /* Check for error status. */ if (temp_status != FX_SUCCESS) { /* Release media protection. */ FX_UNPROTECT /* Return error status. */ return(temp_status); }if (temp_status != FX_SUCCESS) { ... } #ifdef FX_ENABLE_EXFAT if (entry.fx_dir_entry_type == FX_EXFAT_DIR_ENTRY_TYPE_END_MARKER) { /* Set the error code. */ status = FX_NO_MORE_ENTRIES; /* Get out of the loop. */ break; }if (entry.fx_dir_entry_type == FX_EXFAT_DIR_ENTRY_TYPE_END_MARKER) { ... } /* ... */#endif /* FX_ENABLE_EXFAT */ /* Check to see if the entry has something in it. */ #ifdef FX_ENABLE_EXFAT else if (entry.fx_dir_entry_type != FX_EXFAT_DIR_ENTRY_TYPE_FILE_DIRECTORY) #else if (((UCHAR)entry.fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_FREE) && (entry.fx_dir_entry_short_name[0] == 0)) #endif /* FX_ENABLE_EXFAT */ { /* Current entry is free, skip to next entry and continue the loop. */ path_ptr -> fx_path_current_entry++; continue; ...} #ifdef FX_ENABLE_EXFAT else /* FX_EXFAT_DIR_ENTRY_TYPE_FILE_DIRECTORY */ #else else if ((UCHAR)entry.fx_dir_entry_name[0] != (UCHAR)FX_DIR_ENTRY_DONE) #endif /* FX_ENABLE_EXFAT */ { /* A valid directory entry is present. */ /* Copy the name into the destination. */ for (i = 0; entry.fx_dir_entry_name[i]; i++) { *directory_name = entry.fx_dir_entry_name[i]; directory_name++; }for (i = 0; entry.fx_dir_entry_name[i]; i++) { ... } /* Place a NULL at the end of the directory name. */ *directory_name = (CHAR)0; /* Increment the current entry for the media. */ path_ptr -> fx_path_current_entry++; #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE { UINT v, j; /* If a subsequent search for the same name is done, it will find it immediately. */ /* Set the index of the saved name string. */ v = 0; /* First, build the full path and name. */ if (path_string_ptr) { /* Copy the path into the destination. */ while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (path_string_ptr[v])) { /* Copy one character. */ media_ptr -> fx_media_last_found_name[v] = path_string_ptr[v]; /* Move to next character. */ v++; }while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (path_string_ptr[v])) { ... } }if (path_string_ptr) { ... } /* We know there is room at this point, place a directory separator character. */ media_ptr -> fx_media_last_found_name[v++] = '/'; /* Now append the name to the path. */ j = 0; while ((v < FX_MAX_LAST_NAME_LEN) && (entry.fx_dir_entry_name[j])) { /* Copy one character. */ media_ptr -> fx_media_last_found_name[v] = entry.fx_dir_entry_name[j]; /* Move to next character. */ v++; j++; }while ((v < FX_MAX_LAST_NAME_LEN) && (entry.fx_dir_entry_name[j])) { ... } /* Null terminate the last name string. */ if (v < FX_MAX_LAST_NAME_LEN) { /* Null terminate. */ media_ptr -> fx_media_last_found_name[v] = FX_NULL; }if (v < FX_MAX_LAST_NAME_LEN) { ... } else { /* The string is too big, NULL the string so it won't be used in searching. */ media_ptr -> fx_media_last_found_name[0] = FX_NULL; }else { ... } /* Determine if there is a search pointer. */ if (search_dir_ptr) { /* Yes, there is a search directory pointer so save it! */ media_ptr -> fx_media_last_found_directory = *search_dir_ptr; /* Indicate the search directory is valid. */ media_ptr -> fx_media_last_found_directory_valid = FX_TRUE; }if (search_dir_ptr) { ... } else { /* Indicate the search directory is not valid. */ media_ptr -> fx_media_last_found_directory_valid = FX_FALSE; }else { ... } /* Copy the directory entry. */ media_ptr -> fx_media_last_found_entry = entry; /* Setup the last found directory entry to point at the last found internal file name. */ media_ptr -> fx_media_last_found_entry.fx_dir_entry_name = media_ptr -> fx_media_last_found_file_name; /* Copy the actual directory name into the cached directory name. */ for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) { /* Copy character into the cached directory name. */ media_ptr -> fx_media_last_found_file_name[index] = entry.fx_dir_entry_name[index]; /* See if we have copied the NULL termination character. */ if (entry.fx_dir_entry_name[index] == (CHAR)FX_NULL) { /* Check to see if we use the break to get out of the loop. */ if (v < (FX_MAX_LONG_NAME_LEN - 1)) { /* Yes, not at the end of the string, break. */ break; }if (v < (FX_MAX_LONG_NAME_LEN - 1)) { ... } }if (entry.fx_dir_entry_name[index] == (CHAR)FX_NULL) { ... } }for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) { ... } ...}/* ... */ #endif /* Set return status to success. */ status = FX_SUCCESS; /* Get out of the loop. */ break; ...} #ifndef FX_ENABLE_EXFAT else { /* Set the error code. */ status = FX_NO_MORE_ENTRIES; /* Get out of the loop. */ break; }else { ... } /* ... */#endif /* FX_ENABLE_EXFAT */ }while (path_ptr -> fx_path_current_entry < directory_size) { ... } /* Release media protection. */ FX_UNPROTECT /* Return status to the caller. */ return(status); }{ ... }