GCC Code Coverage Report


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

fxe_file_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 /** File */
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_file.h"
30
31
32 FX_CALLER_CHECKING_EXTERNS
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _fxe_file_open PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function checks for errors in the file open call. */
48 /* */
49 /* INPUT */
50 /* */
51 /* media_ptr Media control block pointer */
52 /* file_ptr File control block pointer */
53 /* file_name Name pointer */
54 /* open_type Type of open requested */
55 /* file_control_block_size Size of FX_FILE structure */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* return status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _fx_file_open Actual open file service */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /**************************************************************************/
70 6957441 UINT _fxe_file_open(FX_MEDIA *media_ptr, FX_FILE *file_ptr, CHAR *file_name, UINT open_type, UINT file_control_block_size)
71 {
72
73 UINT status;
74 FX_FILE *current_file;
75 ULONG open_count;
76
77
78 /* Check for a null media or file pointer. */
79
8/8
✓ Branch 2 → 3 taken 6957433 times.
✓ Branch 2 → 6 taken 8 times.
✓ Branch 3 → 4 taken 6957425 times.
✓ Branch 3 → 6 taken 8 times.
✓ Branch 4 → 5 taken 6956735 times.
✓ Branch 4 → 6 taken 690 times.
✓ Branch 5 → 6 taken 690 times.
✓ Branch 5 → 7 taken 6956045 times.
6957441 if ((media_ptr == FX_NULL) || (media_ptr -> fx_media_id != FX_MEDIA_ID) || (file_ptr == FX_NULL) || (file_control_block_size != sizeof(FX_FILE)))
80 {
81 1396 return(FX_PTR_ERROR);
82 }
83
84 /* Check for an invalid open type. */
85
6/6
✓ Branch 7 → 8 taken 3544573 times.
✓ Branch 7 → 11 taken 3411472 times.
✓ Branch 8 → 9 taken 3544557 times.
✓ Branch 8 → 11 taken 16 times.
✓ Branch 9 → 10 taken 690 times.
✓ Branch 9 → 11 taken 3543867 times.
6956045 if ((open_type != FX_OPEN_FOR_READ) && (open_type != FX_OPEN_FOR_READ_FAST) && (open_type != FX_OPEN_FOR_WRITE))
86 {
87 690 return(FX_ACCESS_ERROR);
88 }
89
90 /* Check for a valid caller. */
91
6/6
✓ Branch 11 → 12 taken 6878897 times.
✓ Branch 11 → 14 taken 690 times.
✓ Branch 12 → 13 taken 6878207 times.
✓ Branch 12 → 14 taken 690 times.
✓ Branch 13 → 14 taken 690 times.
✓ Branch 13 → 15 taken 6877517 times.
6879587 FX_CALLER_CHECKING_CODE
92
93 /* Get protection. */
94 6877517 FX_PROTECT
95
96 /* Check for a duplicate file open. */
97
98 /* Loop to search the list for the same file handle. */
99 6953284 current_file = media_ptr -> fx_media_opened_file_list;
100 6953284 open_count = media_ptr -> fx_media_opened_file_count;
101
102
4/4
✓ Branch 15 → 12 taken 268356 times.
✓ Branch 15 → 16 taken 75760 times.
✓ Branch 21 → 17 taken 268356 times.
✓ Branch 21 → 22 taken 6877508 times.
7489980 while (open_count--)
103 {
104
105 /* See if a match exists. */
106
4/4
✓ Branch 12 → 13 taken 8 times.
✓ Branch 12 → 14 taken 268348 times.
✓ Branch 17 → 18 taken 8 times.
✓ Branch 17 → 20 taken 268348 times.
536712 if (file_ptr == current_file)
107 {
108
109 /* Release protection. */
110 8 FX_UNPROTECT
111
112 /* Return error. */
113 16 return(FX_PTR_ERROR);
114 }
115
116 /* Move to the next opened file. */
117 536696 current_file = current_file -> fx_file_opened_next;
118 }
119
120 /* Release protection. */
121 6877508 FX_UNPROTECT
122
123 /* Call actual file open service. */
124 6953268 status = _fx_file_open(media_ptr, file_ptr, file_name, open_type);
125
126 /* Open is complete, return status. */
127 6953263 return(status);
128 }
129
130