GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_media_cache_invalidate.c Lines: 15 15 100.0 %
Date: 2026-03-06 18:49:02 Branches: 6 6 100.0 %

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
3052
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
3052
    media_ptr -> fx_media_flushes++;
79
#endif
80
81
    /* Check the media to make sure it is open.  */
82
3052
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
83
    {
84
85
        /* Return the media not opened error.  */
86
1
        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
3051
    FX_PROTECT
94
    /* Flush the cached individual FAT entries */
95
3051
    _fx_utility_FAT_flush(media_ptr);
96
97
    /* Flush changed sector(s) in the primary FAT to secondary FATs.  */
98
3051
    _fx_utility_FAT_map_flush(media_ptr);
99
100
    /* Clear the FAT cache entry array.  */
101
198315
    for (i = 0; i < FX_MAX_FAT_CACHE; i++)
102
    {
103
104
        /* Clear entry in the FAT cache.  */
105
195264
        media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_cluster =   0;
106
195264
        media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_value   =   0;
107
    }
108
109
    /* Clear the secondary FAT update map.  */
110
6102
    for (i = 0; i < FX_FAT_MAP_SIZE; i++)
111
    {
112
113
        /* Clear bit map entry for secondary FAT update.  */
114
3051
        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
3051
    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
3051
    FX_UNPROTECT
122
123
    /* If we get here, return successful status to the caller.  */
124
3051
    return(status);
125
}
126