Home | History | Annotate | Line # | Download | only in dev
dkvar.h revision 1.30.4.1
      1  1.30.4.1    martin /* $NetBSD: dkvar.h,v 1.30.4.1 2020/04/08 14:08:02 martin Exp $ */
      2       1.1     elric 
      3       1.1     elric /*-
      4       1.1     elric  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5       1.1     elric  * All rights reserved.
      6       1.1     elric  *
      7       1.1     elric  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1     elric  * by Roland C. Dowdeswell.
      9       1.1     elric  *
     10       1.1     elric  * Redistribution and use in source and binary forms, with or without
     11       1.1     elric  * modification, are permitted provided that the following conditions
     12       1.1     elric  * are met:
     13       1.1     elric  * 1. Redistributions of source code must retain the above copyright
     14       1.1     elric  *    notice, this list of conditions and the following disclaimer.
     15       1.1     elric  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     elric  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     elric  *    documentation and/or other materials provided with the distribution.
     18       1.1     elric  *
     19       1.1     elric  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1     elric  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1     elric  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1     elric  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1     elric  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1     elric  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1     elric  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1     elric  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1     elric  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1     elric  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1     elric  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1     elric  */
     31       1.1     elric 
     32      1.30   mlelstv #ifndef _DEV_DKVAR_H_
     33      1.30   mlelstv #define _DEV_DKVAR_H_
     34      1.30   mlelstv 
     35      1.24   mlelstv #include <sys/rndsource.h>
     36      1.24   mlelstv 
     37      1.15  dholland struct pathbuf; /* from namei.h */
     38      1.15  dholland 
     39       1.1     elric /* literally this is not a softc, but is intended to be included in
     40       1.1     elric  * the pseudo-disk's softc and passed to calls in dksubr.c.  It
     41       1.1     elric  * should include the common elements of the pseudo-disk's softc.
     42       1.1     elric  * All elements that are included here should describe the external
     43       1.1     elric  * representation of the disk to the higher layers, and flags that
     44       1.1     elric  * are common to each of the pseudo-disk drivers.
     45       1.1     elric  */
     46       1.1     elric struct dk_softc {
     47      1.16     elric 	device_t		 sc_dev;
     48       1.1     elric 	u_int32_t		 sc_flags;	/* flags */
     49       1.1     elric #define DK_XNAME_SIZE 8
     50       1.1     elric 	char			 sc_xname[DK_XNAME_SIZE]; /* external name */
     51       1.1     elric 	struct disk		 sc_dkdev;	/* generic disk info */
     52      1.21   mlelstv 	kmutex_t		 sc_iolock;	/* protects buffer queue */
     53       1.8      yamt 	struct bufq_state	*sc_bufq;	/* buffer queue */
     54      1.20   mlelstv 	int			 sc_dtype;	/* disk type */
     55      1.27  jdolecek 	struct buf		*sc_deferred;	/* retry after start failed */
     56      1.28   mlelstv 	int			 sc_busy;	/* processing buffers */
     57      1.24   mlelstv 	krndsource_t		 sc_rnd_source;	/* entropy source */
     58       1.1     elric };
     59       1.1     elric 
     60       1.1     elric /* sc_flags:
     61       1.1     elric  *   We separate the flags into two varieties, those that dksubr.c
     62       1.1     elric  *   understands and manipulates and those that it does not.
     63       1.1     elric  */
     64       1.1     elric 
     65       1.1     elric #define DKF_INITED	0x00010000 /* unit has been initialised */
     66       1.1     elric #define DKF_WLABEL	0x00020000 /* label area is writable */
     67       1.1     elric #define DKF_LABELLING	0x00040000 /* unit is currently being labeled */
     68       1.1     elric #define DKF_WARNLABEL	0x00080000 /* warn if disklabel not present */
     69       1.1     elric #define DKF_LABELSANITY	0x00100000 /* warn if disklabel not sane */
     70       1.1     elric #define DKF_TAKEDUMP	0x00200000 /* allow dumping */
     71      1.20   mlelstv #define DKF_KLABEL      0x00400000 /* keep label on close */
     72      1.20   mlelstv #define DKF_VLABEL      0x00800000 /* label is valid */
     73      1.22   mlelstv #define DKF_SLEEP       0x80000000 /* dk_start/dk_done may sleep */
     74      1.29  jdolecek #define DKF_NO_RND	0x01000000 /* do not attach as rnd source */
     75       1.1     elric 
     76       1.1     elric /* Mask of flags that dksubr.c understands, other flags are fair game */
     77       1.1     elric #define DK_FLAGMASK	0xffff0000
     78       1.1     elric 
     79      1.20   mlelstv #define DK_ATTACHED(_dksc) ((_dksc)->sc_flags & DKF_INITED)
     80       1.1     elric 
     81       1.1     elric #define DK_BUSY(_dksc, _pmask)				\
     82      1.14    dyoung 	(((_dksc)->sc_dkdev.dk_openmask & ~(_pmask)) ||	\
     83       1.1     elric 	((_dksc)->sc_dkdev.dk_bopenmask & (_pmask)  &&	\
     84      1.14    dyoung 	((_dksc)->sc_dkdev.dk_copenmask & (_pmask))))
     85       1.1     elric 
     86  1.30.4.1    martin #define	DK_DUMP_RECURSIVE	__BIT(0) /* this is a virtual disk */
     87  1.30.4.1    martin 
     88       1.1     elric /*
     89       1.1     elric  * Functions that are exported to the pseudo disk implementations:
     90       1.1     elric  */
     91       1.1     elric 
     92      1.20   mlelstv void	dk_init(struct dk_softc *, device_t, int);
     93      1.20   mlelstv void	dk_attach(struct dk_softc *);
     94      1.20   mlelstv void	dk_detach(struct dk_softc *);
     95       1.1     elric 
     96      1.20   mlelstv int	dk_open(struct dk_softc *, dev_t,
     97       1.9  christos 		int, int, struct lwp *);
     98      1.20   mlelstv int	dk_close(struct dk_softc *, dev_t,
     99       1.9  christos 		 int, int, struct lwp *);
    100      1.20   mlelstv void	dk_strategy(struct dk_softc *, struct buf *);
    101      1.25   mlelstv int	dk_strategy_defer(struct dk_softc *, struct buf *);
    102      1.25   mlelstv int	dk_strategy_pending(struct dk_softc *);
    103      1.21   mlelstv int	dk_discard(struct dk_softc *, dev_t, off_t, off_t);
    104      1.21   mlelstv void	dk_start(struct dk_softc *, struct buf *);
    105      1.20   mlelstv void	dk_done(struct dk_softc *, struct buf *);
    106      1.22   mlelstv void	dk_drain(struct dk_softc *);
    107      1.20   mlelstv int	dk_size(struct dk_softc *, dev_t);
    108      1.20   mlelstv int	dk_ioctl(struct dk_softc *, dev_t,
    109      1.10  christos 		 u_long, void *, int, struct lwp *);
    110      1.20   mlelstv int	dk_dump(struct dk_softc *, dev_t,
    111  1.30.4.1    martin 		daddr_t, void *, size_t, int);
    112      1.20   mlelstv void	dk_getdisklabel(struct dk_softc *, dev_t);
    113      1.20   mlelstv void	dk_getdefaultlabel(struct dk_softc *, struct disklabel *);
    114       1.1     elric 
    115      1.30   mlelstv #endif /* ! _DEV_DKVAR_H_ */
    116