]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/compat/opensolaris/sys/vnode.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 #include_next <sys/vnode.h>
33 #include <sys/mount.h>
34 #include <sys/cred.h>
35 #include <sys/fcntl.h>
36 #include <sys/namei.h>
37 #include <sys/proc.h>
38 #include <sys/filedesc.h>
39 #include <sys/syscallsubr.h>
40
41 typedef struct vnode    vnode_t;
42 typedef struct vattr    vattr_t;
43 typedef void            caller_context_t;
44
45 typedef struct vop_vector       vnodeops_t;
46 #define vop_fid         vop_vptofh
47 #define vop_fid_args    vop_vptofh_args
48 #define a_fid           a_fhp
49
50 #define v_count v_usecount
51
52 static __inline int
53 vn_is_readonly(vnode_t *vp)
54 {
55         return (vp->v_mount->mnt_flag & MNT_RDONLY);
56 }
57 #define vn_vfswlock(vp)         (0)
58 #define vn_vfsunlock(vp)        do { } while (0)
59 #define vn_ismntpt(vp)          ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
60 #define vn_mountedvfs(vp)       ((vp)->v_mountedhere)
61 #define vn_has_cached_data(vp)  ((vp)->v_object != NULL && (vp)->v_object->resident_page_count > 0)
62
63 #define VN_HOLD(v)      vref(v)
64 #define VN_RELE(v)      vrele(v)
65 #define VN_URELE(v)     vput(v)
66
67 #define VOP_REALVP(vp, vpp)     (*(vpp) = (vp), 0)
68
69 #define vnevent_remove(vp)      do { } while (0)
70 #define vnevent_rmdir(vp)       do { } while (0)
71 #define vnevent_rename_src(vp)  do { } while (0)
72 #define vnevent_rename_dest(vp) do { } while (0)
73
74
75 #define IS_DEVVP(vp)    \
76         ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
77
78 #define MODEMASK        ALLPERMS
79
80 #define specvp(vp, rdev, type, cr)      (VN_HOLD(vp), (vp))
81 #define MANDMODE(mode)  (0)
82 #define chklock(vp, op, offset, size, mode, ct) (0)
83 #define cleanlocks(vp, pid, foo)        do { } while (0)
84 #define cleanshares(vp, pid)            do { } while (0)
85
86 /*
87  * We will use va_spare is place of Solaris' va_mask.
88  * This field is initialized in zfs_setattr().
89  */
90 #define va_mask         va_spare
91 /* TODO: va_fileid is shorter than va_nodeid !!! */
92 #define va_nodeid       va_fileid
93 /* TODO: This field needs conversion! */
94 #define va_nblocks      va_bytes
95 #define va_blksize      va_blocksize
96 #define va_seq          va_gen
97
98 #define MAXOFFSET_T     OFF_MAX
99 #define EXCL            0
100
101 #define AT_TYPE         0x0001
102 #define AT_MODE         0x0002
103 #define AT_UID          0x0004
104 #define AT_GID          0x0008
105 #define AT_FSID         0x0010
106 #define AT_NODEID       0x0020
107 #define AT_NLINK        0x0040
108 #define AT_SIZE         0x0080
109 #define AT_ATIME        0x0100
110 #define AT_MTIME        0x0200
111 #define AT_CTIME        0x0400
112 #define AT_RDEV         0x0800
113 #define AT_BLKSIZE      0x1000
114 #define AT_NBLOCKS      0x2000
115 #define AT_SEQ          0x4000
116 #define AT_NOSET        (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
117                          AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
118
119 #define ACCESSED                (AT_ATIME)
120 #define STATE_CHANGED           (AT_CTIME)
121 #define CONTENT_MODIFIED        (AT_MTIME | AT_CTIME)
122
123 static __inline void
124 vattr_init_mask(vattr_t *vap)
125 {
126
127         vap->va_mask = 0;
128
129         if (vap->va_type != VNON)
130                 vap->va_mask |= AT_TYPE;
131         if (vap->va_uid != (uid_t)VNOVAL)
132                 vap->va_mask |= AT_UID;
133         if (vap->va_gid != (gid_t)VNOVAL)
134                 vap->va_mask |= AT_GID;
135         if (vap->va_size != (u_quad_t)VNOVAL)
136                 vap->va_mask |= AT_SIZE;
137         if (vap->va_atime.tv_sec != VNOVAL)
138                 vap->va_mask |= AT_ATIME;
139         if (vap->va_mtime.tv_sec != VNOVAL)
140                 vap->va_mask |= AT_MTIME;
141         if (vap->va_mode != (u_short)VNOVAL)
142                 vap->va_mask |= AT_MODE;
143 }
144
145 #define FCREAT  O_CREAT
146 #define FTRUNC  O_TRUNC
147 #define FDSYNC  FFSYNC
148 #define FRSYNC  FFSYNC
149 #define FSYNC   FFSYNC
150 #define FOFFMAX 0x00
151
152 enum create     { CRCREAT };
153
154 static __inline int
155 zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
156     vnode_t **vpp, enum create crwhy, mode_t umask)
157 {
158         struct thread *td = curthread;
159         struct nameidata nd;
160         int error;
161
162         ASSERT(seg == UIO_SYSSPACE);
163         ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
164         ASSERT(crwhy == CRCREAT);
165         ASSERT(umask == 0);
166
167         if (td->td_proc->p_fd->fd_rdir == NULL)
168                 td->td_proc->p_fd->fd_rdir = rootvnode;
169         if (td->td_proc->p_fd->fd_cdir == NULL)
170                 td->td_proc->p_fd->fd_cdir = rootvnode;
171
172         NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pnamep, td);
173         error = vn_open_cred(&nd, &filemode, createmode, td->td_ucred, NULL);
174         NDFREE(&nd, NDF_ONLY_PNBUF);
175         if (error == 0) {
176                 /* We just unlock so we hold a reference. */
177                 VN_HOLD(nd.ni_vp);
178                 VOP_UNLOCK(nd.ni_vp, 0, td);
179                 *vpp = nd.ni_vp;
180         }
181         return (error);
182 }
183 #define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)   \
184         zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
185
186 #define RLIM64_INFINITY 0
187 static __inline int
188 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
189     offset_t offset, enum uio_seg seg, int ioflag, int ulimit, cred_t *cr,
190     ssize_t *residp)
191 {
192         struct thread *td = curthread;
193         int error, vfslocked, resid;
194
195         ASSERT(rw == UIO_WRITE);
196         ASSERT(ioflag == 0);
197         ASSERT(ulimit == RLIM64_INFINITY);
198
199         ioflag = IO_APPEND | IO_UNIT;
200
201         vfslocked = VFS_LOCK_GIANT(vp->v_mount);
202         VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
203         error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED,
204             &resid, td);
205         VFS_UNLOCK_GIANT(vfslocked);
206         if (residp != NULL)
207                 *residp = (ssize_t)resid;
208         return (error);
209 }
210 #define vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
211         zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
212
213 static __inline int
214 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
215 {
216         struct thread *td = curthread;
217         struct mount *mp;
218         int error, vfslocked;
219
220         ASSERT(flag == FSYNC);
221
222         vfslocked = VFS_LOCK_GIANT(vp->v_mount);
223         if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
224                 goto drop;
225         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
226         error = VOP_FSYNC(vp, MNT_WAIT, td);
227         VOP_UNLOCK(vp, 0, td);
228         vn_finished_write(mp);
229 drop:
230         VFS_UNLOCK_GIANT(vfslocked);
231         return (error);
232 }
233 #define VOP_FSYNC(vp, flag, cr) zfs_vop_fsync((vp), (flag), (cr))
234
235 static __inline int
236 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
237 {
238
239         ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
240         ASSERT(count == 1);
241         ASSERT(offset == 0);
242
243         return (vn_close(vp, flag, cr, curthread));
244 }
245 #define VOP_CLOSE(vp, oflags, count, offset, cr)                        \
246         zfs_vop_close((vp), (oflags), (count), (offset), (cr))
247
248 static __inline int
249 vn_rename(char *from, char *to, enum uio_seg seg)
250 {
251
252         ASSERT(seg == UIO_SYSSPACE);
253
254         return (kern_rename(curthread, from, to, seg));
255 }
256
257 enum rm { RMFILE };
258 static __inline int
259 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
260 {
261
262         ASSERT(seg == UIO_SYSSPACE);
263         ASSERT(dirflag == RMFILE);
264
265         return (kern_unlink(curthread, fnamep, seg));
266 }
267
268 #endif  /* _OPENSOLARIS_SYS_VNODE_H_ */