Home | History | Annotate | Line # | Download | only in dev
vndvar.h revision 1.26
      1 /*	$NetBSD: vndvar.h,v 1.26 2009/12/14 03:11:22 uebayasi Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      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 /*
     33  * Copyright (c) 1990, 1993
     34  *	The Regents of the University of California.  All rights reserved.
     35  *
     36  * This code is derived from software contributed to Berkeley by
     37  * the Systems Programming Group of the University of Utah Computer
     38  * Science Department.
     39  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  * 3. Neither the name of the University nor the names of its contributors
     49  *    may be used to endorse or promote products derived from this software
     50  *    without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  * from: Utah $Hdr: fdioctl.h 1.1 90/07/09$
     65  *
     66  *	@(#)vnioctl.h	8.1 (Berkeley) 6/10/93
     67  */
     68 
     69 /*
     70  * Copyright (c) 1988 University of Utah.
     71  *
     72  * This code is derived from software contributed to Berkeley by
     73  * the Systems Programming Group of the University of Utah Computer
     74  * Science Department.
     75  *
     76  * Redistribution and use in source and binary forms, with or without
     77  * modification, are permitted provided that the following conditions
     78  * are met:
     79  * 1. Redistributions of source code must retain the above copyright
     80  *    notice, this list of conditions and the following disclaimer.
     81  * 2. Redistributions in binary form must reproduce the above copyright
     82  *    notice, this list of conditions and the following disclaimer in the
     83  *    documentation and/or other materials provided with the distribution.
     84  * 3. All advertising materials mentioning features or use of this software
     85  *    must display the following acknowledgement:
     86  *	This product includes software developed by the University of
     87  *	California, Berkeley and its contributors.
     88  * 4. Neither the name of the University nor the names of its contributors
     89  *    may be used to endorse or promote products derived from this software
     90  *    without specific prior written permission.
     91  *
     92  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     93  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     94  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     95  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     96  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     97  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     98  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     99  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    100  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    101  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    102  * SUCH DAMAGE.
    103  *
    104  * from: Utah $Hdr: fdioctl.h 1.1 90/07/09$
    105  *
    106  *	@(#)vnioctl.h	8.1 (Berkeley) 6/10/93
    107  */
    108 
    109 #ifndef _SYS_DEV_VNDVAR_H_
    110 #define _SYS_DEV_VNDVAR_H_
    111 
    112 #include <sys/pool.h>
    113 
    114 /*
    115  * Vnode disk pseudo-geometry information.
    116  */
    117 struct vndgeom {
    118 	u_int32_t	vng_secsize;	/* # bytes per sector */
    119 	u_int32_t	vng_nsectors;	/* # data sectors per track */
    120 	u_int32_t	vng_ntracks;	/* # tracks per cylinder */
    121 	u_int32_t	vng_ncylinders;	/* # cylinders per unit */
    122 };
    123 
    124 /*
    125  * Ioctl definitions for file (vnode) disk pseudo-device.
    126  */
    127 struct vnd_ioctl {
    128 	char		*vnd_file;	/* pathname of file to mount */
    129 	int		vnd_flags;	/* flags; see below */
    130 	struct vndgeom	vnd_geom;	/* geometry to emulate */
    131 	unsigned int	vnd_osize;	/* (returned) size of disk */
    132 	uint64_t	vnd_size;	/* (returned) size of disk */
    133 };
    134 
    135 /* vnd_flags */
    136 #define	VNDIOF_HASGEOM	0x01		/* use specified geometry */
    137 #define	VNDIOF_READONLY	0x02		/* as read-only device */
    138 #define	VNDIOF_FORCE	0x04		/* force close */
    139 
    140 #ifdef _KERNEL
    141 
    142 struct vnode;
    143 
    144 /*
    145  * A vnode disk's state information.
    146  */
    147 struct vnd_softc {
    148 	device_t         sc_dev;
    149 	int		 sc_flags;	/* flags */
    150 	size_t		 sc_size;	/* size of vnd */
    151 	struct vnode	*sc_vp;		/* vnode */
    152 	kauth_cred_t	 sc_cred;	/* credentials */
    153 	int		 sc_maxactive;	/* max # of active requests */
    154 	struct bufq_state *sc_tab;	/* transfer queue */
    155 	int		 sc_active;	/* number of active transfers */
    156 	struct disk	 sc_dkdev;	/* generic disk device info */
    157 	struct vndgeom	 sc_geom;	/* virtual geometry */
    158 	struct pool	 sc_vxpool;	/* vndxfer pool */
    159 	struct pool	 sc_vbpool;	/* vndbuf pool */
    160 	struct lwp 	*sc_kthread;	/* kernel thread */
    161 	u_int32_t	 sc_comp_blksz;	/* precompressed block size */
    162 	u_int32_t	 sc_comp_numoffs;/* count of compressed block offsets */
    163 	u_int64_t	*sc_comp_offsets;/* file idx's to compressed blocks */
    164 	unsigned char	*sc_comp_buff;	/* compressed data buffer */
    165 	unsigned char	*sc_comp_decombuf;/* decompressed data buffer */
    166 	int32_t		 sc_comp_buffblk;/*current decompressed block */
    167 	z_stream	 sc_comp_stream;/* decompress descriptor */
    168 };
    169 #endif
    170 
    171 /* sc_flags */
    172 #define	VNF_INITED	0x001	/* unit has been initialized */
    173 #define	VNF_WLABEL	0x002	/* label area is writable */
    174 #define	VNF_LABELLING	0x004	/* unit is currently being labelled */
    175 #define	VNF_WANTED	0x008	/* someone is waiting to obtain a lock */
    176 #define	VNF_LOCKED	0x010	/* unit is locked */
    177 #define	VNF_READONLY	0x020	/* unit is read-only */
    178 #define	VNF_KLABEL	0x040	/* keep label on close */
    179 #define	VNF_VLABEL	0x080	/* label is valid */
    180 #define	VNF_KTHREAD	0x100	/* thread is running */
    181 #define	VNF_VUNCONF	0x200	/* device is unconfiguring */
    182 #define VNF_COMP	0x400	/* file is compressed */
    183 #define VNF_CLEARING	0x800	/* unit is being torn down */
    184 
    185 /* structure of header in a compressed file */
    186 struct vnd_comp_header
    187 {
    188 	char preamble[128];
    189 	u_int32_t block_size;
    190 	u_int32_t num_blocks;
    191 };
    192 
    193 /*
    194  * A simple structure for describing which vnd units are in use.
    195  */
    196 #ifdef COMPAT_30
    197 struct vnd_ouser {
    198 	int		vnu_unit;	/* which vnd unit */
    199 	dev_t		vnu_dev;	/* file is on this device... */
    200 	uint32_t	vnu_ino;	/* ...at this inode */
    201 };
    202 #define VNDIOOCGET	_IOWR('F', 2, struct vnd_ouser)	/* get list */
    203 #endif
    204 
    205 struct vnd_user {
    206 	int		vnu_unit;	/* which vnd unit */
    207 	dev_t		vnu_dev;	/* file is on this device... */
    208 	ino_t		vnu_ino;	/* ...at this inode */
    209 };
    210 
    211 /*
    212  * Before you can use a unit, it must be configured with VNDIOCSET.
    213  * The configuration persists across opens and closes of the device;
    214  * an VNDIOCCLR must be used to reset a configuration.  An attempt to
    215  * VNDIOCSET an already active unit will return EBUSY.
    216  */
    217 #define VNDIOCSET	_IOWR('F', 0, struct vnd_ioctl)	/* enable disk */
    218 #define VNDIOCCLR	_IOW('F', 1, struct vnd_ioctl)	/* disable disk */
    219 #define VNDIOCGET	_IOWR('F', 3, struct vnd_user)	/* get list */
    220 
    221 /* These only have the 32bit vnd_osize field */
    222 #define VNDIOOCSET	_IOC(IOC_INOUT, 'F', 0, \
    223 				offsetof(struct vnd_ioctl, vnd_size))
    224 #define VNDIOOCCLR	_IOC(IOC_IN, 'F', 1, \
    225 				offsetof(struct vnd_ioctl, vnd_size))
    226 
    227 #endif /* _SYS_DEV_VNDVAR_H_ */
    228