xref: /onnv-gate/usr/src/uts/common/smbsrv/smb_vops.h (revision 6600:4e63bcd27ae9)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
225772Sas200622  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw #ifndef _SMBSRV_SMB_VOPS_H
275331Samw #define	_SMBSRV_SMB_VOPS_H
285331Samw 
295331Samw #pragma ident	"%Z%%M%	%I%	%E% SMI"
305331Samw 
315331Samw /*
325331Samw  * Common file system interfaces and definitions.
335331Samw  */
345331Samw 
355331Samw #include <sys/types.h>
365331Samw #include <sys/param.h>
375331Samw #include <sys/file.h>
385331Samw #include <sys/time.h>
395331Samw #include <sys/mntent.h>
405331Samw #include <sys/uio.h>
415331Samw #include <sys/vnode.h>
425331Samw #include <sys/vfs.h>
435331Samw #include <sys/refstr.h>
445331Samw #include <sys/acl.h>
45*6600Sas200622 #include <sys/fcntl.h>
465331Samw #include <smbsrv/smb_i18n.h>
475331Samw #include <smbsrv/smb_fsd.h>
485331Samw 
495331Samw #ifdef __cplusplus
505331Samw extern "C" {
515331Samw #endif
525331Samw 
535331Samw #define	ROOTVOL ""
545331Samw #define	CHKPNT ".chkpnt"
555331Samw #define	XATTR_DIR "xattr_dir"
565331Samw 
575331Samw #define	SMB_STREAM_PREFIX "SUNWsmb"
585331Samw #define	SMB_STREAM_PREFIX_LEN (sizeof (SMB_STREAM_PREFIX) - 1)
595331Samw 
605331Samw #define	MANGLE_NAMELEN 14
615331Samw #define	SMB_EOF	0x7FFFFFFF
625331Samw 
635331Samw /*
645331Samw  * SMB_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
655331Samw  *	VOP_READDIR.  Its value is the size of the maximum possible edirent_t
665331Samw  *	for solaris.  The EDIRENT_RECLEN macro returns the size of edirent_t
675331Samw  *	required for a given name length.  MAXNAMELEN is the maximum
685331Samw  *	filename length allowed in Solaris.  The first two EDIRENT_RECLEN()
695331Samw  *	macros are to allow for . and .. entries -- just a minor tweak to try
705331Samw  *	and guarantee that buffer we give to VOP_READDIR will be large enough
715331Samw  *	to hold ., .., and the largest possible solaris edirent_t.
725331Samw  *
735331Samw  *	This bufsize will also be used when reading dirent64_t entries.
745331Samw  */
755331Samw 
765331Samw #define	SMB_MINLEN_RDDIR_BUF \
775331Samw 	(EDIRENT_RECLEN(1) + EDIRENT_RECLEN(2) + EDIRENT_RECLEN(MAXNAMELEN))
785331Samw 
795331Samw /*
805331Samw  * DP_TO_EDP
815331Samw  *
825331Samw  * Fill in an edirent_t structure with information from a dirent64_t.
835331Samw  * This allows the use of an edirent_t in code where both edirent_t's
845331Samw  * and dirent64_t's are manipulated.
855331Samw  */
865331Samw 
875331Samw #define	DP_TO_EDP(dp, edp)						\
885331Samw {									\
895331Samw 	ASSERT((dp));							\
905331Samw 	ASSERT((edp));							\
915331Samw 	(edp)->ed_ino = (dp)->d_ino;					\
925331Samw 	(edp)->ed_off = (dp)->d_off;					\
935331Samw 	(edp)->ed_eflags = 0;						\
945331Samw 	(edp)->ed_reclen = (dp)->d_reclen;				\
955331Samw 	(void) strlcpy((edp)->ed_name, (dp)->d_name, MAXNAMELEN);	\
965331Samw }
975331Samw 
985331Samw /*
995331Samw  * DP_ADVANCE
1005331Samw  *
1015331Samw  * In readdir operations, advance to read the next entry in a buffer
1025331Samw  * returned from VOP_READDIR.  The entries are of type dirent64_t.
1035331Samw  */
1045331Samw 
1055331Samw #define	DP_ADVANCE(dp, dirbuf, numbytes)				\
1065331Samw {									\
1075331Samw 	ASSERT((dp));							\
1085331Samw 	if ((dp)->d_reclen == 0) {					\
1095331Samw 		(dp) = NULL;						\
1105331Samw 	} else {							\
1115331Samw 		(dp) = (dirent64_t *)((char *)(dp) + (dp)->d_reclen);	\
1125331Samw 		if ((dp) >= (dirent64_t *)((dirbuf) + (numbytes)))	\
1135331Samw 			(dp) = NULL;					\
1145331Samw 	}								\
1155331Samw }
1165331Samw 
1175331Samw /*
1185331Samw  * EDP_ADVANCE
1195331Samw  *
1205331Samw  * In readdir operations, advance to read the next entry in a buffer
1215331Samw  * returned from VOP_READDIR.  The entries are of type edirent_t.
1225331Samw  */
1235331Samw 
1245331Samw #define	EDP_ADVANCE(edp, dirbuf, numbytes)				\
1255331Samw {									\
1265331Samw 	ASSERT((edp));							\
1275331Samw 	if ((edp)->ed_reclen == 0) {					\
1285331Samw 		(edp) = NULL;						\
1295331Samw 	} else {							\
1305331Samw 		(edp) = (edirent_t *)((char *)(edp) + (edp)->ed_reclen);\
1315331Samw 		if ((edp) >= (edirent_t *)((dirbuf) + (numbytes)))	\
1325331Samw 			(edp) = NULL;					\
1335331Samw 	}								\
1345331Samw }
1355331Samw 
1365331Samw struct smb_node;
1375331Samw struct smb_request;
1385331Samw 
1395331Samw /*
1405331Samw  * Note: When specifying the mask for an smb_attr_t,
1415331Samw  * the sa_mask, and not the sa_vattr.va_mask, should be
1425331Samw  * filled in.  The #define's that should be used are those
1435331Samw  * prefixed with SMB_AT_*.  Only FSIL routines should
1445331Samw  * manipulate the sa_vattr.va_mask field.
1455331Samw  */
1465331Samw typedef struct smb_attr {
1475331Samw 	uint_t		sa_mask;	/* For both vattr and CIFS attr's */
1485331Samw 	vattr_t		sa_vattr;	/* Legacy vattr */
1495331Samw 	uint32_t	sa_dosattr;	/* DOS attributes */
1505331Samw 	timestruc_t	sa_crtime;	/* Creation time */
1515331Samw } smb_attr_t;
1525331Samw 
1535331Samw #define	SMB_AT_TYPE	0x00001
1545331Samw #define	SMB_AT_MODE	0x00002
1555331Samw #define	SMB_AT_UID	0x00004
1565331Samw #define	SMB_AT_GID	0x00008
1575331Samw #define	SMB_AT_FSID	0x00010
1585331Samw #define	SMB_AT_NODEID	0x00020
1595331Samw #define	SMB_AT_NLINK	0x00040
1605331Samw #define	SMB_AT_SIZE	0x00080
1615331Samw #define	SMB_AT_ATIME	0x00100
1625331Samw #define	SMB_AT_MTIME	0x00200
1635331Samw #define	SMB_AT_CTIME	0x00400
1645331Samw #define	SMB_AT_RDEV	0x00800
1655331Samw #define	SMB_AT_BLKSIZE	0x01000
1665331Samw #define	SMB_AT_NBLOCKS	0x02000
1675331Samw #define	SMB_AT_SEQ	0x08000
1685331Samw 
1695331Samw #define	SMB_AT_DOSATTR	0x00100000
1705331Samw #define	SMB_AT_CRTIME	0x00200000
1715331Samw #define	SMB_AT_SMB	0x00300000
1725331Samw 
1735331Samw #define	SMB_AT_ALL	(SMB_AT_TYPE|SMB_AT_MODE|SMB_AT_UID|SMB_AT_GID|\
1745331Samw 			SMB_AT_FSID|SMB_AT_NODEID|SMB_AT_NLINK|SMB_AT_SIZE|\
1755331Samw 			SMB_AT_ATIME|SMB_AT_MTIME|SMB_AT_CTIME|SMB_AT_RDEV|\
1765331Samw 			SMB_AT_BLKSIZE|SMB_AT_NBLOCKS|SMB_AT_SEQ|SMB_AT_SMB)
1775331Samw 
1785331Samw /*
1795331Samw  * DOS Attributes
1805331Samw  * Previously defined in smbsrv/ntaccess.h
1815331Samw  */
1825331Samw 
1835331Samw #define	FILE_ATTRIBUTE_READONLY			0x00000001
1845331Samw #define	FILE_ATTRIBUTE_HIDDEN			0x00000002
1855331Samw #define	FILE_ATTRIBUTE_SYSTEM			0x00000004
1865331Samw #define	FILE_ATTRIBUTE_DIRECTORY		0x00000010
1875331Samw #define	FILE_ATTRIBUTE_ARCHIVE			0x00000020
1885331Samw #define	FILE_ATTRIBUTE_ENCRYPTED		0x00000040
1895331Samw #define	FILE_ATTRIBUTE_NORMAL			0x00000080
1905331Samw #define	FILE_ATTRIBUTE_TEMPORARY		0x00000100
1915331Samw #define	FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
1925331Samw #define	FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
1935331Samw #define	FILE_ATTRIBUTE_COMPRESSED		0x00000800
1945331Samw #define	FILE_ATTRIBUTE_OFFLINE			0x00001000
1955331Samw #define	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
1965331Samw #define	FILE_ATTRIBUTE_MODIFIED			0x00004000
1975331Samw #define	FILE_ATTRIBUTE_QUARANTINED		0x00008000
1985331Samw #define	FILE_ATTRIBUTE_VALID_FLAGS		0x0000dfb7
1995331Samw #define	FILE_ATTRIBUTE_VALID_SET_FLAGS		0x0000dfa7
2005331Samw #define	FILE_ATTRIBUTE_MASK			0x00003FFF
2015331Samw 
2025331Samw 
2035331Samw #ifndef PBSHORTCUT
2045331Samw /* remove from libsmbbase */
2055331Samw #define	FHF_SMB			0x02
2065331Samw #endif
2075331Samw 
2085331Samw /* DOS specific attribute bits */
2095331Samw #define	FSA_DOSATTR	(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | \
2105331Samw 			FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN)
2115331Samw 
2125331Samw /*
2135331Samw  * File types (FSA_FMT) and permissions (FSA_MODMASK).
2145331Samw  * Restricted to lower 16-bits due to FS inode definitions.
2155331Samw  */
2165331Samw #define	FSA_MTIME_SEQ	0x10000000
2175331Samw /* #define FSA_USTREAM_SKIPSEQ	0x10000000 */
2185331Samw #define	FSA_UNDEF	0007000
2195331Samw #define	FSA_SUID	0004000
2205331Samw #define	FSA_SGID	0002000
2215331Samw #define	FSA_STICKY	0001000
2225331Samw #define	FSA_UPERM	0000700
2235331Samw #define	FSA_UREAD	0000400
2245331Samw #define	FSA_UWRITE	0000200
2255331Samw #define	FSA_UEXEC	0000100
2265331Samw #define	FSA_GPERM	0000070
2275331Samw #define	FSA_GREAD	0000040
2285331Samw #define	FSA_GWRITE	0000020
2295331Samw #define	FSA_GEXEC	0000010
2305331Samw #define	FSA_OPERM	0000007
2315331Samw #define	FSA_OREAD	0000004
2325331Samw #define	FSA_OWRITE	0000002
2335331Samw #define	FSA_OEXEC	0000001
2345331Samw 
2355331Samw 
2365331Samw #define	FSA_PERM_MASK		(FSA_UPERM | FSA_GPERM | FSA_OPERM)
2375331Samw #define	FSA_MODMASK		0007777	/* mutable by fs_setaddr() */
2385331Samw #define	FSA_DIR_PERM		0777	/* default permission for new */
2395331Samw 					/* directories */
2405331Samw #define	FSA_FILE_PERM		0666	/* default permission for new files */
2415331Samw 
2425331Samw #define	FCM_CREATEVERFSIZE	8
2435331Samw 
2445331Samw /* stability for write */
2455331Samw #define	FSSTAB_UNSTABLE		0
2465331Samw #define	FSSTAB_DATA_SYNC	1
2475331Samw #define	FSSTAB_FILE_SYNC	2
2485331Samw 
2495331Samw /*
2505331Samw  * fs_online flags (meaning when set):
2515331Samw  *
2525331Samw  * FSOLF_NOMON		Do not monitor this FS.
2535331Samw  * FSOLF_UTF8_NAME	All names in this FS should be in UTF-8 format.
2545331Samw  * FSOLF_SYNCNOW	Flush all dirty blocks for this FS.
2555331Samw  * FSOLF_NODRIVE	Do not assign a drive letter to this FS.
2565331Samw  * FSOLF_STREAMS	This FS supports streams.
2575331Samw  * FSOLF_DISABLE_OPLOCKS  Oplocks are disabled on this FS.
2585331Samw  * FSOLF_RM_PENDING 	The volume is being removed (unmounted, deleted,
2595331Samw  *                      zapped etc.).
2605331Samw  * FSOLF_MDCACHE	Enable VFS meta-data caching for this FS.
2615331Samw  * FSOLF_ERROR 		Inconsistencies detected in the volume.
2625331Samw  * FSOLF_SYSTEM     	This is a system volume, no del, ren, dtq, quotas etc
2635331Samw  *                      allowed
2645331Samw  * FSOLF_COMPLIANT  	This volume is compliant; supports retention on
2655331Samw  *                      immutable and unlinkable (no delete, no rename).
2665331Samw  * FSOLF_LITE_COMPLIANT This volume has a less-stringent compliant capability
2675331Samw  * FSOLF_SYSAUDIT   	This volume supports the storing of system audit logs
2685331Samw  */
2695331Samw #define	FSOLF_NOEXPORT		0x00000001
2705331Samw #define	FSOLF_READONLY		0x00000002
2715331Samw #define	FSOLF_LOCKED		0x00000004
2725331Samw #define	FSOLF_NOMON		0x00000008
2735331Samw #define	FSOLF_NOSHOWMNT		0x00000010
2745331Samw #define	FSOLF_CASE_INSENSITIVE	0x00000020
2755331Samw #define	FSOLF_SUPPORTS_ACLS	0x00000040
2765331Samw #define	FSOLF_UTF8_NAME		0x00000080
2775331Samw #define	FSOLF_MIRRORING		0x00000100
2785331Samw #define	FSOLF_SYNCNOW		0x00000200
2795331Samw #define	FSOLF_NODRIVE		0x00000400
2805331Samw #define	FSOLF_OFFLINE		0x00000800
2815331Samw #define	FSOLF_STREAMS		0x00001000
2825331Samw #define	FSOLF_DISABLE_OPLOCKS	0x00002000
2835331Samw #define	FSOLF_RM_PENDING	0x00004000
2845331Samw #define	FSOLF_MDCACHE		0x00008000
2855331Samw #define	FSOLF_MNT_IN_PROGRESS	0x00010000
2865331Samw #define	FSOLF_NO_ATIME		0x00020000
2875331Samw #define	FSOLF_ERROR		0x00040000
2885331Samw #define	FSOLF_SYSTEM		0x00080000
2895331Samw #define	FSOLF_COMPLIANT		0x00100000
2905331Samw #define	FSOLF_LITE_COMPLIANT	0x00200000
2915331Samw #define	FSOLF_SYSAUDIT		0x00400000
2925331Samw #define	FSOLF_NO_CASE_SENSITIVE	0x00800000
2935331Samw #define	FSOLF_XVATTR		0x02000000
2945331Samw #define	FSOLF_DIRENTFLAGS	0x04000000
2955331Samw 
2965331Samw /*
2975331Samw  * The following flags are shared between live and checkpoint volumes.
2985331Samw  */
2995331Samw #define	FSOLF_SHARED_FLAGS	(FSOLF_CASE_INSENSITIVE | FSOLF_UTF8_NAME | \
3005331Samw     FSOLF_STREAMS)
3015331Samw 
3025331Samw /*
3035331Samw  * the following flags are dynamically set and reset so should not be stored
3045331Samw  * in volume.
3055331Samw  */
3065331Samw #define	FSOLF_MASK		~(FSOLF_NOEXPORT | FSOLF_READONLY |  \
3075331Samw 				FSOLF_LOCKED | FSOLF_NOMON |        \
3085331Samw 				FSOLF_SYNCNOW | FSOLF_NOSHOWMNT |   \
3095331Samw 				FSOLF_NODRIVE | FSOLF_RM_PENDING)
3105331Samw 
3115331Samw /*
3125331Samw  * case_flag: set FHF_IGNORECASE for case-insensitive compare.
3135331Samw  */
3145331Samw 
3155331Samw struct fs_stream_info {
3165331Samw 	char name[MAXPATHLEN];
3175331Samw 	uint64_t size;
3185331Samw };
3195331Samw 
3205331Samw int fhopen(const struct smb_node *, int);
3215331Samw 
3226139Sjb150015 int smb_vop_init(void);
3236139Sjb150015 void smb_vop_fini(void);
3246139Sjb150015 void smb_vop_start(void);
3256139Sjb150015 int smb_vop_open(vnode_t **, int, cred_t *);
3266139Sjb150015 int smb_vop_close(vnode_t *, int, cred_t *);
3276139Sjb150015 int smb_vop_read(vnode_t *, uio_t *, cred_t *);
3286139Sjb150015 int smb_vop_write(vnode_t *, uio_t *, unsigned int *, uint32_t *, cred_t *);
3296139Sjb150015 int smb_vop_getattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *);
3306139Sjb150015 int smb_vop_setattr(vnode_t *, vnode_t *, smb_attr_t *, int, cred_t *,
3316139Sjb150015     boolean_t);
3326139Sjb150015 int smb_vop_access(vnode_t *, int, int, vnode_t *, cred_t *);
3336139Sjb150015 void smb_vop_eaccess(vnode_t *, int *, int, vnode_t *, cred_t *);
3346139Sjb150015 int smb_vop_lookup(vnode_t *, char *, vnode_t **, char *, int, vnode_t *,
3355772Sas200622     cred_t *);
3366139Sjb150015 int smb_vop_create(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
3376139Sjb150015     vsecattr_t *);
3386139Sjb150015 int smb_vop_remove(vnode_t *, char *, int, cred_t *);
3396139Sjb150015 int smb_vop_rename(vnode_t *, char *, vnode_t *, char *, int, cred_t *);
3406139Sjb150015 int smb_vop_mkdir(vnode_t *, char *, smb_attr_t *, vnode_t **, int, cred_t *,
3416139Sjb150015     vsecattr_t *);
3426139Sjb150015 int smb_vop_rmdir(vnode_t *, char *, int, cred_t *);
3436139Sjb150015 int smb_vop_readdir(vnode_t *, uint32_t *, char *, int *, ino64_t *, vnode_t **,
3445772Sas200622     char *, int, cred_t *);
3456139Sjb150015 int smb_vop_commit(vnode_t *, cred_t *);
3466139Sjb150015 int smb_vop_getdents(struct smb_node *, uint32_t *, uint64_t *, int32_t *,
3476139Sjb150015     char *, char *, uint32_t, struct smb_request *, cred_t *);
3486139Sjb150015 int smb_vop_statfs(vnode_t *, struct statvfs64 *, cred_t *);
3496139Sjb150015 int smb_vop_stream_lookup(vnode_t *, char *, vnode_t **, char *, vnode_t **,
3506139Sjb150015     int, vnode_t *, cred_t *);
3516139Sjb150015 int smb_vop_stream_create(vnode_t *, char *, smb_attr_t *, vnode_t **,
3526139Sjb150015     vnode_t **, int, cred_t *);
3536139Sjb150015 int smb_vop_stream_remove(vnode_t *, char *, int, cred_t *);
3546139Sjb150015 int smb_vop_stream_readdir(vnode_t *, uint32_t *, struct fs_stream_info *,
3556139Sjb150015     vnode_t **, vnode_t **, int, cred_t *);
3566139Sjb150015 int smb_vop_lookup_xattrdir(vnode_t *, vnode_t **, int, cred_t *);
3576139Sjb150015 int smb_vop_traverse_check(vnode_t **);
3585331Samw 
3595772Sas200622 int smb_vop_acl_read(vnode_t *, acl_t **, int, acl_type_t, cred_t *);
3605772Sas200622 int smb_vop_acl_write(vnode_t *, acl_t *, int, cred_t *);
3615772Sas200622 acl_type_t smb_vop_acl_type(vnode_t *);
3625772Sas200622 
3635772Sas200622 int smb_vop_shrlock(vnode_t *, uint32_t, uint32_t, uint32_t, cred_t *);
3645772Sas200622 int smb_vop_unshrlock(vnode_t *, uint32_t, cred_t *);
3655331Samw 
366*6600Sas200622 int smb_vop_frlock(vnode_t *, cred_t *, int, flock64_t *);
367*6600Sas200622 
3685331Samw #ifdef __cplusplus
3695331Samw }
3705331Samw #endif
3715331Samw 
3725331Samw #endif /* _SMBSRV_SMB_VOPS_H */
373