1 /* $NetBSD: disk.h,v 1.17 2002/01/27 12:41:09 simonb 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 #define DK_DISKNAMELEN 16 135 136 /* The following structure is 64-bit alignment safe */ 137 struct disk_sysctl { 138 char dk_name[DK_DISKNAMELEN]; 139 int32_t dk_busy; 140 int32_t pad; 141 u_int64_t dk_xfer; 142 u_int64_t dk_seek; 143 u_int64_t dk_bytes; 144 u_int32_t dk_attachtime_sec; 145 u_int32_t dk_attachtime_usec; 146 u_int32_t dk_timestamp_sec; 147 u_int32_t dk_timestamp_usec; 148 u_int32_t dk_time_sec; 149 u_int32_t dk_time_usec; 150 }; 151 152 struct dkdriver { 153 void (*d_strategy) __P((struct buf *)); 154 #ifdef notyet 155 int (*d_open) __P((dev_t dev, int ifmt, int, struct proc *)); 156 int (*d_close) __P((dev_t dev, int, int ifmt, struct proc *)); 157 int (*d_ioctl) __P((dev_t dev, u_long cmd, caddr_t data, int fflag, 158 struct proc *)); 159 int (*d_dump) __P((dev_t)); 160 void (*d_start) __P((struct buf *, daddr_t)); 161 int (*d_mklabel) __P((struct disk *)); 162 #endif 163 }; 164 165 /* states */ 166 #define DK_CLOSED 0 /* drive is closed */ 167 #define DK_WANTOPEN 1 /* drive being opened */ 168 #define DK_WANTOPENRAW 2 /* drive being opened */ 169 #define DK_RDLABEL 3 /* label being read */ 170 #define DK_OPEN 4 /* label read, drive open */ 171 #define DK_OPENRAW 5 /* open without label */ 172 173 #ifdef DISKSORT_STATS 174 /* 175 * Stats from disksort(). 176 */ 177 struct disksort_stats { 178 long ds_newhead; /* # new queue heads created */ 179 long ds_newtail; /* # new queue tails created */ 180 long ds_midfirst; /* # insertions into sort list */ 181 long ds_endfirst; /* # insertions at end of sort list */ 182 long ds_newsecond; /* # inversions (2nd lists) created */ 183 long ds_midsecond; /* # insertions into 2nd list */ 184 long ds_endsecond; /* # insertions at end of 2nd list */ 185 }; 186 #endif 187 188 /* 189 * disklist_head is defined here so that user-land has access to it. 190 */ 191 TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ 192 193 #ifdef _KERNEL 194 extern int disk_count; /* number of disks in global disklist */ 195 196 void disk_init __P((void)); 197 void disk_attach __P((struct disk *)); 198 void disk_detach __P((struct disk *)); 199 void disk_busy __P((struct disk *)); 200 void disk_unbusy __P((struct disk *, long)); 201 void disk_resetstat __P((struct disk *)); 202 struct disk *disk_find __P((char *)); 203 204 #ifdef __BROKEN_DK_ESTABLISH /* XXX DEPRECATED */ 205 struct device; 206 void dk_establish __P((struct disk *, struct device *)); 207 #endif 208 #endif 209 210 #endif /* _SYS_DISK_H_ */ 211