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); 3375374Sbp#endif 3475374Sbp 3587599Sobrien#define SMBFSERR(format, args...) printf("%s: "format, __func__ ,## args) 3675374Sbp 3775374Sbp#ifdef SMB_VNODE_DEBUG 3887599Sobrien#define SMBVDEBUG(format, args...) printf("%s: "format, __func__ ,## args) 3975374Sbp#else 4075374Sbp#define SMBVDEBUG(format, args...) 4175374Sbp#endif 4275374Sbp 4375374Sbp/* 4475374Sbp * Possible lock commands 4575374Sbp */ 4675374Sbp#define SMB_LOCK_EXCL 0 4775374Sbp#define SMB_LOCK_SHARED 1 4875374Sbp#define SMB_LOCK_RELEASE 2 4975374Sbp 5075374Sbpstruct smbmount; 5175374Sbpstruct proc; 5275374Sbpstruct timespec; 5375374Sbpstruct ucred; 5475374Sbpstruct vattr; 5575374Sbpstruct vnode; 5675374Sbpstruct statfs; 5775374Sbp 5875374Sbpstruct smbfattr { 5975374Sbp int fa_attr; 6075374Sbp int64_t fa_size; 6175374Sbp struct timespec fa_atime; 6275374Sbp struct timespec fa_ctime; 6375374Sbp struct timespec fa_mtime; 6475374Sbp long fa_ino; 6575374Sbp}; 6675374Sbp 6775374Sbp/* 6875374Sbp * Context to perform findfirst/findnext/findclose operations 6975374Sbp */ 7075374Sbp#define SMBFS_RDD_FINDFIRST 0x01 7175374Sbp#define SMBFS_RDD_EOF 0x02 7275374Sbp#define SMBFS_RDD_FINDSINGLE 0x04 7375374Sbp#define SMBFS_RDD_USESEARCH 0x08 7475374Sbp#define SMBFS_RDD_NOCLOSE 0x10 7575374Sbp#define SMBFS_RDD_GOTRNAME 0x1000 7675374Sbp 7775374Sbp/* 7875374Sbp * Search context supplied by server 7975374Sbp */ 8075374Sbp#define SMB_SKEYLEN 21 /* search context */ 8175374Sbp#define SMB_DENTRYLEN (SMB_SKEYLEN + 22) /* entire entry */ 8275374Sbp 8375374Sbpstruct smbfs_fctx { 8475374Sbp /* 8575374Sbp * Setable values 8675374Sbp */ 8775374Sbp int f_flags; /* SMBFS_RDD_ */ 8875374Sbp /* 8975374Sbp * Return values 9075374Sbp */ 9175374Sbp struct smbfattr f_attr; /* current attributes */ 9275374Sbp char * f_name; /* current file name */ 9375374Sbp int f_nmlen; /* name len */ 9475374Sbp /* 9575374Sbp * Internal variables 9675374Sbp */ 9775374Sbp int f_limit; /* maximum number of entries */ 9875374Sbp int f_attrmask; /* SMB_FA_ */ 9975374Sbp int f_wclen; 10075374Sbp const char * f_wildcard; 10175374Sbp struct smbnode* f_dnp; 10275374Sbp struct smb_cred*f_scred; 10375374Sbp struct smb_share *f_ssp; 10475374Sbp union { 10575374Sbp struct smb_rq * uf_rq; 10675374Sbp struct smb_t2rq * uf_t2; 10775374Sbp } f_urq; 10875374Sbp int f_left; /* entries left */ 10975374Sbp int f_ecnt; /* entries left in the current reponse */ 11075374Sbp int f_eofs; /* entry offset in the parameter block */ 11175374Sbp u_char f_skey[SMB_SKEYLEN]; /* server side search context */ 11275374Sbp u_char f_fname[8 + 1 + 3 + 1]; /* common case for 8.3 filenames */ 11375374Sbp u_int16_t f_Sid; 11475374Sbp u_int16_t f_infolevel; 11575374Sbp int f_rnamelen; 11675374Sbp char * f_rname; /* resume name/key */ 11775374Sbp int f_rnameofs; 11875374Sbp}; 11975374Sbp 12075374Sbp#define f_rq f_urq.uf_rq 12175374Sbp#define f_t2 f_urq.uf_t2 12275374Sbp 12375374Sbp/* 12475374Sbp * smb level 12575374Sbp */ 12675374Sbpint smbfs_smb_lock(struct smbnode *np, int op, caddr_t id, 12775374Sbp off_t start, off_t end, struct smb_cred *scred); 12875374Sbpint smbfs_smb_statfs(struct smb_share *ssp, struct statfs *sbp, 12975374Sbp struct smb_cred *scred); 13075374Sbpint smbfs_smb_setfsize(struct smbnode *np, int newsize, struct smb_cred *scred); 13175374Sbp 132103533Sbpint smbfs_smb_query_info(struct smbnode *np, const char *name, int len, 133103533Sbp struct smbfattr *fap, struct smb_cred *scred); 13475374Sbpint smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr, 13575374Sbp struct timespec *mtime, struct smb_cred *scred); 13675374Sbpint smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime, 13775374Sbp struct timespec *atime, int attr, struct smb_cred *scred); 13875374Sbpint smbfs_smb_setpattrNT(struct smbnode *np, u_int16_t attr, 13975374Sbp struct timespec *mtime, struct timespec *atime, struct smb_cred *scred); 14075374Sbp 14175374Sbpint smbfs_smb_setftime(struct smbnode *np, struct timespec *mtime, 14275374Sbp struct timespec *atime, struct smb_cred *scred); 14375374Sbpint smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr, 14475374Sbp struct timespec *mtime, struct timespec *atime, struct smb_cred *scred); 14575374Sbp 14675374Sbpint smbfs_smb_open(struct smbnode *np, int accmode, struct smb_cred *scred); 14775374Sbpint smbfs_smb_close(struct smb_share *ssp, u_int16_t fid, 14875374Sbp struct timespec *mtime, struct smb_cred *scred); 14975374Sbpint smbfs_smb_create(struct smbnode *dnp, const char *name, int len, 15075374Sbp struct smb_cred *scred); 15175374Sbpint smbfs_smb_delete(struct smbnode *np, struct smb_cred *scred); 152103533Sbpint smbfs_smb_flush(struct smbnode *np, struct smb_cred *scred); 15375374Sbpint smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp, 15475374Sbp const char *tname, int tnmlen, struct smb_cred *scred); 15575374Sbpint smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp, 15675374Sbp const char *tname, int tnmlen, u_int16_t flags, struct smb_cred *scred); 15775374Sbpint smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len, 15875374Sbp struct smb_cred *scred); 15975374Sbpint smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scred); 16075374Sbpint smbfs_findopen(struct smbnode *dnp, const char *wildcard, int wclen, 16175374Sbp int attr, struct smb_cred *scred, struct smbfs_fctx **ctxpp); 16275374Sbpint smbfs_findnext(struct smbfs_fctx *ctx, int limit, struct smb_cred *scred); 16375374Sbpint smbfs_findclose(struct smbfs_fctx *ctx, struct smb_cred *scred); 16475374Sbpint smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, 16575374Sbp struct smbnode *dnp, const char *name, int nmlen); 16675374Sbpint smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen, 16775374Sbp struct smbfattr *fap, struct smb_cred *scred); 16875374Sbp 169145872Stakawataint smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt); 17075374Sbp 17175374Sbpvoid smb_time_local2server(struct timespec *tsp, int tzoff, u_long *seconds); 17275374Sbpvoid smb_time_server2local(u_long seconds, int tzoff, struct timespec *tsp); 17375374Sbpvoid smb_time_NT2local(int64_t nsec, int tzoff, struct timespec *tsp); 17475374Sbpvoid smb_time_local2NT(struct timespec *tsp, int tzoff, int64_t *nsec); 17575374Sbpvoid smb_time_unix2dos(struct timespec *tsp, int tzoff, u_int16_t *ddp, 17675374Sbp u_int16_t *dtp, u_int8_t *dhp); 17775374Sbpvoid smb_dos2unixtime (u_int dd, u_int dt, u_int dh, int tzoff, struct timespec *tsp); 17875374Sbp 17975374Sbp#endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */ 180