1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** FileX Component */
16 /** */
17 /** File */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define FX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "fx_api.h"
28 #include "fx_file.h"
29
30
31 FX_CALLER_CHECKING_EXTERNS
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _fxe_file_date_time_set PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function checks for errors in the file date/time set service. */
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_file_date_time_set Actual file date/time set */
66 /* service */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Application Code */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
77 /* 09-30-2020 William E. Lamie Modified comment(s), */
78 /* resulting in version 6.1 */
79 /* */
80 /**************************************************************************/
_fxe_file_date_time_set(FX_MEDIA * media_ptr,CHAR * file_name,UINT year,UINT month,UINT day,UINT hour,UINT minute,UINT second)81 UINT _fxe_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
82 UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
83 {
84
85 UINT status;
86
87
88 /* Check for a NULL media or file name pointer. */
89 if ((media_ptr == FX_NULL) || (file_name == FX_NULL))
90 {
91 return(FX_PTR_ERROR);
92 }
93
94 /* Check for invalid year. */
95 if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR))
96 {
97 return(FX_INVALID_YEAR);
98 }
99
100 /* Check for invalid day. */
101 if (day < 1)
102 {
103 return(FX_INVALID_DAY);
104 }
105
106 /* Check for invalid day. */
107 switch (month)
108 {
109
110 case 1:
111 {
112
113 /* Check for 31 days. */
114 if (day > 31)
115 {
116 return(FX_INVALID_DAY);
117 }
118 break;
119 }
120
121 case 2:
122 {
123
124 /* Check for leap year. */
125 if ((year % 4) == 0)
126 {
127
128 /* Leap year, February has 29 days. */
129 if (day > 29)
130 {
131 return(FX_INVALID_DAY);
132 }
133 }
134 else
135 {
136
137 /* Otherwise, non-leap year. February has
138 28 days. */
139 if (day > 28)
140 {
141 return(FX_INVALID_DAY);
142 }
143 }
144 break;
145 }
146
147 case 3:
148 {
149
150 /* Check for 31 days. */
151 if (day > 31)
152 {
153 return(FX_INVALID_DAY);
154 }
155 break;
156 }
157
158 case 4:
159 {
160
161 /* Check for 30 days. */
162 if (day > 30)
163 {
164 return(FX_INVALID_DAY);
165 }
166 break;
167 }
168
169 case 5:
170 {
171
172 /* Check for 31 days. */
173 if (day > 31)
174 {
175 return(FX_INVALID_DAY);
176 }
177 break;
178 }
179
180 case 6:
181 {
182
183 /* Check for 30 days. */
184 if (day > 30)
185 {
186 return(FX_INVALID_DAY);
187 }
188 break;
189 }
190
191 case 7:
192 {
193
194 /* Check for 31 days. */
195 if (day > 31)
196 {
197 return(FX_INVALID_DAY);
198 }
199 break;
200 }
201
202 case 8:
203 {
204
205 /* Check for 31 days. */
206 if (day > 31)
207 {
208 return(FX_INVALID_DAY);
209 }
210 break;
211 }
212
213 case 9:
214 {
215
216 /* Check for 30 days. */
217 if (day > 30)
218 {
219 return(FX_INVALID_DAY);
220 }
221 break;
222 }
223
224 case 10:
225 {
226
227 /* Check for 31 days. */
228 if (day > 31)
229 {
230 return(FX_INVALID_DAY);
231 }
232 break;
233 }
234
235 case 11:
236 {
237
238 /* Check for 30 days. */
239 if (day > 30)
240 {
241 return(FX_INVALID_DAY);
242 }
243 break;
244 }
245
246 case 12:
247 {
248
249 /* Check for 31 days. */
250 if (day > 31)
251 {
252 return(FX_INVALID_DAY);
253 }
254 break;
255 }
256
257 default:
258
259 /* Invalid month. */
260 return(FX_INVALID_MONTH);
261 }
262
263 /* Check for invalid hour. */
264 if (hour > FX_MAXIMUM_HOUR)
265 {
266 return(FX_INVALID_HOUR);
267 }
268
269 /* Check for invalid minute. */
270 if (minute > FX_MAXIMUM_MINUTE)
271 {
272 return(FX_INVALID_MINUTE);
273 }
274
275 /* Check for invalid second. */
276 if (second > FX_MAXIMUM_SECOND)
277 {
278 return(FX_INVALID_SECOND);
279 }
280
281 /* Check for a valid caller. */
282 FX_CALLER_CHECKING_CODE
283
284 /* Call actual file date/time set service. */
285 status = _fx_file_date_time_set(media_ptr, file_name,
286 year, month, day,
287 hour, minute, second);
288
289 /* Return status to the caller. */
290 return(status);
291 }
292
293