ReactOS 0.4.15-dev-8061-g57b775e
timesup.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1989-2000 Microsoft Corporation
4
5Module Name:
6
7 TimeSup.c
8
9Abstract:
10
11 This module implements the Fat Time conversion support routines
12
13
14--*/
15
16#include "fatprocs.h"
17
18#ifdef ALLOC_PRAGMA
19#pragma alloc_text(PAGE, FatNtTimeToFatTime)
20#pragma alloc_text(PAGE, FatFatDateToNtTime)
21#pragma alloc_text(PAGE, FatFatTimeToNtTime)
22#pragma alloc_text(PAGE, FatGetCurrentFatTime)
23#endif
24
25_Success_(return != FALSE)
27FatNtTimeToFatTime (
28 _In_ PIRP_CONTEXT IrpContext,
33 )
34
35/*++
36
37Routine Description:
38
39 This routine converts an NtTime value to its corresponding Fat time value.
40
41Arguments:
42
43 NtTime - Supplies the Nt GMT Time value to convert from
44
45 Rounding - Indicates whether the NT time should be rounded up to a FAT boundary.
46 This should only be done *once* in the lifetime of a timestamp (important
47 for tunneling, which will cause a timestamp to pass through at least twice).
48 If true, rounded up. If false, rounded down to 10ms boundary. This obeys
49 the rules for non-creation time and creation times (respectively).
50
51 FatTime - Receives the equivalent Fat time value
52
53 TenMsecs - Optionally receive the number of tens of milliseconds the NtTime, after
54 any rounding, is greater than the FatTime
55
56Return Value:
57
58 BOOLEAN - TRUE if the Nt time value is within the range of Fat's
59 time range, and FALSE otherwise
60
61--*/
62
63{
65
66 PAGED_CODE();
67
68 //
69 // Convert the input to the a time field record.
70 //
71
72 if (Rounding) {
73
74 //
75 // Add almost two seconds to round up to the nearest double second.
76 //
77
79 }
80
82
84
85 //
86 // Check the range of the date found in the time field record
87 //
88
89 if ((TimeFields.Year < 1980) || (TimeFields.Year > (1980 + 127))) {
90
92
93 return FALSE;
94 }
95
96 //
97 // The year will fit in Fat so simply copy over the information
98 //
99
100 FatTime->Time.DoubleSeconds = (USHORT)(TimeFields.Second / 2);
101 FatTime->Time.Minute = (USHORT)(TimeFields.Minute);
102 FatTime->Time.Hour = (USHORT)(TimeFields.Hour);
103
104 FatTime->Date.Year = (USHORT)(TimeFields.Year - 1980);
105 FatTime->Date.Month = (USHORT)(TimeFields.Month);
106 FatTime->Date.Day = (USHORT)(TimeFields.Day);
107
108 if (TenMsecs) {
109
110 if (!Rounding) {
111
112 //
113 // If the number of seconds was not divisible by two, then there
114 // is another second of time (1 sec, 3 sec, etc.) Note we round down
115 // the number of milleconds onto tens of milleseconds boundaries.
116 //
117
118#ifdef _MSC_VER
119#pragma warning( push )
120#pragma warning( disable: 4244 )
121#endif
123 ((TimeFields.Second % 2) * 100);
124#ifdef _MSC_VER
125#pragma warning( pop )
126#endif
127 } else {
128
129 //
130 // If we rounded up, we have in effect changed the NT time. Therefore,
131 // it does not differ from the FAT time.
132 //
133
134 *TenMsecs = 0;
135 }
136 }
137
138 if (Rounding) {
139
140 //
141 // Slice off non-FAT boundary time and convert back to 64bit form
142 //
143
146
147 } else {
148
149 //
150 // Round down to 10ms boundary
151 //
152
154 }
155
156 //
157 // Convert back to NT time
158 //
159
161
163
164 UNREFERENCED_PARAMETER( IrpContext );
165
166 return TRUE;
167}
168
169
172 _In_ PIRP_CONTEXT IrpContext,
173 _In_ FAT_DATE FatDate
174 )
175
176/*++
177
178Routine Description:
179
180 This routine converts a Fat datev value to its corresponding Nt GMT
181 Time value.
182
183Arguments:
184
185 FatDate - Supplies the Fat Date to convert from
186
187Return Value:
188
189 LARGE_INTEGER - Receives the corresponding Nt Time value
190
191--*/
192
193{
196
197 PAGED_CODE();
198
199 //
200 // Pack the input time/date into a time field record
201 //
202
203 TimeFields.Year = (USHORT)(FatDate.Year + 1980);
204 TimeFields.Month = (USHORT)(FatDate.Month);
205 TimeFields.Day = (USHORT)(FatDate.Day);
210
211 //
212 // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
213 // if we were given a bogus time.
214 //
215
217
218 Time.LowPart = 0;
219 Time.HighPart = 0;
220
221 } else {
222
224 }
225
226 return Time;
227
228 UNREFERENCED_PARAMETER( IrpContext );
229}
230
231
234 _In_ PIRP_CONTEXT IrpContext,
236 _In_ UCHAR TenMilliSeconds
237 )
238
239/*++
240
241Routine Description:
242
243 This routine converts a Fat time value pair to its corresponding Nt GMT
244 Time value.
245
246Arguments:
247
248 FatTime - Supplies the Fat Time to convert from
249
250 TenMilliSeconds - A 10 Milisecond resolution
251
252Return Value:
253
254 LARGE_INTEGER - Receives the corresponding Nt GMT Time value
255
256--*/
257
258{
261
262 PAGED_CODE();
263
264 //
265 // Pack the input time/date into a time field record
266 //
267
268 TimeFields.Year = (USHORT)(FatTime.Date.Year + 1980);
269 TimeFields.Month = (USHORT)(FatTime.Date.Month);
270 TimeFields.Day = (USHORT)(FatTime.Date.Day);
271 TimeFields.Hour = (USHORT)(FatTime.Time.Hour);
272 TimeFields.Minute = (USHORT)(FatTime.Time.Minute);
273 TimeFields.Second = (USHORT)(FatTime.Time.DoubleSeconds * 2);
274
275 if (TenMilliSeconds != 0) {
276
277 TimeFields.Second += (USHORT)(TenMilliSeconds / 100);
278 TimeFields.Milliseconds = (USHORT)((TenMilliSeconds % 100) * 10);
279
280 } else {
281
283 }
284
285 //
286 // If the second value is greater than 59 then we truncate it to 0.
287 // Note that this can't happen with a proper FAT timestamp.
288 //
289
290 if (TimeFields.Second > 59) {
291
292 TimeFields.Second = 0;
293 }
294
295 //
296 // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
297 // if we were given a bogus time.
298 //
299
301
302 Time.LowPart = 0;
303 Time.HighPart = 0;
304
305 } else {
306
308 }
309
310 return Time;
311
312 UNREFERENCED_PARAMETER( IrpContext );
313}
314
315
318 _In_ PIRP_CONTEXT IrpContext
319 )
320
321/*++
322
323Routine Description:
324
325 This routine returns the current system time in Fat time
326
327Arguments:
328
329Return Value:
330
331 FAT_TIME_STAMP - Receives the current system time
332
333--*/
334
335{
339
340 PAGED_CODE();
341
342 //
343 // Get the current system time, and map it into a time field record.
344 //
345
347
349
350 //
351 // Always add almost two seconds to round up to the nearest double second.
352 //
353
355
357
358 //
359 // Now simply copy over the information
360 //
361
362 FatTime.Time.DoubleSeconds = (USHORT)(TimeFields.Second / 2);
363 FatTime.Time.Minute = (USHORT)(TimeFields.Minute);
364 FatTime.Time.Hour = (USHORT)(TimeFields.Hour);
365
366 FatTime.Date.Year = (USHORT)(TimeFields.Year - 1980);
367 FatTime.Date.Month = (USHORT)(TimeFields.Month);
368 FatTime.Date.Day = (USHORT)(TimeFields.Day);
369
370 UNREFERENCED_PARAMETER( IrpContext );
371
372 return FatTime;
373}
374
375
#define PAGED_CODE()
unsigned char BOOLEAN
#define VOID
Definition: acefi.h:82
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ExSystemTimeToLocalTime(SysTime, LocTime)
Definition: env_spec_w32.h:729
#define AlmostTwoSeconds
Definition: fatdata.h:125
_In_ PLARGE_INTEGER NtTime
Definition: fatprocs.h:1914
_In_ PLARGE_INTEGER _In_ BOOLEAN _Out_ PFAT_TIME_STAMP _Out_opt_ PUCHAR TenMsecs
Definition: fatprocs.h:1918
_In_ PLARGE_INTEGER _In_ BOOLEAN _Out_ PFAT_TIME_STAMP FatTime
Definition: fatprocs.h:1916
_In_ PLARGE_INTEGER _In_ BOOLEAN Rounding
Definition: fatprocs.h:1915
static PLARGE_INTEGER Time
Definition: time.c:105
static PTIME_FIELDS TimeFields
Definition: time.c:104
#define _Out_opt_
Definition: ms_sal.h:346
#define _Success_(expr)
Definition: ms_sal.h:259
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
unsigned short USHORT
Definition: pedump.c:61
Definition: fat.h:274
USHORT Milliseconds
Definition: env_spec_w32.h:717
FAT_TIME_STAMP FatGetCurrentFatTime(_In_ PIRP_CONTEXT IrpContext)
Definition: timesup.c:317
LARGE_INTEGER FatFatTimeToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_TIME_STAMP FatTime, _In_ UCHAR TenMilliSeconds)
Definition: timesup.c:233
LARGE_INTEGER FatFatDateToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_DATE FatDate)
Definition: timesup.c:171
unsigned char * PUCHAR
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
unsigned char UCHAR
Definition: xmlstorage.h:181