fx_utility_logical_sector_flush.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 | |||
| 32 | |||
| 33 | /**************************************************************************/ | ||
| 34 | /* */ | ||
| 35 | /* FUNCTION RELEASE */ | ||
| 36 | /* */ | ||
| 37 | /* _fx_utility_logical_sector_flush PORTABLE C */ | ||
| 38 | /* 6.1.10 */ | ||
| 39 | /* AUTHOR */ | ||
| 40 | /* */ | ||
| 41 | /* William E. Lamie, Microsoft Corporation */ | ||
| 42 | /* */ | ||
| 43 | /* DESCRIPTION */ | ||
| 44 | /* */ | ||
| 45 | /* This function handles logical sector flush requests for all FileX */ | ||
| 46 | /* components. It will process all dirty logical sectors in the */ | ||
| 47 | /* logical sector cache within the range specified. This function */ | ||
| 48 | /* optionally invalidates sectors. */ | ||
| 49 | /* */ | ||
| 50 | /* INPUT */ | ||
| 51 | /* */ | ||
| 52 | /* media_ptr Media control block pointer */ | ||
| 53 | /* starting_sector Starting sector number */ | ||
| 54 | /* sectors Number of sectors */ | ||
| 55 | /* invalidate Invalidate flag */ | ||
| 56 | /* (FX_TRUE -> invalidate) */ | ||
| 57 | /* */ | ||
| 58 | /* OUTPUT */ | ||
| 59 | /* */ | ||
| 60 | /* return status */ | ||
| 61 | /* */ | ||
| 62 | /* CALLS */ | ||
| 63 | /* */ | ||
| 64 | /* I/O Driver */ | ||
| 65 | /* */ | ||
| 66 | /* CALLED BY */ | ||
| 67 | /* */ | ||
| 68 | /* FileX System Functions */ | ||
| 69 | /* */ | ||
| 70 | /**************************************************************************/ | ||
| 71 | 1202695317 | UINT _fx_utility_logical_sector_flush(FX_MEDIA *media_ptr, ULONG64 starting_sector, ULONG64 sectors, UINT invalidate) | |
| 72 | { | ||
| 73 | |||
| 74 | #ifndef FX_DISABLE_CACHE | ||
| 75 | FX_CACHED_SECTOR *cache_entry; | ||
| 76 | UINT cache_size; | ||
| 77 | UINT i, bit_set, use_starting_sector; | ||
| 78 | ULONG index; | ||
| 79 | ULONG remaining_valid; | ||
| 80 | ULONG remaining_dirty; | ||
| 81 | ULONG64 ending_sector; | ||
| 82 | ULONG valid_bit_map; | ||
| 83 | |||
| 84 | |||
| 85 | /* Extended port-specific processing macro, which is by default defined to white space. */ | ||
| 86 |
4/4✓ Branch 2 → 3 taken 49 times.
✓ Branch 2 → 5 taken 532754196 times.
✓ Branch 3 → 4 taken 28 times.
✓ Branch 3 → 5 taken 21 times.
|
532754245 | FX_UTILITY_LOGICAL_SECTOR_FLUSH_EXTENSION |
| 87 | |||
| 88 | /* Calculate the ending sector. */ | ||
| 89 | 532754217 | ending_sector = starting_sector + sectors - 1; | |
| 90 | |||
| 91 | /* Pickup the number of dirty sectors currently in the cache. */ | ||
| 92 | 532754217 | remaining_dirty = media_ptr -> fx_media_sector_cache_dirty_count; | |
| 93 | |||
| 94 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 95 | FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_MEDIA_FLUSH, media_ptr, media_ptr -> fx_media_sector_cache_dirty_count, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) | ||
| 96 | |||
| 97 | /* Determine what type of cache configuration we have. */ | ||
| 98 |
3/3✓ Branch 5 → 6 taken 521734619 times.
✓ Branch 5 → 29 taken 9973726 times.
✓ Branch 5 → 31 taken 1045872 times.
|
532754217 | if (media_ptr -> fx_media_sector_cache_hashed == FX_FALSE) |
| 99 | { | ||
| 100 | |||
| 101 | /* Linear cache present, simply walk through the search list until | ||
| 102 | an unused cache entry is present. */ | ||
| 103 | |||
| 104 | /* Flush and invalidate the internal logical sector cache. */ | ||
| 105 | 521734619 | cache_size = media_ptr -> fx_media_sector_cache_size; | |
| 106 | 521734619 | cache_entry = media_ptr -> fx_media_sector_cache_list_ptr; | |
| 107 | |||
| 108 | /* Look at the cache entries that have been written to. */ | ||
| 109 |
8/8✓ Branch 26 → 27 taken 1671298183 times.
✓ Branch 26 → 28 taken 186032599 times.
✓ Branch 27 → 7 taken 1671298164 times.
✓ Branch 27 → 28 taken 19 times.
✓ Branch 28 → 29 taken 13787050 times.
✓ Branch 28 → 30 taken 13614766 times.
✓ Branch 29 → 7 taken 13787030 times.
✓ Branch 29 → 30 taken 20 times.
|
1884732598 | while ((cache_size--) && (cache_entry -> fx_cached_sector)) |
| 110 | { | ||
| 111 | |||
| 112 | /* Determine if invalidation is not required and there are no | ||
| 113 | more dirty sectors. */ | ||
| 114 |
4/4✓ Branch 7 → 8 taken 1607689753 times.
✓ Branch 7 → 10 taken 77395441 times.
✓ Branch 8 → 9 taken 322027789 times.
✓ Branch 8 → 10 taken 1285661964 times.
|
1685085194 | if ((remaining_dirty == 0) && (invalidate == FX_FALSE)) |
| 115 | { | ||
| 116 | |||
| 117 | /* Yes, nothing left to do. */ | ||
| 118 | 322027789 | break; | |
| 119 | } | ||
| 120 | |||
| 121 | /* Determine if there are any more sectors to process. */ | ||
| 122 |
2/2✓ Branch 10 → 11 taken 900 times.
✓ Branch 10 → 12 taken 1363056505 times.
|
1363057405 | if (sectors == 0) |
| 123 | { | ||
| 124 | |||
| 125 | /* No more sectors required to process. */ | ||
| 126 | 900 | break; | |
| 127 | } | ||
| 128 | |||
| 129 | /* Determine if this cached sector is within the specified range and is valid. */ | ||
| 130 |
3/3✓ Branch 12 → 13 taken 1333788204 times.
✓ Branch 12 → 25 taken 18587056 times.
✓ Branch 12 → 27 taken 10681245 times.
|
1363056505 | if ((cache_entry -> fx_cached_sector_valid) && |
| 131 |
3/3✓ Branch 13 → 14 taken 1034895361 times.
✓ Branch 13 → 25 taken 298788509 times.
✓ Branch 13 → 27 taken 104334 times.
|
1333788204 | (cache_entry -> fx_cached_sector >= starting_sector) && |
| 132 |
3/3✓ Branch 14 → 15 taken 83730987 times.
✓ Branch 14 → 25 taken 951129121 times.
✓ Branch 14 → 27 taken 35253 times.
|
1034895361 | (cache_entry -> fx_cached_sector <= ending_sector)) |
| 133 | { | ||
| 134 | |||
| 135 | /* Yes, the cache entry is valid and within the specified range. Determine if | ||
| 136 | the requested sector has been written to. */ | ||
| 137 |
3/3✓ Branch 15 → 16 taken 77253385 times.
✓ Branch 15 → 21 taken 3808125 times.
✓ Branch 15 → 23 taken 2669477 times.
|
83730987 | if (cache_entry -> fx_cached_sector_buffer_dirty) |
| 138 | { | ||
| 139 | |||
| 140 | /* Yes, write the cached sector out to the media. */ | ||
| 141 | |||
| 142 | /* Check for write protect at the media level (set by driver). */ | ||
| 143 |
3/3✓ Branch 16 → 17 taken 77251600 times.
✓ Branch 16 → 21 taken 1020 times.
✓ Branch 16 → 23 taken 765 times.
|
77253385 | if (media_ptr -> fx_media_driver_write_protect == FX_FALSE) |
| 144 | { | ||
| 145 | |||
| 146 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 147 | |||
| 148 | /* Increment the number of driver write sector(s) requests. */ | ||
| 149 | 77251600 | media_ptr -> fx_media_driver_write_requests++; | |
| 150 | #endif | ||
| 151 | |||
| 152 | /* Build write request to the driver. */ | ||
| 153 | 77251600 | media_ptr -> fx_media_driver_request = FX_DRIVER_WRITE; | |
| 154 | 77251600 | media_ptr -> fx_media_driver_status = FX_IO_ERROR; | |
| 155 | 77251600 | media_ptr -> fx_media_driver_buffer = cache_entry -> fx_cached_sector_memory_buffer; | |
| 156 | #ifdef FX_DRIVER_USE_64BIT_LBA | ||
| 157 | media_ptr -> fx_media_driver_logical_sector = cache_entry -> fx_cached_sector; | ||
| 158 | #else | ||
| 159 | 77251600 | media_ptr -> fx_media_driver_logical_sector = (ULONG)cache_entry -> fx_cached_sector; | |
| 160 | #endif | ||
| 161 | 77251600 | media_ptr -> fx_media_driver_sectors = 1; | |
| 162 | 77251600 | media_ptr -> fx_media_driver_sector_type = cache_entry -> fx_cached_sector_type; | |
| 163 | |||
| 164 | /* Sectors other than FX_DATA_SECTOR will never be dirty when FX_FAULT_TOLERANT is defined. */ | ||
| 165 | #ifndef FX_FAULT_TOLERANT | ||
| 166 | /* Determine if the system write flag needs to be set. */ | ||
| 167 |
2/2✓ Branch 17 → 18 taken 249731 times.
✓ Branch 17 → 19 taken 2199 times.
|
251930 | if (cache_entry -> fx_cached_sector_type != FX_DATA_SECTOR) |
| 168 | { | ||
| 169 | |||
| 170 | /* Yes, a system sector write is present so set the flag. The driver | ||
| 171 | can use this flag to make extra safeguards in writing the sector | ||
| 172 | out, yielding more fault tolerance. */ | ||
| 173 | 249731 | media_ptr -> fx_media_driver_system_write = FX_TRUE; | |
| 174 | } | ||
| 175 | #endif /* FX_FAULT_TOLERANT */ | ||
| 176 | |||
| 177 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 178 | FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_WRITE, media_ptr, cache_entry -> fx_cached_sector, 1, cache_entry -> fx_cached_sector_memory_buffer, FX_TRACE_INTERNAL_EVENTS, 0, 0) | ||
| 179 | |||
| 180 | /* Invoke the driver to write the sector. */ | ||
| 181 | 77251600 | (media_ptr -> fx_media_driver_entry) (media_ptr); | |
| 182 | |||
| 183 | /* Clear the system write flag. */ | ||
| 184 | 77251599 | media_ptr -> fx_media_driver_system_write = FX_FALSE; | |
| 185 | |||
| 186 | /* Check for successful completion. */ | ||
| 187 |
4/4✓ Branch 18 → 19 taken 4 times.
✓ Branch 18 → 20 taken 76999665 times.
✓ Branch 20 → 21 taken 58521 times.
✓ Branch 20 → 22 taken 193409 times.
|
77251599 | if (media_ptr -> fx_media_driver_status) |
| 188 | { | ||
| 189 | |||
| 190 | /* Error writing a cached sector out. Return the | ||
| 191 | error status. */ | ||
| 192 | 58525 | return(media_ptr -> fx_media_driver_status); | |
| 193 | } | ||
| 194 | |||
| 195 | /* Clear the buffer dirty flag since it has been flushed | ||
| 196 | out. */ | ||
| 197 | 77193074 | cache_entry -> fx_cached_sector_buffer_dirty = FX_FALSE; | |
| 198 | |||
| 199 | /* Decrement the number of dirty sectors currently in the cache. */ | ||
| 200 | 77193074 | media_ptr -> fx_media_sector_cache_dirty_count--; | |
| 201 | 77193074 | remaining_dirty--; | |
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | /* Determine if the invalidate option is specified. */ | ||
| 206 |
4/4✓ Branch 21 → 22 taken 3815443 times.
✓ Branch 21 → 24 taken 76993367 times.
✓ Branch 23 → 24 taken 2848133 times.
✓ Branch 23 → 26 taken 15518 times.
|
83672461 | if (invalidate) |
| 207 | { | ||
| 208 | |||
| 209 | /* Invalidate the cache entry. */ | ||
| 210 | 6663576 | cache_entry -> fx_cached_sector_valid = FX_FALSE; | |
| 211 | |||
| 212 | /* Place all ones in the sector number. */ | ||
| 213 | 6663576 | cache_entry -> fx_cached_sector = (~(ULONG64)0); | |
| 214 | |||
| 215 | /* Determine if this sector is still dirty, this could be the case if | ||
| 216 | write protection was turned on. */ | ||
| 217 |
4/4✓ Branch 22 → 23 taken 1020 times.
✓ Branch 22 → 24 taken 3814423 times.
✓ Branch 24 → 25 taken 765 times.
✓ Branch 24 → 26 taken 2847368 times.
|
6663576 | if (cache_entry -> fx_cached_sector_buffer_dirty) |
| 218 | { | ||
| 219 | |||
| 220 | /* Yes, clear the dirty flag. */ | ||
| 221 | 1785 | cache_entry -> fx_cached_sector_buffer_dirty = FX_FALSE; | |
| 222 | |||
| 223 | /* Decrement the number of dirty sectors currently in the cache. */ | ||
| 224 | 1785 | media_ptr -> fx_media_sector_cache_dirty_count--; | |
| 225 | 1785 | remaining_dirty--; | |
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | /* Decrement the number of sectors in the range that have been processed. */ | ||
| 230 | 83672461 | sectors--; | |
| 231 | } | ||
| 232 | |||
| 233 | /* Move to the next entry in the sector cache. */ | ||
| 234 | 1362997979 | cache_entry = cache_entry -> fx_cached_sector_next_used; | |
| 235 | } | ||
| 236 | } | ||
| 237 | else | ||
| 238 | { | ||
| 239 | |||
| 240 | /* Hashed cache is present. Pickup the cache size. */ | ||
| 241 | 11019598 | cache_size = media_ptr -> fx_media_sector_cache_size; | |
| 242 | |||
| 243 | /* Initialize the loop control parameters. */ | ||
| 244 | 11019598 | bit_set = 0; | |
| 245 | 11019598 | valid_bit_map = media_ptr -> fx_media_sector_cache_hashed_sector_valid; | |
| 246 | |||
| 247 | /* Determine how to process the hashed cache based on the number of sectors | ||
| 248 | to process. If the sequential sector range is less than the bit map size, | ||
| 249 | simply use the starting sector to derive the index into the cache. */ | ||
| 250 |
4/4✓ Branch 29 → 30 taken 6560173 times.
✓ Branch 29 → 31 taken 3413553 times.
✓ Branch 31 → 32 taken 44016 times.
✓ Branch 31 → 33 taken 1001856 times.
|
11019598 | if (sectors < 32) |
| 251 | { | ||
| 252 | 6604189 | use_starting_sector = FX_TRUE; | |
| 253 | } | ||
| 254 | else | ||
| 255 | { | ||
| 256 | 4415409 | use_starting_sector = FX_FALSE; | |
| 257 | } | ||
| 258 | |||
| 259 | /* Determine if there is anything valid in the cache. */ | ||
| 260 |
4/4✓ Branch 78 → 33 taken 68618746 times.
✓ Branch 78 → 79 taken 1474927 times.
✓ Branch 82 → 35 taken 23928306 times.
✓ Branch 82 → 83 taken 990953 times.
|
95012932 | while (valid_bit_map) |
| 261 | { | ||
| 262 | |||
| 263 | /* Determine if invalidation is not required and there are no | ||
| 264 | more dirty sectors. */ | ||
| 265 |
8/8✓ Branch 33 → 34 taken 62890232 times.
✓ Branch 33 → 36 taken 5728514 times.
✓ Branch 34 → 35 taken 4183598 times.
✓ Branch 34 → 36 taken 58706634 times.
✓ Branch 35 → 36 taken 233845 times.
✓ Branch 35 → 38 taken 23694461 times.
✓ Branch 36 → 37 taken 12181 times.
✓ Branch 36 → 38 taken 221664 times.
|
92547052 | if ((remaining_dirty == 0) && (invalidate == FX_FALSE)) |
| 266 | { | ||
| 267 | |||
| 268 | /* Yes, nothing left to do. */ | ||
| 269 | 4195779 | break; | |
| 270 | } | ||
| 271 | |||
| 272 | /* Determine if there are any more sectors to process. */ | ||
| 273 |
8/8✓ Branch 36 → 37 taken 64434591 times.
✓ Branch 36 → 79 taken 557 times.
✓ Branch 37 → 38 taken 60122457 times.
✓ Branch 37 → 79 taken 4312134 times.
✓ Branch 38 → 39 taken 23915603 times.
✓ Branch 38 → 83 taken 522 times.
✓ Branch 39 → 40 taken 23873396 times.
✓ Branch 39 → 83 taken 42207 times.
|
88351273 | if ((sectors == 0) || (starting_sector > ending_sector)) |
| 274 | { | ||
| 275 | |||
| 276 | /* No more sectors required to process. */ | ||
| 277 | break; | ||
| 278 | } | ||
| 279 | |||
| 280 | /* Determine how to compute the hash index. */ | ||
| 281 |
4/4✓ Branch 38 → 39 taken 22806504 times.
✓ Branch 38 → 40 taken 37315953 times.
✓ Branch 40 → 41 taken 55427 times.
✓ Branch 40 → 42 taken 23817969 times.
|
83995853 | if (use_starting_sector) |
| 282 | { | ||
| 283 | |||
| 284 | /* Calculate the hash value of this sector using the lower bits. */ | ||
| 285 | 22861931 | index = (ULONG)(starting_sector & media_ptr -> fx_media_sector_cache_hash_mask); | |
| 286 | |||
| 287 | /* Calculate the bit set indicating there is one or more valid sectors at this cache index. */ | ||
| 288 | 22861931 | bit_set = (index % 32); | |
| 289 | |||
| 290 | /* Compute the actual array index by multiplying by the cache depth. */ | ||
| 291 | 22861931 | index = (bit_set * FX_SECTOR_CACHE_DEPTH); | |
| 292 | } | ||
| 293 | else | ||
| 294 | { | ||
| 295 | |||
| 296 | /* Walk the bit map to find the next valid entry. */ | ||
| 297 | |||
| 298 | /* Find the next set bit. */ | ||
| 299 |
4/4✓ Branch 42 → 41 taken 9431387 times.
✓ Branch 42 → 43 taken 37315953 times.
✓ Branch 44 → 43 taken 7285978 times.
✓ Branch 44 → 45 taken 23817969 times.
|
77851287 | while ((valid_bit_map & 1) == 0) |
| 300 | { | ||
| 301 | |||
| 302 | /* Otherwise, shift down the bit in the bit map. */ | ||
| 303 | 16717365 | valid_bit_map = valid_bit_map >> 1; | |
| 304 | |||
| 305 | /* Increment the set bit marker. */ | ||
| 306 | 16717365 | bit_set++; | |
| 307 | } | ||
| 308 | |||
| 309 | /* Compute the first actual index into the hashed cache. */ | ||
| 310 | 61133922 | index = (bit_set * FX_SECTOR_CACHE_DEPTH); | |
| 311 | } | ||
| 312 | |||
| 313 | /* At this point, bit_set represents the next group of hashed sectors that could | ||
| 314 | have valid cache entries and index represents the index into the sector cache | ||
| 315 | of that sector group. */ | ||
| 316 | |||
| 317 | /* Clear the remaining valid sectors for this entry in the bit map. */ | ||
| 318 | 83995853 | remaining_valid = 0; | |
| 319 | |||
| 320 | /* Loop to check the corresponding hash entries. */ | ||
| 321 | do | ||
| 322 | { | ||
| 323 | |||
| 324 | /* Setup pointer to the cache entry. */ | ||
| 325 | 138600149 | cache_entry = &(media_ptr -> fx_media_sector_cache[index]); | |
| 326 | |||
| 327 | /* Loop to examine the full depth of the hashed cache. */ | ||
| 328 |
4/4✓ Branch 68 → 46 taken 362474396 times.
✓ Branch 68 → 69 taken 90382473 times.
✓ Branch 72 → 48 taken 188996093 times.
✓ Branch 72 → 73 taken 47238854 times.
|
689091816 | for (i = 0; i < 4; i++) |
| 329 | { | ||
| 330 | |||
| 331 | /* Determine if this cached sector is within the specified range and is valid. */ | ||
| 332 |
4/4✓ Branch 46 → 47 taken 62588288 times.
✓ Branch 46 → 59 taken 299886108 times.
✓ Branch 48 → 49 taken 26754730 times.
✓ Branch 48 → 63 taken 162241363 times.
|
551470489 | if ((cache_entry -> fx_cached_sector_valid) && |
| 333 |
4/4✓ Branch 47 → 48 taken 19453014 times.
✓ Branch 47 → 59 taken 43135274 times.
✓ Branch 49 → 50 taken 477596 times.
✓ Branch 49 → 63 taken 26277134 times.
|
89343018 | (cache_entry -> fx_cached_sector >= starting_sector) && |
| 334 |
4/4✓ Branch 48 → 49 taken 18844826 times.
✓ Branch 48 → 59 taken 608188 times.
✓ Branch 50 → 51 taken 449041 times.
✓ Branch 50 → 63 taken 28555 times.
|
19930610 | (cache_entry -> fx_cached_sector <= ending_sector)) |
| 335 | { | ||
| 336 | |||
| 337 | /* Determine if the requested sector has been written to. */ | ||
| 338 |
4/4✓ Branch 49 → 50 taken 967816 times.
✓ Branch 49 → 55 taken 17877010 times.
✓ Branch 51 → 52 taken 89117 times.
✓ Branch 51 → 59 taken 359924 times.
|
19293867 | if (cache_entry -> fx_cached_sector_buffer_dirty) |
| 339 | { | ||
| 340 | |||
| 341 | |||
| 342 | /* Yes, write the cached sector out to the media. */ | ||
| 343 | |||
| 344 | /* Check for write protect at the media level (set by driver). */ | ||
| 345 |
4/4✓ Branch 50 → 51 taken 967304 times.
✓ Branch 50 → 55 taken 512 times.
✓ Branch 52 → 53 taken 88349 times.
✓ Branch 52 → 59 taken 768 times.
|
1056933 | if (media_ptr -> fx_media_driver_write_protect == FX_FALSE) |
| 346 | { | ||
| 347 | |||
| 348 | #ifndef FX_MEDIA_STATISTICS_DISABLE | ||
| 349 | |||
| 350 | /* Increment the number of driver write sector(s) requests. */ | ||
| 351 | 1055653 | media_ptr -> fx_media_driver_write_requests++; | |
| 352 | #endif | ||
| 353 | |||
| 354 | /* Build Write request to the driver. */ | ||
| 355 | 1055653 | media_ptr -> fx_media_driver_request = FX_DRIVER_WRITE; | |
| 356 | 1055653 | media_ptr -> fx_media_driver_status = FX_IO_ERROR; | |
| 357 | 1055653 | media_ptr -> fx_media_driver_buffer = cache_entry -> fx_cached_sector_memory_buffer; | |
| 358 | #ifdef FX_DRIVER_USE_64BIT_LBA | ||
| 359 | media_ptr -> fx_media_driver_logical_sector = cache_entry -> fx_cached_sector; | ||
| 360 | #else | ||
| 361 | 1055653 | media_ptr -> fx_media_driver_logical_sector = (ULONG)cache_entry -> fx_cached_sector; | |
| 362 | #endif | ||
| 363 | 1055653 | media_ptr -> fx_media_driver_sectors = 1; | |
| 364 | 1055653 | media_ptr -> fx_media_driver_sector_type = cache_entry -> fx_cached_sector_type; | |
| 365 | |||
| 366 | /* Sectors other than FX_DATA_SECTOR will never be dirty when FX_FAULT_TOLERANT is defined. */ | ||
| 367 | #ifndef FX_FAULT_TOLERANT | ||
| 368 | /* Determine if the system write flag needs to be set. */ | ||
| 369 |
2/2✓ Branch 53 → 54 taken 42147 times.
✓ Branch 53 → 55 taken 46202 times.
|
88349 | if (cache_entry -> fx_cached_sector_type != FX_DATA_SECTOR) |
| 370 | { | ||
| 371 | |||
| 372 | /* Yes, a system sector write is present so set the flag. The driver | ||
| 373 | can use this flag to make extra safeguards in writing the sector | ||
| 374 | out, yielding more fault tolerance. */ | ||
| 375 | 42147 | media_ptr -> fx_media_driver_system_write = FX_TRUE; | |
| 376 | } | ||
| 377 | #endif /* FX_FAULT_TOLERANT */ | ||
| 378 | |||
| 379 | /* If trace is enabled, insert this event into the trace buffer. */ | ||
| 380 | FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_WRITE, media_ptr, cache_entry -> fx_cached_sector, 1, cache_entry -> fx_cached_sector_memory_buffer, FX_TRACE_INTERNAL_EVENTS, 0, 0) | ||
| 381 | |||
| 382 | /* Invoke the driver to write the sector. */ | ||
| 383 | 1055653 | (media_ptr -> fx_media_driver_entry) (media_ptr); | |
| 384 | |||
| 385 | /* Clear the system write flag. */ | ||
| 386 | 1055653 | media_ptr -> fx_media_driver_system_write = FX_FALSE; | |
| 387 | |||
| 388 | /* Check for successful completion. */ | ||
| 389 |
4/4✓ Branch 52 → 53 taken 2510 times.
✓ Branch 52 → 54 taken 964794 times.
✓ Branch 56 → 57 taken 9 times.
✓ Branch 56 → 58 taken 88340 times.
|
1055653 | if (media_ptr -> fx_media_driver_status) |
| 390 | { | ||
| 391 | |||
| 392 | /* Error writing a cached sector out. Return the | ||
| 393 | error status. */ | ||
| 394 | 2519 | return(media_ptr -> fx_media_driver_status); | |
| 395 | } | ||
| 396 | |||
| 397 | /* Clear the buffer dirty flag since it has been flushed | ||
| 398 | out. */ | ||
| 399 | 1053134 | cache_entry -> fx_cached_sector_buffer_dirty = FX_FALSE; | |
| 400 | |||
| 401 | /* Decrement the number of dirty sectors currently in the cache. */ | ||
| 402 | 1053134 | media_ptr -> fx_media_sector_cache_dirty_count--; | |
| 403 | 1053134 | remaining_dirty--; | |
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | /* Determine if the invalidate option is specified. */ | ||
| 408 |
4/4✓ Branch 55 → 56 taken 243251 times.
✓ Branch 55 → 58 taken 18599065 times.
✓ Branch 59 → 60 taken 232197 times.
✓ Branch 59 → 62 taken 216835 times.
|
19291348 | if (invalidate) |
| 409 | { | ||
| 410 | |||
| 411 | /* Invalidate the cache entry. */ | ||
| 412 | 475448 | cache_entry -> fx_cached_sector_valid = FX_FALSE; | |
| 413 | |||
| 414 | /* Place all ones in the sector number. */ | ||
| 415 | 475448 | cache_entry -> fx_cached_sector = (~(ULONG64)0); | |
| 416 | |||
| 417 | /* Determine if this sector is still dirty, this could be the case if | ||
| 418 | write protection was turned on. */ | ||
| 419 |
4/4✓ Branch 56 → 57 taken 512 times.
✓ Branch 56 → 58 taken 242739 times.
✓ Branch 60 → 61 taken 768 times.
✓ Branch 60 → 62 taken 231429 times.
|
475448 | if (cache_entry -> fx_cached_sector_buffer_dirty) |
| 420 | { | ||
| 421 | |||
| 422 | /* Yes, clear the dirty flag. */ | ||
| 423 | 1280 | cache_entry -> fx_cached_sector_buffer_dirty = FX_FALSE; | |
| 424 | |||
| 425 | /* Decrement the number of dirty sectors currently in the cache. */ | ||
| 426 | 1280 | media_ptr -> fx_media_sector_cache_dirty_count--; | |
| 427 | 1280 | remaining_dirty--; | |
| 428 | } | ||
| 429 | } | ||
| 430 | |||
| 431 | /* Decrement the number of sectors in the range that have been processed. */ | ||
| 432 | 19291348 | sectors--; | |
| 433 | } | ||
| 434 | else | ||
| 435 | { | ||
| 436 | |||
| 437 | /* Determine if the sector is valid. */ | ||
| 438 |
4/4✓ Branch 59 → 60 taken 43743462 times.
✓ Branch 59 → 61 taken 299886108 times.
✓ Branch 63 → 64 taken 26305689 times.
✓ Branch 63 → 65 taken 162241363 times.
|
532176622 | if (cache_entry -> fx_cached_sector_valid) |
| 439 | { | ||
| 440 | |||
| 441 | /* Increment the number of still remaining but out of range sectors. */ | ||
| 442 | 70049151 | remaining_valid++; | |
| 443 | } | ||
| 444 | } | ||
| 445 | |||
| 446 | /* Determine if invalidation is not required and there are no | ||
| 447 | more dirty sectors. */ | ||
| 448 |
8/8✓ Branch 61 → 62 taken 343320752 times.
✓ Branch 61 → 64 taken 19151134 times.
✓ Branch 62 → 63 taken 939228 times.
✓ Branch 62 → 64 taken 342381524 times.
✓ Branch 65 → 66 taken 913851 times.
✓ Branch 65 → 68 taken 188082233 times.
✓ Branch 66 → 67 taken 36450 times.
✓ Branch 66 → 68 taken 877401 times.
|
551467970 | if ((remaining_dirty == 0) && (invalidate == FX_FALSE)) |
| 449 | { | ||
| 450 | |||
| 451 | /* Yes, nothing left to do. */ | ||
| 452 | 975678 | break; | |
| 453 | } | ||
| 454 | |||
| 455 | /* Determine if there are any more sectors to process. */ | ||
| 456 |
8/8✓ Branch 64 → 65 taken 1963 times.
✓ Branch 64 → 67 taken 361530695 times.
✓ Branch 65 → 66 taken 352 times.
✓ Branch 65 → 67 taken 1611 times.
✓ Branch 68 → 69 taken 1848 times.
✓ Branch 68 → 71 taken 188957786 times.
✓ Branch 69 → 70 taken 273 times.
✓ Branch 69 → 71 taken 1575 times.
|
550492292 | if ((sectors == 0) && (invalidate == FX_FALSE)) |
| 457 | { | ||
| 458 | |||
| 459 | /* No more sectors required to process. */ | ||
| 460 | 625 | break; | |
| 461 | } | ||
| 462 | |||
| 463 | /* Move to the next cache entry. */ | ||
| 464 | 550491667 | cache_entry++; | |
| 465 | } | ||
| 466 | |||
| 467 | /* Move the index to the next position since the bit map can only represent 32 | ||
| 468 | cache entries. */ | ||
| 469 | 138597630 | index = index + (32 * FX_SECTOR_CACHE_DEPTH); | |
| 470 |
4/4✓ Branch 69 → 70 taken 31202106 times.
✓ Branch 69 → 71 taken 60119947 times.
✓ Branch 73 → 74 taken 23402190 times.
✓ Branch 73 → 75 taken 23873387 times.
|
138597630 | } while (index < cache_size); |
| 471 | |||
| 472 | /* Determine if invalidation was required and there are no more valid sectors | ||
| 473 | associated with this bit position. */ | ||
| 474 |
8/8✓ Branch 71 → 72 taken 54397493 times.
✓ Branch 71 → 74 taken 5722454 times.
✓ Branch 72 → 73 taken 15742683 times.
✓ Branch 72 → 74 taken 38654810 times.
✓ Branch 75 → 76 taken 23667332 times.
✓ Branch 75 → 78 taken 206055 times.
✓ Branch 76 → 77 taken 217824 times.
✓ Branch 76 → 78 taken 23449508 times.
|
83993334 | if ((invalidate) && (remaining_valid == 0)) |
| 475 | { | ||
| 476 | |||
| 477 | /* Clear this bit position. */ | ||
| 478 | 15960507 | media_ptr -> fx_media_sector_cache_hashed_sector_valid &= ~(((ULONG)1) << bit_set); | |
| 479 | } | ||
| 480 | |||
| 481 | /* Determine if the starting sector is being used for examination of the hash. */ | ||
| 482 |
4/4✓ Branch 74 → 75 taken 22806504 times.
✓ Branch 74 → 76 taken 37313443 times.
✓ Branch 78 → 79 taken 55427 times.
✓ Branch 78 → 80 taken 23817960 times.
|
83993334 | if (use_starting_sector) |
| 483 | { | ||
| 484 | |||
| 485 | /* Move to the next sector. */ | ||
| 486 | 22861931 | starting_sector++; | |
| 487 | } | ||
| 488 | else | ||
| 489 | { | ||
| 490 | |||
| 491 | /* Move to next bit in the map. */ | ||
| 492 | 61131403 | valid_bit_map = valid_bit_map >> 1; | |
| 493 | |||
| 494 | /* Increment the set bit marker. */ | ||
| 495 | 61131403 | bit_set++; | |
| 496 | } | ||
| 497 | } | ||
| 498 | } | ||
| 499 | #else | ||
| 500 | FX_PARAMETER_NOT_USED(media_ptr); | ||
| 501 | FX_PARAMETER_NOT_USED(starting_sector); | ||
| 502 | FX_PARAMETER_NOT_USED(sectors); | ||
| 503 | FX_PARAMETER_NOT_USED(invalidate); | ||
| 504 | #endif /* FX_DISABLE_CACHE */ | ||
| 505 | |||
| 506 | /* If we get here, return successful status to the caller. */ | ||
| 507 | 1202634244 | return(FX_SUCCESS); | |
| 508 | } | ||
| 509 | |||
| 510 |