GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 15 / 0 / 15
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 10 / 0 / 10

fx_media_cache_invalidate.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 /** Media */
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_media.h"
30 #include "fx_utility.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _fx_media_cache_invalidate PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* William E. Lamie, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function examines the logical cache, flushing written sectors */
46 /* out to the media and invalidating all sectors in the logical cache. */
47 /* */
48 /* INPUT */
49 /* */
50 /* media_ptr Media control block pointer */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* return status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _fx_utility_FAT_flush Flush cached FAT entries */
59 /* _fx_utility_FAT_map_flush Flush primary FAT changes to */
60 /* secondary FAT(s) */
61 /* _fx_utility_logical_sector_flush Flush logical sector cache */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /**************************************************************************/
68 27594 UINT _fx_media_cache_invalidate(FX_MEDIA *media_ptr)
69 {
70
71 UINT status;
72 UINT i;
73
74
75 #ifndef FX_MEDIA_STATISTICS_DISABLE
76
77 /* Increment the number of times this service has been called. */
78 27594 media_ptr -> fx_media_flushes++;
79 #endif
80
81 /* Check the media to make sure it is open. */
82
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 27585 times.
27594 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
83 {
84
85 /* Return the media not opened error. */
86 9 return(FX_MEDIA_NOT_OPEN);
87 }
88
89 /* If trace is enabled, insert this event into the trace buffer. */
90 FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_CACHE_INVALIDATE, media_ptr, 0, 0, 0, FX_TRACE_MEDIA_EVENTS, 0, 0)
91
92 /* Protect against other threads accessing the media. */
93 15318 FX_PROTECT
94 /* Flush the cached individual FAT entries */
95 27585 _fx_utility_FAT_flush(media_ptr);
96
97 /* Flush changed sector(s) in the primary FAT to secondary FATs. */
98 27585 _fx_utility_FAT_map_flush(media_ptr);
99
100 /* Clear the FAT cache entry array. */
101
4/4
✓ Branch 8 → 7 taken 785088 times.
✓ Branch 8 → 9 taken 12267 times.
✓ Branch 9 → 8 taken 980352 times.
✓ Branch 9 → 10 taken 15318 times.
1793025 for (i = 0; i < FX_MAX_FAT_CACHE; i++)
102 {
103
104 /* Clear entry in the FAT cache. */
105 1765440 media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
106 1765440 media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
107 }
108
109 /* Clear the secondary FAT update map. */
110
4/4
✓ Branch 11 → 10 taken 12267 times.
✓ Branch 11 → 12 taken 12267 times.
✓ Branch 12 → 11 taken 15318 times.
✓ Branch 12 → 13 taken 15318 times.
55170 for (i = 0; i < FX_FAT_MAP_SIZE; i++)
111 {
112
113 /* Clear bit map entry for secondary FAT update. */
114 27585 media_ptr -> fx_media_fat_secondary_update_map[i] = 0;
115 }
116
117 /* Call the logical sector flush to invalidate the logical sector cache. */
118 27585 status = _fx_utility_logical_sector_flush(media_ptr, ((ULONG64) 1), (ULONG64) (media_ptr -> fx_media_total_sectors), FX_TRUE);
119
120 /* Release media protection. */
121 15318 FX_UNPROTECT
122
123 /* If we get here, return successful status to the caller. */
124 27585 return(status);
125 }
126
127