Changeset View
Changeset View
Standalone View
Standalone View
head/sys/boot/efi/libefi/time.c
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// (#defines From FreeBSD 3.2 lib/libc/stdtime/tzfile.h) | // (#defines From FreeBSD 3.2 lib/libc/stdtime/tzfile.h) | ||||
*/ | */ | ||||
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) | #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) | ||||
#define SECSPERHOUR ( 60*60 ) | #define SECSPERHOUR ( 60*60 ) | ||||
#define SECSPERDAY (24 * SECSPERHOUR) | #define SECSPERDAY (24 * SECSPERHOUR) | ||||
void | |||||
efi_time_init(void) | |||||
{ | |||||
} | |||||
void | |||||
efi_time_fini(void) | |||||
{ | |||||
} | |||||
static time_t | |||||
efi_time(EFI_TIME *ETime) | |||||
{ | |||||
/* | /* | ||||
// These arrays give the cumulative number of days up to the first of the | // These arrays give the cumulative number of days up to the first of the | ||||
// month number used as the index (1 -> 12) for regular and leap years. | // month number used as the index (1 -> 12) for regular and leap years. | ||||
// The value at index 13 is for the whole year. | // The value at index 13 is for the whole year. | ||||
*/ | */ | ||||
static time_t CumulativeDays[2][14] = { | static const time_t CumulativeDays[2][14] = { | ||||
{0, | {0, | ||||
0, | 0, | ||||
31, | 31, | ||||
31 + 28, | 31 + 28, | ||||
31 + 28 + 31, | 31 + 28 + 31, | ||||
31 + 28 + 31 + 30, | 31 + 28 + 31 + 30, | ||||
31 + 28 + 31 + 30 + 31, | 31 + 28 + 31 + 30 + 31, | ||||
31 + 28 + 31 + 30 + 31 + 30, | 31 + 28 + 31 + 30 + 31 + 30, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31, | 31 + 28 + 31 + 30 + 31 + 30 + 31, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, | ||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }, | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }, | ||||
{0, | {0, | ||||
0, | 0, | ||||
31, | 31, | ||||
31 + 29, | 31 + 29, | ||||
31 + 29 + 31, | 31 + 29 + 31, | ||||
31 + 29 + 31 + 30, | 31 + 29 + 31 + 30, | ||||
31 + 29 + 31 + 30 + 31, | 31 + 29 + 31 + 30 + 31, | ||||
31 + 29 + 31 + 30 + 31 + 30, | 31 + 29 + 31 + 30 + 31 + 30, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31, | 31 + 29 + 31 + 30 + 31 + 30 + 31, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31, | 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30, | 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, | 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, | 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, | ||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }}; | 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }}; | ||||
void | |||||
efi_time_init(void) | |||||
{ | |||||
} | |||||
void | |||||
efi_time_fini(void) | |||||
{ | |||||
} | |||||
void | |||||
to_efi_time(EFI_TIME *efi_time, time_t time) | |||||
{ | |||||
if (time >= 0) { | |||||
for (efi_time->Year = 1970; | |||||
time > CumulativeDays[isleap(efi_time->Year)][13] * SECSPERDAY; | |||||
time -= CumulativeDays[isleap(efi_time->Year)][13] * SECSPERDAY, | |||||
efi_time->Year++); | |||||
for (efi_time->Month = 0; | |||||
time > CumulativeDays[isleap(efi_time->Year)][efi_time->Month] * | |||||
SECSPERDAY; | |||||
efi_time->Month++); | |||||
time -= CumulativeDays[isleap(efi_time->Year)][efi_time->Month - 1] * | |||||
SECSPERDAY; | |||||
for (efi_time->Day = 0; time > SECSPERDAY; | |||||
time -= SECSPERDAY, efi_time->Day++); | |||||
for (efi_time->Hour = 0; time > SECSPERHOUR; | |||||
time -= SECSPERHOUR, efi_time->Hour++); | |||||
for (efi_time->Minute = 0; time > 60; | |||||
time -= 60, efi_time->Minute++); | |||||
efi_time->Second = time; | |||||
efi_time->Nanosecond = 0; | |||||
efi_time->TimeZone = 0; | |||||
efi_time->Daylight = 0; | |||||
} else { | |||||
memset(efi_time, 0, sizeof(EFI_TIME)); | |||||
} | |||||
} | |||||
time_t | |||||
from_efi_time(EFI_TIME *ETime) | |||||
{ | |||||
time_t UTime; | time_t UTime; | ||||
int Year; | int Year; | ||||
/* | /* | ||||
// Do a santity check | // Do a santity check | ||||
*/ | */ | ||||
if ( ETime->Year < 1998 || ETime->Year > 2099 || | if ( ETime->Year < 1998 || ETime->Year > 2099 || | ||||
ETime->Month == 0 || ETime->Month > 12 || | ETime->Month == 0 || ETime->Month > 12 || | ||||
ETime->Day == 0 || ETime->Month > 31 || | ETime->Day == 0 || ETime->Month > 31 || | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | EFI_GetTimeOfDay( | ||||
Status = RS->GetTime(&EfiTime, &Capabilities); | Status = RS->GetTime(&EfiTime, &Capabilities); | ||||
if (EFI_ERROR(Status)) | if (EFI_ERROR(Status)) | ||||
return (-1); | return (-1); | ||||
/* | /* | ||||
// Convert to UNIX time (ie seconds since the epoch | // Convert to UNIX time (ie seconds since the epoch | ||||
*/ | */ | ||||
tp->tv_sec = efi_time( &EfiTime ); | tp->tv_sec = from_efi_time( &EfiTime ); | ||||
tp->tv_usec = 0; /* EfiTime.Nanosecond * 1000; */ | tp->tv_usec = 0; /* EfiTime.Nanosecond * 1000; */ | ||||
/* | /* | ||||
// Do something with the timezone if needed | // Do something with the timezone if needed | ||||
*/ | */ | ||||
if (tzp) { | if (tzp) { | ||||
tzp->tz_minuteswest = | tzp->tz_minuteswest = | ||||
Show All 27 Lines |