GCC Code Coverage Report


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

fx_file_date_time_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_directory.h"
30 #include "fx_file.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _fx_file_date_time_set PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* William E. Lamie, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function sets the specified file's date and time with the */
46 /* values provided. */
47 /* */
48 /* INPUT */
49 /* */
50 /* media_ptr Media control block pointer */
51 /* file_name File name pointer */
52 /* year Year */
53 /* month Month */
54 /* day Day */
55 /* hour Hour */
56 /* minute Minute */
57 /* second Second */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* return status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _fx_directory_search Search for the file name in */
66 /* the directory structure */
67 /* _fx_directory_entry_write Write the directory entry */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* */
73 /**************************************************************************/
74 123 UINT _fx_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
75 UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
76 {
77
78 UINT status;
79 FX_DIR_ENTRY dir_entry;
80
81
82 /* Setup pointer to media name buffer. */
83 123 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
84
85 /* Clear the short name string. */
86 123 dir_entry.fx_dir_entry_short_name[0] = 0;
87
88 /* Check the media to make sure it is open. */
89
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 114 times.
123 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
90 {
91
92 /* Return the media not opened error. */
93 9 return(FX_MEDIA_NOT_OPEN);
94 }
95
96 /* If trace is enabled, insert this event into the trace buffer. */
97 FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_DATE_TIME_SET, media_ptr, file_name, year, month, FX_TRACE_FILE_EVENTS, 0, 0)
98
99 /* Protect against other threads accessing the media. */
100 58 FX_PROTECT
101
102 /* Search the system for the supplied directory name. */
103 114 status = _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
104
105 /* Determine if the search was successful. */
106
4/4
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 7 taken 52 times.
✓ Branch 6 → 7 taken 5 times.
✓ Branch 6 → 9 taken 53 times.
114 if (status != FX_SUCCESS)
107 {
108
109 /* Release media protection. */
110 5 FX_UNPROTECT
111
112 /* Return the error code. */
113 9 return(status);
114 }
115
116 /* Set the new time and date. */
117 105 dir_entry.fx_dir_entry_time = (hour << FX_HOUR_SHIFT) | (minute << FX_MINUTE_SHIFT) | (second / 2);
118 105 dir_entry.fx_dir_entry_date = ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) | (month << FX_MONTH_SHIFT) | day;
119
120 /* Write the directory entry to the media. */
121 105 status = _fx_directory_entry_write(media_ptr, &dir_entry);
122
123 /* Release media protection. */
124 53 FX_UNPROTECT
125
126 /* Directory information write is complete, return status. */
127 105 return(status);
128 }
129
130