GCC Code Coverage Report


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

fx_fault_tolerant_read_FAT.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_fault_tolerant.h"
28
29
30 #ifdef FX_ENABLE_FAULT_TOLERANT
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _fx_fault_tolerant_read_FAT PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function reads value of a FAT entry from log file if it */
44 /* exists. During file or directory operations with Fault Tolerant */
45 /* protection, intermediate operations are written to the fault */
46 /* tolerant log files. Therefore, FAT-entry read should search for */
47 /* fault tolerant log before the request can be passed to normal FAT */
48 /* entry read routine. */
49 /* */
50 /* INPUT */
51 /* */
52 /* media_ptr Media control block pointer */
53 /* cluster Cluster entry number */
54 /* value Pointer to value for the entry*/
55 /* log_type FAT or bitmap */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* return status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _fx_utility_16_unsigned_read Read a USHORT from memory */
64 /* _fx_utility_32_unsigned_read Read a ULONG from memory */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* _fx_utility_FAT_entry_read */
69 /* */
70 /**************************************************************************/
71 119365487 UINT _fx_fault_tolerant_read_FAT(FX_MEDIA *media_ptr, ULONG cluster, ULONG *value, ULONG log_type)
72 {
73 ULONG logs_remaining;
74 UCHAR *current_ptr;
75 119365487 UCHAR found = FX_FALSE;
76 ULONG size;
77 USHORT type;
78 ULONG log_len;
79 FX_FAULT_TOLERANT_FAT_LOG *fat_log;
80
81
82 /* Get fault tolerant data. */
83 119365487 logs_remaining = media_ptr -> fx_media_fault_tolerant_total_logs;
84
85 /* Any redo logs? */
86
2/2
✓ Branch 2 → 3 taken 86558549 times.
✓ Branch 2 → 4 taken 32806938 times.
119365487 if (logs_remaining == 0)
87 {
88
89 /* No. Just return. */
90 86558549 return(FX_READ_CONTINUE);
91 }
92
93 /* Get size of all logs. */
94 32806938 size = media_ptr -> fx_media_fault_tolerant_file_size - FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET;
95
96 /* Get the first log pointer. */
97 32806938 current_ptr = media_ptr -> fx_media_fault_tolerant_memory_buffer +
98 FX_FAULT_TOLERANT_LOG_CONTENT_OFFSET +
99 FX_FAULT_TOLERANT_LOG_CONTENT_HEADER_SIZE;
100
101 /* Loop throught all FAT logs. */
102
2/2
✓ Branch 15 → 5 taken 32816444 times.
✓ Branch 15 → 16 taken 32806936 times.
65623380 while (logs_remaining)
103 {
104
105 /* Check log type. */
106 32816444 type = (USHORT)_fx_utility_16_unsigned_read(current_ptr);
107
108 /* Get log length. */
109 32816444 log_len = _fx_utility_16_unsigned_read(current_ptr + 2);
110
111 /* Validate the size value. */
112
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 32816442 times.
32816444 if (log_len > size)
113 {
114
115 /* Log file is corrupted. Nothing can be done. Return.*/
116 2 return(FX_FILE_CORRUPT);
117 }
118 32816442 size -= log_len;
119
120 /* Check log type. */
121
2/2
✓ Branch 9 → 10 taken 1204 times.
✓ Branch 9 → 14 taken 32815238 times.
32816442 if (type == log_type)
122 {
123
124 /* This is the log with same type . */
125 /* Get the log pointer. */
126 1204 fat_log = (FX_FAULT_TOLERANT_FAT_LOG *)current_ptr;
127
128 /* Is this FAT log entry the one looking for? */
129
2/2
✓ Branch 11 → 12 taken 56 times.
✓ Branch 11 → 14 taken 1148 times.
1204 if (_fx_utility_32_unsigned_read((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_cluster) == cluster)
130 {
131
132 /* Yes, it is. */
133 56 *value = _fx_utility_32_unsigned_read((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_value);
134
135 /* Do not return since there may be more than one log for this cluster. */
136 56 found = FX_TRUE;
137 }
138 }
139
140 /* Decrease the logs_remaining counter. */
141 32816442 logs_remaining--;
142
143 /* Get next log pointer. */
144 32816442 current_ptr += log_len;
145 }
146
147
2/2
✓ Branch 16 → 17 taken 32806880 times.
✓ Branch 16 → 18 taken 56 times.
32806936 if (found != FX_TRUE)
148 {
149
150 /* Pass the request to FAT entry read. */
151 32806880 return(FX_READ_CONTINUE);
152 }
153
154 /* Return success. */
155 56 return(FX_SUCCESS);
156 }
157
158 #endif /* FX_ENABLE_FAULT_TOLERANT */
159
160