| 1 | /*	$OpenBSD: disk.h,v 1.42 2025/09/15 10:33:03 krw Exp $	*/ |
| 2 | /*	$NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $	*/ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1995 Jason R. Thorpe. All rights reserved. |
| 6 | * Copyright (c) 1992, 1993 |
| 7 | *	The Regents of the University of California. All rights reserved. |
| 8 | * |
| 9 | * This software was developed by the Computer Systems Engineering group |
| 10 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
| 11 | * contributed to Berkeley. |
| 12 | * |
| 13 | * All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | *	This product includes software developed by the University of |
| 16 | *	California, Lawrence Berkeley Laboratory. |
| 17 | * |
| 18 | * Redistribution and use in source and binary forms, with or without |
| 19 | * modification, are permitted provided that the following conditions |
| 20 | * are met: |
| 21 | * 1. Redistributions of source code must retain the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer. |
| 23 | * 2. Redistributions in binary form must reproduce the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer in the |
| 25 | * documentation and/or other materials provided with the distribution. |
| 26 | * 3. Neither the name of the University nor the names of its contributors |
| 27 | * may be used to endorse or promote products derived from this software |
| 28 | * without specific prior written permission. |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 40 | * SUCH DAMAGE. |
| 41 | * |
| 42 | * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) |
| 43 | * |
| 44 | *	@(#)disk.h	8.1 (Berkeley) 6/2/93 |
| 45 | */ |
| 46 | |
| 47 | /* |
| 48 | * Disk device structures. |
| 49 | */ |
| 50 | |
| 51 | #include <sys/device.h> |
| 52 | #include <sys/time.h> |
| 53 | #include <sys/queue.h> |
| 54 | #include <sys/rwlock.h> |
| 55 | #include <sys/mutex.h> |
| 56 | |
| 57 | struct disklabel; |
| 58 | |
| 59 | #define DS_DISKNAMELEN	16 |
| 60 | |
| 61 | struct diskstats { |
| 62 | 	char		ds_name[DS_DISKNAMELEN]; |
| 63 | 	int		ds_busy;	/* busy counter */ |
| 64 | 	u_int64_t	ds_rxfer;	/* total number of read transfers */ |
| 65 | 	u_int64_t	ds_wxfer;	/* total number of write transfers */ |
| 66 | 	u_int64_t	ds_seek;	/* total independent seek operations */ |
| 67 | 	u_int64_t	ds_rbytes;	/* total bytes read */ |
| 68 | 	u_int64_t	ds_wbytes;	/* total bytes written */ |
| 69 | 	struct timeval	ds_attachtime;	/* time disk was attached */ |
| 70 | 	struct timeval	ds_timestamp;	/* time of first busy or any unbusy */ |
| 71 | 	struct timeval	ds_time;	/* total time spent busy */ |
| 72 | }; |
| 73 | |
| 74 | struct disk { |
| 75 | 	TAILQ_ENTRY(disk) dk_link;	/* link in global disklist */ |
| 76 | 	struct rwlock	dk_lock;	/* disk lock */ |
| 77 | 	struct mutex	dk_mtx;		/* busy/unbusy mtx */ |
| 78 | 	char		*dk_name;	/* disk name */ |
| 79 | 	struct device	*dk_device;	/* disk device structure. */ |
| 80 | 	dev_t		dk_devno;	/* disk device number. */ |
| 81 | 	int		dk_flags;	/* disk flags */ |
| 82 | #define DKF_CONSTRUCTED	0x0001 |
| 83 | #define DKF_OPENED	0x0002 |
| 84 | #define DKF_NOLABELREAD	0x0004 |
| 85 | |
| 86 | 	/* |
| 87 | 	 * Metrics data; note that some metrics may have no meaning |
| 88 | 	 * on certain types of disks. |
| 89 | 	 */ |
| 90 | 	int		dk_busy;	/* busy counter */ |
| 91 | 	u_int64_t	dk_rxfer;	/* total number of read transfers */ |
| 92 | 	u_int64_t	dk_wxfer;	/* total number of write transfers */ |
| 93 | 	u_int64_t	dk_seek;	/* total independent seek operations */ |
| 94 | 	u_int64_t	dk_rbytes;	/* total bytes read */ |
| 95 | 	u_int64_t	dk_wbytes;	/* total bytes written */ |
| 96 | 	struct timeval	dk_attachtime;	/* time disk was attached */ |
| 97 | 	struct timeval	dk_timestamp;	/* time of first busy or any unbusy */ |
| 98 | 	struct timeval	dk_time;	/* total time spent busy */ |
| 99 | |
| 100 | 	uint64_t	dk_bopenmask;	/* block devices open */ |
| 101 | 	uint64_t	dk_copenmask;	/* character devices open */ |
| 102 | 	uint64_t	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 | 	 * Disk label information. Storage for the in-core disk label |
| 109 | 	 * must be dynamically allocated, otherwise the size of this |
| 110 | 	 * structure becomes machine-dependent. |
| 111 | 	 */ |
| 112 | 	struct disklabel *dk_label; |
| 113 | }; |
| 114 | |
| 115 | /* states */ |
| 116 | #define	DK_CLOSED	0		/* drive is closed */ |
| 117 | #define	DK_WANTOPEN	1		/* drive being opened */ |
| 118 | #define	DK_WANTOPENRAW	2		/* drive being opened */ |
| 119 | #define	DK_RDLABEL	3		/* label being read */ |
| 120 | #define	DK_OPEN		4		/* label read, drive open */ |
| 121 | #define	DK_OPENRAW	5		/* open without label */ |
| 122 | |
| 123 | /* Disk map flags. */ |
| 124 | #define	DM_OPENPART	0x1		/* Open raw partition. */ |
| 125 | #define	DM_OPENBLCK	0x2		/* Open block device. */ |
| 126 | |
| 127 | /* |
| 128 | * disklist_head is defined here so that user-land has access to it. |
| 129 | */ |
| 130 | TAILQ_HEAD(disklist_head, disk);	/* the disklist is a TAILQ */ |
| 131 | |
| 132 | #ifdef _KERNEL |
| 133 | extern	struct disklist_head disklist;	/* list of disks attached to system */ |
| 134 | extern	int disk_count;			/* number of disks in global disklist */ |
| 135 | extern	int disk_change;		/* disk attached/detached */ |
| 136 | |
| 137 | void	disk_init(void); |
| 138 | int	disk_construct(struct disk *); |
| 139 | void	disk_attach(struct device *, struct disk *); |
| 140 | void	disk_detach(struct disk *); |
| 141 | int	disk_openpart(struct disk *, int, int, int); |
| 142 | void	disk_closepart(struct disk *, int, int); |
| 143 | void	disk_gone(int (*)(dev_t, int, int, struct proc *), int); |
| 144 | void	disk_busy(struct disk *); |
| 145 | void	disk_unbusy(struct disk *, long, daddr_t, int); |
| 146 | |
| 147 | int	disk_lock(struct disk *); |
| 148 | void	disk_lock_nointr(struct disk *); |
| 149 | void disk_unlock(struct disk *); |
| 150 | struct device *disk_lookup(struct cfdriver *, int); |
| 151 | |
| 152 | char 	*disk_readlabel(struct disklabel *, dev_t, char *, size_t); |
| 153 | |
| 154 | int	disk_map(const char *, char *, int, int); |
| 155 | |
| 156 | int	duid_iszero(u_char *); |
| 157 | const char *duid_format(u_char *); |
| 158 | #endif |