xref: /titanic_50/usr/src/uts/common/smbsrv/smb_vops.h (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SMBSRV_SMB_VOPS_H
27 #define	_SMBSRV_SMB_VOPS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Common file system interfaces and definitions.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/file.h>
38 #include <sys/time.h>
39 #include <sys/mntent.h>
40 #include <sys/uio.h>
41 #include <sys/vnode.h>
42 #include <sys/vfs.h>
43 #include <sys/refstr.h>
44 #include <sys/acl.h>
45 #include <sys/fcntl.h>
46 #include <smbsrv/smb_i18n.h>
47 #include <smbsrv/smb_fsd.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #define	ROOTVOL ""
54 #define	CHKPNT ".chkpnt"
55 #define	XATTR_DIR "xattr_dir"
56 
57 #define	SMB_STREAM_PREFIX "SUNWsmb"
58 #define	SMB_STREAM_PREFIX_LEN (sizeof (SMB_STREAM_PREFIX) - 1)
59 
60 #define	MANGLE_NAMELEN 14
61 #define	SMB_EOF	0x7FFFFFFF
62 
63 /*
64  * SMB_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
65  *	VOP_READDIR.  Its value is the size of the maximum possible edirent_t
66  *	for solaris.  The EDIRENT_RECLEN macro returns the size of edirent_t
67  *	required for a given name length.  MAXNAMELEN is the maximum
68  *	filename length allowed in Solaris.  The first two EDIRENT_RECLEN()
69  *	macros are to allow for . and .. entries -- just a minor tweak to try
70  *	and guarantee that buffer we give to VOP_READDIR will be large enough
71  *	to hold ., .., and the largest possible solaris edirent_t.
72  *
73  *	This bufsize will also be used when reading dirent64_t entries.
74  */
75 
76 #define	SMB_MINLEN_RDDIR_BUF \
77 	(EDIRENT_RECLEN(1) + EDIRENT_RECLEN(2) + EDIRENT_RECLEN(MAXNAMELEN))
78 
79 /*
80  * DP_TO_EDP
81  *
82  * Fill in an edirent_t structure with information from a dirent64_t.
83  * This allows the use of an edirent_t in code where both edirent_t's
84  * and dirent64_t's are manipulated.
85  */
86 
87 #define	DP_TO_EDP(dp, edp)						\
88 {									\
89 	ASSERT((dp));							\
90 	ASSERT((edp));							\
91 	(edp)->ed_ino = (dp)->d_ino;					\
92 	(edp)->ed_off = (dp)->d_off;					\
93 	(edp)->ed_eflags = 0;						\
94 	(edp)->ed_reclen = (dp)->d_reclen;				\
95 	(void) strlcpy((edp)->ed_name, (dp)->d_name, MAXNAMELEN);	\
96 }
97 
98 /*
99  * DP_ADVANCE
100  *
101  * In readdir operations, advance to read the next entry in a buffer
102  * returned from VOP_READDIR.  The entries are of type dirent64_t.
103  */
104 
105 #define	DP_ADVANCE(dp, dirbuf, numbytes)				\
106 {									\
107 	ASSERT((dp));							\
108 	if ((dp)->d_reclen == 0) {					\
109 		(dp) = NULL;						\
110 	} else {							\
111 		(dp) = (dirent64_t *)((char *)(dp) + (dp)->d_reclen);	\
112 		if ((dp) >= (dirent64_t *)((dirbuf) + (numbytes)))	\
113 			(dp) = NULL;					\
114 	}								\
115 }
116 
117 /*
118  * EDP_ADVANCE
119  *
120  * In readdir operations, advance to read the next entry in a buffer
121  * returned from VOP_READDIR.  The entries are of type edirent_t.
122  */
123 
124 #define	EDP_ADVANCE(edp, dirbuf, numbytes)				\
125 {									\
126 	ASSERT((edp));							\
127 	if ((edp)->ed_reclen == 0) {					\
128 		(edp) = NULL;						\
129 	} else {							\
130 		(edp) = (edirent_t *)((char *)(edp) + (edp)->ed_reclen);\
131 		if ((edp) >= (edirent_t *)((dirbuf) + (numbytes)))	\
132 			(edp) = NULL;					\
133 	}								\
134 }
135 
136 struct smb_node;
137 struct smb_request;
138 
139 /*
140  * Note: When specifying the mask for an smb_attr_t,
141  * the sa_mask, and not the sa_vattr.va_mask, should be
142  * filled in.  The #define's that should be used are those
143  * prefixed with SMB_AT_*.  Only FSIL routines should
144  * manipulate the sa_vattr.va_mask field.
145  */
146 typedef struct smb_attr {
147 	uint_t		sa_mask;	/* For both vattr and CIFS attr's */
148 	vattr_t		sa_vattr;	/* Legacy vattr */
149 	uint32_t	sa_dosattr;	/* DOS attributes */
150 	timestruc_t	sa_crtime;	/* Creation time */
151 } smb_attr_t;
152 
153 #define	SMB_AT_TYPE	0x00001
154 #define	SMB_AT_MODE	0x00002
155 #define	SMB_AT_UID	0x00004
156 #define	SMB_AT_GID	0x00008
157 #define	SMB_AT_FSID	0x00010
158 #define	SMB_AT_NODEID	0x00020
159 #define	SMB_AT_NLINK	0x00040
160 #define	SMB_AT_SIZE	0x00080
161 #define	SMB_AT_ATIME	0x00100
162 #define	SMB_AT_MTIME	0x00200
163 #define	SMB_AT_CTIME	0x00400
164 #define	SMB_AT_RDEV	0x00800
165 #define	SMB_AT_BLKSIZE	0x01000
166 #define	SMB_AT_NBLOCKS	0x02000
167 #define	SMB_AT_SEQ	0x08000
168 
169 #define	SMB_AT_DOSATTR	0x00100000
170 #define	SMB_AT_CRTIME	0x00200000
171 #define	SMB_AT_SMB	0x00300000
172 
173 #define	SMB_AT_ALL	(SMB_AT_TYPE|SMB_AT_MODE|SMB_AT_UID|SMB_AT_GID|\
174 			SMB_AT_FSID|SMB_AT_NODEID|SMB_AT_NLINK|SMB_AT_SIZE|\
175 			SMB_AT_ATIME|SMB_AT_MTIME|SMB_AT_CTIME|SMB_AT_RDEV|\
176 			SMB_AT_BLKSIZE|SMB_AT_NBLOCKS|SMB_AT_SEQ|SMB_AT_SMB)
177 
178 /*
179  * fs_online flags (meaning when set):
180  *
181  * FSOLF_NOMON		Do not monitor this FS.
182  * FSOLF_UTF8_NAME	All names in this FS should be in UTF-8 format.
183  * FSOLF_SYNCNOW	Flush all dirty blocks for this FS.
184  * FSOLF_NODRIVE	Do not assign a drive letter to this FS.
185  * FSOLF_STREAMS	This FS supports streams.
186  * FSOLF_DISABLE_OPLOCKS  Oplocks are disabled on this FS.
187  * FSOLF_RM_PENDING 	The volume is being removed (unmounted, deleted,
188  *                      zapped etc.).
189  * FSOLF_MDCACHE	Enable VFS meta-data caching for this FS.
190  * FSOLF_ERROR 		Inconsistencies detected in the volume.
191  * FSOLF_SYSTEM     	This is a system volume, no del, ren, dtq, quotas etc
192  *                      allowed
193  * FSOLF_COMPLIANT  	This volume is compliant; supports retention on
194  *                      immutable and unlinkable (no delete, no rename).
195  * FSOLF_LITE_COMPLIANT This volume has a less-stringent compliant capability
196  * FSOLF_SYSAUDIT   	This volume supports the storing of system audit logs
197  */
198 #define	FSOLF_NOEXPORT		0x00000001
199 #define	FSOLF_READONLY		0x00000002
200 #define	FSOLF_LOCKED		0x00000004
201 #define	FSOLF_NOMON		0x00000008
202 #define	FSOLF_NOSHOWMNT		0x00000010
203 #define	FSOLF_CASE_INSENSITIVE	0x00000020
204 #define	FSOLF_SUPPORTS_ACLS	0x00000040
205 #define	FSOLF_UTF8_NAME		0x00000080
206 #define	FSOLF_MIRRORING		0x00000100
207 #define	FSOLF_SYNCNOW		0x00000200
208 #define	FSOLF_NODRIVE		0x00000400
209 #define	FSOLF_OFFLINE		0x00000800
210 #define	FSOLF_STREAMS		0x00001000
211 #define	FSOLF_DISABLE_OPLOCKS	0x00002000
212 #define	FSOLF_RM_PENDING	0x00004000
213 #define	FSOLF_MDCACHE		0x00008000
214 #define	FSOLF_MNT_IN_PROGRESS	0x00010000
215 #define	FSOLF_NO_ATIME		0x00020000
216 #define	FSOLF_ERROR		0x00040000
217 #define	FSOLF_SYSTEM		0x00080000
218 #define	FSOLF_COMPLIANT		0x00100000
219 #define	FSOLF_LITE_COMPLIANT	0x00200000
220 #define	FSOLF_SYSAUDIT		0x00400000
221 #define	FSOLF_NO_CASE_SENSITIVE	0x00800000
222 #define	FSOLF_XVATTR		0x02000000
223 #define	FSOLF_DIRENTFLAGS	0x04000000
224 
225 /*
226  * The following flags are shared between live and checkpoint volumes.
227  */
228 #define	FSOLF_SHARED_FLAGS	(FSOLF_CASE_INSENSITIVE | FSOLF_UTF8_NAME | \
229     FSOLF_STREAMS)
230 
231 /*
232  * the following flags are dynamically set and reset so should not be stored
233  * in volume.
234  */
235 #define	FSOLF_MASK		~(FSOLF_NOEXPORT | FSOLF_READONLY |  \
236 				FSOLF_LOCKED | FSOLF_NOMON |        \
237 				FSOLF_SYNCNOW | FSOLF_NOSHOWMNT |   \
238 				FSOLF_NODRIVE | FSOLF_RM_PENDING)
239 
240 /*
241  * case_flag: set FHF_IGNORECASE for case-insensitive compare.
242  */
243 
244 struct fs_stream_info {
245 	char name[MAXPATHLEN];
246 	uint64_t size;
247 };
248 
249 int fhopen(const struct smb_node *, int);
250 
251 int smb_vop_init(void);
252 void smb_vop_fini(void);
253 void smb_vop_start(void);
254 int smb_vop_open(vnode_t **, int, cred_t *);
255 int smb_vop_close(vnode_t *, int, cred_t *);
256 int smb_vop_read(vnode_t *, uio_t *, cred_t *);
257 int smb_vop_write(vnode_t *, uio_t *, int, uint32_t *, cred_t *);
258 int smb_vop_getattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *);
259 int smb_vop_setattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *,
260     boolean_t);
261 int smb_vop_access(vnode_t *, int, int, vnode_t *, cred_t *);
262 void smb_vop_eaccess(vnode_t *, int *, int, vnode_t *, cred_t *);
263 int smb_vop_lookup(vnode_t *, char *, vnode_t **, char *, int, vnode_t *,
264     cred_t *);
265 int smb_vop_create(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
266     vsecattr_t *);
267 int smb_vop_remove(vnode_t *, char *, int, cred_t *);
268 int smb_vop_rename(vnode_t *, char *, vnode_t *, char *, int, cred_t *);
269 int smb_vop_mkdir(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
270     vsecattr_t *);
271 int smb_vop_rmdir(vnode_t *, char *, int, cred_t *);
272 int smb_vop_readdir(vnode_t *, uint32_t *, char *, int *, ino64_t *, vnode_t **,
273     char *, int, cred_t *);
274 int smb_vop_commit(vnode_t *, cred_t *);
275 int smb_vop_getdents(struct smb_node *, uint32_t *, uint64_t *, int32_t *,
276     char *, char *, uint32_t, struct smb_request *, cred_t *);
277 int smb_vop_statfs(vnode_t *, struct statvfs64 *, cred_t *);
278 int smb_vop_stream_lookup(vnode_t *, char *, vnode_t **, char *, vnode_t **,
279     int, vnode_t *, cred_t *);
280 int smb_vop_stream_create(vnode_t *, char *, smb_attr_t *, vnode_t **,
281     vnode_t **, int, cred_t *);
282 int smb_vop_stream_remove(vnode_t *, char *, int, cred_t *);
283 int smb_vop_stream_readdir(vnode_t *, uint32_t *, struct fs_stream_info *,
284     vnode_t **, vnode_t **, int, cred_t *);
285 int smb_vop_lookup_xattrdir(vnode_t *, vnode_t **, int, cred_t *);
286 int smb_vop_traverse_check(vnode_t **);
287 
288 int smb_vop_acl_read(vnode_t *, acl_t **, int, acl_type_t, cred_t *);
289 int smb_vop_acl_write(vnode_t *, acl_t *, int, cred_t *);
290 acl_type_t smb_vop_acl_type(vnode_t *);
291 
292 int smb_vop_shrlock(vnode_t *, uint32_t, uint32_t, uint32_t, cred_t *);
293 int smb_vop_unshrlock(vnode_t *, uint32_t, cred_t *);
294 
295 int smb_vop_frlock(vnode_t *, cred_t *, int, flock64_t *);
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif /* _SMBSRV_SMB_VOPS_H */
302