Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_utility.h"
...
...
_fx_utility_logical_sector_cache_entry_read(FX_MEDIA *, ULONG64, FX_CACHED_SECTOR **)
Files
loading...
CodeScopeSTM32 Libraries and Samplesfilexcommon/src/fx_utility_logical_sector_cache_entry_read.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** FileX Component */ /** */ /** Utility */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE /* Include necessary system files. */ #include "fx_api.h" #include "fx_system.h" #include "fx_utility.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_utility_logical_sector_cache_entry_read PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function handles logical sector cache read requests for the */ /* logical sector read function. If the function finds the requested */ /* sector in the cache, it setup the appropriate pointers and */ /* returns a FX_NULL. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* logical_sector Logical sector number */ /* previous_cache_entry Pointer to previous entry in */ /* non-hashed cache */ /* */ /* OUTPUT */ /* */ /* FX_CACHED_SECTOR * Cache entry to setup */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _fx_utility_logical_sector_read Logical sector read function */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 William E. Lamie Modified comment(s), and */ /* added conditional to */ /* disable cache, */ /* resulting in version 6.1 */ /* 01-31-2022 William E. Lamie Modified comment(s), fixed */ /* errors without cache, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ FX_CACHED_SECTOR *_fx_utility_logical_sector_cache_entry_read(FX_MEDIA *media_ptr, ULONG64 logical_sector, FX_CACHED_SECTOR **previous_cache_entry) { #ifndef FX_DISABLE_CACHE FX_CACHED_SECTOR *cache_entry; FX_CACHED_SECTOR temp_storage; ULONG cache_size; ULONG index; /* Determine if the logical sector cache access should use the hash function. */ if (media_ptr -> fx_media_sector_cache_hashed) { /* Calculate the area of the cache for this logical sector. */ /* First compute the hashed value of this index by simply using the lower bits of the sector number. *//* ... */ index = (ULONG)(logical_sector & media_ptr -> fx_media_sector_cache_hash_mask); /* Set the bit indicating there is one or more valid sectors at this cache index. */ media_ptr -> fx_media_sector_cache_hashed_sector_valid |= ((ULONG)1) << (index % 32); /* Compute the actual array index by multiplying by the cache depth. */ index = index * FX_SECTOR_CACHE_DEPTH; /* Build a pointer to the cache entry. */ cache_entry = &(media_ptr -> fx_media_sector_cache[index]); /* Determine if the logical sector is in the cache - assuming the depth of the sector cache is 4 entries. *//* ... */ if ((cache_entry -> fx_cached_sector_valid) && (cache_entry -> fx_cached_sector == logical_sector)) { /* Yes, we found a match. Simply setup the pointer to this buffer and return. *//* ... */ media_ptr -> fx_media_memory_buffer = cache_entry -> fx_cached_sector_memory_buffer; #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of logical sectors cache read hits. */ media_ptr -> fx_media_logical_sector_cache_read_hits++;/* ... */ #endif /* Success, return to caller immediately! */ return(FX_NULL); }if ((cache_entry -> fx_cached_sector_valid) && (cache_entry -> fx_cached_sector == logical_sector)) { ... } else if (((cache_entry + 1) -> fx_cached_sector_valid) && ((cache_entry + 1) -> fx_cached_sector == logical_sector)) { /* Yes, we found a match. Simply setup the pointer to this buffer and return. *//* ... */ media_ptr -> fx_media_memory_buffer = (cache_entry + 1) -> fx_cached_sector_memory_buffer; #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of logical sectors cache read hits. */ media_ptr -> fx_media_logical_sector_cache_read_hits++;/* ... */ #endif /* Swap the first and second cache entries to keep the most recently used at the top. *//* ... */ temp_storage.fx_cached_sector_memory_buffer = (cache_entry) -> fx_cached_sector_memory_buffer; temp_storage.fx_cached_sector = (cache_entry) -> fx_cached_sector; temp_storage.fx_cached_sector_buffer_dirty = (cache_entry) -> fx_cached_sector_buffer_dirty; temp_storage.fx_cached_sector_valid = (cache_entry) -> fx_cached_sector_valid; temp_storage.fx_cached_sector_type = (cache_entry) -> fx_cached_sector_type; (cache_entry) -> fx_cached_sector_memory_buffer = (cache_entry + 1) -> fx_cached_sector_memory_buffer; (cache_entry) -> fx_cached_sector = (cache_entry + 1) -> fx_cached_sector; (cache_entry) -> fx_cached_sector_buffer_dirty = (cache_entry + 1) -> fx_cached_sector_buffer_dirty; (cache_entry) -> fx_cached_sector_valid = (cache_entry + 1) -> fx_cached_sector_valid; (cache_entry) -> fx_cached_sector_type = (cache_entry + 1) -> fx_cached_sector_type; (cache_entry + 1) -> fx_cached_sector_memory_buffer = temp_storage.fx_cached_sector_memory_buffer; (cache_entry + 1) -> fx_cached_sector = temp_storage.fx_cached_sector; (cache_entry + 1) -> fx_cached_sector_buffer_dirty = temp_storage.fx_cached_sector_buffer_dirty; (cache_entry + 1) -> fx_cached_sector_valid = temp_storage.fx_cached_sector_valid; (cache_entry + 1) -> fx_cached_sector_type = temp_storage.fx_cached_sector_type; /* Success, return to caller immediately! */ return(FX_NULL); }else if (((cache_entry + 1) -> fx_cached_sector_valid) && ((cache_entry + 1) -> fx_cached_sector == logical_sector)) { ... } else if (((cache_entry + 2) -> fx_cached_sector_valid) && ((cache_entry + 2) -> fx_cached_sector == logical_sector)) { /* Yes, we found a match. Simply setup the pointer to this buffer and return. *//* ... */ media_ptr -> fx_media_memory_buffer = (cache_entry + 2) -> fx_cached_sector_memory_buffer; #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of logical sectors cache read hits. */ media_ptr -> fx_media_logical_sector_cache_read_hits++;/* ... */ #endif /* Move the third entry to the top and the first two entries down. */ temp_storage.fx_cached_sector_memory_buffer = (cache_entry) -> fx_cached_sector_memory_buffer; temp_storage.fx_cached_sector = (cache_entry) -> fx_cached_sector; temp_storage.fx_cached_sector_buffer_dirty = (cache_entry) -> fx_cached_sector_buffer_dirty; temp_storage.fx_cached_sector_valid = (cache_entry) -> fx_cached_sector_valid; temp_storage.fx_cached_sector_type = (cache_entry) -> fx_cached_sector_type; (cache_entry) -> fx_cached_sector_memory_buffer = (cache_entry + 2) -> fx_cached_sector_memory_buffer; (cache_entry) -> fx_cached_sector = (cache_entry + 2) -> fx_cached_sector; (cache_entry) -> fx_cached_sector_buffer_dirty = (cache_entry + 2) -> fx_cached_sector_buffer_dirty; (cache_entry) -> fx_cached_sector_valid = (cache_entry + 2) -> fx_cached_sector_valid; (cache_entry) -> fx_cached_sector_type = (cache_entry + 2) -> fx_cached_sector_type; (cache_entry + 2) -> fx_cached_sector_memory_buffer = (cache_entry + 1) -> fx_cached_sector_memory_buffer; (cache_entry + 2) -> fx_cached_sector = (cache_entry + 1) -> fx_cached_sector; (cache_entry + 2) -> fx_cached_sector_buffer_dirty = (cache_entry + 1) -> fx_cached_sector_buffer_dirty; (cache_entry + 2) -> fx_cached_sector_valid = (cache_entry + 1) -> fx_cached_sector_valid; (cache_entry + 2) -> fx_cached_sector_type = (cache_entry + 1) -> fx_cached_sector_type; (cache_entry + 1) -> fx_cached_sector_memory_buffer = temp_storage.fx_cached_sector_memory_buffer; (cache_entry + 1) -> fx_cached_sector = temp_storage.fx_cached_sector; (cache_entry + 1) -> fx_cached_sector_buffer_dirty = temp_storage.fx_cached_sector_buffer_dirty; (cache_entry + 1) -> fx_cached_sector_valid = temp_storage.fx_cached_sector_valid; (cache_entry + 1) -> fx_cached_sector_type = temp_storage.fx_cached_sector_type; /* Success, return to caller immediately! */ return(FX_NULL); }else if (((cache_entry + 2) -> fx_cached_sector_valid) && ((cache_entry + 2) -> fx_cached_sector == logical_sector)) { ... } else if (((cache_entry + 3) -> fx_cached_sector_valid) && ((cache_entry + 3) -> fx_cached_sector == logical_sector)) { /* Yes, we found a match. Simply setup the pointer to this buffer and return. *//* ... */ media_ptr -> fx_media_memory_buffer = (cache_entry + 3) -> fx_cached_sector_memory_buffer; #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of logical sectors cache read hits. */ media_ptr -> fx_media_logical_sector_cache_read_hits++;/* ... */ #endif /* Move the last entry to the top and the first three entries down. */ temp_storage.fx_cached_sector_memory_buffer = (cache_entry) -> fx_cached_sector_memory_buffer; temp_storage.fx_cached_sector = (cache_entry) -> fx_cached_sector; temp_storage.fx_cached_sector_buffer_dirty = (cache_entry) -> fx_cached_sector_buffer_dirty; temp_storage.fx_cached_sector_valid = (cache_entry) -> fx_cached_sector_valid; temp_storage.fx_cached_sector_type = (cache_entry) -> fx_cached_sector_type; (cache_entry) -> fx_cached_sector_memory_buffer = (cache_entry + 3) -> fx_cached_sector_memory_buffer; (cache_entry) -> fx_cached_sector = (cache_entry + 3) -> fx_cached_sector; (cache_entry) -> fx_cached_sector_buffer_dirty = (cache_entry + 3) -> fx_cached_sector_buffer_dirty; (cache_entry) -> fx_cached_sector_valid = (cache_entry + 3) -> fx_cached_sector_valid; (cache_entry) -> fx_cached_sector_type = (cache_entry + 3) -> fx_cached_sector_type; (cache_entry + 3) -> fx_cached_sector_memory_buffer = (cache_entry + 2) -> fx_cached_sector_memory_buffer; (cache_entry + 3) -> fx_cached_sector = (cache_entry + 2) -> fx_cached_sector; (cache_entry + 3) -> fx_cached_sector_buffer_dirty = (cache_entry + 2) -> fx_cached_sector_buffer_dirty; (cache_entry + 3) -> fx_cached_sector_valid = (cache_entry + 2) -> fx_cached_sector_valid; (cache_entry + 3) -> fx_cached_sector_type = (cache_entry + 2) -> fx_cached_sector_type; (cache_entry + 2) -> fx_cached_sector_memory_buffer = (cache_entry + 1) -> fx_cached_sector_memory_buffer; (cache_entry + 2) -> fx_cached_sector = (cache_entry + 1) -> fx_cached_sector; (cache_entry + 2) -> fx_cached_sector_buffer_dirty = (cache_entry + 1) -> fx_cached_sector_buffer_dirty; (cache_entry + 2) -> fx_cached_sector_valid = (cache_entry + 1) -> fx_cached_sector_valid; (cache_entry + 2) -> fx_cached_sector_type = (cache_entry + 1) -> fx_cached_sector_type; (cache_entry + 1) -> fx_cached_sector_memory_buffer = temp_storage.fx_cached_sector_memory_buffer; (cache_entry + 1) -> fx_cached_sector = temp_storage.fx_cached_sector; (cache_entry + 1) -> fx_cached_sector_buffer_dirty = temp_storage.fx_cached_sector_buffer_dirty; (cache_entry + 1) -> fx_cached_sector_valid = temp_storage.fx_cached_sector_valid; (cache_entry + 1) -> fx_cached_sector_type = temp_storage.fx_cached_sector_type; /* Success, return to caller immediately! */ return(FX_NULL); }else if (((cache_entry + 3) -> fx_cached_sector_valid) && ((cache_entry + 3) -> fx_cached_sector == logical_sector)) { ... } /* At this point we have a cache miss. We need to move all of the sectors down one slot, swapping the 4th entry with the first. *//* ... */ temp_storage.fx_cached_sector_memory_buffer = (cache_entry + 3) -> fx_cached_sector_memory_buffer; temp_storage.fx_cached_sector = (cache_entry + 3) -> fx_cached_sector; temp_storage.fx_cached_sector_buffer_dirty = (cache_entry + 3) -> fx_cached_sector_buffer_dirty; temp_storage.fx_cached_sector_valid = (cache_entry + 3) -> fx_cached_sector_valid; temp_storage.fx_cached_sector_type = (cache_entry + 3) -> fx_cached_sector_type; (cache_entry + 3) -> fx_cached_sector_memory_buffer = (cache_entry + 2) -> fx_cached_sector_memory_buffer; (cache_entry + 3) -> fx_cached_sector = (cache_entry + 2) -> fx_cached_sector; (cache_entry + 3) -> fx_cached_sector_buffer_dirty = (cache_entry + 2) -> fx_cached_sector_buffer_dirty; (cache_entry + 3) -> fx_cached_sector_valid = (cache_entry + 2) -> fx_cached_sector_valid; (cache_entry + 3) -> fx_cached_sector_type = (cache_entry + 2) -> fx_cached_sector_type; (cache_entry + 2) -> fx_cached_sector_memory_buffer = (cache_entry + 1) -> fx_cached_sector_memory_buffer; (cache_entry + 2) -> fx_cached_sector = (cache_entry + 1) -> fx_cached_sector; (cache_entry + 2) -> fx_cached_sector_buffer_dirty = (cache_entry + 1) -> fx_cached_sector_buffer_dirty; (cache_entry + 2) -> fx_cached_sector_valid = (cache_entry + 1) -> fx_cached_sector_valid; (cache_entry + 2) -> fx_cached_sector_type = (cache_entry + 1) -> fx_cached_sector_type; (cache_entry + 1) -> fx_cached_sector_memory_buffer = (cache_entry) -> fx_cached_sector_memory_buffer; (cache_entry + 1) -> fx_cached_sector = (cache_entry) -> fx_cached_sector; (cache_entry + 1) -> fx_cached_sector_buffer_dirty = (cache_entry) -> fx_cached_sector_buffer_dirty; (cache_entry + 1) -> fx_cached_sector_valid = (cache_entry) -> fx_cached_sector_valid; (cache_entry + 1) -> fx_cached_sector_type = (cache_entry) -> fx_cached_sector_type; (cache_entry) -> fx_cached_sector_memory_buffer = temp_storage.fx_cached_sector_memory_buffer; (cache_entry) -> fx_cached_sector = temp_storage.fx_cached_sector; (cache_entry) -> fx_cached_sector_buffer_dirty = temp_storage.fx_cached_sector_buffer_dirty; (cache_entry) -> fx_cached_sector_valid = temp_storage.fx_cached_sector_valid; (cache_entry) -> fx_cached_sector_type = temp_storage.fx_cached_sector_type; /* Set the previous pointer to NULL to avoid the linked list update below. */ *previous_cache_entry = FX_NULL; }if (media_ptr -> fx_media_sector_cache_hashed) { ... } else { /* Search for an entry in the cache that matches this request. */ cache_size = media_ptr -> fx_media_sector_cache_size; cache_entry = media_ptr -> fx_media_sector_cache_list_ptr; *previous_cache_entry = FX_NULL; /* Look at the cache entries until a match is found or the end of the cache is reached. *//* ... */ while (cache_size--) { /* Determine if the requested sector has been found. */ if ((cache_entry -> fx_cached_sector_valid) && (cache_entry -> fx_cached_sector == logical_sector)) { /* Yes, we found a match. Simply setup the pointer to this buffer and return. *//* ... */ media_ptr -> fx_media_memory_buffer = cache_entry -> fx_cached_sector_memory_buffer; /* Determine if we need to update the last used list. */ if (*previous_cache_entry) { /* Yes, the current entry is not at the front of the list so we need to change the order. *//* ... */ /* Link the previous entry to this entry's next pointer. */ (*previous_cache_entry) -> fx_cached_sector_next_used = cache_entry -> fx_cached_sector_next_used; /* Place this entry at the head of the list. */ cache_entry -> fx_cached_sector_next_used = media_ptr -> fx_media_sector_cache_list_ptr; media_ptr -> fx_media_sector_cache_list_ptr = cache_entry; }if (*previous_cache_entry) { ... } #ifndef FX_MEDIA_STATISTICS_DISABLE /* Increment the number of logical sectors cache read hits. */ media_ptr -> fx_media_logical_sector_cache_read_hits++;/* ... */ #endif /* Success, return to caller immediately! */ return(FX_NULL); }if ((cache_entry -> fx_cached_sector_valid) && (cache_entry -> fx_cached_sector == logical_sector)) { ... } /* Otherwise, we have not found the cached entry yet. */ /* If there are more entries, move to the next one. */ if (cache_entry -> fx_cached_sector_next_used) { *previous_cache_entry = cache_entry; cache_entry = cache_entry -> fx_cached_sector_next_used; }if (cache_entry -> fx_cached_sector_next_used) { ... } }while (cache_size--) { ... } }else { ... } /* The requested sector is not in cache, return the last cache entry. */ return(cache_entry);/* ... */ #else FX_PARAMETER_NOT_USED(media_ptr); FX_PARAMETER_NOT_USED(logical_sector); FX_PARAMETER_NOT_USED(previous_cache_entry); return(FX_NULL);/* ... */ #endif /* FX_DISABLE_CACHE */ }{ ... }