xref: /onnv-gate/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr.h (revision 11564:184d27948276)
16007Sthurlow /*
26007Sthurlow  * Copyright (c) 2000-2001, Boris Popov
36007Sthurlow  * All rights reserved.
46007Sthurlow  *
56007Sthurlow  * Redistribution and use in source and binary forms, with or without
66007Sthurlow  * modification, are permitted provided that the following conditions
76007Sthurlow  * are met:
86007Sthurlow  * 1. Redistributions of source code must retain the above copyright
96007Sthurlow  *    notice, this list of conditions and the following disclaimer.
106007Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
116007Sthurlow  *    notice, this list of conditions and the following disclaimer in the
126007Sthurlow  *    documentation and/or other materials provided with the distribution.
136007Sthurlow  * 3. All advertising materials mentioning features or use of this software
146007Sthurlow  *    must display the following acknowledgement:
156007Sthurlow  *    This product includes software developed by Boris Popov.
166007Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
176007Sthurlow  *    may be used to endorse or promote products derived from this software
186007Sthurlow  *    without specific prior written permission.
196007Sthurlow  *
206007Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
216007Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
226007Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
236007Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
246007Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
256007Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
266007Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
276007Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
286007Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
296007Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
306007Sthurlow  * SUCH DAMAGE.
316007Sthurlow  *
326007Sthurlow  * $Id: smbfs_subr.h,v 1.25 2005/03/17 01:23:40 lindak Exp $
336007Sthurlow  */
346007Sthurlow 
356007Sthurlow /*
36*11564SGordon.Ross@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
376007Sthurlow  * Use is subject to license terms.
386007Sthurlow  */
396007Sthurlow 
406007Sthurlow #ifndef _FS_SMBFS_SMBFS_SUBR_H_
416007Sthurlow #define	_FS_SMBFS_SMBFS_SUBR_H_
426007Sthurlow 
436007Sthurlow #include <sys/cmn_err.h>
446711Sgwr #include <netsmb/mchain.h>
456007Sthurlow 
466007Sthurlow #if defined(DEBUG) || defined(lint)
476007Sthurlow #define	SMB_VNODE_DEBUG 1
486007Sthurlow #endif
496007Sthurlow 
506007Sthurlow #ifndef FALSE
516007Sthurlow #define	FALSE   (0)
526007Sthurlow #endif
536007Sthurlow 
546007Sthurlow #ifndef TRUE
556007Sthurlow #define	TRUE    (1)
566007Sthurlow #endif
576007Sthurlow 
586007Sthurlow /*
596007Sthurlow  * Let's use C99 standard variadic macros!
606007Sthurlow  * Also the C99 __func__ (function name) feature.
616007Sthurlow  */
626007Sthurlow #define	SMBFSERR(...) \
636007Sthurlow 	smb_errmsg(CE_NOTE, __func__, __VA_ARGS__)
646007Sthurlow #define	SMBVDEBUG(...) \
656007Sthurlow 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
666007Sthurlow 
676007Sthurlow /*
686007Sthurlow  * Possible lock commands
696007Sthurlow  */
706007Sthurlow #define	SMB_LOCK_EXCL		0
716007Sthurlow #define	SMB_LOCK_SHARED		1
726007Sthurlow #define	SMB_LOCK_RELEASE	2
736007Sthurlow 
746007Sthurlow struct smb_cred;
756007Sthurlow struct smb_vc;
766007Sthurlow struct statvfs;
776007Sthurlow struct timespec;
786007Sthurlow 
797040Sgwr /*
807040Sgwr  * Types of find_first, find_next context objects
817040Sgwr  */
827040Sgwr typedef enum {
837040Sgwr 	ft_LM1 = 1,
847040Sgwr 	ft_LM2,
857040Sgwr 	ft_XA
867040Sgwr } smbfs_fctx_type_t;
876007Sthurlow 
886007Sthurlow /*
896007Sthurlow  * Context to perform findfirst/findnext/findclose operations
906007Sthurlow  */
916007Sthurlow #define	SMBFS_RDD_FINDFIRST	0x01
926007Sthurlow #define	SMBFS_RDD_EOF		0x02
936007Sthurlow #define	SMBFS_RDD_FINDSINGLE	0x04
947040Sgwr /* note	SMBFS_RDD_USESEARCH	0x08 replaced by smbfs_fctx_type */
956007Sthurlow #define	SMBFS_RDD_NOCLOSE	0x10
966007Sthurlow 
976007Sthurlow /*
986007Sthurlow  * Search context supplied by server
996007Sthurlow  */
1006007Sthurlow #define	SMB_SKEYLEN		21			/* search context */
1016007Sthurlow #define	SMB_DENTRYLEN		(SMB_SKEYLEN + 22)	/* entire entry */
1026007Sthurlow 
1036007Sthurlow struct smbfs_fctx {
1046007Sthurlow 	/*
1056007Sthurlow 	 * Setable values
1066007Sthurlow 	 */
1077040Sgwr 	smbfs_fctx_type_t	f_type;
1086007Sthurlow 	int		f_flags;	/* SMBFS_RDD_ */
1096007Sthurlow 	/*
1106007Sthurlow 	 * Return values
1116007Sthurlow 	 */
1126007Sthurlow 	struct smbfattr	f_attr;		/* current attributes */
11311332SGordon.Ross@Sun.COM 	u_longlong_t	f_inum;		/* current I number */
1146007Sthurlow 	char		*f_name;	/* current file name */
1156007Sthurlow 	int		f_nmlen;	/* name len */
1166007Sthurlow 	int		f_namesz;	/* memory allocated */
1176007Sthurlow 	/*
1186007Sthurlow 	 * Internal variables
1196007Sthurlow 	 */
1206007Sthurlow 	uint16_t	f_limit;	/* maximum number of entries */
1216007Sthurlow 	uint16_t	f_attrmask;	/* SMB_FA_ */
1226007Sthurlow 	int		f_wclen;
1236007Sthurlow 	const char	*f_wildcard;
1246007Sthurlow 	struct smbnode	*f_dnp;
1256007Sthurlow 	struct smb_cred	*f_scred;
1266007Sthurlow 	struct smb_share	*f_ssp;
1276007Sthurlow 	union {
1286007Sthurlow 		struct smb_rq *uf_rq;
1296007Sthurlow 		struct smb_t2rq *uf_t2;
1306007Sthurlow 	} f_urq;
1316007Sthurlow 	int		f_left;		/* entries left */
1326007Sthurlow 	int		f_ecnt;		/* entries left in current response */
1336007Sthurlow 	int		f_eofs;		/* entry offset in data block */
1346007Sthurlow 	uchar_t 	f_skey[SMB_SKEYLEN]; /* server side search context */
1356007Sthurlow 	uchar_t		f_fname[8 + 1 + 3 + 1]; /* for 8.3 filenames */
1366007Sthurlow 	uint16_t	f_Sid;		/* Search handle (like a FID) */
1376007Sthurlow 	uint16_t	f_infolevel;
1386007Sthurlow 	int		f_rnamelen;
1396007Sthurlow 	char		*f_rname;	/* resume name */
1406007Sthurlow 	int		f_rnameofs;
1416007Sthurlow 	int		f_otws;		/* # over-the-wire ops so far */
1426007Sthurlow 	char		*f_firstnm;	/* first filename we got back */
1436007Sthurlow 	int		f_firstnmlen;
1446007Sthurlow 	int		f_rkey;		/* resume key */
1456007Sthurlow };
1466007Sthurlow typedef struct smbfs_fctx smbfs_fctx_t;
1476007Sthurlow 
1486007Sthurlow #define	f_rq	f_urq.uf_rq
1496007Sthurlow #define	f_t2	f_urq.uf_t2
1506007Sthurlow 
1516007Sthurlow /*
15211332SGordon.Ross@Sun.COM  * smb level (smbfs_smb.c)
1536007Sthurlow  */
1546007Sthurlow int  smbfs_smb_lock(struct smbnode *np, int op, caddr_t id,
1556007Sthurlow 	offset_t start, uint64_t len,	int largelock,
1566007Sthurlow 	struct smb_cred *scrp, uint32_t timeout);
15710023SGordon.Ross@Sun.COM int  smbfs_smb_qfsattr(struct smb_share *ssp, struct smb_fs_attr_info *,
1586007Sthurlow 	struct smb_cred *scrp);
1596007Sthurlow int  smbfs_smb_statfs(struct smb_share *ssp, statvfs64_t *sbp,
1606007Sthurlow 	struct smb_cred *scrp);
1616007Sthurlow int  smbfs_smb_setfsize(struct smbnode *np, uint16_t fid, uint64_t newsize,
1626007Sthurlow 	struct smb_cred *scrp);
1636007Sthurlow 
1646007Sthurlow int  smbfs_smb_getfattr(struct smbnode *np, struct smbfattr *fap,
1656007Sthurlow 	struct smb_cred *scrp);
1666007Sthurlow 
16711332SGordon.Ross@Sun.COM int  smbfs_smb_setfattr(struct smbnode *np, int fid,
1686007Sthurlow 	uint32_t attr, struct timespec *mtime, struct timespec *atime,
1696007Sthurlow 	struct smb_cred *scrp);
1706007Sthurlow 
17111332SGordon.Ross@Sun.COM int  smbfs_smb_open(struct smbnode *np, const char *name, int nmlen,
17211332SGordon.Ross@Sun.COM 	int xattr, uint32_t rights, struct smb_cred *scrp,
17311332SGordon.Ross@Sun.COM 	uint16_t *fidp, uint32_t *rightsp, struct smbfattr *fap);
1746007Sthurlow int  smbfs_smb_tmpopen(struct smbnode *np, uint32_t rights,
1756007Sthurlow 	struct smb_cred *scrp, uint16_t *fidp);
1766007Sthurlow int  smbfs_smb_close(struct smb_share *ssp, uint16_t fid,
1776007Sthurlow 	struct timespec *mtime, struct smb_cred *scrp);
1786007Sthurlow int  smbfs_smb_tmpclose(struct smbnode *ssp, uint16_t fid,
1796007Sthurlow 	struct smb_cred *scrp);
18011332SGordon.Ross@Sun.COM int  smbfs_smb_create(struct smbnode *dnp, const char *name, int nmlen,
18111332SGordon.Ross@Sun.COM 	int xattr, uint32_t disp, struct smb_cred *scrp, uint16_t *fidp);
1826007Sthurlow int  smbfs_smb_delete(struct smbnode *np, struct smb_cred *scrp,
1836007Sthurlow 	const char *name, int len, int xattr);
1846007Sthurlow int  smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp,
1856007Sthurlow 	const char *tname, int tnmlen, struct smb_cred *scrp);
1866007Sthurlow int  smbfs_smb_t2rename(struct smbnode *np, struct smbnode *tdnp,
1876007Sthurlow 	const char *tname, int tnmlen, struct smb_cred *scrp, int overwrite);
1886007Sthurlow int  smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp,
1896007Sthurlow 	const char *tname, int tnmlen, uint16_t flags, struct smb_cred *scrp);
1906007Sthurlow int  smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len,
1916007Sthurlow 	struct smb_cred *scrp);
1926007Sthurlow int  smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scrp);
1936007Sthurlow int  smbfs_smb_findopen(struct smbnode *dnp, const char *wildcard, int wclen,
1946007Sthurlow 	int attr, struct smb_cred *scrp, struct smbfs_fctx **ctxpp);
1956007Sthurlow int  smbfs_smb_findnext(struct smbfs_fctx *ctx, int limit,
1966007Sthurlow 	struct smb_cred *scrp);
1976007Sthurlow int  smbfs_smb_findclose(struct smbfs_fctx *ctx, struct smb_cred *scrp);
1986007Sthurlow int  smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp,
1996007Sthurlow 	struct smbnode *dnp, const char *name, int *nmlenp, uint8_t sep);
2006007Sthurlow int  smbfs_smb_lookup(struct smbnode *dnp, const char **namep, int *nmlenp,
2016007Sthurlow 	struct smbfattr *fap, struct smb_cred *scrp);
2026007Sthurlow int  smbfs_smb_hideit(struct smbnode *np, const char *name, int len,
2036007Sthurlow 	struct smb_cred *scrp);
2046007Sthurlow int  smbfs_smb_unhideit(struct smbnode *np, const char *name, int len,
2056007Sthurlow 			struct smb_cred *scrp);
2066007Sthurlow int smbfs_smb_flush(struct smbnode *np, struct smb_cred *scrp);
2076007Sthurlow int smbfs_0extend(vnode_t *vp, uint16_t fid, len_t from, len_t to,
2086007Sthurlow 		struct smb_cred *scredp, int timo);
2096007Sthurlow 
2106711Sgwr /* get/set security descriptor */
2116711Sgwr int  smbfs_smb_getsec_m(struct smb_share *ssp, uint16_t fid,
2126711Sgwr 	struct smb_cred *scrp, uint32_t selector,
2136711Sgwr 	mblk_t **res, uint32_t *reslen);
2146711Sgwr int  smbfs_smb_setsec_m(struct smb_share *ssp, uint16_t fid,
2156711Sgwr 	struct smb_cred *scrp, uint32_t selector, mblk_t **mp);
2166711Sgwr 
21711332SGordon.Ross@Sun.COM /*
21811332SGordon.Ross@Sun.COM  * VFS-level init, fini stuff
21911332SGordon.Ross@Sun.COM  */
2206007Sthurlow 
22111332SGordon.Ross@Sun.COM int smbfs_vfsinit(void);
22211332SGordon.Ross@Sun.COM void smbfs_vfsfini(void);
2236007Sthurlow int smbfs_subrinit(void);
2246007Sthurlow void smbfs_subrfini(void);
2256007Sthurlow int smbfs_clntinit(void);
2266007Sthurlow void smbfs_clntfini(void);
22711332SGordon.Ross@Sun.COM 
2286007Sthurlow void smbfs_zonelist_add(smbmntinfo_t *smi);
2296007Sthurlow void smbfs_zonelist_remove(smbmntinfo_t *smi);
23011332SGordon.Ross@Sun.COM 
23111332SGordon.Ross@Sun.COM int smbfs_check_table(struct vfs *vfsp, struct smbnode *srp);
2326007Sthurlow void smbfs_destroy_table(struct vfs *vfsp);
23311332SGordon.Ross@Sun.COM void smbfs_rflush(struct vfs *vfsp, cred_t *cr);
23411332SGordon.Ross@Sun.COM 
23511332SGordon.Ross@Sun.COM /*
23611332SGordon.Ross@Sun.COM  * Function definitions - those having to do with
23711332SGordon.Ross@Sun.COM  * smbfs nodes, vnodes, etc
23811332SGordon.Ross@Sun.COM  */
23911332SGordon.Ross@Sun.COM 
24011332SGordon.Ross@Sun.COM void smbfs_attrcache_prune(struct smbnode *np);
24111332SGordon.Ross@Sun.COM void smbfs_attrcache_remove(struct smbnode *np);
24211332SGordon.Ross@Sun.COM void smbfs_attrcache_rm_locked(struct smbnode *np);
24311332SGordon.Ross@Sun.COM #ifndef	DEBUG
24411332SGordon.Ross@Sun.COM #define	smbfs_attrcache_rm_locked(np)	(np)->r_attrtime = gethrtime()
24511332SGordon.Ross@Sun.COM #endif
24611332SGordon.Ross@Sun.COM void smbfs_attr_touchdir(struct smbnode *dnp);
24711332SGordon.Ross@Sun.COM void smbfs_attrcache_fa(vnode_t *vp, struct smbfattr *fap);
24811332SGordon.Ross@Sun.COM void smbfs_cache_check(struct vnode *vp, struct smbfattr *fap);
24911332SGordon.Ross@Sun.COM 
25011332SGordon.Ross@Sun.COM void smbfs_addfree(struct smbnode *sp);
25111332SGordon.Ross@Sun.COM void smbfs_rmhash(struct smbnode *);
25211332SGordon.Ross@Sun.COM 
25311332SGordon.Ross@Sun.COM /* See avl_create in smbfs_vfsops.c */
25411332SGordon.Ross@Sun.COM void smbfs_init_hash_avl(avl_tree_t *);
25511332SGordon.Ross@Sun.COM 
25611332SGordon.Ross@Sun.COM uint32_t smbfs_gethash(const char *rpath, int prlen);
25711332SGordon.Ross@Sun.COM uint32_t smbfs_getino(struct smbnode *dnp, const char *name, int nmlen);
25811332SGordon.Ross@Sun.COM 
25911332SGordon.Ross@Sun.COM extern struct smbfattr smbfs_fattr0;
26011332SGordon.Ross@Sun.COM smbnode_t *smbfs_node_findcreate(smbmntinfo_t *mi,
26111332SGordon.Ross@Sun.COM     const char *dir, int dirlen,
26211332SGordon.Ross@Sun.COM     const char *name, int nmlen,
26311332SGordon.Ross@Sun.COM     char sep, struct smbfattr *fap);
26411332SGordon.Ross@Sun.COM 
26511332SGordon.Ross@Sun.COM int smbfs_nget(vnode_t *dvp, const char *name, int nmlen,
26611332SGordon.Ross@Sun.COM 	struct smbfattr *fap, vnode_t **vpp);
26711332SGordon.Ross@Sun.COM 
26811332SGordon.Ross@Sun.COM void smbfs_fname_tolocal(struct smbfs_fctx *ctx);
26911332SGordon.Ross@Sun.COM char    *smbfs_name_alloc(const char *name, int nmlen);
27011332SGordon.Ross@Sun.COM void	smbfs_name_free(const char *name, int nmlen);
27111332SGordon.Ross@Sun.COM 
2726007Sthurlow int smbfs_readvnode(vnode_t *, uio_t *, cred_t *, struct vattr *);
2736007Sthurlow int smbfs_writevnode(vnode_t *vp, uio_t *uiop, cred_t *cr,
2746007Sthurlow 			int ioflag, int timo);
2756007Sthurlow int smbfsgetattr(vnode_t *vp, struct vattr *vap, cred_t *cr);
2766007Sthurlow 
277*11564SGordon.Ross@Sun.COM /* smbfs ACL support */
278*11564SGordon.Ross@Sun.COM int smbfs_acl_getids(vnode_t *, cred_t *);
279*11564SGordon.Ross@Sun.COM int smbfs_acl_setids(vnode_t *, vattr_t *, cred_t *);
280*11564SGordon.Ross@Sun.COM int smbfs_acl_getvsa(vnode_t *, vsecattr_t *, int, cred_t *);
281*11564SGordon.Ross@Sun.COM int smbfs_acl_setvsa(vnode_t *, vsecattr_t *, int, cred_t *);
282*11564SGordon.Ross@Sun.COM int smbfs_acl_iocget(vnode_t *, intptr_t, int, cred_t *);
283*11564SGordon.Ross@Sun.COM int smbfs_acl_iocset(vnode_t *, intptr_t, int, cred_t *);
284*11564SGordon.Ross@Sun.COM 
2857040Sgwr /* smbfs_xattr.c */
2867040Sgwr int smbfs_get_xattrdir(vnode_t *dvp, vnode_t **vpp, cred_t *cr, int);
2877040Sgwr int smbfs_xa_parent(vnode_t *vp, vnode_t **vpp);
2887040Sgwr int smbfs_xa_exists(vnode_t *vp, cred_t *cr);
2897040Sgwr int smbfs_xa_getfattr(struct smbnode *np, struct smbfattr *fap,
2907040Sgwr 	struct smb_cred *scrp);
2917040Sgwr int smbfs_xa_findopen(struct smbfs_fctx *ctx, struct smbnode *dnp,
2927040Sgwr 	const char *name, int nmlen);
2937040Sgwr int smbfs_xa_findnext(struct smbfs_fctx *ctx, uint16_t limit);
2947040Sgwr int smbfs_xa_findclose(struct smbfs_fctx *ctx);
2957040Sgwr 
2966007Sthurlow /* For Solaris, interruptible rwlock */
2976007Sthurlow int smbfs_rw_enter_sig(smbfs_rwlock_t *l, krw_t rw, int intr);
2986007Sthurlow int smbfs_rw_tryenter(smbfs_rwlock_t *l, krw_t rw);
2996007Sthurlow void smbfs_rw_exit(smbfs_rwlock_t *l);
3006007Sthurlow int smbfs_rw_lock_held(smbfs_rwlock_t *l, krw_t rw);
3016007Sthurlow void smbfs_rw_init(smbfs_rwlock_t *l, char *name, krw_type_t type, void *arg);
3026007Sthurlow void smbfs_rw_destroy(smbfs_rwlock_t *l);
3036007Sthurlow 
3046007Sthurlow #endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */
305