]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/cddl/compat/opensolaris/sys/vnode.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / cddl / compat / opensolaris / sys / vnode.h
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 #ifdef _KERNEL
33
34 struct vnode;
35 struct vattr;
36
37 typedef struct vnode    vnode_t;
38 typedef struct vattr    vattr_t;
39 typedef enum vtype vtype_t;
40
41 #include <sys/namei.h>
42 enum symfollow { NO_FOLLOW = NOFOLLOW };
43
44 #include <sys/proc.h>
45 #include_next <sys/vnode.h>
46 #include <sys/mount.h>
47 #include <sys/cred.h>
48 #include <sys/fcntl.h>
49 #include <sys/file.h>
50 #include <sys/filedesc.h>
51 #include <sys/syscallsubr.h>
52
53 typedef struct vop_vector       vnodeops_t;
54 #define VOP_FID         VOP_VPTOFH
55 #define vop_fid         vop_vptofh
56 #define vop_fid_args    vop_vptofh_args
57 #define a_fid           a_fhp
58
59 #define IS_XATTRDIR(dvp)        (0)
60
61 #define v_count v_usecount
62
63 #define V_APPEND        VAPPEND
64
65 #define rootvfs         (rootvnode == NULL ? NULL : rootvnode->v_mount)
66
67 static __inline int
68 vn_is_readonly(vnode_t *vp)
69 {
70         return (vp->v_mount->mnt_flag & MNT_RDONLY);
71 }
72 #define vn_vfswlock(vp)         (0)
73 #define vn_vfsunlock(vp)        do { } while (0)
74 #define vn_ismntpt(vp)          ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
75 #define vn_mountedvfs(vp)       ((vp)->v_mountedhere)
76 #define vn_has_cached_data(vp)  \
77         ((vp)->v_object != NULL && \
78          ((vp)->v_object->resident_page_count > 0 || \
79           !vm_object_cache_is_empty((vp)->v_object)))
80 #define vn_exists(vp)           do { } while (0)
81 #define vn_invalid(vp)          do { } while (0)
82 #define vn_renamepath(tdvp, svp, tnm, lentnm)   do { } while (0)
83 #define vn_free(vp)             do { } while (0)
84 #define vn_matchops(vp, vops)   ((vp)->v_op == &(vops))
85
86 #define VN_HOLD(v)      vref(v)
87 #define VN_RELE(v)      vrele(v)
88 #define VN_URELE(v)     vput(v)
89
90 #define VOP_REALVP(vp, vpp, ct) (*(vpp) = (vp), 0)
91
92 #define vnevent_create(vp, ct)                  do { } while (0)
93 #define vnevent_link(vp, ct)                    do { } while (0)
94 #define vnevent_remove(vp, dvp, name, ct)       do { } while (0)
95 #define vnevent_rmdir(vp, dvp, name, ct)        do { } while (0)
96 #define vnevent_rename_src(vp, dvp, name, ct)   do { } while (0)
97 #define vnevent_rename_dest(vp, dvp, name, ct)  do { } while (0)
98 #define vnevent_rename_dest_dir(vp, ct)         do { } while (0)
99
100 #define specvp(vp, rdev, type, cr)      (VN_HOLD(vp), (vp))
101 #define MANDMODE(mode)          (0)
102 #define MANDLOCK(vp, mode)      (0)
103 #define chklock(vp, op, offset, size, mode, ct) (0)
104 #define cleanlocks(vp, pid, foo)        do { } while (0)
105 #define cleanshares(vp, pid)            do { } while (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 ACCESSED                (AT_ATIME)
123 #define STATE_CHANGED           (AT_CTIME)
124 #define CONTENT_MODIFIED        (AT_MTIME | AT_CTIME)
125
126 static __inline void
127 vattr_init_mask(vattr_t *vap)
128 {
129
130         vap->va_mask = 0;
131
132         if (vap->va_type != VNON)
133                 vap->va_mask |= AT_TYPE;
134         if (vap->va_uid != (uid_t)VNOVAL)
135                 vap->va_mask |= AT_UID;
136         if (vap->va_gid != (gid_t)VNOVAL)
137                 vap->va_mask |= AT_GID;
138         if (vap->va_size != (u_quad_t)VNOVAL)
139                 vap->va_mask |= AT_SIZE;
140         if (vap->va_atime.tv_sec != VNOVAL)
141                 vap->va_mask |= AT_ATIME;
142         if (vap->va_mtime.tv_sec != VNOVAL)
143                 vap->va_mask |= AT_MTIME;
144         if (vap->va_mode != (u_short)VNOVAL)
145                 vap->va_mask |= AT_MODE;
146         if (vap->va_flags != VNOVAL)
147                 vap->va_mask |= AT_XVATTR;
148 }
149
150 #define FCREAT          O_CREAT
151 #define FTRUNC          O_TRUNC
152 #define FEXCL           O_EXCL
153 #define FDSYNC          FFSYNC
154 #define FRSYNC          FFSYNC
155 #define FSYNC           FFSYNC
156 #define FOFFMAX         0x00
157 #define FIGNORECASE     0x00
158
159 static __inline int
160 vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
161     vnode_t **vpp, enum create crwhy, mode_t umask, struct vnode *startvp,
162     int fd)
163 {
164         struct thread *td = curthread;
165         struct filedesc *fdc;
166         struct nameidata nd;
167         int error, operation;
168
169         ASSERT(seg == UIO_SYSSPACE);
170         if ((filemode & FCREAT) != 0) {
171                 ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
172                 ASSERT(crwhy == CRCREAT);
173                 operation = CREATE;
174         } else {
175                 ASSERT(filemode == (FREAD | FOFFMAX) ||
176                     filemode == (FREAD | FWRITE | FOFFMAX));
177                 ASSERT(crwhy == 0);
178                 operation = LOOKUP;
179         }
180         ASSERT(umask == 0);
181
182         fdc = td->td_proc->p_fd;
183         FILEDESC_XLOCK(fdc);
184         if (fdc->fd_rdir == NULL) {
185                 fdc->fd_rdir = rootvnode;
186                 vref(fdc->fd_rdir);
187         }
188         if (fdc->fd_cdir == NULL) {
189                 fdc->fd_cdir = rootvnode;
190                 vref(fdc->fd_rdir);
191         }
192         FILEDESC_XUNLOCK(fdc);
193
194         if (startvp != NULL)
195                 vref(startvp);
196         NDINIT_ATVP(&nd, operation, 0, UIO_SYSSPACE, pnamep, startvp, td);
197         filemode |= O_NOFOLLOW;
198         error = vn_open_cred(&nd, &filemode, createmode, 0, td->td_ucred, NULL);
199         NDFREE(&nd, NDF_ONLY_PNBUF);
200         if (error == 0) {
201                 /* We just unlock so we hold a reference. */
202                 VOP_UNLOCK(nd.ni_vp, 0);
203                 *vpp = nd.ni_vp;
204         }
205         return (error);
206 }
207
208 static __inline int
209 zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
210     vnode_t **vpp, enum create crwhy, mode_t umask)
211 {
212
213         return (vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy,
214             umask, NULL, -1));
215 }
216 #define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)   \
217         zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
218
219 #define RLIM64_INFINITY 0
220 static __inline int
221 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
222     offset_t offset, enum uio_seg seg, int ioflag, int ulimit, cred_t *cr,
223     ssize_t *residp)
224 {
225         struct thread *td = curthread;
226         int error;
227         ssize_t resid;
228
229         ASSERT(ioflag == 0);
230         ASSERT(ulimit == RLIM64_INFINITY);
231
232         if (rw == UIO_WRITE) {
233                 ioflag = IO_SYNC;
234         } else {
235                 ioflag = IO_DIRECT;
236         }
237         error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED,
238             &resid, td);
239         if (residp != NULL)
240                 *residp = (ssize_t)resid;
241         return (error);
242 }
243 #define vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
244         zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
245
246 static __inline int
247 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
248 {
249         struct mount *mp;
250         int error;
251
252         ASSERT(flag == FSYNC);
253
254         if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
255                 goto drop;
256         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
257         error = VOP_FSYNC(vp, MNT_WAIT, curthread);
258         VOP_UNLOCK(vp, 0);
259         vn_finished_write(mp);
260 drop:
261         return (error);
262 }
263 #define VOP_FSYNC(vp, flag, cr, ct)     zfs_vop_fsync((vp), (flag), (cr))
264
265 static __inline int
266 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
267 {
268         int error;
269
270         ASSERT(count == 1);
271         ASSERT(offset == 0);
272
273         error = vn_close(vp, flag, cr, curthread);
274         return (error);
275 }
276 #define VOP_CLOSE(vp, oflags, count, offset, cr, ct)                    \
277         zfs_vop_close((vp), (oflags), (count), (offset), (cr))
278
279 static __inline int
280 vn_rename(char *from, char *to, enum uio_seg seg)
281 {
282
283         ASSERT(seg == UIO_SYSSPACE);
284
285         return (kern_rename(curthread, from, to, seg));
286 }
287
288 static __inline int
289 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
290 {
291
292         ASSERT(seg == UIO_SYSSPACE);
293         ASSERT(dirflag == RMFILE);
294
295         return (kern_unlink(curthread, fnamep, seg));
296 }
297
298 #endif  /* _KERNEL */
299
300 #endif  /* _OPENSOLARIS_SYS_VNODE_H_ */