xref: /titanic_50/usr/src/uts/common/smbsrv/smb_vops.h (revision 1b22764f59e3a183ca5db98b6bfd27fdf2b20e02)
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	"@(#)smb_vops.h	1.9	08/08/07 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 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 #define	ROOTVOL ""
53 #define	XATTR_DIR "xattr_dir"
54 
55 #define	SMB_STREAM_PREFIX "SUNWsmb"
56 #define	SMB_STREAM_PREFIX_LEN (sizeof (SMB_STREAM_PREFIX) - 1)
57 
58 #define	SMB_SHORTNAMELEN 14
59 #define	SMB_EOF	0x7FFFFFFF
60 
61 /*
62  * SMB_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
63  *	VOP_READDIR.  Its value is the size of the maximum possible edirent_t
64  *	for solaris.  The EDIRENT_RECLEN macro returns the size of edirent_t
65  *	required for a given name length.  MAXNAMELEN is the maximum
66  *	filename length allowed in Solaris.  The first two EDIRENT_RECLEN()
67  *	macros are to allow for . and .. entries -- just a minor tweak to try
68  *	and guarantee that buffer we give to VOP_READDIR will be large enough
69  *	to hold ., .., and the largest possible solaris edirent_t.
70  *
71  *	This bufsize will also be used when reading dirent64_t entries.
72  */
73 
74 #define	SMB_MINLEN_RDDIR_BUF \
75 	(EDIRENT_RECLEN(1) + EDIRENT_RECLEN(2) + EDIRENT_RECLEN(MAXNAMELEN))
76 
77 /*
78  * DP_TO_EDP
79  *
80  * Fill in an edirent_t structure with information from a dirent64_t.
81  * This allows the use of an edirent_t in code where both edirent_t's
82  * and dirent64_t's are manipulated.
83  */
84 
85 #define	DP_TO_EDP(dp, edp)						\
86 {									\
87 	ASSERT((dp));							\
88 	ASSERT((edp));							\
89 	(edp)->ed_ino = (dp)->d_ino;					\
90 	(edp)->ed_off = (dp)->d_off;					\
91 	(edp)->ed_eflags = 0;						\
92 	(edp)->ed_reclen = (dp)->d_reclen;				\
93 	(void) strlcpy((edp)->ed_name, (dp)->d_name, MAXNAMELEN);	\
94 }
95 
96 /*
97  * DP_ADVANCE
98  *
99  * In readdir operations, advance to read the next entry in a buffer
100  * returned from VOP_READDIR.  The entries are of type dirent64_t.
101  */
102 
103 #define	DP_ADVANCE(dp, dirbuf, numbytes)				\
104 {									\
105 	ASSERT((dp));							\
106 	if ((dp)->d_reclen == 0) {					\
107 		(dp) = NULL;						\
108 	} else {							\
109 		(dp) = (dirent64_t *)((char *)(dp) + (dp)->d_reclen);	\
110 		if ((dp) >= (dirent64_t *)((dirbuf) + (numbytes)))	\
111 			(dp) = NULL;					\
112 	}								\
113 }
114 
115 /*
116  * EDP_ADVANCE
117  *
118  * In readdir operations, advance to read the next entry in a buffer
119  * returned from VOP_READDIR.  The entries are of type edirent_t.
120  */
121 
122 #define	EDP_ADVANCE(edp, dirbuf, numbytes)				\
123 {									\
124 	ASSERT((edp));							\
125 	if ((edp)->ed_reclen == 0) {					\
126 		(edp) = NULL;						\
127 	} else {							\
128 		(edp) = (edirent_t *)((char *)(edp) + (edp)->ed_reclen);\
129 		if ((edp) >= (edirent_t *)((dirbuf) + (numbytes)))	\
130 			(edp) = NULL;					\
131 	}								\
132 }
133 
134 struct smb_node;
135 struct smb_request;
136 
137 /*
138  * Note: When specifying the mask for an smb_attr_t,
139  * the sa_mask, and not the sa_vattr.va_mask, should be
140  * filled in.  The #define's that should be used are those
141  * prefixed with SMB_AT_*.  Only FSIL routines should
142  * manipulate the sa_vattr.va_mask field.
143  */
144 typedef struct smb_attr {
145 	uint_t		sa_mask;	/* For both vattr and CIFS attr's */
146 	vattr_t		sa_vattr;	/* Legacy vattr */
147 	uint32_t	sa_dosattr;	/* DOS attributes */
148 	timestruc_t	sa_crtime;	/* Creation time */
149 } smb_attr_t;
150 
151 #define	SMB_AT_TYPE	0x00001
152 #define	SMB_AT_MODE	0x00002
153 #define	SMB_AT_UID	0x00004
154 #define	SMB_AT_GID	0x00008
155 #define	SMB_AT_FSID	0x00010
156 #define	SMB_AT_NODEID	0x00020
157 #define	SMB_AT_NLINK	0x00040
158 #define	SMB_AT_SIZE	0x00080
159 #define	SMB_AT_ATIME	0x00100
160 #define	SMB_AT_MTIME	0x00200
161 #define	SMB_AT_CTIME	0x00400
162 #define	SMB_AT_RDEV	0x00800
163 #define	SMB_AT_BLKSIZE	0x01000
164 #define	SMB_AT_NBLOCKS	0x02000
165 #define	SMB_AT_SEQ	0x08000
166 
167 #define	SMB_AT_DOSATTR	0x00100000
168 #define	SMB_AT_CRTIME	0x00200000
169 #define	SMB_AT_SMB	0x00300000
170 
171 #define	SMB_AT_ALL	(SMB_AT_TYPE|SMB_AT_MODE|SMB_AT_UID|SMB_AT_GID|\
172 			SMB_AT_FSID|SMB_AT_NODEID|SMB_AT_NLINK|SMB_AT_SIZE|\
173 			SMB_AT_ATIME|SMB_AT_MTIME|SMB_AT_CTIME|SMB_AT_RDEV|\
174 			SMB_AT_BLKSIZE|SMB_AT_NBLOCKS|SMB_AT_SEQ|SMB_AT_SMB)
175 
176 struct fs_stream_info {
177 	char name[MAXPATHLEN];
178 	uint64_t size;
179 };
180 
181 int fhopen(const struct smb_node *, int);
182 
183 int smb_vop_init(void);
184 void smb_vop_fini(void);
185 void smb_vop_start(void);
186 int smb_vop_open(vnode_t **, int, cred_t *);
187 void smb_vop_close(vnode_t *, int, cred_t *);
188 int smb_vop_read(vnode_t *, uio_t *, cred_t *);
189 int smb_vop_write(vnode_t *, uio_t *, int, uint32_t *, cred_t *);
190 int smb_vop_getattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *);
191 int smb_vop_setattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *);
192 int smb_vop_access(vnode_t *, int, int, vnode_t *, cred_t *);
193 void smb_vop_eaccess(vnode_t *, int *, int, vnode_t *, cred_t *);
194 int smb_vop_lookup(vnode_t *, char *, vnode_t **, char *, int, vnode_t *,
195     cred_t *);
196 int smb_vop_create(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
197     vsecattr_t *);
198 int smb_vop_remove(vnode_t *, char *, int, cred_t *);
199 int smb_vop_rename(vnode_t *, char *, vnode_t *, char *, int, cred_t *);
200 int smb_vop_mkdir(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
201     vsecattr_t *);
202 int smb_vop_rmdir(vnode_t *, char *, int, cred_t *);
203 int smb_vop_readdir(vnode_t *, uint32_t *, char *, int *, ino64_t *, vnode_t **,
204     char *, int, cred_t *);
205 int smb_vop_commit(vnode_t *, cred_t *);
206 int smb_vop_getdents(struct smb_node *, uint32_t *, uint64_t *, int32_t *,
207     char *, char *, uint32_t, struct smb_request *, cred_t *);
208 int smb_vop_statfs(vnode_t *, struct statvfs64 *, cred_t *);
209 int smb_vop_stream_lookup(vnode_t *, char *, vnode_t **, char *, vnode_t **,
210     int, vnode_t *, cred_t *);
211 int smb_vop_stream_create(vnode_t *, char *, smb_attr_t *, vnode_t **,
212     vnode_t **, int, cred_t *);
213 int smb_vop_stream_remove(vnode_t *, char *, int, cred_t *);
214 int smb_vop_stream_readdir(vnode_t *, uint32_t *, struct fs_stream_info *,
215     vnode_t **, vnode_t **, int, cred_t *);
216 int smb_vop_lookup_xattrdir(vnode_t *, vnode_t **, int, cred_t *);
217 int smb_vop_traverse_check(vnode_t **);
218 
219 int smb_vop_acl_read(vnode_t *, acl_t **, int, acl_type_t, cred_t *);
220 int smb_vop_acl_write(vnode_t *, acl_t *, int, cred_t *);
221 acl_type_t smb_vop_acl_type(vnode_t *);
222 
223 int smb_vop_shrlock(vnode_t *, uint32_t, uint32_t, uint32_t, cred_t *);
224 int smb_vop_unshrlock(vnode_t *, uint32_t, cred_t *);
225 
226 int smb_vop_frlock(vnode_t *, cred_t *, int, flock64_t *);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif /* _SMBSRV_SMB_VOPS_H */
233