fx_directory_search.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************************************************** | ||
| 2 | * Copyright (c) 2024 Microsoft Corporation | ||
| 3 | * Copyright (c) 2026-present Eclipse ThreadX contributors | ||
| 4 | * | ||
| 5 | * This program and the accompanying materials are made available under the | ||
| 6 | * terms of the MIT License which is available at | ||
| 7 | * https://opensource.org/licenses/MIT. | ||
| 8 | * | ||
| 9 | * SPDX-License-Identifier: MIT | ||
| 10 | **************************************************************************/ | ||
| 11 | |||
| 12 | |||
| 13 | /**************************************************************************/ | ||
| 14 | /**************************************************************************/ | ||
| 15 | /** */ | ||
| 16 | /** FileX Component */ | ||
| 17 | /** */ | ||
| 18 | /** Directory */ | ||
| 19 | /** */ | ||
| 20 | /**************************************************************************/ | ||
| 21 | /**************************************************************************/ | ||
| 22 | |||
| 23 | #define FX_SOURCE_CODE | ||
| 24 | |||
| 25 | |||
| 26 | /* Include necessary system files. */ | ||
| 27 | |||
| 28 | #include "fx_api.h" | ||
| 29 | #include "fx_system.h" | ||
| 30 | #include "fx_directory.h" | ||
| 31 | #include "fx_utility.h" | ||
| 32 | |||
| 33 | #ifndef FX_NO_LOCAL_PATH | ||
| 34 | FX_LOCAL_PATH_SETUP | ||
| 35 | #endif | ||
| 36 | |||
| 37 | |||
| 38 | /**************************************************************************/ | ||
| 39 | /* */ | ||
| 40 | /* FUNCTION RELEASE */ | ||
| 41 | /* */ | ||
| 42 | /* _fx_directory_search PORTABLE C */ | ||
| 43 | /* 6.1.10 */ | ||
| 44 | /* AUTHOR */ | ||
| 45 | /* */ | ||
| 46 | /* William E. Lamie, Microsoft Corporation */ | ||
| 47 | /* */ | ||
| 48 | /* DESCRIPTION */ | ||
| 49 | /* */ | ||
| 50 | /* This function searches the media for the supplied name. The search */ | ||
| 51 | /* routine will find files as well as directory names. */ | ||
| 52 | /* */ | ||
| 53 | /* INPUT */ | ||
| 54 | /* */ | ||
| 55 | /* media_ptr Media control block pointer */ | ||
| 56 | /* name_ptr Name pointer */ | ||
| 57 | /* entry_ptr Pointer to directory entry */ | ||
| 58 | /* record */ | ||
| 59 | /* last_dir_ptr Pointer to destination for */ | ||
| 60 | /* the last directory entry */ | ||
| 61 | /* last_name_ptr Pointer to the last name */ | ||
| 62 | /* token that was searched for */ | ||
| 63 | /* */ | ||
| 64 | /* OUTPUT */ | ||
| 65 | /* */ | ||
| 66 | /* return status */ | ||
| 67 | /* */ | ||
| 68 | /* CALLS */ | ||
| 69 | /* */ | ||
| 70 | /* _fx_directory_name_extract Extract directory name from */ | ||
| 71 | /* input string */ | ||
| 72 | /* _fx_directory_entry_read Read entries from root dir */ | ||
| 73 | /* _fx_utility_FAT_entry_read Read FAT entries to calculate */ | ||
| 74 | /* the sub-directory size */ | ||
| 75 | /* */ | ||
| 76 | /* CALLED BY */ | ||
| 77 | /* */ | ||
| 78 | /* FileX System Functions */ | ||
| 79 | /* */ | ||
| 80 | /**************************************************************************/ | ||
| 81 | 7707583 | UINT _fx_directory_search(FX_MEDIA *media_ptr, CHAR *name_ptr, FX_DIR_ENTRY *entry_ptr, | |
| 82 | FX_DIR_ENTRY *last_dir_ptr, CHAR **last_name_ptr) | ||
| 83 | { | ||
| 84 | |||
| 85 | ULONG i, n; | ||
| 86 | UINT found; | ||
| 87 | UINT status; | ||
| 88 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 89 | UINT v, j; | ||
| 90 | #endif /* FX_MEDIA_DISABLE_SEARCH_CACHE */ | ||
| 91 | 7707583 | ULONG cluster, next_cluster = 0; | |
| 92 | ULONG64 directory_size; | ||
| 93 | CHAR *dir_name_ptr; | ||
| 94 | CHAR *work_ptr; | ||
| 95 | CHAR *source_name_ptr; | ||
| 96 | CHAR *destination_name_ptr; | ||
| 97 | FX_DIR_ENTRY search_dir; | ||
| 98 | FX_DIR_ENTRY *search_dir_ptr; | ||
| 99 | CHAR *name, alpha, name_alpha; | ||
| 100 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 101 | UINT index; | ||
| 102 | 7707583 | CHAR *path_ptr = FX_NULL; | |
| 103 | 7707583 | CHAR *original_name = name_ptr; | |
| 104 | #endif | ||
| 105 | |||
| 106 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 107 | |||
| 108 | /* Increment the number of directory search requests. */ | ||
| 109 | 7707583 | media_ptr -> fx_media_directory_searches++; | |
| 110 | #endif | ||
| 111 | |||
| 112 | /* Setup pointer to media name buffer. */ | ||
| 113 | 7707583 | name = media_ptr -> fx_media_name_buffer; | |
| 114 | |||
| 115 | /* Setup the last directory, if required. */ | ||
| 116 |
2/2✓ Branch 2 → 3 taken 710305 times.
✓ Branch 2 → 4 taken 6997278 times.
|
7707583 | if (last_dir_ptr) |
| 117 | { | ||
| 118 | |||
| 119 | /* Set the first character of the directory entry to NULL to | ||
| 120 | indicate root or no directory. */ | ||
| 121 | 710305 | last_dir_ptr -> fx_dir_entry_name[0] = 0; | |
| 122 | } | ||
| 123 | |||
| 124 | /* Determine if the file name has a full directory path. */ | ||
| 125 |
4/4✓ Branch 4 → 5 taken 7580732 times.
✓ Branch 4 → 6 taken 126851 times.
✓ Branch 5 → 6 taken 7714 times.
✓ Branch 5 → 7 taken 7573018 times.
|
7707583 | if ((*name_ptr == '\\') || (*name_ptr == '/')) |
| 126 | { | ||
| 127 | |||
| 128 | /* Directory name has full path, set the search pointer to NULL. */ | ||
| 129 | 134565 | search_dir_ptr = FX_NULL; | |
| 130 | } | ||
| 131 | else | ||
| 132 | { | ||
| 133 | |||
| 134 | /* Set the initial search directory to the current working | ||
| 135 | directory - if there is one. */ | ||
| 136 | |||
| 137 | /* First check for a local path pointer stored in the thread control block. This | ||
| 138 | is only available in ThreadX Version 4 and above. */ | ||
| 139 | #ifndef FX_NO_LOCAL_PATH | ||
| 140 |
2/2✓ Branch 7 → 8 taken 18410 times.
✓ Branch 7 → 11 taken 7216998 times.
|
7235408 | if (_tx_thread_current_ptr -> tx_thread_filex_ptr) |
| 141 | { | ||
| 142 | |||
| 143 | /* Determine if the local directory is not the root directory. */ | ||
| 144 |
2/2✓ Branch 8 → 9 taken 16638 times.
✓ Branch 8 → 10 taken 1772 times.
|
18410 | if (((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_directory.fx_dir_entry_name[0]) |
| 145 | { | ||
| 146 | |||
| 147 | /* Start at the current working directory of the media. */ | ||
| 148 | 16638 | search_dir = ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_directory; | |
| 149 | |||
| 150 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 151 | |||
| 152 | /* Setup pointer to the path. */ | ||
| 153 | 16638 | path_ptr = ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_string; | |
| 154 | #endif | ||
| 155 | |||
| 156 | /* Set the internal pointer to the search directory as well. */ | ||
| 157 | 16638 | search_dir_ptr = &search_dir; | |
| 158 | } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | |||
| 162 | /* We are searching in the root directory. */ | ||
| 163 | 1772 | search_dir_ptr = FX_NULL; | |
| 164 | } | ||
| 165 | } | ||
| 166 | else | ||
| 167 | #endif | ||
| 168 |
4/4✓ Branch 7 → 8 taken 5902 times.
✓ Branch 7 → 9 taken 331708 times.
✓ Branch 11 → 12 taken 2328 times.
✓ Branch 11 → 13 taken 7214670 times.
|
7554608 | if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0]) |
| 169 | { | ||
| 170 | |||
| 171 | /* Start at the current working directory of the media. */ | ||
| 172 | 8230 | search_dir = media_ptr -> fx_media_default_path.fx_path_directory; | |
| 173 | |||
| 174 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 175 | |||
| 176 | /* Setup pointer to the path. */ | ||
| 177 | 8230 | path_ptr = media_ptr -> fx_media_default_path.fx_path_string; | |
| 178 | #endif | ||
| 179 | |||
| 180 | /* Set the internal pointer to the search directory as well. */ | ||
| 181 | 8230 | search_dir_ptr = &search_dir; | |
| 182 | } | ||
| 183 | else | ||
| 184 | { | ||
| 185 | |||
| 186 | /* The current default directory is the root so just set the | ||
| 187 | search directory pointer to NULL. */ | ||
| 188 | 7546378 | search_dir_ptr = FX_NULL; | |
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 193 | |||
| 194 | /* Determine if there is a previously found directory entry. */ | ||
| 195 |
4/4✓ Branch 10 → 11 taken 88302 times.
✓ Branch 10 → 79 taken 309130 times.
✓ Branch 14 → 15 taken 6923449 times.
✓ Branch 14 → 83 taken 386702 times.
|
7707583 | if (media_ptr -> fx_media_last_found_name[0]) |
| 196 | { | ||
| 197 | |||
| 198 | UINT match; | ||
| 199 | CHAR *temp_ptr, beta; | ||
| 200 | |||
| 201 | /* Yes, there is a previously found directory in our cache. */ | ||
| 202 | |||
| 203 | /* Initialize the index. */ | ||
| 204 | 7011751 | v = 0; | |
| 205 | |||
| 206 | /* Determine if there is a full path. */ | ||
| 207 |
8/8✓ Branch 11 → 12 taken 88266 times.
✓ Branch 11 → 13 taken 36 times.
✓ Branch 12 → 13 taken 567 times.
✓ Branch 12 → 27 taken 87699 times.
✓ Branch 15 → 16 taken 6923404 times.
✓ Branch 15 → 17 taken 45 times.
✓ Branch 16 → 17 taken 442 times.
✓ Branch 16 → 31 taken 6922962 times.
|
7011751 | if ((*name_ptr == '\\') || (*name_ptr == '/')) |
| 208 | { | ||
| 209 | |||
| 210 | /* Yes, the full path is in the name buffer. Simply compare with what is in | ||
| 211 | the last search buffer. */ | ||
| 212 |
8/8✓ Branch 21 → 22 taken 16688 times.
✓ Branch 21 → 23 taken 48 times.
✓ Branch 22 → 14 taken 16612 times.
✓ Branch 22 → 23 taken 76 times.
✓ Branch 25 → 26 taken 20153 times.
✓ Branch 25 → 27 taken 60 times.
✓ Branch 26 → 18 taken 20083 times.
✓ Branch 26 → 27 taken 70 times.
|
36949 | while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[v])) |
| 213 | { | ||
| 214 | |||
| 215 | /* Pickup the respective name characters. */ | ||
| 216 | 36695 | alpha = name_ptr[v]; | |
| 217 | 36695 | beta = media_ptr -> fx_media_last_found_name[v]; | |
| 218 | |||
| 219 | /* Ensure directory markers are the same. */ | ||
| 220 |
4/4✓ Branch 14 → 15 taken 68 times.
✓ Branch 14 → 16 taken 16544 times.
✓ Branch 18 → 19 taken 85 times.
✓ Branch 18 → 20 taken 19998 times.
|
36695 | if (alpha == '\\') |
| 221 | { | ||
| 222 | 153 | alpha = '/'; | |
| 223 | } | ||
| 224 |
4/4✓ Branch 16 → 17 taken 104 times.
✓ Branch 16 → 18 taken 16508 times.
✓ Branch 20 → 21 taken 256 times.
✓ Branch 20 → 22 taken 19827 times.
|
36695 | if (beta == '\\') |
| 225 | { | ||
| 226 | 360 | beta = '/'; | |
| 227 | } | ||
| 228 | |||
| 229 | /* Is the name the same? */ | ||
| 230 |
4/4✓ Branch 18 → 19 taken 479 times.
✓ Branch 18 → 20 taken 16133 times.
✓ Branch 22 → 23 taken 357 times.
✓ Branch 22 → 24 taken 19726 times.
|
36695 | if (alpha != beta) |
| 231 | { | ||
| 232 | |||
| 233 | /* Break out of loop! */ | ||
| 234 | 836 | break; | |
| 235 | } | ||
| 236 | |||
| 237 | /* Move to next character. */ | ||
| 238 | 35859 | v++; | |
| 239 | } | ||
| 240 | |||
| 241 | /* Determine if we have a match. */ | ||
| 242 |
4/4✓ Branch 23 → 24 taken 517 times.
✓ Branch 23 → 25 taken 86 times.
✓ Branch 27 → 28 taken 397 times.
✓ Branch 27 → 29 taken 90 times.
|
1090 | if (name_ptr[v] != media_ptr -> fx_media_last_found_name[v]) |
| 243 | { | ||
| 244 | 914 | match = FX_FALSE; | |
| 245 | } | ||
| 246 | else | ||
| 247 | { | ||
| 248 | 176 | match = FX_TRUE; | |
| 249 | } | ||
| 250 | } | ||
| 251 | else | ||
| 252 | { | ||
| 253 | |||
| 254 | /* Default to found. */ | ||
| 255 | 7010661 | match = FX_TRUE; | |
| 256 | |||
| 257 | /* Determine if there is a default path to compare with. */ | ||
| 258 |
4/4✓ Branch 27 → 28 taken 3905 times.
✓ Branch 27 → 40 taken 83794 times.
✓ Branch 31 → 32 taken 16121 times.
✓ Branch 31 → 44 taken 6906841 times.
|
7010661 | if (path_ptr) |
| 259 | { | ||
| 260 | |||
| 261 | /* Yes, compare the current path with what is contained in the last | ||
| 262 | found buffer. Note that the last found name must have at least one | ||
| 263 | path separator as well as room for at least one character for a name. */ | ||
| 264 |
8/8✓ Branch 36 → 37 taken 61157 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 37 → 29 taken 57276 times.
✓ Branch 37 → 38 taken 3881 times.
✓ Branch 40 → 41 taken 215117 times.
✓ Branch 40 → 42 taken 15 times.
✓ Branch 41 → 33 taken 199061 times.
✓ Branch 41 → 42 taken 16056 times.
|
276297 | while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v])) |
| 265 | { | ||
| 266 | |||
| 267 | /* Pickup the respective name characters. */ | ||
| 268 | 256337 | alpha = media_ptr -> fx_media_last_found_name[v]; | |
| 269 | 256337 | beta = path_ptr[v]; | |
| 270 | |||
| 271 | /* Ensure directory markers are the same. */ | ||
| 272 |
4/4✓ Branch 29 → 30 taken 4493 times.
✓ Branch 29 → 31 taken 52783 times.
✓ Branch 33 → 34 taken 26513 times.
✓ Branch 33 → 35 taken 172548 times.
|
256337 | if (alpha == '\\') |
| 273 | { | ||
| 274 | 31006 | alpha = '/'; | |
| 275 | } | ||
| 276 |
4/4✓ Branch 31 → 32 taken 4859 times.
✓ Branch 31 → 33 taken 52417 times.
✓ Branch 35 → 36 taken 27266 times.
✓ Branch 35 → 37 taken 171795 times.
|
256337 | if (beta == '\\') |
| 277 | { | ||
| 278 | 32125 | beta = '/'; | |
| 279 | } | ||
| 280 | |||
| 281 | /* Is the name the same? */ | ||
| 282 |
4/4✓ Branch 33 → 34 taken 16 times.
✓ Branch 33 → 35 taken 57260 times.
✓ Branch 37 → 38 taken 50 times.
✓ Branch 37 → 39 taken 199011 times.
|
256337 | if (alpha != beta) |
| 283 | { | ||
| 284 | |||
| 285 | /* Break out of loop! */ | ||
| 286 | 66 | break; | |
| 287 | } | ||
| 288 | |||
| 289 | /* Move to next character. */ | ||
| 290 | 256271 | v++; | |
| 291 | } | ||
| 292 | |||
| 293 | /* Determine if we don't have a match... The relative path must be exhausted. */ | ||
| 294 |
4/4✓ Branch 38 → 39 taken 16 times.
✓ Branch 38 → 40 taken 3889 times.
✓ Branch 42 → 43 taken 50 times.
✓ Branch 42 → 44 taken 16071 times.
|
20026 | if (path_ptr[v]) |
| 295 | { | ||
| 296 | 66 | match = FX_FALSE; | |
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | /* Determine if we still have a match. */ | ||
| 301 |
4/4✓ Branch 40 → 41 taken 87683 times.
✓ Branch 40 → 61 taken 16 times.
✓ Branch 44 → 45 taken 6922912 times.
✓ Branch 44 → 65 taken 50 times.
|
7010661 | if (match) |
| 302 | { | ||
| 303 | |||
| 304 | /* Now examine the rest of the last name and the newly supplied | ||
| 305 | input name. */ | ||
| 306 | |||
| 307 | /* Determine if a valid directory separator is present. */ | ||
| 308 |
4/4✓ Branch 41 → 42 taken 87663 times.
✓ Branch 41 → 44 taken 20 times.
✓ Branch 45 → 46 taken 6922857 times.
✓ Branch 45 → 48 taken 55 times.
|
7010595 | if ((media_ptr -> fx_media_last_found_name[v] != '\\') && |
| 309 |
4/4✓ Branch 42 → 43 taken 632 times.
✓ Branch 42 → 44 taken 87031 times.
✓ Branch 46 → 47 taken 1026 times.
✓ Branch 46 → 48 taken 6921831 times.
|
7010520 | (media_ptr -> fx_media_last_found_name[v] != '/')) |
| 310 | { | ||
| 311 | |||
| 312 | /* Set match to false - invalid directory path separator. */ | ||
| 313 | 1658 | match = FX_FALSE; | |
| 314 | } | ||
| 315 | else | ||
| 316 | { | ||
| 317 | /* Position past the next directory separator in the | ||
| 318 | last name string. */ | ||
| 319 | 7008937 | v++; | |
| 320 | } | ||
| 321 | |||
| 322 | /* Yes, the full path is in the name buffer. Simply compare with what is in | ||
| 323 | the last search buffer. */ | ||
| 324 | 7010595 | j = 0; | |
| 325 |
12/12✓ Branch 53 → 54 taken 411703 times.
✓ Branch 53 → 56 taken 24 times.
✓ Branch 54 → 55 taken 410140 times.
✓ Branch 54 → 56 taken 1563 times.
✓ Branch 55 → 46 taken 409512 times.
✓ Branch 55 → 56 taken 628 times.
✓ Branch 57 → 58 taken 36978929 times.
✓ Branch 57 → 60 taken 43 times.
✓ Branch 58 → 59 taken 36964359 times.
✓ Branch 58 → 60 taken 14570 times.
✓ Branch 59 → 50 taken 36963343 times.
✓ Branch 59 → 60 taken 1016 times.
|
37390699 | while ((v < (FX_MAX_LAST_NAME_LEN - 1)) && (name_ptr[j]) && (match)) |
| 326 | { | ||
| 327 | |||
| 328 | /* Pickup the respective name characters. */ | ||
| 329 | 37372855 | alpha = name_ptr[j]; | |
| 330 | 37372855 | beta = media_ptr -> fx_media_last_found_name[v]; | |
| 331 | |||
| 332 | /* Ensure directory markers are the same. */ | ||
| 333 |
4/4✓ Branch 46 → 47 taken 24 times.
✓ Branch 46 → 48 taken 409488 times.
✓ Branch 50 → 51 taken 30 times.
✓ Branch 50 → 52 taken 36963313 times.
|
37372855 | if (alpha == '\\') |
| 334 | { | ||
| 335 | 54 | alpha = '/'; | |
| 336 | } | ||
| 337 |
4/4✓ Branch 48 → 49 taken 24 times.
✓ Branch 48 → 50 taken 409488 times.
✓ Branch 52 → 53 taken 30 times.
✓ Branch 52 → 54 taken 36963313 times.
|
37372855 | if (beta == '\\') |
| 338 | { | ||
| 339 | 54 | beta = '/'; | |
| 340 | } | ||
| 341 | |||
| 342 | /* Is the name the same? */ | ||
| 343 |
4/4✓ Branch 50 → 51 taken 85468 times.
✓ Branch 50 → 52 taken 324044 times.
✓ Branch 54 → 55 taken 6907283 times.
✓ Branch 54 → 56 taken 30056060 times.
|
37372855 | if (alpha != beta) |
| 344 | { | ||
| 345 | |||
| 346 | /* Break out of loop! */ | ||
| 347 | 6992751 | break; | |
| 348 | } | ||
| 349 | |||
| 350 | /* Move to next character. */ | ||
| 351 | 30380104 | v++; | |
| 352 | 30380104 | j++; | |
| 353 | } | ||
| 354 | |||
| 355 | /* Avoid accessing fx_media_last_found_name out of bounds. */ | ||
| 356 |
4/4✓ Branch 56 → 57 taken 4 times.
✓ Branch 56 → 58 taken 87679 times.
✓ Branch 60 → 61 taken 5 times.
✓ Branch 60 → 62 taken 6922907 times.
|
7010595 | if (v >= 256) |
| 357 | { | ||
| 358 | 9 | match = FX_FALSE; | |
| 359 | } | ||
| 360 |
8/8✓ Branch 58 → 59 taken 87047 times.
✓ Branch 58 → 61 taken 632 times.
✓ Branch 59 → 60 taken 85570 times.
✓ Branch 59 → 61 taken 1477 times.
✓ Branch 62 → 63 taken 6921881 times.
✓ Branch 62 → 65 taken 1026 times.
✓ Branch 63 → 64 taken 6907420 times.
✓ Branch 63 → 65 taken 14461 times.
|
7010586 | else if ((match) && (name_ptr[j] != media_ptr -> fx_media_last_found_name[v])) |
| 361 | { | ||
| 362 | |||
| 363 | /* We don't have a match. */ | ||
| 364 | 6992990 | match = FX_FALSE; | |
| 365 | } | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | /* Now determine if we actually found a match. */ | ||
| 370 |
4/4✓ Branch 61 → 62 taken 1563 times.
✓ Branch 61 → 79 taken 86739 times.
✓ Branch 65 → 66 taken 14551 times.
✓ Branch 65 → 83 taken 6908898 times.
|
7011751 | if (match) |
| 371 | { | ||
| 372 | |||
| 373 | /* Save the directory entry name pointer. */ | ||
| 374 | 16114 | temp_ptr = entry_ptr -> fx_dir_entry_name; | |
| 375 | |||
| 376 | /* Copy the saved directory entry. */ | ||
| 377 | 16114 | *entry_ptr = media_ptr -> fx_media_last_found_entry; | |
| 378 | |||
| 379 | /* Restore the directory entry name pointer. */ | ||
| 380 | 16114 | entry_ptr -> fx_dir_entry_name = temp_ptr; | |
| 381 | |||
| 382 | /* Copy the directory name into the destination directory name. */ | ||
| 383 |
4/4✓ Branch 67 → 63 taken 13055 times.
✓ Branch 67 → 68 taken 8 times.
✓ Branch 71 → 67 taken 75142 times.
✓ Branch 71 → 72 taken 10 times.
|
88215 | for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) |
| 384 | { | ||
| 385 | |||
| 386 | /* Copy character into the destination. */ | ||
| 387 | 88197 | temp_ptr[index] = media_ptr -> fx_media_last_found_file_name[index]; | |
| 388 | |||
| 389 | /* See if we have copied the NULL termination character. */ | ||
| 390 |
4/4✓ Branch 63 → 64 taken 1563 times.
✓ Branch 63 → 66 taken 11492 times.
✓ Branch 67 → 68 taken 14551 times.
✓ Branch 67 → 70 taken 60591 times.
|
88197 | if (temp_ptr[index] == (CHAR)FX_NULL) |
| 391 | { | ||
| 392 | |||
| 393 | /* Determine if we should break here or at the top of the loop. */ | ||
| 394 |
4/4✓ Branch 64 → 65 taken 1555 times.
✓ Branch 64 → 66 taken 8 times.
✓ Branch 68 → 69 taken 14541 times.
✓ Branch 68 → 70 taken 10 times.
|
16114 | if (index < (FX_MAX_LONG_NAME_LEN - 1)) |
| 395 | { | ||
| 396 | |||
| 397 | /* Yes, break out of the loop early. */ | ||
| 398 | 16096 | break; | |
| 399 | } | ||
| 400 | } | ||
| 401 | } | ||
| 402 | |||
| 403 | /* Determine if there is a search directory to copy. */ | ||
| 404 |
8/8✓ Branch 68 → 69 taken 356 times.
✓ Branch 68 → 76 taken 1207 times.
✓ Branch 69 → 70 taken 314 times.
✓ Branch 69 → 76 taken 42 times.
✓ Branch 72 → 73 taken 402 times.
✓ Branch 72 → 80 taken 14149 times.
✓ Branch 73 → 74 taken 357 times.
✓ Branch 73 → 80 taken 45 times.
|
16114 | if ((last_dir_ptr) && (media_ptr -> fx_media_last_found_directory_valid)) |
| 405 | { | ||
| 406 | |||
| 407 | /* Yes, there was a search directory... and one is requested in this request as well. | ||
| 408 | Simply copy it into the destination. */ | ||
| 409 | |||
| 410 | /* First, save the name pointer from the list directory pointer. */ | ||
| 411 | 671 | destination_name_ptr = last_dir_ptr -> fx_dir_entry_name; | |
| 412 | |||
| 413 | /* Copy the entire directory entry structure. */ | ||
| 414 | 671 | *last_dir_ptr = media_ptr -> fx_media_last_found_directory; | |
| 415 | |||
| 416 | /* Restore the original name buffer pointer. */ | ||
| 417 | 671 | last_dir_ptr -> fx_dir_entry_name = destination_name_ptr; | |
| 418 | |||
| 419 | /* Pickup pointer to name to copy. */ | ||
| 420 | 671 | source_name_ptr = media_ptr -> fx_media_last_found_directory.fx_dir_entry_name; | |
| 421 | |||
| 422 | /* Loop to copy the name into the last directory name buffer. */ | ||
| 423 |
4/4✓ Branch 75 → 71 taken 5174 times.
✓ Branch 75 → 76 taken 4 times.
✓ Branch 79 → 75 taken 6102 times.
✓ Branch 79 → 80 taken 5 times.
|
11285 | for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) |
| 424 | { | ||
| 425 | |||
| 426 | /* Copy a character. */ | ||
| 427 | 11276 | destination_name_ptr[n] = source_name_ptr[n]; | |
| 428 | |||
| 429 | /* See if we have copied the NULL termination character. */ | ||
| 430 |
4/4✓ Branch 71 → 72 taken 314 times.
✓ Branch 71 → 74 taken 4860 times.
✓ Branch 75 → 76 taken 357 times.
✓ Branch 75 → 78 taken 5745 times.
|
11276 | if (source_name_ptr[n] == (CHAR)FX_NULL) |
| 431 | { | ||
| 432 | |||
| 433 | /* Determine if we should break here or at the top of the loop. */ | ||
| 434 |
4/4✓ Branch 72 → 73 taken 310 times.
✓ Branch 72 → 74 taken 4 times.
✓ Branch 76 → 77 taken 352 times.
✓ Branch 76 → 78 taken 5 times.
|
671 | if (n < (FX_MAX_LONG_NAME_LEN - 1)) |
| 435 | { | ||
| 436 | |||
| 437 | /* Yes, break out of the loop early. */ | ||
| 438 | 662 | break; | |
| 439 | } | ||
| 440 | } | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | /* Return the last name pointer, if required. */ | ||
| 445 |
4/4✓ Branch 76 → 77 taken 328 times.
✓ Branch 76 → 78 taken 1235 times.
✓ Branch 80 → 81 taken 373 times.
✓ Branch 80 → 82 taken 14178 times.
|
16114 | if (last_name_ptr) |
| 446 | { | ||
| 447 | |||
| 448 | /* Just set the last name to initial name string. */ | ||
| 449 | 701 | *last_name_ptr = temp_ptr; | |
| 450 | } | ||
| 451 | |||
| 452 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 453 | |||
| 454 | /* Increment the number of directory search cache hits. */ | ||
| 455 | 16114 | media_ptr -> fx_media_directory_search_cache_hits++; | |
| 456 | #endif | ||
| 457 | |||
| 458 | /* Return success. */ | ||
| 459 | 16114 | return(FX_SUCCESS); | |
| 460 | } | ||
| 461 | } | ||
| 462 | |||
| 463 | /* Not a sequential search, invalidate the saved information. */ | ||
| 464 | 7691469 | media_ptr -> fx_media_last_found_name[0] = FX_NULL; | |
| 465 | |||
| 466 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 467 | |||
| 468 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 469 | 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) | ||
| 470 | #else | ||
| 471 | |||
| 472 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 473 | FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_DIR_CACHE_MISS, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) | ||
| 474 | #endif | ||
| 475 | #endif | ||
| 476 | |||
| 477 | /* Loop to traverse the directory paths to find the specified file. */ | ||
| 478 | do | ||
| 479 | { | ||
| 480 | |||
| 481 | /* Remember the last name pointer, if required. */ | ||
| 482 |
4/4✓ Branch 80 → 81 taken 374770 times.
✓ Branch 80 → 82 taken 82507 times.
✓ Branch 84 → 85 taken 468394 times.
✓ Branch 84 → 86 taken 6904450 times.
|
7830121 | if (last_name_ptr) |
| 483 | { | ||
| 484 | |||
| 485 | /* Just set the last name to initial name string. */ | ||
| 486 | 843164 | *last_name_ptr = name_ptr; | |
| 487 | } | ||
| 488 | |||
| 489 | /* Extract file name. */ | ||
| 490 | 7830121 | name_ptr = _fx_directory_name_extract(name_ptr, name); | |
| 491 | |||
| 492 | /* Calculate the directory size. */ | ||
| 493 |
4/4✓ Branch 83 → 84 taken 66470 times.
✓ Branch 83 → 102 taken 390807 times.
✓ Branch 87 → 88 taken 83680 times.
✓ Branch 87 → 106 taken 7289164 times.
|
7830121 | if (search_dir_ptr) |
| 494 | { | ||
| 495 | |||
| 496 | /* Ensure that the search directory's last search cluster is cleared. */ | ||
| 497 | 150150 | search_dir_ptr -> fx_dir_entry_last_search_cluster = 0; | |
| 498 | |||
| 499 | /* Calculate the directory size by counting the allocated | ||
| 500 | clusters for it. */ | ||
| 501 | 150150 | i = 0; | |
| 502 | 150150 | cluster = search_dir_ptr -> fx_dir_entry_cluster; | |
| 503 |
4/4✓ Branch 93 → 85 taken 181702 times.
✓ Branch 93 → 94 taken 66422 times.
✓ Branch 97 → 89 taken 230818 times.
✓ Branch 97 → 98 taken 83598 times.
|
562540 | while (cluster < media_ptr -> fx_media_fat_reserved) |
| 504 | { | ||
| 505 | |||
| 506 | /* Increment the cluster count. */ | ||
| 507 | 412520 | i++; | |
| 508 | |||
| 509 | /* Read the next FAT entry. */ | ||
| 510 | 412520 | status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster); | |
| 511 | |||
| 512 | /* Check the return status. */ | ||
| 513 |
4/4✓ Branch 86 → 87 taken 4 times.
✓ Branch 86 → 88 taken 181698 times.
✓ Branch 90 → 91 taken 5 times.
✓ Branch 90 → 92 taken 230813 times.
|
412520 | if (status != FX_SUCCESS) |
| 514 | { | ||
| 515 | |||
| 516 | /* Return the bad status. */ | ||
| 517 | 9 | return(status); | |
| 518 | } | ||
| 519 | |||
| 520 | /* Check for error situation. */ | ||
| 521 |
12/12✓ Branch 88 → 89 taken 181678 times.
✓ Branch 88 → 91 taken 20 times.
✓ Branch 89 → 90 taken 181666 times.
✓ Branch 89 → 91 taken 12 times.
✓ Branch 90 → 91 taken 12 times.
✓ Branch 90 → 92 taken 181654 times.
✓ Branch 92 → 93 taken 230766 times.
✓ Branch 92 → 95 taken 47 times.
✓ Branch 93 → 94 taken 230751 times.
✓ Branch 93 → 95 taken 15 times.
✓ Branch 94 → 95 taken 15 times.
✓ Branch 94 → 96 taken 230736 times.
|
412511 | if ((cluster < FX_FAT_ENTRY_START) || (cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters)) |
| 522 | { | ||
| 523 | |||
| 524 | /* Return the bad status. */ | ||
| 525 | 121 | return(FX_FAT_READ_ERROR); | |
| 526 | } | ||
| 527 | |||
| 528 | 412390 | cluster = next_cluster; | |
| 529 | } | ||
| 530 | |||
| 531 | /* Now we can calculate the directory size. */ | ||
| 532 | 150020 | directory_size = (((ULONG64) media_ptr -> fx_media_bytes_per_sector) * | |
| 533 | 150020 | ((ULONG64) media_ptr -> fx_media_sectors_per_cluster) * i) | |
| 534 | / (ULONG64) FX_DIR_ENTRY_SIZE; | ||
| 535 | |||
| 536 | /* Also save this in the directory entry so we don't have to | ||
| 537 | calculate it later. */ | ||
| 538 | 150020 | search_dir_ptr -> fx_dir_entry_file_size = directory_size; | |
| 539 | |||
| 540 | /* If required, copy the last search directory entry into the | ||
| 541 | destination. */ | ||
| 542 |
4/4✓ Branch 94 → 95 taken 63409 times.
✓ Branch 94 → 101 taken 3013 times.
✓ Branch 98 → 99 taken 79238 times.
✓ Branch 98 → 105 taken 4360 times.
|
150020 | if (last_dir_ptr) |
| 543 | { | ||
| 544 | |||
| 545 | /* Copy the last search directory into the destination. */ | ||
| 546 | |||
| 547 | /* First, save the name pointer from the list directory pointer. */ | ||
| 548 | 142647 | destination_name_ptr = last_dir_ptr -> fx_dir_entry_name; | |
| 549 | |||
| 550 | /* Copy the entire directory entry structure. */ | ||
| 551 | 142647 | *last_dir_ptr = *search_dir_ptr; | |
| 552 | |||
| 553 | /* Restore the original name buffer pointer. */ | ||
| 554 | 142647 | last_dir_ptr -> fx_dir_entry_name = destination_name_ptr; | |
| 555 | |||
| 556 | /* Pickup pointer to name to copy. */ | ||
| 557 | 142647 | source_name_ptr = search_dir_ptr -> fx_dir_entry_name; | |
| 558 | |||
| 559 | /* Loop to copy the name into the last directory name buffer. */ | ||
| 560 |
4/4✓ Branch 100 → 96 taken 340168 times.
✓ Branch 100 → 101 taken 12 times.
✓ Branch 104 → 100 taken 434594 times.
✓ Branch 104 → 105 taken 15 times.
|
774789 | for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) |
| 561 | { | ||
| 562 | |||
| 563 | /* Copy a character. */ | ||
| 564 | 774762 | destination_name_ptr[n] = source_name_ptr[n]; | |
| 565 | |||
| 566 | /* See if we have copied the NULL termination character. */ | ||
| 567 |
4/4✓ Branch 96 → 97 taken 63409 times.
✓ Branch 96 → 99 taken 276759 times.
✓ Branch 100 → 101 taken 79238 times.
✓ Branch 100 → 103 taken 355356 times.
|
774762 | if (source_name_ptr[n] == (CHAR) FX_NULL) |
| 568 | { | ||
| 569 | |||
| 570 | /* Determine if we should break here or at the top of the loop. */ | ||
| 571 |
4/4✓ Branch 97 → 98 taken 63397 times.
✓ Branch 97 → 99 taken 12 times.
✓ Branch 101 → 102 taken 79223 times.
✓ Branch 101 → 103 taken 15 times.
|
142647 | if (n < (FX_MAX_LONG_NAME_LEN - 1)) |
| 572 | { | ||
| 573 | |||
| 574 | /* Yes, break out of the loop early. */ | ||
| 575 | 142620 | break; | |
| 576 | } | ||
| 577 | } | ||
| 578 | } | ||
| 579 | } | ||
| 580 | } | ||
| 581 | else | ||
| 582 | { | ||
| 583 | |||
| 584 | /* Directory size is the number of entries in the root directory. */ | ||
| 585 | 7679971 | directory_size = (ULONG)media_ptr -> fx_media_root_directory_entries; | |
| 586 | } | ||
| 587 | |||
| 588 | /* Loop through entries in the directory. Yes, this is a | ||
| 589 | linear search! */ | ||
| 590 | 7829991 | i = 0; | |
| 591 | 7829991 | found = FX_FALSE; | |
| 592 | |||
| 593 | |||
| 594 | do | ||
| 595 | { | ||
| 596 | |||
| 597 | /* Read an entry from the directory. */ | ||
| 598 | 74128077 | status = _fx_directory_entry_read(media_ptr, search_dir_ptr, &i, entry_ptr); | |
| 599 | |||
| 600 | 74128077 | i++; | |
| 601 | |||
| 602 | /* Check for error status. */ | ||
| 603 |
4/4✓ Branch 105 → 106 taken 43 times.
✓ Branch 105 → 107 taken 5741423 times.
✓ Branch 109 → 110 taken 67 times.
✓ Branch 109 → 111 taken 68386544 times.
|
74128077 | if (status != FX_SUCCESS) |
| 604 | { | ||
| 605 | 110 | return(status); | |
| 606 | } | ||
| 607 | |||
| 608 | /* Determine if this is the last directory entry. */ | ||
| 609 |
4/4✓ Branch 107 → 108 taken 256968 times.
✓ Branch 107 → 109 taken 5484455 times.
✓ Branch 111 → 112 taken 321128 times.
✓ Branch 111 → 113 taken 68065416 times.
|
74127967 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_DONE) |
| 610 | { | ||
| 611 | 578096 | break; | |
| 612 | } | ||
| 613 | |||
| 614 | /* Determine if the entry is a volume label entry */ | ||
| 615 |
4/4✓ Branch 109 → 110 taken 4105 times.
✓ Branch 109 → 111 taken 5480350 times.
✓ Branch 113 → 114 taken 5104 times.
✓ Branch 113 → 115 taken 68060312 times.
|
73549871 | if ((entry_ptr -> fx_dir_entry_attributes & FX_VOLUME)) |
| 616 | { | ||
| 617 | 9209 | continue; | |
| 618 | } | ||
| 619 | |||
| 620 | /* Determine if this is an empty entry. */ | ||
| 621 |
8/8✓ Branch 111 → 112 taken 11044 times.
✓ Branch 111 → 114 taken 5469306 times.
✓ Branch 112 → 113 taken 10928 times.
✓ Branch 112 → 114 taken 116 times.
✓ Branch 115 → 116 taken 13787 times.
✓ Branch 115 → 118 taken 68046525 times.
✓ Branch 116 → 117 taken 13644 times.
✓ Branch 116 → 118 taken 143 times.
|
73540662 | if (((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_FREE) && (entry_ptr -> fx_dir_entry_short_name[0] == 0)) |
| 622 | { | ||
| 623 | 24572 | continue; | |
| 624 | } | ||
| 625 | |||
| 626 | /* Compare the input name and extension with the directory | ||
| 627 | entry. */ | ||
| 628 | 73516090 | work_ptr = &name[0]; | |
| 629 | 73516090 | dir_name_ptr = &(entry_ptr -> fx_dir_entry_name[0]); | |
| 630 | |||
| 631 | /* Loop to compare names. */ | ||
| 632 | do | ||
| 633 | { | ||
| 634 | |||
| 635 | /* Pickup character of directory name. */ | ||
| 636 | 387557974 | alpha = *dir_name_ptr; | |
| 637 | |||
| 638 | /* Pickup character of name. */ | ||
| 639 | 387557974 | name_alpha = *work_ptr; | |
| 640 | |||
| 641 | /* Determine if its case needs to be changed. */ | ||
| 642 |
8/8✓ Branch 115 → 116 taken 255259 times.
✓ Branch 115 → 118 taken 17621849 times.
✓ Branch 116 → 117 taken 242915 times.
✓ Branch 116 → 118 taken 12344 times.
✓ Branch 119 → 120 taken 361865 times.
✓ Branch 119 → 122 taken 369319001 times.
✓ Branch 120 → 121 taken 346444 times.
✓ Branch 120 → 122 taken 15421 times.
|
387557974 | if ((alpha >= 'a') && (alpha <= 'z')) |
| 643 | { | ||
| 644 | |||
| 645 | /* Yes, make upper case. */ | ||
| 646 | 589359 | alpha = (CHAR)((INT)alpha - 0x20); | |
| 647 | } | ||
| 648 | |||
| 649 | /* Determine if its case needs to be changed. */ | ||
| 650 |
8/8✓ Branch 118 → 119 taken 388654 times.
✓ Branch 118 → 121 taken 17488454 times.
✓ Branch 119 → 120 taken 388576 times.
✓ Branch 119 → 121 taken 78 times.
✓ Branch 122 → 123 taken 522154 times.
✓ Branch 122 → 125 taken 369158712 times.
✓ Branch 123 → 124 taken 522056 times.
✓ Branch 123 → 125 taken 98 times.
|
387557974 | if ((name_alpha >= 'a') && (name_alpha <= 'z')) |
| 651 | { | ||
| 652 | |||
| 653 | /* Yes, make upper case. */ | ||
| 654 | 910632 | name_alpha = (CHAR)((INT)name_alpha - 0x20); | |
| 655 | } | ||
| 656 | |||
| 657 | /* Compare name with directory name. */ | ||
| 658 |
4/4✓ Branch 121 → 122 taken 5320032 times.
✓ Branch 121 → 123 taken 12557076 times.
✓ Branch 125 → 126 taken 61057959 times.
✓ Branch 125 → 127 taken 308622907 times.
|
387557974 | if (alpha != name_alpha) |
| 659 | { | ||
| 660 | |||
| 661 | /* The names don't match, get out of the loop. */ | ||
| 662 | 66377991 | break; | |
| 663 | } | ||
| 664 | |||
| 665 | /* Otherwise, increment the name pointers. */ | ||
| 666 | 321179983 | work_ptr++; | |
| 667 | 321179983 | dir_name_ptr++; | |
| 668 |
4/4✓ Branch 123 → 124 taken 12407686 times.
✓ Branch 123 → 125 taken 149390 times.
✓ Branch 127 → 128 taken 301634198 times.
✓ Branch 127 → 129 taken 6988709 times.
|
321179983 | } while (*dir_name_ptr); |
| 669 | |||
| 670 | /* Determine if the requested name has been found. If so, | ||
| 671 | return success to the caller. */ | ||
| 672 |
8/8✓ Branch 125 → 126 taken 149390 times.
✓ Branch 125 → 128 taken 5320032 times.
✓ Branch 126 → 127 taken 142319 times.
✓ Branch 126 → 128 taken 7071 times.
✓ Branch 129 → 130 taken 6988709 times.
✓ Branch 129 → 132 taken 61057959 times.
✓ Branch 130 → 131 taken 6979567 times.
✓ Branch 130 → 132 taken 9142 times.
|
73516090 | if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr)) |
| 673 | { | ||
| 674 | |||
| 675 | /* Yes, the name was located. All pertinent directory | ||
| 676 | information is in the directory entry field. */ | ||
| 677 | 7121886 | found = FX_TRUE; | |
| 678 | } | ||
| 679 | /* Determine if there is a short name to check. */ | ||
| 680 |
4/4✓ Branch 128 → 129 taken 205623 times.
✓ Branch 128 → 140 taken 5121480 times.
✓ Branch 132 → 133 taken 256005 times.
✓ Branch 132 → 144 taken 60811096 times.
|
66394204 | else if (entry_ptr -> fx_dir_entry_short_name[0] != 0) |
| 681 | { | ||
| 682 | |||
| 683 | /* Yes, check for the short part of the name. */ | ||
| 684 | |||
| 685 | /* Compare the input name and extension with the directory entry. */ | ||
| 686 | 461628 | work_ptr = &name[0]; | |
| 687 | 461628 | dir_name_ptr = &(entry_ptr -> fx_dir_entry_short_name[0]); | |
| 688 | |||
| 689 | /* Loop to compare names. */ | ||
| 690 | do | ||
| 691 | { | ||
| 692 | |||
| 693 | /* Pickup character of directory name. */ | ||
| 694 | 724665 | alpha = *dir_name_ptr; | |
| 695 | |||
| 696 | /* Pickup character of name. */ | ||
| 697 | 724665 | name_alpha = *work_ptr; | |
| 698 | |||
| 699 | /* Determine if its case needs to be changed. */ | ||
| 700 |
8/8✓ Branch 130 → 131 taken 219864 times.
✓ Branch 130 → 133 taken 95484 times.
✓ Branch 131 → 132 taken 219812 times.
✓ Branch 131 → 133 taken 52 times.
✓ Branch 134 → 135 taken 284839 times.
✓ Branch 134 → 137 taken 124478 times.
✓ Branch 135 → 136 taken 284764 times.
✓ Branch 135 → 137 taken 75 times.
|
724665 | if ((name_alpha >= 'a') && (name_alpha <= 'z')) |
| 701 | { | ||
| 702 | |||
| 703 | /* Yes, make upper case. */ | ||
| 704 | 504576 | name_alpha = (CHAR)((INT)name_alpha - 0x20); | |
| 705 | } | ||
| 706 | |||
| 707 | /* Compare name with directory name. */ | ||
| 708 |
4/4✓ Branch 133 → 134 taken 188799 times.
✓ Branch 133 → 135 taken 126549 times.
✓ Branch 137 → 138 taken 235594 times.
✓ Branch 137 → 139 taken 173723 times.
|
724665 | if (alpha != name_alpha) |
| 709 | { | ||
| 710 | |||
| 711 | /* The names don't match, get out of the loop. */ | ||
| 712 | 424393 | break; | |
| 713 | } | ||
| 714 | |||
| 715 | /* Otherwise, move the name pointers and increment the | ||
| 716 | count. */ | ||
| 717 | 300272 | work_ptr++; | |
| 718 | 300272 | dir_name_ptr++; | |
| 719 |
4/4✓ Branch 135 → 136 taken 109725 times.
✓ Branch 135 → 137 taken 16824 times.
✓ Branch 139 → 140 taken 153312 times.
✓ Branch 139 → 141 taken 20411 times.
|
300272 | } while (*dir_name_ptr); |
| 720 | |||
| 721 | /* Determine if the names match. */ | ||
| 722 |
8/8✓ Branch 137 → 138 taken 16824 times.
✓ Branch 137 → 140 taken 188799 times.
✓ Branch 138 → 139 taken 12935 times.
✓ Branch 138 → 140 taken 3889 times.
✓ Branch 141 → 142 taken 20411 times.
✓ Branch 141 → 144 taken 235594 times.
✓ Branch 142 → 143 taken 15685 times.
✓ Branch 142 → 144 taken 4726 times.
|
461628 | if ((*dir_name_ptr == 0) && (*work_ptr == *dir_name_ptr)) |
| 723 | { | ||
| 724 | |||
| 725 | /* Yes, the name was located. All pertinent directory | ||
| 726 | information is in the directory entry field. */ | ||
| 727 | 28620 | found = FX_TRUE; | |
| 728 | } | ||
| 729 | } | ||
| 730 |
8/8✓ Branch 140 → 141 taken 5438906 times.
✓ Branch 140 → 143 taken 45549 times.
✓ Branch 141 → 142 taken 5284237 times.
✓ Branch 141 → 143 taken 154669 times.
✓ Branch 144 → 145 taken 68008352 times.
✓ Branch 144 → 147 taken 57064 times.
✓ Branch 145 → 146 taken 61013849 times.
✓ Branch 145 → 147 taken 6994503 times.
|
73549871 | } while ((i < directory_size) && (!found)); |
| 731 | |||
| 732 | /* Now determine if we have a match. */ | ||
| 733 |
4/4✓ Branch 143 → 144 taken 301932 times.
✓ Branch 143 → 145 taken 155254 times.
✓ Branch 147 → 148 taken 377443 times.
✓ Branch 147 → 149 taken 6995252 times.
|
7829881 | if (!found) |
| 734 | { | ||
| 735 | |||
| 736 | /* Return a "not found" status to the caller. */ | ||
| 737 | 679375 | return(FX_NOT_FOUND); | |
| 738 | } | ||
| 739 | |||
| 740 | /* Determine if the found entry is indeed a sub-directory. */ | ||
| 741 |
4/4✓ Branch 145 → 146 taken 75208 times.
✓ Branch 145 → 152 taken 80046 times.
✓ Branch 149 → 150 taken 94434 times.
✓ Branch 149 → 156 taken 6900818 times.
|
7150506 | if (entry_ptr -> fx_dir_entry_attributes & FX_DIRECTORY) |
| 742 | { | ||
| 743 | |||
| 744 | /* Move the directory search pointer to this entry. */ | ||
| 745 | 169642 | search_dir = *entry_ptr; | |
| 746 | 169642 | search_dir_ptr = &search_dir; | |
| 747 | |||
| 748 | /* Ensure that the search directory's last search cluster is cleared. */ | ||
| 749 | 169642 | search_dir_ptr -> fx_dir_entry_last_search_cluster = 0; | |
| 750 | |||
| 751 | /* Now determine if the new search directory is the root | ||
| 752 | directory. */ | ||
| 753 |
4/4✓ Branch 146 → 147 taken 36 times.
✓ Branch 146 → 154 taken 75172 times.
✓ Branch 150 → 151 taken 101 times.
✓ Branch 150 → 158 taken 94333 times.
|
169642 | if (!search_dir_ptr -> fx_dir_entry_cluster) |
| 754 | { | ||
| 755 | |||
| 756 | /* This is a backward link to the root directory. Make | ||
| 757 | sure this is indicated in the search directory | ||
| 758 | information. */ | ||
| 759 | 137 | search_dir_ptr -> fx_dir_entry_name[0] = 0; | |
| 760 | |||
| 761 | /* Determine if we need to remember this in the last | ||
| 762 | directory searched return area. */ | ||
| 763 |
4/4✓ Branch 147 → 148 taken 4 times.
✓ Branch 147 → 151 taken 32 times.
✓ Branch 151 → 152 taken 5 times.
✓ Branch 151 → 155 taken 96 times.
|
137 | if (last_dir_ptr) |
| 764 | { | ||
| 765 | |||
| 766 | /* Yes, return this value to the caller. */ | ||
| 767 | |||
| 768 | /* First, save the name pointer from the list directory pointer. */ | ||
| 769 | 9 | destination_name_ptr = last_dir_ptr -> fx_dir_entry_name; | |
| 770 | |||
| 771 | /* Copy the entire directory entry structure. */ | ||
| 772 | 9 | *last_dir_ptr = *search_dir_ptr; | |
| 773 | |||
| 774 | /* Restore the original name buffer pointer. */ | ||
| 775 | 9 | last_dir_ptr -> fx_dir_entry_name = destination_name_ptr; | |
| 776 | |||
| 777 | /* Pickup pointer to name to copy. */ | ||
| 778 | 9 | source_name_ptr = search_dir_ptr -> fx_dir_entry_name; | |
| 779 | |||
| 780 | /* Loop to copy the name into the last directory name buffer. */ | ||
| 781 |
4/4✓ Branch 150 → 149 taken 1024 times.
✓ Branch 150 → 151 taken 4 times.
✓ Branch 154 → 153 taken 1280 times.
✓ Branch 154 → 155 taken 5 times.
|
2313 | for (n = 0; n < FX_MAX_LONG_NAME_LEN; n++) |
| 782 | { | ||
| 783 | |||
| 784 | /* Copy a character. */ | ||
| 785 | 2304 | destination_name_ptr[n] = source_name_ptr[n]; | |
| 786 | } | ||
| 787 | } | ||
| 788 | |||
| 789 | /* Set the search directory pointer to NULL to indicate | ||
| 790 | we are at the root directory. */ | ||
| 791 | 137 | search_dir_ptr = FX_NULL; | |
| 792 | } | ||
| 793 | } | ||
| 794 | else | ||
| 795 | { | ||
| 796 | |||
| 797 | /* This is not a directory, we better return not found | ||
| 798 | since we can't continue the search. */ | ||
| 799 |
4/4✓ Branch 152 → 153 taken 4 times.
✓ Branch 152 → 154 taken 80042 times.
✓ Branch 156 → 157 taken 5 times.
✓ Branch 156 → 158 taken 6900813 times.
|
6980864 | if (name_ptr) |
| 800 | { | ||
| 801 | |||
| 802 | /* Return not-found status to caller. */ | ||
| 803 | 9 | return(FX_NOT_FOUND); | |
| 804 | } | ||
| 805 | } | ||
| 806 |
4/4✓ Branch 154 → 155 taken 61408 times.
✓ Branch 154 → 156 taken 93842 times.
✓ Branch 158 → 159 taken 77244 times.
✓ Branch 158 → 160 taken 6918003 times.
|
7150497 | } while (name_ptr); |
| 807 | |||
| 808 | /* If you reach this point, the directory is found absolutely, since !found will return directly in the loop above. */ | ||
| 809 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 810 | |||
| 811 | |||
| 812 | /* At this point, cache the found information. If a subsequent search for the same name is done, | ||
| 813 | it will return immediately. */ | ||
| 814 | |||
| 815 | /* Set the index of the saved name string. */ | ||
| 816 | 7011845 | v= 0; | |
| 817 | |||
| 818 | /* First, build the full path and name. */ | ||
| 819 |
12/12✓ Branch 156 → 157 taken 93790 times.
✓ Branch 156 → 163 taken 52 times.
✓ Branch 157 → 158 taken 92557 times.
✓ Branch 157 → 163 taken 1233 times.
✓ Branch 158 → 159 taken 3193 times.
✓ Branch 158 → 163 taken 89364 times.
✓ Branch 160 → 161 taken 6917933 times.
✓ Branch 160 → 167 taken 70 times.
✓ Branch 161 → 162 taken 6916614 times.
✓ Branch 161 → 167 taken 1319 times.
✓ Branch 162 → 163 taken 4106 times.
✓ Branch 162 → 167 taken 6912508 times.
|
7011845 | if ((*original_name != '\\') && (*original_name != '/') && (path_ptr)) |
| 820 | { | ||
| 821 | |||
| 822 | /* Copy the path into the destination. */ | ||
| 823 |
8/8✓ Branch 161 → 162 taken 108453 times.
✓ Branch 161 → 163 taken 220 times.
✓ Branch 162 → 160 taken 105480 times.
✓ Branch 162 → 163 taken 2973 times.
✓ Branch 165 → 166 taken 245100 times.
✓ Branch 165 → 167 taken 579 times.
✓ Branch 166 → 164 taken 241573 times.
✓ Branch 166 → 167 taken 3527 times.
|
354352 | while ((v< (FX_MAX_LAST_NAME_LEN - 1)) && (path_ptr[v])) |
| 824 | { | ||
| 825 | |||
| 826 | /* Copy one character. */ | ||
| 827 | 347053 | media_ptr -> fx_media_last_found_name[v] = path_ptr[v]; | |
| 828 | |||
| 829 | /* Move to next character. */ | ||
| 830 | 347053 | v++; | |
| 831 | } | ||
| 832 | } | ||
| 833 | |||
| 834 | /* Now see if there is no directory path symbol in the name itself. */ | ||
| 835 |
8/8✓ Branch 163 → 164 taken 93790 times.
✓ Branch 163 → 167 taken 52 times.
✓ Branch 164 → 165 taken 92557 times.
✓ Branch 164 → 167 taken 1233 times.
✓ Branch 167 → 168 taken 6917933 times.
✓ Branch 167 → 171 taken 70 times.
✓ Branch 168 → 169 taken 6916614 times.
✓ Branch 168 → 171 taken 1319 times.
|
7011845 | if ((*original_name != '\\') && (*original_name != '/')) |
| 836 | { | ||
| 837 | |||
| 838 | /* If there is room, place a directory separator character. */ | ||
| 839 |
4/4✓ Branch 165 → 166 taken 92337 times.
✓ Branch 165 → 167 taken 220 times.
✓ Branch 169 → 170 taken 6916035 times.
✓ Branch 169 → 171 taken 579 times.
|
7009171 | if (v < (FX_MAX_LAST_NAME_LEN - 1)) |
| 840 | { | ||
| 841 | 7008372 | media_ptr -> fx_media_last_found_name[v++] = '/'; | |
| 842 | } | ||
| 843 | } | ||
| 844 | |||
| 845 | /* Now append the name to the path. */ | ||
| 846 | 7011845 | j = 0; | |
| 847 |
8/8✓ Branch 169 → 170 taken 924144 times.
✓ Branch 169 → 171 taken 401 times.
✓ Branch 170 → 168 taken 830703 times.
✓ Branch 170 → 171 taken 93441 times.
✓ Branch 173 → 174 taken 71975707 times.
✓ Branch 173 → 175 taken 855 times.
✓ Branch 174 → 172 taken 65058559 times.
✓ Branch 174 → 175 taken 6917148 times.
|
72901107 | while ((v < FX_MAX_LAST_NAME_LEN) && (original_name[j])) |
| 848 | { | ||
| 849 | |||
| 850 | /* Copy one character. */ | ||
| 851 | 65889262 | media_ptr -> fx_media_last_found_name[v] = original_name[j]; | |
| 852 | |||
| 853 | /* Move to next character. */ | ||
| 854 | 65889262 | v++; | |
| 855 | 65889262 | j++; | |
| 856 | } | ||
| 857 | |||
| 858 | /* Null terminate the last name string. */ | ||
| 859 |
4/4✓ Branch 171 → 172 taken 93441 times.
✓ Branch 171 → 173 taken 401 times.
✓ Branch 175 → 176 taken 6917148 times.
✓ Branch 175 → 177 taken 855 times.
|
7011845 | if (v< FX_MAX_LAST_NAME_LEN) |
| 860 | { | ||
| 861 | |||
| 862 | /* Null terminate. */ | ||
| 863 | 7010589 | media_ptr -> fx_media_last_found_name[v] = FX_NULL; | |
| 864 | } | ||
| 865 | else | ||
| 866 | { | ||
| 867 | |||
| 868 | /* The string is too big, NULL the string so it won't be used in searching. */ | ||
| 869 | 1256 | media_ptr -> fx_media_last_found_name[0] = FX_NULL; | |
| 870 | } | ||
| 871 | |||
| 872 | /* Determine if there is a search pointer. */ | ||
| 873 |
4/4✓ Branch 174 → 175 taken 14216 times.
✓ Branch 174 → 176 taken 79626 times.
✓ Branch 178 → 179 taken 17675 times.
✓ Branch 178 → 180 taken 6900328 times.
|
7011845 | if (search_dir_ptr) |
| 874 | { | ||
| 875 | |||
| 876 | /* Yes, there is a search directory pointer so save it! */ | ||
| 877 | 31891 | media_ptr -> fx_media_last_found_directory = *search_dir_ptr; | |
| 878 | |||
| 879 | /* Indicate the search directory is valid. */ | ||
| 880 | 31891 | media_ptr -> fx_media_last_found_directory_valid = FX_TRUE; | |
| 881 | } | ||
| 882 | else | ||
| 883 | { | ||
| 884 | |||
| 885 | /* Indicate the search directory is not valid. */ | ||
| 886 | 6979954 | media_ptr -> fx_media_last_found_directory_valid = FX_FALSE; | |
| 887 | } | ||
| 888 | |||
| 889 | /* Copy the directory entry. */ | ||
| 890 | 7011845 | media_ptr -> fx_media_last_found_entry = *entry_ptr; | |
| 891 | |||
| 892 | /* Setup the directory entry for the last found internal file name. */ | ||
| 893 | 7011845 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_name = media_ptr -> fx_media_last_found_file_name; | |
| 894 | |||
| 895 | /* Copy the actual directory name into the cached directory name. */ | ||
| 896 |
4/4✓ Branch 182 → 178 taken 904044 times.
✓ Branch 182 → 183 taken 101 times.
✓ Branch 186 → 182 taken 71955394 times.
✓ Branch 186 → 187 taken 156 times.
|
72859695 | for (index = 0; index < FX_MAX_LONG_NAME_LEN; index++) |
| 897 | { | ||
| 898 | |||
| 899 | /* Copy character into the cached directory name. */ | ||
| 900 | 72859438 | media_ptr -> fx_media_last_found_file_name[index] = entry_ptr -> fx_dir_entry_name[index]; | |
| 901 | |||
| 902 | /* See if we have copied the NULL termination character. */ | ||
| 903 |
4/4✓ Branch 178 → 179 taken 93842 times.
✓ Branch 178 → 181 taken 810202 times.
✓ Branch 182 → 183 taken 6918003 times.
✓ Branch 182 → 185 taken 65037391 times.
|
72859438 | if (entry_ptr -> fx_dir_entry_name[index] == (CHAR)FX_NULL) |
| 904 | { | ||
| 905 | |||
| 906 | /* Check to see if we use the break to get out of the loop. */ | ||
| 907 |
4/4✓ Branch 179 → 180 taken 93741 times.
✓ Branch 179 → 181 taken 101 times.
✓ Branch 183 → 184 taken 6917847 times.
✓ Branch 183 → 185 taken 156 times.
|
7011845 | if (index < (FX_MAX_LONG_NAME_LEN - 1)) |
| 908 | { | ||
| 909 | |||
| 910 | /* Yes, not at the end of the string, break. */ | ||
| 911 | 7011588 | break; | |
| 912 | } | ||
| 913 | } | ||
| 914 | } | ||
| 915 | #endif | ||
| 916 | |||
| 917 | 7011845 | return(FX_SUCCESS); | |
| 918 | } | ||
| 919 | |||
| 920 |