Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_media.h"
#include "fx_utility.h"
...
...
_fx_media_check_lost_cluster_check(FX_MEDIA *, UCHAR *, ULONG, ULONG)
...
...
Files
loading...
CodeScopeSTM32 Libraries and Samplesfilexcommon/src/fx_media_check_lost_cluster_check.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** Media */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE /* Include necessary system files. */ #include "fx_api.h" #include "fx_media.h" #include "fx_utility.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_media_check_lost_cluster_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function examines all clusters to see if there are any unused */ /* clusters that are also unavailable. If specified, this routine will */ /* also mark the cluster as available. */ /* */ /* INPUT */ /* */ /* media_ptr Pointer to a previously */ /* opened media */ /* logical_fat Pointer to the logical FAT */ /* bit map */ /* total_clusters Total number of clusters */ /* error_correction_option Option for correcting lost */ /* cluster errors */ /* */ /* OUTPUT */ /* */ /* error Error code */ /* */ /* CALLS */ /* */ /* _fx_utility_FAT_entry_read Read a FAT entry */ /* _fx_utility_FAT_entry_write Write a FAT entry */ /* */ /* CALLED BY */ /* */ /* _fx_check_media Check media 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), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ ULONG _fx_media_check_lost_cluster_check(FX_MEDIA *media_ptr, UCHAR *logical_fat, ULONG total_clusters, ULONG error_correction_option) { ULONG cluster, next_cluster = 0; ULONG fat_last; ULONG error; UINT status; /* Calculate the FAT reserved and last sector values. */ if (media_ptr -> fx_media_32_bit_FAT) { fat_last = FX_LAST_CLUSTER_1_32; }if (media_ptr -> fx_media_32_bit_FAT) { ... } else { fat_last = FX_LAST_CLUSTER_1; }else { ... } /* Initialize the error. */ error = 0; /* Loop through all the clusters to see if any clusters NOT in the logical sector FAT have a non zero value. *//* ... */ for (cluster = FX_FAT_ENTRY_START; cluster < total_clusters; cluster++) { /* Determine if this cluster is in the logical FAT. */ if (logical_fat[cluster >> 3] & (1 << (cluster & 7))) { /* Yes, the cluster is in use by a file or sub-directory. Just continue the loop. */ continue; }if (logical_fat[cluster >> 3] & (1 << (cluster & 7))) { ... } /* Otherwise, the cluster is not in use. */ /* Read the contents of what should be a free cluster. */ status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster); /* Check for a good status. */ if (status) { /* Set the error code. */ error = error | FX_IO_ERROR; /* Return error code. */ return(error); }if (status) { ... } /* Determine if the contents of the cluster is valid. */ if (((next_cluster > (ULONG)FX_FREE_CLUSTER) && (next_cluster < media_ptr -> fx_media_fat_reserved)) || (next_cluster >= fat_last)) { /* Lost cluster is present. */ /* Set the error code status. */ error = FX_LOST_CLUSTER_ERROR; /* Determine if the lost cluster should be recovered. */ if (error_correction_option & FX_LOST_CLUSTER_ERROR) { /* Make the cluster available again. */ status = _fx_utility_FAT_entry_write(media_ptr, cluster, FX_FREE_CLUSTER); /* Check for a good status. */ if (status) { /* Increment the available clusters. */ media_ptr -> fx_media_available_clusters++; /* Set the error code. */ error = error | FX_IO_ERROR; /* Return error code. */ return(error); }if (status) { ... } }if (error_correction_option & FX_LOST_CLUSTER_ERROR) { ... } }if (((next_cluster > (ULONG)FX_FREE_CLUSTER) && (next_cluster < media_ptr -> fx_media_fat_reserved)) || (next_cluster >= fat_last)) { ... } }for (cluster = FX_FAT_ENTRY_START; cluster < total_clusters; cluster++) { ... } /* Return error code. */ return(error); }{ ... } #ifdef FX_ENABLE_EXFAT... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_media_check_exFAT_lost_cluster_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function examines all clusters in exFAT to see if there are */ /* any unused clusters that are also unavailable. */ /* */ /* INPUT */ /* */ /* media_ptr Pointer to a previously */ /* opened media */ /* logical_fat Pointer to the logical FAT */ /* bit map */ /* total_clusters Total number of clusters */ /* error_correction_option Option for correcting lost */ /* cluster errors */ /* */ /* OUTPUT */ /* */ /* error Error code */ /* */ /* CALLS */ /* */ /* _fx_utility_exFAT_bitmap_flush Flush dirty bitmap clusters */ /* _fx_utility_exFAT_bitmap_cache_update Cache bitmap clusters */ /* */ /* CALLED BY */ /* */ /* _fx_check_media Check media 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), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ ULONG _fx_media_check_exFAT_lost_cluster_check(FX_MEDIA *media_ptr, UCHAR *logical_fat, ULONG total_clusters, ULONG error_correction_option) { ULONG cluster = FX_FAT_ENTRY_START; ULONG cached_bitmap_bytes = media_ptr -> fx_media_exfat_bitmap_cache_size_in_sectors * media_ptr -> fx_media_bytes_per_sector; ULONG cached_bitmap_bits = cached_bitmap_bytes << 3; ULONG offset = 0; UINT status, i; /* This parameter has not been supported yet. */ FX_PARAMETER_NOT_USED(error_correction_option); /* Flush Allocation Bitmap Table first. */ status = _fx_utility_exFAT_bitmap_flush(media_ptr); if (FX_SUCCESS != status) { return(status); }if (FX_SUCCESS != status) { ... } while (total_clusters) { /* Read Allocation Bitmap Table from disk. */ status = _fx_utility_exFAT_bitmap_cache_update(media_ptr, cluster); if (FX_SUCCESS != status) { return(status); }if (FX_SUCCESS != status) { ... } if (total_clusters >= cached_bitmap_bits) { total_clusters -= cached_bitmap_bits; /* Compare cached bitmap with logical_fat. */ for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { if (logical_fat[offset + i] != ((UCHAR *)(media_ptr -> fx_media_exfat_bitmap_cache))[i]) { return(FX_LOST_CLUSTER_ERROR); }if (logical_fat[offset + i] != ((UCHAR *)(media_ptr -> fx_media_exfat_bitmap_cache))[i]) { ... } offset += cached_bitmap_bytes; cluster += cached_bitmap_bits; }for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { ... } }if (total_clusters >= cached_bitmap_bits) { ... } else { /* Compare cached bitmap with logical_fat. */ for (i = 0; i < ((total_clusters + 7) >> 3); i++) { if (logical_fat[offset + i] != ((UCHAR *)(media_ptr -> fx_media_exfat_bitmap_cache))[i]) { return(FX_LOST_CLUSTER_ERROR); }if (logical_fat[offset + i] != ((UCHAR *)(media_ptr -> fx_media_exfat_bitmap_cache))[i]) { ... } }for (i = 0; i < ((total_clusters + 7) >> 3); i++) { ... } total_clusters = 0; }else { ... } }while (total_clusters) { ... } return(FX_SUCCESS); }_fx_media_check_exFAT_lost_cluster_check (FX_MEDIA *media_ptr, UCHAR *logical_fat, ULONG total_clusters, ULONG error_correction_option) { ... } ...#endif/* ... */ /* FX_ENABLE_EXFAT */