lsxen.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2011 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. #include <grub/dl.h>
  19. #include <grub/misc.h>
  20. #include <grub/command.h>
  21. #include <grub/i18n.h>
  22. #include <grub/xen.h>
  23. #include <grub/term.h>
  24. GRUB_MOD_LICENSE ("GPLv3+");
  25. static int
  26. hook (const char *dir, void *hook_data __attribute__ ((unused)))
  27. {
  28. grub_printf ("%s\n", dir);
  29. return 0;
  30. }
  31. static grub_err_t
  32. grub_cmd_lsxen (grub_command_t cmd __attribute__ ((unused)),
  33. int argc, char **args)
  34. {
  35. char *dir;
  36. grub_err_t err;
  37. char *buf;
  38. if (argc >= 1)
  39. return grub_xenstore_dir (args[0], hook, NULL);
  40. buf = grub_xenstore_get_file ("domid", NULL);
  41. if (!buf)
  42. return grub_errno;
  43. dir = grub_xasprintf ("/local/domain/%s", buf);
  44. grub_free (buf);
  45. err = grub_xenstore_dir (dir, hook, NULL);
  46. grub_free (dir);
  47. return err;
  48. }
  49. static grub_err_t
  50. grub_cmd_catxen (grub_command_t cmd __attribute__ ((unused)),
  51. int argc, char **args)
  52. {
  53. const char *dir = "domid";
  54. char *buf;
  55. if (argc >= 1)
  56. dir = args[0];
  57. buf = grub_xenstore_get_file (dir, NULL);
  58. if (!buf)
  59. return grub_errno;
  60. grub_xputs (buf);
  61. grub_xputs ("\n");
  62. grub_free (buf);
  63. return GRUB_ERR_NONE;
  64. }
  65. static grub_command_t cmd_ls, cmd_cat;
  66. GRUB_MOD_INIT (lsxen)
  67. {
  68. cmd_ls = grub_register_command ("xen_ls", grub_cmd_lsxen, N_("[DIR]"),
  69. N_("List Xen storage."));
  70. cmd_cat = grub_register_command ("xen_cat", grub_cmd_catxen, N_("[DIR]"),
  71. N_("List Xen storage."));
  72. }
  73. GRUB_MOD_FINI (lsxen)
  74. {
  75. grub_unregister_command (cmd_ls);
  76. grub_unregister_command (cmd_cat);
  77. }