1 |
|
|
/**************************************************************************/ |
2 |
|
|
/* */ |
3 |
|
|
/* Copyright (c) Microsoft Corporation. All rights reserved. */ |
4 |
|
|
/* */ |
5 |
|
|
/* This software is licensed under the Microsoft Software License */ |
6 |
|
|
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ |
7 |
|
|
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ |
8 |
|
|
/* and in the root directory of this software. */ |
9 |
|
|
/* */ |
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 |
|
|
/* RELEASE HISTORY */ |
68 |
|
|
/* */ |
69 |
|
|
/* DATE NAME DESCRIPTION */ |
70 |
|
|
/* */ |
71 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
72 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
73 |
|
|
/* resulting in version 6.1 */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
3052 |
UINT _fx_media_cache_invalidate(FX_MEDIA *media_ptr) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
UINT status; |
80 |
|
|
UINT i; |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
#ifndef FX_MEDIA_STATISTICS_DISABLE |
84 |
|
|
|
85 |
|
|
/* Increment the number of times this service has been called. */ |
86 |
|
3052 |
media_ptr -> fx_media_flushes++; |
87 |
|
|
#endif |
88 |
|
|
|
89 |
|
|
/* Check the media to make sure it is open. */ |
90 |
✓✓ |
3052 |
if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
91 |
|
|
{ |
92 |
|
|
|
93 |
|
|
/* Return the media not opened error. */ |
94 |
|
1 |
return(FX_MEDIA_NOT_OPEN); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
98 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_CACHE_INVALIDATE, media_ptr, 0, 0, 0, FX_TRACE_MEDIA_EVENTS, 0, 0) |
99 |
|
|
|
100 |
|
|
/* Protect against other threads accessing the media. */ |
101 |
|
3051 |
FX_PROTECT |
102 |
|
|
/* Flush the cached individual FAT entries */ |
103 |
|
3051 |
_fx_utility_FAT_flush(media_ptr); |
104 |
|
|
|
105 |
|
|
/* Flush changed sector(s) in the primary FAT to secondary FATs. */ |
106 |
|
3051 |
_fx_utility_FAT_map_flush(media_ptr); |
107 |
|
|
|
108 |
|
|
/* Clear the FAT cache entry array. */ |
109 |
✓✓ |
198315 |
for (i = 0; i < FX_MAX_FAT_CACHE; i++) |
110 |
|
|
{ |
111 |
|
|
|
112 |
|
|
/* Clear entry in the FAT cache. */ |
113 |
|
195264 |
media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0; |
114 |
|
195264 |
media_ptr -> fx_media_fat_cache[i].fx_fat_cache_entry_value = 0; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* Clear the secondary FAT update map. */ |
118 |
✓✓ |
6102 |
for (i = 0; i < FX_FAT_MAP_SIZE; i++) |
119 |
|
|
{ |
120 |
|
|
|
121 |
|
|
/* Clear bit map entry for secondary FAT update. */ |
122 |
|
3051 |
media_ptr -> fx_media_fat_secondary_update_map[i] = 0; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
/* Call the logical sector flush to invalidate the logical sector cache. */ |
126 |
|
3051 |
status = _fx_utility_logical_sector_flush(media_ptr, ((ULONG64) 1), (ULONG64) (media_ptr -> fx_media_total_sectors), FX_TRUE); |
127 |
|
|
|
128 |
|
|
/* Release media protection. */ |
129 |
|
3051 |
FX_UNPROTECT |
130 |
|
|
|
131 |
|
|
/* If we get here, return successful status to the caller. */ |
132 |
|
3051 |
return(status); |
133 |
|
|
} |
134 |
|
|
|