grub的date命令实现在grub-core/commands/date.c 中
GRUB_MOD_INIT(date)
{
cmd =
grub_register_command ("date", grub_cmd_date,
N_("[[year-]month-day] [hour:minute[:second]]"),
N_("Display/set current datetime."));
}
可见回调函数是grub_cmd_date
static grub_err_t
grub_cmd_date (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
struct grub_datetime datetime;
int limit[6][2] = {{1980, 2079}, {1, 12}, {1, 31}, {0, 23}, {0, 59}, {0, 59}};
int value[6], mask;
if (argc == 0)
{
if (grub_get_datetime (&datetime))
return grub_errno;
grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second,
grub_get_weekday_name (&datetime));
return 0;
}
}
我们常常直接在grub的命令行中直接输入date命令,因此这种情况下argc是0,直接调用grub_get_datetime
grub_err_t
grub_get_datetime (struct grub_datetime *datetime)
{
grub_efi_status_t status;
struct grub_efi_time efi_time;
status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
&efi_time, 0);
if (status)
return grub_error (GRUB_ERR_INVALID_COMMAND,
"can\'t get datetime using efi");
else
{
datetime->year = efi_time.year;
datetime->month = efi_time.month;
datetime->day = efi_time.day;
datetime->hour = efi_time.hour;
datetime->minute = efi_time.minute;
datetime->second = efi_time.second;
}
return 0;
}
最终在grub_get_datetime 中直接调用bios的runtime_service 来获取时间,同理kernel中也是通过bios的runtime_service来获取时间,如果怀疑kernel的bios提供的runtime_service 有问题,可以在grub中试试看。方便定位问题。
GRUB_MOD_INIT(date)
{
cmd =
grub_register_command ("date", grub_cmd_date,
N_("[[year-]month-day] [hour:minute[:second]]"),
N_("Display/set current datetime."));
}
可见回调函数是grub_cmd_date
static grub_err_t
grub_cmd_date (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
struct grub_datetime datetime;
int limit[6][2] = {{1980, 2079}, {1, 12}, {1, 31}, {0, 23}, {0, 59}, {0, 59}};
int value[6], mask;
if (argc == 0)
{
if (grub_get_datetime (&datetime))
return grub_errno;
grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second,
grub_get_weekday_name (&datetime));
return 0;
}
}
我们常常直接在grub的命令行中直接输入date命令,因此这种情况下argc是0,直接调用grub_get_datetime
grub_err_t
grub_get_datetime (struct grub_datetime *datetime)
{
grub_efi_status_t status;
struct grub_efi_time efi_time;
status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
&efi_time, 0);
if (status)
return grub_error (GRUB_ERR_INVALID_COMMAND,
"can\'t get datetime using efi");
else
{
datetime->year = efi_time.year;
datetime->month = efi_time.month;
datetime->day = efi_time.day;
datetime->hour = efi_time.hour;
datetime->minute = efi_time.minute;
datetime->second = efi_time.second;
}
return 0;
}
最终在grub_get_datetime 中直接调用bios的runtime_service 来获取时间,同理kernel中也是通过bios的runtime_service来获取时间,如果怀疑kernel的bios提供的runtime_service 有问题,可以在grub中试试看。方便定位问题。