GCC Code Coverage Report


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

fx_fault_tolerant_add_dir_log.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_add_dir_log PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function converts directory entry write into log entry and add */
44 /* it into log file. */
45 /* */
46 /* INPUT */
47 /* */
48 /* media_ptr Media control block pointer */
49 /* logical_sector Original sector to write to */
50 /* offset Offset in original sector */
51 /* data Data of log */
52 /* data_size Size of data */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* return status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _fx_utility_16_unsigned_write Write a USHORT from memory */
61 /* _fx_utility_32_unsigned_write Write a ULONG from memory */
62 /* _fx_utility_64_unsigned_write Write a ULONG64 from memory */
63 /* memcpy Memory Copy */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* _fx_directory_entry_write */
68 /* */
69 /**************************************************************************/
70 163560218 UINT _fx_fault_tolerant_add_dir_log(FX_MEDIA *media_ptr, ULONG64 logical_sector, ULONG offset,
71 UCHAR *data, ULONG data_size)
72 {
73 ULONG file_size;
74 FX_FAULT_TOLERANT_DIR_LOG *dir_log;
75
76 /* Increment the size of the log file. */
77 163560218 file_size = media_ptr -> fx_media_fault_tolerant_file_size + data_size + FX_FAULT_TOLERANT_DIR_LOG_ENTRY_SIZE;
78
79 /* Check whether log file exceeds the buffer. */
80
2/2
✓ Branch 2 → 3 taken 12 times.
✓ Branch 2 → 4 taken 163560206 times.
163560218 if (file_size > media_ptr -> fx_media_fault_tolerant_memory_buffer_size)
81 {
82
83 /* Log file exceeds the size of the log buffer. This is a failure. */
84 12 return(FX_NO_MORE_SPACE);
85 }
86
87 /* Any data to write? */
88
2/2
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 163560202 times.
163560206 if (data_size == 0)
89 {
90
91 /* No. Just return. */
92 4 return FX_SUCCESS;
93 }
94
95 /* Set log pointer. */
96 163560202 dir_log = (FX_FAULT_TOLERANT_DIR_LOG *)(media_ptr -> fx_media_fault_tolerant_memory_buffer +
97 163560202 media_ptr -> fx_media_fault_tolerant_file_size);
98
99 /* Set log type. */
100 163560202 _fx_utility_16_unsigned_write((UCHAR *)&dir_log -> fx_fault_tolerant_dir_log_type,
101 FX_FAULT_TOLERANT_DIR_LOG_TYPE);
102
103 /* Size of log. */
104 163560202 _fx_utility_16_unsigned_write((UCHAR *)&dir_log -> fx_fault_tolerant_dir_log_size,
105 163560202 data_size + FX_FAULT_TOLERANT_DIR_LOG_ENTRY_SIZE);
106
107 /* Set sector and offset. */
108 163560202 _fx_utility_64_unsigned_write((UCHAR *)&dir_log -> fx_fault_tolerant_dir_log_sector, logical_sector);
109 163560202 _fx_utility_32_unsigned_write((UCHAR *)&dir_log -> fx_fault_tolerant_dir_log_offset, offset);
110
111 163560202 memcpy(media_ptr -> fx_media_fault_tolerant_memory_buffer + /* Use case of memcpy is verified. */
112 163560202 media_ptr -> fx_media_fault_tolerant_file_size + FX_FAULT_TOLERANT_DIR_LOG_ENTRY_SIZE,
113 data, data_size);
114
115
116 /* Update log information. */
117 163560202 media_ptr -> fx_media_fault_tolerant_file_size = (USHORT)file_size;
118 163560202 media_ptr -> fx_media_fault_tolerant_total_logs += 1;
119
120 163560202 return(FX_SUCCESS);
121 }
122 #endif /* FX_ENABLE_FAULT_TOLERANT */
123
124