Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_fault_tolerant.h"
#include "fx_utility.h"
...
Files
loading...
SourceVuSTM32 Libraries and Samplesfilexcommon/src/fx_fault_tolerant_transaction_end.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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_fault_tolerant.h" #include "fx_utility.h" #ifdef FX_ENABLE_FAULT_TOLERANT... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_fault_tolerant_transaction_end PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function completes a file system update operation protected */ /* by fault tolerant. This function first computes the checksum */ /* for the log entries, flush the log file to the file system (a */ /* necessary step to record vital information for the file system to */ /* recover, in case the update operation fails midway). After the */ /* log entries are written to the physical medium, the actualy file */ /* system changes (FAT table, directory entries) are applied. */ /* */ /* If the file system changes are successfully applied, the log */ /* entries can be removed. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_utility_16_unsigned_write Write a USHORT from memory */ /* _fx_fault_tolerant_apply_logs Apply logs into file system */ /* _fx_fault_tolerant_calculate_checksum Compute Checksum of data */ /* _fx_fault_tolerant_write_log_file Write log file */ /* _fx_fault_tolerant_reset_log_file Reset the log file */ /* */ /* CALLED BY */ /* */ /* _fx_directory_attributes_set */ /* _fx_directory_create */ /* _fx_directory_delete */ /* _fx_directory_rename */ /* _fx_file_allocate */ /* _fx_file_attributes_set */ /* _fx_file_best_effort_allocate */ /* _fx_file_create */ /* _fx_file_delete */ /* _fx_file_rename */ /* _fx_file_truncate */ /* _fx_file_truncate_release */ /* _fx_file_write */ /* _fx_unicode_directory_create */ /* _fx_unicode_file_create */ /* */ /* 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_fault_tolerant_transaction_end(FX_MEDIA *media_ptr) { ULONG relative_sector; UINT status; USHORT checksum; UINT offset; FX_FAULT_TOLERANT_LOG_HEADER *log_header; FX_FAULT_TOLERANT_LOG_CONTENT *log_content; /* Is fault tolerant enabled? */ if (media_ptr -> fx_media_fault_tolerant_enabled == FX_FALSE) { return(FX_SUCCESS); }if (media_ptr -> fx_media_fault_tolerant_enabled == FX_FALSE) { ... } /* Decrease the transaction. */ media_ptr -> fx_media_fault_tolerant_transaction_count--; /* Is transaction finished? */ if (media_ptr -> fx_media_fault_tolerant_transaction_count != 0) { return(FX_SUCCESS); }if (media_ptr -> fx_media_fault_tolerant_transaction_count != 0) { ... } /* Close this transaction. */ media_ptr -> fx_media_fault_tolerant_state = FX_FAULT_TOLERANT_STATE_IDLE; /* Set log header and FAT chain pointer. */ log_header = (FX_FAULT_TOLERANT_LOG_HEADER *)media_ptr -> fx_media_fault_tolerant_memory_buffer; log_content = (FX_FAULT_TOLERANT_LOG_CONTENT *)(media_ptr -> fx_media_fault_tolerant_memory_buffer + FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET); /* Reset checksum field and update log entry counter field. */ _fx_utility_16_unsigned_write((UCHAR *)&log_content -> fx_fault_tolerant_log_content_checksum, 0); _fx_utility_16_unsigned_write((UCHAR *)&log_content -> fx_fault_tolerant_log_content_count, media_ptr -> fx_media_fault_tolerant_total_logs); /* Now calculate the checksum of log content. */ checksum = _fx_fault_tolerant_calculate_checksum((media_ptr -> fx_media_fault_tolerant_memory_buffer + FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET), (media_ptr -> fx_media_fault_tolerant_file_size - FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET)); /* Record checksum field of log content. */ _fx_utility_16_unsigned_write((UCHAR *)&log_content -> fx_fault_tolerant_log_content_checksum, checksum); /* Record log header. */ _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_total_size, media_ptr -> fx_media_fault_tolerant_file_size); _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_checksum, 0); /* Calculate checksum of the header. */ checksum = _fx_fault_tolerant_calculate_checksum((UCHAR *)log_header, FX_FAULT_TOLERANT_LOG_HEADER_SIZE); /* Record checksum field of the header. */ _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_checksum, checksum); /* Flush log content and flush first sector at last. The first sector contains size of total log file. * The log file will contain wrong value of size when it is interrupted after first sector flushed to file system. *//* ... */ relative_sector = 1; offset = media_ptr -> fx_media_bytes_per_sector; while (offset < media_ptr -> fx_media_fault_tolerant_file_size) { /* Write back the log. */ status = _fx_fault_tolerant_write_log_file(media_ptr, relative_sector); /* Check for good completion status. */ if (status != FX_SUCCESS) { /* Error. */ return(status); }if (status != FX_SUCCESS) { ... } /* Increase relative sector and offset. */ relative_sector++; offset += media_ptr -> fx_media_bytes_per_sector; }while (offset < media_ptr -> fx_media_fault_tolerant_file_size) { ... } /* Flush first sector. */ status = _fx_fault_tolerant_write_log_file(media_ptr, 0); /* Check for good completion status. */ if (status != FX_SUCCESS) { /* Error. */ return(status); }if (status != FX_SUCCESS) { ... } /* At this pointer, the vital information has been flushed to the physical medium. Update the file system (FAT table, directory entry) using information recorded in the log file. *//* ... */ status = _fx_fault_tolerant_apply_logs(media_ptr); /* Check for a bad status. */ if (status != FX_SUCCESS) { /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } /* The file system has been updated successfully. Remove and reset the fault tolerant log file. *//* ... */ status = _fx_fault_tolerant_reset_log_file(media_ptr); return(status); }_fx_fault_tolerant_transaction_end (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.