GCC Code Coverage Report


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

fx_file_attributes_set.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_system.h"
30 #include "fx_directory.h"
31 #include "fx_file.h"
32 #include "fx_utility.h"
33 #ifdef FX_ENABLE_FAULT_TOLERANT
34 #include "fx_fault_tolerant.h"
35 #endif /* FX_ENABLE_FAULT_TOLERANT */
36
37
38 /**************************************************************************/
39 /* */
40 /* FUNCTION RELEASE */
41 /* */
42 /* _fx_file_attributes_set PORTABLE C */
43 /* 6.1 */
44 /* AUTHOR */
45 /* */
46 /* William E. Lamie, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This function first attempts to find the specified file. If found, */
51 /* the attribute set request is valid and the directory entry will be */
52 /* modified with the new attributes. Otherwise, if the file is not */
53 /* found, the appropriate error code is returned to the caller. */
54 /* */
55 /* INPUT */
56 /* */
57 /* media_ptr Media control block pointer */
58 /* file_name File name pointer */
59 /* attributes New file attributes */
60 /* */
61 /* OUTPUT */
62 /* */
63 /* return status */
64 /* */
65 /* CALLS */
66 /* */
67 /* _fx_directory_entry_write Write the new directory entry */
68 /* _fx_directory_search Search for the file name in */
69 /* the directory structure */
70 /* _fx_fault_tolerant_transaction_start Start fault tolerant */
71 /* transaction */
72 /* _fx_fault_tolerant_transaction_end End fault tolerant transaction*/
73 /* _fx_fault_tolerant_recover Recover FAT chain */
74 /* _fx_fault_tolerant_reset_log_file Reset the log file */
75 /* */
76 /* CALLED BY */
77 /* */
78 /* Application Code */
79 /* */
80 /**************************************************************************/
81 123 UINT _fx_file_attributes_set(FX_MEDIA *media_ptr, CHAR *file_name, UINT attributes)
82 {
83
84 UINT status;
85 ULONG open_count;
86 FX_FILE *search_ptr;
87 FX_DIR_ENTRY dir_entry;
88 UCHAR not_a_file_attr;
89
90
91 #ifndef FX_MEDIA_STATISTICS_DISABLE
92
93 /* Increment the number of times this service has been called. */
94 123 media_ptr -> fx_media_file_attributes_sets++;
95 #endif
96
97 /* Setup pointer to media name buffer. */
98 123 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 123 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 114 times.
123 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 114 not_a_file_attr = FX_DIRECTORY | FX_VOLUME;
111
112 /* If trace is enabled, insert this event into the trace buffer. */
113 FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_ATTRIBUTES_SET, media_ptr, file_name, attributes, 0, FX_TRACE_FILE_EVENTS, 0, 0)
114
115 /* Protect against other threads accessing the media. */
116 64 FX_PROTECT
117
118 /* Check for write protect at the media level (set by driver). */
119
4/4
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 46 times.
✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 8 taken 59 times.
114 if (media_ptr -> fx_media_driver_write_protect)
120 {
121
122 /* Release media protection. */
123 5 FX_UNPROTECT
124
125 /* Return write protect error. */
126 9 return(FX_WRITE_PROTECT);
127 }
128
129 /* Search the system for the supplied file name. */
130 105 status = _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
131
132 /* Determine if the search was successful. */
133
4/4
✓ Branch 7 → 8 taken 4 times.
✓ Branch 7 → 9 taken 42 times.
✓ Branch 9 → 10 taken 10 times.
✓ Branch 9 → 12 taken 49 times.
105 if (status != FX_SUCCESS)
134 {
135
136 /* Release media protection. */
137 10 FX_UNPROTECT
138
139 /* Return the error code. */
140 14 return(status);
141 }
142
143 /* Check to make sure the found entry is a file. */
144
4/4
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 38 times.
✓ Branch 12 → 13 taken 5 times.
✓ Branch 12 → 15 taken 44 times.
91 if (dir_entry.fx_dir_entry_attributes & not_a_file_attr)
145 {
146
147 /* Release media protection. */
148 5 FX_UNPROTECT
149
150 /* Return the not a file error code. */
151 9 return(FX_NOT_A_FILE);
152 }
153
154 /* Search the opened files to see if this file is currently
155 opened. */
156 82 open_count = media_ptr -> fx_media_opened_file_count;
157 82 search_ptr = media_ptr -> fx_media_opened_file_list;
158
4/4
✓ Branch 16 → 12 taken 52 times.
✓ Branch 16 → 17 taken 34 times.
✓ Branch 21 → 16 taken 65 times.
✓ Branch 21 → 22 taken 39 times.
190 while (open_count)
159 {
160
161 /* Look at each opened file to see if the same file is opened. */
162
4/4
✓ Branch 12 → 13 taken 24 times.
✓ Branch 12 → 15 taken 28 times.
✓ Branch 16 → 17 taken 30 times.
✓ Branch 16 → 20 taken 35 times.
117 if ((search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector == dir_entry.fx_dir_entry_log_sector) &&
163
4/4
✓ Branch 13 → 14 taken 4 times.
✓ Branch 13 → 15 taken 20 times.
✓ Branch 17 → 18 taken 5 times.
✓ Branch 17 → 20 taken 25 times.
54 (search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset == dir_entry.fx_dir_entry_byte_offset))
164 {
165
166 /* Release media protection. */
167 5 FX_UNPROTECT
168
169 /* The file is currently open. */
170 9 return(FX_ACCESS_ERROR);
171 }
172
173 /* Adjust the pointer and decrement the search count. */
174 108 search_ptr = search_ptr -> fx_file_opened_next;
175 108 open_count--;
176 }
177
178 /* Place the new attributes in the directory entry. */
179 73 dir_entry.fx_dir_entry_attributes = (UCHAR)attributes;
180
181 #ifdef FX_ENABLE_FAULT_TOLERANT
182 /* Start transaction. */
183 48 _fx_fault_tolerant_transaction_start(media_ptr);
184 #endif /* FX_ENABLE_FAULT_TOLERANT */
185
186 /* Now write out the directory entry. */
187 73 status = _fx_directory_entry_write(media_ptr, &dir_entry);
188
189 #ifdef FX_ENABLE_FAULT_TOLERANT
190 /* Check for a bad status. */
191
4/4
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 22 taken 23 times.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 28 taken 23 times.
48 if (status != FX_SUCCESS)
192 {
193
194 2 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
195
196 /* Release media protection. */
197 1 FX_UNPROTECT
198
199 /* Return the bad status. */
200 2 return(status);
201 }
202
203 /* End transaction. */
204 46 status = _fx_fault_tolerant_transaction_end(media_ptr);
205 #endif /* FX_ENABLE_FAULT_TOLERANT */
206
207 /* Release media protection. */
208 26 FX_UNPROTECT
209
210 /* File attribute set is complete, return status. */
211 47 return(status);
212 }
213
214