host.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <grub/dl.h>
  22. #include <grub/disk.h>
  23. #include <grub/misc.h>
  24. int grub_disk_host_i_want_a_reference;
  25. static int
  26. grub_host_iterate (int (*hook) (const char *name, void *closure),
  27. void *closure)
  28. {
  29. if (hook ("host", closure))
  30. return 1;
  31. return 0;
  32. }
  33. static grub_err_t
  34. grub_host_open (const char *name, grub_disk_t disk)
  35. {
  36. if (grub_strcmp (name, "host"))
  37. return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk");
  38. disk->total_sectors = 0;
  39. disk->id = (unsigned long) "host";
  40. disk->has_partitions = 0;
  41. disk->data = 0;
  42. return GRUB_ERR_NONE;
  43. }
  44. static void
  45. grub_host_close (grub_disk_t disk __attribute((unused)))
  46. {
  47. }
  48. static grub_err_t
  49. grub_host_read (grub_disk_t disk __attribute((unused)),
  50. grub_disk_addr_t sector __attribute((unused)),
  51. grub_size_t size __attribute((unused)),
  52. char *buf __attribute((unused)))
  53. {
  54. return GRUB_ERR_OUT_OF_RANGE;
  55. }
  56. static grub_err_t
  57. grub_host_write (grub_disk_t disk __attribute ((unused)),
  58. grub_disk_addr_t sector __attribute ((unused)),
  59. grub_size_t size __attribute ((unused)),
  60. const char *buf __attribute ((unused)))
  61. {
  62. return GRUB_ERR_OUT_OF_RANGE;
  63. }
  64. static struct grub_disk_dev grub_host_dev =
  65. {
  66. /* The only important line in this file :-) */
  67. .name = "host",
  68. .id = GRUB_DISK_DEVICE_HOST_ID,
  69. .iterate = grub_host_iterate,
  70. .open = grub_host_open,
  71. .close = grub_host_close,
  72. .read = grub_host_read,
  73. .write = grub_host_write,
  74. .next = 0
  75. };
  76. GRUB_MOD_INIT(host)
  77. {
  78. grub_disk_dev_register (&grub_host_dev);
  79. }
  80. GRUB_MOD_FINI(host)
  81. {
  82. grub_disk_dev_unregister (&grub_host_dev);
  83. }