1 /* $NetBSD: disk.h,v 1.24 2003/08/07 16:34:01 agc 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. 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/time.h> 90 #include <sys/queue.h> 91 92 struct buf; 93 struct disklabel; 94 struct cpu_disklabel; 95 96 struct disk { 97 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ 98 char *dk_name; /* disk name */ 99 int dk_bopenmask; /* block devices open */ 100 int dk_copenmask; /* character devices open */ 101 int dk_openmask; /* composite (bopen|copen) */ 102 int dk_state; /* label state ### */ 103 int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ 104 int dk_byteshift; /* shift to convert bytes to blks */ 105 106 /* 107 * Metrics data; note that some metrics may have no meaning 108 * on certain types of disks. 109 */ 110 int dk_busy; /* busy counter */ 111 u_int64_t dk_rxfer; /* total number of read transfers */ 112 u_int64_t dk_wxfer; /* total number of write transfers */ 113 u_int64_t dk_seek; /* total independent seek operations */ 114 u_int64_t dk_rbytes; /* total bytes read */ 115 u_int64_t dk_wbytes; /* total bytes written */ 116 struct timeval dk_attachtime; /* time disk was attached */ 117 struct timeval dk_timestamp; /* timestamp of last unbusy */ 118 struct timeval dk_time; /* total time spent busy */ 119 120 struct dkdriver *dk_driver; /* pointer to driver */ 121 122 /* 123 * Disk label information. Storage for the in-core disk label 124 * must be dynamically allocated, otherwise the size of this 125 * structure becomes machine-dependent. 126 */ 127 daddr_t dk_labelsector; /* sector containing label */ 128 struct disklabel *dk_label; /* label */ 129 struct cpu_disklabel *dk_cpulabel; 130 }; 131 132 #define DK_DISKNAMELEN 16 133 134 /* The following structure is 64-bit alignment safe */ 135 struct disk_sysctl { 136 char dk_name[DK_DISKNAMELEN]; 137 int32_t dk_busy; 138 int32_t pad; 139 u_int64_t dk_xfer; 140 u_int64_t dk_seek; 141 u_int64_t dk_bytes; 142 u_int32_t dk_attachtime_sec; 143 u_int32_t dk_attachtime_usec; 144 u_int32_t dk_timestamp_sec; 145 u_int32_t dk_timestamp_usec; 146 u_int32_t dk_time_sec; 147 u_int32_t dk_time_usec; 148 /* New separate read/write stats */ 149 u_int64_t dk_rxfer; 150 u_int64_t dk_rbytes; 151 u_int64_t dk_wxfer; 152 u_int64_t dk_wbytes; 153 }; 154 155 struct dkdriver { 156 void (*d_strategy) __P((struct buf *)); 157 #ifdef notyet 158 int (*d_open) __P((dev_t, int, int, struct proc *)); 159 int (*d_close) __P((dev_t, int, int, struct proc *)); 160 int (*d_ioctl) __P((dev_t, u_long, caddr_t, int, struct proc *)); 161 int (*d_dump) __P((dev_t)); 162 void (*d_start) __P((struct buf *, daddr_t)); 163 int (*d_mklabel) __P((struct disk *)); 164 #endif 165 }; 166 167 /* states */ 168 #define DK_CLOSED 0 /* drive is closed */ 169 #define DK_WANTOPEN 1 /* drive being opened */ 170 #define DK_WANTOPENRAW 2 /* drive being opened */ 171 #define DK_RDLABEL 3 /* label being read */ 172 #define DK_OPEN 4 /* label read, drive open */ 173 #define DK_OPENRAW 5 /* open without label */ 174 175 /* 176 * disklist_head is defined here so that user-land has access to it. 177 */ 178 TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ 179 180 /* 181 * Bad sector lists per fixed disk 182 */ 183 struct disk_badsectors { 184 SLIST_ENTRY(disk_badsectors) dbs_next; 185 daddr_t dbs_min; /* min. sector number */ 186 daddr_t dbs_max; /* max. sector number */ 187 struct timeval dbs_failedat; /* first failure at */ 188 }; 189 190 struct disk_badsecinfo { 191 u_int32_t dbsi_bufsize; /* size of region pointed to */ 192 u_int32_t dbsi_skip; /* how many to skip past */ 193 u_int32_t dbsi_copied; /* how many got copied back */ 194 u_int32_t dbsi_left; /* remaining to copy */ 195 caddr_t dbsi_buffer; /* region to copy disk_badsectors to */ 196 }; 197 198 #ifdef _KERNEL 199 extern int disk_count; /* number of disks in global disklist */ 200 201 void disk_init __P((void)); 202 void disk_attach __P((struct disk *)); 203 void disk_detach __P((struct disk *)); 204 void disk_busy __P((struct disk *)); 205 void disk_unbusy __P((struct disk *, long, int)); 206 void disk_resetstat __P((struct disk *)); 207 struct disk *disk_find __P((char *)); 208 #endif 209 210 #endif /* _SYS_DISK_H_ */ 211