1 /* 2 * Copyright (c) 2000-2001, Boris Popov 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Boris Popov. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Id: smbfs_subr.h,v 1.25 2005/03/17 01:23:40 lindak Exp $ 33 */ 34 35 /* 36 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 37 * Use is subject to license terms. 38 */ 39 40 #ifndef _FS_SMBFS_SMBFS_SUBR_H_ 41 #define _FS_SMBFS_SMBFS_SUBR_H_ 42 43 #include <sys/cmn_err.h> 44 #include <netsmb/mchain.h> 45 46 #if defined(DEBUG) || defined(lint) 47 #define SMB_VNODE_DEBUG 1 48 #endif 49 50 #ifndef FALSE 51 #define FALSE (0) 52 #endif 53 54 #ifndef TRUE 55 #define TRUE (1) 56 #endif 57 58 /* 59 * Let's use C99 standard variadic macros! 60 * Also the C99 __func__ (function name) feature. 61 */ 62 #define SMBFSERR(...) \ 63 smb_errmsg(CE_NOTE, __func__, __VA_ARGS__) 64 #define SMBVDEBUG(...) \ 65 smb_errmsg(CE_CONT, __func__, __VA_ARGS__) 66 67 /* 68 * Possible lock commands 69 */ 70 #define SMB_LOCK_EXCL 0 71 #define SMB_LOCK_SHARED 1 72 #define SMB_LOCK_RELEASE 2 73 74 struct smb_cred; 75 struct smb_vc; 76 struct statvfs; 77 struct timespec; 78 79 /* 80 * Types of find_first, find_next context objects 81 */ 82 typedef enum { 83 ft_LM1 = 1, 84 ft_LM2, 85 ft_XA 86 } smbfs_fctx_type_t; 87 88 /* 89 * Context to perform findfirst/findnext/findclose operations 90 */ 91 #define SMBFS_RDD_FINDFIRST 0x01 92 #define SMBFS_RDD_EOF 0x02 93 #define SMBFS_RDD_FINDSINGLE 0x04 94 /* note SMBFS_RDD_USESEARCH 0x08 replaced by smbfs_fctx_type */ 95 #define SMBFS_RDD_NOCLOSE 0x10 96 97 /* 98 * Search context supplied by server 99 */ 100 #define SMB_SKEYLEN 21 /* search context */ 101 #define SMB_DENTRYLEN (SMB_SKEYLEN + 22) /* entire entry */ 102 103 struct smbfs_fctx { 104 /* 105 * Setable values 106 */ 107 smbfs_fctx_type_t f_type; 108 int f_flags; /* SMBFS_RDD_ */ 109 /* 110 * Return values 111 */ 112 struct smbfattr f_attr; /* current attributes */ 113 u_longlong_t f_inum; /* current I number */ 114 char *f_name; /* current file name */ 115 int f_nmlen; /* name len */ 116 int f_namesz; /* memory allocated */ 117 /* 118 * Internal variables 119 */ 120 uint16_t f_limit; /* maximum number of entries */ 121 uint16_t f_attrmask; /* SMB_FA_ */ 122 int f_wclen; 123 const char *f_wildcard; 124 struct smbnode *f_dnp; 125 struct smb_cred *f_scred; 126 struct smb_share *f_ssp; 127 union { 128 struct smb_rq *uf_rq; 129 struct smb_t2rq *uf_t2; 130 } f_urq; 131 int f_left; /* entries left */ 132 int f_ecnt; /* entries left in current response */ 133 int f_eofs; /* entry offset in data block */ 134 uchar_t f_skey[SMB_SKEYLEN]; /* server side search context */ 135 uchar_t f_fname[8 + 1 + 3 + 1]; /* for 8.3 filenames */ 136 uint16_t f_Sid; /* Search handle (like a FID) */ 137 uint16_t f_infolevel; 138 int f_rnamelen; 139 char *f_rname; /* resume name */ 140 int f_rnameofs; 141 int f_otws; /* # over-the-wire ops so far */ 142 char *f_firstnm; /* first filename we got back */ 143 int f_firstnmlen; 144 int f_rkey; /* resume key */ 145 }; 146 typedef struct smbfs_fctx smbfs_fctx_t; 147 148 #define f_rq f_urq.uf_rq 149 #define f_t2 f_urq.uf_t2 150 151 /* 152 * smb level (smbfs_smb.c) 153 */ 154 int smbfs_smb_lock(struct smbnode *np, int op, caddr_t id, 155 offset_t start, uint64_t len, int largelock, 156 struct smb_cred *scrp, uint32_t timeout); 157 int smbfs_smb_qfsattr(struct smb_share *ssp, struct smb_fs_attr_info *, 158 struct smb_cred *scrp); 159 int smbfs_smb_statfs(struct smb_share *ssp, statvfs64_t *sbp, 160 struct smb_cred *scrp); 161 int smbfs_smb_setfsize(struct smbnode *np, uint16_t fid, uint64_t newsize, 162 struct smb_cred *scrp); 163 164 int smbfs_smb_getfattr(struct smbnode *np, struct smbfattr *fap, 165 struct smb_cred *scrp); 166 167 int smbfs_smb_setfattr(struct smbnode *np, int fid, 168 uint32_t attr, struct timespec *mtime, struct timespec *atime, 169 struct smb_cred *scrp); 170 171 int smbfs_smb_open(struct smbnode *np, const char *name, int nmlen, 172 int xattr, uint32_t rights, struct smb_cred *scrp, 173 uint16_t *fidp, uint32_t *rightsp, struct smbfattr *fap); 174 int smbfs_smb_tmpopen(struct smbnode *np, uint32_t rights, 175 struct smb_cred *scrp, uint16_t *fidp); 176 int smbfs_smb_close(struct smb_share *ssp, uint16_t fid, 177 struct timespec *mtime, struct smb_cred *scrp); 178 int smbfs_smb_tmpclose(struct smbnode *ssp, uint16_t fid, 179 struct smb_cred *scrp); 180 int smbfs_smb_create(struct smbnode *dnp, const char *name, int nmlen, 181 int xattr, uint32_t disp, struct smb_cred *scrp, uint16_t *fidp); 182 int smbfs_smb_delete(struct smbnode *np, struct smb_cred *scrp, 183 const char *name, int len, int xattr); 184 int smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp, 185 const char *tname, int tnmlen, struct smb_cred *scrp); 186 int smbfs_smb_t2rename(struct smbnode *np, struct smbnode *tdnp, 187 const char *tname, int tnmlen, struct smb_cred *scrp, int overwrite); 188 int smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp, 189 const char *tname, int tnmlen, uint16_t flags, struct smb_cred *scrp); 190 int smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len, 191 struct smb_cred *scrp); 192 int smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scrp); 193 int smbfs_smb_findopen(struct smbnode *dnp, const char *wildcard, int wclen, 194 int attr, struct smb_cred *scrp, struct smbfs_fctx **ctxpp); 195 int smbfs_smb_findnext(struct smbfs_fctx *ctx, int limit, 196 struct smb_cred *scrp); 197 int smbfs_smb_findclose(struct smbfs_fctx *ctx, struct smb_cred *scrp); 198 int smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, 199 struct smbnode *dnp, const char *name, int *nmlenp, uint8_t sep); 200 int smbfs_smb_lookup(struct smbnode *dnp, const char **namep, int *nmlenp, 201 struct smbfattr *fap, struct smb_cred *scrp); 202 int smbfs_smb_hideit(struct smbnode *np, const char *name, int len, 203 struct smb_cred *scrp); 204 int smbfs_smb_unhideit(struct smbnode *np, const char *name, int len, 205 struct smb_cred *scrp); 206 int smbfs_smb_flush(struct smbnode *np, struct smb_cred *scrp); 207 int smbfs_0extend(vnode_t *vp, uint16_t fid, len_t from, len_t to, 208 struct smb_cred *scredp, int timo); 209 210 /* get/set security descriptor */ 211 int smbfs_smb_getsec_m(struct smb_share *ssp, uint16_t fid, 212 struct smb_cred *scrp, uint32_t selector, 213 mblk_t **res, uint32_t *reslen); 214 int smbfs_smb_setsec_m(struct smb_share *ssp, uint16_t fid, 215 struct smb_cred *scrp, uint32_t selector, mblk_t **mp); 216 217 int smbfs_getacl(vnode_t *vp, vsecattr_t *vsecattr, 218 uid_t *uidp, gid_t *gidp, int flag, cred_t *cr); 219 int smbfs_setacl(vnode_t *vp, vsecattr_t *vsecattr, 220 uid_t uid, gid_t gid, int flag, cred_t *cr); 221 222 int smbfs_getsd(vnode_t *vp, uint32_t sel, mblk_t **mp, cred_t *cr); 223 int smbfs_setsd(vnode_t *vp, uint32_t sel, mblk_t **mp, cred_t *cr); 224 int smbfs_ioc_getsd(vnode_t *vp, intptr_t arg, int flag, cred_t *cr); 225 int smbfs_ioc_setsd(vnode_t *vp, intptr_t arg, int flag, cred_t *cr); 226 227 #ifdef NOT_YET 228 int smbfs_smb_getsec(struct smb_share *ssp, uint16_t fid, 229 struct smb_cred *scrp, uint32_t selector, struct ntsecdesc **res); 230 int smbfs_smb_setsec(struct smb_share *ssp, uint16_t fid, 231 struct smb_cred *scrp, uint32_t selector, uint16_t flags, 232 struct ntsid *owner, struct ntsid *group, struct ntacl *sacl, 233 struct ntacl *dacl); 234 int smbfs_smb_qstreaminfo(struct smbnode *np, struct smb_cred *scrp, 235 uio_t uio, size_t *sizep); 236 #endif /* NOT_YET */ 237 238 /* 239 * VFS-level init, fini stuff 240 */ 241 242 243 int smbfs_vfsinit(void); 244 void smbfs_vfsfini(void); 245 int smbfs_subrinit(void); 246 void smbfs_subrfini(void); 247 int smbfs_clntinit(void); 248 void smbfs_clntfini(void); 249 250 void smbfs_zonelist_add(smbmntinfo_t *smi); 251 void smbfs_zonelist_remove(smbmntinfo_t *smi); 252 253 int smbfs_check_table(struct vfs *vfsp, struct smbnode *srp); 254 void smbfs_destroy_table(struct vfs *vfsp); 255 void smbfs_rflush(struct vfs *vfsp, cred_t *cr); 256 257 /* 258 * Function definitions - those having to do with 259 * smbfs nodes, vnodes, etc 260 */ 261 262 void smbfs_attrcache_prune(struct smbnode *np); 263 void smbfs_attrcache_remove(struct smbnode *np); 264 void smbfs_attrcache_rm_locked(struct smbnode *np); 265 #ifndef DEBUG 266 #define smbfs_attrcache_rm_locked(np) (np)->r_attrtime = gethrtime() 267 #endif 268 void smbfs_attr_touchdir(struct smbnode *dnp); 269 void smbfs_attrcache_fa(vnode_t *vp, struct smbfattr *fap); 270 void smbfs_cache_check(struct vnode *vp, struct smbfattr *fap); 271 272 void smbfs_addfree(struct smbnode *sp); 273 void smbfs_rmhash(struct smbnode *); 274 275 /* See avl_create in smbfs_vfsops.c */ 276 void smbfs_init_hash_avl(avl_tree_t *); 277 278 uint32_t smbfs_gethash(const char *rpath, int prlen); 279 uint32_t smbfs_getino(struct smbnode *dnp, const char *name, int nmlen); 280 281 extern struct smbfattr smbfs_fattr0; 282 smbnode_t *smbfs_node_findcreate(smbmntinfo_t *mi, 283 const char *dir, int dirlen, 284 const char *name, int nmlen, 285 char sep, struct smbfattr *fap); 286 287 int smbfs_nget(vnode_t *dvp, const char *name, int nmlen, 288 struct smbfattr *fap, vnode_t **vpp); 289 290 void smbfs_fname_tolocal(struct smbfs_fctx *ctx); 291 char *smbfs_name_alloc(const char *name, int nmlen); 292 void smbfs_name_free(const char *name, int nmlen); 293 294 int smbfs_readvnode(vnode_t *, uio_t *, cred_t *, struct vattr *); 295 int smbfs_writevnode(vnode_t *vp, uio_t *uiop, cred_t *cr, 296 int ioflag, int timo); 297 int smbfsgetattr(vnode_t *vp, struct vattr *vap, cred_t *cr); 298 299 /* smbfs_xattr.c */ 300 int smbfs_get_xattrdir(vnode_t *dvp, vnode_t **vpp, cred_t *cr, int); 301 int smbfs_xa_parent(vnode_t *vp, vnode_t **vpp); 302 int smbfs_xa_exists(vnode_t *vp, cred_t *cr); 303 int smbfs_xa_getfattr(struct smbnode *np, struct smbfattr *fap, 304 struct smb_cred *scrp); 305 int smbfs_xa_findopen(struct smbfs_fctx *ctx, struct smbnode *dnp, 306 const char *name, int nmlen); 307 int smbfs_xa_findnext(struct smbfs_fctx *ctx, uint16_t limit); 308 int smbfs_xa_findclose(struct smbfs_fctx *ctx); 309 310 /* For Solaris, interruptible rwlock */ 311 int smbfs_rw_enter_sig(smbfs_rwlock_t *l, krw_t rw, int intr); 312 int smbfs_rw_tryenter(smbfs_rwlock_t *l, krw_t rw); 313 void smbfs_rw_exit(smbfs_rwlock_t *l); 314 int smbfs_rw_lock_held(smbfs_rwlock_t *l, krw_t rw); 315 void smbfs_rw_init(smbfs_rwlock_t *l, char *name, krw_type_t type, void *arg); 316 void smbfs_rw_destroy(smbfs_rwlock_t *l); 317 318 #endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */ 319