fx_directory_entry_write.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 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 33 | #include "fx_fault_tolerant.h" | ||
| 34 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 35 | |||
| 36 | |||
| 37 | /**************************************************************************/ | ||
| 38 | /* */ | ||
| 39 | /* FUNCTION RELEASE */ | ||
| 40 | /* */ | ||
| 41 | /* _fx_directory_entry_write PORTABLE C */ | ||
| 42 | /* 6.1.5 */ | ||
| 43 | /* AUTHOR */ | ||
| 44 | /* */ | ||
| 45 | /* William E. Lamie, Microsoft Corporation */ | ||
| 46 | /* */ | ||
| 47 | /* DESCRIPTION */ | ||
| 48 | /* */ | ||
| 49 | /* This function writes the supplied directory entry to the specified */ | ||
| 50 | /* logical sector and offset. */ | ||
| 51 | /* */ | ||
| 52 | /* INPUT */ | ||
| 53 | /* */ | ||
| 54 | /* media_ptr Media control block pointer */ | ||
| 55 | /* entry_ptr Pointer to directory entry */ | ||
| 56 | /* */ | ||
| 57 | /* OUTPUT */ | ||
| 58 | /* */ | ||
| 59 | /* return status */ | ||
| 60 | /* */ | ||
| 61 | /* CALLS */ | ||
| 62 | /* */ | ||
| 63 | /* _fx_utility_FAT_entry_read Read a new FAT entry */ | ||
| 64 | /* _fx_utility_logical_sector_read Read directory sector */ | ||
| 65 | /* _fx_utility_logical_sector_write Write directory sector */ | ||
| 66 | /* _fx_utility_16_unsigned_write Write a UINT from memory */ | ||
| 67 | /* _fx_utility_32_unsigned_write Write a ULONG from memory */ | ||
| 68 | /* _fx_fault_tolerant_add_dir_log Add directory redo log */ | ||
| 69 | /* */ | ||
| 70 | /* CALLED BY */ | ||
| 71 | /* */ | ||
| 72 | /* FileX System Functions */ | ||
| 73 | /* */ | ||
| 74 | /**************************************************************************/ | ||
| 75 | 170573693 | UINT _fx_directory_entry_write(FX_MEDIA *media_ptr, FX_DIR_ENTRY *entry_ptr) | |
| 76 | { | ||
| 77 | |||
| 78 | UCHAR *work_ptr, *sector_base_ptr; | ||
| 79 | UINT status, temp, entry, delete_flag; | ||
| 80 | UINT i, j, k, l, card, len, dotfound, dotpos, match; | ||
| 81 | UCHAR checksum, eof_marker; | ||
| 82 | CHAR alpha; | ||
| 83 | CHAR shortname[FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE + 1]; | ||
| 84 | ULONG logical_sector, relative_sector; | ||
| 85 | ULONG byte_offset; | ||
| 86 | ULONG cluster, next_cluster; | ||
| 87 | |||
| 88 | |||
| 89 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 90 | UCHAR *changed_ptr; | ||
| 91 | UINT changed_size; | ||
| 92 | ULONG changed_offset; | ||
| 93 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 94 | |||
| 95 | |||
| 96 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 97 | |||
| 98 | /* Increment the number of directory entry write requests. */ | ||
| 99 | 170573693 | media_ptr -> fx_media_directory_entry_writes++; | |
| 100 | #endif | ||
| 101 | |||
| 102 | /* Extended port-specific processing macro, which is by default defined to white space. */ | ||
| 103 |
4/4✓ Branch 2 → 3 taken 72 times.
✓ Branch 2 → 5 taken 170573621 times.
✓ Branch 3 → 4 taken 45 times.
✓ Branch 3 → 5 taken 27 times.
|
170573693 | FX_DIRECTORY_ENTRY_WRITE_EXTENSION |
| 104 | |||
| 105 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 106 | FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_DIR_ENTRY_WRITE, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) | ||
| 107 | |||
| 108 | /* Determine if this is entry is being deleted. */ | ||
| 109 |
2/2✓ Branch 5 → 6 taken 35651 times.
✓ Branch 5 → 8 taken 170537997 times.
|
170573648 | if (((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_FREE) && |
| 110 |
2/2✓ Branch 6 → 7 taken 5499 times.
✓ Branch 6 → 8 taken 30152 times.
|
35651 | ((UCHAR)entry_ptr -> fx_dir_entry_short_name[0] == (UCHAR)FX_DIR_ENTRY_FREE)) |
| 111 | { | ||
| 112 | |||
| 113 | /* Yes, this is a request to delete the entry. Set the flag to remember this. */ | ||
| 114 | 5499 | delete_flag = FX_TRUE; | |
| 115 | |||
| 116 | /* Null the short file name. */ | ||
| 117 | 5499 | entry_ptr -> fx_dir_entry_short_name[0] = 0; | |
| 118 | } | ||
| 119 | else | ||
| 120 | { | ||
| 121 | |||
| 122 | /* Not a deleted entry. Set the flag to false. */ | ||
| 123 | 170568149 | delete_flag = FX_FALSE; | |
| 124 | } | ||
| 125 | |||
| 126 | /* Pickup the byte offset of the entry. */ | ||
| 127 | 170573648 | byte_offset = entry_ptr -> fx_dir_entry_byte_offset; | |
| 128 | |||
| 129 | /* Pickup the logical sector of the entry. */ | ||
| 130 | 170573648 | logical_sector = (ULONG)entry_ptr -> fx_dir_entry_log_sector; | |
| 131 | |||
| 132 | /* Figure out where what cluster we are in. */ | ||
| 133 |
2/2✓ Branch 9 → 10 taken 158184340 times.
✓ Branch 9 → 11 taken 12389308 times.
|
170573648 | if (logical_sector >= (ULONG)(media_ptr -> fx_media_data_sector_start)) |
| 134 | { | ||
| 135 | |||
| 136 | /* Calculate the cluster that this logical sector is in. */ | ||
| 137 | 158184340 | cluster = (logical_sector - media_ptr -> fx_media_data_sector_start) / (media_ptr -> fx_media_sectors_per_cluster) + FX_FAT_ENTRY_START; | |
| 138 | |||
| 139 | /* Calculate the relative cluster. */ | ||
| 140 | 158184340 | relative_sector = logical_sector - (((ULONG)media_ptr -> fx_media_data_sector_start) + | |
| 141 | 158184340 | (((ULONG)cluster - FX_FAT_ENTRY_START) * | |
| 142 | 158184340 | ((ULONG)media_ptr -> fx_media_sectors_per_cluster))); | |
| 143 | } | ||
| 144 | else | ||
| 145 | { | ||
| 146 | |||
| 147 | /* Clear the cluster and the relative sector. */ | ||
| 148 | 12389308 | cluster = 0; | |
| 149 | 12389308 | relative_sector = 0; | |
| 150 | } | ||
| 151 | |||
| 152 | /* Read the logical directory sector. */ | ||
| 153 | 170573648 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) entry_ptr -> fx_dir_entry_log_sector, | |
| 154 | 170573648 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_DIRECTORY_SECTOR); | |
| 155 | |||
| 156 | /* Determine if an error occurred. */ | ||
| 157 |
2/2✓ Branch 13 → 14 taken 21730 times.
✓ Branch 13 → 15 taken 170551918 times.
|
170573648 | if (status != FX_SUCCESS) |
| 158 | { | ||
| 159 | |||
| 160 | /* Return the error status. */ | ||
| 161 | 21730 | return(status); | |
| 162 | } | ||
| 163 | |||
| 164 | /* Setup a pointer into the buffer. */ | ||
| 165 | 170551918 | sector_base_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer; | |
| 166 | 170551918 | work_ptr = sector_base_ptr + (UINT)entry_ptr -> fx_dir_entry_byte_offset; | |
| 167 | |||
| 168 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 169 | /* Initialize data for fault tolerant. */ | ||
| 170 | 169814188 | changed_ptr = work_ptr; | |
| 171 | 169814188 | changed_size = 0; | |
| 172 | 169814188 | changed_offset = entry_ptr -> fx_dir_entry_byte_offset; | |
| 173 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 174 | |||
| 175 | /* Determine if a long file name is present. */ | ||
| 176 |
3/3✓ Branch 15 → 16 taken 12280 times.
✓ Branch 15 → 175 taken 732004 times.
✓ Branch 15 → 177 taken 169807634 times.
|
170551918 | if (entry_ptr -> fx_dir_entry_long_name_present) |
| 177 | { | ||
| 178 | |||
| 179 | /* Yes, long name is present - prepare short name and write out this name. */ | ||
| 180 |
2/2✓ Branch 25 → 17 taken 250001 times.
✓ Branch 25 → 26 taken 12280 times.
|
262281 | for (len = 0, i = 0, dotpos = 0, dotfound = 0; entry_ptr -> fx_dir_entry_name[len]; len++) |
| 181 | { | ||
| 182 | |||
| 183 | /* Check for a dot. */ | ||
| 184 |
2/2✓ Branch 17 → 18 taken 1039 times.
✓ Branch 17 → 21 taken 248962 times.
|
250001 | if (entry_ptr -> fx_dir_entry_name[len] == '.') |
| 185 | { | ||
| 186 | |||
| 187 | /* Check for leading dot. */ | ||
| 188 |
2/2✓ Branch 18 → 19 taken 54 times.
✓ Branch 18 → 20 taken 985 times.
|
1039 | if (len == 0) |
| 189 | { | ||
| 190 | /* Yes, this is a leading dot. */ | ||
| 191 | 54 | continue; | |
| 192 | } | ||
| 193 | |||
| 194 | /* Yes, a dot is present. From this position the extension will | ||
| 195 | be written. */ | ||
| 196 | 985 | dotfound = i; | |
| 197 | 985 | dotpos = len + 1; | |
| 198 | 985 | continue; | |
| 199 | } | ||
| 200 | |||
| 201 | /* Check for non-space and within the short file name length. */ | ||
| 202 |
4/4✓ Branch 21 → 22 taken 248737 times.
✓ Branch 21 → 24 taken 225 times.
✓ Branch 22 → 23 taken 70790 times.
✓ Branch 22 → 24 taken 177947 times.
|
248962 | if ((entry_ptr -> fx_dir_entry_name[len] != ' ') && (i < 8)) |
| 203 | { | ||
| 204 | |||
| 205 | /* Copy characters into the short file name area. */ | ||
| 206 | 70790 | shortname[i] = entry_ptr -> fx_dir_entry_name[len]; | |
| 207 | 70790 | i++; | |
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | /* Fill remaining short file name with spaces. */ | ||
| 212 |
2/2✓ Branch 28 → 27 taken 64290 times.
✓ Branch 28 → 29 taken 12280 times.
|
76570 | for (j = i; j < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; j++) |
| 213 | { | ||
| 214 | 64290 | shortname[j] = ' '; | |
| 215 | } | ||
| 216 | |||
| 217 | /* Determine if a dot was encountered. */ | ||
| 218 |
2/2✓ Branch 29 → 30 taken 805 times.
✓ Branch 29 → 39 taken 11475 times.
|
12280 | if (dotpos) |
| 219 | { | ||
| 220 | |||
| 221 | /* Process relative to the dot position. */ | ||
| 222 |
2/2✓ Branch 30 → 31 taken 688 times.
✓ Branch 30 → 32 taken 117 times.
|
805 | if (entry_ptr -> fx_dir_entry_name[dotpos]) |
| 223 | { | ||
| 224 | 688 | shortname[8] = entry_ptr -> fx_dir_entry_name[dotpos++]; | |
| 225 | } | ||
| 226 |
2/2✓ Branch 32 → 33 taken 645 times.
✓ Branch 32 → 34 taken 160 times.
|
805 | if (entry_ptr -> fx_dir_entry_name[dotpos]) |
| 227 | { | ||
| 228 | 645 | shortname[9] = entry_ptr -> fx_dir_entry_name[dotpos++]; | |
| 229 | } | ||
| 230 |
2/2✓ Branch 34 → 35 taken 614 times.
✓ Branch 34 → 36 taken 191 times.
|
805 | if (entry_ptr -> fx_dir_entry_name[dotpos]) |
| 231 | { | ||
| 232 | 614 | shortname[10] = entry_ptr -> fx_dir_entry_name[dotpos++]; | |
| 233 | } | ||
| 234 | |||
| 235 | /* Determine if additional spaces are needed. */ | ||
| 236 | 805 | i = dotfound; | |
| 237 | |||
| 238 |
2/2✓ Branch 38 → 37 taken 2601 times.
✓ Branch 38 → 39 taken 805 times.
|
3406 | for (; dotfound <= 7; dotfound++) |
| 239 | { | ||
| 240 | /* Add space... */ | ||
| 241 | 2601 | shortname[dotfound] = ' '; | |
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | /* Each entry contains 13 unicode entries. Calculate the remainder. */ | ||
| 246 |
2/2✓ Branch 39 → 40 taken 274 times.
✓ Branch 39 → 41 taken 12006 times.
|
12280 | if (len % 13 == 0) |
| 247 | { | ||
| 248 | 274 | card = len / 13; | |
| 249 | } | ||
| 250 | else | ||
| 251 | { | ||
| 252 | 12006 | card = len / 13 + 1; | |
| 253 | } | ||
| 254 | |||
| 255 | /* Default the name match to true. */ | ||
| 256 | 12280 | match = FX_TRUE; | |
| 257 | |||
| 258 | /* Loop through the newly derived short name and the original name and look | ||
| 259 | for a non-matching character. */ | ||
| 260 | 12280 | l = 0; | |
| 261 | 12280 | k = 0; | |
| 262 |
2/2✓ Branch 56 → 43 taken 82716 times.
✓ Branch 56 → 57 taken 451 times.
|
83167 | while (k < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE) |
| 263 | { | ||
| 264 | |||
| 265 | /* Determine if a space is detected in the short name. If so, | ||
| 266 | advance to the extension index. */ | ||
| 267 |
2/2✓ Branch 43 → 44 taken 12197 times.
✓ Branch 43 → 49 taken 70519 times.
|
82716 | if (shortname[k] == ' ') |
| 268 | { | ||
| 269 | |||
| 270 | /* The first pad space was detected. First, check for a name | ||
| 271 | without an extension. */ | ||
| 272 |
2/2✓ Branch 44 → 45 taken 5813 times.
✓ Branch 44 → 46 taken 6384 times.
|
12197 | if (entry_ptr -> fx_dir_entry_name[l] == FX_NULL) |
| 273 | { | ||
| 274 | |||
| 275 | /* All is okay, get out of the loop! */ | ||
| 276 | 5813 | break; | |
| 277 | } | ||
| 278 | |||
| 279 | /* Now check for a period in the long name... if not, there is a non-match! */ | ||
| 280 |
2/2✓ Branch 46 → 47 taken 5813 times.
✓ Branch 46 → 48 taken 571 times.
|
6384 | if (entry_ptr -> fx_dir_entry_name[l] != '.') |
| 281 | { | ||
| 282 | |||
| 283 | /* Set the match flag to false and exit the loop. */ | ||
| 284 | 5813 | match = FX_FALSE; | |
| 285 | 5813 | break; | |
| 286 | } | ||
| 287 | |||
| 288 | /* Otherwise move short file name index to the extension area and | ||
| 289 | increment the long file name index. */ | ||
| 290 | 571 | k = 8; | |
| 291 | 571 | l++; | |
| 292 | |||
| 293 | /* Restart the loop at the top. */ | ||
| 294 | 571 | continue; | |
| 295 | } | ||
| 296 | |||
| 297 | /* Check for the dot for the 8.3 match... it is no longer in the | ||
| 298 | shortname but possibly still present in the long name. */ | ||
| 299 |
4/4✓ Branch 49 → 50 taken 625 times.
✓ Branch 49 → 52 taken 69894 times.
✓ Branch 50 → 51 taken 94 times.
✓ Branch 50 → 52 taken 531 times.
|
70519 | if ((k == 8) && (entry_ptr -> fx_dir_entry_name[l] == '.')) |
| 300 | { | ||
| 301 | |||
| 302 | /* Yes, handle the implicit dot in the shortname by | ||
| 303 | positioning past it in the long name. */ | ||
| 304 | 94 | l++; | |
| 305 | } | ||
| 306 | |||
| 307 | /* Do the names match? */ | ||
| 308 |
2/2✓ Branch 52 → 53 taken 203 times.
✓ Branch 52 → 54 taken 70316 times.
|
70519 | if (shortname[k] != entry_ptr -> fx_dir_entry_name[l]) |
| 309 | { | ||
| 310 | |||
| 311 | /* No, the names do not match, set the match flag to false and | ||
| 312 | exit the loop. */ | ||
| 313 | 203 | match = FX_FALSE; | |
| 314 | 203 | break; | |
| 315 | } | ||
| 316 | |||
| 317 | /* Move the indices forward. */ | ||
| 318 | 70316 | k++; | |
| 319 | 70316 | l++; | |
| 320 | } | ||
| 321 | |||
| 322 | /* Check if there is a dot in the name, but no extension in the short name. In this case, | ||
| 323 | we should create a mangled short name. */ | ||
| 324 |
4/4✓ Branch 57 → 58 taken 805 times.
✓ Branch 57 → 60 taken 11475 times.
✓ Branch 58 → 59 taken 153 times.
✓ Branch 58 → 60 taken 652 times.
|
12280 | if ((dotpos) && (shortname[8] == ' ')) |
| 325 | { | ||
| 326 | |||
| 327 | /* Something left.. the names do not match! */ | ||
| 328 | 153 | match = FX_FALSE; | |
| 329 | } | ||
| 330 | |||
| 331 | /* One final check to make sure there is nothing left on the long file name. */ | ||
| 332 |
2/2✓ Branch 60 → 61 taken 6025 times.
✓ Branch 60 → 62 taken 6255 times.
|
12280 | if (entry_ptr -> fx_dir_entry_name[l]) |
| 333 | { | ||
| 334 | |||
| 335 | /* Something left.. the names do not match! */ | ||
| 336 | 6025 | match = FX_FALSE; | |
| 337 | } | ||
| 338 | |||
| 339 | /* Determine if the derived short name matches exactly the long file name. If so | ||
| 340 | we don't need to mangle the name with a numeric value based on its entry. */ | ||
| 341 |
2/2✓ Branch 62 → 63 taken 6124 times.
✓ Branch 62 → 78 taken 6156 times.
|
12280 | if (match == FX_FALSE) |
| 342 | { | ||
| 343 | |||
| 344 | /* Name does not match, create a mangled name. */ | ||
| 345 | |||
| 346 | /* Generate short file name from LFN. */ | ||
| 347 | 6124 | entry = entry_ptr -> fx_dir_entry_number; | |
| 348 | |||
| 349 | /* Name suffice is between 000 and FFFF in hex, calculate this short file | ||
| 350 | name's numeric component. */ | ||
| 351 | 6124 | entry = entry % 0x10000; | |
| 352 | |||
| 353 | /* Build short name of the format xxx~NNNN.ext. */ | ||
| 354 |
2/2✓ Branch 63 → 64 taken 6061 times.
✓ Branch 63 → 65 taken 63 times.
|
6124 | if (i > 3) |
| 355 | { | ||
| 356 | 6061 | i = 3; | |
| 357 | } | ||
| 358 | 6124 | shortname[i++] = '~'; | |
| 359 | |||
| 360 | /* Loop to build the numeric part of the name. */ | ||
| 361 |
2/2✓ Branch 77 → 66 taken 24496 times.
✓ Branch 77 → 78 taken 6124 times.
|
30620 | for (l = 0; l < 4; l++) |
| 362 | { | ||
| 363 | |||
| 364 | /* Shift down the entry number based on the numeric position. */ | ||
| 365 |
2/2✓ Branch 66 → 67 taken 6124 times.
✓ Branch 66 → 68 taken 18372 times.
|
24496 | if (l == 0) |
| 366 | { | ||
| 367 | 6124 | temp = ((entry >> 12) & 0xf); | |
| 368 | } | ||
| 369 |
2/2✓ Branch 68 → 69 taken 6124 times.
✓ Branch 68 → 70 taken 12248 times.
|
18372 | else if (l == 1) |
| 370 | { | ||
| 371 | 6124 | temp = ((entry >> 8) & 0xf); | |
| 372 | } | ||
| 373 |
2/2✓ Branch 70 → 71 taken 6124 times.
✓ Branch 70 → 72 taken 6124 times.
|
12248 | else if (l == 2) |
| 374 | { | ||
| 375 | 6124 | temp = ((entry >> 4) & 0xf); | |
| 376 | } | ||
| 377 | else | ||
| 378 | { | ||
| 379 | 6124 | temp = ((entry) & 0xf); | |
| 380 | } | ||
| 381 | |||
| 382 | /* Now build hex value. */ | ||
| 383 |
2/2✓ Branch 73 → 74 taken 1711 times.
✓ Branch 73 → 75 taken 22785 times.
|
24496 | if (temp > 9) |
| 384 | 1711 | shortname[i++] = (CHAR)('A' + (temp - 10)); | |
| 385 | else | ||
| 386 | 22785 | shortname[i++] = (CHAR)('0' + temp); | |
| 387 | } | ||
| 388 | } | ||
| 389 | |||
| 390 | /* Set end of short string to NULL. */ | ||
| 391 | 12280 | shortname[11] = 0; | |
| 392 | |||
| 393 | /* Determine if the first character of the short file name is the directory free | ||
| 394 | value. If so, it must be changed. */ | ||
| 395 |
4/4✓ Branch 78 → 79 taken 1468 times.
✓ Branch 78 → 81 taken 10812 times.
✓ Branch 79 → 80 taken 103 times.
✓ Branch 79 → 81 taken 1365 times.
|
12280 | if (((UCHAR)shortname[0] == (UCHAR)FX_DIR_ENTRY_FREE) && (delete_flag == FX_FALSE)) |
| 396 | { | ||
| 397 | |||
| 398 | /* Change to 0x8F to be compatible with what DOS does. */ | ||
| 399 | 103 | shortname[0] = (CHAR)0x8F; | |
| 400 | } | ||
| 401 | |||
| 402 | /* Loop to convert the new short file name to upper case. */ | ||
| 403 |
2/2✓ Branch 86 → 82 taken 135080 times.
✓ Branch 86 → 87 taken 12280 times.
|
147360 | for (i = 0; i < (FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE); i++) |
| 404 | { | ||
| 405 | |||
| 406 | /* Pickup shortname character. */ | ||
| 407 | 135080 | alpha = shortname[i]; | |
| 408 | |||
| 409 | /* Determine if character is lower case. */ | ||
| 410 |
4/4✓ Branch 82 → 83 taken 27929 times.
✓ Branch 82 → 85 taken 107151 times.
✓ Branch 83 → 84 taken 21805 times.
✓ Branch 83 → 85 taken 6124 times.
|
135080 | if ((alpha >= 'a') && (alpha <= 'z')) |
| 411 | { | ||
| 412 | |||
| 413 | /* Store the character - converted to upper case. */ | ||
| 414 | 21805 | alpha = (CHAR)(alpha - ((CHAR)0x20)); | |
| 415 | } | ||
| 416 | |||
| 417 | /* Now store the short name character. */ | ||
| 418 | 135080 | shortname[i] = alpha; | |
| 419 | } | ||
| 420 | |||
| 421 | /* Determine if there already is a short name and we are not deleting the entry. */ | ||
| 422 |
2/2✓ Branch 87 → 88 taken 809 times.
✓ Branch 87 → 112 taken 11471 times.
|
12280 | if (entry_ptr -> fx_dir_entry_short_name[0] != 0) |
| 423 | { | ||
| 424 | |||
| 425 | /* Yes, override the calculated shortname with the original 8.3 name. */ | ||
| 426 | |||
| 427 | /* Clear the short file name area. */ | ||
| 428 |
2/2✓ Branch 90 → 89 taken 8899 times.
✓ Branch 90 → 91 taken 809 times.
|
9708 | for (i = 0; i < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++) |
| 429 | { | ||
| 430 | 8899 | shortname[i] = ' '; | |
| 431 | } | ||
| 432 | |||
| 433 | /* Loop to copy the original short file name. */ | ||
| 434 |
2/2✓ Branch 97 → 92 taken 5622 times.
✓ Branch 97 → 98 taken 559 times.
|
6181 | for (i = 0, j = 0; j < FX_DIR_NAME_SIZE; i++, j++) |
| 435 | { | ||
| 436 | |||
| 437 | /* Check for end of copy conditions. */ | ||
| 438 |
2/2✓ Branch 92 → 93 taken 56 times.
✓ Branch 92 → 94 taken 5566 times.
|
5622 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == '.') |
| 439 | { | ||
| 440 | 56 | break; | |
| 441 | } | ||
| 442 |
2/2✓ Branch 94 → 95 taken 194 times.
✓ Branch 94 → 96 taken 5372 times.
|
5566 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == 0) |
| 443 | { | ||
| 444 | 194 | break; | |
| 445 | } | ||
| 446 | |||
| 447 | /* Pickup the character. */ | ||
| 448 | 5372 | alpha = entry_ptr -> fx_dir_entry_short_name[i]; | |
| 449 | |||
| 450 | /* Copy file name character. */ | ||
| 451 | 5372 | shortname[j] = alpha; | |
| 452 | } | ||
| 453 | |||
| 454 | /* Determine if there is anything left in the short file name. */ | ||
| 455 |
2/2✓ Branch 98 → 99 taken 82 times.
✓ Branch 98 → 104 taken 727 times.
|
809 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] != 0) |
| 456 | { | ||
| 457 | |||
| 458 | /* Pickup remaining characters. */ | ||
| 459 |
2/2✓ Branch 103 → 100 taken 238 times.
✓ Branch 103 → 104 taken 61 times.
|
299 | for (i++, j = FX_DIR_NAME_SIZE; j < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++, j++) |
| 460 | { | ||
| 461 | |||
| 462 | /* If NULL is encountered, stop the copying. */ | ||
| 463 |
2/2✓ Branch 100 → 101 taken 21 times.
✓ Branch 100 → 102 taken 217 times.
|
238 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == 0) |
| 464 | { | ||
| 465 | 21 | break; | |
| 466 | } | ||
| 467 | |||
| 468 | /* Pickup the character. */ | ||
| 469 | 217 | alpha = entry_ptr -> fx_dir_entry_short_name[i]; | |
| 470 | |||
| 471 | /* Copy file name character. */ | ||
| 472 | 217 | shortname[j] = alpha; | |
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | /* Loop to make sure the short name is upper case. */ | ||
| 477 |
2/2✓ Branch 109 → 105 taken 8899 times.
✓ Branch 109 → 110 taken 809 times.
|
9708 | for (j = 0; j < (FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE); j++) |
| 478 | { | ||
| 479 | |||
| 480 | /* Pickup the character. */ | ||
| 481 | 8899 | alpha = shortname[j]; | |
| 482 | |||
| 483 | /* Determine if character is lower case. */ | ||
| 484 |
4/4✓ Branch 105 → 106 taken 525 times.
✓ Branch 105 → 108 taken 8374 times.
✓ Branch 106 → 107 taken 13 times.
✓ Branch 106 → 108 taken 512 times.
|
8899 | if ((alpha >= 'a') && (alpha <= 'z')) |
| 485 | { | ||
| 486 | |||
| 487 | /* Store the character - converted to upper case. */ | ||
| 488 | 13 | alpha = (CHAR)(alpha - ((CHAR)0x20)); | |
| 489 | } | ||
| 490 | |||
| 491 | /* Copy file name character. */ | ||
| 492 | 8899 | shortname[j] = alpha; | |
| 493 | } | ||
| 494 | |||
| 495 | /* Determine if the first character of the short file name is the directory free | ||
| 496 | value. If so, it must be changed. */ | ||
| 497 |
2/2✓ Branch 110 → 111 taken 9 times.
✓ Branch 110 → 112 taken 800 times.
|
809 | if (((UCHAR)shortname[0]) == ((UCHAR)FX_DIR_ENTRY_FREE)) |
| 498 | { | ||
| 499 | |||
| 500 | /* Change to 0x8F to be compatible with what DOS does. */ | ||
| 501 | 9 | shortname[0] = (CHAR)0x8F; | |
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 505 | /* Loop to calculate the checksum. */ | ||
| 506 |
2/2✓ Branch 114 → 113 taken 135080 times.
✓ Branch 114 → 115 taken 12280 times.
|
147360 | for (i = checksum = 0; i < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++) |
| 507 | { | ||
| 508 | |||
| 509 | /* Calculate the checksum. */ | ||
| 510 | 135080 | checksum = (UCHAR)((UCHAR)(((checksum & 1) << 7) | ((checksum & (UCHAR)0xfe) >> 1)) + shortname[i]); | |
| 511 | } | ||
| 512 | |||
| 513 | /* Set the last entry mark. */ | ||
| 514 | 12280 | work_ptr[0] = (UCHAR)(0x40 | card); | |
| 515 | |||
| 516 | /* Loop to process remainder of long file name entry. */ | ||
| 517 |
4/4✓ Branch 153 → 116 taken 11554 times.
✓ Branch 153 → 154 taken 5696 times.
✓ Branch 155 → 116 taken 14826 times.
✓ Branch 155 → 156 taken 6530 times.
|
38606 | while (card > 0) |
| 518 | { | ||
| 519 | |||
| 520 | /* Clear eof marker. */ | ||
| 521 | 26380 | eof_marker = 0; | |
| 522 | |||
| 523 | /* Determine if the entry is free. */ | ||
| 524 |
2/2✓ Branch 116 → 117 taken 3126 times.
✓ Branch 116 → 118 taken 23254 times.
|
26380 | if ((UCHAR)shortname[0] == (UCHAR)FX_DIR_ENTRY_FREE) |
| 525 | { | ||
| 526 | /* Yes, place delete marker. */ | ||
| 527 | 3126 | work_ptr[0] = (UCHAR)FX_DIR_ENTRY_FREE; | |
| 528 | } | ||
| 529 | |||
| 530 | /* Setup various long file name fields. */ | ||
| 531 | 26380 | work_ptr[11] = FX_LONG_NAME; | |
| 532 | 26380 | work_ptr[12] = 0; | |
| 533 | 26380 | work_ptr[13] = checksum; | |
| 534 | 26380 | work_ptr[26] = 0; | |
| 535 | 26380 | work_ptr[27] = 0; | |
| 536 | |||
| 537 | /* Loop through file name fields. */ | ||
| 538 |
2/2✓ Branch 131 → 119 taken 422080 times.
✓ Branch 131 → 132 taken 26380 times.
|
448460 | for (i = 1, j = 13 * (card - 1); i < FX_DIR_ENTRY_SIZE; i += 2) |
| 539 | { | ||
| 540 | |||
| 541 | /* Process relative to specific fields. */ | ||
| 542 |
4/4✓ Branch 119 → 120 taken 395700 times.
✓ Branch 119 → 121 taken 26380 times.
✓ Branch 120 → 121 taken 26380 times.
✓ Branch 120 → 122 taken 369320 times.
|
422080 | if ((i == 11) || (i == 26)) |
| 543 | { | ||
| 544 | 52760 | continue; | |
| 545 | } | ||
| 546 | |||
| 547 |
2/2✓ Branch 122 → 123 taken 26380 times.
✓ Branch 122 → 124 taken 342940 times.
|
369320 | if (i == 13) |
| 548 | { | ||
| 549 | 26380 | i = 12; | |
| 550 | 26380 | continue; | |
| 551 | } | ||
| 552 | |||
| 553 | /* Determine if the EOF marker is present. */ | ||
| 554 |
2/2✓ Branch 124 → 125 taken 92867 times.
✓ Branch 124 → 126 taken 250073 times.
|
342940 | if (eof_marker) |
| 555 | { | ||
| 556 | |||
| 557 | 92867 | work_ptr[i] = eof_marker; | |
| 558 | 92867 | work_ptr[i + 1] = eof_marker; | |
| 559 | } | ||
| 560 | else | ||
| 561 | { | ||
| 562 | 250073 | work_ptr[i] = (UCHAR)entry_ptr -> fx_dir_entry_name[j]; | |
| 563 | 250073 | work_ptr[i + 1] = 0; | |
| 564 | } | ||
| 565 | |||
| 566 |
2/2✓ Branch 127 → 128 taken 98492 times.
✓ Branch 127 → 129 taken 244448 times.
|
342940 | if (entry_ptr -> fx_dir_entry_name[j] == 0) |
| 567 | { | ||
| 568 | |||
| 569 | /* end of name, pad with 0xff. */ | ||
| 570 | 98492 | eof_marker = (UCHAR)0xff; | |
| 571 | } | ||
| 572 | |||
| 573 | 342940 | j++; | |
| 574 | } | ||
| 575 | |||
| 576 | /* Move to the next directory entry. */ | ||
| 577 | 26380 | work_ptr += FX_DIR_ENTRY_SIZE; | |
| 578 | 26380 | byte_offset += FX_DIR_ENTRY_SIZE; | |
| 579 | |||
| 580 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 581 | /* Update changed_size. */ | ||
| 582 | 14826 | changed_size += FX_DIR_ENTRY_SIZE; | |
| 583 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 584 | |||
| 585 | /* Determine if the entry overlaps into the next sector. */ | ||
| 586 |
3/3✓ Branch 132 → 133 taken 4952 times.
✓ Branch 132 → 152 taken 8986 times.
✓ Branch 132 → 154 taken 12442 times.
|
26380 | if (byte_offset >= media_ptr -> fx_media_bytes_per_sector) |
| 587 | { | ||
| 588 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 589 |
2/2✓ Branch 133 → 134 taken 330 times.
✓ Branch 133 → 135 taken 2054 times.
|
2384 | if (media_ptr -> fx_media_fault_tolerant_enabled) |
| 590 | { | ||
| 591 | |||
| 592 | /* Redirect this request to log file. */ | ||
| 593 | 330 | status = _fx_fault_tolerant_add_dir_log(media_ptr, logical_sector, changed_offset, changed_ptr, changed_size); | |
| 594 | } | ||
| 595 | else | ||
| 596 | { | ||
| 597 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 598 | |||
| 599 | /* Write current logical sector out. */ | ||
| 600 | 4622 | status = _fx_utility_logical_sector_write(media_ptr, (ULONG64) logical_sector, | |
| 601 | sector_base_ptr, ((ULONG) 1), FX_DIRECTORY_SECTOR); | ||
| 602 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 603 | } | ||
| 604 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 605 | |||
| 606 | /* Determine if an error occurred. */ | ||
| 607 |
4/4✓ Branch 134 → 135 taken 5 times.
✓ Branch 134 → 136 taken 2563 times.
✓ Branch 136 → 137 taken 4 times.
✓ Branch 136 → 138 taken 2380 times.
|
4952 | if (status != FX_SUCCESS) |
| 608 | { | ||
| 609 | |||
| 610 | /* Return the error status. */ | ||
| 611 | 9 | return(status); | |
| 612 | } | ||
| 613 | |||
| 614 | /* Determine if we are in the root directory. */ | ||
| 615 |
4/4✓ Branch 136 → 137 taken 1822 times.
✓ Branch 136 → 146 taken 741 times.
✓ Branch 138 → 139 taken 1766 times.
✓ Branch 138 → 148 taken 614 times.
|
4943 | if (logical_sector >= (ULONG)(media_ptr -> fx_media_data_sector_start)) |
| 616 | { | ||
| 617 | |||
| 618 | /* Determine the next sector of the directory entry. */ | ||
| 619 |
4/4✓ Branch 137 → 138 taken 223 times.
✓ Branch 137 → 139 taken 1599 times.
✓ Branch 139 → 140 taken 472 times.
✓ Branch 139 → 141 taken 1294 times.
|
3588 | if (relative_sector < (media_ptr -> fx_media_sectors_per_cluster - 1)) |
| 620 | { | ||
| 621 | |||
| 622 | /* More sectors in this cluster. */ | ||
| 623 | |||
| 624 | /* Simply increment the logical sector. */ | ||
| 625 | 695 | logical_sector++; | |
| 626 | |||
| 627 | /* Increment the relative sector. */ | ||
| 628 | 695 | relative_sector++; | |
| 629 | } | ||
| 630 | else | ||
| 631 | { | ||
| 632 | |||
| 633 | /* We need to move to the next cluster. */ | ||
| 634 | |||
| 635 | /* Pickup the next cluster. */ | ||
| 636 | 2893 | status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster); | |
| 637 | |||
| 638 | /* Check for I/O error. */ | ||
| 639 |
4/4✓ Branch 140 → 141 taken 5 times.
✓ Branch 140 → 142 taken 1594 times.
✓ Branch 142 → 143 taken 4 times.
✓ Branch 142 → 144 taken 1290 times.
|
2893 | if (status != FX_SUCCESS) |
| 640 | { | ||
| 641 | |||
| 642 | /* Return error code. */ | ||
| 643 | 9 | return(status); | |
| 644 | } | ||
| 645 | |||
| 646 | /* Copy next cluster to the current cluster. */ | ||
| 647 | 2884 | cluster = next_cluster; | |
| 648 | |||
| 649 | /* Check the value of the new cluster - it must be a valid cluster number | ||
| 650 | or something is really wrong! */ | ||
| 651 |
8/8✓ Branch 142 → 143 taken 1589 times.
✓ Branch 142 → 144 taken 5 times.
✓ Branch 143 → 144 taken 5 times.
✓ Branch 143 → 145 taken 1584 times.
✓ Branch 144 → 145 taken 1286 times.
✓ Branch 144 → 146 taken 4 times.
✓ Branch 145 → 146 taken 4 times.
✓ Branch 145 → 147 taken 1282 times.
|
2884 | if ((cluster < FX_FAT_ENTRY_START) || (cluster >= media_ptr -> fx_media_fat_reserved)) |
| 652 | { | ||
| 653 | |||
| 654 | /* Send error message back to caller. */ | ||
| 655 | 18 | return(FX_FILE_CORRUPT); | |
| 656 | } | ||
| 657 | |||
| 658 | /* Setup the relative sector (this is zero for subsequent cluster. */ | ||
| 659 | 2866 | relative_sector = 0; | |
| 660 | |||
| 661 | /* Calculate the next logical sector. */ | ||
| 662 | 2866 | logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) + | |
| 663 | 2866 | (((ULONG)cluster - FX_FAT_ENTRY_START) * | |
| 664 | 2866 | ((ULONG)media_ptr -> fx_media_sectors_per_cluster)); | |
| 665 | } | ||
| 666 | } | ||
| 667 | else | ||
| 668 | { | ||
| 669 | |||
| 670 | /* Increment the logical sector. */ | ||
| 671 | 1355 | logical_sector++; | |
| 672 | |||
| 673 | /* Determine if the logical sector is valid. */ | ||
| 674 |
4/4✓ Branch 146 → 147 taken 5 times.
✓ Branch 146 → 148 taken 736 times.
✓ Branch 148 → 149 taken 4 times.
✓ Branch 148 → 150 taken 610 times.
|
1355 | if (logical_sector >= (ULONG)(media_ptr -> fx_media_data_sector_start)) |
| 675 | { | ||
| 676 | |||
| 677 | /* We have exceeded the root directory. */ | ||
| 678 | |||
| 679 | /* Send error message back to caller. */ | ||
| 680 | 9 | return(FX_FILE_CORRUPT); | |
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 | /* Read the sector. */ | ||
| 685 | 4907 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) logical_sector, | |
| 686 | 4907 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_DIRECTORY_SECTOR); | |
| 687 | |||
| 688 | /* Determine if an error occurred. */ | ||
| 689 |
4/4✓ Branch 149 → 150 taken 5 times.
✓ Branch 149 → 151 taken 2538 times.
✓ Branch 151 → 152 taken 4 times.
✓ Branch 151 → 153 taken 2360 times.
|
4907 | if (status != FX_SUCCESS) |
| 690 | { | ||
| 691 | |||
| 692 | /* Return the error status. */ | ||
| 693 | 9 | return(status); | |
| 694 | } | ||
| 695 | |||
| 696 | /* Setup logical sector. */ | ||
| 697 | 4898 | sector_base_ptr = media_ptr -> fx_media_memory_buffer; | |
| 698 | |||
| 699 | /* Setup a fresh byte offset. */ | ||
| 700 | 4898 | byte_offset = 0; | |
| 701 | |||
| 702 | /* Setup a new pointer into the buffer. */ | ||
| 703 | 4898 | work_ptr = sector_base_ptr; | |
| 704 | |||
| 705 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 706 | /* Initialize data for fault tolerant. */ | ||
| 707 | 2360 | changed_ptr = work_ptr; | |
| 708 | 2360 | changed_size = 0; | |
| 709 | 2360 | changed_offset = 0; | |
| 710 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 711 | } | ||
| 712 | |||
| 713 | /* Decrement loop control. */ | ||
| 714 | 26326 | card--; | |
| 715 | 26326 | work_ptr[0] = (UCHAR)card; | |
| 716 | } | ||
| 717 | |||
| 718 | /* Determine if there is a short name. */ | ||
| 719 |
4/4✓ Branch 154 → 155 taken 5431 times.
✓ Branch 154 → 158 taken 265 times.
✓ Branch 156 → 157 taken 5986 times.
✓ Branch 156 → 160 taken 544 times.
|
12226 | if (entry_ptr -> fx_dir_entry_short_name[0] == 0) |
| 720 | { | ||
| 721 | |||
| 722 | /* Loop to copy the new short file name. */ | ||
| 723 |
4/4✓ Branch 157 → 156 taken 59741 times.
✓ Branch 157 → 229 taken 5431 times.
✓ Branch 159 → 158 taken 65846 times.
✓ Branch 159 → 233 taken 5986 times.
|
137004 | for (i = 0; i < (FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE); i++) |
| 724 | { | ||
| 725 | |||
| 726 | /* Pickup shortname character. */ | ||
| 727 | 125587 | alpha = shortname[i]; | |
| 728 | |||
| 729 | /* Now store the short name character. */ | ||
| 730 | 125587 | *work_ptr++ = (UCHAR)alpha; | |
| 731 | } | ||
| 732 | } | ||
| 733 | else | ||
| 734 | { | ||
| 735 | |||
| 736 | /* Clear the short file name area. */ | ||
| 737 |
4/4✓ Branch 160 → 159 taken 2915 times.
✓ Branch 160 → 161 taken 265 times.
✓ Branch 162 → 161 taken 5984 times.
✓ Branch 162 → 163 taken 544 times.
|
9708 | for (i = 0; i < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++) |
| 738 | { | ||
| 739 | 8899 | work_ptr[i] = ' '; | |
| 740 | } | ||
| 741 | |||
| 742 | /* Loop to copy the old short file name. */ | ||
| 743 |
4/4✓ Branch 167 → 162 taken 1950 times.
✓ Branch 167 → 168 taken 215 times.
✓ Branch 169 → 164 taken 3672 times.
✓ Branch 169 → 170 taken 344 times.
|
6181 | for (i = 0, j = 0; j < FX_DIR_NAME_SIZE; i++, j++) |
| 744 | { | ||
| 745 | |||
| 746 | /* Check for end of copy conditions. */ | ||
| 747 |
4/4✓ Branch 162 → 163 taken 10 times.
✓ Branch 162 → 164 taken 1940 times.
✓ Branch 164 → 165 taken 46 times.
✓ Branch 164 → 166 taken 3626 times.
|
5622 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == '.') |
| 748 | { | ||
| 749 | 56 | break; | |
| 750 | } | ||
| 751 |
4/4✓ Branch 164 → 165 taken 40 times.
✓ Branch 164 → 166 taken 1900 times.
✓ Branch 166 → 167 taken 154 times.
✓ Branch 166 → 168 taken 3472 times.
|
5566 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == 0) |
| 752 | { | ||
| 753 | 194 | break; | |
| 754 | } | ||
| 755 | |||
| 756 | /* Copy file name character. */ | ||
| 757 | 5372 | work_ptr[j] = (UCHAR)entry_ptr -> fx_dir_entry_short_name[i]; | |
| 758 | } | ||
| 759 | |||
| 760 | /* Determine if there is anything left in the short file name. */ | ||
| 761 |
4/4✓ Branch 168 → 169 taken 20 times.
✓ Branch 168 → 174 taken 245 times.
✓ Branch 170 → 171 taken 62 times.
✓ Branch 170 → 176 taken 482 times.
|
809 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] != 0) |
| 762 | { | ||
| 763 | |||
| 764 | /* Pickup remaining characters. */ | ||
| 765 |
4/4✓ Branch 173 → 170 taken 60 times.
✓ Branch 173 → 174 taken 15 times.
✓ Branch 175 → 172 taken 178 times.
✓ Branch 175 → 176 taken 46 times.
|
299 | for (i++, j = FX_DIR_NAME_SIZE; j < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++, j++) |
| 766 | { | ||
| 767 | |||
| 768 | /* If NULL is encountered, stop the copying. */ | ||
| 769 |
4/4✓ Branch 170 → 171 taken 5 times.
✓ Branch 170 → 172 taken 55 times.
✓ Branch 172 → 173 taken 16 times.
✓ Branch 172 → 174 taken 162 times.
|
238 | if ((UCHAR)entry_ptr -> fx_dir_entry_short_name[i] == 0) |
| 770 | { | ||
| 771 | 21 | break; | |
| 772 | } | ||
| 773 | |||
| 774 | /* Copy file name character. */ | ||
| 775 | 217 | work_ptr[j] = (UCHAR)entry_ptr -> fx_dir_entry_short_name[i]; | |
| 776 | } | ||
| 777 | } | ||
| 778 | |||
| 779 | /* Adjust the work pointer accordingly. */ | ||
| 780 | 809 | work_ptr += (FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE); | |
| 781 | } | ||
| 782 | } | ||
| 783 | else | ||
| 784 | { | ||
| 785 | |||
| 786 | /* Determine if long name was shorted. */ | ||
| 787 |
4/4✓ Branch 175 → 176 taken 75 times.
✓ Branch 175 → 202 taken 731929 times.
✓ Branch 177 → 178 taken 408 times.
✓ Branch 177 → 206 taken 169807226 times.
|
170539638 | if (entry_ptr -> fx_dir_entry_long_name_shorted > 0) |
| 788 | { | ||
| 789 | |||
| 790 | /* Check for a valid short name. */ | ||
| 791 |
4/4✓ Branch 176 → 177 taken 70 times.
✓ Branch 176 → 202 taken 5 times.
✓ Branch 178 → 179 taken 398 times.
✓ Branch 178 → 206 taken 10 times.
|
483 | if ((UCHAR)(0x40 | entry_ptr -> fx_dir_entry_long_name_shorted) == (UCHAR)(*work_ptr)) |
| 792 | { | ||
| 793 | |||
| 794 | /* Loop through the file name. */ | ||
| 795 |
4/4✓ Branch 201 → 178 taken 405 times.
✓ Branch 201 → 202 taken 40 times.
✓ Branch 205 → 180 taken 1374 times.
✓ Branch 205 → 206 taken 374 times.
|
2193 | for (j = 0; j < entry_ptr -> fx_dir_entry_long_name_shorted; j++) |
| 796 | { | ||
| 797 | |||
| 798 | /* Check for a free entry to be written. */ | ||
| 799 |
4/4✓ Branch 178 → 179 taken 130 times.
✓ Branch 178 → 180 taken 275 times.
✓ Branch 180 → 181 taken 128 times.
✓ Branch 180 → 182 taken 1246 times.
|
1779 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[0] == (UCHAR)FX_DIR_ENTRY_FREE) |
| 800 | { | ||
| 801 | /* Delete long parts. */ | ||
| 802 | 258 | work_ptr[0] = (UCHAR)FX_DIR_ENTRY_FREE; | |
| 803 | } | ||
| 804 | |||
| 805 | /* Setup pointers for the name write. */ | ||
| 806 | 1779 | work_ptr += FX_DIR_ENTRY_SIZE; | |
| 807 | 1779 | byte_offset += FX_DIR_ENTRY_SIZE; | |
| 808 | |||
| 809 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 810 | /* Update changed_size. */ | ||
| 811 | 1374 | changed_size += FX_DIR_ENTRY_SIZE; | |
| 812 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 813 | |||
| 814 | /* Determine if the write is within the current sector. */ | ||
| 815 |
4/4✓ Branch 180 → 181 taken 110 times.
✓ Branch 180 → 200 taken 295 times.
✓ Branch 182 → 183 taken 278 times.
✓ Branch 182 → 204 taken 1096 times.
|
1779 | if (byte_offset >= media_ptr -> fx_media_bytes_per_sector) |
| 816 | { | ||
| 817 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 818 |
2/2✓ Branch 183 → 184 taken 2 times.
✓ Branch 183 → 185 taken 276 times.
|
278 | if (media_ptr -> fx_media_fault_tolerant_enabled) |
| 819 | { | ||
| 820 | |||
| 821 | /* Redirect this request to log file. */ | ||
| 822 | 2 | status = _fx_fault_tolerant_add_dir_log(media_ptr, (ULONG64) logical_sector, changed_offset, changed_ptr, changed_size); | |
| 823 | } | ||
| 824 | else | ||
| 825 | { | ||
| 826 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 827 | |||
| 828 | /* Write the current sector out. */ | ||
| 829 | 386 | status = _fx_utility_logical_sector_write(media_ptr, (ULONG64) logical_sector, | |
| 830 | sector_base_ptr, ((ULONG) 1), FX_DIRECTORY_SECTOR); | ||
| 831 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 832 | } | ||
| 833 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 834 | |||
| 835 | /* Determine if an error occurred. */ | ||
| 836 |
4/4✓ Branch 182 → 183 taken 5 times.
✓ Branch 182 → 184 taken 105 times.
✓ Branch 186 → 187 taken 4 times.
✓ Branch 186 → 188 taken 274 times.
|
388 | if (status != FX_SUCCESS) |
| 837 | { | ||
| 838 | |||
| 839 | /* Return the error status. */ | ||
| 840 | 9 | return(status); | |
| 841 | } | ||
| 842 | |||
| 843 | /* Determine if we are in the root directory. */ | ||
| 844 |
4/4✓ Branch 184 → 185 taken 55 times.
✓ Branch 184 → 194 taken 50 times.
✓ Branch 188 → 189 taken 106 times.
✓ Branch 188 → 198 taken 168 times.
|
379 | if (logical_sector >= (ULONG)(media_ptr -> fx_media_data_sector_start)) |
| 845 | { | ||
| 846 | |||
| 847 | /* Determine the next sector of the directory entry. */ | ||
| 848 |
4/4✓ Branch 185 → 186 taken 30 times.
✓ Branch 185 → 187 taken 25 times.
✓ Branch 189 → 190 taken 62 times.
✓ Branch 189 → 191 taken 44 times.
|
161 | if (relative_sector < (media_ptr -> fx_media_sectors_per_cluster - 1)) |
| 849 | { | ||
| 850 | |||
| 851 | /* More sectors in this cluster. */ | ||
| 852 | |||
| 853 | /* Simply increment the logical sector. */ | ||
| 854 | 92 | logical_sector++; | |
| 855 | |||
| 856 | /* Increment the relative sector. */ | ||
| 857 | 92 | relative_sector++; | |
| 858 | } | ||
| 859 | else | ||
| 860 | { | ||
| 861 | |||
| 862 | /* We need to move to the next cluster. */ | ||
| 863 | |||
| 864 | /* Pickup the next cluster. */ | ||
| 865 | 69 | status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster); | |
| 866 | |||
| 867 | /* Check for I/O error. */ | ||
| 868 |
4/4✓ Branch 188 → 189 taken 5 times.
✓ Branch 188 → 190 taken 20 times.
✓ Branch 192 → 193 taken 4 times.
✓ Branch 192 → 194 taken 40 times.
|
69 | if (status != FX_SUCCESS) |
| 869 | { | ||
| 870 | |||
| 871 | /* Return error code. */ | ||
| 872 | 9 | return(status); | |
| 873 | } | ||
| 874 | |||
| 875 | /* Copy next cluster to the current cluster. */ | ||
| 876 | 60 | cluster = next_cluster; | |
| 877 | |||
| 878 | /* Check the value of the new cluster - it must be a valid cluster number | ||
| 879 | or something is really wrong! */ | ||
| 880 |
8/8✓ Branch 190 → 191 taken 15 times.
✓ Branch 190 → 192 taken 5 times.
✓ Branch 191 → 192 taken 5 times.
✓ Branch 191 → 193 taken 10 times.
✓ Branch 194 → 195 taken 36 times.
✓ Branch 194 → 196 taken 4 times.
✓ Branch 195 → 196 taken 4 times.
✓ Branch 195 → 197 taken 32 times.
|
60 | if ((cluster < FX_FAT_ENTRY_START) || (cluster >= media_ptr -> fx_media_fat_reserved)) |
| 881 | { | ||
| 882 | |||
| 883 | /* Send error message back to caller. */ | ||
| 884 | 18 | return(FX_FILE_CORRUPT); | |
| 885 | } | ||
| 886 | |||
| 887 | /* Setup the relative sector (this is zero for subsequent cluster. */ | ||
| 888 | 42 | relative_sector = 0; | |
| 889 | |||
| 890 | /* Calculate the next logical sector. */ | ||
| 891 | 42 | logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) + | |
| 892 | 42 | (((ULONG)cluster - FX_FAT_ENTRY_START) * | |
| 893 | 42 | ((ULONG)media_ptr -> fx_media_sectors_per_cluster)); | |
| 894 | } | ||
| 895 | } | ||
| 896 | else | ||
| 897 | { | ||
| 898 | |||
| 899 | /* Increment the logical sector. */ | ||
| 900 | 218 | logical_sector++; | |
| 901 | |||
| 902 | /* Determine if the logical sector is valid. */ | ||
| 903 |
4/4✓ Branch 194 → 195 taken 5 times.
✓ Branch 194 → 196 taken 45 times.
✓ Branch 198 → 199 taken 4 times.
✓ Branch 198 → 200 taken 164 times.
|
218 | if (logical_sector >= (ULONG)(media_ptr -> fx_media_data_sector_start)) |
| 904 | { | ||
| 905 | |||
| 906 | /* We have exceeded the root directory. */ | ||
| 907 | |||
| 908 | /* Send error message back to caller. */ | ||
| 909 | 9 | return(FX_FILE_CORRUPT); | |
| 910 | } | ||
| 911 | } | ||
| 912 | |||
| 913 | /* Read the next logical sector. */ | ||
| 914 | 343 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) logical_sector, | |
| 915 | 343 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_DIRECTORY_SECTOR); | |
| 916 | |||
| 917 | /* Determine if an error occurred. */ | ||
| 918 |
4/4✓ Branch 197 → 198 taken 5 times.
✓ Branch 197 → 199 taken 80 times.
✓ Branch 201 → 202 taken 4 times.
✓ Branch 201 → 203 taken 254 times.
|
343 | if (status != FX_SUCCESS) |
| 919 | { | ||
| 920 | |||
| 921 | /* Return the error status. */ | ||
| 922 | 9 | return(status); | |
| 923 | } | ||
| 924 | |||
| 925 | /* Move to the next sector buffer. */ | ||
| 926 | 334 | sector_base_ptr = media_ptr -> fx_media_memory_buffer; | |
| 927 | |||
| 928 | /* Setup new buffer pointers. */ | ||
| 929 | 334 | byte_offset = 0; | |
| 930 | 334 | work_ptr = sector_base_ptr; | |
| 931 | |||
| 932 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 933 | /* Initialize data for fault tolerant. */ | ||
| 934 | 254 | changed_ptr = work_ptr; | |
| 935 | 254 | changed_size = 0; | |
| 936 | 254 | changed_offset = 0; | |
| 937 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 938 | } | ||
| 939 | } | ||
| 940 | } | ||
| 941 | } | ||
| 942 | |||
| 943 | /* This is an 8.3 name. First clear the directory name. */ | ||
| 944 |
4/4✓ Branch 204 → 203 taken 8051714 times.
✓ Branch 204 → 205 taken 731974 times.
✓ Branch 208 → 207 taken 1867883710 times.
✓ Branch 208 → 209 taken 169807610 times.
|
2046475008 | for (j = 0; j < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; j++) |
| 945 | { | ||
| 946 | 1875935424 | work_ptr[j] = ' '; | |
| 947 | } | ||
| 948 | |||
| 949 | /* Copy leading dots in case of first two entries of a directory. */ | ||
| 950 |
4/4✓ Branch 207 → 206 taken 295796 times.
✓ Branch 207 → 208 taken 731974 times.
✓ Branch 211 → 210 taken 247276 times.
✓ Branch 211 → 212 taken 169807610 times.
|
171082656 | for (i = 0; (UCHAR)entry_ptr -> fx_dir_entry_name[i] == '.'; i++) |
| 951 | { | ||
| 952 | 543072 | work_ptr[i] = '.'; | |
| 953 | } | ||
| 954 | |||
| 955 | /* Determine if there are more characters to copy. */ | ||
| 956 |
4/4✓ Branch 208 → 209 taken 534775 times.
✓ Branch 208 → 219 taken 197199 times.
✓ Branch 212 → 213 taken 169642758 times.
✓ Branch 212 → 223 taken 164852 times.
|
170539584 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[i] != 0) |
| 957 | { | ||
| 958 | |||
| 959 | /* Copy directory name. */ | ||
| 960 |
4/4✓ Branch 218 → 210 taken 3521734 times.
✓ Branch 218 → 219 taken 35 times.
✓ Branch 222 → 214 taken 868690785 times.
✓ Branch 222 → 223 taken 324 times.
|
872212878 | for (i = 0, j = 0; j < FX_DIR_NAME_SIZE; i++, j++) |
| 961 | { | ||
| 962 | |||
| 963 | /* Check for end of copy conditions. */ | ||
| 964 |
4/4✓ Branch 210 → 211 taken 423607 times.
✓ Branch 210 → 212 taken 3098127 times.
✓ Branch 214 → 215 taken 169544882 times.
✓ Branch 214 → 216 taken 699145903 times.
|
872212519 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[i] == '.') |
| 965 | { | ||
| 966 | 169968489 | break; | |
| 967 | } | ||
| 968 |
4/4✓ Branch 212 → 213 taken 111133 times.
✓ Branch 212 → 214 taken 2986994 times.
✓ Branch 216 → 217 taken 97552 times.
✓ Branch 216 → 218 taken 699048351 times.
|
702244030 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[i] == 0) |
| 969 | { | ||
| 970 | 208685 | break; | |
| 971 | } | ||
| 972 | |||
| 973 | /* Pickup shortname character. */ | ||
| 974 | 702035345 | alpha = entry_ptr -> fx_dir_entry_name[i]; | |
| 975 | |||
| 976 | /* Determine if character is lower case. */ | ||
| 977 |
8/8✓ Branch 214 → 215 taken 65 times.
✓ Branch 214 → 217 taken 2986929 times.
✓ Branch 215 → 216 taken 50 times.
✓ Branch 215 → 217 taken 15 times.
✓ Branch 218 → 219 taken 124 times.
✓ Branch 218 → 221 taken 699048227 times.
✓ Branch 219 → 220 taken 80 times.
✓ Branch 219 → 221 taken 44 times.
|
702035345 | if ((alpha >= 'a') && (alpha <= 'z')) |
| 978 | { | ||
| 979 | |||
| 980 | /* Store the character - converted to upper case. */ | ||
| 981 | 130 | alpha = (CHAR)(alpha - ((CHAR)0x20)); | |
| 982 | } | ||
| 983 | |||
| 984 | /* Copy a name character. */ | ||
| 985 | 702035345 | work_ptr[j] = (UCHAR)alpha; | |
| 986 | } | ||
| 987 | } | ||
| 988 | |||
| 989 | /* Determine if there are more characters in the name. */ | ||
| 990 |
4/4✓ Branch 219 → 220 taken 423617 times.
✓ Branch 219 → 228 taken 308357 times.
✓ Branch 223 → 224 taken 169544890 times.
✓ Branch 223 → 232 taken 262720 times.
|
170539584 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[i] != 0) |
| 991 | { | ||
| 992 | |||
| 993 | /* Loop to copy the remainder of the name. */ | ||
| 994 |
4/4✓ Branch 227 → 221 taken 1270851 times.
✓ Branch 227 → 228 taken 423607 times.
✓ Branch 231 → 225 taken 508634670 times.
✓ Branch 231 → 232 taken 169544882 times.
|
679874010 | for (i++, j = FX_DIR_NAME_SIZE; j < FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE; i++, j++) |
| 995 | { | ||
| 996 | |||
| 997 | /* Check for end of copy conditions. */ | ||
| 998 |
4/4✓ Branch 221 → 222 taken 10 times.
✓ Branch 221 → 223 taken 1270841 times.
✓ Branch 225 → 226 taken 8 times.
✓ Branch 225 → 227 taken 508634662 times.
|
509905521 | if ((UCHAR)entry_ptr -> fx_dir_entry_name[i] == 0) |
| 999 | { | ||
| 1000 | 18 | break; | |
| 1001 | } | ||
| 1002 | |||
| 1003 | /* Pickup shortname character. */ | ||
| 1004 | 509905503 | alpha = entry_ptr -> fx_dir_entry_name[i]; | |
| 1005 | |||
| 1006 | /* Determine if character is lower case. */ | ||
| 1007 |
8/8✓ Branch 223 → 224 taken 25 times.
✓ Branch 223 → 226 taken 1270816 times.
✓ Branch 224 → 225 taken 15 times.
✓ Branch 224 → 226 taken 10 times.
✓ Branch 227 → 228 taken 32 times.
✓ Branch 227 → 230 taken 508634630 times.
✓ Branch 228 → 229 taken 24 times.
✓ Branch 228 → 230 taken 8 times.
|
509905503 | if ((alpha >= 'a') && (alpha <= 'z')) |
| 1008 | { | ||
| 1009 | |||
| 1010 | /* Store the character - converted to upper case. */ | ||
| 1011 | 39 | alpha = (CHAR)(alpha - ((CHAR)0x20)); | |
| 1012 | } | ||
| 1013 | |||
| 1014 | /* Copy a name character. */ | ||
| 1015 | 509905503 | work_ptr[j] = (UCHAR)alpha; | |
| 1016 | } | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | /* Move to the next entry. */ | ||
| 1020 | 170539584 | work_ptr += (FX_DIR_NAME_SIZE + FX_DIR_EXT_SIZE); | |
| 1021 | } | ||
| 1022 | |||
| 1023 | /* Write out the 8.3 part of the name. */ | ||
| 1024 | |||
| 1025 | /* Copy the attribute into the destination. */ | ||
| 1026 | 170551810 | *work_ptr++ = entry_ptr -> fx_dir_entry_attributes; | |
| 1027 | |||
| 1028 | /* Copy the reserved byte. */ | ||
| 1029 | 170551810 | *work_ptr++ = entry_ptr -> fx_dir_entry_reserved; | |
| 1030 | |||
| 1031 | /* Copy the created time in milliseconds. */ | ||
| 1032 | 170551810 | *work_ptr++ = entry_ptr -> fx_dir_entry_created_time_ms; | |
| 1033 | |||
| 1034 | /* Copy the created time. */ | ||
| 1035 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, entry_ptr -> fx_dir_entry_created_time); | |
| 1036 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1037 | |||
| 1038 | /* Copy the created date. */ | ||
| 1039 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, entry_ptr -> fx_dir_entry_created_date); | |
| 1040 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1041 | |||
| 1042 | /* Copy the last accessed date. */ | ||
| 1043 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, entry_ptr -> fx_dir_entry_last_accessed_date); | |
| 1044 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1045 | |||
| 1046 | /* Determine if a FAT32 entry is present. */ | ||
| 1047 |
4/4✓ Branch 232 → 233 taken 291652 times.
✓ Branch 232 → 234 taken 446018 times.
✓ Branch 236 → 237 taken 157609078 times.
✓ Branch 236 → 238 taken 12205062 times.
|
170551810 | if (media_ptr -> fx_media_32_bit_FAT) |
| 1048 | { | ||
| 1049 | |||
| 1050 | /* Yes, FAT32 is present, store upper half of cluster. */ | ||
| 1051 | 157900730 | temp = (entry_ptr -> fx_dir_entry_cluster >> 16); | |
| 1052 | 157900730 | _fx_utility_16_unsigned_write(work_ptr, temp); | |
| 1053 | } | ||
| 1054 | else | ||
| 1055 | { | ||
| 1056 | |||
| 1057 | /* No, FAT16 or FAT12 is present, just write a 0 for | ||
| 1058 | the upper half of the cluster. */ | ||
| 1059 | 12651080 | _fx_utility_16_unsigned_write(work_ptr, 0); | |
| 1060 | } | ||
| 1061 | |||
| 1062 | /* Advance the entry pointer. */ | ||
| 1063 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1064 | |||
| 1065 | /* Copy the time into the destination. */ | ||
| 1066 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, entry_ptr -> fx_dir_entry_time); | |
| 1067 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1068 | |||
| 1069 | /* Copy the date into the destination. */ | ||
| 1070 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, entry_ptr -> fx_dir_entry_date); | |
| 1071 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1072 | |||
| 1073 | /* Copy the starting cluster into the destination. */ | ||
| 1074 | 170551810 | _fx_utility_16_unsigned_write(work_ptr, (UINT)entry_ptr -> fx_dir_entry_cluster); | |
| 1075 | 170551810 | work_ptr = work_ptr + 2; /* Always 2 bytes */ | |
| 1076 | |||
| 1077 | /* Copy the file size into the destination. */ | ||
| 1078 | 170551810 | _fx_utility_32_unsigned_write(work_ptr, (ULONG)entry_ptr -> fx_dir_entry_file_size); | |
| 1079 | |||
| 1080 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 1081 | /* Update changed_size. */ | ||
| 1082 | 169814140 | changed_size += FX_DIR_ENTRY_SIZE; | |
| 1083 | |||
| 1084 |
2/2✓ Branch 243 → 244 taken 166961338 times.
✓ Branch 243 → 246 taken 2852802 times.
|
169814140 | if (media_ptr -> fx_media_fault_tolerant_enabled && |
| 1085 |
2/2✓ Branch 244 → 245 taken 163558444 times.
✓ Branch 244 → 246 taken 3402894 times.
|
166961338 | (media_ptr -> fx_media_fault_tolerant_state & FX_FAULT_TOLERANT_STATE_STARTED)) |
| 1086 | { | ||
| 1087 | |||
| 1088 | /* Redirect this request to log file. */ | ||
| 1089 | 163558444 | status = _fx_fault_tolerant_add_dir_log(media_ptr, (ULONG64) logical_sector, changed_offset, changed_ptr, changed_size); | |
| 1090 | } | ||
| 1091 | else | ||
| 1092 | { | ||
| 1093 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 1094 | |||
| 1095 | /* Write the directory sector to the media. */ | ||
| 1096 | 6993366 | status = _fx_utility_logical_sector_write(media_ptr, (ULONG64) logical_sector, | |
| 1097 | sector_base_ptr, ((ULONG) 1), FX_DIRECTORY_SECTOR); | ||
| 1098 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 1099 | } | ||
| 1100 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 1101 | |||
| 1102 | /* Determine if an error occurred. */ | ||
| 1103 |
4/4✓ Branch 240 → 241 taken 144 times.
✓ Branch 240 → 242 taken 737526 times.
✓ Branch 247 → 248 taken 22904 times.
✓ Branch 247 → 249 taken 169791234 times.
|
170551808 | if (status != FX_SUCCESS) |
| 1104 | { | ||
| 1105 | |||
| 1106 | /* Return the error status. */ | ||
| 1107 | 23048 | return(status); | |
| 1108 | } | ||
| 1109 | |||
| 1110 | #ifndef FX_MEDIA_DISABLE_SEARCH_CACHE | ||
| 1111 | |||
| 1112 | /* Determine if there is a previously found directory entry in the directory | ||
| 1113 | search cache. */ | ||
| 1114 |
4/4✓ Branch 242 → 243 taken 147980 times.
✓ Branch 242 → 246 taken 589546 times.
✓ Branch 249 → 250 taken 169252794 times.
✓ Branch 249 → 253 taken 538440 times.
|
170528760 | if (media_ptr -> fx_media_last_found_name[0]) |
| 1115 | { | ||
| 1116 | |||
| 1117 | /* Determine if the cached search directory entry matches the directory entry being | ||
| 1118 | written. */ | ||
| 1119 |
4/4✓ Branch 243 → 244 taken 147895 times.
✓ Branch 243 → 246 taken 85 times.
✓ Branch 250 → 251 taken 169219872 times.
✓ Branch 250 → 253 taken 32922 times.
|
169400774 | if ((entry_ptr -> fx_dir_entry_log_sector == media_ptr -> fx_media_last_found_entry.fx_dir_entry_log_sector) && |
| 1120 |
4/4✓ Branch 244 → 245 taken 35726 times.
✓ Branch 244 → 246 taken 112169 times.
✓ Branch 251 → 252 taken 168754676 times.
✓ Branch 251 → 253 taken 465196 times.
|
169367767 | (entry_ptr -> fx_dir_entry_byte_offset == media_ptr -> fx_media_last_found_entry.fx_dir_entry_byte_offset)) |
| 1121 | { | ||
| 1122 | |||
| 1123 | /* Yes, this entry is the same as the one currently in the directory search cache. | ||
| 1124 | Update various fields in the directory search cache with the information being | ||
| 1125 | written now. */ | ||
| 1126 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_cluster = entry_ptr -> fx_dir_entry_cluster; | |
| 1127 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_file_size = entry_ptr -> fx_dir_entry_file_size; | |
| 1128 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_attributes = entry_ptr -> fx_dir_entry_attributes; | |
| 1129 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_time = entry_ptr -> fx_dir_entry_time; | |
| 1130 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_date = entry_ptr -> fx_dir_entry_date; | |
| 1131 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_reserved = entry_ptr -> fx_dir_entry_reserved; | |
| 1132 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_created_time_ms = entry_ptr -> fx_dir_entry_created_time_ms; | |
| 1133 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_created_time = entry_ptr -> fx_dir_entry_created_time; | |
| 1134 | 168790402 | media_ptr -> fx_media_last_found_entry.fx_dir_entry_created_date = entry_ptr -> fx_dir_entry_created_date; | |
| 1135 | } | ||
| 1136 | } | ||
| 1137 | #endif | ||
| 1138 | |||
| 1139 | /* Return success to the caller. */ | ||
| 1140 | 170528760 | return(FX_SUCCESS); | |
| 1141 | } | ||
| 1142 | |||
| 1143 |