xref: /netbsd/sys/sys/disk.h (revision c4a72b64)
1 /*	$NetBSD: disk.h,v 1.20 2002/11/01 11:32:02 mrg 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_rxfer;	/* total number of read transfers */
116 	u_int64_t	dk_wxfer;	/* total number of write transfers */
117 	u_int64_t	dk_seek;	/* total independent seek operations */
118 	u_int64_t	dk_rbytes;	/* total bytes read */
119 	u_int64_t	dk_wbytes;	/* total bytes written */
120 	struct timeval	dk_attachtime;	/* time disk was attached */
121 	struct timeval	dk_timestamp;	/* timestamp of last unbusy */
122 	struct timeval	dk_time;	/* total time spent busy */
123 
124 	struct	dkdriver *dk_driver;	/* pointer to driver */
125 
126 	/*
127 	 * Disk label information.  Storage for the in-core disk label
128 	 * must be dynamically allocated, otherwise the size of this
129 	 * structure becomes machine-dependent.
130 	 */
131 	daddr_t		dk_labelsector;		/* sector containing label */
132 	struct disklabel *dk_label;	/* label */
133 	struct cpu_disklabel *dk_cpulabel;
134 };
135 
136 #define	DK_DISKNAMELEN	16
137 
138 /* The following structure is 64-bit alignment safe */
139 struct disk_sysctl {
140 	char		dk_name[DK_DISKNAMELEN];
141 	int32_t		dk_busy;
142 	int32_t		pad;
143 	u_int64_t	dk_xfer;
144 	u_int64_t	dk_seek;
145 	u_int64_t	dk_bytes;
146 	u_int32_t	dk_attachtime_sec;
147 	u_int32_t	dk_attachtime_usec;
148 	u_int32_t	dk_timestamp_sec;
149 	u_int32_t	dk_timestamp_usec;
150 	u_int32_t	dk_time_sec;
151 	u_int32_t	dk_time_usec;
152 	/* New separate read/write stats */
153 	u_int64_t	dk_rxfer;
154 	u_int64_t	dk_rbytes;
155 	u_int64_t	dk_wxfer;
156 	u_int64_t	dk_wbytes;
157 };
158 
159 struct dkdriver {
160 	void	(*d_strategy) __P((struct buf *));
161 #ifdef notyet
162 	int	(*d_open) __P((dev_t dev, int ifmt, int, struct proc *));
163 	int	(*d_close) __P((dev_t dev, int, int ifmt, struct proc *));
164 	int	(*d_ioctl) __P((dev_t dev, u_long cmd, caddr_t data, int fflag,
165 				struct proc *));
166 	int	(*d_dump) __P((dev_t));
167 	void	(*d_start) __P((struct buf *, daddr_t));
168 	int	(*d_mklabel) __P((struct disk *));
169 #endif
170 };
171 
172 /* states */
173 #define	DK_CLOSED	0		/* drive is closed */
174 #define	DK_WANTOPEN	1		/* drive being opened */
175 #define	DK_WANTOPENRAW	2		/* drive being opened */
176 #define	DK_RDLABEL	3		/* label being read */
177 #define	DK_OPEN		4		/* label read, drive open */
178 #define	DK_OPENRAW	5		/* open without label */
179 
180 /*
181  * disklist_head is defined here so that user-land has access to it.
182  */
183 TAILQ_HEAD(disklist_head, disk);	/* the disklist is a TAILQ */
184 
185 #ifdef _KERNEL
186 extern	int disk_count;			/* number of disks in global disklist */
187 
188 void	disk_init __P((void));
189 void	disk_attach __P((struct disk *));
190 void	disk_detach __P((struct disk *));
191 void	disk_busy __P((struct disk *));
192 void	disk_unbusy __P((struct disk *, long, int));
193 void	disk_resetstat __P((struct disk *));
194 struct	disk *disk_find __P((char *));
195 #endif
196 
197 #endif /* _SYS_DISK_H_ */
198