1191783Srmacklem/*-
2191783Srmacklem * Copyright (c) 1989, 1993
3191783Srmacklem *	The Regents of the University of California.  All rights reserved.
4191783Srmacklem *
5191783Srmacklem * This code is derived from software contributed to Berkeley by
6191783Srmacklem * Rick Macklem at The University of Guelph.
7191783Srmacklem *
8191783Srmacklem * Redistribution and use in source and binary forms, with or without
9191783Srmacklem * modification, are permitted provided that the following conditions
10191783Srmacklem * are met:
11191783Srmacklem * 1. Redistributions of source code must retain the above copyright
12191783Srmacklem *    notice, this list of conditions and the following disclaimer.
13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright
14191783Srmacklem *    notice, this list of conditions and the following disclaimer in the
15191783Srmacklem *    documentation and/or other materials provided with the distribution.
16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors
17191783Srmacklem *    may be used to endorse or promote products derived from this software
18191783Srmacklem *    without specific prior written permission.
19191783Srmacklem *
20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23191783Srmacklem * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30191783Srmacklem * SUCH DAMAGE.
31191783Srmacklem *
32191783Srmacklem * $FreeBSD$
33191783Srmacklem */
34191783Srmacklem
35191783Srmacklem#ifndef _NFSCLIENT_NFSNODE_H_
36191783Srmacklem#define	_NFSCLIENT_NFSNODE_H_
37191783Srmacklem
38224606Srmacklem#include <sys/_task.h>
39224606Srmacklem
40191783Srmacklem/*
41191783Srmacklem * Silly rename structure that hangs off the nfsnode until the name
42191783Srmacklem * can be removed by nfs_inactive()
43191783Srmacklem */
44191783Srmacklemstruct sillyrename {
45224606Srmacklem	struct	task s_task;
46191783Srmacklem	struct	ucred *s_cred;
47191783Srmacklem	struct	vnode *s_dvp;
48191783Srmacklem	long	s_namlen;
49191783Srmacklem	char	s_name[32];
50191783Srmacklem};
51191783Srmacklem
52191783Srmacklem/*
53191783Srmacklem * This structure is used to save the logical directory offset to
54191783Srmacklem * NFS cookie mappings.
55191783Srmacklem * The mappings are stored in a list headed
56191783Srmacklem * by n_cookies, as required.
57191783Srmacklem * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information
58191783Srmacklem * stored in increasing logical offset byte order.
59191783Srmacklem */
60191783Srmacklem#define	NFSNUMCOOKIES		31
61191783Srmacklem
62191783Srmacklemstruct nfsdmap {
63191783Srmacklem	LIST_ENTRY(nfsdmap)	ndm_list;
64191783Srmacklem	int			ndm_eocookie;
65191783Srmacklem	union {
66191783Srmacklem		nfsuint64	ndmu3_cookies[NFSNUMCOOKIES];
67191783Srmacklem		uint64_t	ndmu4_cookies[NFSNUMCOOKIES];
68191783Srmacklem	} ndm_un1;
69191783Srmacklem};
70191783Srmacklem
71191783Srmacklem#define	ndm_cookies	ndm_un1.ndmu3_cookies
72191783Srmacklem#define	ndm4_cookies	ndm_un1.ndmu4_cookies
73191783Srmacklem
74191783Srmacklemstruct nfs_accesscache {
75191783Srmacklem	u_int32_t		mode;	/* ACCESS mode cache */
76191783Srmacklem	uid_t			uid;	/* credentials having mode */
77191783Srmacklem	time_t			stamp;	/* mode cache timestamp */
78191783Srmacklem};
79191783Srmacklem
80191783Srmacklem/*
81191783Srmacklem * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
82191783Srmacklem * is purely coincidental.
83191783Srmacklem * There is a unique nfsnode allocated for each active file,
84191783Srmacklem * each current directory, each mounted-on file, text file, and the root.
85191783Srmacklem * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
86191783Srmacklem * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite
87191783Srmacklem * type definitions), file handles of > 32 bytes should probably be split out
88191783Srmacklem * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by
89191783Srmacklem * changing the definition in nfsproto.h of NFS_SMALLFH.)
90191783Srmacklem * NB: Hopefully the current order of the fields is such that everything will
91191783Srmacklem *     be well aligned and, therefore, tightly packed.
92191783Srmacklem */
93191783Srmacklemstruct nfsnode {
94191783Srmacklem	struct mtx 		n_mtx;		/* Protects all of these members */
95191783Srmacklem	u_quad_t		n_size;		/* Current size of file */
96191783Srmacklem	u_quad_t		n_brev;		/* Modify rev when cached */
97191783Srmacklem	u_quad_t		n_lrev;		/* Modify rev for lease */
98191783Srmacklem	struct nfsvattr		n_vattr;	/* Vnode attribute cache */
99191783Srmacklem	time_t			n_attrstamp;	/* Attr. cache timestamp */
100191783Srmacklem	struct nfs_accesscache	n_accesscache[NFS_ACCESSCACHESIZE];
101191783Srmacklem	struct timespec		n_mtime;	/* Prev modify time. */
102191783Srmacklem	struct nfsfh		*n_fhp;		/* NFS File Handle */
103191783Srmacklem	struct vnode		*n_vnode;	/* associated vnode */
104191783Srmacklem	struct vnode		*n_dvp;		/* parent vnode */
105191783Srmacklem	struct lockf		*n_lockf;	/* Locking record of file */
106191783Srmacklem	int			n_error;	/* Save write error value */
107191783Srmacklem	union {
108191783Srmacklem		struct timespec	nf_atim;	/* Special file times */
109191783Srmacklem		nfsuint64	nd_cookieverf;	/* Cookie verifier (dir only) */
110191783Srmacklem		u_char		nd4_cookieverf[NFSX_VERF];
111191783Srmacklem	} n_un1;
112191783Srmacklem	union {
113191783Srmacklem		struct timespec	nf_mtim;
114191783Srmacklem		off_t		nd_direof;	/* Dir. EOF offset cache */
115191783Srmacklem	} n_un2;
116191783Srmacklem	union {
117191783Srmacklem		struct sillyrename *nf_silly;	/* Ptr to silly rename struct */
118191783Srmacklem		LIST_HEAD(, nfsdmap) nd_cook;	/* cookies */
119191783Srmacklem	} n_un3;
120191783Srmacklem	short			n_fhsize;	/* size in bytes, of fh */
121191783Srmacklem	u_int32_t		n_flag;		/* Flag for locking.. */
122191783Srmacklem	int			n_directio_opens;
123191783Srmacklem	int                     n_directio_asyncwr;
124191783Srmacklem	u_int64_t		 n_change;	/* old Change attribute */
125191783Srmacklem	struct nfsv4node	*n_v4;		/* extra V4 stuff */
126235332Srmacklem	struct ucred		*n_writecred;	/* Cred. for putpages */
127191783Srmacklem};
128191783Srmacklem
129191783Srmacklem#define	n_atim		n_un1.nf_atim
130191783Srmacklem#define	n_mtim		n_un2.nf_mtim
131191783Srmacklem#define	n_sillyrename	n_un3.nf_silly
132191783Srmacklem#define	n_cookieverf	n_un1.nd_cookieverf
133191783Srmacklem#define	n4_cookieverf	n_un1.nd4_cookieverf
134191783Srmacklem#define	n_direofoffset	n_un2.nd_direof
135191783Srmacklem#define	n_cookies	n_un3.nd_cook
136191783Srmacklem
137191783Srmacklem/*
138191783Srmacklem * Flags for n_flag
139191783Srmacklem */
140191783Srmacklem#define	NDIRCOOKIELK	0x00000001  /* Lock to serialize access to directory cookies */
141191783Srmacklem#define	NFSYNCWAIT      0x00000002  /* fsync waiting for all directio async
142191783Srmacklem				  writes to drain */
143191783Srmacklem#define	NMODIFIED	0x00000004  /* Might have a modified buffer in bio */
144191783Srmacklem#define	NWRITEERR	0x00000008  /* Flag write errors so close will know */
145191783Srmacklem#define	NCREATED	0x00000010  /* Opened by nfs_create() */
146191783Srmacklem#define	NTRUNCATE	0x00000020  /* Opened by nfs_setattr() */
147191783Srmacklem#define	NSIZECHANGED	0x00000040  /* File size has changed: need cache inval */
148191783Srmacklem#define	NNONCACHE	0x00000080  /* Node marked as noncacheable */
149191783Srmacklem#define	NACC		0x00000100  /* Special file accessed */
150191783Srmacklem#define	NUPD		0x00000200  /* Special file updated */
151191783Srmacklem#define	NCHG		0x00000400  /* Special file times changed */
152191783Srmacklem#define	NDELEGMOD	0x00000800  /* Modified delegation */
153191783Srmacklem#define	NDELEGRECALL	0x00001000  /* Recall in progress */
154191783Srmacklem#define	NREMOVEINPROG	0x00002000  /* Remove in progress */
155191783Srmacklem#define	NREMOVEWANT	0x00004000  /* Want notification that remove is done */
156191783Srmacklem#define	NLOCK		0x00008000  /* Sleep lock the node */
157191783Srmacklem#define	NLOCKWANT	0x00010000  /* Want the sleep lock */
158244042Srmacklem#define	NNOLAYOUT	0x00020000  /* Can't get a layout for this file */
159244042Srmacklem#define	NWRITEOPENED	0x00040000  /* Has been opened for writing */
160191783Srmacklem
161191783Srmacklem/*
162191783Srmacklem * Convert between nfsnode pointers and vnode pointers
163191783Srmacklem */
164191783Srmacklem#define	VTONFS(vp)	((struct nfsnode *)(vp)->v_data)
165191783Srmacklem#define	NFSTOV(np)	((struct vnode *)(np)->n_vnode)
166191783Srmacklem
167191783Srmacklem#define	NFS_TIMESPEC_COMPARE(T1, T2)	(((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec))
168191783Srmacklem
169191783Srmacklem#if defined(_KERNEL)
170191783Srmacklem
171191783Srmacklem/*
172191783Srmacklem * Prototypes for NFS vnode operations
173191783Srmacklem */
174191783Srmacklemint	ncl_getpages(struct vop_getpages_args *);
175191783Srmacklemint	ncl_putpages(struct vop_putpages_args *);
176191783Srmacklemint	ncl_write(struct vop_write_args *);
177191783Srmacklemint	ncl_inactive(struct vop_inactive_args *);
178191783Srmacklemint	ncl_reclaim(struct vop_reclaim_args *);
179191783Srmacklem
180191783Srmacklem/* other stuff */
181191783Srmacklemint	ncl_removeit(struct sillyrename *, struct vnode *);
182220732Srmacklemint	ncl_nget(struct mount *, u_int8_t *, int, struct nfsnode **, int);
183191783Srmacklemnfsuint64 *ncl_getcookie(struct nfsnode *, off_t, int);
184191783Srmacklemvoid	ncl_invaldir(struct vnode *);
185191783Srmacklemint	ncl_upgrade_vnlock(struct vnode *);
186191783Srmacklemvoid	ncl_downgrade_vnlock(struct vnode *, int);
187191783Srmacklemvoid	ncl_printf(const char *, ...);
188191783Srmacklemvoid	ncl_dircookie_lock(struct nfsnode *);
189191783Srmacklemvoid	ncl_dircookie_unlock(struct nfsnode *);
190191783Srmacklem
191191783Srmacklem#endif /* _KERNEL */
192191783Srmacklem
193191783Srmacklem#endif	/* _NFSCLIENT_NFSNODE_H_ */
194