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