Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_utility.h"
#include "fx_directory.h"
#include "fx_fault_tolerant.h"
...
Files
loading (1/3)...
SourceVuSTM32 Libraries and Samplesfilexcommon/src/fx_fault_tolerant_create_log_file.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** Fault Tolerant */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE #include "fx_api.h" #include "fx_utility.h" #include "fx_directory.h" #include "fx_fault_tolerant.h" #ifdef FX_ENABLE_FAULT_TOLERANT... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_fault_tolerant_create_log_file PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function finds an available cluster used by log file. Then it */ /* sets the cluster number to boot sector. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_utility_exFAT_cluster_state_set Set state of exFAT cluster */ /* _fx_utility_FAT_entry_read Read a FAT entry */ /* _fx_utility_FAT_entry_write Write a FAT entry */ /* _fx_utility_exFAT_bitmap_flush Flush exFAT allocation bitmap */ /* _fx_utility_FAT_flush Flush written FAT entries */ /* _fx_utility_32_unsigned_write Write a ULONG from memory */ /* _fx_utility_exFAT_system_sector_write Write data into boot sector */ /* _fx_utility_exFAT_system_area_checksum_write */ /* Write checksum of boot sector */ /* _fx_utility_exFAT_bitmap_free_cluster_find */ /* Find a free cluster */ /* _fx_utility_logical_sector_read Read a logical sector */ /* */ /* CALLED BY */ /* */ /* _fx_fault_tolerant_enable */ /* */ /* 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 */ /* 01-31-2022 Bhupendra Naphade Modified comment(s), replaced */ /* sector size constant, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ UINT _fx_fault_tolerant_create_log_file(FX_MEDIA *media_ptr) { ULONG clusters; ULONG FAT_index; ULONG FAT_value = 0; UINT found; UINT status; UINT i; #ifdef FX_ENABLE_EXFAT ULONG checksum; UINT count; UCHAR *byte_ptr; UCHAR cluster_state;/* ... */ #endif /* FX_ENABLE_EXFAT */ /* Yes. Create a log file. */ /* First find a free cluster. */ if (media_ptr -> fx_media_available_clusters < media_ptr -> fx_media_fault_tolerant_clusters) { /* Out of disk space. */ return(FX_NO_MORE_SPACE); }if (media_ptr -> fx_media_available_clusters < media_ptr -> fx_media_fault_tolerant_clusters) { ... } /* Now we need to find the consecutive clusters. */ clusters = media_ptr -> fx_media_fault_tolerant_clusters; FAT_index = FX_FAT_ENTRY_START; found = FX_FALSE; while (FAT_index <= (media_ptr -> fx_media_total_clusters - clusters + FX_FAT_ENTRY_START)) { /* Determine if enough consecutive FAT entries are available. */ i = 0; #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { do { /* Get cluster state. */ status = _fx_utility_exFAT_cluster_state_get(media_ptr, (FAT_index + i), &cluster_state); /* Check for a successful status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Determine if the entry is free. */ if (cluster_state == FX_EXFAT_BITMAP_CLUSTER_OCCUPIED) { break; }if (cluster_state == FX_EXFAT_BITMAP_CLUSTER_OCCUPIED) { ... } /* Otherwise, increment the consecutive FAT indices. */ i++; ...} while (i < clusters); }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } else { #endif /* FX_ENABLE_EXFAT */ do { /* Read a FAT entry. */ status = _fx_utility_FAT_entry_read(media_ptr, (FAT_index + i), &FAT_value); /* Check for a successful status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Determine if the entry is free. */ if (FAT_value != FX_FREE_CLUSTER) { break; }if (FAT_value != FX_FREE_CLUSTER) { ... } /* Otherwise, increment the consecutive FAT indices. */ i++; ...} while (i < clusters); #ifdef FX_ENABLE_EXFAT }else { ... } #endif /* FX_ENABLE_EXFAT */ /* Determine if we found enough FAT entries. */ if (i >= clusters) { /* Yes, we have found enough FAT entries - set the found flag and get out of this loop. *//* ... */ found = FX_TRUE; break; }if (i >= clusters) { ... } else { #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { /* Find free cluster from exFAT media. */ status = _fx_utility_exFAT_bitmap_free_cluster_find(media_ptr, FAT_index + i + 1, &FAT_value); if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } if (FAT_value < FAT_index + i + 1) { /* If we wrapped. */ FAT_index = media_ptr -> fx_media_total_clusters + FX_FAT_ENTRY_START; }if (FAT_value < FAT_index + i + 1) { ... } else { FAT_index = FAT_value; }else { ... } }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } else { #endif /* FX_ENABLE_EXFAT */ /* Position to the next possibly free FAT entry. */ FAT_index = FAT_index + i + 1; #ifdef FX_ENABLE_EXFAT }else { ... } #endif /* FX_ENABLE_EXFAT */ }else { ... } }while (FAT_index <= (media_ptr -> fx_media_total_clusters - clusters + FX_FAT_ENTRY_START)) { ... } /* Determine if we found enough consecutive clusters to satisfy the request. *//* ... */ if (!found) { /* Not enough contiguous space on the media. Return error status. */ return(FX_NO_MORE_SPACE); }if (!found) { ... } /* Update the link pointers in the new clusters. */ for (i = 0; i < (clusters - 1); i++) { /* Update the cluster links. Since the allocation is sequential, we just have to link each FAT entry to the next one. *//* ... */ status = _fx_utility_FAT_entry_write(media_ptr, FAT_index + i, FAT_index + i + 1); /* Check for a bad status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { /* Mark the cluster as used. */ status = _fx_utility_exFAT_cluster_state_set(media_ptr, FAT_index + i, FX_EXFAT_BITMAP_CLUSTER_OCCUPIED); /* Check for a bad status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } /* ... */#endif /* FX_ENABLE_EXFAT */ }for (i = 0; i < (clusters - 1); i++) { ... } /* Now place an EOF in the last cluster entry. */ status = _fx_utility_FAT_entry_write(media_ptr, FAT_index + clusters - 1, media_ptr -> fx_media_fat_last); /* Check for a bad status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { /* Mark the cluster as used. */ status = _fx_utility_exFAT_cluster_state_set(media_ptr, FAT_index + clusters - 1, FX_EXFAT_BITMAP_CLUSTER_OCCUPIED); /* Check for a bad status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } /* ... */#endif /* FX_ENABLE_EXFAT */ #ifdef FX_FAULT_TOLERANT /* Flush the cached individual FAT entries */ _fx_utility_FAT_flush(media_ptr); #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { _fx_utility_exFAT_bitmap_flush(media_ptr); }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } /* ... */#endif /* FX_ENABLE_EXFAT *//* ... */ #endif /* Write start cluster for the file tolerant log file into the boot sector. */ _fx_utility_32_unsigned_write(media_ptr -> fx_media_fault_tolerant_memory_buffer + FX_FAULT_TOLERANT_BOOT_INDEX, FAT_index); /* Write the boot sector. */ media_ptr -> fx_media_driver_request = FX_DRIVER_BOOT_WRITE; media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_buffer = media_ptr -> fx_media_fault_tolerant_memory_buffer; media_ptr -> fx_media_driver_sectors = 1; media_ptr -> fx_media_driver_sector_type = FX_BOOT_SECTOR; /* If trace is enabled, insert this event into the trace buffer. */ FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_BOOT_WRITE, media_ptr, media_ptr -> fx_media_fault_tolerant_memory_buffer, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) /* Invoke the driver to read the boot sector. */ (media_ptr -> fx_media_driver_entry) (media_ptr); /* Determine if the boot sector was read correctly. */ if (media_ptr -> fx_media_driver_status != FX_SUCCESS) { /* Return the boot sector error status. */ return(FX_BOOT_ERROR); }if (media_ptr -> fx_media_driver_status != FX_SUCCESS) { ... } #ifdef FX_ENABLE_EXFAT if (media_ptr -> fx_media_FAT_type == FX_exFAT) { /* Write backup. */ status = _fx_utility_exFAT_system_sector_write(media_ptr, media_ptr -> fx_media_fault_tolerant_memory_buffer, FX_EXFAT_FAT_MAIN_SYSTEM_AREA_SIZE, 1, FX_BOOT_SECTOR); /* Determine if the boot sector was read correctly. */ if (status != FX_SUCCESS) { /* Return the boot sector error status. */ return(FX_BOOT_ERROR); }if (status != FX_SUCCESS) { ... } /* Calculate checksum. */ checksum = 0; byte_ptr = media_ptr -> fx_media_fault_tolerant_memory_buffer; /* Calculate Boot Sector Check Sum. */ for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { if ((FX_EF_VOLUME_FLAGS == i) || (FX_EF_VOLUME_FLAGS + 1 == i) || (FX_EF_PERCENT_IN_USE == i)) { continue; }if ((FX_EF_VOLUME_FLAGS == i) || (FX_EF_VOLUME_FLAGS + 1 == i) || (FX_EF_PERCENT_IN_USE == i)) { ... } checksum = ((checksum >> 1) | (checksum << 31)) + (ULONG)byte_ptr[i]; }for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { ... } for (count = 1; count < FX_EXFAT_FAT_CHECK_SUM_OFFSET; count++) { /* Read sector. */ status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) count, media_ptr -> fx_media_fault_tolerant_memory_buffer, ((ULONG) 1), FX_BOOT_SECTOR); /* Check for good completion status. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Calculate Check Sum for System Area */ for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { checksum = ((checksum >> 1) | (checksum << 31)) + (ULONG)byte_ptr[i]; }for (i = 0; i < media_ptr -> fx_media_bytes_per_sector; i++) { ... } }for (count = 1; count < FX_EXFAT_FAT_CHECK_SUM_OFFSET; count++) { ... } /* Write System Area CheckSum. */ status = _fx_utility_exFAT_system_area_checksum_write(media_ptr, media_ptr -> fx_media_fault_tolerant_memory_buffer, &checksum); if (status != FX_SUCCESS) { return(status); }if (status != FX_SUCCESS) { ... } }if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... } /* ... */#endif /* FX_ENABLE_EXFAT */ /* Set the start cluster. */ media_ptr -> fx_media_fault_tolerant_start_cluster = FAT_index; /* Decrease available cluster. */ media_ptr -> fx_media_available_clusters = media_ptr -> fx_media_available_clusters - clusters; /* Return success. */ return(FX_SUCCESS); }_fx_fault_tolerant_create_log_file (FX_MEDIA *media_ptr) { ... } /* ... */#endif /* FX_ENABLE_FAULT_TOLERANT */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.