1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang *
4a9643ea8Slogwang * Copyright (c) 1987, 1988, 1993
5a9643ea8Slogwang * The Regents of the University of California. All rights reserved.
6a9643ea8Slogwang *
7a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without
8a9643ea8Slogwang * modification, are permitted provided that the following conditions
9a9643ea8Slogwang * are met:
10a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright
11a9643ea8Slogwang * notice, this list of conditions and the following disclaimer.
12a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright
13a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the
14a9643ea8Slogwang * documentation and/or other materials provided with the distribution.
15*22ce4affSfengbojiang * 3. Neither the name of the University nor the names of its contributors
16a9643ea8Slogwang * may be used to endorse or promote products derived from this software
17a9643ea8Slogwang * without specific prior written permission.
18a9643ea8Slogwang *
19a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29a9643ea8Slogwang * SUCH DAMAGE.
30a9643ea8Slogwang *
31a9643ea8Slogwang * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
32a9643ea8Slogwang * $FreeBSD$
33a9643ea8Slogwang */
34a9643ea8Slogwang
35a9643ea8Slogwang #ifndef _SYS_DISKLABEL_H_
36a9643ea8Slogwang #define _SYS_DISKLABEL_H_
37a9643ea8Slogwang
38a9643ea8Slogwang #ifndef _KERNEL
39a9643ea8Slogwang #include <sys/types.h>
40a9643ea8Slogwang #endif
41a9643ea8Slogwang #include <sys/ioccom.h>
42a9643ea8Slogwang
43*22ce4affSfengbojiang #include <sys/disk/bsd.h>
44*22ce4affSfengbojiang
45*22ce4affSfengbojiang /* Disk description table, see disktab(5) */
46a9643ea8Slogwang #define _PATH_DISKTAB "/etc/disktab"
47a9643ea8Slogwang
48a9643ea8Slogwang /*
49a9643ea8Slogwang * The label is in block 0 or 1, possibly offset from the beginning
50a9643ea8Slogwang * to leave room for a bootstrap, etc.
51*22ce4affSfengbojiang * XXX these should be defined per controller (or drive) elsewhere, not here!
52*22ce4affSfengbojiang * XXX in actuality it can't even be per controller or drive. It should be
53*22ce4affSfengbojiang * constant/fixed across storage hardware and CPU architectures. Disks can
54*22ce4affSfengbojiang * travel from one machine to another and a label created on one machine
55*22ce4affSfengbojiang * should be detectable and understood by the other.
56a9643ea8Slogwang */
57a9643ea8Slogwang #define LABELSECTOR 1 /* sector containing label */
58a9643ea8Slogwang #define LABELOFFSET 0 /* offset of label in sector */
59a9643ea8Slogwang
60*22ce4affSfengbojiang #define DISKMAGIC BSD_MAGIC /* The disk magic number */
61*22ce4affSfengbojiang
62a9643ea8Slogwang #ifndef MAXPARTITIONS
63*22ce4affSfengbojiang #define MAXPARTITIONS BSD_NPARTS_MIN
64a9643ea8Slogwang #endif
65a9643ea8Slogwang
66a9643ea8Slogwang /* Size of bootblock area in sector-size neutral bytes */
67*22ce4affSfengbojiang #define BBSIZE BSD_BOOTBLOCK_SIZE
68a9643ea8Slogwang
69*22ce4affSfengbojiang #define LABEL_PART BSD_PART_RAW
70*22ce4affSfengbojiang #define RAW_PART BSD_PART_RAW
71*22ce4affSfengbojiang #define SWAP_PART BSD_PART_SWAP
72a9643ea8Slogwang
73*22ce4affSfengbojiang #define NDDATA BSD_NDRIVEDATA
74*22ce4affSfengbojiang #define NSPARE BSD_NSPARE
75a9643ea8Slogwang
76a9643ea8Slogwang static __inline u_int16_t dkcksum(struct disklabel *lp);
77a9643ea8Slogwang static __inline u_int16_t
dkcksum(struct disklabel * lp)78a9643ea8Slogwang dkcksum(struct disklabel *lp)
79a9643ea8Slogwang {
80a9643ea8Slogwang u_int16_t *start, *end;
81a9643ea8Slogwang u_int16_t sum = 0;
82a9643ea8Slogwang
83a9643ea8Slogwang start = (u_int16_t *)lp;
84a9643ea8Slogwang end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions];
85a9643ea8Slogwang while (start < end)
86a9643ea8Slogwang sum ^= *start++;
87a9643ea8Slogwang return (sum);
88a9643ea8Slogwang }
89a9643ea8Slogwang
90a9643ea8Slogwang #ifdef DKTYPENAMES
91a9643ea8Slogwang static const char *dktypenames[] = {
92a9643ea8Slogwang "unknown",
93a9643ea8Slogwang "SMD",
94a9643ea8Slogwang "MSCP",
95a9643ea8Slogwang "old DEC",
96a9643ea8Slogwang "SCSI",
97a9643ea8Slogwang "ESDI",
98a9643ea8Slogwang "ST506",
99a9643ea8Slogwang "HP-IB",
100a9643ea8Slogwang "HP-FL",
101a9643ea8Slogwang "type 9",
102a9643ea8Slogwang "floppy",
103a9643ea8Slogwang "CCD",
104a9643ea8Slogwang "Vinum",
105a9643ea8Slogwang "DOC2K",
106a9643ea8Slogwang "Raid",
107a9643ea8Slogwang "?",
108a9643ea8Slogwang "jfs",
109a9643ea8Slogwang NULL
110a9643ea8Slogwang };
111a9643ea8Slogwang #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
112a9643ea8Slogwang #endif
113a9643ea8Slogwang
114a9643ea8Slogwang #ifdef FSTYPENAMES
115a9643ea8Slogwang static const char *fstypenames[] = {
116a9643ea8Slogwang "unused",
117a9643ea8Slogwang "swap",
118a9643ea8Slogwang "Version 6",
119a9643ea8Slogwang "Version 7",
120a9643ea8Slogwang "System V",
121a9643ea8Slogwang "4.1BSD",
122a9643ea8Slogwang "Eighth Edition",
123a9643ea8Slogwang "4.2BSD",
124a9643ea8Slogwang "MSDOS",
125a9643ea8Slogwang "4.4LFS",
126a9643ea8Slogwang "unknown",
127a9643ea8Slogwang "HPFS",
128a9643ea8Slogwang "ISO9660",
129a9643ea8Slogwang "boot",
130a9643ea8Slogwang "vinum",
131a9643ea8Slogwang "raid",
132a9643ea8Slogwang "Filecore",
133a9643ea8Slogwang "EXT2FS",
134a9643ea8Slogwang "NTFS",
135a9643ea8Slogwang "?",
136a9643ea8Slogwang "ccd",
137a9643ea8Slogwang "jfs",
138a9643ea8Slogwang "HAMMER",
139a9643ea8Slogwang "HAMMER2",
140a9643ea8Slogwang "UDF",
141a9643ea8Slogwang "?",
142a9643ea8Slogwang "EFS",
143a9643ea8Slogwang "ZFS",
144a9643ea8Slogwang "?",
145a9643ea8Slogwang "?",
146a9643ea8Slogwang "nandfs",
147a9643ea8Slogwang NULL
148a9643ea8Slogwang };
149a9643ea8Slogwang #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
150a9643ea8Slogwang #endif
151a9643ea8Slogwang
152a9643ea8Slogwang /*
153a9643ea8Slogwang * NB: <sys/disk.h> defines ioctls from 'd'/128 and up.
154a9643ea8Slogwang */
155a9643ea8Slogwang
156a9643ea8Slogwang /*
157a9643ea8Slogwang * Functions for proper encoding/decoding of struct disklabel into/from
158a9643ea8Slogwang * bytestring.
159a9643ea8Slogwang */
160a9643ea8Slogwang void bsd_partition_le_dec(u_char *ptr, struct partition *d);
161a9643ea8Slogwang int bsd_disklabel_le_dec(u_char *ptr, struct disklabel *d, int maxpart);
162a9643ea8Slogwang void bsd_partition_le_enc(u_char *ptr, struct partition *d);
163a9643ea8Slogwang void bsd_disklabel_le_enc(u_char *ptr, struct disklabel *d);
164a9643ea8Slogwang
165a9643ea8Slogwang #ifndef _KERNEL
166a9643ea8Slogwang __BEGIN_DECLS
167a9643ea8Slogwang struct disklabel *getdiskbyname(const char *);
168a9643ea8Slogwang __END_DECLS
169a9643ea8Slogwang #endif
170a9643ea8Slogwang
171a9643ea8Slogwang #endif /* !_SYS_DISKLABEL_H_ */
172