3 Copyright (c) 1989-2000 Microsoft Corporation
11 This module implements the Fat Time conversion support routines
19 #pragma alloc_text(PAGE, FatNtTimeToFatTime)
20 #pragma alloc_text(PAGE, FatFatDateToNtTime)
21 #pragma alloc_text(PAGE, FatFatTimeToNtTime)
22 #pragma alloc_text(PAGE, FatGetCurrentFatTime)
25 _Success_(return != FALSE
)
28 _In_ PIRP_CONTEXT IrpContext
,
29 _In_ PLARGE_INTEGER NtTime
,
30 _In_ BOOLEAN Rounding
,
31 _Out_ PFAT_TIME_STAMP FatTime
,
32 _Out_opt_ PUCHAR TenMsecs
39 This routine converts an NtTime value to its corresponding Fat time value.
43 NtTime - Supplies the Nt GMT Time value to convert from
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).
51 FatTime - Receives the equivalent Fat time value
53 TenMsecs - Optionally receive the number of tens of milliseconds the NtTime, after
54 any rounding, is greater than the FatTime
58 BOOLEAN - TRUE if the Nt time value is within the range of Fat's
59 time range, and FALSE otherwise
64 TIME_FIELDS TimeFields
;
69 // Convert the input to the a time field record.
75 // Add almost two seconds to round up to the nearest double second.
78 NtTime
->QuadPart
= NtTime
->QuadPart
+ AlmostTwoSeconds
;
81 ExSystemTimeToLocalTime( NtTime
, NtTime
);
83 RtlTimeToTimeFields( NtTime
, &TimeFields
);
86 // Check the range of the date found in the time field record
89 if ((TimeFields
.Year
< 1980) || (TimeFields
.Year
> (1980 + 127))) {
91 ExLocalTimeToSystemTime( NtTime
, NtTime
);
97 // The year will fit in Fat so simply copy over the information
100 FatTime
->Time
.DoubleSeconds
= (USHORT
)(TimeFields
.Second
/ 2);
101 FatTime
->Time
.Minute
= (USHORT
)(TimeFields
.Minute
);
102 FatTime
->Time
.Hour
= (USHORT
)(TimeFields
.Hour
);
104 FatTime
->Date
.Year
= (USHORT
)(TimeFields
.Year
- 1980);
105 FatTime
->Date
.Month
= (USHORT
)(TimeFields
.Month
);
106 FatTime
->Date
.Day
= (USHORT
)(TimeFields
.Day
);
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.
119 #pragma warning( push )
120 #pragma warning( disable: 4244 )
122 *TenMsecs
= (TimeFields
.Milliseconds
/ 10) +
123 ((TimeFields
.Second
% 2) * 100);
125 #pragma warning( pop )
130 // If we rounded up, we have in effect changed the NT time. Therefore,
131 // it does not differ from the FAT time.
141 // Slice off non-FAT boundary time and convert back to 64bit form
144 TimeFields
.Milliseconds
= 0;
145 TimeFields
.Second
-= TimeFields
.Second
% 2;
150 // Round down to 10ms boundary
153 TimeFields
.Milliseconds
-= TimeFields
.Milliseconds
% 10;
157 // Convert back to NT time
160 (VOID
) RtlTimeFieldsToTime(&TimeFields
, NtTime
);
162 ExLocalTimeToSystemTime( NtTime
, NtTime
);
164 UNREFERENCED_PARAMETER( IrpContext
);
172 _In_ PIRP_CONTEXT IrpContext
,
173 _In_ FAT_DATE FatDate
180 This routine converts a Fat datev value to its corresponding Nt GMT
185 FatDate - Supplies the Fat Date to convert from
189 LARGE_INTEGER - Receives the corresponding Nt Time value
194 TIME_FIELDS TimeFields
;
200 // Pack the input time/date into a time field record
203 TimeFields
.Year
= (USHORT
)(FatDate
.Year
+ 1980);
204 TimeFields
.Month
= (USHORT
)(FatDate
.Month
);
205 TimeFields
.Day
= (USHORT
)(FatDate
.Day
);
206 TimeFields
.Hour
= (USHORT
)0;
207 TimeFields
.Minute
= (USHORT
)0;
208 TimeFields
.Second
= (USHORT
)0;
209 TimeFields
.Milliseconds
= (USHORT
)0;
212 // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
213 // if we were given a bogus time.
216 if (!RtlTimeFieldsToTime( &TimeFields
, &Time
)) {
223 ExLocalTimeToSystemTime( &Time
, &Time
);
228 UNREFERENCED_PARAMETER( IrpContext
);
234 _In_ PIRP_CONTEXT IrpContext
,
235 _In_ FAT_TIME_STAMP FatTime
,
236 _In_ UCHAR TenMilliSeconds
243 This routine converts a Fat time value pair to its corresponding Nt GMT
248 FatTime - Supplies the Fat Time to convert from
250 TenMilliSeconds - A 10 Milisecond resolution
254 LARGE_INTEGER - Receives the corresponding Nt GMT Time value
259 TIME_FIELDS TimeFields
;
265 // Pack the input time/date into a time field record
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);
275 if (TenMilliSeconds
!= 0) {
277 TimeFields
.Second
+= (USHORT
)(TenMilliSeconds
/ 100);
278 TimeFields
.Milliseconds
= (USHORT
)((TenMilliSeconds
% 100) * 10);
282 TimeFields
.Milliseconds
= (USHORT
)0;
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.
290 if (TimeFields
.Second
> 59) {
292 TimeFields
.Second
= 0;
296 // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
297 // if we were given a bogus time.
300 if (!RtlTimeFieldsToTime( &TimeFields
, &Time
)) {
307 ExLocalTimeToSystemTime( &Time
, &Time
);
312 UNREFERENCED_PARAMETER( IrpContext
);
317 FatGetCurrentFatTime (
318 _In_ PIRP_CONTEXT IrpContext
325 This routine returns the current system time in Fat time
331 FAT_TIME_STAMP - Receives the current system time
337 TIME_FIELDS TimeFields
;
338 FAT_TIME_STAMP FatTime
;
343 // Get the current system time, and map it into a time field record.
346 KeQuerySystemTime( &Time
);
348 ExSystemTimeToLocalTime( &Time
, &Time
);
351 // Always add almost two seconds to round up to the nearest double second.
354 Time
.QuadPart
= Time
.QuadPart
+ AlmostTwoSeconds
;
356 (VOID
)RtlTimeToTimeFields( &Time
, &TimeFields
);
359 // Now simply copy over the information
362 FatTime
.Time
.DoubleSeconds
= (USHORT
)(TimeFields
.Second
/ 2);
363 FatTime
.Time
.Minute
= (USHORT
)(TimeFields
.Minute
);
364 FatTime
.Time
.Hour
= (USHORT
)(TimeFields
.Hour
);
366 FatTime
.Date
.Year
= (USHORT
)(TimeFields
.Year
- 1980);
367 FatTime
.Date
.Month
= (USHORT
)(TimeFields
.Month
);
368 FatTime
.Date
.Day
= (USHORT
)(TimeFields
.Day
);
370 UNREFERENCED_PARAMETER( IrpContext
);