Thu Jun 8 22:24:59 2017 UTC ()
do not expose kernel-internal structure definitions to userland.
needed for ZFS.


(chs)
diff -r1.70 -r1.71 src/sys/sys/disk.h

cvs diff -r1.70 -r1.71 src/sys/sys/disk.h (switch to unified diff)

--- src/sys/sys/disk.h 2017/03/05 23:07:12 1.70
+++ src/sys/sys/disk.h 2017/06/08 22:24:59 1.71
@@ -1,560 +1,555 @@ @@ -1,560 +1,555 @@
1/* $NetBSD: disk.h,v 1.70 2017/03/05 23:07:12 mlelstv Exp $ */ 1/* $NetBSD: disk.h,v 1.71 2017/06/08 22:24:59 chs Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Copyright (c) 1992, 1993 34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved. 35 * The Regents of the University of California. All rights reserved.
36 * 36 *
37 * This software was developed by the Computer Systems Engineering group 37 * This software was developed by the Computer Systems Engineering group
38 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 38 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
39 * contributed to Berkeley. 39 * contributed to Berkeley.
40 * 40 *
41 * All advertising materials mentioning features or use of this software 41 * All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement: 42 * must display the following acknowledgement:
43 * This product includes software developed by the University of 43 * This product includes software developed by the University of
44 * California, Lawrence Berkeley Laboratories. 44 * California, Lawrence Berkeley Laboratories.
45 * 45 *
46 * Redistribution and use in source and binary forms, with or without 46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions 47 * modification, are permitted provided that the following conditions
48 * are met: 48 * are met:
49 * 1. Redistributions of source code must retain the above copyright 49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer. 50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright 51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the 52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution. 53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors 54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software 55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission. 56 * without specific prior written permission.
57 * 57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 * 69 *
70 * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) 70 * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL)
71 * 71 *
72 * @(#)disk.h 8.2 (Berkeley) 1/9/95 72 * @(#)disk.h 8.2 (Berkeley) 1/9/95
73 */ 73 */
74 74
75#ifndef _SYS_DISK_H_ 75#ifndef _SYS_DISK_H_
76#define _SYS_DISK_H_ 76#define _SYS_DISK_H_
77 77
78/* 78/*
79 * Disk device structures. 79 * Disk device structures.
80 */ 80 */
81 81
82#ifdef _KERNEL 
83#include <sys/device.h> 
84#endif 
85#include <sys/dkio.h> 82#include <sys/dkio.h>
86#include <sys/time.h> 83#include <sys/time.h>
87#include <sys/queue.h> 84#include <sys/queue.h>
88#include <sys/mutex.h> 
89#include <sys/iostat.h> 
90 
91#include <prop/proplib.h> 
92 
93struct buf; 
94struct disk; 
95struct disklabel; 
96struct cpu_disklabel; 
97struct lwp; 
98struct vnode; 
99 85
100/* 86/*
101 * Disk information dictionary. 87 * Disk information dictionary.
102 * 88 *
103 * This contains general infomation for disk devices. 89 * This contains general infomation for disk devices.
104 * 90 *
105 * <dict> 91 * <dict>
106 * <key>type</key> 92 * <key>type</key>
107 * <string>...</string> 93 * <string>...</string>
108 * <key>geometry</key> 94 * <key>geometry</key>
109 * <dict> 95 * <dict>
110 * <!-- See below for disk geometry dictionary 96 * <!-- See below for disk geometry dictionary
111 * contents. --> 97 * contents. -->
112 * </dict> 98 * </dict>
113 * 99 *
114 * <!-- optional information --> 100 * <!-- optional information -->
115 * <key>rpm</key> 101 * <key>rpm</key>
116 * <integer>...</integer> 102 * <integer>...</integer>
117 * <key>sector-interleave</key> 103 * <key>sector-interleave</key>
118 * <integer>...</integer> 104 * <integer>...</integer>
119 * <key>track-skew</key> 105 * <key>track-skew</key>
120 * <integer>...</integer> 106 * <integer>...</integer>
121 * <key>cylinder-skew</key> 107 * <key>cylinder-skew</key>
122 * <integer>...</integer> 108 * <integer>...</integer>
123 * <key>head-switch-usecs</key> 109 * <key>head-switch-usecs</key>
124 * <integer>...</integer> 110 * <integer>...</integer>
125 * <key>track-seek-usecs</key> 111 * <key>track-seek-usecs</key>
126 * <integer>...</integer> 112 * <integer>...</integer>
127 * <key>removable</key> 113 * <key>removable</key>
128 * <false/> 114 * <false/>
129 * <key>ecc</key> 115 * <key>ecc</key>
130 * <false/> 116 * <false/>
131 * <key>bad-sector-forwarding</key> 117 * <key>bad-sector-forwarding</key>
132 * <true/> 118 * <true/>
133 * <key>ramdisk</key> 119 * <key>ramdisk</key>
134 * <false/> 120 * <false/>
135 * <key>back-to-back-transfers</key> 121 * <key>back-to-back-transfers</key>
136 * <true/> 122 * <true/>
137 * 123 *
138 * <!-- additional information for SMD drives --> 124 * <!-- additional information for SMD drives -->
139 * <key>smd-skip-sectoring</key> 125 * <key>smd-skip-sectoring</key>
140 * <false/> 126 * <false/>
141 * <!-- XXX better names for these properties --> 127 * <!-- XXX better names for these properties -->
142 * <key>smd-mindist</key> 128 * <key>smd-mindist</key>
143 * <integer>...</integer> 129 * <integer>...</integer>
144 * <key>smd-maxdist</key> 130 * <key>smd-maxdist</key>
145 * <integer>...</integer> 131 * <integer>...</integer>
146 * <key>smd-sdist</key> 132 * <key>smd-sdist</key>
147 * <integer>...</integer> 133 * <integer>...</integer>
148 * 134 *
149 * <!-- additional information for ST506 drives --> 135 * <!-- additional information for ST506 drives -->
150 * <!-- XXX better names for these properties --> 136 * <!-- XXX better names for these properties -->
151 * <key>st506-precompcyl</key> 137 * <key>st506-precompcyl</key>
152 * <integer>...</integer> 138 * <integer>...</integer>
153 * <key>st506-gap3</key> 139 * <key>st506-gap3</key>
154 * <integer>...</integer> 140 * <integer>...</integer>
155 * 141 *
156 * <!-- additional information for ATA drives --> 142 * <!-- additional information for ATA drives -->
157 * <!-- XXX --> 143 * <!-- XXX -->
158 * 144 *
159 * <!-- additional information for SCSI drives --> 145 * <!-- additional information for SCSI drives -->
160 * <!-- XXX --> 146 * <!-- XXX -->
161 * </dict> 147 * </dict>
162 */ 148 */
163 149
164/* 150/*
165 * dkwedge_info: 151 * dkwedge_info:
166 * 152 *
167 * Information needed to configure (or query configuration of) a 153 * Information needed to configure (or query configuration of) a
168 * disk wedge. 154 * disk wedge.
169 */ 155 */
170struct dkwedge_info { 156struct dkwedge_info {
171 char dkw_devname[16];/* device-style name (e.g. "dk0") */ 157 char dkw_devname[16];/* device-style name (e.g. "dk0") */
172 uint8_t dkw_wname[128]; /* wedge name (Unicode, UTF-8) */ 158 uint8_t dkw_wname[128]; /* wedge name (Unicode, UTF-8) */
173 char dkw_parent[16]; /* parent disk device name */ 159 char dkw_parent[16]; /* parent disk device name */
174 daddr_t dkw_offset; /* LBA offset of wedge in parent */ 160 daddr_t dkw_offset; /* LBA offset of wedge in parent */
175 uint64_t dkw_size; /* size of wedge in blocks */ 161 uint64_t dkw_size; /* size of wedge in blocks */
176 char dkw_ptype[32]; /* partition type string */ 162 char dkw_ptype[32]; /* partition type string */
177}; 163};
178 164
179/* 165/*
180 * dkwedge_list: 166 * dkwedge_list:
181 * 167 *
182 * Structure used to query a list of wedges. 168 * Structure used to query a list of wedges.
183 */ 169 */
184struct dkwedge_list { 170struct dkwedge_list {
185 void *dkwl_buf; /* storage for dkwedge_info array */ 171 void *dkwl_buf; /* storage for dkwedge_info array */
186 size_t dkwl_bufsize; /* size of that buffer */ 172 size_t dkwl_bufsize; /* size of that buffer */
187 u_int dkwl_nwedges; /* total number of wedges */ 173 u_int dkwl_nwedges; /* total number of wedges */
188 u_int dkwl_ncopied; /* number actually copied */ 174 u_int dkwl_ncopied; /* number actually copied */
189}; 175};
190 176
191#ifdef _KERNEL 
192/* 
193 * dkwedge_discovery_method: 
194 * 
195 * Structure used to describe partition map parsing schemes 
196 * used for wedge autodiscovery. 
197 */ 
198struct dkwedge_discovery_method { 
199 /* link in wedge driver's list */ 
200 LIST_ENTRY(dkwedge_discovery_method) ddm_list; 
201 const char *ddm_name; /* name of this method */ 
202 int ddm_priority; /* search priority */ 
203 int (*ddm_discover)(struct disk *, struct vnode *); 
204}; 
205 
206#define DKWEDGE_DISCOVERY_METHOD_DECL(name, prio, discover) \ 
207static struct dkwedge_discovery_method name ## _ddm = { \ 
208 { NULL, NULL }, \ 
209 #name, \ 
210 prio, \ 
211 discover \ 
212}; \ 
213__link_set_add_data(dkwedge_methods, name ## _ddm) 
214#endif /* _KERNEL */ 
215 
216/* Some common partition types */ 177/* Some common partition types */
217#define DKW_PTYPE_UNKNOWN "" 178#define DKW_PTYPE_UNKNOWN ""
218#define DKW_PTYPE_UNUSED "unused" 179#define DKW_PTYPE_UNUSED "unused"
219#define DKW_PTYPE_SWAP "swap" 180#define DKW_PTYPE_SWAP "swap"
220#define DKW_PTYPE_V6 "v6" 181#define DKW_PTYPE_V6 "v6"
221#define DKW_PTYPE_V7 "v7" 182#define DKW_PTYPE_V7 "v7"
222#define DKW_PTYPE_SYSV "sysv" 183#define DKW_PTYPE_SYSV "sysv"
223#define DKW_PTYPE_V71K "v71k" 184#define DKW_PTYPE_V71K "v71k"
224#define DKW_PTYPE_V8 "v8" 185#define DKW_PTYPE_V8 "v8"
225#define DKW_PTYPE_FFS "ffs" 186#define DKW_PTYPE_FFS "ffs"
226#define DKW_PTYPE_FAT "msdos" 187#define DKW_PTYPE_FAT "msdos"
227#define DKW_PTYPE_LFS "lfs" 188#define DKW_PTYPE_LFS "lfs"
228#define DKW_PTYPE_OTHER "other" 189#define DKW_PTYPE_OTHER "other"
229#define DKW_PTYPE_HPFS "hpfs" 190#define DKW_PTYPE_HPFS "hpfs"
230#define DKW_PTYPE_ISO9660 "cd9660" 191#define DKW_PTYPE_ISO9660 "cd9660"
231#define DKW_PTYPE_BOOT "boot" 192#define DKW_PTYPE_BOOT "boot"
232#define DKW_PTYPE_AMIGADOS "ados" 193#define DKW_PTYPE_AMIGADOS "ados"
233#define DKW_PTYPE_HFS "hfs" 194#define DKW_PTYPE_HFS "hfs"
234#define DKW_PTYPE_FILECORE "filecore" 195#define DKW_PTYPE_FILECORE "filecore"
235#define DKW_PTYPE_EXT2FS "ext2fs" 196#define DKW_PTYPE_EXT2FS "ext2fs"
236#define DKW_PTYPE_NTFS "ntfs" 197#define DKW_PTYPE_NTFS "ntfs"
237#define DKW_PTYPE_RAIDFRAME "raidframe" 198#define DKW_PTYPE_RAIDFRAME "raidframe"
238#define DKW_PTYPE_CCD "ccd" 199#define DKW_PTYPE_CCD "ccd"
239#define DKW_PTYPE_JFS2 "jfs2" 200#define DKW_PTYPE_JFS2 "jfs2"
240#define DKW_PTYPE_APPLEUFS "appleufs" 201#define DKW_PTYPE_APPLEUFS "appleufs"
241#define DKW_PTYPE_VINUM "vinum" 202#define DKW_PTYPE_VINUM "vinum"
242#define DKW_PTYPE_UDF "udf" 203#define DKW_PTYPE_UDF "udf"
243#define DKW_PTYPE_APPLEHFS "hfs" 204#define DKW_PTYPE_APPLEHFS "hfs"
244#define DKW_PTYPE_SYSVBFS "sysvbfs" 205#define DKW_PTYPE_SYSVBFS "sysvbfs"
245#define DKW_PTYPE_EFS "efs" 206#define DKW_PTYPE_EFS "efs"
246#define DKW_PTYPE_NILFS "nilfs" 207#define DKW_PTYPE_NILFS "nilfs"
247#define DKW_PTYPE_CGD "cgd" 208#define DKW_PTYPE_CGD "cgd"
248#define DKW_PTYPE_MINIXFS3 "minixfs3" 209#define DKW_PTYPE_MINIXFS3 "minixfs3"
249 210
250/* 211/*
251 * Ensure each symbol used in FSTYPE_DEFN in <sys/disklabel.h> 212 * Ensure each symbol used in FSTYPE_DEFN in <sys/disklabel.h>
252 * has a corresponding DKW_PTYPE_* definition. 213 * has a corresponding DKW_PTYPE_* definition.
253 */ 214 */
254#define DKW_PTYPE_MSDOS DKW_PTYPE_FAT 215#define DKW_PTYPE_MSDOS DKW_PTYPE_FAT
255#define DKW_PTYPE_BSDFFS DKW_PTYPE_FFS 216#define DKW_PTYPE_BSDFFS DKW_PTYPE_FFS
256#define DKW_PTYPE_BSDLFS DKW_PTYPE_LFS 217#define DKW_PTYPE_BSDLFS DKW_PTYPE_LFS
257#define DKW_PTYPE_ADOS DKW_PTYPE_AMIGADOS 218#define DKW_PTYPE_ADOS DKW_PTYPE_AMIGADOS
258#define DKW_PTYPE_EX2FS DKW_PTYPE_EXT2FS 219#define DKW_PTYPE_EX2FS DKW_PTYPE_EXT2FS
259#define DKW_PTYPE_RAID DKW_PTYPE_RAIDFRAME 220#define DKW_PTYPE_RAID DKW_PTYPE_RAIDFRAME
260 221
261/* 222/*
262 * Disk geometry dictionary. 223 * Disk geometry dictionary.
263 * 224 *
264 * NOTE: Not all geometry information is relevant for every kind of disk. 225 * NOTE: Not all geometry information is relevant for every kind of disk.
265 * 226 *
266 * <dict> 227 * <dict>
267 * <key>sectors-per-unit</key> 228 * <key>sectors-per-unit</key>
268 * <integer>...</integer> 229 * <integer>...</integer>
269 * <key>sector-size</key> 230 * <key>sector-size</key>
270 * <integer>...</integer> 231 * <integer>...</integer>
271 * <key>sectors-per-track</key> 232 * <key>sectors-per-track</key>
272 * <integer>...</integer> 233 * <integer>...</integer>
273 * <key>tracks-per-cylinder</key> 234 * <key>tracks-per-cylinder</key>
274 * <integer>...</integer> 235 * <integer>...</integer>
275 * <key>cylinders-per-unit</key> 236 * <key>cylinders-per-unit</key>
276 * <integer>...</integer> 237 * <integer>...</integer>
277 * <key>physical-cylinders-per-unit</key> 238 * <key>physical-cylinders-per-unit</key>
278 * <integer>...</integer> 239 * <integer>...</integer>
279 * <key>spare-sectors-per-track</key> 240 * <key>spare-sectors-per-track</key>
280 * <integer>...</integer> 241 * <integer>...</integer>
281 * <key>spare-sectors-per-cylinder</key> 242 * <key>spare-sectors-per-cylinder</key>
282 * <integer>...</integer> 243 * <integer>...</integer>
283 * <key>alternative-cylinders</key> 244 * <key>alternative-cylinders</key>
284 * <integer>...</integer> 245 * <integer>...</integer>
285 * </dict> 246 * </dict>
286 * NOTE: Not all geometry information is relevant for every kind of disk. 247 * NOTE: Not all geometry information is relevant for every kind of disk.
287 */ 248 */
288 249
289struct disk_geom { 250struct disk_geom {
290 int64_t dg_secperunit; /* # of data sectors per unit */ 251 int64_t dg_secperunit; /* # of data sectors per unit */
291 uint32_t dg_secsize; /* # of bytes per sector */ 252 uint32_t dg_secsize; /* # of bytes per sector */
292 uint32_t dg_nsectors; /* # of data sectors per track */ 253 uint32_t dg_nsectors; /* # of data sectors per track */
293 uint32_t dg_ntracks; /* # of tracks per cylinder */ 254 uint32_t dg_ntracks; /* # of tracks per cylinder */
294 uint32_t dg_ncylinders; /* # of data cylinders per unit */ 255 uint32_t dg_ncylinders; /* # of data cylinders per unit */
295 uint32_t dg_secpercyl; /* # of data sectors per cylinder */ 256 uint32_t dg_secpercyl; /* # of data sectors per cylinder */
296 uint32_t dg_pcylinders; /* # of physical cylinders per unit */ 257 uint32_t dg_pcylinders; /* # of physical cylinders per unit */
297 258
298 /* 259 /*
299 * Spares (bad sector replacements) below are not counted in 260 * Spares (bad sector replacements) below are not counted in
300 * dg_nsectors or dg_secpercyl. Spare sectors are assumed to 261 * dg_nsectors or dg_secpercyl. Spare sectors are assumed to
301 * be physical sectors which occupy space at the end of each 262 * be physical sectors which occupy space at the end of each
302 * track and/or cylinder. 263 * track and/or cylinder.
303 */ 264 */
304 uint32_t dg_sparespertrack; 265 uint32_t dg_sparespertrack;
305 uint32_t dg_sparespercyl; 266 uint32_t dg_sparespercyl;
306 /* 267 /*
307 * Alternative cylinders include maintenance, replacement, 268 * Alternative cylinders include maintenance, replacement,
308 * configuration description areas, etc. 269 * configuration description areas, etc.
309 */ 270 */
310 uint32_t dg_acylinders; 271 uint32_t dg_acylinders;
311}; 272};
312 273
313/* 274/*
 275 * Bad sector lists per fixed disk
 276 */
 277struct disk_badsectors {
 278 SLIST_ENTRY(disk_badsectors) dbs_next;
 279 daddr_t dbs_min; /* min. sector number */
 280 daddr_t dbs_max; /* max. sector number */
 281 struct timeval dbs_failedat; /* first failure at */
 282};
 283
 284struct disk_badsecinfo {
 285 uint32_t dbsi_bufsize; /* size of region pointed to */
 286 uint32_t dbsi_skip; /* how many to skip past */
 287 uint32_t dbsi_copied; /* how many got copied back */
 288 uint32_t dbsi_left; /* remaining to copy */
 289 void * dbsi_buffer; /* region to copy disk_badsectors to */
 290};
 291
 292#define DK_STRATEGYNAMELEN 32
 293struct disk_strategy {
 294 char dks_name[DK_STRATEGYNAMELEN]; /* name of strategy */
 295 char *dks_param; /* notyet; should be NULL */
 296 size_t dks_paramlen; /* notyet; should be 0 */
 297};
 298
 299#ifdef _KERNEL
 300#include <sys/device.h>
 301#include <sys/mutex.h>
 302#include <sys/iostat.h>
 303
 304#include <prop/proplib.h>
 305
 306struct buf;
 307struct disk;
 308struct disklabel;
 309struct cpu_disklabel;
 310struct lwp;
 311struct vnode;
 312
 313/*
 314 * dkwedge_discovery_method:
 315 *
 316 * Structure used to describe partition map parsing schemes
 317 * used for wedge autodiscovery.
 318 */
 319struct dkwedge_discovery_method {
 320 /* link in wedge driver's list */
 321 LIST_ENTRY(dkwedge_discovery_method) ddm_list;
 322 const char *ddm_name; /* name of this method */
 323 int ddm_priority; /* search priority */
 324 int (*ddm_discover)(struct disk *, struct vnode *);
 325};
 326
 327#define DKWEDGE_DISCOVERY_METHOD_DECL(name, prio, discover) \
 328static struct dkwedge_discovery_method name ## _ddm = { \
 329 { NULL, NULL }, \
 330 #name, \
 331 prio, \
 332 discover \
 333}; \
 334__link_set_add_data(dkwedge_methods, name ## _ddm)
 335
 336/*
314 * Disk partition dictionary. 337 * Disk partition dictionary.
315 * 338 *
316 * A partition is represented as a dictionary containing generic partition 339 * A partition is represented as a dictionary containing generic partition
317 * properties (such as starting block and block count), as well as information 340 * properties (such as starting block and block count), as well as information
318 * that is specific to individual partition map formats. 341 * that is specific to individual partition map formats.
319 * 342 *
320 * <dict> 343 * <dict>
321 * <key>start-block</key> 344 * <key>start-block</key>
322 * <integer>...</integer> 345 * <integer>...</integer>
323 * <key>block-count</key> 346 * <key>block-count</key>
324 * <integer>...</integer> 347 * <integer>...</integer>
325 * <!-- DKW_PTYPE strings ("" or missing if unknown) --> 348 * <!-- DKW_PTYPE strings ("" or missing if unknown) -->
326 * <key>type</type> 349 * <key>type</type>
327 * <string>...</string> 350 * <string>...</string>
328 * <!-- optional --> 351 * <!-- optional -->
329 * <key>name</key> 352 * <key>name</key>
330 * <string>...</string> 353 * <string>...</string>
331 * 354 *
332 * <!-- these are valid for GPT partition maps --> 355 * <!-- these are valid for GPT partition maps -->
333 * <key>gpt-type-guid</key> 356 * <key>gpt-type-guid</key>
334 * <string>...</string> 357 * <string>...</string>
335 * <key>gpt-partition-guid</key> 358 * <key>gpt-partition-guid</key>
336 * <string>...</string> 359 * <string>...</string>
337 * <key>gpt-platform-required</key> 360 * <key>gpt-platform-required</key>
338 * <false/> 361 * <false/>
339 * 362 *
340 * <!-- these are valid for 4.4BSD partition maps --> 363 * <!-- these are valid for 4.4BSD partition maps -->
341 * <key>bsd44-partition-type</key> 364 * <key>bsd44-partition-type</key>
342 * <integer>...</integer> 365 * <integer>...</integer>
343 * <key>bsd44-fs-fragment-size</key> 366 * <key>bsd44-fs-fragment-size</key>
344 * <integer>...</integer> 367 * <integer>...</integer>
345 * <key>bsd44-iso9660-session-offset</key> 368 * <key>bsd44-iso9660-session-offset</key>
346 * <integer>...</integer> 369 * <integer>...</integer>
347 * <key>bsd44-ffs-cylinders-per-group</key> 370 * <key>bsd44-ffs-cylinders-per-group</key>
348 * <integer>...</integer> 371 * <integer>...</integer>
349 * <key>bsd44-lfs-segment-shift</key> 372 * <key>bsd44-lfs-segment-shift</key>
350 * <integer>...</integer> 373 * <integer>...</integer>
351 * 374 *
352 * <!-- these are valid for NeXT partition maps --> 375 * <!-- these are valid for NeXT partition maps -->
353 * <key>next-block-size</key> 376 * <key>next-block-size</key>
354 * <integer>...</integer> 377 * <integer>...</integer>
355 * <key>next-fs-fragment-size</key> 378 * <key>next-fs-fragment-size</key>
356 * <integer>...</integer> 379 * <integer>...</integer>
357 * <key>next-fs-optimization</key> 380 * <key>next-fs-optimization</key>
358 * <string>...</string> <!-- "space" or "time" --> 381 * <string>...</string> <!-- "space" or "time" -->
359 * <key>next-fs-cylinders-per-group</key> 382 * <key>next-fs-cylinders-per-group</key>
360 * <integer>...</integer> 383 * <integer>...</integer>
361 * <key>next-bytes-per-inode-density</key> 384 * <key>next-bytes-per-inode-density</key>
362 * <integer>...</integer> 385 * <integer>...</integer>
363 * <key>next-minfree-percentage</key> 386 * <key>next-minfree-percentage</key>
364 * <integer>...</integer> 387 * <integer>...</integer>
365 * <key>next-run-newfs-during-init</key> 388 * <key>next-run-newfs-during-init</key>
366 * <false/> 389 * <false/>
367 * <key>next-mount-point</key> 390 * <key>next-mount-point</key>
368 * <string>...</string> 391 * <string>...</string>
369 * <key>next-automount</key> 392 * <key>next-automount</key>
370 * <true/> 393 * <true/>
371 * <key>next-partition-type</key> 394 * <key>next-partition-type</key>
372 * <string>...</string> 395 * <string>...</string>
373 * 396 *
374 * <!-- these are valid for MBR partition maps --> 397 * <!-- these are valid for MBR partition maps -->
375 * <key>mbr-start-head</key> 398 * <key>mbr-start-head</key>
376 * <integer>...</integer> 399 * <integer>...</integer>
377 * <key>mbr-start-sector</key> 400 * <key>mbr-start-sector</key>
378 * <integer>...</integer> 401 * <integer>...</integer>
379 * <key>mbr-start-cylinder</key> 402 * <key>mbr-start-cylinder</key>
380 * <integer>...</integer> 403 * <integer>...</integer>
381 * <key>mbr-partition-type</key> 404 * <key>mbr-partition-type</key>
382 * <integer>...</integer> 405 * <integer>...</integer>
383 * <key>mbr-end-head</key> 406 * <key>mbr-end-head</key>
384 * <integer>...</integer> 407 * <integer>...</integer>
385 * <key>mbr-end-sector</key> 408 * <key>mbr-end-sector</key>
386 * <integer>...</integer> 409 * <integer>...</integer>
387 * <key>mbr-end-cylinder</key> 410 * <key>mbr-end-cylinder</key>
388 * <integer>...</integer> 411 * <integer>...</integer>
389 * <key>mbr-active-partition</key> 412 * <key>mbr-active-partition</key>
390 * <false/> 413 * <false/>
391 * 414 *
392 * <!-- these are valid for Apple partition maps --> 415 * <!-- these are valid for Apple partition maps -->
393 * <key>apple-partition-type</key> 416 * <key>apple-partition-type</key>
394 * <string>...</string> 417 * <string>...</string>
395 * <!-- XXX What else do we need? wrstuden? --> 418 * <!-- XXX What else do we need? wrstuden? -->
396 * 419 *
397 * <!-- these are valid for RISCiX partition maps --> 420 * <!-- these are valid for RISCiX partition maps -->
398 * <key>riscix-partition-type</key> 421 * <key>riscix-partition-type</key>
399 * <integer>...</integer> 422 * <integer>...</integer>
400 * 423 *
401 * <!-- these are valid for MIPS/SGI partition maps --> 424 * <!-- these are valid for MIPS/SGI partition maps -->
402 * <key>mips-partition-type</key> 425 * <key>mips-partition-type</key>
403 * <integer>...</integer> 426 * <integer>...</integer>
404 * 427 *
405 * <!-- SunOS 4 partition maps have no specific 428 * <!-- SunOS 4 partition maps have no specific
406 * additional information. Note, however, 429 * additional information. Note, however,
407 * that SunOS 4 partitions must begin on 430 * that SunOS 4 partitions must begin on
408 * cylinder boundaries. --> 431 * cylinder boundaries. -->
409 * 432 *
410 * <!-- XXX Need Amiga partition map info --> 433 * <!-- XXX Need Amiga partition map info -->
411 * 434 *
412 * <!-- these are valid for VTOC partition maps --> 435 * <!-- these are valid for VTOC partition maps -->
413 * <key>vtoc-tag</key> 436 * <key>vtoc-tag</key>
414 * <integer>...</integer> 437 * <integer>...</integer>
415 * <key>vtoc-unmount</key> 438 * <key>vtoc-unmount</key>
416 * <false/> 439 * <false/>
417 * <key>vtoc-read-only</key> 440 * <key>vtoc-read-only</key>
418 * <false/> 441 * <false/>
419 * <!-- XXX is this really part of the partition info? --> 442 * <!-- XXX is this really part of the partition info? -->
420 * <key>vtoc-timestamp</key> 443 * <key>vtoc-timestamp</key>
421 * <integer>...</integer> 444 * <integer>...</integer>
422 * 445 *
423 * <!-- mvme68k partition maps use 4.4BSD partition 446 * <!-- mvme68k partition maps use 4.4BSD partition
424 * info stuffed into two different areas of the 447 * info stuffed into two different areas of the
425 * disk information label recognized by BUG. --> 448 * disk information label recognized by BUG. -->
426 * 449 *
427 * <!-- XXX What else? --> 450 * <!-- XXX What else? -->
428 * </dict> 451 * </dict>
429 */ 452 */
430 453
431struct disk { 454struct disk {
432 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ 455 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */
433 const char *dk_name; /* disk name */ 456 const char *dk_name; /* disk name */
434 prop_dictionary_t dk_info; /* reference to disk-info dictionary */ 457 prop_dictionary_t dk_info; /* reference to disk-info dictionary */
435 struct disk_geom dk_geom; /* cooked version of dk_info */ 458 struct disk_geom dk_geom; /* cooked version of dk_info */
436 int dk_bopenmask; /* block devices open */ 459 int dk_bopenmask; /* block devices open */
437 int dk_copenmask; /* character devices open */ 460 int dk_copenmask; /* character devices open */
438 int dk_openmask; /* composite (bopen|copen) */ 461 int dk_openmask; /* composite (bopen|copen) */
439 int dk_state; /* label state ### */ 462 int dk_state; /* label state ### */
440 int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ 463 int dk_blkshift; /* shift to convert DEV_BSIZE to blks */
441 int dk_byteshift; /* shift to convert bytes to blks */ 464 int dk_byteshift; /* shift to convert bytes to blks */
442 465
443 /* 466 /*
444 * Metrics data; note that some metrics may have no meaning 467 * Metrics data; note that some metrics may have no meaning
445 * on certain types of disks. 468 * on certain types of disks.
446 */ 469 */
447 struct io_stats *dk_stats; 470 struct io_stats *dk_stats;
448 471
449 const struct dkdriver *dk_driver; /* pointer to driver */ 472 const struct dkdriver *dk_driver; /* pointer to driver */
450 473
451 /* 474 /*
452 * Information required to be the parent of a disk wedge. 475 * Information required to be the parent of a disk wedge.
453 */ 476 */
454 kmutex_t dk_rawlock; /* lock on these fields */ 477 kmutex_t dk_rawlock; /* lock on these fields */
455 u_int dk_rawopens; /* # of openes of rawvp */ 478 u_int dk_rawopens; /* # of openes of rawvp */
456 struct vnode *dk_rawvp; /* vnode for the RAW_PART bdev */ 479 struct vnode *dk_rawvp; /* vnode for the RAW_PART bdev */
457 480
458 kmutex_t dk_openlock; /* lock on these and openmask */ 481 kmutex_t dk_openlock; /* lock on these and openmask */
459 u_int dk_nwedges; /* # of configured wedges */ 482 u_int dk_nwedges; /* # of configured wedges */
460 /* all wedges on this disk */ 483 /* all wedges on this disk */
461 LIST_HEAD(, dkwedge_softc) dk_wedges; 484 LIST_HEAD(, dkwedge_softc) dk_wedges;
462 485
463 /* 486 /*
464 * Disk label information. Storage for the in-core disk label 487 * Disk label information. Storage for the in-core disk label
465 * must be dynamically allocated, otherwise the size of this 488 * must be dynamically allocated, otherwise the size of this
466 * structure becomes machine-dependent. 489 * structure becomes machine-dependent.
467 */ 490 */
468 daddr_t dk_labelsector; /* sector containing label */ 491 daddr_t dk_labelsector; /* sector containing label */
469 struct disklabel *dk_label; /* label */ 492 struct disklabel *dk_label; /* label */
470 struct cpu_disklabel *dk_cpulabel; 493 struct cpu_disklabel *dk_cpulabel;
471}; 494};
472 495
473#ifdef _KERNEL 
474struct dkdriver { 496struct dkdriver {
475 void (*d_strategy)(struct buf *); 497 void (*d_strategy)(struct buf *);
476 void (*d_minphys)(struct buf *); 498 void (*d_minphys)(struct buf *);
477 int (*d_open)(dev_t, int, int, struct lwp *); 499 int (*d_open)(dev_t, int, int, struct lwp *);
478 int (*d_close)(dev_t, int, int, struct lwp *); 500 int (*d_close)(dev_t, int, int, struct lwp *);
479 int (*d_diskstart)(device_t, struct buf *); 501 int (*d_diskstart)(device_t, struct buf *);
480 void (*d_iosize)(device_t, int *); 502 void (*d_iosize)(device_t, int *);
481 int (*d_dumpblocks)(device_t, void *, daddr_t, int); 503 int (*d_dumpblocks)(device_t, void *, daddr_t, int);
482 int (*d_lastclose)(device_t); 504 int (*d_lastclose)(device_t);
483 int (*d_discard)(device_t, off_t, off_t); 505 int (*d_discard)(device_t, off_t, off_t);
484 int (*d_firstopen)(device_t, dev_t, int, int); 506 int (*d_firstopen)(device_t, dev_t, int, int);
485 void (*d_label)(device_t, struct disklabel *lp); 507 void (*d_label)(device_t, struct disklabel *lp);
486}; 508};
487#endif 
488 509
489/* states */ 510/* states */
490#define DK_CLOSED 0 /* drive is closed */ 511#define DK_CLOSED 0 /* drive is closed */
491#define DK_WANTOPEN 1 /* drive being opened */ 512#define DK_WANTOPEN 1 /* drive being opened */
492#define DK_WANTOPENRAW 2 /* drive being opened */ 513#define DK_WANTOPENRAW 2 /* drive being opened */
493#define DK_RDLABEL 3 /* label being read */ 514#define DK_RDLABEL 3 /* label being read */
494#define DK_OPEN 4 /* label read, drive open */ 515#define DK_OPEN 4 /* label read, drive open */
495#define DK_OPENRAW 5 /* open without label */ 516#define DK_OPENRAW 5 /* open without label */
496 517
497/* 
498 * Bad sector lists per fixed disk 
499 */ 
500struct disk_badsectors { 
501 SLIST_ENTRY(disk_badsectors) dbs_next; 
502 daddr_t dbs_min; /* min. sector number */ 
503 daddr_t dbs_max; /* max. sector number */ 
504 struct timeval dbs_failedat; /* first failure at */ 
505}; 
506 
507struct disk_badsecinfo { 
508 uint32_t dbsi_bufsize; /* size of region pointed to */ 
509 uint32_t dbsi_skip; /* how many to skip past */ 
510 uint32_t dbsi_copied; /* how many got copied back */ 
511 uint32_t dbsi_left; /* remaining to copy */ 
512 void * dbsi_buffer; /* region to copy disk_badsectors to */ 
513}; 
514 
515#define DK_STRATEGYNAMELEN 32 
516struct disk_strategy { 
517 char dks_name[DK_STRATEGYNAMELEN]; /* name of strategy */ 
518 char *dks_param; /* notyet; should be NULL */ 
519 size_t dks_paramlen; /* notyet; should be 0 */ 
520}; 
521 
522#define DK_BSIZE2BLKSHIFT(b) ((ffs((b) / DEV_BSIZE)) - 1) 518#define DK_BSIZE2BLKSHIFT(b) ((ffs((b) / DEV_BSIZE)) - 1)
523#define DK_BSIZE2BYTESHIFT(b) (ffs((b)) - 1) 519#define DK_BSIZE2BYTESHIFT(b) (ffs((b)) - 1)
524#define DK_DEV_BSIZE_OK(b) \ 520#define DK_DEV_BSIZE_OK(b) \
525 ((b) >= DEV_BSIZE && ((b) & ((b) - 1)) == 0 && (b) <= MAXPHYS) 521 ((b) >= DEV_BSIZE && ((b) & ((b) - 1)) == 0 && (b) <= MAXPHYS)
526 522
527#ifdef _KERNEL 
528extern int disk_count; /* number of disks in global disklist */ 523extern int disk_count; /* number of disks in global disklist */
529 524
530struct proc; 525struct proc;
531 526
532void disk_attach(struct disk *); 527void disk_attach(struct disk *);
533int disk_begindetach(struct disk *, int (*)(device_t), device_t, int); 528int disk_begindetach(struct disk *, int (*)(device_t), device_t, int);
534void disk_detach(struct disk *); 529void disk_detach(struct disk *);
535void disk_init(struct disk *, const char *, const struct dkdriver *); 530void disk_init(struct disk *, const char *, const struct dkdriver *);
536void disk_destroy(struct disk *); 531void disk_destroy(struct disk *);
537void disk_wait(struct disk *); 532void disk_wait(struct disk *);
538void disk_busy(struct disk *); 533void disk_busy(struct disk *);
539void disk_unbusy(struct disk *, long, int); 534void disk_unbusy(struct disk *, long, int);
540bool disk_isbusy(struct disk *); 535bool disk_isbusy(struct disk *);
541struct disk *disk_find(const char *); 536struct disk *disk_find(const char *);
542int disk_ioctl(struct disk *, dev_t, u_long, void *, int, struct lwp *); 537int disk_ioctl(struct disk *, dev_t, u_long, void *, int, struct lwp *);
543void disk_set_info(device_t, struct disk *, const char *); 538void disk_set_info(device_t, struct disk *, const char *);
544 539
545void dkwedge_init(void); 540void dkwedge_init(void);
546int dkwedge_add(struct dkwedge_info *); 541int dkwedge_add(struct dkwedge_info *);
547int dkwedge_del(struct dkwedge_info *); 542int dkwedge_del(struct dkwedge_info *);
548void dkwedge_delall(struct disk *); 543void dkwedge_delall(struct disk *);
549int dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *); 544int dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *);
550void dkwedge_discover(struct disk *); 545void dkwedge_discover(struct disk *);
551int dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t); 546int dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t);
552device_t dkwedge_find_by_wname(const char *); 547device_t dkwedge_find_by_wname(const char *);
553device_t dkwedge_find_by_parent(const char *, size_t *); 548device_t dkwedge_find_by_parent(const char *, size_t *);
554const char *dkwedge_get_parent_name(dev_t); 549const char *dkwedge_get_parent_name(dev_t);
555void dkwedge_print_wnames(void); 550void dkwedge_print_wnames(void);
556device_t dkwedge_find_partition(device_t, daddr_t, uint64_t); 551device_t dkwedge_find_partition(device_t, daddr_t, uint64_t);
557 552
558#endif 553#endif /* _KERNEL */
559 554
560#endif /* _SYS_DISK_H_ */ 555#endif /* _SYS_DISK_H_ */