host.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* host.c - Dummy disk driver to provide access to the hosts filesystem */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2007 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. /* When using the disk, make a reference to this module. Otherwise
  20. the user will end up with a useless module :-). */
  21. #include <config-util.h>
  22. #include <config.h>
  23. #include <grub/dl.h>
  24. #include <grub/disk.h>
  25. #include <grub/misc.h>
  26. #include <grub/emu/hostdisk.h>
  27. int grub_disk_host_i_want_a_reference;
  28. static int
  29. grub_host_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
  30. grub_disk_pull_t pull)
  31. {
  32. if (pull != GRUB_DISK_PULL_NONE)
  33. return 0;
  34. if (hook ("host", hook_data))
  35. return 1;
  36. return 0;
  37. }
  38. static grub_err_t
  39. grub_host_open (const char *name, grub_disk_t disk)
  40. {
  41. if (grub_strcmp (name, "host"))
  42. return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk");
  43. disk->total_sectors = 0;
  44. disk->id = 0;
  45. disk->data = 0;
  46. return GRUB_ERR_NONE;
  47. }
  48. static void
  49. grub_host_close (grub_disk_t disk __attribute((unused)))
  50. {
  51. }
  52. static grub_err_t
  53. grub_host_read (grub_disk_t disk __attribute((unused)),
  54. grub_disk_addr_t sector __attribute((unused)),
  55. grub_size_t size __attribute((unused)),
  56. char *buf __attribute((unused)))
  57. {
  58. return GRUB_ERR_OUT_OF_RANGE;
  59. }
  60. static grub_err_t
  61. grub_host_write (grub_disk_t disk __attribute ((unused)),
  62. grub_disk_addr_t sector __attribute ((unused)),
  63. grub_size_t size __attribute ((unused)),
  64. const char *buf __attribute ((unused)))
  65. {
  66. return GRUB_ERR_OUT_OF_RANGE;
  67. }
  68. static struct grub_disk_dev grub_host_dev =
  69. {
  70. /* The only important line in this file :-) */
  71. .name = "host",
  72. .id = GRUB_DISK_DEVICE_HOST_ID,
  73. .disk_iterate = grub_host_iterate,
  74. .disk_open = grub_host_open,
  75. .disk_close = grub_host_close,
  76. .disk_read = grub_host_read,
  77. .disk_write = grub_host_write,
  78. .next = 0
  79. };
  80. GRUB_MOD_INIT(host)
  81. {
  82. grub_disk_dev_register (&grub_host_dev);
  83. }
  84. GRUB_MOD_FINI(host)
  85. {
  86. grub_disk_dev_unregister (&grub_host_dev);
  87. }