xref: /titanic_41/usr/src/uts/common/smbsrv/smb_vops.h (revision cb3f2375234dff602cedb2b5e0afd6c27ec05ecb)
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  * DOS Attributes
180  * Previously defined in smbsrv/ntaccess.h
181  */
182 
183 #define	FILE_ATTRIBUTE_READONLY			0x00000001
184 #define	FILE_ATTRIBUTE_HIDDEN			0x00000002
185 #define	FILE_ATTRIBUTE_SYSTEM			0x00000004
186 #define	FILE_ATTRIBUTE_DIRECTORY		0x00000010
187 #define	FILE_ATTRIBUTE_ARCHIVE			0x00000020
188 #define	FILE_ATTRIBUTE_ENCRYPTED		0x00000040
189 #define	FILE_ATTRIBUTE_NORMAL			0x00000080
190 #define	FILE_ATTRIBUTE_TEMPORARY		0x00000100
191 #define	FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
192 #define	FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
193 #define	FILE_ATTRIBUTE_COMPRESSED		0x00000800
194 #define	FILE_ATTRIBUTE_OFFLINE			0x00001000
195 #define	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
196 #define	FILE_ATTRIBUTE_MODIFIED			0x00004000
197 #define	FILE_ATTRIBUTE_QUARANTINED		0x00008000
198 #define	FILE_ATTRIBUTE_VALID_FLAGS		0x0000dfb7
199 #define	FILE_ATTRIBUTE_VALID_SET_FLAGS		0x0000dfa7
200 #define	FILE_ATTRIBUTE_MASK			0x00003FFF
201 
202 
203 #ifndef PBSHORTCUT
204 /* remove from libsmbbase */
205 #define	FHF_SMB			0x02
206 #endif
207 
208 /* DOS specific attribute bits */
209 #define	FSA_DOSATTR	(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | \
210 			FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN)
211 
212 /*
213  * File types (FSA_FMT) and permissions (FSA_MODMASK).
214  * Restricted to lower 16-bits due to FS inode definitions.
215  */
216 #define	FSA_MTIME_SEQ	0x10000000
217 /* #define FSA_USTREAM_SKIPSEQ	0x10000000 */
218 #define	FSA_UNDEF	0007000
219 #define	FSA_SUID	0004000
220 #define	FSA_SGID	0002000
221 #define	FSA_STICKY	0001000
222 #define	FSA_UPERM	0000700
223 #define	FSA_UREAD	0000400
224 #define	FSA_UWRITE	0000200
225 #define	FSA_UEXEC	0000100
226 #define	FSA_GPERM	0000070
227 #define	FSA_GREAD	0000040
228 #define	FSA_GWRITE	0000020
229 #define	FSA_GEXEC	0000010
230 #define	FSA_OPERM	0000007
231 #define	FSA_OREAD	0000004
232 #define	FSA_OWRITE	0000002
233 #define	FSA_OEXEC	0000001
234 
235 
236 #define	FSA_PERM_MASK		(FSA_UPERM | FSA_GPERM | FSA_OPERM)
237 #define	FSA_MODMASK		0007777	/* mutable by fs_setaddr() */
238 #define	FSA_DIR_PERM		0777	/* default permission for new */
239 					/* directories */
240 #define	FSA_FILE_PERM		0666	/* default permission for new files */
241 
242 #define	FCM_CREATEVERFSIZE	8
243 
244 /* stability for write */
245 #define	FSSTAB_UNSTABLE		0
246 #define	FSSTAB_DATA_SYNC	1
247 #define	FSSTAB_FILE_SYNC	2
248 
249 /*
250  * fs_online flags (meaning when set):
251  *
252  * FSOLF_NOMON		Do not monitor this FS.
253  * FSOLF_UTF8_NAME	All names in this FS should be in UTF-8 format.
254  * FSOLF_SYNCNOW	Flush all dirty blocks for this FS.
255  * FSOLF_NODRIVE	Do not assign a drive letter to this FS.
256  * FSOLF_STREAMS	This FS supports streams.
257  * FSOLF_DISABLE_OPLOCKS  Oplocks are disabled on this FS.
258  * FSOLF_RM_PENDING 	The volume is being removed (unmounted, deleted,
259  *                      zapped etc.).
260  * FSOLF_MDCACHE	Enable VFS meta-data caching for this FS.
261  * FSOLF_ERROR 		Inconsistencies detected in the volume.
262  * FSOLF_SYSTEM     	This is a system volume, no del, ren, dtq, quotas etc
263  *                      allowed
264  * FSOLF_COMPLIANT  	This volume is compliant; supports retention on
265  *                      immutable and unlinkable (no delete, no rename).
266  * FSOLF_LITE_COMPLIANT This volume has a less-stringent compliant capability
267  * FSOLF_SYSAUDIT   	This volume supports the storing of system audit logs
268  */
269 #define	FSOLF_NOEXPORT		0x00000001
270 #define	FSOLF_READONLY		0x00000002
271 #define	FSOLF_LOCKED		0x00000004
272 #define	FSOLF_NOMON		0x00000008
273 #define	FSOLF_NOSHOWMNT		0x00000010
274 #define	FSOLF_CASE_INSENSITIVE	0x00000020
275 #define	FSOLF_SUPPORTS_ACLS	0x00000040
276 #define	FSOLF_UTF8_NAME		0x00000080
277 #define	FSOLF_MIRRORING		0x00000100
278 #define	FSOLF_SYNCNOW		0x00000200
279 #define	FSOLF_NODRIVE		0x00000400
280 #define	FSOLF_OFFLINE		0x00000800
281 #define	FSOLF_STREAMS		0x00001000
282 #define	FSOLF_DISABLE_OPLOCKS	0x00002000
283 #define	FSOLF_RM_PENDING	0x00004000
284 #define	FSOLF_MDCACHE		0x00008000
285 #define	FSOLF_MNT_IN_PROGRESS	0x00010000
286 #define	FSOLF_NO_ATIME		0x00020000
287 #define	FSOLF_ERROR		0x00040000
288 #define	FSOLF_SYSTEM		0x00080000
289 #define	FSOLF_COMPLIANT		0x00100000
290 #define	FSOLF_LITE_COMPLIANT	0x00200000
291 #define	FSOLF_SYSAUDIT		0x00400000
292 #define	FSOLF_NO_CASE_SENSITIVE	0x00800000
293 #define	FSOLF_XVATTR		0x02000000
294 #define	FSOLF_DIRENTFLAGS	0x04000000
295 
296 /*
297  * The following flags are shared between live and checkpoint volumes.
298  */
299 #define	FSOLF_SHARED_FLAGS	(FSOLF_CASE_INSENSITIVE | FSOLF_UTF8_NAME | \
300     FSOLF_STREAMS)
301 
302 /*
303  * the following flags are dynamically set and reset so should not be stored
304  * in volume.
305  */
306 #define	FSOLF_MASK		~(FSOLF_NOEXPORT | FSOLF_READONLY |  \
307 				FSOLF_LOCKED | FSOLF_NOMON |        \
308 				FSOLF_SYNCNOW | FSOLF_NOSHOWMNT |   \
309 				FSOLF_NODRIVE | FSOLF_RM_PENDING)
310 
311 /*
312  * case_flag: set FHF_IGNORECASE for case-insensitive compare.
313  */
314 
315 struct fs_stream_info {
316 	char name[MAXPATHLEN];
317 	uint64_t size;
318 };
319 
320 int fhopen(const struct smb_node *, int);
321 
322 int smb_vop_init(void);
323 void smb_vop_fini(void);
324 void smb_vop_start(void);
325 int smb_vop_open(vnode_t **, int, cred_t *);
326 int smb_vop_close(vnode_t *, int, cred_t *);
327 int smb_vop_read(vnode_t *, uio_t *, cred_t *);
328 int smb_vop_write(vnode_t *, uio_t *, unsigned int *, uint32_t *, cred_t *);
329 int smb_vop_getattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *);
330 int smb_vop_setattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *,
331     boolean_t);
332 int smb_vop_access(vnode_t *, int, int, vnode_t *, cred_t *);
333 void smb_vop_eaccess(vnode_t *, int *, int, vnode_t *, cred_t *);
334 int smb_vop_lookup(vnode_t *, char *, vnode_t **, char *, int, vnode_t *,
335     cred_t *);
336 int smb_vop_create(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
337     vsecattr_t *);
338 int smb_vop_remove(vnode_t *, char *, int, cred_t *);
339 int smb_vop_rename(vnode_t *, char *, vnode_t *, char *, int, cred_t *);
340 int smb_vop_mkdir(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
341     vsecattr_t *);
342 int smb_vop_rmdir(vnode_t *, char *, int, cred_t *);
343 int smb_vop_readdir(vnode_t *, uint32_t *, char *, int *, ino64_t *, vnode_t **,
344     char *, int, cred_t *);
345 int smb_vop_commit(vnode_t *, cred_t *);
346 int smb_vop_getdents(struct smb_node *, uint32_t *, uint64_t *, int32_t *,
347     char *, char *, uint32_t, struct smb_request *, cred_t *);
348 int smb_vop_statfs(vnode_t *, struct statvfs64 *, cred_t *);
349 int smb_vop_stream_lookup(vnode_t *, char *, vnode_t **, char *, vnode_t **,
350     int, vnode_t *, cred_t *);
351 int smb_vop_stream_create(vnode_t *, char *, smb_attr_t *, vnode_t **,
352     vnode_t **, int, cred_t *);
353 int smb_vop_stream_remove(vnode_t *, char *, int, cred_t *);
354 int smb_vop_stream_readdir(vnode_t *, uint32_t *, struct fs_stream_info *,
355     vnode_t **, vnode_t **, int, cred_t *);
356 int smb_vop_lookup_xattrdir(vnode_t *, vnode_t **, int, cred_t *);
357 int smb_vop_traverse_check(vnode_t **);
358 
359 int smb_vop_acl_read(vnode_t *, acl_t **, int, acl_type_t, cred_t *);
360 int smb_vop_acl_write(vnode_t *, acl_t *, int, cred_t *);
361 acl_type_t smb_vop_acl_type(vnode_t *);
362 
363 int smb_vop_shrlock(vnode_t *, uint32_t, uint32_t, uint32_t, cred_t *);
364 int smb_vop_unshrlock(vnode_t *, uint32_t, cred_t *);
365 
366 int smb_vop_frlock(vnode_t *, cred_t *, int, flock64_t *);
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #endif /* _SMBSRV_SMB_VOPS_H */
373