part.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _PART_H
  24. #define _PART_H
  25. #include <ide.h>
  26. typedef struct block_dev_desc {
  27. int if_type; /* type of the interface */
  28. int dev; /* device number */
  29. unsigned char part_type; /* partition type */
  30. unsigned char target; /* target SCSI ID */
  31. unsigned char lun; /* target LUN */
  32. unsigned char type; /* device type */
  33. unsigned char removable; /* removable device */
  34. #ifdef CONFIG_LBA48
  35. unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */
  36. #endif
  37. lbaint_t lba; /* number of blocks */
  38. unsigned long blksz; /* block size */
  39. int log2blksz; /* for convenience: log2(blksz) */
  40. char vendor [40+1]; /* IDE model, SCSI Vendor */
  41. char product[20+1]; /* IDE Serial no, SCSI product */
  42. char revision[8+1]; /* firmware revision */
  43. unsigned long (*block_read)(int dev,
  44. unsigned long start,
  45. lbaint_t blkcnt,
  46. void *buffer);
  47. unsigned long (*block_write)(int dev,
  48. unsigned long start,
  49. lbaint_t blkcnt,
  50. const void *buffer);
  51. unsigned long (*block_erase)(int dev,
  52. unsigned long start,
  53. lbaint_t blkcnt);
  54. void *priv; /* driver private struct pointer */
  55. }block_dev_desc_t;
  56. #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
  57. #define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
  58. (PAD_SIZE(size, block_dev_desc->blksz))
  59. #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
  60. ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
  61. ((x & 0xffff0000) ? 16 : 0))
  62. #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
  63. /* Interface types: */
  64. #define IF_TYPE_UNKNOWN 0
  65. #define IF_TYPE_IDE 1
  66. #define IF_TYPE_SCSI 2
  67. #define IF_TYPE_ATAPI 3
  68. #define IF_TYPE_USB 4
  69. #define IF_TYPE_DOC 5
  70. #define IF_TYPE_MMC 6
  71. #define IF_TYPE_SD 7
  72. #define IF_TYPE_SATA 8
  73. /* Part types */
  74. #define PART_TYPE_UNKNOWN 0x00
  75. #define PART_TYPE_MAC 0x01
  76. #define PART_TYPE_DOS 0x02
  77. #define PART_TYPE_ISO 0x03
  78. #define PART_TYPE_AMIGA 0x04
  79. #define PART_TYPE_EFI 0x05
  80. /*
  81. * Type string for U-Boot bootable partitions
  82. */
  83. #define BOOT_PART_TYPE "U-Boot" /* primary boot partition type */
  84. #define BOOT_PART_COMP "PPCBoot" /* PPCBoot compatibility type */
  85. /* device types */
  86. #define DEV_TYPE_UNKNOWN 0xff /* not connected */
  87. #define DEV_TYPE_HARDDISK 0x00 /* harddisk */
  88. #define DEV_TYPE_TAPE 0x01 /* Tape */
  89. #define DEV_TYPE_CDROM 0x05 /* CD-ROM */
  90. #define DEV_TYPE_OPDISK 0x07 /* optical disk */
  91. typedef struct disk_partition {
  92. ulong start; /* # of first block in partition */
  93. ulong size; /* number of blocks in partition */
  94. ulong blksz; /* block size in bytes */
  95. uchar name[32]; /* partition name */
  96. uchar type[32]; /* string type description */
  97. int bootable; /* Active/Bootable flag is set */
  98. #ifdef CONFIG_PARTITION_UUIDS
  99. char uuid[37]; /* filesystem UUID as string, if exists */
  100. #endif
  101. } disk_partition_t;
  102. /* Misc _get_dev functions */
  103. #ifdef CONFIG_PARTITIONS
  104. block_dev_desc_t *get_dev(const char *ifname, int dev);
  105. block_dev_desc_t* ide_get_dev(int dev);
  106. block_dev_desc_t* sata_get_dev(int dev);
  107. block_dev_desc_t* scsi_get_dev(int dev);
  108. block_dev_desc_t* usb_stor_get_dev(int dev);
  109. block_dev_desc_t* mmc_get_dev(int dev);
  110. block_dev_desc_t* systemace_get_dev(int dev);
  111. block_dev_desc_t* mg_disk_get_dev(int dev);
  112. /* disk/part.c */
  113. int get_partition_info (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  114. void print_part (block_dev_desc_t *dev_desc);
  115. void init_part (block_dev_desc_t *dev_desc);
  116. void dev_print(block_dev_desc_t *dev_desc);
  117. int get_device(const char *ifname, const char *dev_str,
  118. block_dev_desc_t **dev_desc);
  119. int get_device_and_partition(const char *ifname, const char *dev_part_str,
  120. block_dev_desc_t **dev_desc,
  121. disk_partition_t *info, int allow_whole_dev);
  122. #else
  123. static inline block_dev_desc_t *get_dev(const char *ifname, int dev)
  124. { return NULL; }
  125. static inline block_dev_desc_t* ide_get_dev(int dev) { return NULL; }
  126. static inline block_dev_desc_t* sata_get_dev(int dev) { return NULL; }
  127. static inline block_dev_desc_t* scsi_get_dev(int dev) { return NULL; }
  128. static inline block_dev_desc_t* usb_stor_get_dev(int dev) { return NULL; }
  129. static inline block_dev_desc_t* mmc_get_dev(int dev) { return NULL; }
  130. static inline block_dev_desc_t* systemace_get_dev(int dev) { return NULL; }
  131. static inline block_dev_desc_t* mg_disk_get_dev(int dev) { return NULL; }
  132. static inline int get_partition_info (block_dev_desc_t * dev_desc, int part,
  133. disk_partition_t *info) { return -1; }
  134. static inline void print_part (block_dev_desc_t *dev_desc) {}
  135. static inline void init_part (block_dev_desc_t *dev_desc) {}
  136. static inline void dev_print(block_dev_desc_t *dev_desc) {}
  137. static inline int get_device(const char *ifname, const char *dev_str,
  138. block_dev_desc_t **dev_desc)
  139. { return -1; }
  140. static inline int get_device_and_partition(const char *ifname,
  141. const char *dev_part_str,
  142. block_dev_desc_t **dev_desc,
  143. disk_partition_t *info,
  144. int allow_whole_dev)
  145. { *dev_desc = NULL; return -1; }
  146. #endif
  147. #ifdef CONFIG_MAC_PARTITION
  148. /* disk/part_mac.c */
  149. int get_partition_info_mac (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  150. void print_part_mac (block_dev_desc_t *dev_desc);
  151. int test_part_mac (block_dev_desc_t *dev_desc);
  152. #endif
  153. #ifdef CONFIG_DOS_PARTITION
  154. /* disk/part_dos.c */
  155. int get_partition_info_dos (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  156. void print_part_dos (block_dev_desc_t *dev_desc);
  157. int test_part_dos (block_dev_desc_t *dev_desc);
  158. #endif
  159. #ifdef CONFIG_ISO_PARTITION
  160. /* disk/part_iso.c */
  161. int get_partition_info_iso (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  162. void print_part_iso (block_dev_desc_t *dev_desc);
  163. int test_part_iso (block_dev_desc_t *dev_desc);
  164. #endif
  165. #ifdef CONFIG_AMIGA_PARTITION
  166. /* disk/part_amiga.c */
  167. int get_partition_info_amiga (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  168. void print_part_amiga (block_dev_desc_t *dev_desc);
  169. int test_part_amiga (block_dev_desc_t *dev_desc);
  170. #endif
  171. #ifdef CONFIG_EFI_PARTITION
  172. #include <part_efi.h>
  173. /* disk/part_efi.c */
  174. int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
  175. void print_part_efi (block_dev_desc_t *dev_desc);
  176. int test_part_efi (block_dev_desc_t *dev_desc);
  177. /**
  178. * write_gpt_table() - Write the GUID Partition Table to disk
  179. *
  180. * @param dev_desc - block device descriptor
  181. * @param gpt_h - pointer to GPT header representation
  182. * @param gpt_e - pointer to GPT partition table entries
  183. *
  184. * @return - zero on success, otherwise error
  185. */
  186. int write_gpt_table(block_dev_desc_t *dev_desc,
  187. gpt_header *gpt_h, gpt_entry *gpt_e);
  188. /**
  189. * gpt_fill_pte(): Fill the GPT partition table entry
  190. *
  191. * @param gpt_h - GPT header representation
  192. * @param gpt_e - GPT partition table entries
  193. * @param partitions - list of partitions
  194. * @param parts - number of partitions
  195. *
  196. * @return zero on success
  197. */
  198. int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
  199. disk_partition_t *partitions, int parts);
  200. /**
  201. * gpt_fill_header(): Fill the GPT header
  202. *
  203. * @param dev_desc - block device descriptor
  204. * @param gpt_h - GPT header representation
  205. * @param str_guid - disk guid string representation
  206. * @param parts_count - number of partitions
  207. *
  208. * @return - error on str_guid conversion error
  209. */
  210. int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
  211. char *str_guid, int parts_count);
  212. /**
  213. * gpt_restore(): Restore GPT partition table
  214. *
  215. * @param dev_desc - block device descriptor
  216. * @param str_disk_guid - disk GUID
  217. * @param partitions - list of partitions
  218. * @param parts - number of partitions
  219. *
  220. * @return zero on success
  221. */
  222. int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
  223. disk_partition_t *partitions, const int parts_count);
  224. #endif
  225. #endif /* _PART_H */