1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
28 #include <linux/module.h>
29 #include <linux/syscalls.h>
30 #include <linux/fcntl.h>
31 #include <linux/buffer_head.h>
32 #include <linux/dcache.h>
33 #include <linux/namei.h>
34 #include <linux/file.h>
36 #include <linux/fs_struct.h>
37 #include <linux/mount.h>
39 #include <sys/mutex.h>
40 #include <sys/types.h>
43 #include <sys/sunldi.h>
46 #define XVA_MAGIC 0x78766174
49 * Prior to linux-2.6.33 only O_DSYNC semantics were implemented and
50 * they used the O_SYNC flag. As of linux-2.6.33 the this behavior
51 * was properly split in to O_SYNC and O_DSYNC respectively.
54 #define O_DSYNC O_SYNC
59 #define FCREAT O_CREAT
60 #define FTRUNC O_TRUNC
61 #define FOFFMAX O_LARGEFILE
63 #define FDSYNC O_DSYNC
66 #define FDIRECT O_DIRECT
67 #define FAPPEND O_APPEND
69 #define FNODSYNC 0x10000 /* fsync pseudo flag */
70 #define FNOFOLLOW 0x20000 /* don't follow symlinks */
72 #define AT_TYPE 0x00001
73 #define AT_MODE 0x00002
74 #undef AT_UID /* Conflicts with linux/auxvec.h */
75 #define AT_UID 0x00004
76 #undef AT_GID /* Conflicts with linux/auxvec.h */
77 #define AT_GID 0x00008
78 #define AT_FSID 0x00010
79 #define AT_NODEID 0x00020
80 #define AT_NLINK 0x00040
81 #define AT_SIZE 0x00080
82 #define AT_ATIME 0x00100
83 #define AT_MTIME 0x00200
84 #define AT_CTIME 0x00400
85 #define AT_RDEV 0x00800
86 #define AT_BLKSIZE 0x01000
87 #define AT_NBLOCKS 0x02000
88 #define AT_SEQ 0x08000
89 #define AT_XVATTR 0x10000
97 #ifdef HAVE_PATH_IN_NAMEIDATA
98 # define nd_dentry path.dentry
99 # define nd_mnt path.mnt
101 # define nd_dentry dentry
120 typedef struct vattr
{
121 enum vtype va_type
; /* vnode type */
122 u_int va_mask
; /* attribute bit-mask */
123 u_short va_mode
; /* acc mode */
124 uid_t va_uid
; /* owner uid */
125 gid_t va_gid
; /* owner gid */
126 long va_fsid
; /* fs id */
127 long va_nodeid
; /* node # */
128 uint32_t va_nlink
; /* # links */
129 uint64_t va_size
; /* file size */
130 uint32_t va_blocksize
; /* block size */
131 uint64_t va_nblocks
; /* space used */
132 struct timespec va_atime
; /* last acc */
133 struct timespec va_mtime
; /* last mod */
134 struct timespec va_ctime
; /* last chg */
135 dev_t va_rdev
; /* dev */
138 typedef struct xoptattr
{
139 timestruc_t xoa_createtime
; /* Create time of file */
142 uint8_t xoa_readonly
;
144 uint8_t xoa_nounlink
;
145 uint8_t xoa_immutable
;
146 uint8_t xoa_appendonly
;
148 uint8_t xoa_settable
;
150 uint8_t xoa_av_quarantined
;
151 uint8_t xoa_av_modified
;
154 typedef struct xvattr
{
155 vattr_t xva_vattr
; /* Embedded vattr structure */
156 uint32_t xva_magic
; /* Magic Number */
157 uint32_t xva_mapsize
; /* Size of attr bitmap (32-bit words) */
158 uint32_t *xva_rtnattrmapp
; /* Ptr to xva_rtnattrmap[] */
159 uint32_t xva_reqattrmap
[XVA_MAPSIZE
]; /* Requested attrs */
160 uint32_t xva_rtnattrmap
[XVA_MAPSIZE
]; /* Returned attrs */
161 xoptattr_t xva_xoptattrs
; /* Optional attributes */
164 typedef struct vsecattr
{
165 uint_t vsa_mask
; /* See below */
166 int vsa_aclcnt
; /* ACL entry count */
167 void *vsa_aclentp
; /* pointer to ACL entries */
168 int vsa_dfaclcnt
; /* default ACL entry count */
169 void *vsa_dfaclentp
; /* pointer to default ACL entries */
170 size_t vsa_aclentsz
; /* ACE size in bytes of vsa_aclentp */
171 uint_t vsa_aclflags
; /* ACE ACL flags */
174 typedef struct vnode
{
176 kmutex_t v_lock
; /* protects vnode fields */
177 uint_t v_flag
; /* vnode flags (see below) */
178 uint_t v_count
; /* reference count */
179 void *v_data
; /* private data for fs */
180 struct vfs
*v_vfsp
; /* ptr to containing VFS */
181 struct stdata
*v_stream
; /* associated stream */
182 enum vtype v_type
; /* vnode type */
183 dev_t v_rdev
; /* device (VCHR, VBLK) */
184 gfp_t v_gfp_mask
; /* original mapping gfp mask */
187 typedef struct vn_file
{
188 int f_fd
; /* linux fd for lookup */
189 struct file
*f_file
; /* linux file struct */
190 atomic_t f_ref
; /* ref count */
191 kmutex_t f_lock
; /* struct lock */
192 loff_t f_offset
; /* offset */
193 vnode_t
*f_vnode
; /* vnode */
194 struct list_head f_list
; /* list referenced file_t's */
197 typedef struct caller_context
{
198 pid_t cc_pid
; /* Process ID of the caller */
199 int cc_sysid
; /* System ID, used for remote calls */
200 u_longlong_t cc_caller_id
; /* Identifier for (set of) caller(s) */
204 extern vnode_t
*vn_alloc(int flag
);
205 void vn_free(vnode_t
*vp
);
206 extern vtype_t
vn_mode_to_vtype(mode_t
);
207 extern mode_t
vn_vtype_to_mode(vtype_t
);
208 extern int vn_open(const char *path
, uio_seg_t seg
, int flags
, int mode
,
209 vnode_t
**vpp
, int x1
, void *x2
);
210 extern int vn_openat(const char *path
, uio_seg_t seg
, int flags
, int mode
,
211 vnode_t
**vpp
, int x1
, void *x2
, vnode_t
*vp
, int fd
);
212 extern int vn_rdwr(uio_rw_t uio
, vnode_t
*vp
, void *addr
, ssize_t len
,
213 offset_t off
, uio_seg_t seg
, int x1
, rlim64_t x2
,
214 void *x3
, ssize_t
*residp
);
215 extern int vn_close(vnode_t
*vp
, int flags
, int x1
, int x2
, void *x3
, void *x4
);
216 extern int vn_seek(vnode_t
*vp
, offset_t o
, offset_t
*op
, caller_context_t
*ct
);
218 extern int vn_remove(const char *path
, uio_seg_t seg
, int flags
);
219 extern int vn_rename(const char *path1
, const char *path2
, int x1
);
220 extern int vn_getattr(vnode_t
*vp
, vattr_t
*vap
, int flags
, void *x3
, void *x4
);
221 extern int vn_fsync(vnode_t
*vp
, int flags
, void *x3
, void *x4
);
222 extern file_t
*vn_getf(int fd
);
223 extern void vn_releasef(int fd
);
224 extern int vn_set_pwd(const char *filename
);
229 static __inline__
int
235 static __inline__
int
236 vn_putpage(vnode_t
*vp
, offset_t off
, ssize_t size
,
237 int flags
, void *x1
, void *x2
) {
241 #define VOP_CLOSE vn_close
242 #define VOP_SEEK vn_seek
243 #define VN_RELE vn_rele
244 #define VOP_GETATTR vn_getattr
245 #define VOP_FSYNC vn_fsync
246 #define VOP_PUTPAGE vn_putpage
247 #define vn_is_readonly(vp) 0
249 #define releasef vn_releasef
251 extern vnode_t
*rootdir
;
253 #endif /* SPL_VNODE_H */