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 2007 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 <smbsrv/smb_i18n.h> 46 #include <smbsrv/smb_fsd.h> 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 #define ROOTVOL "" 53 #define CHKPNT ".chkpnt" 54 #define XATTR_DIR "xattr_dir" 55 56 #define SMB_STREAM_PREFIX "SUNWsmb" 57 #define SMB_STREAM_PREFIX_LEN (sizeof (SMB_STREAM_PREFIX) - 1) 58 59 #define MANGLE_NAMELEN 14 60 #define SMB_EOF 0x7FFFFFFF 61 62 /* 63 * SMB_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to 64 * VOP_READDIR. Its value is the size of the maximum possible edirent_t 65 * for solaris. The EDIRENT_RECLEN macro returns the size of edirent_t 66 * required for a given name length. MAXNAMELEN is the maximum 67 * filename length allowed in Solaris. The first two EDIRENT_RECLEN() 68 * macros are to allow for . and .. entries -- just a minor tweak to try 69 * and guarantee that buffer we give to VOP_READDIR will be large enough 70 * to hold ., .., and the largest possible solaris edirent_t. 71 * 72 * This bufsize will also be used when reading dirent64_t entries. 73 */ 74 75 #define SMB_MINLEN_RDDIR_BUF \ 76 (EDIRENT_RECLEN(1) + EDIRENT_RECLEN(2) + EDIRENT_RECLEN(MAXNAMELEN)) 77 78 /* 79 * DP_TO_EDP 80 * 81 * Fill in an edirent_t structure with information from a dirent64_t. 82 * This allows the use of an edirent_t in code where both edirent_t's 83 * and dirent64_t's are manipulated. 84 */ 85 86 #define DP_TO_EDP(dp, edp) \ 87 { \ 88 ASSERT((dp)); \ 89 ASSERT((edp)); \ 90 (edp)->ed_ino = (dp)->d_ino; \ 91 (edp)->ed_off = (dp)->d_off; \ 92 (edp)->ed_eflags = 0; \ 93 (edp)->ed_reclen = (dp)->d_reclen; \ 94 (void) strlcpy((edp)->ed_name, (dp)->d_name, MAXNAMELEN); \ 95 } 96 97 /* 98 * DP_ADVANCE 99 * 100 * In readdir operations, advance to read the next entry in a buffer 101 * returned from VOP_READDIR. The entries are of type dirent64_t. 102 */ 103 104 #define DP_ADVANCE(dp, dirbuf, numbytes) \ 105 { \ 106 ASSERT((dp)); \ 107 if ((dp)->d_reclen == 0) { \ 108 (dp) = NULL; \ 109 } else { \ 110 (dp) = (dirent64_t *)((char *)(dp) + (dp)->d_reclen); \ 111 if ((dp) >= (dirent64_t *)((dirbuf) + (numbytes))) \ 112 (dp) = NULL; \ 113 } \ 114 } 115 116 /* 117 * EDP_ADVANCE 118 * 119 * In readdir operations, advance to read the next entry in a buffer 120 * returned from VOP_READDIR. The entries are of type edirent_t. 121 */ 122 123 #define EDP_ADVANCE(edp, dirbuf, numbytes) \ 124 { \ 125 ASSERT((edp)); \ 126 if ((edp)->ed_reclen == 0) { \ 127 (edp) = NULL; \ 128 } else { \ 129 (edp) = (edirent_t *)((char *)(edp) + (edp)->ed_reclen);\ 130 if ((edp) >= (edirent_t *)((dirbuf) + (numbytes))) \ 131 (edp) = NULL; \ 132 } \ 133 } 134 135 struct smb_node; 136 struct smb_request; 137 138 /* 139 * Note: When specifying the mask for an smb_attr_t, 140 * the sa_mask, and not the sa_vattr.va_mask, should be 141 * filled in. The #define's that should be used are those 142 * prefixed with SMB_AT_*. Only FSIL routines should 143 * manipulate the sa_vattr.va_mask field. 144 */ 145 typedef struct smb_attr { 146 uint_t sa_mask; /* For both vattr and CIFS attr's */ 147 vattr_t sa_vattr; /* Legacy vattr */ 148 uint32_t sa_dosattr; /* DOS attributes */ 149 timestruc_t sa_crtime; /* Creation time */ 150 } smb_attr_t; 151 152 #define SMB_AT_TYPE 0x00001 153 #define SMB_AT_MODE 0x00002 154 #define SMB_AT_UID 0x00004 155 #define SMB_AT_GID 0x00008 156 #define SMB_AT_FSID 0x00010 157 #define SMB_AT_NODEID 0x00020 158 #define SMB_AT_NLINK 0x00040 159 #define SMB_AT_SIZE 0x00080 160 #define SMB_AT_ATIME 0x00100 161 #define SMB_AT_MTIME 0x00200 162 #define SMB_AT_CTIME 0x00400 163 #define SMB_AT_RDEV 0x00800 164 #define SMB_AT_BLKSIZE 0x01000 165 #define SMB_AT_NBLOCKS 0x02000 166 #define SMB_AT_SEQ 0x08000 167 168 #define SMB_AT_DOSATTR 0x00100000 169 #define SMB_AT_CRTIME 0x00200000 170 #define SMB_AT_SMB 0x00300000 171 172 #define SMB_AT_ALL (SMB_AT_TYPE|SMB_AT_MODE|SMB_AT_UID|SMB_AT_GID|\ 173 SMB_AT_FSID|SMB_AT_NODEID|SMB_AT_NLINK|SMB_AT_SIZE|\ 174 SMB_AT_ATIME|SMB_AT_MTIME|SMB_AT_CTIME|SMB_AT_RDEV|\ 175 SMB_AT_BLKSIZE|SMB_AT_NBLOCKS|SMB_AT_SEQ|SMB_AT_SMB) 176 177 /* 178 * DOS Attributes 179 * Previously defined in smbsrv/ntaccess.h 180 */ 181 182 #define FILE_ATTRIBUTE_READONLY 0x00000001 183 #define FILE_ATTRIBUTE_HIDDEN 0x00000002 184 #define FILE_ATTRIBUTE_SYSTEM 0x00000004 185 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 186 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 187 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040 188 #define FILE_ATTRIBUTE_NORMAL 0x00000080 189 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 190 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 191 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 192 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 193 #define FILE_ATTRIBUTE_OFFLINE 0x00001000 194 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 195 #define FILE_ATTRIBUTE_MODIFIED 0x00004000 196 #define FILE_ATTRIBUTE_QUARANTINED 0x00008000 197 #define FILE_ATTRIBUTE_VALID_FLAGS 0x0000dfb7 198 #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x0000dfa7 199 #define FILE_ATTRIBUTE_MASK 0x00003FFF 200 201 202 #ifndef PBSHORTCUT 203 /* remove from libsmbbase */ 204 #define FHF_SMB 0x02 205 #endif 206 207 /* DOS specific attribute bits */ 208 #define FSA_DOSATTR (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | \ 209 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN) 210 211 /* 212 * File types (FSA_FMT) and permissions (FSA_MODMASK). 213 * Restricted to lower 16-bits due to FS inode definitions. 214 */ 215 #define FSA_MTIME_SEQ 0x10000000 216 /* #define FSA_USTREAM_SKIPSEQ 0x10000000 */ 217 #define FSA_UNDEF 0007000 218 #define FSA_SUID 0004000 219 #define FSA_SGID 0002000 220 #define FSA_STICKY 0001000 221 #define FSA_UPERM 0000700 222 #define FSA_UREAD 0000400 223 #define FSA_UWRITE 0000200 224 #define FSA_UEXEC 0000100 225 #define FSA_GPERM 0000070 226 #define FSA_GREAD 0000040 227 #define FSA_GWRITE 0000020 228 #define FSA_GEXEC 0000010 229 #define FSA_OPERM 0000007 230 #define FSA_OREAD 0000004 231 #define FSA_OWRITE 0000002 232 #define FSA_OEXEC 0000001 233 234 235 #define FSA_PERM_MASK (FSA_UPERM | FSA_GPERM | FSA_OPERM) 236 #define FSA_MODMASK 0007777 /* mutable by fs_setaddr() */ 237 #define FSA_DIR_PERM 0777 /* default permission for new */ 238 /* directories */ 239 #define FSA_FILE_PERM 0666 /* default permission for new files */ 240 241 #define FCM_CREATEVERFSIZE 8 242 243 /* stability for write */ 244 #define FSSTAB_UNSTABLE 0 245 #define FSSTAB_DATA_SYNC 1 246 #define FSSTAB_FILE_SYNC 2 247 248 /* 249 * fs_online flags (meaning when set): 250 * 251 * FSOLF_NOMON Do not monitor this FS. 252 * FSOLF_UTF8_NAME All names in this FS should be in UTF-8 format. 253 * FSOLF_SYNCNOW Flush all dirty blocks for this FS. 254 * FSOLF_NODRIVE Do not assign a drive letter to this FS. 255 * FSOLF_STREAMS This FS supports streams. 256 * FSOLF_DISABLE_OPLOCKS Oplocks are disabled on this FS. 257 * FSOLF_RM_PENDING The volume is being removed (unmounted, deleted, 258 * zapped etc.). 259 * FSOLF_MDCACHE Enable VFS meta-data caching for this FS. 260 * FSOLF_ERROR Inconsistencies detected in the volume. 261 * FSOLF_SYSTEM This is a system volume, no del, ren, dtq, quotas etc 262 * allowed 263 * FSOLF_COMPLIANT This volume is compliant; supports retention on 264 * immutable and unlinkable (no delete, no rename). 265 * FSOLF_LITE_COMPLIANT This volume has a less-stringent compliant capability 266 * FSOLF_SYSAUDIT This volume supports the storing of system audit logs 267 */ 268 #define FSOLF_NOEXPORT 0x00000001 269 #define FSOLF_READONLY 0x00000002 270 #define FSOLF_LOCKED 0x00000004 271 #define FSOLF_NOMON 0x00000008 272 #define FSOLF_NOSHOWMNT 0x00000010 273 #define FSOLF_CASE_INSENSITIVE 0x00000020 274 #define FSOLF_SUPPORTS_ACLS 0x00000040 275 #define FSOLF_UTF8_NAME 0x00000080 276 #define FSOLF_MIRRORING 0x00000100 277 #define FSOLF_SYNCNOW 0x00000200 278 #define FSOLF_NODRIVE 0x00000400 279 #define FSOLF_OFFLINE 0x00000800 280 #define FSOLF_STREAMS 0x00001000 281 #define FSOLF_DISABLE_OPLOCKS 0x00002000 282 #define FSOLF_RM_PENDING 0x00004000 283 #define FSOLF_MDCACHE 0x00008000 284 #define FSOLF_MNT_IN_PROGRESS 0x00010000 285 #define FSOLF_NO_ATIME 0x00020000 286 #define FSOLF_ERROR 0x00040000 287 #define FSOLF_SYSTEM 0x00080000 288 #define FSOLF_COMPLIANT 0x00100000 289 #define FSOLF_LITE_COMPLIANT 0x00200000 290 #define FSOLF_SYSAUDIT 0x00400000 291 #define FSOLF_NO_CASE_SENSITIVE 0x00800000 292 #define FSOLF_XVATTR 0x02000000 293 #define FSOLF_DIRENTFLAGS 0x04000000 294 295 /* 296 * The following flags are shared between live and checkpoint volumes. 297 */ 298 #define FSOLF_SHARED_FLAGS (FSOLF_CASE_INSENSITIVE | FSOLF_UTF8_NAME | \ 299 FSOLF_STREAMS) 300 301 /* 302 * the following flags are dynamically set and reset so should not be stored 303 * in volume. 304 */ 305 #define FSOLF_MASK ~(FSOLF_NOEXPORT | FSOLF_READONLY | \ 306 FSOLF_LOCKED | FSOLF_NOMON | \ 307 FSOLF_SYNCNOW | FSOLF_NOSHOWMNT | \ 308 FSOLF_NODRIVE | FSOLF_RM_PENDING) 309 310 /* 311 * case_flag: set FHF_IGNORECASE for case-insensitive compare. 312 */ 313 314 struct fs_stream_info { 315 char name[MAXPATHLEN]; 316 uint64_t size; 317 }; 318 319 int fhopen(const struct smb_node *, int); 320 321 extern int smb_vop_open(vnode_t **vpp, int mode, cred_t *cred, 322 caller_context_t *ct); 323 extern int smb_vop_close(vnode_t *vp, int flag, cred_t *cred, 324 caller_context_t *ct); 325 extern int smb_vop_read(vnode_t *vp, uio_t *uiop, cred_t *cr, 326 caller_context_t *ct); 327 extern int smb_vop_write(vnode_t *vp, uio_t *uiop, unsigned int *flag, 328 uint32_t *lcount, cred_t *cr, caller_context_t *ct); 329 extern int smb_vop_getattr(vnode_t *vp, vnode_t *unnamed_vp, 330 smb_attr_t *ret_attr, int flags, cred_t *cr, caller_context_t *ct); 331 extern int smb_vop_setattr(vnode_t *vp, vnode_t *unnamed_vp, 332 smb_attr_t *set_attr, int flags, cred_t *cr, caller_context_t *ct); 333 extern int smb_vop_access(vnode_t *vp, int mode, int flags, vnode_t *dir_vp, 334 cred_t *cr); 335 extern void smb_vop_eaccess(vnode_t *vp, int *mode, int flags, vnode_t *dir_vp, 336 cred_t *cr); 337 extern int smb_vop_lookup(vnode_t *dvp, char *name, vnode_t **vpp, 338 char *od_name, int flags, vnode_t *rootvp, cred_t *cr, 339 caller_context_t *ct); 340 extern int smb_vop_create(vnode_t *dvp, char *name, smb_attr_t *attr, 341 vnode_t **vpp, int flags, cred_t *cr, caller_context_t *ct, 342 vsecattr_t *vsap); 343 extern int smb_vop_remove(vnode_t *dvp, char *name, int flags, cred_t *cr, 344 caller_context_t *ct); 345 extern int smb_vop_rename(vnode_t *from_dvp, char *from_name, vnode_t *to_dvp, 346 char *to_name, int flags, cred_t *cr, caller_context_t *ct); 347 extern int smb_vop_mkdir(vnode_t *dvp, char *name, smb_attr_t *attr, 348 vnode_t **vpp, int flags, cred_t *cr, caller_context_t *ct, 349 vsecattr_t *vsap); 350 extern int smb_vop_rmdir(vnode_t *dvp, char *name, int flags, cred_t *cr, 351 caller_context_t *ct); 352 extern int smb_vop_readdir(vnode_t *dvp, uint32_t *cookiep, char *name, 353 int *namelen, ino64_t *inop, vnode_t **vpp, char *od_name, int flags, 354 cred_t *cr, caller_context_t *ct); 355 extern int smb_vop_commit(vnode_t *vp, cred_t *cr, caller_context_t *ct); 356 extern int smb_vop_getdents(struct smb_node *dir_snode, uint32_t *cookiep, 357 uint64_t *verifierp, int32_t *dircountp, char *arg, char *pattern, 358 uint32_t flags, struct smb_request *sr, cred_t *cr, 359 caller_context_t *ct); 360 extern int smb_vop_statfs(vnode_t *vp, struct statvfs64 *statp, cred_t *cr); 361 extern int smb_vop_stream_lookup(vnode_t *fvp, char *stream_name, 362 vnode_t **vpp, char *name, vnode_t **xattrdirvpp, int flags, 363 vnode_t *rootvp, cred_t *cr, caller_context_t *ct); 364 extern int smb_vop_stream_create(vnode_t *fvp, char *stream_name, 365 smb_attr_t *attr, vnode_t **vpp, vnode_t **xattrdirvpp, int flags, 366 cred_t *cr, caller_context_t *ct); 367 extern int smb_vop_stream_remove(vnode_t *vp, char *stream_name, int flags, 368 cred_t *cr, caller_context_t *ct); 369 extern int smb_vop_stream_readdir(vnode_t *fvp, uint32_t *cookiep, 370 struct fs_stream_info *stream_info, vnode_t **vpp, vnode_t **xattrdirvp, 371 int flags, cred_t *cr, caller_context_t *ct); 372 extern int smb_vop_lookup_xattrdir(vnode_t *fvp, vnode_t **xattrdirvpp, 373 int flags, cred_t *cr, caller_context_t *ct); 374 extern int smb_vop_traverse_check(vnode_t **vpp); 375 376 int smb_vop_acl_read(vnode_t *vp, acl_t **aclp, int flags, acl_type_t acl_type, 377 cred_t *cr, caller_context_t *ct); 378 int smb_vop_acl_write(vnode_t *vp, acl_t *aclp, int flags, cred_t *cr, 379 caller_context_t *ct); 380 acl_type_t smb_vop_acl_type(vnode_t *vp); 381 382 #ifdef __cplusplus 383 } 384 #endif 385 386 #endif /* _SMBSRV_SMB_VOPS_H */ 387