From 15d56af06f069a1f8dc3a8a4b106b91a3d249f96 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Tue, 27 Jun 1995 11:07:31 +0000 Subject: This commit was manufactured by cvs2svn to create branch 'CSRG'. --- sys/dev/vn/vn.c | 550 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/nfs/nfsproto.h | 441 ++++++++++++++++++++++++++++++++++++++++++ sys/sys/vnioctl.h | 61 ++++++ 3 files changed, 1052 insertions(+) create mode 100644 sys/dev/vn/vn.c create mode 100644 sys/nfs/nfsproto.h create mode 100644 sys/sys/vnioctl.h (limited to 'sys') diff --git a/sys/dev/vn/vn.c b/sys/dev/vn/vn.c new file mode 100644 index 0000000..63d0359 --- /dev/null +++ b/sys/dev/vn/vn.c @@ -0,0 +1,550 @@ +#define DEBUG 1 +/* + * 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 + * + * @(#)vn.c 8.6 (Berkeley) 4/1/94 + */ + +/* + * 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#ifdef DEBUG +int dovncluster = 1; +int vndebug = 0x00; +#define VDB_FOLLOW 0x01 +#define VDB_INIT 0x02 +#define VDB_IO 0x04 +#endif + +#define vnunit(x) (minor(x) >> 3) + +#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 */ + struct vnode *sc_vp; /* vnode */ + struct ucred *sc_cred; /* credentials */ + int sc_maxactive; /* max # of active requests */ + struct buf sc_tab; /* transfer queue */ +}; + +/* sc_flags */ +#define VNF_INITED 0x01 + +struct vn_softc **vn_softc; +int numvnd; + +void vnattach __P((int num)); +int vnopen __P((dev_t dev, int flags, int mode, struct proc *p)); +void vnstrategy __P((struct buf *bp)); +void vnstart __P((struct vn_softc *vn)); +void vniodone __P((struct buf *bp)); +int vnread __P((dev_t dev, struct uio *uio, int flags, struct proc *p)); +int vnwrite __P((dev_t dev, struct uio *uio, int flags, struct proc *p)); +int vnioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)); +int vnsetcred __P((struct vn_softc *vn, struct ucred *cred)); +void vnthrottle __P((struct vn_softc *vn, struct vnode *vp)); +void vnshutdown __P((void)); +void vnclear __P((struct vn_softc *vn)); +size_t vnsize __P((dev_t dev)); +int vndump __P((dev_t dev)); + +int vnclose() {return 0;} + +int +vnopen(dev_t dev, int flags, int mode, struct proc *p) +{ + int unit = vnunit(dev),size; + struct vn_softc **vscp, **old; + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnopen(%x, %x, %x, %x)\n", dev, flags, mode, p); +#endif + if (unit >= numvnd) { + /* + * We need to get more space for our config. If you say + * this is overkill, you're absolutely right. + */ + size = (unit+1) * (sizeof *vn_softc); + vscp = (struct vn_softc **) malloc(size, M_DEVBUF, M_WAITOK); + if (!vscp) + return(ENOMEM); + bzero(vscp,size); + if (numvnd) + bcopy(vn_softc, vscp, numvnd * (sizeof *vn_softc)); + numvnd = unit + 1; + old = vn_softc; + vn_softc = vscp; + if (old) + free(old, M_DEVBUF); + } + if (!vn_softc[unit]) { + vn_softc[unit] = (struct vn_softc *) + malloc (sizeof **vn_softc, M_DEVBUF, M_WAITOK); + if (!vn_softc[unit]) + return(ENOMEM); + bzero(vn_softc[unit], sizeof **vn_softc); + } + return(0); +} + +/* + * Break the request into bsize pieces and submit using VOP_BMAP/VOP_STRATEGY. + * Note that this driver can only be used for swapping over NFS on the hp + * since nfs_strategy on the vax cannot handle u-areas and page tables. + */ +void +vnstrategy(struct buf *bp) +{ + int unit = vnunit(bp->b_dev); + register struct vn_softc *vn = vn_softc[unit]; + register struct buf *nbp; + register int bn, bsize, resid; + register caddr_t addr; + int sz, flags, error; + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnstrategy(%x): unit %d\n", bp, unit); +#endif + if ((vn->sc_flags & VNF_INITED) == 0) { + bp->b_error = ENXIO; + bp->b_flags |= B_ERROR; + biodone(bp); + return; + } + 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; + } + bn = dbtob(bn); + 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; resid -= sz) { + struct vnode *vp; + daddr_t nbn; + int off, s, nra; + + nra = 0; + error = VOP_BMAP(vn->sc_vp, bn / bsize, &vp, &nbn, &nra); + if (error == 0 && (long)nbn == -1) + error = EIO; +#ifdef DEBUG + if (!dovncluster) + nra = 0; +#endif + + if (off = bn % bsize) + sz = bsize - off; + else + sz = (1 + nra) * bsize; + if (resid < sz) + sz = resid; +#ifdef DEBUG + if (vndebug & VDB_IO) + printf("vnstrategy: vp %x/%x bn %x/%x sz %x\n", + vn->sc_vp, vp, bn, nbn, sz); +#endif + + nbp = getvnbuf(); + nbp->b_flags = flags; + nbp->b_bcount = sz; + nbp->b_bufsize = bp->b_bufsize; + 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); + nbp->b_proc = bp->b_proc; + nbp->b_iodone = vniodone; + nbp->b_vp = vp; + nbp->b_pfcent = (int) bp; /* XXX */ + 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 there was an error or a hole in the file...punt. + * Note that we deal with this after the nbp allocation. + * This ensures that we properly clean up any operations + * that we have already fired off. + * + * XXX we could deal with holes here but it would be + * a hassle (in the write case). + */ + if (error) { + nbp->b_error = error; + nbp->b_flags |= B_ERROR; + bp->b_resid -= (resid - sz); + biodone(nbp); + return; + } + /* + * Just sort by block number + */ + nbp->b_resid = nbp->b_blkno; + s = splbio(); + disksort(&vn->sc_tab, nbp); + if (vn->sc_tab.b_active < vn->sc_maxactive) { + vn->sc_tab.b_active++; + vnstart(vn); + } + splx(s); + bn += sz; + addr += sz; + } +} + +/* + * Feed requests sequentially. + * We do it this way to keep from flooding NFS servers if we are connected + * to an NFS file. This places the burden on the client rather than the + * server. + */ +void +vnstart(struct vn_softc *vn) +{ + register struct buf *bp; + + /* + * Dequeue now since lower level strategy routine might + * queue using same links + */ + bp = vn->sc_tab.b_actf; + vn->sc_tab.b_actf = bp->b_actf; +#ifdef DEBUG + if (vndebug & VDB_IO) + printf("vnstart(%d): bp %x vp %x blkno %x addr %x cnt %x\n", + 0, bp, bp->b_vp, bp->b_blkno, bp->b_data, + bp->b_bcount); +#endif + if ((bp->b_flags & B_READ) == 0) + bp->b_vp->v_numoutput++; + VOP_STRATEGY(bp); +} + +void +vniodone(struct buf *bp) +{ + register struct buf *pbp = (struct buf *)bp->b_pfcent; /* XXX */ + register struct vn_softc *vn = vn_softc[vnunit(pbp->b_dev)]; + int s; + + s = splbio(); +#ifdef DEBUG + if (vndebug & VDB_IO) + printf("vniodone(%d): bp %x vp %x blkno %x addr %x cnt %x\n", + 0, bp, bp->b_vp, bp->b_blkno, bp->b_data, + bp->b_bcount); +#endif + if (bp->b_error) { +#ifdef DEBUG + if (vndebug & VDB_IO) + printf("vniodone: bp %x error %d\n", bp, bp->b_error); +#endif + pbp->b_flags |= B_ERROR; + pbp->b_error = biowait(bp); + } + pbp->b_resid -= bp->b_bcount; + putvnbuf(bp); + if (pbp->b_resid == 0) { +#ifdef DEBUG + if (vndebug & VDB_IO) + printf("vniodone: pbp %x iodone\n", pbp); +#endif + biodone(pbp); + } + if (vn->sc_tab.b_actf) + vnstart(vn); + else + vn->sc_tab.b_active--; + splx(s); +} + +int +vnread(dev_t dev, struct uio *uio, int flags, struct proc *p) +{ + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnread(%x, %x, %x, %x)\n", dev, uio, flags, p); +#endif + return(physio(vnstrategy, NULL, dev, B_READ, minphys, uio)); +} + +int +vnwrite(dev_t dev, struct uio *uio, int flags, struct proc *p) +{ + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnwrite(%x, %x, %x, %x)\n", dev, uio, flags, p); +#endif + return(physio(vnstrategy, NULL, dev, B_WRITE, minphys, uio)); +} + +/* ARGSUSED */ +int +vnioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) +{ + int unit = vnunit(dev); + register struct vn_softc *vn; + struct vn_ioctl *vio; + struct vattr vattr; + struct nameidata nd; + int error; + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnioctl(%x, %x, %x, %x, %x): unit %d\n", + dev, cmd, data, flag, p, unit); +#endif + error = suser(p->p_ucred, &p->p_acflag); + if (error) + return (error); + if (unit >= numvnd) + return (ENXIO); + + vn = vn_softc[unit]; + vio = (struct vn_ioctl *)data; + switch (cmd) { + + case VNIOCSET: + 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); + if (error = vn_open(&nd, FREAD|FWRITE, 0)) + return(error); + if (error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p)) { + VOP_UNLOCK(nd.ni_vp); + (void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p); + return(error); + } + VOP_UNLOCK(nd.ni_vp); + vn->sc_vp = nd.ni_vp; + vn->sc_size = btodb(vattr.va_size); /* note truncation */ + if (error = vnsetcred(vn, p->p_ucred)) { + (void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p); + return(error); + } + vnthrottle(vn, vn->sc_vp); + vio->vn_size = dbtob(vn->sc_size); + vn->sc_flags |= VNF_INITED; +#ifdef DEBUG + if (vndebug & VDB_INIT) + printf("vnioctl: SET vp %x size %x\n", + vn->sc_vp, vn->sc_size); +#endif + break; + + case VNIOCCLR: + if ((vn->sc_flags & VNF_INITED) == 0) + return(ENXIO); + vnclear(vn); +#ifdef DEBUG + if (vndebug & VDB_INIT) + printf("vnioctl: CLRed\n"); +#endif + break; + + default: + return(ENXIO); + } + 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). + */ +int +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; + error = VOP_READ(vn->sc_vp, &auio, 0, vn->sc_cred); + + free(tmpbuf, M_TEMP); + return (error); +} + +/* + * Set maxactive based on FS type + */ +void +vnthrottle(struct vn_softc *vn, struct vnode *vp) +{ +#if 0 + extern int (**nfsv2_vnodeop_p)(); + + if (vp->v_op == nfsv2_vnodeop_p) + vn->sc_maxactive = 2; + else +#endif + vn->sc_maxactive = 8; + + if (vn->sc_maxactive < 1) + vn->sc_maxactive = 1; +} + +void +vnshutdown() +{ + int i; + + for (i = 0; i < numvnd; i++) + if (vn_softc[i] && vn_softc[i]->sc_flags & VNF_INITED) + vnclear(vn_softc[i]); +} +TEXT_SET(cleanup_set,vnshutdown); + +void +vnclear(struct vn_softc *vn) +{ + register struct vnode *vp = vn->sc_vp; + struct proc *p = curproc; /* XXX */ + +#ifdef DEBUG + if (vndebug & VDB_FOLLOW) + printf("vnclear(%x): vp %x\n", vp); +#endif + vn->sc_flags &= ~VNF_INITED; + if (vp == (struct vnode *)0) + panic("vnioctl: null vp"); + (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; +} + +size_t +vnsize(dev_t dev) +{ + int unit = vnunit(dev); + register struct vn_softc *vn = vn_softc[unit]; + + if (unit >= numvnd || (vn->sc_flags & VNF_INITED) == 0) + return(-1); + return(vn->sc_size); +} + +int +vndump(dev_t dev) +{ + return(ENXIO); +} +#endif diff --git a/sys/nfs/nfsproto.h b/sys/nfs/nfsproto.h new file mode 100644 index 0000000..ac1a090 --- /dev/null +++ b/sys/nfs/nfsproto.h @@ -0,0 +1,441 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsproto.h 8.1 (Berkeley) 6/10/93 + * $Id: nfsproto.h,v 1.4 1994/08/21 06:50:13 paul Exp $ + */ + +#ifndef _NFS_NFSPROTO_H_ +#define _NFS_NFSPROTO_H_ + +/* + * nfs definitions as per the Version 2 and 3 specs + */ + +/* + * Constants as defined in the Sun NFS Version 2 and 3 specs. + * "NFS: Network File System Protocol Specification" RFC1094 + * and in the "NFS: Network File System Version 3 Protocol + * Specification" + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_VER3 3 +#define NFS_V2MAXDATA 8192 +#define NFS_MAXDGRAMDATA 16384 +#define NFS_MAXDATA 32768 +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns (version 2 and 3) */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_XDEV 18 /* Version 3 only */ +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_INVAL 22 /* Version 3 only */ +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_MLINK 31 /* Version 3 only */ +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_REMOTE 71 /* Version 3 only */ +#define NFSERR_WFLUSH 99 /* Version 2 only */ +#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ +#define NFSERR_NOT_SYNC 10002 +#define NFSERR_BAD_COOKIE 10003 +#define NFSERR_NOTSUPP 10004 +#define NFSERR_TOOSMALL 10005 +#define NFSERR_SERVERFAULT 10006 +#define NFSERR_BADTYPE 10007 +#define NFSERR_JUKEBOX 10008 +#define NFSERR_TRYLATER NFSERR_JUKEBOX +#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ + +#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ +#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ +#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_UNSIGNED 4 + +/* specific to NFS Version 2 */ +#define NFSX_V2FH 32 +#define NFSX_V2FATTR 68 +#define NFSX_V2SATTR 32 +#define NFSX_V2COOKIE 4 +#define NFSX_V2STATFS 20 + +/* specific to NFS Version 3 */ +#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ +#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ +#define NFSX_V3FATTR 84 +#define NFSX_V3SATTR 60 /* max. all fields filled in */ +#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) +#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) +#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) +#define NFSX_V3COOKIEVERF 8 +#define NFSX_V3WRITEVERF 8 +#define NFSX_V3CREATEVERF 8 +#define NFSX_V3STATFS 52 +#define NFSX_V3FSINFO 48 +#define NFSX_V3PATHCONF 24 + +/* variants for both versions */ +#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ + NFSX_V2FH) +#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) +#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) +#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ + NFSX_V2FATTR) +#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) +#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) +#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) +#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) +#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) +#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ + (2 * NFSX_UNSIGNED)) +#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) + +/* nfs rpc procedure numbers (before version mapping) */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_LOOKUP 3 +#define NFSPROC_ACCESS 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITE 7 +#define NFSPROC_CREATE 8 +#define NFSPROC_MKDIR 9 +#define NFSPROC_SYMLINK 10 +#define NFSPROC_MKNOD 11 +#define NFSPROC_REMOVE 12 +#define NFSPROC_RMDIR 13 +#define NFSPROC_RENAME 14 +#define NFSPROC_LINK 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_READDIRPLUS 17 +#define NFSPROC_FSSTAT 18 +#define NFSPROC_FSINFO 19 +#define NFSPROC_PATHCONF 20 +#define NFSPROC_COMMIT 21 + +/* And leasing (nqnfs) procedure numbers (must be last) */ +#define NQNFSPROC_GETLEASE 22 +#define NQNFSPROC_VACATED 23 +#define NQNFSPROC_EVICTED 24 + +#define NFSPROC_NOOP 25 +#define NFS_NPROCS 26 + +/* Actual Version 2 procedure numbers */ +#define NFSV2PROC_NULL 0 +#define NFSV2PROC_GETATTR 1 +#define NFSV2PROC_SETATTR 2 +#define NFSV2PROC_NOOP 3 +#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_LOOKUP 4 +#define NFSV2PROC_READLINK 5 +#define NFSV2PROC_READ 6 +#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_WRITE 8 +#define NFSV2PROC_CREATE 9 +#define NFSV2PROC_REMOVE 10 +#define NFSV2PROC_RENAME 11 +#define NFSV2PROC_LINK 12 +#define NFSV2PROC_SYMLINK 13 +#define NFSV2PROC_MKDIR 14 +#define NFSV2PROC_RMDIR 15 +#define NFSV2PROC_READDIR 16 +#define NFSV2PROC_STATFS 17 + +/* + * Constants used by the Version 3 protocol for various RPCs + */ +#define NFSV3SATTRTIME_DONTCHANGE 0 +#define NFSV3SATTRTIME_TOSERVER 1 +#define NFSV3SATTRTIME_TOCLIENT 2 + +#define NFSV3ACCESS_READ 0x01 +#define NFSV3ACCESS_LOOKUP 0x02 +#define NFSV3ACCESS_MODIFY 0x04 +#define NFSV3ACCESS_EXTEND 0x08 +#define NFSV3ACCESS_DELETE 0x10 +#define NFSV3ACCESS_EXECUTE 0x20 + +#define NFSV3WRITE_UNSTABLE 0 +#define NFSV3WRITE_DATASYNC 1 +#define NFSV3WRITE_FILESYNC 2 + +#define NFSV3CREATE_UNCHECKED 0 +#define NFSV3CREATE_GUARDED 1 +#define NFSV3CREATE_EXCLUSIVE 2 + +#define NFSV3FSINFO_LINK 0x01 +#define NFSV3FSINFO_SYMLINK 0x02 +#define NFSV3FSINFO_HOMOGENEOUS 0x08 +#define NFSV3FSINFO_CANSETTIME 0x10 + +/* Conversion macros */ +#define vtonfsv2_mode(t,m) \ + txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ + MAKEIMODE((t), (m))) +#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) +#define nfstov_mode(a) (fxdr_unsigned(u_short, (a))&07777) +#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((long)(a))]) +#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((long)(a))]) +#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_long,(a))&0x7] +#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_long,(a))&0x7] + +/* File types */ +typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, + NFSOCK=6, NFFIFO=7 } nfstype; + +/* Structs for common parts of the rpc's */ +/* + * File Handle (32 bytes for version 2), variable up to 64 for version 3. + * File Handles of up to NFS_SMALLFH in size are stored directly in the + * nfs node, whereas larger ones are malloc'd. (This never happens when + * NFS_SMALLFH is set to 64.) + * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. + */ +#ifndef NFS_SMALLFH +#define NFS_SMALLFH 64 +#endif +union nfsfh { + fhandle_t fh_generic; + u_char fh_bytes[NFS_SMALLFH]; +}; +typedef union nfsfh nfsfh_t; + +struct nfsv2_time { + u_long nfsv2_sec; + u_long nfsv2_usec; +}; +typedef struct nfsv2_time nfstime2; + +struct nfsv3_time { + u_long nfsv3_sec; + u_long nfsv3_nsec; +}; +typedef struct nfsv3_time nfstime3; + +/* + * Quads are defined as arrays of 2 longs to ensure dense packing for the + * protocol and to facilitate xdr conversion. + */ +struct nfs_uquad { + u_long nfsuquad[2]; +}; +typedef struct nfs_uquad nfsuint64; + +/* + * Used to convert between two u_longs and a u_quad_t. + */ +union nfs_quadconvert { + u_long lval[2]; + u_quad_t qval; +}; +typedef union nfs_quadconvert nfsquad_t; + +/* + * NFS Version 3 special file number. + */ +struct nfsv3_spec { + u_long specdata1; + u_long specdata2; +}; +typedef struct nfsv3_spec nfsv3spec; + +/* + * File attributes and setable attributes. These structures cover both + * NFS version 2 and the version 3 protocol. Note that the union is only + * used so that one pointer can refer to both variants. These structures + * go out on the wire and must be densely packed, so no quad data types + * are used. (all fields are longs or u_longs or structures of same) + * NB: You can't do sizeof(struct nfs_fattr), you must use the + * NFSX_FATTR(v3) macro. + */ +struct nfs_fattr { + u_long fa_type; + u_long fa_mode; + u_long fa_nlink; + u_long fa_uid; + u_long fa_gid; + union { + struct { + u_long nfsv2fa_size; + u_long nfsv2fa_blocksize; + u_long nfsv2fa_rdev; + u_long nfsv2fa_blocks; + u_long nfsv2fa_fsid; + u_long nfsv2fa_fileid; + nfstime2 nfsv2fa_atime; + nfstime2 nfsv2fa_mtime; + nfstime2 nfsv2fa_ctime; + } fa_nfsv2; + struct { + nfsuint64 nfsv3fa_size; + nfsuint64 nfsv3fa_used; + nfsv3spec nfsv3fa_rdev; + nfsuint64 nfsv3fa_fsid; + nfsuint64 nfsv3fa_fileid; + nfstime3 nfsv3fa_atime; + nfstime3 nfsv3fa_mtime; + nfstime3 nfsv3fa_ctime; + } fa_nfsv3; + } fa_un; +}; + +/* and some ugly defines for accessing union components */ +#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size +#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize +#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev +#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks +#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid +#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid +#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime +#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime +#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime +#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size +#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used +#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev +#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid +#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid +#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime +#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime +#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime + +struct nfsv2_sattr { + u_long sa_mode; + u_long sa_uid; + u_long sa_gid; + u_long sa_size; + nfstime2 sa_atime; + nfstime2 sa_mtime; +}; + +/* + * NFS Version 3 sattr structure for the new node creation case. + */ +struct nfsv3_sattr { + u_long sa_modetrue; + u_long sa_mode; + u_long sa_uidtrue; + u_long sa_uid; + u_long sa_gidtrue; + u_long sa_gid; + u_long sa_sizefalse; + u_long sa_atimetype; + nfstime3 sa_atime; + u_long sa_mtimetype; + nfstime3 sa_mtime; +}; + +struct nfs_statfs { + union { + struct { + u_long nfsv2sf_tsize; + u_long nfsv2sf_bsize; + u_long nfsv2sf_blocks; + u_long nfsv2sf_bfree; + u_long nfsv2sf_bavail; + } sf_nfsv2; + struct { + nfsuint64 nfsv3sf_tbytes; + nfsuint64 nfsv3sf_fbytes; + nfsuint64 nfsv3sf_abytes; + nfsuint64 nfsv3sf_tfiles; + nfsuint64 nfsv3sf_ffiles; + nfsuint64 nfsv3sf_afiles; + u_long nfsv3sf_invarsec; + } sf_nfsv3; + } sf_un; +}; + +#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize +#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize +#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks +#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree +#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail +#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes +#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes +#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes +#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles +#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles +#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles +#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec + +struct nfsv3_fsinfo { + u_long fs_rtmax; + u_long fs_rtpref; + u_long fs_rtmult; + u_long fs_wtmax; + u_long fs_wtpref; + u_long fs_wtmult; + u_long fs_dtpref; + nfsuint64 fs_maxfilesize; + nfstime3 fs_timedelta; + u_long fs_properties; +}; + +struct nfsv3_pathconf { + u_long pc_linkmax; + u_long pc_namemax; + u_long pc_notrunc; + u_long pc_chownrestricted; + u_long pc_caseinsensitive; + u_long pc_casepreserving; +}; + +#endif diff --git a/sys/sys/vnioctl.h b/sys/sys/vnioctl.h new file mode 100644 index 0000000..ace82ee --- /dev/null +++ b/sys/sys/vnioctl.h @@ -0,0 +1,61 @@ +/* + * 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: fdioctl.h 1.1 90/07/09$ + * + * @(#)vnioctl.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Ioctl definitions for file (vnode) disk pseudo-device. + */ + +#define _PATH_VNTAB "/etc/vntab" /* default config file */ + +struct vn_ioctl { + char *vn_file; /* pathname of file to mount */ + int vn_size; /* (returned) size of disk */ +}; + +/* + * Before you can use a unit, it must be configured with VNIOCSET. + * The configuration persists across opens and closes of the device; + * an VNIOCCLR must be used to reset a configuration. An attempt to + * VNIOCSET an already active unit will return EBUSY. + */ +#define VNIOCSET _IOWR('F', 0, struct vn_ioctl) /* enable disk */ +#define VNIOCCLR _IOW('F', 1, struct vn_ioctl) /* disable disk */ -- cgit v1.1