1 /* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Jason R. Thorpe. All rights reserved. 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This software was developed by the Computer Systems Engineering group 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 10 * contributed to Berkeley. 11 * 12 * All advertising materials mentioning features or use of this software 13 * must display the following acknowledgement: 14 * This product includes software developed by the University of 15 * California, Lawrence Berkeley Laboratory. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. All advertising materials mentioning features or use of this software 26 * must display the following acknowledgement: 27 * This product includes software developed by the University of 28 * California, Berkeley and its contributors. 29 * 4. Neither the name of the University nor the names of its contributors 30 * may be used to endorse or promote products derived from this software 31 * without specific prior written permission. 32 * 33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 43 * SUCH DAMAGE. 44 * 45 * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) 46 * 47 * @(#)disk.h 8.1 (Berkeley) 6/2/93 48 */ 49 50 /* 51 * Disk device structures. 52 */ 53 54 #include <sys/time.h> 55 #include <sys/queue.h> 56 57 struct buf; 58 struct disklabel; 59 struct cpu_disklabel; 60 61 struct disk { 62 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ 63 char *dk_name; /* disk name */ 64 int dk_bopenmask; /* block devices open */ 65 int dk_copenmask; /* character devices open */ 66 int dk_openmask; /* composite (bopen|copen) */ 67 int dk_state; /* label state ### */ 68 int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ 69 int dk_byteshift; /* shift to convert bytes to blks */ 70 71 /* 72 * Metrics data; note that some metrics may have no meaning 73 * on certain types of disks. 74 */ 75 int dk_busy; /* busy counter */ 76 u_int64_t dk_xfer; /* total number of transfers */ 77 u_int64_t dk_seek; /* total independent seek operations */ 78 u_int64_t dk_bytes; /* total bytes transfered */ 79 struct timeval dk_attachtime; /* time disk was attached */ 80 struct timeval dk_timestamp; /* timestamp of last unbusy */ 81 struct timeval dk_time; /* total time spent busy */ 82 83 struct dkdriver *dk_driver; /* pointer to driver */ 84 85 /* 86 * Disk label information. Storage for the in-core disk label 87 * must be dynamically allocated, otherwise the size of this 88 * structure becomes machine-dependent. 89 */ 90 daddr_t dk_labelsector; /* sector containing label */ 91 struct disklabel *dk_label; /* label */ 92 struct cpu_disklabel *dk_cpulabel; 93 }; 94 95 struct dkdriver { 96 void (*d_strategy) __P((struct buf *)); 97 #ifdef notyet 98 int (*d_open) __P((dev_t dev, int ifmt, int, struct proc *)); 99 int (*d_close) __P((dev_t dev, int, int ifmt, struct proc *)); 100 int (*d_ioctl) __P((dev_t dev, u_long cmd, caddr_t data, int fflag, 101 struct proc *)); 102 int (*d_dump) __P((dev_t)); 103 void (*d_start) __P((struct buf *, daddr_t)); 104 int (*d_mklabel) __P((struct disk *)); 105 #endif 106 }; 107 108 /* states */ 109 #define DK_CLOSED 0 /* drive is closed */ 110 #define DK_WANTOPEN 1 /* drive being opened */ 111 #define DK_WANTOPENRAW 2 /* drive being opened */ 112 #define DK_RDLABEL 3 /* label being read */ 113 #define DK_OPEN 4 /* label read, drive open */ 114 #define DK_OPENRAW 5 /* open without label */ 115 116 #ifdef DISKSORT_STATS 117 /* 118 * Stats from disksort(). 119 */ 120 struct disksort_stats { 121 long ds_newhead; /* # new queue heads created */ 122 long ds_newtail; /* # new queue tails created */ 123 long ds_midfirst; /* # insertions into sort list */ 124 long ds_endfirst; /* # insertions at end of sort list */ 125 long ds_newsecond; /* # inversions (2nd lists) created */ 126 long ds_midsecond; /* # insertions into 2nd list */ 127 long ds_endsecond; /* # insertions at end of 2nd list */ 128 }; 129 #endif 130 131 /* 132 * disklist_head is defined here so that user-land has access to it. 133 */ 134 TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ 135 136 #ifdef _KERNEL 137 extern int disk_count; /* number of disks in global disklist */ 138 139 void disk_init __P((void)); 140 void disk_attach __P((struct disk *)); 141 void disk_detach __P((struct disk *)); 142 void disk_busy __P((struct disk *)); 143 void disk_unbusy __P((struct disk *, long)); 144 void disk_resetstat __P((struct disk *)); 145 struct disk *disk_find __P((char *)); 146 147 struct device; 148 void dk_establish __P((struct disk *, struct device *)); 149 #endif 150