1 /**	$MirOS: src/sys/arch/i386/include/disklabel.h,v 1.3 2008/11/08 23:04:06 tg Exp $ */
2 /*	$OpenBSD: disklabel.h,v 1.26 2003/11/16 20:30:06 avsm Exp $	*/
3 /*	$NetBSD: disklabel.h,v 1.3 1996/03/09 20:52:54 ghudson Exp $	*/
4 
5 /*
6  * Copyright (c) 1994 Christopher G. Demetriou
7  * Copyright (c) 2004
8  *	Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by Christopher G. Demetriou.
22  * 4. The name of the author may not be used to endorse or promote products
23  *    derived from this software without specific prior written permission
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef	_MACHINE_DISKLABEL_H_
38 #define	_MACHINE_DISKLABEL_H_
39 
40 #define	LABELSECTOR	1		/* sector containing label */
41 #define	LABELOFFSET	0		/* offset of label in sector */
42 #define	MAXPARTITIONS	16		/* number of partitions */
43 #define	RAW_PART	2		/* raw partition: ie. rsd0c */
44 
45 /* DOS partition table -- located in boot block */
46 #define	DOSBBSECTOR	0		/* DOS boot block relative sector # */
47 #define	DOSPARTOFF	446
48 #define	DOSDISKOFF	444
49 #define	NDOSPART	4
50 #define	DOSACTIVE	0x80		/* active partition */
51 
52 struct dos_partition {
53 	u_int8_t	dp_flag;	/* bootstrap flags */
54 	u_int8_t	dp_shd;		/* starting head */
55 	u_int8_t	dp_ssect;	/* starting sector */
56 	u_int8_t	dp_scyl;	/* starting cylinder */
57 	u_int8_t	dp_typ;		/* partition type (see below) */
58 	u_int8_t	dp_ehd;		/* end head */
59 	u_int8_t	dp_esect;	/* end sector */
60 	u_int8_t	dp_ecyl;	/* end cylinder */
61 	u_int32_t	dp_start;	/* absolute starting sector number */
62 	u_int32_t	dp_size;	/* partition size in sectors */
63 };
64 
65 /* Known DOS partition types. */
66 #define	DOSPTYP_UNUSED	0x00		/* Unused partition */
67 #define	DOSPTYP_FAT12	0x01		/* 12-bit FAT */
68 #define	DOSPTYP_FAT16S	0x04		/* 16-bit FAT, less than 32M */
69 #define	DOSPTYP_EXTEND	0x05		/* Extended; contains sub-partitions */
70 #define	DOSPTYP_FAT16B	0x06		/* 16-bit FAT, more than 32M */
71 #define	DOSPTYP_NTFS	0x07		/* OS/2 HPFS, now NT OS/2 NTFS */
72 #define	DOSPTYP_FAT32	0x0B		/* 32-bit FAT */
73 #define	DOSPTYP_FAT32L	0x0C		/* 32-bit FAT, LBA-mapped */
74 #define	DOSPTYP_FAT16L	0x0E		/* 16-bit FAT, LBA-mapped */
75 #define	DOSPTYP_EXTENDL	0x0F		/* Extended, LBA-mapped */
76 #define	DOSPTYP_MIRBSD	0x27		/* MirBSD partition type */
77 #define	DOSPTYP_ONTRACK	0x54
78 #define	DOSPTYP_LINUX	0x83		/* That other thing */
79 #define	DOSPTYP_EXTENDLX 0x85		/* Extended, Linux (pre-EXTENDL) */
80 #define	DOSPTYP_FREEBSD	0xA5		/* FreeBSD partition type */
81 #define	DOSPTYP_OPENBSD	0xA6		/* OpenBSD partition type */
82 #define	DOSPTYP_NETBSD	0xA9		/* NetBSD partition type */
83 
84 struct dos_mbr {
85 	u_int8_t		dmbr_boot[DOSPARTOFF];
86 	struct dos_partition	dmbr_parts[NDOSPART];
87 	u_int16_t		dmbr_sign;
88 } __packed;
89 
90 #define DOSMBR_SIGNATURE	(0xaa55)
91 #define DOSMBR_SIGNATURE_OFF	(0x1fe)
92 
93 #include <sys/dkbad.h>
94 struct cpu_disklabel {
95 	struct dos_partition dosparts[NDOSPART];
96 	struct dkbad bad;
97 };
98 
99 #define DKBAD(x) ((x)->bad)
100 
101 /* Isolate the relevant bits to get sector and cylinder. */
102 #define	DPSECT(s)	((s) & 0x3f)
103 #define	DPCYL(c, s)	((c) + (((s) & 0xc0) << 2))
104 
105 static __inline u_int32_t get_le(void *);
106 static __inline void      set_le(void *, u_int32_t);
107 
108 static __inline u_int32_t
get_le(void * _p)109 get_le(void *_p)
110 {
111 	u_int8_t *p = (u_int8_t *)_p;
112 	u_int32_t x;
113 	x = p[0] | p[1] << 8;
114 	x |= p[2] << 16 | p[3] << 24;
115 	return x;
116 }
117 
118 static __inline void
set_le(void * _p,u_int32_t x)119 set_le(void *_p, u_int32_t x)
120 {
121 	u_int8_t *p = (u_int8_t *)_p;
122 	p[0] = (x & 0xFF);
123 	p[1] = ((x >> 8) & 0xFF);
124 	p[2] = ((x >> 16) & 0xFF);
125 	p[3] = ((x >> 24) & 0xFF);
126 }
127 
128 #endif	/* _MACHINE_DISKLABEL_H_ */
129