xref: /openbsd-src/sys/nfs/nfsnode.h (revision a43f2b810b1f5868c51fb6b0ce5bbc63130f8c93)
1*a43f2b81Smiod /*	$OpenBSD: nfsnode.h,v 1.43 2024/04/30 17:04:23 miod Exp $	*/
278530d46Smickey /*	$NetBSD: nfsnode.h,v 1.16 1996/02/18 11:54:04 fvdl Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1989, 1993
6df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
9df930be7Sderaadt  * Rick Macklem at The University of Guelph.
10df930be7Sderaadt  *
11df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt  * modification, are permitted provided that the following conditions
13df930be7Sderaadt  * are met:
14df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
1929295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
21df930be7Sderaadt  *    without specific prior written permission.
22df930be7Sderaadt  *
23df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt  * SUCH DAMAGE.
34df930be7Sderaadt  *
3578530d46Smickey  *	@(#)nfsnode.h	8.9 (Berkeley) 5/14/95
36df930be7Sderaadt  */
37df930be7Sderaadt 
3878530d46Smickey 
3978530d46Smickey #ifndef _NFS_NFSNODE_H_
4078530d46Smickey #define _NFS_NFSNODE_H_
4178530d46Smickey 
4278530d46Smickey #ifndef _NFS_NFS_H_
4378530d46Smickey #include <nfs/nfs.h>
4478530d46Smickey #endif
4578530d46Smickey 
4653ae78e5Smpi #include <sys/lock.h>
47e4c869ecSmarius 
48df930be7Sderaadt /*
49df930be7Sderaadt  * Silly rename structure that hangs off the nfsnode until the name
50df930be7Sderaadt  * can be removed by nfs_inactive()
51df930be7Sderaadt  */
52df930be7Sderaadt struct sillyrename {
53df930be7Sderaadt 	struct	ucred *s_cred;
54df930be7Sderaadt 	struct	vnode *s_dvp;
55df930be7Sderaadt 	long	s_namlen;
56482c7c11Sbeck 	char	s_name[24];
57df930be7Sderaadt };
58df930be7Sderaadt 
59df930be7Sderaadt /*
60df930be7Sderaadt  * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
61df930be7Sderaadt  * is purely coincidental.
62df930be7Sderaadt  * There is a unique nfsnode allocated for each active file,
63df930be7Sderaadt  * each current directory, each mounted-on file, text file, and the root.
64df930be7Sderaadt  * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
65df930be7Sderaadt  */
66df930be7Sderaadt struct nfsnode {
67e54eb321Sthib 	RB_ENTRY(nfsnode)	n_entry;	/* filehandle/node tree. */
68df930be7Sderaadt 	u_quad_t		n_size;		/* Current size of file */
6978530d46Smickey 	struct vattr		n_vattr;	/* Vnode attribute cache */
7078530d46Smickey 	time_t			n_attrstamp;	/* Attr. cache timestamp */
71c585412dSthib 	struct timespec 	n_mtime;	/* Prev modify time. */
7278530d46Smickey 	time_t			n_ctime;	/* Prev create time. */
7378530d46Smickey 	nfsfh_t			*n_fhp;		/* NFS File Handle */
7478530d46Smickey 	struct vnode		*n_vnode;	/* associated vnode */
756bd4f7caSanton 	struct lockf_state	*n_lockf;	/* Locking record of file */
7653ae78e5Smpi 	struct rrwlock		n_lock;		/* NFSnode lock */
7778530d46Smickey 	int			n_error;	/* Save write error value */
7878530d46Smickey 	union {
7978530d46Smickey 		struct timespec	nf_atim;	/* Special file times */
8078530d46Smickey 		nfsuint64	nd_cookieverf;	/* Cookie verifier (dir only) */
8178530d46Smickey 	} n_un1;
8278530d46Smickey 	union {
8378530d46Smickey 		struct timespec	nf_mtim;
8478530d46Smickey 		off_t		nd_direof;	/* Dir. EOF offset cache */
8578530d46Smickey 	} n_un2;
86116783b3Sthib 	struct sillyrename	*n_sillyrename;	/* Ptr to silly rename struct */
8778530d46Smickey 	short			n_fhsize;	/* size in bytes, of fh */
8878530d46Smickey 	short			n_flag;		/* Flag for locking.. */
8978530d46Smickey 	nfsfh_t			n_fh;		/* Small File Handle */
90c7d932a0Sthib 	time_t			n_accstamp;	/* Access cache timestamp */
91c7d932a0Sthib 	uid_t			n_accuid;	/* Last access requester */
92c7d932a0Sthib 	int			n_accmode;	/* Last mode requested */
93c7d932a0Sthib 	int			n_accerror;	/* Last returned error */
94e3c7f0cdSart 	struct ucred		*n_rcred;
95e3c7f0cdSart 	struct ucred		*n_wcred;
96e4c869ecSmarius 
97b66b9ef8Sjsg 	off_t			n_pushedlo;	/* 1st blk in committed range */
98e4c869ecSmarius 	off_t			n_pushedhi;	/* Last block in range */
99e4c869ecSmarius 	off_t			n_pushlo;	/* 1st block in commit range */
100e4c869ecSmarius 	off_t			n_pushhi;	/* Last block in range */
101e4c869ecSmarius 	struct rwlock		n_commitlock;	/* Serialize commits */
102e4c869ecSmarius 	int			n_commitflags;
103df930be7Sderaadt };
104df930be7Sderaadt 
105e4c869ecSmarius /*
106e4c869ecSmarius  * Values for n_commitflags
107e4c869ecSmarius  */
108e4c869ecSmarius #define NFS_COMMIT_PUSH_VALID   0x0001          /* push range valid */
109e4c869ecSmarius #define NFS_COMMIT_PUSHED_VALID 0x0002          /* pushed range valid */
110e4c869ecSmarius 
11178530d46Smickey #define n_atim		n_un1.nf_atim
11278530d46Smickey #define n_mtim		n_un2.nf_mtim
11378530d46Smickey #define n_cookieverf	n_un1.nd_cookieverf
11478530d46Smickey #define n_direofoffset	n_un2.nd_direof
11578530d46Smickey 
116df930be7Sderaadt /*
117df930be7Sderaadt  * Flags for n_flag
118df930be7Sderaadt  */
119df930be7Sderaadt #define	NFLUSHWANT	0x0001	/* Want wakeup from a flush in prog. */
120df930be7Sderaadt #define	NFLUSHINPROG	0x0002	/* Avoid multiple calls to vinvalbuf() */
121df930be7Sderaadt #define	NMODIFIED	0x0004	/* Might have a modified buffer in bio */
122df930be7Sderaadt #define	NWRITEERR	0x0008	/* Flag write errors so close will know */
123df930be7Sderaadt #define	NACC		0x0100	/* Special file accessed */
124df930be7Sderaadt #define	NUPD		0x0200	/* Special file updated */
125df930be7Sderaadt #define	NCHG		0x0400	/* Special file times changed */
126df930be7Sderaadt 
127fdc7e2e5Sthib #define NFS_INVALIDATE_ATTRCACHE(np)	((np)->n_attrstamp = 0)
128fdc7e2e5Sthib 
129df930be7Sderaadt /*
130df930be7Sderaadt  * Convert between nfsnode pointers and vnode pointers
131df930be7Sderaadt  */
132df930be7Sderaadt #define VTONFS(vp)	((struct nfsnode *)(vp)->v_data)
133e3c7f0cdSart #define NFSTOV(np)	((np)->n_vnode)
134df930be7Sderaadt 
1359c9522aeSthib /*
1369c9522aeSthib  * Queue head for nfsiod's
1379c9522aeSthib  */
1389c9522aeSthib extern TAILQ_HEAD(nfs_bufqhead, buf) nfs_bufq;
1399c9522aeSthib extern uint32_t nfs_bufqlen, nfs_bufqmax;
140df930be7Sderaadt 
1411f7dd9aeSthib #endif		/* _NFS_NFSNODE_H_ */
142