GCC Code Coverage Report


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

fx_directory_name_test.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 /** Directory */
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_system.h"
30 #include "fx_directory.h"
31 #include "fx_file.h"
32 #include "fx_utility.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _fx_directory_name_test PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function first attempts to find the specified directory name. */
48 /* If found, the attributes are checked to see if the entry is a */
49 /* directory. If not, the appropriate error code is returned to the */
50 /* caller. */
51 /* */
52 /* INPUT */
53 /* */
54 /* media_ptr Media control block pointer */
55 /* directory_name Directory name pointer */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* return status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _fx_directory_search Search for the file name in */
64 /* the directory structure */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* */
70 /**************************************************************************/
71 10557 UINT _fx_directory_name_test(FX_MEDIA *media_ptr, CHAR *directory_name)
72 {
73
74 UINT status;
75 FX_DIR_ENTRY dir_entry;
76
77
78 #ifndef FX_MEDIA_STATISTICS_DISABLE
79
80 /* Increment the number of times this service has been called. */
81 10557 media_ptr -> fx_media_directory_name_tests++;
82 #endif
83
84 /* Setup pointer to media name buffer. */
85 10557 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
86
87 /* Clear the short name string. */
88 10557 dir_entry.fx_dir_entry_short_name[0] = 0;
89
90 /* Check the media to make sure it is open. */
91
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 10548 times.
10557 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
92 {
93
94 /* Return the media not opened error. */
95 9 return(FX_MEDIA_NOT_OPEN);
96 }
97
98 /* If trace is enabled, insert this event into the trace buffer. */
99 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_NAME_TEST, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
100
101 /* Protect against other threads accessing the media. */
102 10058 FX_PROTECT
103
104 /* Search the system for the supplied directory name. */
105 10548 status = _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
106
107 /* Determine if the search was successful. */
108
4/4
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 7 taken 486 times.
✓ Branch 6 → 7 taken 5 times.
✓ Branch 6 → 9 taken 10053 times.
10548 if (status != FX_SUCCESS)
109 {
110
111 /* Release media protection. */
112 5 FX_UNPROTECT
113
114 /* Return the error code. */
115 9 return(status);
116 }
117
118 /* Check to see if the entry is a directory. */
119
3/4
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 486 times.
✓ Branch 9 → 10 taken 240 times.
✓ Branch 9 → 12 taken 9813 times.
10539 if (!(dir_entry.fx_dir_entry_attributes & (UCHAR)FX_DIRECTORY))
120 {
121
122 /* Release media protection. */
123 240 FX_UNPROTECT
124
125 /* Return the not a directory error code. */
126 240 return(FX_NOT_DIRECTORY);
127 }
128
129 /* Release media protection. */
130 9813 FX_UNPROTECT
131
132 /* Directory name test is complete, return successful status. */
133 10299 return(FX_SUCCESS);
134 }
135
136