root/sys/disk.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


    1 /*      $OpenBSD: disk.h,v 1.17 2007/06/20 18:15:47 deraadt 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/time.h>
   52 #include <sys/queue.h>
   53 #include <sys/rwlock.h>
   54 
   55 struct buf;
   56 struct disklabel;
   57 
   58 #define DS_DISKNAMELEN  16
   59 
   60 struct diskstats {
   61         char            ds_name[DS_DISKNAMELEN];
   62         int             ds_busy;        /* busy counter */
   63         u_int64_t       ds_rxfer;       /* total number of read transfers */
   64         u_int64_t       ds_wxfer;       /* total number of write transfers */
   65         u_int64_t       ds_seek;        /* total independent seek operations */
   66         u_int64_t       ds_rbytes;      /* total bytes read */
   67         u_int64_t       ds_wbytes;      /* total bytes written */
   68         struct timeval  ds_attachtime;  /* time disk was attached */
   69         struct timeval  ds_timestamp;   /* timestamp of last unbusy */
   70         struct timeval  ds_time;        /* total time spent busy */
   71 };
   72 
   73 struct disk {
   74         TAILQ_ENTRY(disk) dk_link;      /* link in global disklist */
   75         struct rwlock   dk_lock;        /* disk lock */
   76         char            *dk_name;       /* disk name */
   77         int             dk_flags;       /* disk flags */
   78 #define DKF_CONSTRUCTED  0x0001
   79 
   80         /*
   81          * Metrics data; note that some metrics may have no meaning
   82          * on certain types of disks.
   83          */
   84         int             dk_busy;        /* busy counter */
   85         u_int64_t       dk_rxfer;       /* total number of read transfers */
   86         u_int64_t       dk_wxfer;       /* total number of write transfers */
   87         u_int64_t       dk_seek;        /* total independent seek operations */
   88         u_int64_t       dk_rbytes;      /* total bytes read */
   89         u_int64_t       dk_wbytes;      /* total bytes written */
   90         struct timeval  dk_attachtime;  /* time disk was attached */
   91         struct timeval  dk_timestamp;   /* timestamp of last unbusy */
   92         struct timeval  dk_time;        /* total time spent busy */
   93 
   94         int             dk_bopenmask;   /* block devices open */
   95         int             dk_copenmask;   /* character devices open */
   96         int             dk_openmask;    /* composite (bopen|copen) */
   97         int             dk_state;       /* label state   ### */
   98         int             dk_blkshift;    /* shift to convert DEV_BSIZE to blks*/
   99         int             dk_byteshift;   /* shift to convert bytes to blks */
  100 
  101         struct  dkdriver *dk_driver;    /* pointer to driver */
  102 
  103         /*
  104          * Disk label information.  Storage for the in-core disk label
  105          * must be dynamically allocated, otherwise the size of this
  106          * structure becomes machine-dependent.
  107          */
  108         daddr64_t       dk_labelsector;         /* sector containing label */
  109         struct disklabel *dk_label;     /* label */
  110 };
  111 
  112 struct dkdriver {
  113         void    (*d_strategy)(struct buf *);
  114 #ifdef notyet
  115         int     (*d_open)(dev_t dev, int ifmt, int, struct proc *);
  116         int     (*d_close)(dev_t dev, int, int ifmt, struct proc *);
  117         int     (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data, int fflag,
  118                                 struct proc *);
  119         int     (*d_dump)(dev_t);
  120         void    (*d_start)(struct buf *, daddr64_t);
  121         int     (*d_mklabel)(struct disk *);
  122 #endif
  123 };
  124 
  125 /* states */
  126 #define DK_CLOSED       0               /* drive is closed */
  127 #define DK_WANTOPEN     1               /* drive being opened */
  128 #define DK_WANTOPENRAW  2               /* drive being opened */
  129 #define DK_RDLABEL      3               /* label being read */
  130 #define DK_OPEN         4               /* label read, drive open */
  131 #define DK_OPENRAW      5               /* open without label */
  132 
  133 #ifdef DISKSORT_STATS
  134 /*
  135  * Stats from disksort().
  136  */
  137 struct disksort_stats {
  138         long    ds_newhead;             /* # new queue heads created */
  139         long    ds_newtail;             /* # new queue tails created */
  140         long    ds_midfirst;            /* # insertions into sort list */
  141         long    ds_endfirst;            /* # insertions at end of sort list */
  142         long    ds_newsecond;           /* # inversions (2nd lists) created */
  143         long    ds_midsecond;           /* # insertions into 2nd list */
  144         long    ds_endsecond;           /* # insertions at end of 2nd list */
  145 };
  146 #endif
  147 
  148 /*
  149  * disklist_head is defined here so that user-land has access to it.
  150  */
  151 TAILQ_HEAD(disklist_head, disk);        /* the disklist is a TAILQ */
  152 
  153 #ifdef _KERNEL
  154 extern  int disk_count;                 /* number of disks in global disklist */
  155 extern  int disk_change;                /* disk attached/detached */
  156 
  157 void    disk_init(void);
  158 int     disk_construct(struct disk *, char *);
  159 void    disk_attach(struct disk *);
  160 void    disk_detach(struct disk *);
  161 void    disk_busy(struct disk *);
  162 void    disk_unbusy(struct disk *, long, int);
  163 
  164 int     disk_lock(struct disk *);
  165 void    disk_unlock(struct disk *);
  166 #endif

/* [<][>][^][v][top][bottom][index][help] */