1 /*
2  * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _OPENSOLARIS_SYS_VNODE_H_
30 #define	_OPENSOLARIS_SYS_VNODE_H_
31 
32 struct vnode;
33 struct vattr;
34 struct xucred;
35 
36 typedef struct flock	flock64_t;
37 typedef	struct vnode	vnode_t;
38 typedef	struct vattr	vattr_t;
39 typedef enum vtype vtype_t;
40 
41 #include <sys/types.h>
42 #include <sys/queue.h>
43 #include_next <sys/sdt.h>
44 #include <sys/namei.h>
45 enum symfollow { NO_FOLLOW = NOFOLLOW };
46 
47 #define	NOCRED	((struct ucred *)0)	/* no credential available */
48 #define	F_FREESP	11 	/* Free file space */
49 
50 #include <sys/proc.h>
51 #include <sys/vnode_impl.h>
52 #ifndef IN_BASE
53 #include_next <sys/vnode.h>
54 #endif
55 #include <sys/mount.h>
56 #include <sys/cred.h>
57 #include <sys/fcntl.h>
58 #include <sys/refcount.h>
59 #include <sys/file.h>
60 #include <sys/filedesc.h>
61 #include <sys/syscallsubr.h>
62 
63 typedef	struct vop_vector	vnodeops_t;
64 #define	VOP_FID		VOP_VPTOFH
65 #define	vop_fid		vop_vptofh
66 #define	vop_fid_args	vop_vptofh_args
67 #define	a_fid		a_fhp
68 
69 #define	rootvfs		(rootvnode == NULL ? NULL : rootvnode->v_mount)
70 
71 #ifndef IN_BASE
72 static __inline int
73 vn_is_readonly(vnode_t *vp)
74 {
75 	return (vp->v_mount->mnt_flag & MNT_RDONLY);
76 }
77 #endif
78 #define	vn_vfswlock(vp)		(0)
79 #define	vn_vfsunlock(vp)	do { } while (0)
80 #define	vn_ismntpt(vp)	   \
81 	((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
82 #define	vn_mountedvfs(vp)	((vp)->v_mountedhere)
83 #define	vn_has_cached_data(vp)	\
84 	((vp)->v_object != NULL && \
85 	(vp)->v_object->resident_page_count > 0)
86 #define	vn_exists(vp)		do { } while (0)
87 #define	vn_invalid(vp)		do { } while (0)
88 #define	vn_renamepath(tdvp, svp, tnm, lentnm)	do { } while (0)
89 #define	vn_free(vp)		do { } while (0)
90 #define	vn_matchops(vp, vops)	((vp)->v_op == &(vops))
91 
92 #define	VN_HOLD(v)	vref(v)
93 #define	VN_RELE(v)	vrele(v)
94 #define	VN_URELE(v)	vput(v)
95 
96 #define	vnevent_create(vp, ct)			do { } while (0)
97 #define	vnevent_link(vp, ct)			do { } while (0)
98 #define	vnevent_remove(vp, dvp, name, ct)	do { } while (0)
99 #define	vnevent_rmdir(vp, dvp, name, ct)	do { } while (0)
100 #define	vnevent_rename_src(vp, dvp, name, ct)	do { } while (0)
101 #define	vnevent_rename_dest(vp, dvp, name, ct)	do { } while (0)
102 #define	vnevent_rename_dest_dir(vp, ct)		do { } while (0)
103 
104 #define	specvp(vp, rdev, type, cr)	(VN_HOLD(vp), (vp))
105 #define	MANDLOCK(vp, mode)	(0)
106 
107 /*
108  * We will use va_spare is place of Solaris' va_mask.
109  * This field is initialized in zfs_setattr().
110  */
111 #define	va_mask		va_spare
112 /* TODO: va_fileid is shorter than va_nodeid !!! */
113 #define	va_nodeid	va_fileid
114 /* TODO: This field needs conversion! */
115 #define	va_nblocks	va_bytes
116 #define	va_blksize	va_blocksize
117 #define	va_seq		va_gen
118 
119 #define	MAXOFFSET_T	OFF_MAX
120 #define	EXCL		0
121 
122 #define	FCREAT		O_CREAT
123 #define	FTRUNC		O_TRUNC
124 #define	FEXCL		O_EXCL
125 #ifndef FDSYNC
126 #define	FDSYNC		FFSYNC
127 #endif
128 #define	FRSYNC		FFSYNC
129 #define	FSYNC		FFSYNC
130 #define	FOFFMAX		0x00
131 #define	FIGNORECASE	0x00
132 
133 /*
134  * Attributes of interest to the caller of setattr or getattr.
135  */
136 #define	AT_MODE		0x00002
137 #define	AT_UID		0x00004
138 #define	AT_GID		0x00008
139 #define	AT_FSID		0x00010
140 #define	AT_NODEID	0x00020
141 #define	AT_NLINK	0x00040
142 #define	AT_SIZE		0x00080
143 #define	AT_ATIME	0x00100
144 #define	AT_MTIME	0x00200
145 #define	AT_CTIME	0x00400
146 #define	AT_RDEV		0x00800
147 #define	AT_BLKSIZE	0x01000
148 #define	AT_NBLOCKS	0x02000
149 /*			0x04000 */	/* unused */
150 #define	AT_SEQ		0x08000
151 /*
152  * If AT_XVATTR is set then there are additional bits to process in
153  * the xvattr_t's attribute bitmap.  If this is not set then the bitmap
154  * MUST be ignored.  Note that this bit must be set/cleared explicitly.
155  * That is, setting AT_ALL will NOT set AT_XVATTR.
156  */
157 #define	AT_XVATTR	0x10000
158 
159 #define	AT_ALL		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
160 			AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
161 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
162 
163 #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
164 			AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV)
165 
166 #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
167 
168 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|\
169 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
170 
171 #ifndef IN_BASE
172 static __inline void
173 vattr_init_mask(vattr_t *vap)
174 {
175 
176 	vap->va_mask = 0;
177 
178 	if (vap->va_uid != (uid_t)VNOVAL)
179 		vap->va_mask |= AT_UID;
180 	if (vap->va_gid != (gid_t)VNOVAL)
181 		vap->va_mask |= AT_GID;
182 	if (vap->va_size != (u_quad_t)VNOVAL)
183 		vap->va_mask |= AT_SIZE;
184 	if (vap->va_atime.tv_sec != VNOVAL)
185 		vap->va_mask |= AT_ATIME;
186 	if (vap->va_mtime.tv_sec != VNOVAL)
187 		vap->va_mask |= AT_MTIME;
188 	if (vap->va_mode != (uint16_t)VNOVAL)
189 		vap->va_mask |= AT_MODE;
190 	if (vap->va_flags != VNOVAL)
191 		vap->va_mask |= AT_XVATTR;
192 }
193 #endif
194 
195 #define		RLIM64_INFINITY 0
196 
197 static __inline int
198 vn_rename(char *from, char *to, enum uio_seg seg)
199 {
200 
201 	ASSERT(seg == UIO_SYSSPACE);
202 
203 	return (kern_renameat(curthread, AT_FDCWD, from, AT_FDCWD, to, seg));
204 }
205 
206 #include <sys/vfs.h>
207 
208 #endif	/* _OPENSOLARIS_SYS_VNODE_H_ */
209