datetime.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* kern/efi/datetime.c - efi datetime function.
  2. *
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/types.h>
  20. #include <grub/symbol.h>
  21. #include <grub/efi/api.h>
  22. #include <grub/efi/efi.h>
  23. #include <grub/datetime.h>
  24. #include <grub/dl.h>
  25. GRUB_MOD_LICENSE ("GPLv3+");
  26. grub_err_t
  27. grub_get_datetime (struct grub_datetime *datetime)
  28. {
  29. grub_efi_status_t status;
  30. struct grub_efi_time efi_time;
  31. status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
  32. &efi_time, 0);
  33. if (status)
  34. return grub_error (GRUB_ERR_INVALID_COMMAND,
  35. "can\'t get datetime using efi");
  36. else
  37. {
  38. datetime->year = efi_time.year;
  39. datetime->month = efi_time.month;
  40. datetime->day = efi_time.day;
  41. datetime->hour = efi_time.hour;
  42. datetime->minute = efi_time.minute;
  43. datetime->second = efi_time.second;
  44. }
  45. return 0;
  46. }
  47. grub_err_t
  48. grub_set_datetime (struct grub_datetime *datetime)
  49. {
  50. grub_efi_status_t status;
  51. struct grub_efi_time efi_time;
  52. status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
  53. &efi_time, 0);
  54. if (status)
  55. return grub_error (GRUB_ERR_INVALID_COMMAND,
  56. "can\'t get datetime using efi");
  57. efi_time.year = datetime->year;
  58. efi_time.month = datetime->month;
  59. efi_time.day = datetime->day;
  60. efi_time.hour = datetime->hour;
  61. efi_time.minute = datetime->minute;
  62. efi_time.second = datetime->second;
  63. status = efi_call_1 (grub_efi_system_table->runtime_services->set_time,
  64. &efi_time);
  65. if (status)
  66. return grub_error (GRUB_ERR_INVALID_COMMAND,
  67. "can\'t set datetime using efi");
  68. return 0;
  69. }