GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 25 / 0 / 25
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

fx_fault_tolerant_reset_log_file.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** Fault Tolerant */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25 #include "fx_api.h"
26 #include "fx_utility.h"
27 #include "fx_directory.h"
28 #include "fx_fault_tolerant.h"
29
30
31 #ifdef FX_ENABLE_FAULT_TOLERANT
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _fx_fault_tolerant_reset_log_file PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function removes all log entries from the log file, and */
45 /* it to its initial state. */
46 /* */
47 /* INPUT */
48 /* */
49 /* media_ptr Media control block pointer */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* return status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _fx_utility_16_unsigned_write Write a USHORT from memory */
58 /* _fx_utility_32_unsigned_write Write a ULONG from memory */
59 /* _fx_fault_tolerant_calculate_checksum Compute Checksum of data */
60 /* _fx_fault_tolerant_write_log_file Write log file */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* _fx_directory_attributes_set */
65 /* _fx_directory_create */
66 /* _fx_directory_delete */
67 /* _fx_directory_rename */
68 /* _fx_file_allocate */
69 /* _fx_file_attributes_set */
70 /* _fx_file_best_effort_allocate */
71 /* _fx_file_create */
72 /* _fx_file_delete */
73 /* _fx_file_rename */
74 /* _fx_file_truncate */
75 /* _fx_file_truncate_release */
76 /* _fx_file_write */
77 /* _fx_unicode_directory_create */
78 /* _fx_unicode_file_create */
79 /* _fx_fault_tolerant_enable */
80 /* _fx_fault_tolerant_transaction_end */
81 /* */
82 /**************************************************************************/
83
84 160146195 UINT _fx_fault_tolerant_reset_log_file(FX_MEDIA *media_ptr)
85 {
86 UINT status;
87 USHORT checksum;
88 FX_FAULT_TOLERANT_LOG_HEADER *log_header;
89 FX_FAULT_TOLERANT_FAT_CHAIN *FAT_chain;
90 FX_FAULT_TOLERANT_LOG_CONTENT *log_content;
91
92 /* Set log header, FAT chain and log content pointer. */
93 160146195 log_header = (FX_FAULT_TOLERANT_LOG_HEADER *)media_ptr -> fx_media_fault_tolerant_memory_buffer;
94 160146195 FAT_chain = (FX_FAULT_TOLERANT_FAT_CHAIN *)(media_ptr -> fx_media_fault_tolerant_memory_buffer +
95 FX_FAULT_TOLERANT_FAT_CHAIN_OFFSET);
96 160146195 log_content = (FX_FAULT_TOLERANT_LOG_CONTENT *)(media_ptr -> fx_media_fault_tolerant_memory_buffer +
97 FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET);
98
99 /* Reset the log file header. */
100 160146195 _fx_utility_32_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_id, FX_FAULT_TOLERANT_ID);
101 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_total_size,
102 (FX_FAULT_TOLERANT_LOG_HEADER_SIZE + FX_FAULT_TOLERANT_FAT_CHAIN_SIZE));
103 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_checksum, 0);
104 160146195 log_header -> fx_fault_tolerant_log_header_version_major = FX_FAULT_TOLERANT_VERSION_MAJOR;
105 160146195 log_header -> fx_fault_tolerant_log_header_version_minor = FX_FAULT_TOLERANT_VERSION_MINOR;
106 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_reserved, 0);
107 160146195 checksum = _fx_fault_tolerant_calculate_checksum((UCHAR *)log_header, FX_FAULT_TOLERANT_LOG_HEADER_SIZE);
108 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_header -> fx_fault_tolerant_log_header_checksum, checksum);
109
110 /* Reset the undo log section. */
111 160146195 _fx_utility_16_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_checksumm, 0xFFFF);
112 160146195 FAT_chain -> fx_fault_tolerant_FAT_chain_flag = 0;
113 160146195 FAT_chain -> fx_fault_tolerant_FAT_chain_reserved = 0;
114 160146195 _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_front, 0);
115 160146195 _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_head_new, 0);
116 160146195 _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_head_original, 0);
117 160146195 _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_back, 0);
118 160146195 _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_next_deletion, 0);
119
120 /* Reset log content header. */
121 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_content -> fx_fault_tolerant_log_content_checksum, 0xFFFF);
122 160146195 _fx_utility_16_unsigned_write((UCHAR *)&log_content -> fx_fault_tolerant_log_content_count, 0xFFFF);
123
124 /* No matter success or fail, close this transaction. */
125 160146195 media_ptr -> fx_media_fault_tolerant_state = FX_FAULT_TOLERANT_STATE_IDLE;
126
127 /* Write the log header and FAT chain. */
128 160146195 status = _fx_fault_tolerant_write_log_file(media_ptr, 0);
129
130 /* Return the status. */
131 160146131 return(status);
132 }
133 #endif /* FX_ENABLE_FAULT_TOLERANT */
134
135