GCC Code Coverage Report


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

fx_directory_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 /** 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 #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_directory_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 directory. If */
51 /* found, the attribute set request is valid and the directory will */
52 /* be modified with the new attributes. Otherwise, if the directory */
53 /* is not found, the appropriate error code is returned to the caller. */
54 /* */
55 /* INPUT */
56 /* */
57 /* media_ptr Media control block pointer */
58 /* directory_name Directory name pointer */
59 /* attributes New dir 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 91 UINT _fx_directory_attributes_set(FX_MEDIA *media_ptr, CHAR *directory_name, UINT attributes)
82 {
83
84 UINT status;
85 FX_DIR_ENTRY dir_entry;
86
87 #ifndef FX_MEDIA_STATISTICS_DISABLE
88
89 /* Increment the number of times this service has been called. */
90 91 media_ptr -> fx_media_directory_attributes_sets++;
91 #endif
92
93 /* Setup pointer to media name buffer. */
94 91 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
95
96 /* Clear the short name string. */
97 91 dir_entry.fx_dir_entry_short_name[0] = 0;
98
99 /* Check the media to make sure it is open. */
100
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 82 times.
91 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
101 {
102
103 /* Return the media not opened error. */
104 9 return(FX_MEDIA_NOT_OPEN);
105 }
106
107 /* If trace is enabled, insert this event into the trace buffer. */
108 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_ATTRIBUTES_SET, media_ptr, directory_name, attributes, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
109
110 /* Protect against other threads accessing the media. */
111 44 FX_PROTECT
112
113 /* Check for write protect at the media level (set by driver). */
114
4/4
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 34 times.
✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 8 taken 39 times.
82 if (media_ptr -> fx_media_driver_write_protect)
115 {
116
117 /* Release media protection. */
118 5 FX_UNPROTECT
119
120 /* Return write protect error. */
121 9 return(FX_WRITE_PROTECT);
122 }
123
124 /* Search the system for the supplied file name. */
125 73 status = _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
126
127 /* Determine if the search was successful. */
128
4/4
✓ Branch 7 → 8 taken 5 times.
✓ Branch 7 → 9 taken 29 times.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 12 taken 33 times.
73 if (status != FX_SUCCESS)
129 {
130
131 /* Release media protection. */
132 6 FX_UNPROTECT
133
134 /* Return the error code. */
135 11 return(status);
136 }
137
138 /* Check to make sure the found entry is a directory. */
139
4/4
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 25 times.
✓ Branch 12 → 13 taken 5 times.
✓ Branch 12 → 15 taken 28 times.
62 if ((dir_entry.fx_dir_entry_attributes & (UCHAR)(FX_DIRECTORY)) == 0)
140 {
141
142 /* Release media protection. */
143 5 FX_UNPROTECT
144
145 /* Return the not a file error code. */
146 9 return(FX_NOT_DIRECTORY);
147 }
148
149 /* Place the new attributes in the directory entry. Make sure that the
150 directory bit of the attributes is never changed. */
151 53 dir_entry.fx_dir_entry_attributes = (UCHAR)(attributes | FX_DIRECTORY);
152
153 #ifdef FX_ENABLE_FAULT_TOLERANT
154 /* Start transaction. */
155 38 _fx_fault_tolerant_transaction_start(media_ptr);
156 #endif /* FX_ENABLE_FAULT_TOLERANT */
157
158 /* Now write out the directory entry. */
159
160 53 status = _fx_directory_entry_write(media_ptr, &dir_entry);
161
162
163 #ifdef FX_ENABLE_FAULT_TOLERANT
164 /* Check for a bad status. If the return status is not FX_SUCCESS, finish
165 the fault tolerant transaction without flushing the logs. */
166
4/4
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 18 times.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 18 times.
38 if (status != FX_SUCCESS)
167 {
168 2 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
169 }
170 else
171 {
172
173 /* End transaction. */
174 36 status = _fx_fault_tolerant_transaction_end(media_ptr);
175 }
176
177 #endif /* FX_ENABLE_FAULT_TOLERANT */
178
179 /* Release media protection. */
180 16 FX_UNPROTECT
181
182 /* File attribute set is complete, return status. */
183 29 return(status);
184 }
185
186