/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1989, 19934* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Rick Macklem at The University of Guelph.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#ifndef _NFSCLIENT_NFSNODE_H_35#define _NFSCLIENT_NFSNODE_H_3637#include <sys/_task.h>38#if !defined(_NFSCLIENT_NFS_H_) && !defined(_KERNEL)39#include <nfs/nfs.h>40#endif4142/*43* Silly rename structure that hangs off the nfsnode until the name44* can be removed by nfs_inactive()45*/46struct sillyrename {47struct task s_task;48struct ucred *s_cred;49struct vnode *s_dvp;50int (*s_removeit)(struct sillyrename *sp);51long s_namlen;52char s_name[32];53};5455/*56* This structure is used to save the logical directory offset to57* NFS cookie mappings.58* The mappings are stored in a list headed59* by n_cookies, as required.60* There is one mapping for each NFS_DIRBLKSIZ bytes of directory information61* stored in increasing logical offset byte order.62*/63#define NFSNUMCOOKIES 316465struct nfsdmap {66LIST_ENTRY(nfsdmap) ndm_list;67int ndm_eocookie;68union {69nfsuint64 ndmu3_cookies[NFSNUMCOOKIES];70uint64_t ndmu4_cookies[NFSNUMCOOKIES];71} ndm_un1;72};7374#define ndm_cookies ndm_un1.ndmu3_cookies75#define ndm4_cookies ndm_un1.ndmu4_cookies7677struct nfs_accesscache {78u_int32_t mode; /* ACCESS mode cache */79uid_t uid; /* credentials having mode */80time_t stamp; /* mode cache timestamp */81};8283/*84* The nfsnode is the nfs equivalent to ufs's inode. Any similarity85* is purely coincidental.86* There is a unique nfsnode allocated for each active file,87* each current directory, each mounted-on file, text file, and the root.88* An nfsnode is 'named' by its file handle. (nget/nfs_node.c)89* If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite90* type definitions), file handles of > 32 bytes should probably be split out91* into a separate malloc()'d data structure. (Reduce the size of nfsfh_t by92* changing the definition in nfsproto.h of NFS_SMALLFH.)93* NB: Hopefully the current order of the fields is such that everything will94* be well aligned and, therefore, tightly packed.95*/96struct nfsnode {97struct mtx n_mtx; /* Protects all of these members */98u_quad_t n_size; /* Current size of file */99u_quad_t n_brev; /* Modify rev when cached */100u_quad_t n_lrev; /* Modify rev for lease */101struct vattr n_vattr; /* Vnode attribute cache */102time_t n_attrstamp; /* Attr. cache timestamp */103struct nfs_accesscache n_accesscache[NFS_ACCESSCACHESIZE];104struct timespec n_mtime; /* Prev modify time. */105nfsfh_t *n_fhp; /* NFS File Handle */106struct vnode *n_vnode; /* associated vnode */107struct vnode *n_dvp; /* parent vnode */108int n_error; /* Save write error value */109union {110struct timespec nf_atim; /* Special file times */111nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */112u_char nd4_cookieverf[NFSX_V4VERF];113} n_un1;114union {115struct timespec nf_mtim;116off_t nd_direof; /* Dir. EOF offset cache */117} n_un2;118union {119struct sillyrename *nf_silly; /* Ptr to silly rename struct */120LIST_HEAD(, nfsdmap) nd_cook; /* cookies */121} n_un3;122short n_fhsize; /* size in bytes, of fh */123short n_flag; /* Flag for locking.. */124nfsfh_t n_fh; /* Small File Handle */125u_char *n_name; /* leaf name, for v4 OPEN op */126uint32_t n_namelen;127int n_directio_opens;128int n_directio_asyncwr;129struct ucred *n_writecred; /* Cred. for putpages */130};131132#define n_atim n_un1.nf_atim133#define n_mtim n_un2.nf_mtim134#define n_sillyrename n_un3.nf_silly135#define n_cookieverf n_un1.nd_cookieverf136#define n4_cookieverf n_un1.nd4_cookieverf137#define n_direofoffset n_un2.nd_direof138#define n_cookies n_un3.nd_cook139140/*141* Flags for n_flag142*/143#define NFSYNCWAIT 0x0002 /* fsync waiting for all directio async writes144to drain */145#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */146#define NWRITEERR 0x0008 /* Flag write errors so close will know */147/* 0x20, 0x40, 0x80 free */148#define NACC 0x0100 /* Special file accessed */149#define NUPD 0x0200 /* Special file updated */150#define NCHG 0x0400 /* Special file times changed */151#define NCREATED 0x0800 /* Opened by nfs_create() */152#define NTRUNCATE 0x1000 /* Opened by nfs_setattr() */153#define NSIZECHANGED 0x2000 /* File size has changed: need cache inval */154#define NNONCACHE 0x4000 /* Node marked as noncacheable */155#define NDIRCOOKIELK 0x8000 /* Lock to serialize access to directory cookies */156157/*158* Convert between nfsnode pointers and vnode pointers159*/160#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data)161#define NFSTOV(np) ((struct vnode *)(np)->n_vnode)162163#define NFS_TIMESPEC_COMPARE(T1, T2) (((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec))164165/*166* NFS iod threads can be in one of these two states once spawned.167* NFSIOD_NOT_AVAILABLE - Cannot be assigned an I/O operation at this time.168* NFSIOD_AVAILABLE - Available to be assigned an I/O operation.169*/170enum nfsiod_state {171NFSIOD_NOT_AVAILABLE = 0,172NFSIOD_AVAILABLE = 1,173};174175/*176* Queue head for nfsiod's177*/178extern TAILQ_HEAD(nfs_bufq, buf) nfs_bufq;179extern enum nfsiod_state nfs_iodwant[NFS_MAXASYNCDAEMON];180extern struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON];181182#if defined(_KERNEL)183184extern struct vop_vector nfs_fifoops;185extern struct vop_vector nfs_vnodeops;186extern struct buf_ops buf_ops_nfs;187188/*189* Prototypes for NFS vnode operations190*/191int nfs_getpages(struct vop_getpages_args *);192int nfs_putpages(struct vop_putpages_args *);193int nfs_write(struct vop_write_args *);194int nfs_inactive(struct vop_inactive_args *);195int nfs_reclaim(struct vop_reclaim_args *);196197/* other stuff */198int nfs_removeit(struct sillyrename *);199int nfs_nget(struct mount *, nfsfh_t *, int, struct nfsnode **, int flags);200nfsuint64 *nfs_getcookie(struct nfsnode *, off_t, int);201void nfs_invaldir(struct vnode *);202int nfs_upgrade_vnlock(struct vnode *vp);203void nfs_downgrade_vnlock(struct vnode *vp, int old_lock);204void nfs_printf(const char *fmt, ...);205206void nfs_dircookie_lock(struct nfsnode *np);207void nfs_dircookie_unlock(struct nfsnode *np);208209#endif /* _KERNEL */210211#endif212213214