msdos_partition.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2004,2007 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_PC_PARTITION_HEADER
  19. #define GRUB_PC_PARTITION_HEADER 1
  20. #include <grub/symbol.h>
  21. #include <grub/types.h>
  22. #include <grub/err.h>
  23. #include <grub/disk.h>
  24. #include <grub/partition.h>
  25. /* The signature. */
  26. #define GRUB_PC_PARTITION_SIGNATURE 0xaa55
  27. /* This is not a flag actually, but used as if it were a flag. */
  28. #define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG 0x10
  29. /* DOS partition types. */
  30. #define GRUB_PC_PARTITION_TYPE_NONE 0
  31. #define GRUB_PC_PARTITION_TYPE_FAT12 1
  32. #define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4
  33. #define GRUB_PC_PARTITION_TYPE_EXTENDED 5
  34. #define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6
  35. #define GRUB_PC_PARTITION_TYPE_NTFS 7
  36. #define GRUB_PC_PARTITION_TYPE_FAT32 0xb
  37. #define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc
  38. #define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
  39. #define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf
  40. #define GRUB_PC_PARTITION_TYPE_PLAN9 0x39
  41. #define GRUB_PC_PARTITION_TYPE_LDM 0x42
  42. #define GRUB_PC_PARTITION_TYPE_EZD 0x55
  43. #define GRUB_PC_PARTITION_TYPE_MINIX 0x80
  44. #define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81
  45. #define GRUB_PC_PARTITION_TYPE_LINUX_SWAP 0x82
  46. #define GRUB_PC_PARTITION_TYPE_EXT2FS 0x83
  47. #define GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED 0x85
  48. #define GRUB_PC_PARTITION_TYPE_VSTAFS 0x9e
  49. #define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5
  50. #define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6
  51. #define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9
  52. #define GRUB_PC_PARTITION_TYPE_HFS 0xaf
  53. #define GRUB_PC_PARTITION_TYPE_GPT_DISK 0xee
  54. #define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
  55. /* The partition entry. */
  56. struct grub_msdos_partition_entry
  57. {
  58. /* If active, 0x80, otherwise, 0x00. */
  59. grub_uint8_t flag;
  60. /* The head of the start. */
  61. grub_uint8_t start_head;
  62. /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
  63. is the cylinder of the start. Note that S is counted from one. */
  64. grub_uint8_t start_sector;
  65. /* (C & 0xFF) where C is the cylinder of the start. */
  66. grub_uint8_t start_cylinder;
  67. /* The partition type. */
  68. grub_uint8_t type;
  69. /* The end versions of start_head, start_sector and start_cylinder,
  70. respectively. */
  71. grub_uint8_t end_head;
  72. grub_uint8_t end_sector;
  73. grub_uint8_t end_cylinder;
  74. /* The start sector. Note that this is counted from zero. */
  75. grub_uint32_t start;
  76. /* The length in sector units. */
  77. grub_uint32_t length;
  78. } GRUB_PACKED;
  79. /* The structure of MBR. */
  80. struct grub_msdos_partition_mbr
  81. {
  82. /* The code area (actually, including BPB). */
  83. grub_uint8_t code[446];
  84. /* Four partition entries. */
  85. struct grub_msdos_partition_entry entries[4];
  86. /* The signature 0xaa55. */
  87. grub_uint16_t signature;
  88. } GRUB_PACKED;
  89. static inline int
  90. grub_msdos_partition_is_empty (int type)
  91. {
  92. return (type == GRUB_PC_PARTITION_TYPE_NONE);
  93. }
  94. static inline int
  95. grub_msdos_partition_is_extended (int type)
  96. {
  97. return (type == GRUB_PC_PARTITION_TYPE_EXTENDED
  98. || type == GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
  99. || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED);
  100. }
  101. grub_err_t
  102. grub_partition_msdos_iterate (grub_disk_t disk,
  103. grub_partition_iterate_hook_t hook,
  104. void *hook_data);
  105. #endif /* ! GRUB_PC_PARTITION_HEADER */