fx_utility_FAT_entry_read.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 | /** Utility */ | ||
| 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_utility.h" | ||
| 31 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 32 | #include "fx_fault_tolerant.h" | ||
| 33 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 34 | |||
| 35 | |||
| 36 | /**************************************************************************/ | ||
| 37 | /* */ | ||
| 38 | /* FUNCTION RELEASE */ | ||
| 39 | /* */ | ||
| 40 | /* _fx_utility_FAT_entry_read PORTABLE C */ | ||
| 41 | /* 6.2.0 */ | ||
| 42 | /* AUTHOR */ | ||
| 43 | /* */ | ||
| 44 | /* William E. Lamie, Microsoft Corporation */ | ||
| 45 | /* */ | ||
| 46 | /* DESCRIPTION */ | ||
| 47 | /* */ | ||
| 48 | /* This function reads the supplied FAT entry from the first FAT of */ | ||
| 49 | /* the media. 12-bit, 16-bit, and 32-bit FAT reading is supported. */ | ||
| 50 | /* */ | ||
| 51 | /* INPUT */ | ||
| 52 | /* */ | ||
| 53 | /* media_ptr Media control block pointer */ | ||
| 54 | /* cluster Cluster entry number */ | ||
| 55 | /* entry_ptr Pointer to destination for */ | ||
| 56 | /* the FAT entry */ | ||
| 57 | /* */ | ||
| 58 | /* OUTPUT */ | ||
| 59 | /* */ | ||
| 60 | /* return status */ | ||
| 61 | /* */ | ||
| 62 | /* CALLS */ | ||
| 63 | /* */ | ||
| 64 | /* _fx_utility_16_unsigned_read Read a UINT from FAT buffer */ | ||
| 65 | /* _fx_utility_32_unsigned_read Read a ULONG form FAT buffer */ | ||
| 66 | /* _fx_utility_FAT_flush Flush FAT entry cache */ | ||
| 67 | /* _fx_utility_logical_sector_read Read FAT sector into memory */ | ||
| 68 | /* _fx_fault_tolerant_read_FAT Read FAT entry from log file */ | ||
| 69 | /* */ | ||
| 70 | /* CALLED BY */ | ||
| 71 | /* */ | ||
| 72 | /* FileX System Functions */ | ||
| 73 | /* */ | ||
| 74 | /**************************************************************************/ | ||
| 75 | 308480282 | UINT _fx_utility_FAT_entry_read(FX_MEDIA *media_ptr, ULONG cluster, ULONG *entry_ptr) | |
| 76 | { | ||
| 77 | |||
| 78 | ULONG FAT_sector; | ||
| 79 | ULONG byte_offset, entry32; | ||
| 80 | UCHAR *FAT_ptr; | ||
| 81 | UINT entry, index; | ||
| 82 | UINT status; | ||
| 83 | FX_FAT_CACHE_ENTRY *cache_entry_ptr; | ||
| 84 | #ifndef FX_DISABLE_FAT_ENTRY_REFRESH | ||
| 85 | FX_FAT_CACHE_ENTRY temp_cache_entry; | ||
| 86 | #endif /* FX_DISABLE_FAT_ENTRY_REFRESH */ | ||
| 87 | |||
| 88 | |||
| 89 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 90 |
2/2✓ Branch 2 → 3 taken 264577004 times.
✓ Branch 2 → 7 taken 23634324 times.
|
288211328 | if (media_ptr -> fx_media_fault_tolerant_enabled && |
| 91 |
2/2✓ Branch 3 → 4 taken 119365487 times.
✓ Branch 3 → 7 taken 145211517 times.
|
264577004 | (media_ptr -> fx_media_fault_tolerant_state & FX_FAULT_TOLERANT_STATE_STARTED)) |
| 92 | { | ||
| 93 | |||
| 94 | /* Redirect this request to log file. */ | ||
| 95 | 119365487 | status = _fx_fault_tolerant_read_FAT(media_ptr, cluster, entry_ptr, FX_FAULT_TOLERANT_FAT_LOG_TYPE); | |
| 96 | |||
| 97 | /* Return on success. */ | ||
| 98 |
2/2✓ Branch 5 → 6 taken 58 times.
✓ Branch 5 → 7 taken 119365429 times.
|
119365487 | if (status != FX_READ_CONTINUE) |
| 99 | { | ||
| 100 | 58 | return(status); | |
| 101 | } | ||
| 102 | } | ||
| 103 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 104 | |||
| 105 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 106 | /* Increment the number of FAT entry reads and cache hits. */ | ||
| 107 | 308480224 | media_ptr -> fx_media_fat_entry_reads++; | |
| 108 | 308480224 | media_ptr -> fx_media_fat_entry_cache_read_hits++; | |
| 109 | #endif | ||
| 110 | |||
| 111 | /* Extended port-specific processing macro, which is by default defined to white space. */ | ||
| 112 |
23/23✓ Branch 2 → 3 taken 290728 times.
✓ Branch 2 → 13 taken 19978226 times.
✓ Branch 3 → 4 taken 45950 times.
✓ Branch 3 → 5 taken 244778 times.
✓ Branch 5 → 6 taken 80 times.
✓ Branch 5 → 7 taken 244698 times.
✓ Branch 7 → 8 taken 258022 times.
✓ Branch 7 → 9 taken 244658 times.
✓ Branch 7 → 18 taken 287953288 times.
✓ Branch 8 → 9 taken 42028 times.
✓ Branch 8 → 10 taken 215954 times.
✓ Branch 9 → 10 taken 30 times.
✓ Branch 9 → 11 taken 244628 times.
✓ Branch 10 → 11 taken 64 times.
✓ Branch 10 → 12 taken 215890 times.
✓ Branch 11 → 12 taken 20 times.
✓ Branch 11 → 13 taken 244608 times.
✓ Branch 12 → 13 taken 32 times.
✓ Branch 12 → 14 taken 215858 times.
✓ Branch 14 → 15 taken 24 times.
✓ Branch 14 → 16 taken 215834 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 18 taken 215818 times.
|
308480224 | FX_UTILITY_FAT_ENTRY_READ_EXTENSION |
| 113 | |||
| 114 | /* Calculate the area of the cache for this FAT entry. */ | ||
| 115 | 308391940 | index = (cluster & FX_FAT_CACHE_HASH_MASK) * FX_FAT_CACHE_DEPTH; | |
| 116 | |||
| 117 | /* Build a pointer to the cache entry. */ | ||
| 118 | 308391940 | cache_entry_ptr = &media_ptr -> fx_media_fat_cache[index]; | |
| 119 | |||
| 120 | #ifndef FX_DISABLE_FAT_ENTRY_REFRESH | ||
| 121 | /* Determine if the FAT entry is in the cache - assuming the depth of the FAT cache is | ||
| 122 | 4 entries. */ | ||
| 123 |
4/4✓ Branch 13 → 14 taken 9042119 times.
✓ Branch 13 → 15 taken 8379591 times.
✓ Branch 18 → 19 taken 55249253 times.
✓ Branch 18 → 20 taken 93059966 times.
|
165730929 | if ((cache_entry_ptr -> fx_fat_cache_entry_cluster) == cluster) |
| 124 | { | ||
| 125 | |||
| 126 | /* Yes, return the cached value. */ | ||
| 127 | 64291372 | *entry_ptr = cache_entry_ptr -> fx_fat_cache_entry_value; | |
| 128 | |||
| 129 | /* Don't move anything since we found the entry. */ | ||
| 130 | |||
| 131 | /* Return a successful status. */ | ||
| 132 | 64291372 | return(FX_SUCCESS); | |
| 133 | } | ||
| 134 |
4/4✓ Branch 15 → 16 taken 364288 times.
✓ Branch 15 → 17 taken 8015303 times.
✓ Branch 20 → 21 taken 18137216 times.
✓ Branch 20 → 22 taken 74922750 times.
|
101439557 | else if (((cache_entry_ptr + 1) -> fx_fat_cache_entry_cluster) == cluster) |
| 135 | { | ||
| 136 | |||
| 137 | /* Yes, return the cached value. */ | ||
| 138 | 18501504 | *entry_ptr = (cache_entry_ptr + 1) -> fx_fat_cache_entry_value; | |
| 139 | |||
| 140 | /* Just swap the first and second entry. */ | ||
| 141 | 18501504 | temp_cache_entry = *(cache_entry_ptr); | |
| 142 | 18501504 | *(cache_entry_ptr) = *(cache_entry_ptr + 1); | |
| 143 | 18501504 | *(cache_entry_ptr + 1) = temp_cache_entry; | |
| 144 | |||
| 145 | /* Return a successful status. */ | ||
| 146 | 18501504 | return(FX_SUCCESS); | |
| 147 | } | ||
| 148 |
4/4✓ Branch 17 → 18 taken 325820 times.
✓ Branch 17 → 19 taken 7689483 times.
✓ Branch 22 → 23 taken 415313 times.
✓ Branch 22 → 24 taken 74507437 times.
|
82938053 | else if (((cache_entry_ptr + 2) -> fx_fat_cache_entry_cluster) == cluster) |
| 149 | { | ||
| 150 | |||
| 151 | /* Yes, return the cached value. */ | ||
| 152 | 741133 | *entry_ptr = (cache_entry_ptr + 2) -> fx_fat_cache_entry_value; | |
| 153 | |||
| 154 | /* Move the third entry to the top and the first two entries down. */ | ||
| 155 | 741133 | temp_cache_entry = *(cache_entry_ptr); | |
| 156 | 741133 | *(cache_entry_ptr) = *(cache_entry_ptr + 2); | |
| 157 | 741133 | *(cache_entry_ptr + 2) = *(cache_entry_ptr + 1); | |
| 158 | 741133 | *(cache_entry_ptr + 1) = temp_cache_entry; | |
| 159 | |||
| 160 | /* Return a successful status. */ | ||
| 161 | 741133 | return(FX_SUCCESS); | |
| 162 | } | ||
| 163 |
4/4✓ Branch 19 → 20 taken 302471 times.
✓ Branch 19 → 21 taken 7387012 times.
✓ Branch 24 → 25 taken 396512 times.
✓ Branch 24 → 26 taken 74110925 times.
|
82196920 | else if (((cache_entry_ptr + 3) -> fx_fat_cache_entry_cluster) == cluster) |
| 164 | { | ||
| 165 | |||
| 166 | /* Yes, return the cached value. */ | ||
| 167 | 698983 | *entry_ptr = (cache_entry_ptr + 3) -> fx_fat_cache_entry_value; | |
| 168 | |||
| 169 | /* Move the last entry to the top and the first three entries down. */ | ||
| 170 | 698983 | temp_cache_entry = *(cache_entry_ptr); | |
| 171 | 698983 | *(cache_entry_ptr) = *(cache_entry_ptr + 3); | |
| 172 | 698983 | *(cache_entry_ptr + 3) = *(cache_entry_ptr + 2); | |
| 173 | 698983 | *(cache_entry_ptr + 2) = *(cache_entry_ptr + 1); | |
| 174 | 698983 | *(cache_entry_ptr + 1) = temp_cache_entry; | |
| 175 | |||
| 176 | /* Return a successful status. */ | ||
| 177 | 698983 | return(FX_SUCCESS); | |
| 178 | } | ||
| 179 | #else | ||
| 180 |
4/4✓ Branch 17 → 14 taken 4858361 times.
✓ Branch 17 → 18 taken 555971 times.
✓ Branch 22 → 19 taken 353384453 times.
✓ Branch 22 → 23 taken 67224873 times.
|
426023658 | for(UINT i = 0; i < 4; i++) |
| 181 | { | ||
| 182 |
4/4✓ Branch 14 → 15 taken 2245153 times.
✓ Branch 14 → 16 taken 2613208 times.
✓ Branch 19 → 20 taken 72635014 times.
✓ Branch 19 → 21 taken 280749439 times.
|
358242814 | if (((cache_entry_ptr + i) -> fx_fat_cache_entry_cluster) == cluster) |
| 183 | { | ||
| 184 | 74880167 | *entry_ptr = (cache_entry_ptr + i) -> fx_fat_cache_entry_value; | |
| 185 | |||
| 186 | /* Return a successful status. */ | ||
| 187 | 74880167 | return(FX_SUCCESS); | |
| 188 | } | ||
| 189 | } | ||
| 190 | #endif /* FX_DISABLE_FAT_ENTRY_REFRESH */ | ||
| 191 | |||
| 192 | /* Determine if the oldest entry was modified, i.e. whether or not it is | ||
| 193 | dirty. */ | ||
| 194 |
8/8✓ Branch 18 → 19 taken 1135 times.
✓ Branch 18 → 22 taken 554836 times.
✓ Branch 21 → 22 taken 76971 times.
✓ Branch 21 → 25 taken 7310041 times.
✓ Branch 23 → 24 taken 87573 times.
✓ Branch 23 → 27 taken 67137300 times.
✓ Branch 26 → 27 taken 183964 times.
✓ Branch 26 → 30 taken 73926961 times.
|
149278781 | if (media_ptr -> fx_media_fat_cache[index + 3].fx_fat_cache_entry_dirty) |
| 195 | { | ||
| 196 | |||
| 197 | /* Yes, the entry is dirty and needs to be flushed out. */ | ||
| 198 | 349643 | status = _fx_utility_FAT_flush(media_ptr); | |
| 199 | |||
| 200 | /* Check for completion status. */ | ||
| 201 |
6/8✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1135 times.
✓ Branch 23 → 24 taken 60975 times.
✓ Branch 23 → 25 taken 15996 times.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 87569 times.
✓ Branch 28 → 29 taken 90670 times.
✓ Branch 28 → 30 taken 93290 times.
|
349635 | if (status != FX_SUCCESS) |
| 202 | { | ||
| 203 | |||
| 204 | /* Return error status. */ | ||
| 205 | 151645 | return(status); | |
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | /* If we get here, the entry was not found in the FAT entry cache. We need to | ||
| 210 | actually read the FAT entry. */ | ||
| 211 | |||
| 212 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 213 | |||
| 214 | /* Decrement the number of cache hits. */ | ||
| 215 | 149127128 | media_ptr -> fx_media_fat_entry_cache_read_hits--; | |
| 216 | |||
| 217 | /* Increment the number of cache misses. */ | ||
| 218 | 149127128 | media_ptr -> fx_media_fat_entry_cache_read_misses++; | |
| 219 | #endif | ||
| 220 | |||
| 221 | /* Determine which type of FAT is present. */ | ||
| 222 |
8/8✓ Branch 22 → 23 taken 102814 times.
✓ Branch 22 → 42 taken 453157 times.
✓ Branch 25 → 26 taken 1900973 times.
✓ Branch 25 → 45 taken 5425064 times.
✓ Branch 27 → 28 taken 488876 times.
✓ Branch 27 → 47 taken 66735993 times.
✓ Branch 30 → 31 taken 2475309 times.
✓ Branch 30 → 50 taken 71544942 times.
|
149127128 | if (media_ptr -> fx_media_12_bit_FAT) |
| 223 | { | ||
| 224 | |||
| 225 | /* Calculate the byte offset to the cluster entry. */ | ||
| 226 | 4967972 | byte_offset = (((ULONG)cluster << 1) + cluster) >> 1; | |
| 227 | |||
| 228 | /* Calculate the FAT sector the requested FAT entry resides in. */ | ||
| 229 | 4967972 | FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) + | |
| 230 | 4967972 | (ULONG)media_ptr -> fx_media_reserved_sectors; | |
| 231 | |||
| 232 | /* Read the sector in. */ | ||
| 233 | 4967972 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, | |
| 234 | 4967972 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); | |
| 235 | |||
| 236 | /* Determine if an error occurred. */ | ||
| 237 |
6/8✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 102814 times.
✓ Branch 27 → 28 taken 590130 times.
✓ Branch 27 → 29 taken 1310843 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 488876 times.
✓ Branch 32 → 33 taken 786554 times.
✓ Branch 32 → 34 taken 1688755 times.
|
4967972 | if (status != FX_SUCCESS) |
| 238 | { | ||
| 239 | /* Return the error status. */ | ||
| 240 | 1376684 | return(status); | |
| 241 | } | ||
| 242 | |||
| 243 | /* Now calculate the byte offset into this FAT sector. */ | ||
| 244 | 3591288 | byte_offset = byte_offset - | |
| 245 | 3591288 | ((FAT_sector - (ULONG)media_ptr -> fx_media_reserved_sectors) * | |
| 246 | 3591288 | media_ptr -> fx_media_bytes_per_sector); | |
| 247 | |||
| 248 | /* Setup a pointer into the buffer. */ | ||
| 249 | 3591288 | FAT_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer + (UINT)byte_offset; | |
| 250 | |||
| 251 | /* Determine if the cluster entry is odd or even. */ | ||
| 252 |
8/8✓ Branch 26 → 27 taken 51344 times.
✓ Branch 26 → 33 taken 51470 times.
✓ Branch 29 → 30 taken 660759 times.
✓ Branch 29 → 36 taken 650084 times.
✓ Branch 31 → 32 taken 244113 times.
✓ Branch 31 → 38 taken 244763 times.
✓ Branch 34 → 35 taken 852172 times.
✓ Branch 34 → 41 taken 836583 times.
|
3591288 | if (cluster & 1) |
| 253 | { | ||
| 254 | |||
| 255 | /* Odd cluster number. */ | ||
| 256 | |||
| 257 | /* Pickup the lower nibble of the FAT entry. */ | ||
| 258 | 1808388 | entry = (((UINT)*FAT_ptr) & 0xF0) >> 4; | |
| 259 | |||
| 260 | /* Move to the next byte of the FAT entry. */ | ||
| 261 | 1808388 | FAT_ptr++; | |
| 262 | |||
| 263 | /* Determine if we are now past the end of the FAT buffer in memory. */ | ||
| 264 |
8/8✓ Branch 27 → 28 taken 399 times.
✓ Branch 27 → 32 taken 50945 times.
✓ Branch 30 → 31 taken 5243 times.
✓ Branch 30 → 35 taken 655516 times.
✓ Branch 32 → 33 taken 1292 times.
✓ Branch 32 → 37 taken 242821 times.
✓ Branch 35 → 36 taken 6282 times.
✓ Branch 35 → 40 taken 845890 times.
|
1808388 | if (byte_offset == (ULONG)(media_ptr -> fx_media_bytes_per_sector - 1)) |
| 265 | { | ||
| 266 | |||
| 267 | /* Yes, we need to read the next sector. */ | ||
| 268 | 13216 | FAT_sector++; | |
| 269 | 13216 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, | |
| 270 | 13216 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); | |
| 271 | |||
| 272 | /* Determine if an error occurred. */ | ||
| 273 |
6/8✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 399 times.
✓ Branch 32 → 33 taken 1257 times.
✓ Branch 32 → 34 taken 3986 times.
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 1292 times.
✓ Branch 37 → 38 taken 1702 times.
✓ Branch 37 → 39 taken 4580 times.
|
13216 | if (status != FX_SUCCESS) |
| 274 | { | ||
| 275 | |||
| 276 | /* Return the error status. */ | ||
| 277 | 2959 | return(status); | |
| 278 | } | ||
| 279 | |||
| 280 | /* Setup a pointer into the buffer. */ | ||
| 281 | 10257 | FAT_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer; | |
| 282 | } | ||
| 283 | |||
| 284 | /* Pickup the upper 8 bits of the FAT entry. */ | ||
| 285 | 1805429 | entry = entry | (((UINT)*FAT_ptr) << 4); | |
| 286 | } | ||
| 287 | else | ||
| 288 | { | ||
| 289 | |||
| 290 | /* Even cluster number. */ | ||
| 291 | |||
| 292 | /* Pickup the lower byte of the FAT entry. */ | ||
| 293 | 1782900 | entry = (UINT)(((UINT)*FAT_ptr) & 0xFF); | |
| 294 | |||
| 295 | /* Move to the next nibble of the FAT entry. */ | ||
| 296 | 1782900 | FAT_ptr++; | |
| 297 | |||
| 298 | /* Determine if we are now past the end of the FAT buffer in memory. */ | ||
| 299 |
8/8✓ Branch 33 → 34 taken 391 times.
✓ Branch 33 → 38 taken 51079 times.
✓ Branch 36 → 37 taken 4786 times.
✓ Branch 36 → 41 taken 645298 times.
✓ Branch 38 → 39 taken 1272 times.
✓ Branch 38 → 43 taken 243491 times.
✓ Branch 41 → 42 taken 5652 times.
✓ Branch 41 → 46 taken 830931 times.
|
1782900 | if (byte_offset == (ULONG)(media_ptr -> fx_media_bytes_per_sector - 1)) |
| 300 | { | ||
| 301 | |||
| 302 | /* Yes, we need to read the next sector. */ | ||
| 303 | 12101 | FAT_sector++; | |
| 304 | 12101 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, | |
| 305 | 12101 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); | |
| 306 | |||
| 307 | /* Determine if an error occurred. */ | ||
| 308 |
8/8✓ Branch 35 → 36 taken 1 time.
✓ Branch 35 → 37 taken 390 times.
✓ Branch 38 → 39 taken 1054 times.
✓ Branch 38 → 40 taken 3732 times.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 1270 times.
✓ Branch 43 → 44 taken 1434 times.
✓ Branch 43 → 45 taken 4218 times.
|
12101 | if (status != FX_SUCCESS) |
| 309 | { | ||
| 310 | 2491 | return(status); | |
| 311 | } | ||
| 312 | |||
| 313 | /* Setup a pointer into the buffer. */ | ||
| 314 | 9610 | FAT_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer; | |
| 315 | } | ||
| 316 | |||
| 317 | /* Pickup the upper 4 bits of the FAT entry. */ | ||
| 318 | 1780409 | entry = entry | ((((UINT)*FAT_ptr) & 0x0F) << 8); | |
| 319 | } | ||
| 320 | |||
| 321 | /* Determine if we need to do sign extension on the 12-bit eof value. */ | ||
| 322 |
8/8✓ Branch 39 → 40 taken 198 times.
✓ Branch 39 → 41 taken 102615 times.
✓ Branch 42 → 43 taken 548 times.
✓ Branch 42 → 44 taken 1307984 times.
✓ Branch 44 → 45 taken 1378 times.
✓ Branch 44 → 46 taken 487496 times.
✓ Branch 47 → 48 taken 1360 times.
✓ Branch 47 → 49 taken 1684259 times.
|
3585838 | if (entry >= FX_MAX_12BIT_CLUST) |
| 323 | { | ||
| 324 | |||
| 325 | /* Yes, we need to sign extend. */ | ||
| 326 | 3484 | entry = entry | FX_SIGN_EXTEND; | |
| 327 | } | ||
| 328 | |||
| 329 | 3585838 | *entry_ptr = entry; | |
| 330 | } | ||
| 331 | |||
| 332 | /* Check for a 16-bit FAT. */ | ||
| 333 |
8/8✓ Branch 42 → 43 taken 151430 times.
✓ Branch 42 → 48 taken 301727 times.
✓ Branch 45 → 46 taken 2741791 times.
✓ Branch 45 → 51 taken 2683273 times.
✓ Branch 47 → 48 taken 3564452 times.
✓ Branch 47 → 53 taken 63171541 times.
✓ Branch 50 → 51 taken 6404976 times.
✓ Branch 50 → 56 taken 65139966 times.
|
144159156 | else if (!media_ptr -> fx_media_32_bit_FAT) |
| 334 | { | ||
| 335 | |||
| 336 | /* 16-bit FAT is present. */ | ||
| 337 | |||
| 338 | /* Calculate the byte offset to the cluster entry. */ | ||
| 339 | 12862649 | byte_offset = (((ULONG)cluster) * 2); | |
| 340 | |||
| 341 | /* Calculate the FAT sector the requested FAT entry resides in. */ | ||
| 342 | 12862649 | FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) + | |
| 343 | 12862649 | (ULONG)media_ptr -> fx_media_reserved_sectors; | |
| 344 | |||
| 345 | /* Read the FAT sector. */ | ||
| 346 | 12862649 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, | |
| 347 | 12862649 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); | |
| 348 | |||
| 349 | /* Determine if an error occurred. */ | ||
| 350 |
8/8✓ Branch 44 → 45 taken 205 times.
✓ Branch 44 → 46 taken 151225 times.
✓ Branch 47 → 48 taken 595450 times.
✓ Branch 47 → 49 taken 2146341 times.
✓ Branch 49 → 50 taken 414 times.
✓ Branch 49 → 51 taken 3564038 times.
✓ Branch 52 → 53 taken 787220 times.
✓ Branch 52 → 54 taken 5617756 times.
|
12862649 | if (status != FX_SUCCESS) |
| 351 | { | ||
| 352 | |||
| 353 | /* Return the error code. */ | ||
| 354 | 1383289 | return(status); | |
| 355 | } | ||
| 356 | |||
| 357 | /* Now calculate the byte offset into this FAT sector. */ | ||
| 358 | 11479360 | byte_offset = byte_offset - | |
| 359 | 11479360 | ((FAT_sector - (ULONG)media_ptr -> fx_media_reserved_sectors) * | |
| 360 | 11479360 | media_ptr -> fx_media_bytes_per_sector); | |
| 361 | |||
| 362 | /* Setup a pointer into the buffer. */ | ||
| 363 | 11479360 | FAT_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer + (UINT)byte_offset; | |
| 364 | |||
| 365 | /* Pickup the FAT entry. */ | ||
| 366 | 11479360 | entry = _fx_utility_16_unsigned_read(FAT_ptr); | |
| 367 | |||
| 368 | 11479360 | *entry_ptr = entry; | |
| 369 | } | ||
| 370 | else | ||
| 371 | { | ||
| 372 | |||
| 373 | /* Otherwise, a 32 bit FAT present. */ | ||
| 374 | 131296507 | byte_offset = (((ULONG)cluster) * 4); | |
| 375 | |||
| 376 | /* Calculate the FAT sector the requested FAT entry resides in. */ | ||
| 377 | 131296507 | FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) + | |
| 378 | 131296507 | (ULONG)media_ptr -> fx_media_reserved_sectors; | |
| 379 | |||
| 380 | /* Calculate the byte offset to the FAT entry. */ | ||
| 381 | 131296507 | byte_offset = (byte_offset % media_ptr -> fx_media_bytes_per_sector); | |
| 382 | |||
| 383 | /* Read the appropriate FAT sector. */ | ||
| 384 | 131296507 | status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, | |
| 385 | 131296507 | media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); | |
| 386 | |||
| 387 | /* Determine if an error occurred. */ | ||
| 388 |
8/8✓ Branch 49 → 50 taken 380 times.
✓ Branch 49 → 51 taken 301347 times.
✓ Branch 52 → 53 taken 591863 times.
✓ Branch 52 → 54 taken 2091410 times.
✓ Branch 54 → 55 taken 758 times.
✓ Branch 54 → 56 taken 63170783 times.
✓ Branch 57 → 58 taken 788294 times.
✓ Branch 57 → 59 taken 64351672 times.
|
131296507 | if (status != FX_SUCCESS) |
| 389 | { | ||
| 390 | |||
| 391 | /* Return the error code. */ | ||
| 392 | 1381295 | return(status); | |
| 393 | } | ||
| 394 | |||
| 395 | /* Setup a pointer into the buffer. */ | ||
| 396 | 129915212 | FAT_ptr = (UCHAR *)media_ptr -> fx_media_memory_buffer + (ULONG)byte_offset; | |
| 397 | |||
| 398 | /* Pickup the FAT entry. */ | ||
| 399 | 129915212 | entry32 = _fx_utility_32_unsigned_read(FAT_ptr); | |
| 400 | |||
| 401 | |||
| 402 | /* Clear upper nibble. */ | ||
| 403 | 129915212 | entry32 = entry32 & 0x0FFFFFFF; | |
| 404 | |||
| 405 | 129915212 | *entry_ptr = entry32; | |
| 406 | } | ||
| 407 | |||
| 408 | /* Move all the cache entries down so the oldest is at the bottom. */ | ||
| 409 | 144980410 | *(cache_entry_ptr + 3) = *(cache_entry_ptr + 2); | |
| 410 | 144980410 | *(cache_entry_ptr + 2) = *(cache_entry_ptr + 1); | |
| 411 | 144980410 | *(cache_entry_ptr + 1) = *(cache_entry_ptr); | |
| 412 | |||
| 413 | /* Setup the new FAT entry in the cache. */ | ||
| 414 | 144980410 | cache_entry_ptr -> fx_fat_cache_entry_cluster = cluster; | |
| 415 | 144980410 | cache_entry_ptr -> fx_fat_cache_entry_value = *entry_ptr; | |
| 416 | |||
| 417 | /* Return success to the caller. */ | ||
| 418 | 144980410 | return(FX_SUCCESS); | |
| 419 | } | ||
| 420 | |||
| 421 |