xref: /netbsd-src/sys/sys/disk.h (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: disk.h,v 1.12 1997/10/05 18:43:23 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 Laboratory.
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.1 (Berkeley) 6/2/93
84  */
85 
86 /*
87  * Disk device structures.
88  */
89 
90 #include <sys/time.h>
91 #include <sys/queue.h>
92 
93 struct buf;
94 struct disklabel;
95 struct cpu_disklabel;
96 
97 struct disk {
98 	TAILQ_ENTRY(disk) dk_link;	/* link in global disklist */
99 	char		*dk_name;	/* disk name */
100 	int		dk_bopenmask;	/* block devices open */
101 	int		dk_copenmask;	/* character devices open */
102 	int		dk_openmask;	/* composite (bopen|copen) */
103 	int		dk_state;	/* label state   ### */
104 	int		dk_blkshift;	/* shift to convert DEV_BSIZE to blks */
105 	int		dk_byteshift;	/* shift to convert bytes to blks */
106 
107 	/*
108 	 * Metrics data; note that some metrics may have no meaning
109 	 * on certain types of disks.
110 	 */
111 	int		dk_busy;	/* busy counter */
112 	u_int64_t	dk_xfer;	/* total number of transfers */
113 	u_int64_t	dk_seek;	/* total independent seek operations */
114 	u_int64_t	dk_bytes;	/* total bytes transfered */
115 	struct timeval	dk_attachtime;	/* time disk was attached */
116 	struct timeval	dk_timestamp;	/* timestamp of last unbusy */
117 	struct timeval	dk_time;	/* total time spent busy */
118 
119 	struct	dkdriver *dk_driver;	/* pointer to driver */
120 
121 	/*
122 	 * Disk label information.  Storage for the in-core disk label
123 	 * must be dynamically allocated, otherwise the size of this
124 	 * structure becomes machine-dependent.
125 	 */
126 	daddr_t		dk_labelsector;		/* sector containing label */
127 	struct disklabel *dk_label;	/* label */
128 	struct cpu_disklabel *dk_cpulabel;
129 };
130 
131 struct dkdriver {
132 	void	(*d_strategy) __P((struct buf *));
133 #ifdef notyet
134 	int	(*d_open) __P((dev_t dev, int ifmt, int, struct proc *));
135 	int	(*d_close) __P((dev_t dev, int, int ifmt, struct proc *));
136 	int	(*d_ioctl) __P((dev_t dev, u_long cmd, caddr_t data, int fflag,
137 				struct proc *));
138 	int	(*d_dump) __P((dev_t));
139 	void	(*d_start) __P((struct buf *, daddr_t));
140 	int	(*d_mklabel) __P((struct disk *));
141 #endif
142 };
143 
144 /* states */
145 #define	DK_CLOSED	0		/* drive is closed */
146 #define	DK_WANTOPEN	1		/* drive being opened */
147 #define	DK_WANTOPENRAW	2		/* drive being opened */
148 #define	DK_RDLABEL	3		/* label being read */
149 #define	DK_OPEN		4		/* label read, drive open */
150 #define	DK_OPENRAW	5		/* open without label */
151 
152 #ifdef DISKSORT_STATS
153 /*
154  * Stats from disksort().
155  */
156 struct disksort_stats {
157 	long	ds_newhead;		/* # new queue heads created */
158 	long	ds_newtail;		/* # new queue tails created */
159 	long	ds_midfirst;		/* # insertions into sort list */
160 	long	ds_endfirst;		/* # insertions at end of sort list */
161 	long	ds_newsecond;		/* # inversions (2nd lists) created */
162 	long	ds_midsecond;		/* # insertions into 2nd list */
163 	long	ds_endsecond;		/* # insertions at end of 2nd list */
164 };
165 #endif
166 
167 /*
168  * disklist_head is defined here so that user-land has access to it.
169  */
170 TAILQ_HEAD(disklist_head, disk);	/* the disklist is a TAILQ */
171 
172 #ifdef _KERNEL
173 extern	int disk_count;			/* number of disks in global disklist */
174 
175 void	disk_init __P((void));
176 void	disk_attach __P((struct disk *));
177 void	disk_detach __P((struct disk *));
178 void	disk_busy __P((struct disk *));
179 void	disk_unbusy __P((struct disk *, long));
180 void	disk_resetstat __P((struct disk *));
181 struct	disk *disk_find __P((char *));
182 
183 struct device;
184 void	dk_establish __P((struct disk *, struct device *));
185 #endif
186