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_FAT_map_flush(FX_MEDIA *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesfilexcommon/src/fx_utility_FAT_map_flush.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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_FAT_map_flush PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function updates mirrors changes in the primary FAT to each of */ /* secondary FATs in the media. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_utility_logical_sector_read Read FAT sector into memory */ /* _fx_utility_logical_sector_write Write FAT sector back to disk */ /* */ /* CALLED BY */ /* */ /* FileX System Functions */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 William E. Lamie Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _fx_utility_FAT_map_flush(FX_MEDIA *media_ptr) { ULONG FAT_sector, last_sector; UINT i, status, FATs; UCHAR sectors_per_bit; /* Determine how many FAT sectors each bit in the bit map represents. Depending on the number of sectors in the primary FAT, each bit in this map may represent one or more primary FAT sectors. Because of this, it is possible some FAT sectors that were not changed may get flushed out to the secondary FAT. However, this method provides very nice performance benefits during normal operation and is much more reasonable than performing a total copy of the primary FAT to each secondary FAT on media flush and media close. *//* ... */ if (media_ptr -> fx_media_sectors_per_FAT % (FX_FAT_MAP_SIZE << 3) == 0) { sectors_per_bit = (UCHAR)(media_ptr -> fx_media_sectors_per_FAT / (FX_FAT_MAP_SIZE << 3)); }if (media_ptr -> fx_media_sectors_per_FAT % (FX_FAT_MAP_SIZE << 3) == 0) { ... } else { sectors_per_bit = (UCHAR)(media_ptr -> fx_media_sectors_per_FAT / (FX_FAT_MAP_SIZE << 3) + 1); }else { ... } /* Loop through the FAT update map to mirror primary FAT sectors to secondary FAT(s). */ for (i = 0; i < FX_FAT_MAP_SIZE << 3; i++) { /* Determine if there are FAT changes specified by this entry. */ if ((media_ptr -> fx_media_fat_secondary_update_map[i >> 3] & (1 << (i & 7))) == 0) { /* No, look at the next bit map entry. */ continue; }if ((media_ptr -> fx_media_fat_secondary_update_map[i >> 3] & (1 << (i & 7))) == 0) { ... } /* Setup the parameters for performing the update. */ FAT_sector = i * sectors_per_bit + media_ptr -> fx_media_reserved_sectors; last_sector = FAT_sector + sectors_per_bit; /* Make sure the last update sector is within range. */ if (last_sector > (media_ptr -> fx_media_sectors_per_FAT + media_ptr -> fx_media_reserved_sectors)) { last_sector = media_ptr -> fx_media_sectors_per_FAT + media_ptr -> fx_media_reserved_sectors; }if (last_sector > (media_ptr -> fx_media_sectors_per_FAT + media_ptr -> fx_media_reserved_sectors)) { ... } /* Loop to mirror primary FAT sectors to secondary FAT(s). */ for (; FAT_sector < last_sector; FAT_sector++) { /* Read the FAT sector. */ status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) FAT_sector, media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); /* Determine if an error occurred. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Pickup how many secondary FATs there are. */ FATs = media_ptr -> fx_media_number_of_FATs - 1; /* Loop to update additional FAT entries. */ while (FATs) { /* Mirror main FAT sector write into the additional FATs. */ status = _fx_utility_logical_sector_write(media_ptr, ((ULONG64) FAT_sector) + ((ULONG64)FATs * (ULONG64)(media_ptr -> fx_media_sectors_per_FAT)), media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_FAT_SECTOR); /* Determine if an error occurred. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Decrement the number of FATs. */ FATs--; }while (FATs) { ... } }for (; FAT_sector < last_sector; FAT_sector++) { ... } }for (i = 0; i < FX_FAT_MAP_SIZE << 3; i++) { ... } /* Clear the bit map that indicates primary FAT updates. */ for (i = 0; i < FX_FAT_MAP_SIZE; i++) { /* Clear each entry in the bit map. */ media_ptr -> fx_media_fat_secondary_update_map[i] = 0; }for (i = 0; i < FX_FAT_MAP_SIZE; i++) { ... } /* Return a successful completion. */ return(FX_SUCCESS); }{ ... }