disk.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,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_DISK_HEADER
  19. #define GRUB_DISK_HEADER 1
  20. #include <grub/symbol.h>
  21. #include <grub/err.h>
  22. #include <grub/types.h>
  23. #include <grub/device.h>
  24. /* These are used to set a device id. When you add a new disk device,
  25. you must define a new id for it here. */
  26. enum grub_disk_dev_id
  27. {
  28. GRUB_DISK_DEVICE_BIOSDISK_ID,
  29. GRUB_DISK_DEVICE_OFDISK_ID,
  30. GRUB_DISK_DEVICE_LOOPBACK_ID,
  31. GRUB_DISK_DEVICE_EFIDISK_ID,
  32. GRUB_DISK_DEVICE_RAID_ID,
  33. GRUB_DISK_DEVICE_LVM_ID,
  34. GRUB_DISK_DEVICE_HOST_ID,
  35. GRUB_DISK_DEVICE_ATA_ID,
  36. GRUB_DISK_DEVICE_MEMDISK_ID,
  37. GRUB_DISK_DEVICE_NAND_ID,
  38. GRUB_DISK_DEVICE_UUID_ID,
  39. GRUB_DISK_DEVICE_PXE_ID,
  40. GRUB_DISK_DEVICE_SCSI_ID,
  41. GRUB_DISK_DEVICE_FILE_ID,
  42. GRUB_DISK_DEVICE_LUKS_ID,
  43. GRUB_DISK_DEVICE_USB_ID,
  44. GRUB_DISK_DEVICE_MAP_ID,
  45. };
  46. struct grub_disk;
  47. #ifdef GRUB_UTIL
  48. struct grub_disk_memberlist;
  49. #endif
  50. /* Disk device. */
  51. struct grub_disk_dev
  52. {
  53. /* The device name. */
  54. const char *name;
  55. /* The device id used by the cache manager. */
  56. enum grub_disk_dev_id id;
  57. /* Call HOOK with each device name, until HOOK returns non-zero. */
  58. int (*iterate) (int (*hook) (const char *name, void *closure),
  59. void *closure);
  60. /* Open the device named NAME, and set up DISK. */
  61. grub_err_t (*open) (const char *name, struct grub_disk *disk);
  62. /* Close the disk DISK. */
  63. void (*close) (struct grub_disk *disk);
  64. /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
  65. grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector,
  66. grub_size_t size, char *buf);
  67. /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
  68. grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector,
  69. grub_size_t size, const char *buf);
  70. #ifdef GRUB_UTIL
  71. struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk);
  72. #endif
  73. /* The next disk device. */
  74. struct grub_disk_dev *next;
  75. };
  76. typedef struct grub_disk_dev *grub_disk_dev_t;
  77. struct grub_partition;
  78. /* Disk. */
  79. struct grub_disk
  80. {
  81. /* The disk name. */
  82. const char *name;
  83. /* The underlying disk device. */
  84. grub_disk_dev_t dev;
  85. /* The total number of sectors. */
  86. grub_uint64_t total_sectors;
  87. /* If partitions can be stored. */
  88. int has_partitions;
  89. /* The id used by the disk cache manager. */
  90. unsigned long id;
  91. /* The partition information. This is machine-specific. */
  92. struct grub_partition *partition;
  93. /* Called when a sector was read. OFFSET is between 0 and
  94. the sector size minus 1, and LENGTH is between 0 and the sector size. */
  95. void (*read_hook) (grub_disk_addr_t sector,
  96. unsigned offset, unsigned length, void* closure);
  97. void* closure;
  98. /* Device-specific data. */
  99. void *data;
  100. };
  101. typedef struct grub_disk *grub_disk_t;
  102. #ifdef GRUB_UTIL
  103. struct grub_disk_memberlist
  104. {
  105. grub_disk_t disk;
  106. struct grub_disk_memberlist *next;
  107. };
  108. typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
  109. #endif
  110. /* The sector size. */
  111. #define GRUB_DISK_SECTOR_SIZE 0x200
  112. #define GRUB_DISK_SECTOR_BITS 9
  113. /* The maximum number of disk caches. */
  114. #define GRUB_DISK_CACHE_NUM 1021
  115. /* The size of a disk cache in sector units. */
  116. #define GRUB_DISK_CACHE_SIZE 8
  117. #define GRUB_DISK_CACHE_BITS 3
  118. /* This is called from the memory manager. */
  119. void grub_disk_cache_invalidate_all (void);
  120. void grub_disk_dev_register (grub_disk_dev_t dev);
  121. void grub_disk_dev_unregister (grub_disk_dev_t dev);
  122. int grub_disk_dev_iterate (int (*hook) (const char *name, void *closure),
  123. void *closure);
  124. grub_disk_t grub_disk_open (const char *name);
  125. void grub_disk_close (grub_disk_t disk);
  126. grub_err_t grub_disk_read (grub_disk_t disk,
  127. grub_disk_addr_t sector,
  128. grub_off_t offset,
  129. grub_size_t size,
  130. void *buf);
  131. grub_err_t grub_disk_read_ex (grub_disk_t disk,
  132. grub_disk_addr_t sector,
  133. grub_off_t offset,
  134. grub_size_t size,
  135. void *buf,
  136. int flags);
  137. grub_err_t grub_disk_write (grub_disk_t disk,
  138. grub_disk_addr_t sector,
  139. grub_off_t offset,
  140. grub_size_t size,
  141. const void *buf);
  142. grub_uint64_t grub_disk_get_size (grub_disk_t disk);
  143. extern void (* grub_disk_firmware_fini) (void);
  144. extern int grub_disk_firmware_is_tainted;
  145. /* ATA pass through parameters and function. */
  146. struct grub_disk_ata_pass_through_parms
  147. {
  148. grub_uint8_t taskfile[8];
  149. void * buffer;
  150. int size;
  151. };
  152. extern grub_err_t (* grub_disk_ata_pass_through) (grub_disk_t,
  153. struct grub_disk_ata_pass_through_parms *);
  154. #endif /* ! GRUB_DISK_HEADER */