env.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2003,2005,2006,2007,2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_ENV_HEADER
  19. #define GRUB_ENV_HEADER 1
  20. #include <grub/symbol.h>
  21. #include <grub/err.h>
  22. #include <grub/types.h>
  23. #include <grub/menu.h>
  24. struct grub_env_var;
  25. typedef char *(*grub_env_read_hook_t) (struct grub_env_var *var,
  26. const char *val);
  27. typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var,
  28. const char *val);
  29. struct grub_env_var
  30. {
  31. char *name;
  32. char *value;
  33. grub_env_read_hook_t read_hook;
  34. grub_env_write_hook_t write_hook;
  35. struct grub_env_var *next;
  36. struct grub_env_var **prevp;
  37. int global;
  38. };
  39. grub_err_t grub_env_set (const char *name, const char *val);
  40. char *grub_env_get (const char *name);
  41. void grub_env_unset (const char *name);
  42. void grub_env_iterate (int (*func) (struct grub_env_var *var, void *), void *);
  43. struct grub_env_var *grub_env_find (const char *name);
  44. grub_err_t grub_register_variable_hook (const char *name,
  45. grub_env_read_hook_t read_hook,
  46. grub_env_write_hook_t write_hook);
  47. grub_err_t grub_env_context_open (int export);
  48. grub_err_t grub_env_context_close (void);
  49. grub_err_t grub_env_export (const char *name);
  50. struct menu_pointer
  51. {
  52. grub_menu_t menu;
  53. struct menu_pointer *prev;
  54. };
  55. extern struct menu_pointer *grub_current_menu;
  56. static inline void
  57. grub_env_unset_menu (void)
  58. {
  59. grub_current_menu->menu = 0;
  60. }
  61. static inline grub_menu_t
  62. grub_env_get_menu (void)
  63. {
  64. return grub_current_menu->menu;
  65. }
  66. static inline void
  67. grub_env_set_menu (grub_menu_t nmenu)
  68. {
  69. grub_current_menu->menu = nmenu;
  70. }
  71. #endif /* ! GRUB_ENV_HEADER */