1 /* $NetBSD: disk.h,v 1.16 2000/05/16 05:45:53 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1997 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. All advertising materials mentioning features or use of this software 62 * must display the following acknowledgement: 63 * This product includes software developed by the University of 64 * California, Berkeley and its contributors. 65 * 4. Neither the name of the University nor the names of its contributors 66 * may be used to endorse or promote products derived from this software 67 * without specific prior written permission. 68 * 69 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 70 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 71 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 72 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 73 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 74 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 75 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 76 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 77 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 78 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 79 * SUCH DAMAGE. 80 * 81 * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) 82 * 83 * @(#)disk.h 8.2 (Berkeley) 1/9/95 84 */ 85 86 #ifndef _SYS_DISK_H_ 87 #define _SYS_DISK_H_ 88 89 /* 90 * Disk device structures. 91 */ 92 93 #include <sys/time.h> 94 #include <sys/queue.h> 95 96 struct buf; 97 struct disklabel; 98 struct cpu_disklabel; 99 100 struct disk { 101 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ 102 char *dk_name; /* disk name */ 103 int dk_bopenmask; /* block devices open */ 104 int dk_copenmask; /* character devices open */ 105 int dk_openmask; /* composite (bopen|copen) */ 106 int dk_state; /* label state ### */ 107 int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ 108 int dk_byteshift; /* shift to convert bytes to blks */ 109 110 /* 111 * Metrics data; note that some metrics may have no meaning 112 * on certain types of disks. 113 */ 114 int dk_busy; /* busy counter */ 115 u_int64_t dk_xfer; /* total number of transfers */ 116 u_int64_t dk_seek; /* total independent seek operations */ 117 u_int64_t dk_bytes; /* total bytes transfered */ 118 struct timeval dk_attachtime; /* time disk was attached */ 119 struct timeval dk_timestamp; /* timestamp of last unbusy */ 120 struct timeval dk_time; /* total time spent busy */ 121 122 struct dkdriver *dk_driver; /* pointer to driver */ 123 124 /* 125 * Disk label information. Storage for the in-core disk label 126 * must be dynamically allocated, otherwise the size of this 127 * structure becomes machine-dependent. 128 */ 129 daddr_t dk_labelsector; /* sector containing label */ 130 struct disklabel *dk_label; /* label */ 131 struct cpu_disklabel *dk_cpulabel; 132 }; 133 134 struct dkdriver { 135 void (*d_strategy) __P((struct buf *)); 136 #ifdef notyet 137 int (*d_open) __P((dev_t dev, int ifmt, int, struct proc *)); 138 int (*d_close) __P((dev_t dev, int, int ifmt, struct proc *)); 139 int (*d_ioctl) __P((dev_t dev, u_long cmd, caddr_t data, int fflag, 140 struct proc *)); 141 int (*d_dump) __P((dev_t)); 142 void (*d_start) __P((struct buf *, daddr_t)); 143 int (*d_mklabel) __P((struct disk *)); 144 #endif 145 }; 146 147 /* states */ 148 #define DK_CLOSED 0 /* drive is closed */ 149 #define DK_WANTOPEN 1 /* drive being opened */ 150 #define DK_WANTOPENRAW 2 /* drive being opened */ 151 #define DK_RDLABEL 3 /* label being read */ 152 #define DK_OPEN 4 /* label read, drive open */ 153 #define DK_OPENRAW 5 /* open without label */ 154 155 #ifdef DISKSORT_STATS 156 /* 157 * Stats from disksort(). 158 */ 159 struct disksort_stats { 160 long ds_newhead; /* # new queue heads created */ 161 long ds_newtail; /* # new queue tails created */ 162 long ds_midfirst; /* # insertions into sort list */ 163 long ds_endfirst; /* # insertions at end of sort list */ 164 long ds_newsecond; /* # inversions (2nd lists) created */ 165 long ds_midsecond; /* # insertions into 2nd list */ 166 long ds_endsecond; /* # insertions at end of 2nd list */ 167 }; 168 #endif 169 170 /* 171 * disklist_head is defined here so that user-land has access to it. 172 */ 173 TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ 174 175 #ifdef _KERNEL 176 extern int disk_count; /* number of disks in global disklist */ 177 178 void disk_init __P((void)); 179 void disk_attach __P((struct disk *)); 180 void disk_detach __P((struct disk *)); 181 void disk_busy __P((struct disk *)); 182 void disk_unbusy __P((struct disk *, long)); 183 void disk_resetstat __P((struct disk *)); 184 struct disk *disk_find __P((char *)); 185 186 #ifdef __BROKEN_DK_ESTABLISH /* XXX DEPRECATED */ 187 struct device; 188 void dk_establish __P((struct disk *, struct device *)); 189 #endif 190 #endif 191 192 #endif /* _SYS_DISK_H_ */ 193