nfs_subs.c revision 92783
11592Srgrimes/* 21592Srgrimes * Copyright (c) 1989, 1993 31592Srgrimes * The Regents of the University of California. All rights reserved. 41592Srgrimes * 51592Srgrimes * This code is derived from software contributed to Berkeley by 61592Srgrimes * Rick Macklem at The University of Guelph. 71592Srgrimes * 81592Srgrimes * Redistribution and use in source and binary forms, with or without 91592Srgrimes * modification, are permitted provided that the following conditions 101592Srgrimes * are met: 111592Srgrimes * 1. Redistributions of source code must retain the above copyright 121592Srgrimes * notice, this list of conditions and the following disclaimer. 131592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141592Srgrimes * notice, this list of conditions and the following disclaimer in the 151592Srgrimes * documentation and/or other materials provided with the distribution. 161592Srgrimes * 3. All advertising materials mentioning features or use of this software 171592Srgrimes * must display the following acknowledgement: 181592Srgrimes * This product includes software developed by the University of 191592Srgrimes * California, Berkeley and its contributors. 201592Srgrimes * 4. Neither the name of the University nor the names of its contributors 21262136Sbrueffer * may be used to endorse or promote products derived from this software 221592Srgrimes * without specific prior written permission. 231592Srgrimes * 241592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341592Srgrimes * SUCH DAMAGE. 351592Srgrimes * 361592Srgrimes * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95 3727074Ssteve */ 381592Srgrimes 3927074Ssteve#include <sys/cdefs.h> 401592Srgrimes__FBSDID("$FreeBSD: head/sys/nfsclient/nfs_subs.c 92783 2002-03-20 10:07:52Z jeff $"); 411592Srgrimes 421592Srgrimes/* 431592Srgrimes * These functions support the macros and help fiddle mbuf chains for 4431386Scharnier * the nfs op functions. They do things like create the rpc header and 4527077Ssteve * copy data between mbuf chains and uio lists. 4631386Scharnier */ 4731386Scharnier 4850476Speter#include <sys/param.h> 491592Srgrimes#include <sys/systm.h> 501592Srgrimes#include <sys/kernel.h> 511592Srgrimes#include <sys/bio.h> 521592Srgrimes#include <sys/buf.h> 53129652Sstefanf#include <sys/proc.h> 541592Srgrimes#include <sys/mount.h> 551592Srgrimes#include <sys/vnode.h> 561592Srgrimes#include <sys/namei.h> 571592Srgrimes#include <sys/mbuf.h> 581592Srgrimes#include <sys/socket.h> 591592Srgrimes#include <sys/stat.h> 601592Srgrimes#include <sys/malloc.h> 611592Srgrimes#include <sys/sysent.h> 621592Srgrimes#include <sys/syscall.h> 631592Srgrimes#include <sys/sysproto.h> 641592Srgrimes 651592Srgrimes#include <vm/vm.h> 661592Srgrimes#include <vm/vm_object.h> 671592Srgrimes#include <vm/vm_extern.h> 681592Srgrimes#include <vm/uma.h> 691592Srgrimes 701592Srgrimes#include <nfs/rpcv2.h> 711592Srgrimes#include <nfs/nfsproto.h> 721592Srgrimes#include <nfsclient/nfs.h> 731592Srgrimes#include <nfsclient/nfsnode.h> 741592Srgrimes#include <nfs/xdr_subs.h> 751592Srgrimes#include <nfsclient/nfsm_subs.h> 761592Srgrimes#include <nfsclient/nfsmount.h> 771592Srgrimes 781592Srgrimes#include <netinet/in.h> 791592Srgrimes 801592Srgrimes/* 811592Srgrimes * Data items converted to xdr at startup, since they are constant 821592Srgrimes * This is kinda hokey, but may save a little time doing byte swaps 831592Srgrimes */ 841592Srgrimesu_int32_t nfs_xdrneg1; 851592Srgrimesu_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr, 8690377Simp rpc_mismatch, rpc_auth_unix, rpc_msgaccepted; 871592Srgrimesu_int32_t nfs_true, nfs_false; 881592Srgrimes 891592Srgrimes/* And other global data */ 901592Srgrimesstatic u_int32_t nfs_xid = 0; 911592Srgrimesstatic enum vtype nv2tov_type[8]= { 921592Srgrimes VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON 931592Srgrimes}; 941592Srgrimes 951592Srgrimesint nfs_ticks; 961592Srgrimesint nfs_pbuf_freecnt = -1; /* start out unlimited */ 971592Srgrimes 981592Srgrimesstruct nfs_reqq nfs_reqq; 991592Srgrimesstruct nfs_bufq nfs_bufq; 1001592Srgrimes 1011592Srgrimesstatic int nfs_prev_nfsclnt_sy_narg; 1021592Srgrimesstatic sy_call_t *nfs_prev_nfsclnt_sy_call; 1031592Srgrimes 1041592Srgrimes/* 1051592Srgrimes * and the reverse mapping from generic to Version 2 procedure numbers 1061592Srgrimes */ 1071592Srgrimesint nfsv2_procid[NFS_NPROCS] = { 1081592Srgrimes NFSV2PROC_NULL, 1091592Srgrimes NFSV2PROC_GETATTR, 1101592Srgrimes NFSV2PROC_SETATTR, 1111592Srgrimes NFSV2PROC_LOOKUP, 1121592Srgrimes NFSV2PROC_NOOP, 11327074Ssteve NFSV2PROC_READLINK, 1141592Srgrimes NFSV2PROC_READ, 1151592Srgrimes NFSV2PROC_WRITE, 1161592Srgrimes NFSV2PROC_CREATE, 1171592Srgrimes NFSV2PROC_MKDIR, 1181592Srgrimes NFSV2PROC_SYMLINK, 1191592Srgrimes NFSV2PROC_CREATE, 1201592Srgrimes NFSV2PROC_REMOVE, 1211592Srgrimes NFSV2PROC_RMDIR, 1221592Srgrimes NFSV2PROC_RENAME, 1231592Srgrimes NFSV2PROC_LINK, 1241592Srgrimes NFSV2PROC_READDIR, 1251592Srgrimes NFSV2PROC_NOOP, 1261592Srgrimes NFSV2PROC_STATFS, 1271592Srgrimes NFSV2PROC_NOOP, 1281592Srgrimes NFSV2PROC_NOOP, 1291592Srgrimes NFSV2PROC_NOOP, 1301592Srgrimes NFSV2PROC_NOOP, 1311592Srgrimes}; 1321592Srgrimes 1331592SrgrimesLIST_HEAD(nfsnodehashhead, nfsnode); 1341592Srgrimes 1351592Srgrimes/* 1361592Srgrimes * Create the header for an rpc request packet 1371592Srgrimes * The hsiz is the size of the rest of the nfs request header. 1381592Srgrimes * (just used to decide if a cluster is a good idea) 1391592Srgrimes */ 1401592Srgrimesstruct mbuf * 1411592Srgrimesnfsm_reqhead(struct vnode *vp, u_long procid, int hsiz) 1421592Srgrimes{ 1431592Srgrimes struct mbuf *mb; 1441592Srgrimes 1451592Srgrimes MGET(mb, M_TRYWAIT, MT_DATA); 1461592Srgrimes if (hsiz >= MINCLSIZE) 1471592Srgrimes MCLGET(mb, M_TRYWAIT); 1481592Srgrimes mb->m_len = 0; 1491592Srgrimes return (mb); 1501592Srgrimes} 1511592Srgrimes 1521592Srgrimes/* 1531592Srgrimes * Build the RPC header and fill in the authorization info. 1541592Srgrimes * The authorization string argument is only used when the credentials 1551592Srgrimes * come from outside of the kernel. 1561592Srgrimes * Returns the head of the mbuf list. 1571592Srgrimes */ 1581592Srgrimesstruct mbuf * 1591592Srgrimesnfsm_rpchead(struct ucred *cr, int nmflag, int procid, int auth_type, 1601592Srgrimes int auth_len, struct mbuf *mrest, int mrest_len, struct mbuf **mbp, 1611592Srgrimes u_int32_t *xidp) 1621592Srgrimes{ 1631592Srgrimes struct mbuf *mb; 1641592Srgrimes u_int32_t *tl; 1651592Srgrimes caddr_t bpos; 1661592Srgrimes int i; 1671592Srgrimes struct mbuf *mreq; 1681592Srgrimes int grpsiz, authsiz; 1691592Srgrimes 1701592Srgrimes authsiz = nfsm_rndup(auth_len); 1711592Srgrimes MGETHDR(mb, M_TRYWAIT, MT_DATA); 1721592Srgrimes if ((authsiz + 10 * NFSX_UNSIGNED) >= MINCLSIZE) { 1731592Srgrimes MCLGET(mb, M_TRYWAIT); 17490377Simp } else if ((authsiz + 10 * NFSX_UNSIGNED) < MHLEN) { 1751592Srgrimes MH_ALIGN(mb, authsiz + 10 * NFSX_UNSIGNED); 17627079Ssteve } else { 17727079Ssteve MH_ALIGN(mb, 8 * NFSX_UNSIGNED); 17827079Ssteve } 1791592Srgrimes mb->m_len = 0; 1801592Srgrimes mreq = mb; 1811592Srgrimes bpos = mtod(mb, caddr_t); 1821592Srgrimes 1831592Srgrimes /* 1841592Srgrimes * First the RPC header. 1851592Srgrimes */ 1861592Srgrimes tl = nfsm_build(u_int32_t *, 8 * NFSX_UNSIGNED); 1871592Srgrimes 1881592Srgrimes /* Get a pretty random xid to start with */ 18927074Ssteve if (!nfs_xid) 1901592Srgrimes nfs_xid = random(); 1911592Srgrimes /* 1921592Srgrimes * Skip zero xid if it should ever happen. 1931592Srgrimes */ 1941592Srgrimes if (++nfs_xid == 0) 1951592Srgrimes nfs_xid++; 1961592Srgrimes 1971592Srgrimes *tl++ = *xidp = txdr_unsigned(nfs_xid); 1981592Srgrimes *tl++ = rpc_call; 1991592Srgrimes *tl++ = rpc_vers; 2001592Srgrimes *tl++ = txdr_unsigned(NFS_PROG); 2011592Srgrimes if (nmflag & NFSMNT_NFSV3) { 2021592Srgrimes *tl++ = txdr_unsigned(NFS_VER3); 2031592Srgrimes *tl++ = txdr_unsigned(procid); 2041592Srgrimes } else { 2051592Srgrimes *tl++ = txdr_unsigned(NFS_VER2); 2061592Srgrimes *tl++ = txdr_unsigned(nfsv2_procid[procid]); 2071592Srgrimes } 2081592Srgrimes 2091592Srgrimes /* 2101592Srgrimes * And then the authorization cred. 2111592Srgrimes */ 2121592Srgrimes *tl++ = txdr_unsigned(auth_type); 2131592Srgrimes *tl = txdr_unsigned(authsiz); 2141592Srgrimes switch (auth_type) { 2151592Srgrimes case RPCAUTH_UNIX: 2161592Srgrimes tl = nfsm_build(u_int32_t *, auth_len); 2171592Srgrimes *tl++ = 0; /* stamp ?? */ 2181592Srgrimes *tl++ = 0; /* NULL hostname */ 2191592Srgrimes *tl++ = txdr_unsigned(cr->cr_uid); 2201592Srgrimes *tl++ = txdr_unsigned(cr->cr_groups[0]); 2211592Srgrimes grpsiz = (auth_len >> 2) - 5; 2221592Srgrimes *tl++ = txdr_unsigned(grpsiz); 2231592Srgrimes for (i = 1; i <= grpsiz; i++) 2241592Srgrimes *tl++ = txdr_unsigned(cr->cr_groups[i]); 22590377Simp break; 2261592Srgrimes } 22727079Ssteve 22827079Ssteve /* 22927079Ssteve * And the verifier... 23027079Ssteve */ 2311592Srgrimes tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED); 2321592Srgrimes *tl++ = txdr_unsigned(RPCAUTH_NULL); 2331592Srgrimes *tl = 0; 2341592Srgrimes mb->m_next = mrest; 2351592Srgrimes mreq->m_pkthdr.len = authsiz + 10 * NFSX_UNSIGNED + mrest_len; 2361592Srgrimes mreq->m_pkthdr.rcvif = (struct ifnet *)0; 2371592Srgrimes *mbp = mb; 2381592Srgrimes return (mreq); 2391592Srgrimes} 2401592Srgrimes 2411592Srgrimes/* 24227074Ssteve * copies a uio scatter/gather list to an mbuf chain. 2431592Srgrimes * NOTE: can ony handle iovcnt == 1 2441592Srgrimes */ 2451592Srgrimesint 2461592Srgrimesnfsm_uiotombuf(struct uio *uiop, struct mbuf **mq, int siz, caddr_t *bpos) 2471592Srgrimes{ 2481592Srgrimes char *uiocp; 2491592Srgrimes struct mbuf *mp, *mp2; 2501592Srgrimes int xfer, left, mlen; 2511592Srgrimes int uiosiz, clflg, rem; 2521592Srgrimes char *cp; 2531592Srgrimes 2541592Srgrimes#ifdef DIAGNOSTIC 2551592Srgrimes if (uiop->uio_iovcnt != 1) 2561592Srgrimes panic("nfsm_uiotombuf: iovcnt != 1"); 2571592Srgrimes#endif 2581592Srgrimes 2591592Srgrimes if (siz > MLEN) /* or should it >= MCLBYTES ?? */ 2601592Srgrimes clflg = 1; 2611592Srgrimes else 2621592Srgrimes clflg = 0; 2631592Srgrimes rem = nfsm_rndup(siz)-siz; 2641592Srgrimes mp = mp2 = *mq; 2651592Srgrimes while (siz > 0) { 2661592Srgrimes left = uiop->uio_iov->iov_len; 2671592Srgrimes uiocp = uiop->uio_iov->iov_base; 2681592Srgrimes if (left > siz) 2691592Srgrimes left = siz; 2701592Srgrimes uiosiz = left; 2711592Srgrimes while (left > 0) { 2721592Srgrimes mlen = M_TRAILINGSPACE(mp); 2731592Srgrimes if (mlen == 0) { 2741592Srgrimes MGET(mp, M_TRYWAIT, MT_DATA); 2751592Srgrimes if (clflg) 2761592Srgrimes MCLGET(mp, M_TRYWAIT); 2771592Srgrimes mp->m_len = 0; 2781592Srgrimes mp2->m_next = mp; 2791592Srgrimes mp2 = mp; 2801592Srgrimes mlen = M_TRAILINGSPACE(mp); 2811592Srgrimes } 2821592Srgrimes xfer = (left > mlen) ? mlen : left; 2831592Srgrimes#ifdef notdef 2841592Srgrimes /* Not Yet.. */ 28590377Simp if (uiop->uio_iov->iov_op != NULL) 2861592Srgrimes (*(uiop->uio_iov->iov_op)) 2871592Srgrimes (uiocp, mtod(mp, caddr_t)+mp->m_len, xfer); 2881592Srgrimes else 2891592Srgrimes#endif 29027079Ssteve if (uiop->uio_segflg == UIO_SYSSPACE) 29127079Ssteve bcopy(uiocp, mtod(mp, caddr_t)+mp->m_len, xfer); 29227079Ssteve else 2931592Srgrimes copyin(uiocp, mtod(mp, caddr_t)+mp->m_len, xfer); 2941592Srgrimes mp->m_len += xfer; 2951592Srgrimes left -= xfer; 2961592Srgrimes uiocp += xfer; 2971592Srgrimes uiop->uio_offset += xfer; 2981592Srgrimes uiop->uio_resid -= xfer; 2991592Srgrimes } 3001592Srgrimes uiop->uio_iov->iov_base += uiosiz; 3011592Srgrimes uiop->uio_iov->iov_len -= uiosiz; 3021592Srgrimes siz -= uiosiz; 3031592Srgrimes } 3041592Srgrimes if (rem > 0) { 3051592Srgrimes if (rem > M_TRAILINGSPACE(mp)) { 3061592Srgrimes MGET(mp, M_TRYWAIT, MT_DATA); 3071592Srgrimes mp->m_len = 0; 3081592Srgrimes mp2->m_next = mp; 3091592Srgrimes } 3101592Srgrimes cp = mtod(mp, caddr_t)+mp->m_len; 31127074Ssteve for (left = 0; left < rem; left++) 31227074Ssteve *cp++ = '\0'; 3131592Srgrimes mp->m_len += rem; 3141592Srgrimes *bpos = cp; 3151592Srgrimes } else 3161592Srgrimes *bpos = mtod(mp, caddr_t)+mp->m_len; 3171592Srgrimes *mq = mp; 3181592Srgrimes return (0); 3191592Srgrimes} 3201592Srgrimes 3211592Srgrimes/* 3221592Srgrimes * Copy a string into mbufs for the hard cases... 3231592Srgrimes */ 3241592Srgrimesint 3251592Srgrimesnfsm_strtmbuf(struct mbuf **mb, char **bpos, const char *cp, long siz) 3261592Srgrimes{ 3271592Srgrimes struct mbuf *m1 = NULL, *m2; 3281592Srgrimes long left, xfer, len, tlen; 3291592Srgrimes u_int32_t *tl; 3301592Srgrimes int putsize; 3311592Srgrimes 3321592Srgrimes putsize = 1; 33327079Ssteve m2 = *mb; 3341592Srgrimes left = M_TRAILINGSPACE(m2); 3351592Srgrimes if (left > 0) { 3361592Srgrimes tl = ((u_int32_t *)(*bpos)); 3371592Srgrimes *tl++ = txdr_unsigned(siz); 3381592Srgrimes putsize = 0; 3391592Srgrimes left -= NFSX_UNSIGNED; 3401592Srgrimes m2->m_len += NFSX_UNSIGNED; 3411592Srgrimes if (left > 0) { 3421592Srgrimes bcopy(cp, (caddr_t) tl, left); 3431592Srgrimes siz -= left; 3441592Srgrimes cp += left; 3451592Srgrimes m2->m_len += left; 3461592Srgrimes left = 0; 3471592Srgrimes } 3481592Srgrimes } 3491592Srgrimes /* Loop around adding mbufs */ 3501592Srgrimes while (siz > 0) { 3511592Srgrimes MGET(m1, M_TRYWAIT, MT_DATA); 3521592Srgrimes if (siz > MLEN) 3531592Srgrimes MCLGET(m1, M_TRYWAIT); 3541592Srgrimes m1->m_len = NFSMSIZ(m1); 3551592Srgrimes m2->m_next = m1; 3561592Srgrimes m2 = m1; 3571592Srgrimes tl = mtod(m1, u_int32_t *); 3581592Srgrimes tlen = 0; 3591592Srgrimes if (putsize) { 3601592Srgrimes *tl++ = txdr_unsigned(siz); 3611592Srgrimes m1->m_len -= NFSX_UNSIGNED; 3621592Srgrimes tlen = NFSX_UNSIGNED; 3631592Srgrimes putsize = 0; 3641592Srgrimes } 3651592Srgrimes if (siz < m1->m_len) { 3661592Srgrimes len = nfsm_rndup(siz); 3671592Srgrimes xfer = siz; 3681592Srgrimes if (xfer < len) 3691592Srgrimes *(tl+(xfer>>2)) = 0; 3701592Srgrimes } else { 3711592Srgrimes xfer = len = m1->m_len; 3721592Srgrimes } 3731592Srgrimes bcopy(cp, (caddr_t) tl, xfer); 3741592Srgrimes m1->m_len = len+tlen; 3751592Srgrimes siz -= xfer; 3761592Srgrimes cp += xfer; 3771592Srgrimes } 3781592Srgrimes *mb = m1; 3791592Srgrimes *bpos = mtod(m1, caddr_t)+m1->m_len; 3801592Srgrimes return (0); 3811592Srgrimes} 3821592Srgrimes 3831592Srgrimes/* 3841592Srgrimes * Called once to initialize data structures... 3851592Srgrimes */ 3861592Srgrimesint 3871592Srgrimesnfs_init(struct vfsconf *vfsp) 3881592Srgrimes{ 3891592Srgrimes int i; 3901592Srgrimes 39190377Simp nfsmount_zone = uma_zcreate("NFSMOUNT", sizeof(struct nfsmount), 3921592Srgrimes NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 39327074Ssteve rpc_vers = txdr_unsigned(RPC_VER2); 3941592Srgrimes rpc_call = txdr_unsigned(RPC_CALL); 39527079Ssteve rpc_reply = txdr_unsigned(RPC_REPLY); 39627079Ssteve rpc_msgdenied = txdr_unsigned(RPC_MSGDENIED); 3971592Srgrimes rpc_msgaccepted = txdr_unsigned(RPC_MSGACCEPTED); 3981592Srgrimes rpc_mismatch = txdr_unsigned(RPC_MISMATCH); 3991592Srgrimes rpc_autherr = txdr_unsigned(RPC_AUTHERR); 400229780Suqs rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX); 4011592Srgrimes nfs_true = txdr_unsigned(TRUE); 4021592Srgrimes nfs_false = txdr_unsigned(FALSE); 4031592Srgrimes nfs_xdrneg1 = txdr_unsigned(-1); 4041592Srgrimes nfs_ticks = (hz * NFS_TICKINTVL + 500) / 1000; 4051592Srgrimes if (nfs_ticks < 1) 4061592Srgrimes nfs_ticks = 1; 4071592Srgrimes /* Ensure async daemons disabled */ 4081592Srgrimes for (i = 0; i < NFS_MAXASYNCDAEMON; i++) { 4091592Srgrimes nfs_iodwant[i] = (struct proc *)0; 4101592Srgrimes nfs_iodmount[i] = (struct nfsmount *)0; 4111592Srgrimes } 4121592Srgrimes nfs_nhinit(); /* Init the nfsnode table */ 4131592Srgrimes 4141592Srgrimes /* 4151592Srgrimes * Initialize reply list and start timer 4161592Srgrimes */ 4171592Srgrimes TAILQ_INIT(&nfs_reqq); 4181592Srgrimes 4191592Srgrimes nfs_timer(0); 4201592Srgrimes 4211592Srgrimes nfs_prev_nfsclnt_sy_narg = sysent[SYS_nfsclnt].sy_narg; 4221592Srgrimes sysent[SYS_nfsclnt].sy_narg = 2; 42327074Ssteve nfs_prev_nfsclnt_sy_call = sysent[SYS_nfsclnt].sy_call; 42427074Ssteve sysent[SYS_nfsclnt].sy_call = (sy_call_t *)nfsclnt; 42527074Ssteve 4261592Srgrimes nfs_pbuf_freecnt = nswbuf / 2 + 1; 4271592Srgrimes 4281592Srgrimes return (0); 4291592Srgrimes} 4301592Srgrimes 4311592Srgrimesint 4321592Srgrimesnfs_uninit(struct vfsconf *vfsp) 4331592Srgrimes{ 4341592Srgrimes 4351592Srgrimes untimeout(nfs_timer, (void *)NULL, nfs_timer_handle); 4361592Srgrimes sysent[SYS_nfsclnt].sy_narg = nfs_prev_nfsclnt_sy_narg; 4371592Srgrimes sysent[SYS_nfsclnt].sy_call = nfs_prev_nfsclnt_sy_call; 4381592Srgrimes return (0); 4391592Srgrimes} 4401592Srgrimes 44127074Ssteve/* 44227074Ssteve * Attribute cache routines. 4431592Srgrimes * nfs_loadattrcache() - loads or updates the cache contents from attributes 4441592Srgrimes * that are on the mbuf list 4451592Srgrimes * nfs_getattrcache() - returns valid attributes if found in cache, returns 4461592Srgrimes * error otherwise 4471592Srgrimes */ 44868895Skris 4491592Srgrimes/* 4501592Srgrimes * Load the attribute cache (that lives in the nfsnode entry) with 4511592Srgrimes * the values on the mbuf list and 4521592Srgrimes * Iff vap not NULL 4531592Srgrimes * copy the attributes to *vaper 4541592Srgrimes */ 4551592Srgrimesint 4561592Srgrimesnfs_loadattrcache(struct vnode **vpp, struct mbuf **mdp, caddr_t *dposp, 4571592Srgrimes struct vattr *vaper, int dontshrink) 4581592Srgrimes{ 4591592Srgrimes struct vnode *vp = *vpp; 46027074Ssteve struct vattr *vap; 4611592Srgrimes struct nfs_fattr *fp; 4621592Srgrimes struct nfsnode *np; 4631592Srgrimes int32_t t1; 4641592Srgrimes caddr_t cp2; 4651592Srgrimes int rdev; 4661592Srgrimes struct mbuf *md; 4671592Srgrimes enum vtype vtyp; 4681592Srgrimes u_short vmode; 4691592Srgrimes struct timespec mtime; 4701592Srgrimes int v3 = NFS_ISV3(vp); 4711592Srgrimes 4721592Srgrimes md = *mdp; 4731592Srgrimes t1 = (mtod(md, caddr_t) + md->m_len) - *dposp; 4741592Srgrimes cp2 = nfsm_disct(mdp, dposp, NFSX_FATTR(v3), t1); 4751592Srgrimes if (cp2 == NULL) 4761592Srgrimes return EBADRPC; 4771592Srgrimes fp = (struct nfs_fattr *)cp2; 4781592Srgrimes if (v3) { 4791592Srgrimes vtyp = nfsv3tov_type(fp->fa_type); 4801592Srgrimes vmode = fxdr_unsigned(u_short, fp->fa_mode); 4811592Srgrimes rdev = makeudev(fxdr_unsigned(int, fp->fa3_rdev.specdata1), 4821592Srgrimes fxdr_unsigned(int, fp->fa3_rdev.specdata2)); 4831592Srgrimes fxdr_nfsv3time(&fp->fa3_mtime, &mtime); 4841592Srgrimes } else { 4851592Srgrimes vtyp = nfsv2tov_type(fp->fa_type); 4861592Srgrimes vmode = fxdr_unsigned(u_short, fp->fa_mode); 4871592Srgrimes /* 4881592Srgrimes * XXX 4891592Srgrimes * 4901592Srgrimes * The duplicate information returned in fa_type and fa_mode 4911592Srgrimes * is an ambiguity in the NFS version 2 protocol. 4921592Srgrimes * 4931592Srgrimes * VREG should be taken literally as a regular file. If a 4941592Srgrimes * server intents to return some type information differently 4951592Srgrimes * in the upper bits of the mode field (e.g. for sockets, or 4961592Srgrimes * FIFOs), NFSv2 mandates fa_type to be VNON. Anyway, we 4971592Srgrimes * leave the examination of the mode bits even in the VREG 4981592Srgrimes * case to avoid breakage for bogus servers, but we make sure 4991592Srgrimes * that there are actually type bits set in the upper part of 5001592Srgrimes * fa_mode (and failing that, trust the va_type field). 5011592Srgrimes * 5021592Srgrimes * NFSv3 cleared the issue, and requires fa_mode to not 5031592Srgrimes * contain any type information (while also introduing sockets 5041592Srgrimes * and FIFOs for fa_type). 5051592Srgrimes */ 5061592Srgrimes if (vtyp == VNON || (vtyp == VREG && (vmode & S_IFMT) != 0)) 5071592Srgrimes vtyp = IFTOVT(vmode); 50890377Simp rdev = fxdr_unsigned(int32_t, fp->fa2_rdev); 5091592Srgrimes fxdr_nfsv2time(&fp->fa2_mtime, &mtime); 5101592Srgrimes 5111592Srgrimes /* 5121592Srgrimes * Really ugly NFSv2 kludge. 5131592Srgrimes */ 514229780Suqs if (vtyp == VCHR && rdev == 0xffffffff) 5151592Srgrimes vtyp = VFIFO; 5161592Srgrimes } 5171592Srgrimes 5181592Srgrimes /* 5191592Srgrimes * If v_type == VNON it is a new node, so fill in the v_type, 5201592Srgrimes * n_mtime fields. Check to see if it represents a special 5211592Srgrimes * device, and if so, check for a possible alias. Once the 5221592Srgrimes * correct vnode has been obtained, fill in the rest of the 5231592Srgrimes * information. 5241592Srgrimes */ 5251592Srgrimes np = VTONFS(vp); 5261592Srgrimes if (vp->v_type != vtyp) { 52727074Ssteve vp->v_type = vtyp; 52827074Ssteve if (vp->v_type == VFIFO) { 52927074Ssteve vp->v_op = fifo_nfsv2nodeop_p; 5301592Srgrimes } 5311592Srgrimes if (vp->v_type == VCHR || vp->v_type == VBLK) { 5321592Srgrimes vp->v_op = spec_nfsv2nodeop_p; 5331592Srgrimes vp = addaliasu(vp, rdev); 5341592Srgrimes np->n_vnode = vp; 5351592Srgrimes } 5361592Srgrimes np->n_mtime = mtime.tv_sec; 5371592Srgrimes } 5381592Srgrimes vap = &np->n_vattr; 5391592Srgrimes vap->va_type = vtyp; 5401592Srgrimes vap->va_mode = (vmode & 07777); 5411592Srgrimes vap->va_rdev = rdev; 5421592Srgrimes vap->va_mtime = mtime; 5431592Srgrimes vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0]; 5441592Srgrimes if (v3) { 5451592Srgrimes vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink); 5461592Srgrimes vap->va_uid = fxdr_unsigned(uid_t, fp->fa_uid); 5471592Srgrimes vap->va_gid = fxdr_unsigned(gid_t, fp->fa_gid); 5481592Srgrimes vap->va_size = fxdr_hyper(&fp->fa3_size); 5491592Srgrimes vap->va_blocksize = NFS_FABLKSIZE; 5501592Srgrimes vap->va_bytes = fxdr_hyper(&fp->fa3_used); 5511592Srgrimes vap->va_fileid = fxdr_unsigned(int32_t, 5521592Srgrimes fp->fa3_fileid.nfsuquad[1]); 5531592Srgrimes fxdr_nfsv3time(&fp->fa3_atime, &vap->va_atime); 5541592Srgrimes fxdr_nfsv3time(&fp->fa3_ctime, &vap->va_ctime); 55590377Simp vap->va_flags = 0; 5561592Srgrimes vap->va_filerev = 0; 5571592Srgrimes } else { 5581592Srgrimes vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink); 5591592Srgrimes vap->va_uid = fxdr_unsigned(uid_t, fp->fa_uid); 5601592Srgrimes vap->va_gid = fxdr_unsigned(gid_t, fp->fa_gid); 56127079Ssteve vap->va_size = fxdr_unsigned(u_int32_t, fp->fa2_size); 56227079Ssteve vap->va_blocksize = fxdr_unsigned(int32_t, fp->fa2_blocksize); 56327074Ssteve vap->va_bytes = (u_quad_t)fxdr_unsigned(int32_t, fp->fa2_blocks) 5641592Srgrimes * NFS_FABLKSIZE; 5651592Srgrimes vap->va_fileid = fxdr_unsigned(int32_t, fp->fa2_fileid); 5661592Srgrimes fxdr_nfsv2time(&fp->fa2_atime, &vap->va_atime); 5671592Srgrimes vap->va_flags = 0; 56827074Ssteve vap->va_ctime.tv_sec = fxdr_unsigned(u_int32_t, 56927074Ssteve fp->fa2_ctime.nfsv2_sec); 5701592Srgrimes vap->va_ctime.tv_nsec = 0; 5711592Srgrimes vap->va_gen = fxdr_unsigned(u_int32_t, fp->fa2_ctime.nfsv2_usec); 5721592Srgrimes vap->va_filerev = 0; 5731592Srgrimes } 574239991Sed np->n_attrstamp = time_second; 5751592Srgrimes if (vap->va_size != np->n_size) { 5761592Srgrimes if (vap->va_type == VREG) { 5771592Srgrimes if (dontshrink && vap->va_size < np->n_size) { 5781592Srgrimes /* 5791592Srgrimes * We've been told not to shrink the file; 5801592Srgrimes * zero np->n_attrstamp to indicate that 5811592Srgrimes * the attributes are stale. 5821592Srgrimes */ 5831592Srgrimes vap->va_size = np->n_size; 584 np->n_attrstamp = 0; 585 } else if (np->n_flag & NMODIFIED) { 586 if (vap->va_size < np->n_size) 587 vap->va_size = np->n_size; 588 else 589 np->n_size = vap->va_size; 590 } else { 591 np->n_size = vap->va_size; 592 } 593 vnode_pager_setsize(vp, np->n_size); 594 } else { 595 np->n_size = vap->va_size; 596 } 597 } 598 if (vaper != NULL) { 599 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(*vap)); 600 if (np->n_flag & NCHG) { 601 if (np->n_flag & NACC) 602 vaper->va_atime = np->n_atim; 603 if (np->n_flag & NUPD) 604 vaper->va_mtime = np->n_mtim; 605 } 606 } 607 return (0); 608} 609 610#ifdef NFS_ACDEBUG 611#include <sys/sysctl.h> 612SYSCTL_DECL(_vfs_nfs); 613static int nfs_acdebug; 614SYSCTL_INT(_vfs_nfs, OID_AUTO, acdebug, CTLFLAG_RW, &nfs_acdebug, 0, ""); 615#endif 616 617/* 618 * Check the time stamp 619 * If the cache is valid, copy contents to *vap and return 0 620 * otherwise return an error 621 */ 622int 623nfs_getattrcache(struct vnode *vp, struct vattr *vaper) 624{ 625 struct nfsnode *np; 626 struct vattr *vap; 627 struct nfsmount *nmp; 628 int timeo; 629 630 np = VTONFS(vp); 631 vap = &np->n_vattr; 632 nmp = VFSTONFS(vp->v_mount); 633 /* XXX n_mtime doesn't seem to be updated on a miss-and-reload */ 634 timeo = (time_second - np->n_mtime) / 10; 635 636#ifdef NFS_ACDEBUG 637 if (nfs_acdebug>1) 638 printf("nfs_getattrcache: initial timeo = %d\n", timeo); 639#endif 640 641 if (vap->va_type == VDIR) { 642 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acdirmin) 643 timeo = nmp->nm_acdirmin; 644 else if (timeo > nmp->nm_acdirmax) 645 timeo = nmp->nm_acdirmax; 646 } else { 647 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acregmin) 648 timeo = nmp->nm_acregmin; 649 else if (timeo > nmp->nm_acregmax) 650 timeo = nmp->nm_acregmax; 651 } 652 653#ifdef NFS_ACDEBUG 654 if (nfs_acdebug > 2) 655 printf("acregmin %d; acregmax %d; acdirmin %d; acdirmax %d\n", 656 nmp->nm_acregmin, nmp->nm_acregmax, 657 nmp->nm_acdirmin, nmp->nm_acdirmax); 658 659 if (nfs_acdebug) 660 printf("nfs_getattrcache: age = %d; final timeo = %d\n", 661 (time_second - np->n_attrstamp), timeo); 662#endif 663 664 if ((time_second - np->n_attrstamp) >= timeo) { 665 nfsstats.attrcache_misses++; 666 return (ENOENT); 667 } 668 nfsstats.attrcache_hits++; 669 if (vap->va_size != np->n_size) { 670 if (vap->va_type == VREG) { 671 if (np->n_flag & NMODIFIED) { 672 if (vap->va_size < np->n_size) 673 vap->va_size = np->n_size; 674 else 675 np->n_size = vap->va_size; 676 } else { 677 np->n_size = vap->va_size; 678 } 679 vnode_pager_setsize(vp, np->n_size); 680 } else { 681 np->n_size = vap->va_size; 682 } 683 } 684 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(struct vattr)); 685 if (np->n_flag & NCHG) { 686 if (np->n_flag & NACC) 687 vaper->va_atime = np->n_atim; 688 if (np->n_flag & NUPD) 689 vaper->va_mtime = np->n_mtim; 690 } 691 return (0); 692} 693 694static nfsuint64 nfs_nullcookie = { { 0, 0 } }; 695/* 696 * This function finds the directory cookie that corresponds to the 697 * logical byte offset given. 698 */ 699nfsuint64 * 700nfs_getcookie(struct nfsnode *np, off_t off, int add) 701{ 702 struct nfsdmap *dp, *dp2; 703 int pos; 704 705 pos = (uoff_t)off / NFS_DIRBLKSIZ; 706 if (pos == 0 || off < 0) { 707#ifdef DIAGNOSTIC 708 if (add) 709 panic("nfs getcookie add at <= 0"); 710#endif 711 return (&nfs_nullcookie); 712 } 713 pos--; 714 dp = LIST_FIRST(&np->n_cookies); 715 if (!dp) { 716 if (add) { 717 MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap), 718 M_NFSDIROFF, M_WAITOK); 719 dp->ndm_eocookie = 0; 720 LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list); 721 } else 722 return ((nfsuint64 *)0); 723 } 724 while (pos >= NFSNUMCOOKIES) { 725 pos -= NFSNUMCOOKIES; 726 if (LIST_NEXT(dp, ndm_list)) { 727 if (!add && dp->ndm_eocookie < NFSNUMCOOKIES && 728 pos >= dp->ndm_eocookie) 729 return ((nfsuint64 *)0); 730 dp = LIST_NEXT(dp, ndm_list); 731 } else if (add) { 732 MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap), 733 M_NFSDIROFF, M_WAITOK); 734 dp2->ndm_eocookie = 0; 735 LIST_INSERT_AFTER(dp, dp2, ndm_list); 736 dp = dp2; 737 } else 738 return ((nfsuint64 *)0); 739 } 740 if (pos >= dp->ndm_eocookie) { 741 if (add) 742 dp->ndm_eocookie = pos + 1; 743 else 744 return ((nfsuint64 *)0); 745 } 746 return (&dp->ndm_cookies[pos]); 747} 748 749/* 750 * Invalidate cached directory information, except for the actual directory 751 * blocks (which are invalidated separately). 752 * Done mainly to avoid the use of stale offset cookies. 753 */ 754void 755nfs_invaldir(struct vnode *vp) 756{ 757 struct nfsnode *np = VTONFS(vp); 758 759#ifdef DIAGNOSTIC 760 if (vp->v_type != VDIR) 761 panic("nfs: invaldir not dir"); 762#endif 763 np->n_direofoffset = 0; 764 np->n_cookieverf.nfsuquad[0] = 0; 765 np->n_cookieverf.nfsuquad[1] = 0; 766 if (LIST_FIRST(&np->n_cookies)) 767 LIST_FIRST(&np->n_cookies)->ndm_eocookie = 0; 768} 769 770/* 771 * The write verifier has changed (probably due to a server reboot), so all 772 * B_NEEDCOMMIT blocks will have to be written again. Since they are on the 773 * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT 774 * and B_CLUSTEROK flags. Once done the new write verifier can be set for the 775 * mount point. 776 * 777 * B_CLUSTEROK must be cleared along with B_NEEDCOMMIT because stage 1 data 778 * writes are not clusterable. 779 */ 780void 781nfs_clearcommit(struct mount *mp) 782{ 783 struct vnode *vp, *nvp; 784 struct buf *bp, *nbp; 785 int s; 786 787 GIANT_REQUIRED; 788 789 s = splbio(); 790 mtx_lock(&mntvnode_mtx); 791loop: 792 for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp; vp = nvp) { 793 if (vp->v_mount != mp) /* Paranoia */ 794 goto loop; 795 nvp = TAILQ_NEXT(vp, v_nmntvnodes); 796 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { 797 nbp = TAILQ_NEXT(bp, b_vnbufs); 798 if (BUF_REFCNT(bp) == 0 && 799 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) 800 == (B_DELWRI | B_NEEDCOMMIT)) 801 bp->b_flags &= ~(B_NEEDCOMMIT | B_CLUSTEROK); 802 } 803 } 804 mtx_unlock(&mntvnode_mtx); 805 splx(s); 806} 807 808/* 809 * Helper functions for former macros. Some of these should be 810 * moved to their callers. 811 */ 812 813int 814nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f, 815 struct mbuf **md, caddr_t *dpos) 816{ 817 struct nfsnode *ttnp; 818 struct vnode *ttvp; 819 nfsfh_t *ttfhp; 820 u_int32_t *tl; 821 int ttfhsize; 822 int t1; 823 824 if (v3) { 825 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos); 826 if (tl == NULL) 827 return EBADRPC; 828 *f = fxdr_unsigned(int, *tl); 829 } else 830 *f = 1; 831 if (*f) { 832 t1 = nfsm_getfh_xx(&ttfhp, &ttfhsize, (v3), md, dpos); 833 if (t1 != 0) 834 return t1; 835 t1 = nfs_nget(d->v_mount, ttfhp, ttfhsize, &ttnp); 836 if (t1 != 0) 837 return t1; 838 *v = NFSTOV(ttnp); 839 } 840 if (v3) { 841 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos); 842 if (tl == NULL) 843 return EBADRPC; 844 if (*f) 845 *f = fxdr_unsigned(int, *tl); 846 else if (fxdr_unsigned(int, *tl)) 847 nfsm_adv_xx(NFSX_V3FATTR, md, dpos); 848 } 849 if (*f) { 850 ttvp = *v; 851 t1 = nfs_loadattrcache(&ttvp, md, dpos, (struct vattr *)0, 0); 852 if (t1) 853 return t1; 854 *v = ttvp; 855 } 856 return 0; 857} 858 859int 860nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md, caddr_t *dpos) 861{ 862 u_int32_t *tl; 863 864 if (v3) { 865 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos); 866 if (tl == NULL) 867 return EBADRPC; 868 *s = fxdr_unsigned(int, *tl); 869 if (*s <= 0 || *s > NFSX_V3FHMAX) 870 return EBADRPC; 871 } else 872 *s = NFSX_V2FH; 873 *f = nfsm_dissect_xx(nfsm_rndup(*s), md, dpos); 874 if (*f == NULL) 875 return EBADRPC; 876 else 877 return 0; 878} 879 880 881int 882nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md, 883 caddr_t *dpos) 884{ 885 int t1; 886 887 struct vnode *ttvp = *v; 888 t1 = nfs_loadattrcache(&ttvp, md, dpos, va, 0); 889 if (t1 != 0) 890 return t1; 891 *v = ttvp; 892 return 0; 893} 894 895int 896nfsm_postop_attr_xx(struct vnode **v, int *f, struct mbuf **md, 897 caddr_t *dpos) 898{ 899 u_int32_t *tl; 900 int t1; 901 902 struct vnode *ttvp = *v; 903 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos); 904 if (tl == NULL) 905 return EBADRPC; 906 *f = fxdr_unsigned(int, *tl); 907 if (*f != 0) { 908 t1 = nfs_loadattrcache(&ttvp, md, dpos, (struct vattr *)0, 1); 909 if (t1 != 0) { 910 *f = 0; 911 return t1; 912 } 913 *v = ttvp; 914 } 915 return 0; 916} 917 918int 919nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md, caddr_t *dpos) 920{ 921 u_int32_t *tl; 922 int ttattrf, ttretf = 0; 923 int t1; 924 925 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos); 926 if (tl == NULL) 927 return EBADRPC; 928 if (*tl == nfs_true) { 929 tl = nfsm_dissect_xx(6 * NFSX_UNSIGNED, md, dpos); 930 if (tl == NULL) 931 return EBADRPC; 932 if (*f) 933 ttretf = (VTONFS(*v)->n_mtime == 934 fxdr_unsigned(u_int32_t, *(tl + 2))); 935 } 936 t1 = nfsm_postop_attr_xx(v, &ttattrf, md, dpos); 937 if (t1) 938 return t1; 939 if (*f) 940 *f = ttretf; 941 else 942 *f = ttattrf; 943 return 0; 944} 945 946int 947nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb, caddr_t *bpos) 948{ 949 u_int32_t *tl; 950 int t1; 951 952 if (s > m) 953 return ENAMETOOLONG; 954 t1 = nfsm_rndup(s) + NFSX_UNSIGNED; 955 if (t1 <= M_TRAILINGSPACE(*mb)) { 956 tl = nfsm_build_xx(t1, mb, bpos); 957 *tl++ = txdr_unsigned(s); 958 *(tl + ((t1 >> 2) - 2)) = 0; 959 bcopy(a, tl, s); 960 } else { 961 t1 = nfsm_strtmbuf(mb, bpos, a, s); 962 if (t1 != 0) 963 return t1; 964 } 965 return 0; 966} 967 968int 969nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb, caddr_t *bpos) 970{ 971 u_int32_t *tl; 972 int t1; 973 caddr_t cp; 974 975 if (v3) { 976 t1 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; 977 if (t1 < M_TRAILINGSPACE(*mb)) { 978 tl = nfsm_build_xx(t1, mb, bpos); 979 *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); 980 *(tl + ((t1 >> 2) - 2)) = 0; 981 bcopy(VTONFS(v)->n_fhp, tl, VTONFS(v)->n_fhsize); 982 } else { 983 t1 = nfsm_strtmbuf(mb, bpos, 984 (const char *)VTONFS(v)->n_fhp, 985 VTONFS(v)->n_fhsize); 986 if (t1 != 0) 987 return t1; 988 } 989 } else { 990 cp = nfsm_build_xx(NFSX_V2FH, mb, bpos); 991 bcopy(VTONFS(v)->n_fhp, cp, NFSX_V2FH); 992 } 993 return 0; 994} 995 996void 997nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb, 998 caddr_t *bpos) 999{ 1000 u_int32_t *tl; 1001 1002 if (va->va_mode != (mode_t)VNOVAL) { 1003 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos); 1004 *tl++ = nfs_true; 1005 *tl = txdr_unsigned(va->va_mode); 1006 } else { 1007 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1008 *tl = nfs_false; 1009 } 1010 if (full && va->va_uid != (uid_t)VNOVAL) { 1011 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos); 1012 *tl++ = nfs_true; 1013 *tl = txdr_unsigned(va->va_uid); 1014 } else { 1015 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1016 *tl = nfs_false; 1017 } 1018 if (full && va->va_gid != (gid_t)VNOVAL) { 1019 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos); 1020 *tl++ = nfs_true; 1021 *tl = txdr_unsigned(va->va_gid); 1022 } else { 1023 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1024 *tl = nfs_false; 1025 } 1026 if (full && va->va_size != VNOVAL) { 1027 tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos); 1028 *tl++ = nfs_true; 1029 txdr_hyper(va->va_size, tl); 1030 } else { 1031 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1032 *tl = nfs_false; 1033 } 1034 if (va->va_atime.tv_sec != VNOVAL) { 1035 if (va->va_atime.tv_sec != time_second) { 1036 tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos); 1037 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); 1038 txdr_nfsv3time(&va->va_atime, tl); 1039 } else { 1040 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1041 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); 1042 } 1043 } else { 1044 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1045 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); 1046 } 1047 if (va->va_mtime.tv_sec != VNOVAL) { 1048 if (va->va_mtime.tv_sec != time_second) { 1049 tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos); 1050 *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); 1051 txdr_nfsv3time(&va->va_mtime, tl); 1052 } else { 1053 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1054 *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); 1055 } 1056 } else { 1057 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos); 1058 *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); 1059 } 1060} 1061