1139776Simp/*- 2206361Sjoel * Copyright (c) 2000-2001 Boris Popov 375374Sbp * All rights reserved. 475374Sbp * 575374Sbp * Redistribution and use in source and binary forms, with or without 675374Sbp * modification, are permitted provided that the following conditions 775374Sbp * are met: 875374Sbp * 1. Redistributions of source code must retain the above copyright 975374Sbp * notice, this list of conditions and the following disclaimer. 1075374Sbp * 2. Redistributions in binary form must reproduce the above copyright 1175374Sbp * notice, this list of conditions and the following disclaimer in the 1275374Sbp * documentation and/or other materials provided with the distribution. 1375374Sbp * 1475374Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1575374Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1675374Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1775374Sbp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1875374Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1975374Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2075374Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2175374Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2275374Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2375374Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2475374Sbp * SUCH DAMAGE. 2575374Sbp * 2675374Sbp * $FreeBSD$ 2775374Sbp */ 2875374Sbp#ifndef _FS_SMBFS_SMBFS_SUBR_H_ 2975374Sbp#define _FS_SMBFS_SMBFS_SUBR_H_ 3075374Sbp 3175374Sbp#ifdef MALLOC_DECLARE 3275374SbpMALLOC_DECLARE(M_SMBFSDATA); 33242386SdavideMALLOC_DECLARE(M_SMBFSCRED); 3475374Sbp#endif 3575374Sbp 3687599Sobrien#define SMBFSERR(format, args...) printf("%s: "format, __func__ ,## args) 3775374Sbp 3875374Sbp#ifdef SMB_VNODE_DEBUG 3987599Sobrien#define SMBVDEBUG(format, args...) printf("%s: "format, __func__ ,## args) 4075374Sbp#else 4175374Sbp#define SMBVDEBUG(format, args...) 4275374Sbp#endif 4375374Sbp 4475374Sbp/* 4575374Sbp * Possible lock commands 4675374Sbp */ 4775374Sbp#define SMB_LOCK_EXCL 0 4875374Sbp#define SMB_LOCK_SHARED 1 4975374Sbp#define SMB_LOCK_RELEASE 2 5075374Sbp 5175374Sbpstruct smbmount; 5275374Sbpstruct proc; 5375374Sbpstruct timespec; 5475374Sbpstruct ucred; 5575374Sbpstruct vattr; 5675374Sbpstruct vnode; 5775374Sbpstruct statfs; 5875374Sbp 5975374Sbpstruct smbfattr { 6075374Sbp int fa_attr; 6175374Sbp int64_t fa_size; 6275374Sbp struct timespec fa_atime; 6375374Sbp struct timespec fa_ctime; 6475374Sbp struct timespec fa_mtime; 6575374Sbp long fa_ino; 6675374Sbp}; 6775374Sbp 6875374Sbp/* 6975374Sbp * Context to perform findfirst/findnext/findclose operations 7075374Sbp */ 7175374Sbp#define SMBFS_RDD_FINDFIRST 0x01 7275374Sbp#define SMBFS_RDD_EOF 0x02 7375374Sbp#define SMBFS_RDD_FINDSINGLE 0x04 7475374Sbp#define SMBFS_RDD_USESEARCH 0x08 7575374Sbp#define SMBFS_RDD_NOCLOSE 0x10 7675374Sbp#define SMBFS_RDD_GOTRNAME 0x1000 7775374Sbp 7875374Sbp/* 7975374Sbp * Search context supplied by server 8075374Sbp */ 8175374Sbp#define SMB_SKEYLEN 21 /* search context */ 8275374Sbp#define SMB_DENTRYLEN (SMB_SKEYLEN + 22) /* entire entry */ 8375374Sbp 8475374Sbpstruct smbfs_fctx { 8575374Sbp /* 8675374Sbp * Setable values 8775374Sbp */ 8875374Sbp int f_flags; /* SMBFS_RDD_ */ 8975374Sbp /* 9075374Sbp * Return values 9175374Sbp */ 9275374Sbp struct smbfattr f_attr; /* current attributes */ 9375374Sbp char * f_name; /* current file name */ 9475374Sbp int f_nmlen; /* name len */ 9575374Sbp /* 9675374Sbp * Internal variables 9775374Sbp */ 9875374Sbp int f_limit; /* maximum number of entries */ 9975374Sbp int f_attrmask; /* SMB_FA_ */ 10075374Sbp int f_wclen; 10175374Sbp const char * f_wildcard; 10275374Sbp struct smbnode* f_dnp; 10375374Sbp struct smb_cred*f_scred; 10475374Sbp struct smb_share *f_ssp; 10575374Sbp union { 10675374Sbp struct smb_rq * uf_rq; 10775374Sbp struct smb_t2rq * uf_t2; 10875374Sbp } f_urq; 10975374Sbp int f_left; /* entries left */ 11075374Sbp int f_ecnt; /* entries left in the current reponse */ 11175374Sbp int f_eofs; /* entry offset in the parameter block */ 11275374Sbp u_char f_skey[SMB_SKEYLEN]; /* server side search context */ 11375374Sbp u_char f_fname[8 + 1 + 3 + 1]; /* common case for 8.3 filenames */ 11475374Sbp u_int16_t f_Sid; 11575374Sbp u_int16_t f_infolevel; 11675374Sbp int f_rnamelen; 11775374Sbp char * f_rname; /* resume name/key */ 11875374Sbp int f_rnameofs; 11975374Sbp}; 12075374Sbp 12175374Sbp#define f_rq f_urq.uf_rq 12275374Sbp#define f_t2 f_urq.uf_t2 12375374Sbp 12475374Sbp/* 12575374Sbp * smb level 12675374Sbp */ 12775374Sbpint smbfs_smb_lock(struct smbnode *np, int op, caddr_t id, 12875374Sbp off_t start, off_t end, struct smb_cred *scred); 12975374Sbpint smbfs_smb_statfs(struct smb_share *ssp, struct statfs *sbp, 13075374Sbp struct smb_cred *scred); 13175374Sbpint smbfs_smb_setfsize(struct smbnode *np, int newsize, struct smb_cred *scred); 13275374Sbp 133103533Sbpint smbfs_smb_query_info(struct smbnode *np, const char *name, int len, 134103533Sbp struct smbfattr *fap, struct smb_cred *scred); 13575374Sbpint smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr, 13675374Sbp struct timespec *mtime, struct smb_cred *scred); 13775374Sbpint smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime, 13875374Sbp struct timespec *atime, int attr, struct smb_cred *scred); 13975374Sbpint smbfs_smb_setpattrNT(struct smbnode *np, u_int16_t attr, 14075374Sbp struct timespec *mtime, struct timespec *atime, struct smb_cred *scred); 14175374Sbp 14275374Sbpint smbfs_smb_setftime(struct smbnode *np, struct timespec *mtime, 14375374Sbp struct timespec *atime, struct smb_cred *scred); 14475374Sbpint smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr, 14575374Sbp struct timespec *mtime, struct timespec *atime, struct smb_cred *scred); 14675374Sbp 14775374Sbpint smbfs_smb_open(struct smbnode *np, int accmode, struct smb_cred *scred); 14875374Sbpint smbfs_smb_close(struct smb_share *ssp, u_int16_t fid, 14975374Sbp struct timespec *mtime, struct smb_cred *scred); 15075374Sbpint smbfs_smb_create(struct smbnode *dnp, const char *name, int len, 15175374Sbp struct smb_cred *scred); 15275374Sbpint smbfs_smb_delete(struct smbnode *np, struct smb_cred *scred); 153103533Sbpint smbfs_smb_flush(struct smbnode *np, struct smb_cred *scred); 15475374Sbpint smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp, 15575374Sbp const char *tname, int tnmlen, struct smb_cred *scred); 15675374Sbpint smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp, 15775374Sbp const char *tname, int tnmlen, u_int16_t flags, struct smb_cred *scred); 15875374Sbpint smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len, 15975374Sbp struct smb_cred *scred); 16075374Sbpint smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scred); 16175374Sbpint smbfs_findopen(struct smbnode *dnp, const char *wildcard, int wclen, 16275374Sbp int attr, struct smb_cred *scred, struct smbfs_fctx **ctxpp); 16375374Sbpint smbfs_findnext(struct smbfs_fctx *ctx, int limit, struct smb_cred *scred); 16475374Sbpint smbfs_findclose(struct smbfs_fctx *ctx, struct smb_cred *scred); 16575374Sbpint smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, 16675374Sbp struct smbnode *dnp, const char *name, int nmlen); 16775374Sbpint smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen, 16875374Sbp struct smbfattr *fap, struct smb_cred *scred); 16975374Sbp 170145872Stakawataint smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt); 17175374Sbp 17275374Sbpvoid smb_time_local2server(struct timespec *tsp, int tzoff, u_long *seconds); 17375374Sbpvoid smb_time_server2local(u_long seconds, int tzoff, struct timespec *tsp); 17475374Sbpvoid smb_time_NT2local(int64_t nsec, int tzoff, struct timespec *tsp); 17575374Sbpvoid smb_time_local2NT(struct timespec *tsp, int tzoff, int64_t *nsec); 17675374Sbpvoid smb_time_unix2dos(struct timespec *tsp, int tzoff, u_int16_t *ddp, 17775374Sbp u_int16_t *dtp, u_int8_t *dhp); 17875374Sbpvoid smb_dos2unixtime (u_int dd, u_int dt, u_int dh, int tzoff, struct timespec *tsp); 17975374Sbp 180242386Sdavidevoid *smbfs_malloc_scred(void); 181242386Sdavidevoid smbfs_free_scred(void *); 18275374Sbp#endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */ 183