GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 24 / 0 / 24
Functions: 100.0% 1 / 0 / 1
Branches: 89.5% 34 / 0 / 38

fxe_media_open.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 /** Media */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "fx_api.h"
29 #include "fx_media.h"
30 #include "fx_system.h"
31
32
33 FX_CALLER_CHECKING_EXTERNS
34
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _fxe_media_open PORTABLE C */
41 /* 6.1 */
42 /* AUTHOR */
43 /* */
44 /* William E. Lamie, Microsoft Corporation */
45 /* */
46 /* DESCRIPTION */
47 /* */
48 /* This function checks for errors in the media open call. */
49 /* */
50 /* INPUT */
51 /* */
52 /* media_ptr Media control block pointer */
53 /* media_name Pointer to media name string */
54 /* media_driver Media driver entry function */
55 /* driver_info_ptr Optional information pointer */
56 /* supplied to media driver */
57 /* memory_ptr Pointer to memory used by the */
58 /* FileX for this media. */
59 /* memory_size Size of media memory - must */
60 /* at least 512 bytes and */
61 /* one sector size. */
62 /* media_control_block_size Size of FX_MEDIA structure */
63 /* */
64 /* OUTPUT */
65 /* */
66 /* FX_PTR_ERROR One or more input parameters */
67 /* are NULL */
68 /* status Actual completion status */
69 /* */
70 /* CALLS */
71 /* */
72 /* tx_thread_identify Get current thread */
73 /* tx_thread_preemption_change Disable/restore preemption */
74 /* _fx_media_open Actual media open service */
75 /* */
76 /* CALLED BY */
77 /* */
78 /* Application Code */
79 /* */
80 /**************************************************************************/
81 67484 UINT _fxe_media_open(FX_MEDIA *media_ptr, CHAR *media_name,
82 VOID (*media_driver)(FX_MEDIA *), VOID *driver_info_ptr,
83 VOID *memory_ptr, ULONG memory_size, UINT media_control_block_size)
84 {
85
86 UINT status;
87 ULONG temp;
88 FX_MEDIA *current_media;
89 ULONG open_count;
90
91 #ifndef FX_SINGLE_THREAD
92 TX_THREAD *current_thread;
93 UINT old_threshold;
94 #endif
95
96
97 /* Check for invalid input pointers. */
98
8/8
✓ Branch 2 → 3 taken 67476 times.
✓ Branch 2 → 6 taken 8 times.
✓ Branch 3 → 4 taken 66786 times.
✓ Branch 3 → 6 taken 690 times.
✓ Branch 4 → 5 taken 66096 times.
✓ Branch 4 → 6 taken 690 times.
✓ Branch 5 → 6 taken 690 times.
✓ Branch 5 → 7 taken 65406 times.
67484 if ((media_ptr == FX_NULL) || (media_driver == FX_NULL) || (memory_ptr == FX_NULL) || (media_control_block_size != sizeof(FX_MEDIA)))
99 {
100 2078 return(FX_PTR_ERROR);
101 }
102
103 /* Check for a valid caller. */
104
6/6
✓ Branch 7 → 8 taken 34472 times.
✓ Branch 7 → 10 taken 690 times.
✓ Branch 8 → 9 taken 33782 times.
✓ Branch 8 → 10 taken 690 times.
✓ Branch 9 → 10 taken 690 times.
✓ Branch 9 → 11 taken 33092 times.
35162 FX_CALLER_CHECKING_CODE
105
106 /* Check for proper size of the logical sector cache. */
107 63336 temp = _fx_system_media_max_sector_cache;
108
109 /* Isolate the lowest set bit. */
110 63336 temp = (temp & ((~temp) + ((ULONG) 1)));
111
112 /* If FX_MAX_SECTOR_CACHE is a power of 2, the value of temp should be unchanged. */
113
6/8
✓ Branch 7 → 8 taken 30244 times.
✗ Branch 7 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 30244 times.
✓ Branch 11 → 12 taken 32402 times.
✓ Branch 11 → 13 taken 690 times.
✓ Branch 12 → 13 taken 690 times.
✓ Branch 12 → 14 taken 31712 times.
63336 if ((temp == 1) || (temp != _fx_system_media_max_sector_cache))
114 {
115
116 /* Not a power of 2, return an error. */
117 1380 return(FX_MEDIA_INVALID);
118 }
119
120 /* Check for proper size of the FAT cache. */
121 61956 temp = _fx_system_media_max_fat_cache;
122
123 /* Isolate the lowest set bit. */
124 61956 temp = (temp & ((~temp) + ((ULONG) 1)));
125
126 /* If FX_MAX_FAT_CACHE is a power of 2, the value of temp should be unchanged. */
127
6/8
✓ Branch 10 → 11 taken 30244 times.
✗ Branch 10 → 12 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 30244 times.
✓ Branch 14 → 15 taken 31022 times.
✓ Branch 14 → 16 taken 690 times.
✓ Branch 15 → 16 taken 690 times.
✓ Branch 15 → 17 taken 30332 times.
61956 if ((temp == 1) || (temp != _fx_system_media_max_fat_cache))
128 {
129
130 /* Not a power of 2, return an error. */
131 1380 return(FX_MEDIA_INVALID);
132 }
133
134 #ifndef FX_SINGLE_THREAD
135
136 /* Pickup current thread pointer. At this point we know the current thread pointer is non-null since
137 it was checked by code in FX_CALLER_CHECKING_CODE macro. */
138 30332 current_thread = tx_thread_identify();
139
140 /* Disable preemption temporarily. */
141 30332 tx_thread_preemption_change(current_thread, 0, &old_threshold);
142 #endif
143
144 /* Loop to check for the media already opened. */
145 60576 current_media = _fx_system_media_opened_ptr;
146 60576 open_count = _fx_system_media_opened_count;
147
4/4
✓ Branch 17 → 14 taken 22 times.
✓ Branch 17 → 18 taken 30238 times.
✓ Branch 24 → 20 taken 22 times.
✓ Branch 24 → 25 taken 30326 times.
60608 while (open_count--)
148 {
149
150 /* Is the new media pointer already open? */
151
4/4
✓ Branch 14 → 15 taken 6 times.
✓ Branch 14 → 16 taken 16 times.
✓ Branch 20 → 21 taken 6 times.
✓ Branch 20 → 23 taken 16 times.
44 if (media_ptr == current_media)
152 {
153
154 #ifndef FX_SINGLE_THREAD
155
156 /* Restore preemption. */
157 6 tx_thread_preemption_change(current_thread, old_threshold, &old_threshold);
158 #endif
159
160 /* Duplicate media open, return an error! */
161 12 return(FX_PTR_ERROR);
162 }
163
164 /* Move to next entry. */
165 32 current_media = current_media -> fx_media_opened_next;
166 }
167
168 #ifndef FX_SINGLE_THREAD
169
170 /* Restore preemption. */
171 30326 tx_thread_preemption_change(current_thread, old_threshold, &old_threshold);
172 #endif
173
174 /* Call actual media open service. */
175 60564 status = _fx_media_open(media_ptr, media_name, media_driver, driver_info_ptr,
176 memory_ptr, memory_size);
177
178 /* Return status. */
179 60564 return(status);
180 }
181
182