1994-12-04 20:08:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: Utah Hdr: vn.c 1.13 94/04/02
|
|
|
|
*
|
1996-03-28 15:25:43 +00:00
|
|
|
* from: @(#)vn.c 8.6 (Berkeley) 4/1/94
|
1998-08-23 20:16:35 +00:00
|
|
|
* $Id: vn.c,v 1.68 1998/08/19 10:50:32 sos Exp $
|
1994-12-04 20:08:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Vnode disk driver.
|
|
|
|
*
|
|
|
|
* Block/character interface to a vnode. Allows one to treat a file
|
|
|
|
* as a disk (e.g. build a filesystem in it, mount it, etc.).
|
|
|
|
*
|
|
|
|
* NOTE 1: This uses the VOP_BMAP/VOP_STRATEGY interface to the vnode
|
|
|
|
* instead of a simple VOP_RDWR. We do this to avoid distorting the
|
|
|
|
* local buffer cache.
|
|
|
|
*
|
|
|
|
* NOTE 2: There is a security issue involved with this driver.
|
|
|
|
* Once mounted all access to the contents of the "mapped" file via
|
|
|
|
* the special file is controlled by the permissions on the special
|
|
|
|
* file, the protection of the mapped file is ignored (effectively,
|
|
|
|
* by using root credentials in all transactions).
|
|
|
|
*
|
|
|
|
* NOTE 3: Doesn't interact with leases, should it?
|
|
|
|
*/
|
|
|
|
#include "vn.h"
|
|
|
|
#if NVN > 0
|
|
|
|
|
1995-03-01 05:05:21 +00:00
|
|
|
/* default is to have 8 VN's */
|
|
|
|
#if NVN < 8
|
|
|
|
#undef NVN
|
1995-03-04 11:08:26 +00:00
|
|
|
#define NVN 8
|
1995-03-01 05:05:21 +00:00
|
|
|
#endif
|
|
|
|
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-12-06 06:47:32 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-12-04 20:08:35 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
1997-03-23 03:37:54 +00:00
|
|
|
#include <sys/fcntl.h>
|
1995-02-25 16:48:28 +00:00
|
|
|
#include <sys/disklabel.h>
|
1994-12-12 00:23:11 +00:00
|
|
|
#include <sys/diskslice.h>
|
1994-12-16 16:50:15 +00:00
|
|
|
#include <sys/stat.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
#include <sys/conf.h>
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <dev/slice/slice.h>
|
|
|
|
#endif /* SLICE */
|
1994-12-04 20:08:35 +00:00
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
|
|
|
#include <sys/vnioctl.h>
|
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
static d_ioctl_t vnioctl;
|
|
|
|
#ifndef SLICE
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t vnopen;
|
1998-07-04 22:30:26 +00:00
|
|
|
static d_read_t vnread;
|
|
|
|
static d_write_t vnwrite;
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_close_t vnclose;
|
|
|
|
static d_dump_t vndump;
|
|
|
|
static d_psize_t vnsize;
|
|
|
|
static d_strategy_t vnstrategy;
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
#define CDEV_MAJOR 43
|
|
|
|
#define BDEV_MAJOR 15
|
1998-07-04 22:30:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct cdevsw vn_cdevsw = {
|
|
|
|
vnopen, vnclose, vnread, vnwrite,
|
|
|
|
vnioctl, nostop, nullreset, nodevtotty,
|
|
|
|
seltrue, nommap, vnstrategy, "vn",
|
|
|
|
NULL, -1, vndump, vnsize,
|
|
|
|
D_DISK|D_NOCLUSTERRW, 0, -1 };
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#else /* SLICE */
|
|
|
|
|
|
|
|
static sl_h_IO_req_t nvsIOreq; /* IO req downward (to device) */
|
|
|
|
static sl_h_ioctl_t nvsioctl; /* ioctl req downward (to device) */
|
|
|
|
static sl_h_open_t nvsopen; /* downwards travelling open */
|
1998-04-22 10:25:27 +00:00
|
|
|
/*static sl_h_close_t nvsclose; */ /* downwards travelling close */
|
1998-05-06 22:14:48 +00:00
|
|
|
static sl_h_dump_t nvsdump; /* core dump req downward */
|
1998-04-19 23:32:49 +00:00
|
|
|
|
|
|
|
static struct slice_handler slicetype = {
|
|
|
|
"vn",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL, /* constructor */
|
|
|
|
&nvsIOreq,
|
|
|
|
&nvsioctl,
|
|
|
|
&nvsopen,
|
1998-04-22 10:25:27 +00:00
|
|
|
/*&nvsclose*/NULL,
|
1998-04-19 23:32:49 +00:00
|
|
|
NULL, /* revoke */
|
|
|
|
NULL, /* claim */
|
|
|
|
NULL, /* verify */
|
1998-05-06 22:14:48 +00:00
|
|
|
NULL, /* upconfig */
|
|
|
|
&nvsdump
|
1998-04-19 23:32:49 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1994-12-12 00:23:11 +00:00
|
|
|
#define vnunit(dev) dkunit(dev)
|
1994-12-04 20:08:35 +00:00
|
|
|
|
|
|
|
#define getvnbuf() \
|
|
|
|
((struct buf *)malloc(sizeof(struct buf), M_DEVBUF, M_WAITOK))
|
|
|
|
|
|
|
|
#define putvnbuf(bp) \
|
|
|
|
free((caddr_t)(bp), M_DEVBUF)
|
|
|
|
|
|
|
|
struct vn_softc {
|
|
|
|
int sc_flags; /* flags */
|
|
|
|
size_t sc_size; /* size of vn */
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
struct slice *slice;
|
|
|
|
struct slicelimits limit;
|
|
|
|
int mynor;
|
|
|
|
int unit;
|
|
|
|
#else
|
|
|
|
struct diskslices *sc_slices;
|
|
|
|
#endif /* SLICE */
|
1994-12-04 20:08:35 +00:00
|
|
|
struct vnode *sc_vp; /* vnode */
|
|
|
|
struct ucred *sc_cred; /* credentials */
|
|
|
|
int sc_maxactive; /* max # of active requests */
|
|
|
|
struct buf sc_tab; /* transfer queue */
|
1995-03-11 09:32:45 +00:00
|
|
|
u_long sc_options; /* options */
|
1994-12-04 20:08:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* sc_flags */
|
|
|
|
#define VNF_INITED 0x01
|
|
|
|
|
1995-12-09 20:34:16 +00:00
|
|
|
static struct vn_softc *vn_softc[NVN];
|
|
|
|
static u_long vn_options;
|
1995-03-11 09:32:45 +00:00
|
|
|
|
|
|
|
#define IFOPT(vn,opt) if (((vn)->sc_options|vn_options) & (opt))
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-12-09 20:34:16 +00:00
|
|
|
static void vniodone (struct buf *bp);
|
|
|
|
static int vnsetcred (struct vn_softc *vn, struct ucred *cred);
|
1996-08-28 17:45:08 +00:00
|
|
|
static void vnshutdown (int, void *);
|
1995-12-09 20:34:16 +00:00
|
|
|
static void vnclear (struct vn_softc *vn);
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifndef SLICE
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-12-12 00:23:11 +00:00
|
|
|
vnclose(dev_t dev, int flags, int mode, struct proc *p)
|
|
|
|
{
|
1995-03-11 09:32:45 +00:00
|
|
|
struct vn_softc *vn = vn_softc[vnunit(dev)];
|
1994-12-12 00:23:11 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_LABELS)
|
|
|
|
if (vn->sc_slices != NULL)
|
|
|
|
dsclose(dev, mode, vn->sc_slices);
|
1994-12-12 00:23:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-12-04 20:08:35 +00:00
|
|
|
vnopen(dev_t dev, int flags, int mode, struct proc *p)
|
|
|
|
{
|
1995-04-28 22:24:37 +00:00
|
|
|
int unit = vnunit(dev);
|
1995-03-01 05:05:21 +00:00
|
|
|
struct vn_softc *vn;
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
if (unit >= NVN) {
|
|
|
|
if (vn_options & VN_FOLLOW)
|
1995-05-30 08:16:23 +00:00
|
|
|
printf("vnopen(0x%lx, 0x%x, 0x%x, %p)\n",
|
1998-07-11 07:46:16 +00:00
|
|
|
(u_long)dev, flags, mode, (void *)p);
|
1995-03-01 05:05:21 +00:00
|
|
|
return(ENOENT);
|
1995-03-11 09:32:45 +00:00
|
|
|
}
|
1995-03-01 05:05:21 +00:00
|
|
|
|
1994-12-12 00:23:11 +00:00
|
|
|
vn = vn_softc[unit];
|
|
|
|
if (!vn) {
|
|
|
|
vn = malloc(sizeof *vn, M_DEVBUF, M_WAITOK);
|
|
|
|
if (!vn)
|
|
|
|
return (ENOMEM);
|
|
|
|
bzero(vn, sizeof *vn);
|
|
|
|
vn_softc[unit] = vn;
|
|
|
|
}
|
1995-03-11 09:32:45 +00:00
|
|
|
|
|
|
|
IFOPT(vn, VN_FOLLOW)
|
1998-07-11 07:46:16 +00:00
|
|
|
printf("vnopen(0x%lx, 0x%x, 0x%x, %p)\n",
|
|
|
|
(u_long)dev, flags, mode, (void *)p);
|
1995-03-11 09:32:45 +00:00
|
|
|
|
|
|
|
IFOPT(vn, VN_LABELS) {
|
|
|
|
if (vn->sc_flags & VNF_INITED) {
|
|
|
|
struct disklabel label;
|
|
|
|
|
|
|
|
/* Build label for whole disk. */
|
|
|
|
bzero(&label, sizeof label);
|
|
|
|
label.d_secsize = DEV_BSIZE;
|
|
|
|
label.d_nsectors = 32;
|
|
|
|
label.d_ntracks = 64;
|
|
|
|
label.d_ncylinders = vn->sc_size / (32 * 64);
|
|
|
|
label.d_secpercyl = 32 * 64;
|
1995-05-30 08:16:23 +00:00
|
|
|
label.d_secperunit =
|
1995-03-11 09:32:45 +00:00
|
|
|
label.d_partitions[RAW_PART].p_size =
|
|
|
|
vn->sc_size;
|
|
|
|
|
1998-07-30 15:16:06 +00:00
|
|
|
return (dsopen("vn", dev, mode, 0, &vn->sc_slices,
|
|
|
|
&label, vnstrategy, (ds_setgeom_t *)NULL,
|
1998-08-23 20:16:35 +00:00
|
|
|
&vn_cdevsw));
|
1995-03-11 09:32:45 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
if (dkslice(dev) != WHOLE_DISK_SLICE ||
|
1995-03-11 09:32:45 +00:00
|
|
|
dkpart(dev) != RAW_PART ||
|
|
|
|
mode != S_IFCHR)
|
|
|
|
return (ENXIO);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1998-07-04 22:30:26 +00:00
|
|
|
static int
|
|
|
|
vnread(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
return (physio(vnstrategy, NULL, dev, 1, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vnwrite(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
return (physio(vnstrategy, NULL, dev, 0, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
/*
|
1995-04-19 10:31:18 +00:00
|
|
|
* this code does I/O calls through the appropriate VOP entry point...
|
|
|
|
* unless a swap_pager I/O request is being done. This strategy (-))
|
|
|
|
* allows for coherency with mmap except in the case of paging. This
|
|
|
|
* is necessary, because the VOP calls use lots of memory (and actually
|
|
|
|
* are not extremely efficient -- but we want to keep semantics correct),
|
|
|
|
* and the pageout daemon gets really unhappy (and so does the rest of the
|
|
|
|
* system) when it runs out of memory.
|
1994-12-04 20:08:35 +00:00
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1994-12-04 20:08:35 +00:00
|
|
|
vnstrategy(struct buf *bp)
|
|
|
|
{
|
|
|
|
int unit = vnunit(bp->b_dev);
|
|
|
|
register struct vn_softc *vn = vn_softc[unit];
|
1995-04-19 10:31:18 +00:00
|
|
|
register daddr_t bn;
|
|
|
|
int error;
|
1997-10-21 09:51:47 +00:00
|
|
|
int isvplocked = 0;
|
1996-01-14 20:32:14 +00:00
|
|
|
long sz;
|
1995-04-19 10:31:18 +00:00
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_DEBUG)
|
1995-02-14 06:06:07 +00:00
|
|
|
printf("vnstrategy(%p): unit %d\n", bp, unit);
|
1995-03-11 09:32:45 +00:00
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
if ((vn->sc_flags & VNF_INITED) == 0) {
|
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_LABELS) {
|
|
|
|
bp->b_resid = bp->b_bcount;/* XXX best place to set this? */
|
|
|
|
if (vn->sc_slices != NULL && dscheck(bp, vn->sc_slices) <= 0) {
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bn = bp->b_pblkno;
|
|
|
|
bp->b_resid = bp->b_bcount;/* XXX best place to set this? */
|
|
|
|
} else {
|
|
|
|
bn = bp->b_blkno;
|
|
|
|
sz = howmany(bp->b_bcount, DEV_BSIZE);
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
if (bn < 0 || bn + sz > vn->sc_size) {
|
|
|
|
if (bn != vn->sc_size) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
}
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-19 10:31:18 +00:00
|
|
|
if( (bp->b_flags & B_PAGING) == 0) {
|
|
|
|
aiov.iov_base = bp->b_data;
|
|
|
|
aiov.iov_len = bp->b_bcount;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
1996-01-14 20:32:14 +00:00
|
|
|
auio.uio_offset = dbtob(bn);
|
1995-04-19 10:31:18 +00:00
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
if( bp->b_flags & B_READ)
|
|
|
|
auio.uio_rw = UIO_READ;
|
1994-12-04 20:08:35 +00:00
|
|
|
else
|
1995-04-19 10:31:18 +00:00
|
|
|
auio.uio_rw = UIO_WRITE;
|
|
|
|
auio.uio_resid = bp->b_bcount;
|
|
|
|
auio.uio_procp = curproc;
|
1997-10-21 09:51:47 +00:00
|
|
|
if (!VOP_ISLOCKED(vn->sc_vp)) {
|
|
|
|
isvplocked = 1;
|
|
|
|
vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY, curproc);
|
|
|
|
}
|
1995-04-19 10:31:18 +00:00
|
|
|
if( bp->b_flags & B_READ)
|
|
|
|
error = VOP_READ(vn->sc_vp, &auio, 0, vn->sc_cred);
|
|
|
|
else
|
|
|
|
error = VOP_WRITE(vn->sc_vp, &auio, 0, vn->sc_cred);
|
1997-10-21 09:51:47 +00:00
|
|
|
if (isvplocked) {
|
|
|
|
VOP_UNLOCK(vn->sc_vp, 0, curproc);
|
|
|
|
isvplocked = 0;
|
|
|
|
}
|
1995-04-19 10:31:18 +00:00
|
|
|
bp->b_resid = auio.uio_resid;
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-04-19 10:31:18 +00:00
|
|
|
if( error )
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
} else {
|
1996-01-14 20:32:14 +00:00
|
|
|
long bsize, resid;
|
|
|
|
off_t byten;
|
|
|
|
int flags;
|
1995-04-19 10:31:18 +00:00
|
|
|
caddr_t addr;
|
|
|
|
struct buf *nbp;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
nbp = getvnbuf();
|
1998-07-04 00:27:48 +00:00
|
|
|
bzero(nbp, sizeof(struct buf));
|
|
|
|
LIST_INIT(&nbp->b_dep);
|
1996-01-14 20:32:14 +00:00
|
|
|
byten = dbtob(bn);
|
1995-04-19 10:31:18 +00:00
|
|
|
bsize = vn->sc_vp->v_mount->mnt_stat.f_iosize;
|
|
|
|
addr = bp->b_data;
|
|
|
|
flags = bp->b_flags | B_CALL;
|
|
|
|
for (resid = bp->b_resid; resid; ) {
|
|
|
|
struct vnode *vp;
|
|
|
|
daddr_t nbn;
|
|
|
|
int off, s, nra;
|
|
|
|
|
|
|
|
nra = 0;
|
1997-10-21 09:51:47 +00:00
|
|
|
if (!VOP_ISLOCKED(vn->sc_vp)) {
|
|
|
|
isvplocked = 1;
|
|
|
|
vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY, curproc);
|
|
|
|
}
|
1996-01-14 20:32:14 +00:00
|
|
|
error = VOP_BMAP(vn->sc_vp, (daddr_t)(byten / bsize),
|
|
|
|
&vp, &nbn, &nra, NULL);
|
1997-10-21 09:51:47 +00:00
|
|
|
if (isvplocked) {
|
|
|
|
VOP_UNLOCK(vn->sc_vp, 0, curproc);
|
|
|
|
isvplocked = 0;
|
|
|
|
}
|
1996-01-14 20:32:14 +00:00
|
|
|
if (error == 0 && nbn == -1)
|
1995-04-19 10:31:18 +00:00
|
|
|
error = EIO;
|
|
|
|
|
|
|
|
IFOPT(vn, VN_DONTCLUSTER)
|
|
|
|
nra = 0;
|
|
|
|
|
1996-01-14 20:32:14 +00:00
|
|
|
off = byten % bsize;
|
1995-04-19 10:31:18 +00:00
|
|
|
if (off)
|
|
|
|
sz = bsize - off;
|
|
|
|
else
|
|
|
|
sz = (1 + nra) * bsize;
|
|
|
|
if (resid < sz)
|
|
|
|
sz = resid;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
bp->b_resid -= (resid - sz);
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFOPT(vn,VN_IO)
|
1996-01-14 20:32:14 +00:00
|
|
|
printf(
|
|
|
|
/* XXX no %qx in kernel. Synthesize it. */
|
1998-07-11 07:46:16 +00:00
|
|
|
"vnstrategy: vp %p/%p bn 0x%lx%08lx/0x%lx sz 0x%lx\n",
|
|
|
|
(void *)vn->sc_vp, (void *)vp,
|
|
|
|
(u_long)(byten >> 32), (u_long)byten,
|
|
|
|
(u_long)nbn, sz);
|
1995-04-19 10:31:18 +00:00
|
|
|
|
|
|
|
nbp->b_flags = flags;
|
|
|
|
nbp->b_bcount = sz;
|
|
|
|
nbp->b_bufsize = sz;
|
|
|
|
nbp->b_error = 0;
|
|
|
|
if (vp->v_type == VBLK || vp->v_type == VCHR)
|
|
|
|
nbp->b_dev = vp->v_rdev;
|
|
|
|
else
|
|
|
|
nbp->b_dev = NODEV;
|
|
|
|
nbp->b_data = addr;
|
|
|
|
nbp->b_blkno = nbn + btodb(off);
|
1998-08-19 10:50:32 +00:00
|
|
|
nbp->b_offset = dbtob(nbn) + off;
|
1995-04-19 10:31:18 +00:00
|
|
|
nbp->b_proc = bp->b_proc;
|
|
|
|
nbp->b_iodone = vniodone;
|
|
|
|
nbp->b_vp = vp;
|
|
|
|
nbp->b_rcred = vn->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->b_wcred = vn->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->b_dirtyoff = bp->b_dirtyoff;
|
|
|
|
nbp->b_dirtyend = bp->b_dirtyend;
|
|
|
|
nbp->b_validoff = bp->b_validoff;
|
|
|
|
nbp->b_validend = bp->b_validend;
|
|
|
|
|
|
|
|
if ((nbp->b_flags & B_READ) == 0)
|
|
|
|
nbp->b_vp->v_numoutput++;
|
|
|
|
|
1998-07-04 20:45:42 +00:00
|
|
|
VOP_STRATEGY(vp, nbp);
|
1995-04-19 10:31:18 +00:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
while ((nbp->b_flags & B_DONE) == 0) {
|
|
|
|
nbp->b_flags |= B_WANTED;
|
|
|
|
tsleep(nbp, PRIBIO, "vnwait", 0);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if( nbp->b_flags & B_ERROR) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid -= (resid - sz);
|
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
|
|
|
return;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1996-01-14 20:32:14 +00:00
|
|
|
byten += sz;
|
1995-04-19 10:31:18 +00:00
|
|
|
addr += sz;
|
|
|
|
resid -= sz;
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
1995-04-19 10:31:18 +00:00
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#else /* SLICE */
|
|
|
|
static void
|
|
|
|
nvsIOreq(void *private ,struct buf *bp)
|
|
|
|
{
|
|
|
|
struct vn_softc *vn = private;
|
|
|
|
u_int32_t unit = vn->unit;
|
|
|
|
register daddr_t bn;
|
|
|
|
int error;
|
|
|
|
int isvplocked = 0;
|
|
|
|
long sz;
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
|
|
|
|
|
|
|
IFOPT(vn, VN_DEBUG)
|
|
|
|
printf("vnstrategy(%p): unit %d\n", bp, unit);
|
|
|
|
|
|
|
|
if ((vn->sc_flags & VNF_INITED) == 0) {
|
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bn = bp->b_pblkno;
|
|
|
|
bp->b_resid = bp->b_bcount;/* XXX best place to set this? */
|
|
|
|
sz = howmany(bp->b_bcount, DEV_BSIZE);
|
1998-05-06 22:14:48 +00:00
|
|
|
if (bn < 0 || bn + sz > vn->sc_size) {
|
|
|
|
if (bn != vn->sc_size) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
}
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
1998-04-19 23:32:49 +00:00
|
|
|
|
|
|
|
if( (bp->b_flags & B_PAGING) == 0) {
|
|
|
|
aiov.iov_base = bp->b_data;
|
|
|
|
aiov.iov_len = bp->b_bcount;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = dbtob(bn);
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
if( bp->b_flags & B_READ)
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
else
|
|
|
|
auio.uio_rw = UIO_WRITE;
|
|
|
|
auio.uio_resid = bp->b_bcount;
|
|
|
|
auio.uio_procp = curproc;
|
|
|
|
if (!VOP_ISLOCKED(vn->sc_vp)) {
|
|
|
|
isvplocked = 1;
|
|
|
|
vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY, curproc);
|
|
|
|
}
|
|
|
|
if( bp->b_flags & B_READ)
|
|
|
|
error = VOP_READ(vn->sc_vp, &auio, 0, vn->sc_cred);
|
|
|
|
else
|
|
|
|
error = VOP_WRITE(vn->sc_vp, &auio, 0, vn->sc_cred);
|
|
|
|
if (isvplocked) {
|
|
|
|
VOP_UNLOCK(vn->sc_vp, 0, curproc);
|
|
|
|
isvplocked = 0;
|
|
|
|
}
|
|
|
|
bp->b_resid = auio.uio_resid;
|
|
|
|
|
|
|
|
if( error )
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
} else {
|
|
|
|
long bsize, resid;
|
|
|
|
off_t byten;
|
|
|
|
int flags;
|
|
|
|
caddr_t addr;
|
|
|
|
struct buf *nbp;
|
|
|
|
|
|
|
|
nbp = getvnbuf();
|
1998-07-04 00:27:48 +00:00
|
|
|
bzero(nbp, sizeof(struct buf));
|
|
|
|
LIST_INIT(&nbp->b_dep);
|
1998-04-19 23:32:49 +00:00
|
|
|
byten = dbtob(bn);
|
|
|
|
/* This is probably the only time this is RIGHT */
|
|
|
|
bsize = vn->sc_vp->v_mount->mnt_stat.f_iosize;
|
|
|
|
addr = bp->b_data;
|
|
|
|
flags = bp->b_flags | B_CALL;
|
|
|
|
for (resid = bp->b_resid; resid; ) {
|
|
|
|
struct vnode *vp;
|
|
|
|
daddr_t nbn;
|
|
|
|
int off, s, nra;
|
|
|
|
|
|
|
|
nra = 0;
|
|
|
|
if (!VOP_ISLOCKED(vn->sc_vp)) {
|
|
|
|
isvplocked = 1;
|
|
|
|
vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY, curproc);
|
|
|
|
}
|
|
|
|
error = VOP_BMAP(vn->sc_vp, (daddr_t)(byten / bsize),
|
|
|
|
&vp, &nbn, &nra, NULL);
|
|
|
|
if (isvplocked) {
|
|
|
|
VOP_UNLOCK(vn->sc_vp, 0, curproc);
|
|
|
|
isvplocked = 0;
|
|
|
|
}
|
|
|
|
if (error == 0 && nbn == -1)
|
|
|
|
error = EIO;
|
|
|
|
|
|
|
|
IFOPT(vn, VN_DONTCLUSTER)
|
|
|
|
nra = 0;
|
|
|
|
|
|
|
|
off = byten % bsize;
|
|
|
|
if (off)
|
|
|
|
sz = bsize - off;
|
|
|
|
else
|
|
|
|
sz = (1 + nra) * bsize;
|
|
|
|
if (resid < sz)
|
|
|
|
sz = resid;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
bp->b_resid -= (resid - sz);
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFOPT(vn,VN_IO)
|
|
|
|
printf(
|
|
|
|
/* XXX no %qx in kernel. Synthesize it. */
|
1998-07-11 07:46:16 +00:00
|
|
|
"vnstrategy: vp %p/%p bn 0x%lx%08lx/0x%lx sz 0x%lx\n",
|
|
|
|
(void *)vn->sc_vp, (void *)vp,
|
|
|
|
(u_long)(byten >> 32), (u_long)byten,
|
|
|
|
(u_long)nbn, sz);
|
1998-04-19 23:32:49 +00:00
|
|
|
|
|
|
|
nbp->b_flags = flags;
|
|
|
|
nbp->b_bcount = sz;
|
|
|
|
nbp->b_bufsize = sz;
|
|
|
|
nbp->b_error = 0;
|
|
|
|
if (vp->v_type == VBLK || vp->v_type == VCHR)
|
|
|
|
nbp->b_dev = vp->v_rdev;
|
|
|
|
else
|
|
|
|
nbp->b_dev = NODEV;
|
|
|
|
nbp->b_data = addr;
|
|
|
|
nbp->b_blkno = nbn + btodb(off);
|
1998-08-19 10:50:32 +00:00
|
|
|
nbp->b_offset = dbtob(nbn) + off;
|
1998-04-19 23:32:49 +00:00
|
|
|
nbp->b_proc = bp->b_proc;
|
|
|
|
nbp->b_iodone = vniodone;
|
|
|
|
nbp->b_vp = vp;
|
|
|
|
nbp->b_rcred = vn->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->b_wcred = vn->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->b_dirtyoff = bp->b_dirtyoff;
|
|
|
|
nbp->b_dirtyend = bp->b_dirtyend;
|
|
|
|
nbp->b_validoff = bp->b_validoff;
|
|
|
|
nbp->b_validend = bp->b_validend;
|
|
|
|
|
|
|
|
if ((nbp->b_flags & B_READ) == 0)
|
|
|
|
nbp->b_vp->v_numoutput++;
|
|
|
|
|
1998-07-04 20:45:42 +00:00
|
|
|
VOP_STRATEGY(vp, nbp);
|
1998-04-19 23:32:49 +00:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
while ((nbp->b_flags & B_DONE) == 0) {
|
|
|
|
nbp->b_flags |= B_WANTED;
|
|
|
|
tsleep(nbp, PRIBIO, "vnwait", 0);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if( nbp->b_flags & B_ERROR) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid -= (resid - sz);
|
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
byten += sz;
|
|
|
|
addr += sz;
|
|
|
|
resid -= sz;
|
|
|
|
}
|
|
|
|
biodone(bp);
|
|
|
|
putvnbuf(nbp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* SLICE */
|
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
void
|
1995-04-19 10:31:18 +00:00
|
|
|
vniodone( struct buf *bp) {
|
|
|
|
bp->b_flags |= B_DONE;
|
|
|
|
wakeup((caddr_t) bp);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
vnioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1994-12-04 20:08:35 +00:00
|
|
|
{
|
1995-03-11 09:32:45 +00:00
|
|
|
struct vn_softc *vn = vn_softc[vnunit(dev)];
|
1994-12-04 20:08:35 +00:00
|
|
|
struct vn_ioctl *vio;
|
|
|
|
struct vattr vattr;
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
1995-03-11 09:32:45 +00:00
|
|
|
u_long *f;
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
sh_p tp;
|
|
|
|
#endif
|
1994-12-04 20:08:35 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn,VN_FOLLOW)
|
1998-07-11 07:46:16 +00:00
|
|
|
printf("vnioctl(0x%lx, 0x%lx, %p, 0x%x, %p): unit %d\n",
|
|
|
|
(u_long)dev, cmd, (void *)data, flag, (void *)p,
|
|
|
|
vnunit(dev));
|
1994-12-12 00:23:11 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case VNIOCATTACH:
|
|
|
|
case VNIOCDETACH:
|
|
|
|
case VNIOCGSET:
|
|
|
|
case VNIOCGCLEAR:
|
|
|
|
case VNIOCUSET:
|
|
|
|
case VNIOCUCLEAR:
|
|
|
|
goto vn_specific;
|
1994-12-12 00:23:11 +00:00
|
|
|
}
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifndef SLICE
|
1995-03-11 09:32:45 +00:00
|
|
|
|
|
|
|
IFOPT(vn,VN_LABELS) {
|
|
|
|
if (vn->sc_slices != NULL) {
|
1995-04-30 15:14:34 +00:00
|
|
|
error = dsioctl("vn", dev, cmd, data, flag,
|
|
|
|
&vn->sc_slices, vnstrategy,
|
|
|
|
(ds_setgeom_t *)NULL);
|
1997-12-06 14:27:56 +00:00
|
|
|
if (error != ENOIOCTL)
|
1995-03-11 09:32:45 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
if (dkslice(dev) != WHOLE_DISK_SLICE ||
|
1995-03-11 09:32:45 +00:00
|
|
|
dkpart(dev) != RAW_PART)
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#endif
|
1995-03-11 09:32:45 +00:00
|
|
|
vn_specific:
|
1994-12-12 00:23:11 +00:00
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
vio = (struct vn_ioctl *)data;
|
1995-03-11 09:32:45 +00:00
|
|
|
f = (u_long*)data;
|
1994-12-04 20:08:35 +00:00
|
|
|
switch (cmd) {
|
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
case VNIOCATTACH:
|
1994-12-04 20:08:35 +00:00
|
|
|
if (vn->sc_flags & VNF_INITED)
|
|
|
|
return(EBUSY);
|
|
|
|
/*
|
|
|
|
* Always open for read and write.
|
|
|
|
* This is probably bogus, but it lets vn_open()
|
|
|
|
* weed out directories, sockets, etc. so we don't
|
|
|
|
* have to worry about them.
|
|
|
|
*/
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vn_file, p);
|
1995-02-14 06:06:07 +00:00
|
|
|
error = vn_open(&nd, FREAD|FWRITE, 0);
|
|
|
|
if (error)
|
1994-12-04 20:08:35 +00:00
|
|
|
return(error);
|
1995-02-14 06:06:07 +00:00
|
|
|
error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p);
|
|
|
|
if (error) {
|
1997-02-10 02:22:35 +00:00
|
|
|
VOP_UNLOCK(nd.ni_vp, 0, p);
|
1994-12-04 20:08:35 +00:00
|
|
|
(void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return(error);
|
|
|
|
}
|
1997-02-10 02:22:35 +00:00
|
|
|
VOP_UNLOCK(nd.ni_vp, 0, p);
|
1994-12-04 20:08:35 +00:00
|
|
|
vn->sc_vp = nd.ni_vp;
|
|
|
|
vn->sc_size = btodb(vattr.va_size); /* note truncation */
|
1995-02-14 06:06:07 +00:00
|
|
|
error = vnsetcred(vn, p->p_ucred);
|
|
|
|
if (error) {
|
1994-12-04 20:08:35 +00:00
|
|
|
(void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
vio->vn_size = dbtob(vn->sc_size);
|
|
|
|
vn->sc_flags |= VNF_INITED;
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
/*
|
|
|
|
* XXX The filesystem blocksize will say 1024
|
|
|
|
* for a 8K filesystem. don't know yet how to deal with this,
|
|
|
|
* so lie for now.. say 512.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
vn->limit.blksize = vn->sc_vp->v_mount->mnt_stat.f_bsize;
|
|
|
|
#else
|
|
|
|
vn->limit.blksize = DEV_BSIZE;
|
|
|
|
#endif
|
|
|
|
vn->slice->limits.blksize = vn->limit.blksize;
|
|
|
|
vn->limit.slicesize = vattr.va_size;
|
|
|
|
vn->slice->limits.slicesize = vattr.va_size;
|
|
|
|
/*
|
|
|
|
* We have a media to read/write.
|
|
|
|
* Try identify it.
|
|
|
|
*/
|
1998-07-13 08:23:05 +00:00
|
|
|
slice_start_probe(vn->slice); /* this happens asynchronously */
|
1998-04-19 23:32:49 +00:00
|
|
|
#else
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_LABELS) {
|
|
|
|
/*
|
|
|
|
* Reopen so that `ds' knows which devices are open.
|
1995-05-30 08:16:23 +00:00
|
|
|
* If this is the first VNIOCSET, then we've
|
|
|
|
* guaranteed that the device is the cdev and that
|
1995-03-11 09:32:45 +00:00
|
|
|
* no other slices or labels are open. Otherwise,
|
|
|
|
* we rely on VNIOCCLR not being abused.
|
|
|
|
*/
|
|
|
|
error = vnopen(dev, flag, S_IFCHR, p);
|
|
|
|
if (error)
|
|
|
|
vnclear(vn);
|
|
|
|
}
|
1998-04-19 23:32:49 +00:00
|
|
|
#endif
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_FOLLOW)
|
1995-02-14 06:06:07 +00:00
|
|
|
printf("vnioctl: SET vp %p size %x\n",
|
1994-12-04 20:08:35 +00:00
|
|
|
vn->sc_vp, vn->sc_size);
|
|
|
|
break;
|
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
case VNIOCDETACH:
|
1994-12-04 20:08:35 +00:00
|
|
|
if ((vn->sc_flags & VNF_INITED) == 0)
|
|
|
|
return(ENXIO);
|
1994-12-16 16:50:15 +00:00
|
|
|
/*
|
|
|
|
* XXX handle i/o in progress. Return EBUSY, or wait, or
|
|
|
|
* flush the i/o.
|
|
|
|
* XXX handle multiple opens of the device. Return EBUSY,
|
|
|
|
* or revoke the fd's.
|
|
|
|
* How are these problems handled for removable and failing
|
|
|
|
* hardware devices?
|
|
|
|
*/
|
1994-12-04 20:08:35 +00:00
|
|
|
vnclear(vn);
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_FOLLOW)
|
1994-12-04 20:08:35 +00:00
|
|
|
printf("vnioctl: CLRed\n");
|
1995-03-11 09:32:45 +00:00
|
|
|
break;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
case VNIOCGSET:
|
|
|
|
vn_options |= *f;
|
|
|
|
*f = vn_options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VNIOCGCLEAR:
|
|
|
|
vn_options &= ~(*f);
|
|
|
|
*f = vn_options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VNIOCUSET:
|
|
|
|
vn->sc_options |= *f;
|
|
|
|
*f = vn->sc_options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VNIOCUCLEAR:
|
|
|
|
vn->sc_options &= ~(*f);
|
|
|
|
*f = vn->sc_options;
|
1994-12-04 20:08:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1994-12-16 16:50:15 +00:00
|
|
|
return (ENOTTY);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Duplicate the current processes' credentials. Since we are called only
|
|
|
|
* as the result of a SET ioctl and only root can do that, any future access
|
|
|
|
* to this "disk" is essentially as root. Note that credentials may change
|
|
|
|
* if some other uid can write directly to the mapped file (NFS).
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
int
|
1994-12-04 20:08:35 +00:00
|
|
|
vnsetcred(struct vn_softc *vn, struct ucred *cred)
|
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
|
|
|
char *tmpbuf;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
vn->sc_cred = crdup(cred);
|
|
|
|
tmpbuf = malloc(DEV_BSIZE, M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
/* XXX: Horrible kludge to establish credentials for NFS */
|
|
|
|
aiov.iov_base = tmpbuf;
|
|
|
|
aiov.iov_len = min(DEV_BSIZE, dbtob(vn->sc_size));
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
auio.uio_resid = aiov.iov_len;
|
1997-08-14 13:44:19 +00:00
|
|
|
vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY, curproc);
|
1994-12-04 20:08:35 +00:00
|
|
|
error = VOP_READ(vn->sc_vp, &auio, 0, vn->sc_cred);
|
1997-08-14 13:44:19 +00:00
|
|
|
VOP_UNLOCK(vn->sc_vp, 0, curproc);
|
1994-12-04 20:08:35 +00:00
|
|
|
|
|
|
|
free(tmpbuf, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1996-08-19 20:07:07 +00:00
|
|
|
vnshutdown(int howto, void *ignored)
|
1994-12-04 20:08:35 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1995-03-01 05:05:21 +00:00
|
|
|
for (i = 0; i < NVN; i++)
|
1994-12-04 20:08:35 +00:00
|
|
|
if (vn_softc[i] && vn_softc[i]->sc_flags & VNF_INITED)
|
|
|
|
vnclear(vn_softc[i]);
|
|
|
|
}
|
1994-12-06 06:47:32 +00:00
|
|
|
|
1994-12-04 20:08:35 +00:00
|
|
|
void
|
|
|
|
vnclear(struct vn_softc *vn)
|
|
|
|
{
|
|
|
|
register struct vnode *vp = vn->sc_vp;
|
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
|
1995-03-11 09:32:45 +00:00
|
|
|
IFOPT(vn, VN_FOLLOW)
|
|
|
|
printf("vnclear(%p): vp=%p\n", vn, vp);
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
if (vn->slice->handler_up) {
|
|
|
|
(*(vn->slice->handler_up->revoke)) (vn->slice->private_up);
|
|
|
|
}
|
|
|
|
#else /* SLICE */
|
|
|
|
if (vn->sc_slices != NULL)
|
|
|
|
dsgone(&vn->sc_slices);
|
|
|
|
#endif
|
1994-12-04 20:08:35 +00:00
|
|
|
vn->sc_flags &= ~VNF_INITED;
|
|
|
|
if (vp == (struct vnode *)0)
|
1994-12-16 16:50:15 +00:00
|
|
|
panic("vnclear: null vp");
|
1994-12-04 20:08:35 +00:00
|
|
|
(void) vn_close(vp, FREAD|FWRITE, vn->sc_cred, p);
|
|
|
|
crfree(vn->sc_cred);
|
|
|
|
vn->sc_vp = (struct vnode *)0;
|
|
|
|
vn->sc_cred = (struct ucred *)0;
|
|
|
|
vn->sc_size = 0;
|
|
|
|
}
|
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifndef SLICE
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-12-04 20:08:35 +00:00
|
|
|
vnsize(dev_t dev)
|
|
|
|
{
|
|
|
|
int unit = vnunit(dev);
|
|
|
|
|
1995-03-01 05:05:21 +00:00
|
|
|
if (unit >= NVN || (!vn_softc[unit]) ||
|
1994-12-06 06:47:32 +00:00
|
|
|
(vn_softc[unit]->sc_flags & VNF_INITED) == 0)
|
1994-12-04 20:08:35 +00:00
|
|
|
return(-1);
|
1994-12-06 06:47:32 +00:00
|
|
|
return(vn_softc[unit]->sc_size);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-12-04 20:08:35 +00:00
|
|
|
vndump(dev_t dev)
|
|
|
|
{
|
1994-12-16 16:50:15 +00:00
|
|
|
return (ENODEV);
|
1994-12-04 20:08:35 +00:00
|
|
|
}
|
1998-02-20 13:27:36 +00:00
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
static vn_devsw_installed = 0;
|
|
|
|
#endif /* !SLICE */
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
|
|
|
vn_drvinit(void *unused)
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifndef SLICE
|
1995-11-29 10:49:16 +00:00
|
|
|
if( ! vn_devsw_installed ) {
|
1996-08-28 17:45:08 +00:00
|
|
|
if (at_shutdown(&vnshutdown, NULL, SHUTDOWN_POST_SYNC)) {
|
1996-08-19 20:07:07 +00:00
|
|
|
printf("vn: could not install shutdown hook\n");
|
1996-08-19 21:06:39 +00:00
|
|
|
return;
|
1996-08-19 20:07:07 +00:00
|
|
|
}
|
1998-07-04 22:30:26 +00:00
|
|
|
cdevsw_add_generic(BDEV_MAJOR, CDEV_MAJOR, &vn_cdevsw);
|
1996-08-19 21:06:39 +00:00
|
|
|
vn_devsw_installed = 1;
|
1996-01-27 04:18:15 +00:00
|
|
|
}
|
1998-04-19 23:32:49 +00:00
|
|
|
#else /* SLICE */
|
|
|
|
int mynor;
|
|
|
|
int unit;
|
|
|
|
struct vn_softc *vn;
|
|
|
|
char namebuf[64];
|
|
|
|
if (at_shutdown(&vnshutdown, NULL, SHUTDOWN_POST_SYNC)) {
|
|
|
|
printf("vn: could not install shutdown hook\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (unit = 0; unit < NVN; unit++) {
|
|
|
|
vn = malloc(sizeof *vn, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (!vn)
|
|
|
|
return;
|
|
|
|
bzero(vn, sizeof *vn);
|
|
|
|
vn_softc[unit] = vn;
|
|
|
|
vn->unit = unit;
|
|
|
|
sprintf(namebuf,"vn%d",vn->unit);
|
|
|
|
vn->mynor = dkmakeminor(unit, WHOLE_DISK_SLICE,
|
|
|
|
RAW_PART);
|
|
|
|
vn->limit.blksize = DEV_BSIZE;
|
|
|
|
vn->limit.slicesize = ((u_int64_t)vn->sc_size * DEV_BSIZE);
|
|
|
|
sl_make_slice(&slicetype,
|
|
|
|
vn,
|
|
|
|
&vn->limit,
|
|
|
|
&vn->slice,
|
|
|
|
namebuf);
|
|
|
|
/* Allow full probing */
|
|
|
|
vn->slice->probeinfo.typespecific = NULL;
|
|
|
|
vn->slice->probeinfo.type = NULL;
|
|
|
|
}
|
|
|
|
#endif /* SLICE */
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-24 07:54:00 +00:00
|
|
|
SYSINIT(vndev, SI_SUB_DRIVERS, SI_ORDER_ANY, vn_drvinit, NULL)
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1998-04-19 23:32:49 +00:00
|
|
|
#ifdef SLICE
|
|
|
|
|
|
|
|
static int
|
|
|
|
nvsopen(void *private, int flags, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
struct vn_softc *vn;
|
|
|
|
|
|
|
|
vn = private;
|
|
|
|
|
|
|
|
IFOPT(vn, VN_FOLLOW)
|
|
|
|
printf("vnopen(0x%lx, 0x%x, 0x%x, %p)\n",
|
|
|
|
makedev(0,vn->mynor) , flags, mode, p);
|
|
|
|
return (0);
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1998-04-22 10:25:27 +00:00
|
|
|
#if 0
|
1998-04-19 23:32:49 +00:00
|
|
|
static void
|
|
|
|
nvsclose(void *private, int flags, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
struct vn_softc *vn;
|
|
|
|
|
|
|
|
vn = private;
|
|
|
|
IFOPT(vn, VN_FOLLOW)
|
|
|
|
printf("vnclose(0x%lx, 0x%x, 0x%x, %p)\n",
|
|
|
|
makedev(0,vn->mynor) , flags, mode, p);
|
|
|
|
return;
|
|
|
|
}
|
1998-04-22 10:25:27 +00:00
|
|
|
#endif
|
1998-04-19 23:32:49 +00:00
|
|
|
|
|
|
|
static int
|
1998-06-07 20:10:53 +00:00
|
|
|
nvsioctl( void *private, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
1998-04-19 23:32:49 +00:00
|
|
|
{
|
|
|
|
struct vn_softc *vn;
|
|
|
|
|
|
|
|
vn = private;
|
|
|
|
|
|
|
|
return(vnioctl(makedev(0,vn->mynor), cmd, addr, flag, p));
|
|
|
|
}
|
|
|
|
|
1998-05-06 22:14:48 +00:00
|
|
|
static int
|
|
|
|
nvsdump(void *private, int32_t blkoff, int32_t blkcnt)
|
|
|
|
{
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
1998-04-19 23:32:49 +00:00
|
|
|
#endif
|
1994-12-04 20:08:35 +00:00
|
|
|
#endif
|