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