datetime.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = grub_efi_system_table->runtime_services->get_time (&efi_time, 0);
  32. if (status)
  33. return grub_error (GRUB_ERR_INVALID_COMMAND,
  34. "can\'t get datetime using efi");
  35. else
  36. {
  37. datetime->year = efi_time.year;
  38. datetime->month = efi_time.month;
  39. datetime->day = efi_time.day;
  40. datetime->hour = efi_time.hour;
  41. datetime->minute = efi_time.minute;
  42. datetime->second = efi_time.second;
  43. }
  44. return 0;
  45. }
  46. grub_err_t
  47. grub_set_datetime (struct grub_datetime *datetime)
  48. {
  49. grub_efi_status_t status;
  50. struct grub_efi_time efi_time;
  51. status = grub_efi_system_table->runtime_services->get_time (&efi_time, 0);
  52. if (status)
  53. return grub_error (GRUB_ERR_INVALID_COMMAND,
  54. "can\'t get datetime using efi");
  55. efi_time.year = datetime->year;
  56. efi_time.month = datetime->month;
  57. efi_time.day = datetime->day;
  58. efi_time.hour = datetime->hour;
  59. efi_time.minute = datetime->minute;
  60. efi_time.second = datetime->second;
  61. status = grub_efi_system_table->runtime_services->set_time (&efi_time);
  62. if (status)
  63. return grub_error (GRUB_ERR_INVALID_COMMAND,
  64. "can\'t set datetime using efi");
  65. return 0;
  66. }