disklabel.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* $OpenBSD: disklabel.h,v 1.66 2015/07/23 18:02:59 krw Exp $ */
  2. /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */
  3. /*
  4. * Copyright (c) 1987, 1988, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
  32. */
  33. /*
  34. * Disk description table, see disktab(5)
  35. */
  36. #define _PATH_DISKTAB "/etc/disktab"
  37. #define DISKTAB "/etc/disktab" /* deprecated */
  38. /*
  39. * Each disk has a label which includes information about the hardware
  40. * disk geometry, filesystem partitions, and drive specific information.
  41. * The location of the label, as well as the number of partitions the
  42. * label can describe and the number of the "whole disk" (raw)
  43. * partition are machine dependent.
  44. */
  45. #include <machine/disklabel.h>
  46. #include <sys/uuid.h>
  47. /*
  48. * The absolute maximum number of disk partitions allowed.
  49. * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
  50. * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
  51. */
  52. #define MAXMAXPARTITIONS 22
  53. #if MAXPARTITIONS > MAXMAXPARTITIONS
  54. #warn beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
  55. #endif
  56. /*
  57. * Translate between device numbers and major/disk unit/disk partition.
  58. */
  59. #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
  60. #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
  61. #define RAW_PART 2 /* 'c' partition */
  62. #define DISKMINOR(unit, part) \
  63. (((unit) * MAXPARTITIONS) + (part))
  64. #define MAKEDISKDEV(maj, unit, part) \
  65. (makedev((maj), DISKMINOR((unit), (part))))
  66. #define DISKLABELDEV(dev) \
  67. (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
  68. #define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
  69. #define MAXDISKSIZE 0x7fffffffffffLL /* 47 bits of reach */
  70. #ifndef _LOCORE
  71. struct disklabel {
  72. u_int32_t d_magic; /* the magic number */
  73. u_int16_t d_type; /* drive type */
  74. u_int16_t d_subtype; /* controller/d_type specific */
  75. char d_typename[16]; /* type name, e.g. "eagle" */
  76. /*
  77. * d_packname contains the pack identifier and is returned when
  78. * the disklabel is read off the disk or in-core copy.
  79. * d_boot0 and d_boot1 are the (optional) names of the
  80. * primary (block 0) and secondary (block 1-15) bootstraps
  81. * as found in /usr/mdec. These are returned when using
  82. * getdiskbyname(3) to retrieve the values from /etc/disktab.
  83. */
  84. union {
  85. char un_d_packname[16]; /* pack identifier */
  86. struct {
  87. char *un_d_boot0; /* primary bootstrap name */
  88. char *un_d_boot1; /* secondary bootstrap name */
  89. } un_b;
  90. } d_un;
  91. #define d_packname d_un.un_d_packname
  92. #define d_boot0 d_un.un_b.un_d_boot0
  93. #define d_boot1 d_un.un_b.un_d_boot1
  94. /* disk geometry: */
  95. u_int32_t d_secsize; /* # of bytes per sector */
  96. u_int32_t d_nsectors; /* # of data sectors per track */
  97. u_int32_t d_ntracks; /* # of tracks per cylinder */
  98. u_int32_t d_ncylinders; /* # of data cylinders per unit */
  99. u_int32_t d_secpercyl; /* # of data sectors per cylinder */
  100. u_int32_t d_secperunit; /* # of data sectors (low part) */
  101. u_char d_uid[8]; /* Unique label identifier. */
  102. /*
  103. * Alternate cylinders include maintenance, replacement, configuration
  104. * description areas, etc.
  105. */
  106. u_int32_t d_acylinders; /* # of alt. cylinders per unit */
  107. /* hardware characteristics: */
  108. u_int16_t d_bstarth; /* start of useable region (high part) */
  109. u_int16_t d_bendh; /* size of useable region (high part) */
  110. u_int32_t d_bstart; /* start of useable region */
  111. u_int32_t d_bend; /* end of useable region */
  112. u_int32_t d_flags; /* generic flags */
  113. #define NDDATA 5
  114. u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */
  115. u_int16_t d_secperunith; /* # of data sectors (high part) */
  116. u_int16_t d_version; /* version # (1=48 bit addressing) */
  117. #define NSPARE 4
  118. u_int32_t d_spare[NSPARE]; /* reserved for future use */
  119. u_int32_t d_magic2; /* the magic number (again) */
  120. u_int16_t d_checksum; /* xor of data incl. partitions */
  121. /* filesystem and partition information: */
  122. u_int16_t d_npartitions; /* number of partitions in following */
  123. u_int32_t d_bbsize; /* size of boot area at sn0, bytes */
  124. u_int32_t d_sbsize; /* max size of fs superblock, bytes */
  125. struct partition { /* the partition table */
  126. u_int32_t p_size; /* number of sectors (low part) */
  127. u_int32_t p_offset; /* starting sector (low part) */
  128. u_int16_t p_offseth; /* starting sector (high part) */
  129. u_int16_t p_sizeh; /* number of sectors (high part) */
  130. u_int8_t p_fstype; /* filesystem type, see below */
  131. u_int8_t p_fragblock; /* encoded filesystem frag/block */
  132. u_int16_t p_cpg; /* UFS: FS cylinders per group */
  133. } d_partitions[MAXPARTITIONS]; /* actually may be more */
  134. };
  135. struct __partitionv0 { /* old (v0) partition table entry */
  136. u_int32_t p_size; /* number of sectors in partition */
  137. u_int32_t p_offset; /* starting sector */
  138. u_int32_t p_fsize; /* filesystem basic fragment size */
  139. u_int8_t p_fstype; /* filesystem type, see below */
  140. u_int8_t p_frag; /* filesystem fragments per block */
  141. union {
  142. u_int16_t cpg; /* UFS: FS cylinders per group */
  143. u_int16_t sgs; /* LFS: FS segment shift */
  144. } __partitionv0_u1;
  145. };
  146. #endif /* _LOCORE */
  147. #define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \
  148. ((fsize) * (frag) == 0 ? 0 : \
  149. (((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag))))
  150. #define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12)))
  151. #define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1)))
  152. #define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \
  153. (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i)))
  154. #define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size)
  155. #define DL_SETPSIZE(p, n) do { \
  156. u_int64_t x = (n); \
  157. (p)->p_sizeh = x >> 32; \
  158. (p)->p_size = x; \
  159. } while (0)
  160. #define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset)
  161. #define DL_SETPOFFSET(p, n) do { \
  162. u_int64_t x = (n); \
  163. (p)->p_offseth = x >> 32; \
  164. (p)->p_offset = x; \
  165. } while (0)
  166. #define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \
  167. (d)->d_secperunit)
  168. #define DL_SETDSIZE(d, n) do { \
  169. u_int64_t x = (n); \
  170. (d)->d_secperunith = x >> 32; \
  171. (d)->d_secperunit = x; \
  172. } while (0)
  173. #define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \
  174. (d)->d_bstart)
  175. #define DL_SETBSTART(d, n) do { \
  176. u_int64_t x = (n); \
  177. (d)->d_bstarth = x >> 32; \
  178. (d)->d_bstart = x; \
  179. } while (0)
  180. #define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \
  181. (d)->d_bend)
  182. #define DL_SETBEND(d, n) do { \
  183. u_int64_t x = (n); \
  184. (d)->d_bendh = x >> 32; \
  185. (d)->d_bend = x; \
  186. } while (0)
  187. #define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE)
  188. #define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d))
  189. #define DL_BLKTOSEC(d, n) ((n) / DL_BLKSPERSEC(d))
  190. #define DL_BLKOFFSET(d, n) (((n) % DL_BLKSPERSEC(d)) * DEV_BSIZE)
  191. /* d_type values: */
  192. #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
  193. #define DTYPE_MSCP 2 /* MSCP */
  194. #define DTYPE_DEC 3 /* other DEC (rk, rl) */
  195. #define DTYPE_SCSI 4 /* SCSI */
  196. #define DTYPE_ESDI 5 /* ESDI interface */
  197. #define DTYPE_ST506 6 /* ST506 etc. */
  198. #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
  199. #define DTYPE_HPFL 8 /* HP Fiber-link */
  200. #define DTYPE_FLOPPY 10 /* floppy */
  201. #define DTYPE_CCD 11 /* was: concatenated disk device */
  202. #define DTYPE_VND 12 /* vnode pseudo-disk */
  203. #define DTYPE_ATAPI 13 /* ATAPI */
  204. #define DTYPE_RAID 14 /* was: RAIDframe */
  205. #ifdef DKTYPENAMES
  206. static char *dktypenames[] = {
  207. "unknown",
  208. "SMD",
  209. "MSCP",
  210. "old DEC",
  211. "SCSI",
  212. "ESDI",
  213. "ST506",
  214. "HP-IB",
  215. "HP-FL",
  216. "type 9",
  217. "floppy",
  218. "ccd", /* deprecated */
  219. "vnd",
  220. "ATAPI",
  221. "RAID",
  222. NULL
  223. };
  224. #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
  225. #endif
  226. /*
  227. * Filesystem type and version.
  228. * Used to interpret other filesystem-specific
  229. * per-partition information.
  230. */
  231. #define FS_UNUSED 0 /* unused */
  232. #define FS_SWAP 1 /* swap */
  233. #define FS_V6 2 /* Sixth Edition */
  234. #define FS_V7 3 /* Seventh Edition */
  235. #define FS_SYSV 4 /* System V */
  236. #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
  237. #define FS_V8 6 /* Eighth Edition, 4K blocks */
  238. #define FS_BSDFFS 7 /* 4.2BSD fast file system */
  239. #define FS_MSDOS 8 /* MSDOS file system */
  240. #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
  241. #define FS_OTHER 10 /* in use, but unknown/unsupported */
  242. #define FS_HPFS 11 /* OS/2 high-performance file system */
  243. #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
  244. #define FS_BOOT 13 /* partition contains bootstrap */
  245. #define FS_ADOS 14 /* AmigaDOS fast file system */
  246. #define FS_HFS 15 /* Macintosh HFS */
  247. #define FS_ADFS 16 /* Acorn Disk Filing System */
  248. #define FS_EXT2FS 17 /* ext2fs */
  249. #define FS_CCD 18 /* ccd component */
  250. #define FS_RAID 19 /* RAIDframe or softraid */
  251. #define FS_NTFS 20 /* Windows/NT file system */
  252. #define FS_UDF 21 /* UDF (DVD) filesystem */
  253. #ifdef DKTYPENAMES
  254. static char *fstypenames[] = {
  255. "unused",
  256. "swap",
  257. "Version6",
  258. "Version7",
  259. "SystemV",
  260. "4.1BSD",
  261. "Eighth-Edition",
  262. "4.2BSD",
  263. "MSDOS",
  264. "4.4LFS",
  265. "unknown",
  266. "HPFS",
  267. "ISO9660",
  268. "boot",
  269. "ADOS",
  270. "HFS",
  271. "ADFS",
  272. "ext2fs",
  273. "ccd",
  274. "RAID",
  275. "NTFS",
  276. "UDF",
  277. NULL
  278. };
  279. /* Similar to the above, but used for things like the mount command. */
  280. static char *fstypesnames[] = {
  281. "", /* 0 */
  282. "", /* 1 */
  283. "", /* 2 */
  284. "", /* 3 */
  285. "", /* 4 */
  286. "", /* 5 */
  287. "", /* 6 */
  288. "ffs", /* 7 */
  289. "msdos", /* 8 */
  290. "lfs", /* 9 */
  291. "", /* 10 */
  292. "", /* 11 */
  293. "cd9660", /* 12 */
  294. "", /* 13 */
  295. "ados", /* 14 */
  296. "", /* 15 */
  297. "", /* 16 */
  298. "ext2fs", /* 17 */
  299. "", /* 18 */
  300. "", /* 19 */
  301. "ntfs", /* 20 */
  302. "udf", /* 21 */
  303. NULL
  304. };
  305. #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
  306. #endif
  307. /*
  308. * flags shared by various drives:
  309. */
  310. #define D_BADSECT 0x04 /* supports bad sector forw. */
  311. #define D_VENDOR 0x08 /* vendor disklabel */
  312. /*
  313. * Drive data for SMD.
  314. */
  315. #define d_smdflags d_drivedata[0]
  316. #define D_SSE 0x1 /* supports skip sectoring */
  317. #define d_mindist d_drivedata[1]
  318. #define d_maxdist d_drivedata[2]
  319. #define d_sdist d_drivedata[3]
  320. /*
  321. * Drive data for ST506.
  322. */
  323. #define d_precompcyl d_drivedata[0]
  324. #define d_gap3 d_drivedata[1] /* used only when formatting */
  325. /*
  326. * Drive data for SCSI.
  327. */
  328. #define d_blind d_drivedata[0]
  329. #ifndef _LOCORE
  330. /*
  331. * Structure used to perform a format or other raw operation, returning
  332. * data and/or register values. Register identification and format
  333. * are device- and driver-dependent.
  334. */
  335. struct format_op {
  336. char *df_buf;
  337. int df_count; /* value-result */
  338. daddr_t df_startblk;
  339. int df_reg[8]; /* result */
  340. };
  341. /*
  342. * Structure used internally to retrieve information about a partition
  343. * on a disk.
  344. */
  345. struct partinfo {
  346. struct disklabel *disklab;
  347. struct partition *part;
  348. };
  349. /* GUID partition table -- located at sector 1 of some disks. */
  350. #define GPTSECTOR 1 /* DOS boot block relative sector # */
  351. #define GPTSIGNATURE 0x5452415020494645LL
  352. /* ASCII string "EFI PART" encoded as 64-bit */
  353. #define GPTREVISION 0x10000 /* GPT header version 1.0 */
  354. #define NGPTPARTITIONS 128
  355. #define GPTDOSACTIVE 0x2
  356. #define GPTMINHDRSIZE 92
  357. #define GPTMINPARTSIZE 128
  358. /* all values in the GPT need to be little endian as per UEFI specification */
  359. struct gpt_header {
  360. u_int64_t gh_sig; /* "EFI PART" */
  361. u_int32_t gh_rev; /* GPT Version 1.0: 0x00000100 */
  362. u_int32_t gh_size; /* Little-Endian */
  363. u_int32_t gh_csum; /* CRC32: with this field as 0 */
  364. u_int32_t gh_rsvd; /* always zero */
  365. u_int64_t gh_lba_self; /* LBA of this header */
  366. u_int64_t gh_lba_alt; /* LBA of alternate header */
  367. u_int64_t gh_lba_start; /* first usable LBA */
  368. u_int64_t gh_lba_end; /* last usable LBA */
  369. struct uuid gh_guid; /* disk GUID used to identify the disk */
  370. u_int64_t gh_part_lba; /* starting LBA of GPT partition entries */
  371. u_int32_t gh_part_num; /* # of partition entries */
  372. u_int32_t gh_part_size; /* size per entry, shall be 128*(2**n)
  373. with n >= 0 */
  374. u_int32_t gh_part_csum; /* CRC32 checksum of all partition entries:
  375. * starts at gh_part_lba and is computed over
  376. * a byte length of gh_part_num*gh_part_size */
  377. /* the rest of the block is reserved by UEFI and must be zero */
  378. };
  379. struct gpt_partition {
  380. struct uuid gp_type; /* partition type GUID */
  381. struct uuid gp_guid; /* unique partition GUID */
  382. u_int64_t gp_lba_start; /* starting LBA of this partition */
  383. u_int64_t gp_lba_end; /* ending LBA of this partition, inclusive,
  384. usually odd */
  385. u_int64_t gp_attrs; /* attribute flags */
  386. u_int16_t gp_name[36]; /* partition name, utf-16le */
  387. /* the rest of the GPT partition entry, if any, is reserved by UEFI
  388. and must be zero */
  389. };
  390. #define GPT_PARTSPERSEC(gh) (DEV_BSIZE / letoh32((gh)->gh_part_size))
  391. #define GPT_SECOFFSET(gh, n) ((gh)->gh_part_size * n)
  392. #define GPT_UUID_UNUSED \
  393. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  394. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
  395. #define GPT_UUID_MSDOS \
  396. { 0xeb, 0xd0, 0xa0, 0xa2, 0xb9, 0xe5, 0x44, 0x33, \
  397. 0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 }
  398. #define GPT_UUID_EFI_SYSTEM \
  399. { 0xc1, 0x2a, 0x73, 0x28, 0xf8, 0x1f, 0x11, 0xd2, \
  400. 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b }
  401. #define GPT_UUID_LEGACY_MBR \
  402. { 0x02, 0x4d, 0xee, 0x41, 0x33, 0x37, 0x11, 0xd3, \
  403. 0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f }
  404. #define GPT_UUID_OPENBSD \
  405. { 0x82, 0x4c, 0xc7, 0xa0, 0x36, 0xa8, 0x11, 0xe3, \
  406. 0x89, 0x0a, 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 }
  407. #define GPT_UUID_CHROMEROOTFS \
  408. { 0x3c, 0xb8, 0xe2, 0x02, 0x3b, 0x7e, 0x47, 0xdd, \
  409. 0x8a, 0x3c, 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec }
  410. #define GPT_UUID_LINUX \
  411. { 0x0f, 0xc6, 0x3d, 0xaf, 0x84, 0x83, 0x47, 0x72, \
  412. 0x8e, 0x79, 0x3d, 0x69, 0xd8, 0x47, 0x7d, 0xe4 }
  413. #define GPT_UUID_LINUX_HOME \
  414. { 0x93, 0x3a, 0xc7, 0xe1, 0x2e, 0xb4, 0x4f, 0x13, \
  415. 0xb8, 0x44, 0x0e, 0x14, 0xe2, 0xae, 0xf9, 0x15 }
  416. #define GPT_UUID_LINUX_SRV \
  417. { 0x3b, 0x8f, 0x84, 0x25, 0x20, 0xe0, 0x4f, 0x3b, \
  418. 0x90, 0x7f, 0x1a, 0x25, 0xa7, 0x6f, 0x98, 0xe8 }
  419. #define GPT_UUID_FBSD_DATA \
  420. { 0x51, 0x6e, 0x7c, 0xb4, 0x6e, 0xcf, 0x11, 0xd6, \
  421. 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
  422. #define GPT_UUID_FBSD_UFS \
  423. { 0x51, 0x6e, 0x7c, 0xb6, 0x6e, 0xcf, 0x11, 0xd6, \
  424. 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
  425. #define GPT_UUID_NBSD_UFS \
  426. { 0x49, 0xf4, 0x8d, 0x5a, 0xb1, 0x0e, 0x11, 0xdc, \
  427. 0xb9, 0x9b, 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 }
  428. #define GPT_UUID_APPLE_HFS \
  429. { 0x48, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
  430. 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
  431. #define GPT_UUID_APPLE_UFS \
  432. { 0x55, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
  433. 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
  434. /* DOS partition table -- located at start of some disks. */
  435. #define DOS_LABELSECTOR 1
  436. #define DOSBBSECTOR 0 /* DOS boot block relative sector # */
  437. #define DOSPARTOFF 446
  438. #define DOSDISKOFF 444
  439. #define NDOSPART 4
  440. #define DOSACTIVE 0x80 /* active partition */
  441. #define DOSMBR_SIGNATURE (0xaa55)
  442. #define DOSMBR_SIGNATURE_OFF (0x1fe)
  443. /* Maximum number of Extended Boot Records (EBRs) to traverse. */
  444. #define DOS_MAXEBR 256
  445. struct dos_partition {
  446. u_int8_t dp_flag; /* bootstrap flags */
  447. u_int8_t dp_shd; /* starting head */
  448. u_int8_t dp_ssect; /* starting sector */
  449. u_int8_t dp_scyl; /* starting cylinder */
  450. u_int8_t dp_typ; /* partition type (see below) */
  451. u_int8_t dp_ehd; /* end head */
  452. u_int8_t dp_esect; /* end sector */
  453. u_int8_t dp_ecyl; /* end cylinder */
  454. u_int32_t dp_start; /* absolute starting sector number */
  455. u_int32_t dp_size; /* partition size in sectors */
  456. };
  457. /* Isolate the relevant bits to get sector and cylinder. */
  458. #define DPSECT(s) ((s) & 0x3f)
  459. #define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
  460. /* Known DOS partition types. */
  461. #define DOSPTYP_UNUSED 0x00 /* Unused partition */
  462. #define DOSPTYP_FAT12 0x01 /* 12-bit FAT */
  463. #define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */
  464. #define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */
  465. #define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */
  466. #define DOSPTYP_NTFS 0x07 /* NTFS */
  467. #define DOSPTYP_FAT32 0x0b /* 32-bit FAT */
  468. #define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */
  469. #define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */
  470. #define DOSPTYP_EXTENDL 0x0f /* Extended, LBA-mapped; (sub-partitions) */
  471. #define DOSPTYP_ONTRACK 0x54
  472. #define DOSPTYP_LINUX 0x83 /* That other thing */
  473. #define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */
  474. #define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */
  475. #define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */
  476. #define DOSPTYP_EFI 0xee /* EFI Protective Partition */
  477. #define DOSPTYP_EFISYS 0xef /* EFI System Partition */
  478. struct dos_mbr {
  479. u_int8_t dmbr_boot[DOSPARTOFF];
  480. struct dos_partition dmbr_parts[NDOSPART];
  481. u_int16_t dmbr_sign;
  482. } __packed;
  483. #ifdef _KERNEL
  484. void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
  485. u_int dkcksum(struct disklabel *);
  486. int initdisklabel(struct disklabel *);
  487. int checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t);
  488. int setdisklabel(struct disklabel *, struct disklabel *, u_int);
  489. int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
  490. int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
  491. int bounds_check_with_label(struct buf *, struct disklabel *);
  492. int readdoslabel(struct buf *, void (*)(struct buf *),
  493. struct disklabel *, daddr_t *, int);
  494. #ifdef GPT
  495. int readgptlabel(struct buf *, void (*)(struct buf *),
  496. struct disklabel *, daddr_t *, int);
  497. #endif
  498. #ifdef CD9660
  499. int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
  500. struct disklabel *lp);
  501. #endif
  502. #ifdef UDF
  503. int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
  504. struct disklabel *lp);
  505. #endif
  506. #endif
  507. #endif /* _LOCORE */
  508. #if !defined(_KERNEL) && !defined(_LOCORE)
  509. #include <sys/cdefs.h>
  510. __BEGIN_DECLS
  511. struct disklabel *getdiskbyname(const char *);
  512. __END_DECLS
  513. #endif