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