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 2008 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 #pragma ident "%Z%%M% %I% %E% SMI" 44 45 /* This defines terms used in the error messages */ 46 #include <sys/cmn_err.h> 47 48 #if defined(DEBUG) || defined(lint) 49 #define SMB_VNODE_DEBUG 1 50 #endif 51 52 #ifndef FALSE 53 #define FALSE (0) 54 #endif 55 56 #ifndef TRUE 57 #define TRUE (1) 58 #endif 59 60 /* 61 * Let's use C99 standard variadic macros! 62 * Also the C99 __func__ (function name) feature. 63 */ 64 #define SMBFSERR(...) \ 65 smb_errmsg(CE_NOTE, __func__, __VA_ARGS__) 66 #define SMBVDEBUG(...) \ 67 smb_errmsg(CE_CONT, __func__, __VA_ARGS__) 68 69 /* 70 * Possible lock commands 71 */ 72 #define SMB_LOCK_EXCL 0 73 #define SMB_LOCK_SHARED 1 74 #define SMB_LOCK_RELEASE 2 75 76 struct mbchain; 77 struct smb_cred; 78 struct smb_vc; 79 struct statvfs; 80 struct timespec; 81 82 83 /* 84 * Context to perform findfirst/findnext/findclose operations 85 */ 86 #define SMBFS_RDD_FINDFIRST 0x01 87 #define SMBFS_RDD_EOF 0x02 88 #define SMBFS_RDD_FINDSINGLE 0x04 89 #define SMBFS_RDD_USESEARCH 0x08 90 #define SMBFS_RDD_NOCLOSE 0x10 91 #define SMBFS_RDD_GOTRNAME 0x1000 92 93 /* 94 * Search context supplied by server 95 */ 96 #define SMB_SKEYLEN 21 /* search context */ 97 #define SMB_DENTRYLEN (SMB_SKEYLEN + 22) /* entire entry */ 98 99 struct smbfs_fctx { 100 /* 101 * Setable values 102 */ 103 int f_flags; /* SMBFS_RDD_ */ 104 /* 105 * Return values 106 */ 107 struct smbfattr f_attr; /* current attributes */ 108 char *f_name; /* current file name */ 109 int f_nmlen; /* name len */ 110 int f_namesz; /* memory allocated */ 111 /* 112 * Internal variables 113 */ 114 uint16_t f_limit; /* maximum number of entries */ 115 uint16_t f_attrmask; /* SMB_FA_ */ 116 int f_wclen; 117 const char *f_wildcard; 118 struct smbnode *f_dnp; 119 struct smb_cred *f_scred; 120 struct smb_share *f_ssp; 121 union { 122 struct smb_rq *uf_rq; 123 struct smb_t2rq *uf_t2; 124 } f_urq; 125 int f_left; /* entries left */ 126 int f_ecnt; /* entries left in current response */ 127 int f_eofs; /* entry offset in data block */ 128 uchar_t f_skey[SMB_SKEYLEN]; /* server side search context */ 129 uchar_t f_fname[8 + 1 + 3 + 1]; /* for 8.3 filenames */ 130 uint16_t f_Sid; /* Search handle (like a FID) */ 131 uint16_t f_infolevel; 132 int f_rnamelen; 133 char *f_rname; /* resume name */ 134 int f_rnameofs; 135 int f_otws; /* # over-the-wire ops so far */ 136 char *f_firstnm; /* first filename we got back */ 137 int f_firstnmlen; 138 int f_rkey; /* resume key */ 139 }; 140 typedef struct smbfs_fctx smbfs_fctx_t; 141 142 #define f_rq f_urq.uf_rq 143 #define f_t2 f_urq.uf_t2 144 145 146 /* 147 * smb level 148 */ 149 int smbfs_smb_lock(struct smbnode *np, int op, caddr_t id, 150 offset_t start, uint64_t len, int largelock, 151 struct smb_cred *scrp, uint32_t timeout); 152 int smbfs_smb_qfsattr(struct smb_share *ssp, uint32_t *attrp, 153 struct smb_cred *scrp); 154 int smbfs_smb_statfs(struct smb_share *ssp, statvfs64_t *sbp, 155 struct smb_cred *scrp); 156 int smbfs_smb_setfsize(struct smbnode *np, uint16_t fid, uint64_t newsize, 157 struct smb_cred *scrp); 158 159 int smbfs_smb_getfattr(struct smbnode *np, struct smbfattr *fap, 160 struct smb_cred *scrp); 161 162 int smbfs_smb_setfattr(struct smbnode *np, uint16_t fid, 163 uint32_t attr, struct timespec *mtime, struct timespec *atime, 164 struct smb_cred *scrp); 165 166 int smbfs_smb_setpattr(struct smbnode *np, 167 uint32_t attr, struct timespec *mtime, struct timespec *atime, 168 struct smb_cred *scrp); 169 170 int smbfs_smb_open(struct smbnode *np, uint32_t rights, struct smb_cred *scrp, 171 int *attrcacheupdated, uint16_t *fidp, const char *name, int nmlen, 172 int xattr, len_t *sizep, uint32_t *rightsp); 173 int smbfs_smb_tmpopen(struct smbnode *np, uint32_t rights, 174 struct smb_cred *scrp, uint16_t *fidp); 175 int smbfs_smb_close(struct smb_share *ssp, uint16_t fid, 176 struct timespec *mtime, struct smb_cred *scrp); 177 int smbfs_smb_tmpclose(struct smbnode *ssp, uint16_t fid, 178 struct smb_cred *scrp); 179 int smbfs_smb_create(struct smbnode *dnp, const char *name, int len, 180 struct smb_cred *scrp, uint16_t *fidp, uint32_t disp, int xattr); 181 int smbfs_smb_delete(struct smbnode *np, struct smb_cred *scrp, 182 const char *name, int len, int xattr); 183 int smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp, 184 const char *tname, int tnmlen, struct smb_cred *scrp); 185 int smbfs_smb_t2rename(struct smbnode *np, struct smbnode *tdnp, 186 const char *tname, int tnmlen, struct smb_cred *scrp, int overwrite); 187 int smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp, 188 const char *tname, int tnmlen, uint16_t flags, struct smb_cred *scrp); 189 int smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len, 190 struct smb_cred *scrp); 191 int smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scrp); 192 int smbfs_smb_findopen(struct smbnode *dnp, const char *wildcard, int wclen, 193 int attr, struct smb_cred *scrp, struct smbfs_fctx **ctxpp); 194 int smbfs_smb_findnext(struct smbfs_fctx *ctx, int limit, 195 struct smb_cred *scrp); 196 int smbfs_smb_findclose(struct smbfs_fctx *ctx, struct smb_cred *scrp); 197 int smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, 198 struct smbnode *dnp, const char *name, int *nmlenp, uint8_t sep); 199 int smbfs_smb_lookup(struct smbnode *dnp, const char **namep, int *nmlenp, 200 struct smbfattr *fap, struct smb_cred *scrp); 201 int smbfs_smb_hideit(struct smbnode *np, const char *name, int len, 202 struct smb_cred *scrp); 203 int smbfs_smb_unhideit(struct smbnode *np, const char *name, int len, 204 struct smb_cred *scrp); 205 int smbfs_smb_flush(struct smbnode *np, struct smb_cred *scrp); 206 int smbfs_0extend(vnode_t *vp, uint16_t fid, len_t from, len_t to, 207 struct smb_cred *scredp, int timo); 208 209 #ifdef NOT_YET 210 int smbfs_smb_getsec(struct smb_share *ssp, uint16_t fid, 211 struct smb_cred *scrp, uint32_t selector, struct ntsecdesc **res); 212 int smbfs_smb_setsec(struct smb_share *ssp, uint16_t fid, 213 struct smb_cred *scrp, uint32_t selector, uint16_t flags, 214 struct ntsid *owner, struct ntsid *group, struct ntacl *sacl, 215 struct ntacl *dacl); 216 int smbfs_smb_qstreaminfo(struct smbnode *np, struct smb_cred *scrp, 217 uio_t uio, size_t *sizep); 218 #endif /* NOT_YET */ 219 220 void smbfs_fname_tolocal(struct smbfs_fctx *ctx); 221 222 void smb_time_local2server(struct timespec *tsp, int tzoff, long *seconds); 223 void smb_time_server2local(ulong_t seconds, int tzoff, struct timespec *tsp); 224 void smb_time_NT2local(uint64_t nsec, int tzoff, struct timespec *tsp); 225 void smb_time_local2NT(struct timespec *tsp, int tzoff, uint64_t *nsec); 226 void smb_time_unix2dos(struct timespec *tsp, int tzoff, uint16_t *ddp, 227 uint16_t *dtp, uint8_t *dhp); 228 void smb_dos2unixtime(uint_t dd, uint_t dt, uint_t dh, int tzoff, 229 struct timespec *tsp); 230 231 /* Stuff borrowed from NFS (and then hacked) */ 232 vnode_t *smbfs_make_node(vfs_t *vfsp, 233 const char *dir, int dirlen, 234 const char *name, int nmlen, 235 struct smbfattr *fap); 236 void smb_addfree(smbnode_t *sp); 237 void smb_addhash(smbnode_t *sp); 238 void smb_rmhash(smbnode_t *); 239 240 int smbfs_subrinit(void); 241 void smbfs_subrfini(void); 242 int smbfs_clntinit(void); 243 void smbfs_clntfini(void); 244 void smbfs_zonelist_add(smbmntinfo_t *smi); 245 void smbfs_zonelist_remove(smbmntinfo_t *smi); 246 void smbfs_destroy_table(struct vfs *vfsp); 247 int smbfs_readvnode(vnode_t *, uio_t *, cred_t *, struct vattr *); 248 int smbfs_writevnode(vnode_t *vp, uio_t *uiop, cred_t *cr, 249 int ioflag, int timo); 250 int smbfsgetattr(vnode_t *vp, struct vattr *vap, cred_t *cr); 251 252 /* For Solaris, interruptible rwlock */ 253 int smbfs_rw_enter_sig(smbfs_rwlock_t *l, krw_t rw, int intr); 254 int smbfs_rw_tryenter(smbfs_rwlock_t *l, krw_t rw); 255 void smbfs_rw_exit(smbfs_rwlock_t *l); 256 int smbfs_rw_lock_held(smbfs_rwlock_t *l, krw_t rw); 257 void smbfs_rw_init(smbfs_rwlock_t *l, char *name, krw_type_t type, void *arg); 258 void smbfs_rw_destroy(smbfs_rwlock_t *l); 259 260 #endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */ 261