1/* $OpenBSD: disk.h,v 1.38 2023/11/15 20:23:19 kn 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 57struct buf; 58struct disklabel; 59 60#define DS_DISKNAMELEN 16 61 62struct diskstats { 63 char ds_name[DS_DISKNAMELEN]; 64 int ds_busy; /* busy counter */ 65 u_int64_t ds_rxfer; /* total number of read transfers */ 66 u_int64_t ds_wxfer; /* total number of write transfers */ 67 u_int64_t ds_seek; /* total independent seek operations */ 68 u_int64_t ds_rbytes; /* total bytes read */ 69 u_int64_t ds_wbytes; /* total bytes written */ 70 struct timeval ds_attachtime; /* time disk was attached */ 71 struct timeval ds_timestamp; /* time of first busy or any unbusy */ 72 struct timeval ds_time; /* total time spent busy */ 73}; 74 75struct disk { 76 TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ 77 struct rwlock dk_lock; /* disk lock */ 78 struct mutex dk_mtx; /* busy/unbusy mtx */ 79 char *dk_name; /* disk name */ 80 struct device *dk_device; /* disk device structure. */ 81 dev_t dk_devno; /* disk device number. */ 82 int dk_flags; /* disk flags */ 83#define DKF_CONSTRUCTED 0x0001 84#define DKF_OPENED 0x0002 85#define DKF_NOLABELREAD 0x0004 86 87 /* 88 * Metrics data; note that some metrics may have no meaning 89 * on certain types of disks. 90 */ 91 int dk_busy; /* busy counter */ 92 u_int64_t dk_rxfer; /* total number of read transfers */ 93 u_int64_t dk_wxfer; /* total number of write transfers */ 94 u_int64_t dk_seek; /* total independent seek operations */ 95 u_int64_t dk_rbytes; /* total bytes read */ 96 u_int64_t dk_wbytes; /* total bytes written */ 97 struct timeval dk_attachtime; /* time disk was attached */ 98 struct timeval dk_timestamp; /* time of first busy or any unbusy */ 99 struct timeval dk_time; /* total time spent busy */ 100 101 int dk_bopenmask; /* block devices open */ 102 int dk_copenmask; /* character devices open */ 103 int dk_openmask; /* composite (bopen|copen) */ 104 int dk_state; /* label state ### */ 105 int dk_blkshift; /* shift to convert DEV_BSIZE to blks*/ 106 int dk_byteshift; /* shift to convert bytes to blks */ 107 108 /* 109 * Disk label information. Storage for the in-core disk label 110 * must be dynamically allocated, otherwise the size of this 111 * structure becomes machine-dependent. 112 */ 113 struct disklabel *dk_label; 114}; 115 116/* states */ 117#define DK_CLOSED 0 /* drive is closed */ 118#define DK_WANTOPEN 1 /* drive being opened */ 119#define DK_WANTOPENRAW 2 /* drive being opened */ 120#define DK_RDLABEL 3 /* label being read */ 121#define DK_OPEN 4 /* label read, drive open */ 122#define DK_OPENRAW 5 /* open without label */ 123 124/* Disk map flags. */ 125#define DM_OPENPART 0x1 /* Open raw partition. */ 126#define DM_OPENBLCK 0x2 /* Open block device. */ 127 128/* 129 * disklist_head is defined here so that user-land has access to it. 130 */ 131TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ 132 133#ifdef _KERNEL 134extern struct disklist_head disklist; /* list of disks attached to system */ 135extern int disk_count; /* number of disks in global disklist */ 136extern int disk_change; /* disk attached/detached */ 137 138void disk_init(void); 139int disk_construct(struct disk *); 140void disk_attach(struct device *, struct disk *); 141void disk_detach(struct disk *); 142int disk_openpart(struct disk *, int, int, int); 143void disk_closepart(struct disk *, int, int); 144void disk_gone(int (*)(dev_t, int, int, struct proc *), int); 145void disk_busy(struct disk *); 146void disk_unbusy(struct disk *, long, daddr_t, int); 147 148int disk_lock(struct disk *); 149void disk_lock_nointr(struct disk *); 150void disk_unlock(struct disk *); 151struct device *disk_lookup(struct cfdriver *, int); 152 153char *disk_readlabel(struct disklabel *, dev_t, char *, size_t); 154 155int disk_map(const char *, char *, int, int); 156 157int duid_iszero(u_char *); 158const char *duid_format(u_char *); 159#endif 160