GCC Code Coverage Report


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

fx_directory_information_get.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_information_get 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 complete file parameters are placed in all non-NULL */
49 /* return parameters. If the file name is not found, the appropriate */
50 /* error code is returned to the caller. */
51 /* */
52 /* INPUT */
53 /* */
54 /* media_ptr Media control block pointer */
55 /* directory_name Directory name pointer */
56 /* attributes Pointer to attributes */
57 /* size Pointer to size */
58 /* year Pointer to year */
59 /* month Pointer to month */
60 /* day Pointer to day */
61 /* hour Pointer to hour */
62 /* minute Pointer to minute */
63 /* second Pointer to second */
64 /* */
65 /* OUTPUT */
66 /* */
67 /* return status */
68 /* */
69 /* CALLS */
70 /* */
71 /* _fx_directory_search Search for the file name in */
72 /* the directory structure */
73 /* */
74 /* CALLED BY */
75 /* */
76 /* Application Code */
77 /* */
78 /**************************************************************************/
79 63 UINT _fx_directory_information_get(FX_MEDIA *media_ptr, CHAR *directory_name,
80 UINT *attributes, ULONG *size,
81 UINT *year, UINT *month, UINT *day,
82 UINT *hour, UINT *minute, UINT *second)
83 {
84
85 UINT status;
86 FX_DIR_ENTRY dir_entry;
87 ULONG open_count;
88 FX_FILE *search_ptr;
89
90
91 #ifndef FX_MEDIA_STATISTICS_DISABLE
92
93 /* Increment the number of times this service has been called. */
94 63 media_ptr -> fx_media_directory_information_gets++;
95 #endif
96
97 /* Setup pointer to media name buffer. */
98 63 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
99
100 /* Clear the short name string. */
101 63 dir_entry.fx_dir_entry_short_name[0] = 0;
102
103 /* Check the media to make sure it is open. */
104
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 54 times.
63 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
105 {
106
107 /* Return the media not opened error. */
108 9 return(FX_MEDIA_NOT_OPEN);
109 }
110
111 /* If trace is enabled, insert this event into the trace buffer. */
112 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_INFORMATION_GET, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
113
114 /* Protect against other threads accessing the media. */
115 30 FX_PROTECT
116
117 /* Search the system for the supplied directory name. */
118 54 status = _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
119
120 /* Determine if the search was successful. */
121
4/4
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 7 taken 20 times.
✓ Branch 6 → 7 taken 5 times.
✓ Branch 6 → 9 taken 25 times.
54 if (status != FX_SUCCESS)
122 {
123
124 /* Release media protection. */
125 5 FX_UNPROTECT
126
127 /* Return the error code. */
128 9 return(status);
129 }
130
131 /* Check the list of open files for others open for writing. */
132 45 open_count = media_ptr -> fx_media_opened_file_count;
133 45 search_ptr = media_ptr -> fx_media_opened_file_list;
134
4/4
✓ Branch 14 → 8 taken 64 times.
✓ Branch 14 → 15 taken 16 times.
✓ Branch 16 → 10 taken 80 times.
✓ Branch 16 → 17 taken 20 times.
180 while (open_count)
135 {
136
137 /* Look at each opened file to see if the same file is opened
138 for writing. */
139
4/4
✓ Branch 8 → 9 taken 28 times.
✓ Branch 8 → 13 taken 36 times.
✓ Branch 10 → 11 taken 35 times.
✓ Branch 10 → 15 taken 45 times.
144 if ((search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector == dir_entry.fx_dir_entry_log_sector) &&
140
4/4
✓ Branch 9 → 10 taken 12 times.
✓ Branch 9 → 13 taken 16 times.
✓ Branch 11 → 12 taken 15 times.
✓ Branch 11 → 15 taken 20 times.
63 (search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset == dir_entry.fx_dir_entry_byte_offset) &&
141
4/4
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 13 taken 8 times.
✓ Branch 12 → 13 taken 5 times.
✓ Branch 12 → 15 taken 10 times.
27 (search_ptr -> fx_file_open_mode))
142 {
143
144 /* The file has been opened for writing by a previous call. Use the information used by
145 the writer instead of what is currently on the media. */
146 9 _fx_utility_memory_copy((UCHAR *)&search_ptr -> fx_file_dir_entry, (UCHAR *)&dir_entry, sizeof(FX_DIR_ENTRY)); /* Use case of memcpy is verified. */
147 9 break;
148 }
149
150 /* Adjust the pointer and decrement the search count. */
151 135 search_ptr = search_ptr -> fx_file_opened_next;
152 135 open_count--;
153 }
154
155 /* Check to see if attributes are required. */
156
4/4
✓ Branch 15 → 16 taken 12 times.
✓ Branch 15 → 17 taken 8 times.
✓ Branch 17 → 18 taken 15 times.
✓ Branch 17 → 19 taken 10 times.
45 if (attributes)
157 {
158
159 /* Pickup the attributes. */
160 27 *attributes = dir_entry.fx_dir_entry_attributes;
161 }
162
163 /* Check to see if the size is required. */
164
4/4
✓ Branch 17 → 18 taken 12 times.
✓ Branch 17 → 19 taken 8 times.
✓ Branch 19 → 20 taken 15 times.
✓ Branch 19 → 21 taken 10 times.
45 if (size)
165 {
166
167 /* Pickup the size. */
168 27 *size = (ULONG)dir_entry.fx_dir_entry_file_size;
169 }
170
171 /* Check to see if the year is required. */
172
4/4
✓ Branch 19 → 20 taken 12 times.
✓ Branch 19 → 21 taken 8 times.
✓ Branch 21 → 22 taken 15 times.
✓ Branch 21 → 23 taken 10 times.
45 if (year)
173 {
174
175 /* Pickup the year. */
176 27 *year = ((dir_entry.fx_dir_entry_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) +
177 FX_BASE_YEAR;
178 }
179
180 /* Check to see if the month is required. */
181
4/4
✓ Branch 21 → 22 taken 12 times.
✓ Branch 21 → 23 taken 8 times.
✓ Branch 23 → 24 taken 15 times.
✓ Branch 23 → 25 taken 10 times.
45 if (month)
182 {
183
184 /* Pickup the month. */
185 27 *month = (dir_entry.fx_dir_entry_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
186 }
187
188 /* Check to see if the day is required. */
189
4/4
✓ Branch 23 → 24 taken 12 times.
✓ Branch 23 → 25 taken 8 times.
✓ Branch 25 → 26 taken 15 times.
✓ Branch 25 → 27 taken 10 times.
45 if (day)
190 {
191
192 /* Pickup the day. */
193 27 *day = dir_entry.fx_dir_entry_date & FX_DAY_MASK;
194 }
195
196 /* Check to see if the hour is required. */
197
4/4
✓ Branch 25 → 26 taken 12 times.
✓ Branch 25 → 27 taken 8 times.
✓ Branch 27 → 28 taken 15 times.
✓ Branch 27 → 29 taken 10 times.
45 if (hour)
198 {
199
200 /* Pickup the hour. */
201 27 *hour = (dir_entry.fx_dir_entry_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
202 }
203
204 /* Check to see if the minute is required. */
205
4/4
✓ Branch 27 → 28 taken 16 times.
✓ Branch 27 → 29 taken 4 times.
✓ Branch 29 → 30 taken 20 times.
✓ Branch 29 → 31 taken 5 times.
45 if (minute)
206 {
207
208 /* Pickup the minute. */
209 36 *minute = (dir_entry.fx_dir_entry_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
210 }
211
212 /* Check to see if the second is required. */
213
4/4
✓ Branch 29 → 30 taken 16 times.
✓ Branch 29 → 31 taken 4 times.
✓ Branch 31 → 32 taken 20 times.
✓ Branch 31 → 33 taken 5 times.
45 if (second)
214 {
215
216 /* Pickup the second. */
217 36 *second = (dir_entry.fx_dir_entry_time & FX_SECOND_MASK) * 2;
218 }
219
220 /* Release media protection. */
221 25 FX_UNPROTECT
222
223 /* Directory information get is complete, return successful status. */
224 45 return(FX_SUCCESS);
225 }
226
227