xref: /freebsd-src/sys/fs/smbfs/smbfs_subr.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1d167cf6fSWarner Losh /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3d63027b6SPedro F. Giffuni  *
4d122d784SJoel Dahl  * Copyright (c) 2000-2001 Boris Popov
5681a5bbeSBoris Popov  * All rights reserved.
6681a5bbeSBoris Popov  *
7681a5bbeSBoris Popov  * Redistribution and use in source and binary forms, with or without
8681a5bbeSBoris Popov  * modification, are permitted provided that the following conditions
9681a5bbeSBoris Popov  * are met:
10681a5bbeSBoris Popov  * 1. Redistributions of source code must retain the above copyright
11681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer.
12681a5bbeSBoris Popov  * 2. Redistributions in binary form must reproduce the above copyright
13681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer in the
14681a5bbeSBoris Popov  *    documentation and/or other materials provided with the distribution.
15681a5bbeSBoris Popov  *
16681a5bbeSBoris Popov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17681a5bbeSBoris Popov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18681a5bbeSBoris Popov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19681a5bbeSBoris Popov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20681a5bbeSBoris Popov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21681a5bbeSBoris Popov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22681a5bbeSBoris Popov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23681a5bbeSBoris Popov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24681a5bbeSBoris Popov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25681a5bbeSBoris Popov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26681a5bbeSBoris Popov  * SUCH DAMAGE.
27681a5bbeSBoris Popov  */
28681a5bbeSBoris Popov #ifndef _FS_SMBFS_SMBFS_SUBR_H_
29681a5bbeSBoris Popov #define _FS_SMBFS_SMBFS_SUBR_H_
30681a5bbeSBoris Popov 
31681a5bbeSBoris Popov #ifdef MALLOC_DECLARE
32681a5bbeSBoris Popov MALLOC_DECLARE(M_SMBFSDATA);
33afe09751SDavide Italiano MALLOC_DECLARE(M_SMBFSCRED);
34681a5bbeSBoris Popov #endif
35681a5bbeSBoris Popov 
366e551fb6SDavid E. O'Brien #define SMBFSERR(format, args...) printf("%s: "format, __func__ ,## args)
37681a5bbeSBoris Popov 
38681a5bbeSBoris Popov #ifdef SMB_VNODE_DEBUG
396e551fb6SDavid E. O'Brien #define SMBVDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
40681a5bbeSBoris Popov #else
41681a5bbeSBoris Popov #define SMBVDEBUG(format, args...)
42681a5bbeSBoris Popov #endif
43681a5bbeSBoris Popov 
44681a5bbeSBoris Popov /*
45681a5bbeSBoris Popov  * Possible lock commands
46681a5bbeSBoris Popov  */
47681a5bbeSBoris Popov #define SMB_LOCK_EXCL		0
48681a5bbeSBoris Popov #define	SMB_LOCK_SHARED		1
49681a5bbeSBoris Popov #define	SMB_LOCK_RELEASE	2
50681a5bbeSBoris Popov 
51681a5bbeSBoris Popov struct smbmount;
52681a5bbeSBoris Popov struct proc;
53681a5bbeSBoris Popov struct timespec;
54681a5bbeSBoris Popov struct ucred;
55681a5bbeSBoris Popov struct vattr;
56681a5bbeSBoris Popov struct vnode;
57681a5bbeSBoris Popov struct statfs;
58681a5bbeSBoris Popov 
59681a5bbeSBoris Popov struct smbfattr {
60681a5bbeSBoris Popov 	int		fa_attr;
61681a5bbeSBoris Popov 	int64_t		fa_size;
62681a5bbeSBoris Popov 	struct timespec	fa_atime;
63681a5bbeSBoris Popov 	struct timespec	fa_ctime;
64681a5bbeSBoris Popov 	struct timespec	fa_mtime;
65681a5bbeSBoris Popov 	long		fa_ino;
66681a5bbeSBoris Popov };
67681a5bbeSBoris Popov 
68681a5bbeSBoris Popov /*
69681a5bbeSBoris Popov  * Context to perform findfirst/findnext/findclose operations
70681a5bbeSBoris Popov  */
71681a5bbeSBoris Popov #define	SMBFS_RDD_FINDFIRST	0x01
72681a5bbeSBoris Popov #define	SMBFS_RDD_EOF		0x02
73681a5bbeSBoris Popov #define	SMBFS_RDD_FINDSINGLE	0x04
74681a5bbeSBoris Popov #define	SMBFS_RDD_USESEARCH	0x08
75681a5bbeSBoris Popov #define	SMBFS_RDD_NOCLOSE	0x10
76681a5bbeSBoris Popov #define	SMBFS_RDD_GOTRNAME	0x1000
77681a5bbeSBoris Popov 
78681a5bbeSBoris Popov /*
79681a5bbeSBoris Popov  * Search context supplied by server
80681a5bbeSBoris Popov  */
81681a5bbeSBoris Popov #define	SMB_SKEYLEN		21			/* search context */
82681a5bbeSBoris Popov #define SMB_DENTRYLEN		(SMB_SKEYLEN + 22)	/* entire entry */
83681a5bbeSBoris Popov 
84681a5bbeSBoris Popov struct smbfs_fctx {
85681a5bbeSBoris Popov 	/*
86681a5bbeSBoris Popov 	 * Setable values
87681a5bbeSBoris Popov 	 */
88681a5bbeSBoris Popov 	int		f_flags;	/* SMBFS_RDD_ */
89681a5bbeSBoris Popov 	/*
90681a5bbeSBoris Popov 	 * Return values
91681a5bbeSBoris Popov 	 */
92681a5bbeSBoris Popov 	struct smbfattr	f_attr;		/* current attributes */
93681a5bbeSBoris Popov 	char *		f_name;		/* current file name */
94681a5bbeSBoris Popov 	int		f_nmlen;	/* name len */
95681a5bbeSBoris Popov 	/*
96681a5bbeSBoris Popov 	 * Internal variables
97681a5bbeSBoris Popov 	 */
98681a5bbeSBoris Popov 	int		f_limit;	/* maximum number of entries */
99681a5bbeSBoris Popov 	int		f_attrmask;	/* SMB_FA_ */
100681a5bbeSBoris Popov 	int		f_wclen;
101681a5bbeSBoris Popov 	const char *	f_wildcard;
102681a5bbeSBoris Popov 	struct smbnode*	f_dnp;
103681a5bbeSBoris Popov 	struct smb_cred*f_scred;
104681a5bbeSBoris Popov 	struct smb_share *f_ssp;
105681a5bbeSBoris Popov 	union {
106681a5bbeSBoris Popov 		struct smb_rq *	uf_rq;
107681a5bbeSBoris Popov 		struct smb_t2rq * uf_t2;
108681a5bbeSBoris Popov 	} f_urq;
109681a5bbeSBoris Popov 	int		f_left;		/* entries left */
110b3a15dddSPedro F. Giffuni 	int		f_ecnt;		/* entries left in the current response */
111681a5bbeSBoris Popov 	int		f_eofs;		/* entry offset in the parameter block */
112681a5bbeSBoris Popov 	u_char 		f_skey[SMB_SKEYLEN]; /* server side search context */
113681a5bbeSBoris Popov 	u_char		f_fname[8 + 1 + 3 + 1]; /* common case for 8.3 filenames */
114681a5bbeSBoris Popov 	u_int16_t	f_Sid;
115681a5bbeSBoris Popov 	u_int16_t	f_infolevel;
116681a5bbeSBoris Popov 	int		f_rnamelen;
117681a5bbeSBoris Popov 	char *		f_rname;	/* resume name/key */
118681a5bbeSBoris Popov 	int		f_rnameofs;
119681a5bbeSBoris Popov };
120681a5bbeSBoris Popov 
121681a5bbeSBoris Popov #define f_rq	f_urq.uf_rq
122681a5bbeSBoris Popov #define f_t2	f_urq.uf_t2
123681a5bbeSBoris Popov 
124681a5bbeSBoris Popov /*
125681a5bbeSBoris Popov  * smb level
126681a5bbeSBoris Popov  */
127681a5bbeSBoris Popov int  smbfs_smb_lock(struct smbnode *np, int op, caddr_t id,
128681a5bbeSBoris Popov 	off_t start, off_t end,	struct smb_cred *scred);
129681a5bbeSBoris Popov int  smbfs_smb_statfs(struct smb_share *ssp, struct statfs *sbp,
130681a5bbeSBoris Popov 	struct smb_cred *scred);
131c829016eSAndrey V. Elsukov int  smbfs_smb_setfsize(struct smbnode *np, int64_t newsize,
132c829016eSAndrey V. Elsukov 	struct smb_cred *scred);
133681a5bbeSBoris Popov 
1343c2f5c3cSBoris Popov int  smbfs_smb_query_info(struct smbnode *np, const char *name, int len,
1353c2f5c3cSBoris Popov 	struct smbfattr *fap, struct smb_cred *scred);
136681a5bbeSBoris Popov int  smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr,
137681a5bbeSBoris Popov 	struct timespec *mtime, struct smb_cred *scred);
138681a5bbeSBoris Popov int  smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime,
139681a5bbeSBoris Popov 	struct timespec *atime, int attr, struct smb_cred *scred);
140681a5bbeSBoris Popov int  smbfs_smb_setpattrNT(struct smbnode *np, u_int16_t attr,
141681a5bbeSBoris Popov 	struct timespec *mtime, struct timespec *atime, struct smb_cred *scred);
142681a5bbeSBoris Popov 
143681a5bbeSBoris Popov int  smbfs_smb_setftime(struct smbnode *np, struct timespec *mtime,
144681a5bbeSBoris Popov 	struct timespec *atime, struct smb_cred *scred);
145681a5bbeSBoris Popov int  smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr,
146681a5bbeSBoris Popov 	struct timespec *mtime,	struct timespec *atime, struct smb_cred *scred);
147681a5bbeSBoris Popov 
148681a5bbeSBoris Popov int  smbfs_smb_open(struct smbnode *np, int accmode, struct smb_cred *scred);
149681a5bbeSBoris Popov int  smbfs_smb_close(struct smb_share *ssp, u_int16_t fid,
150681a5bbeSBoris Popov 	 struct timespec *mtime, struct smb_cred *scred);
151681a5bbeSBoris Popov int  smbfs_smb_create(struct smbnode *dnp, const char *name, int len,
152681a5bbeSBoris Popov 	struct smb_cred *scred);
153681a5bbeSBoris Popov int  smbfs_smb_delete(struct smbnode *np, struct smb_cred *scred);
1543c2f5c3cSBoris Popov int  smbfs_smb_flush(struct smbnode *np, struct smb_cred *scred);
155681a5bbeSBoris Popov int  smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp,
156681a5bbeSBoris Popov 	const char *tname, int tnmlen, struct smb_cred *scred);
157681a5bbeSBoris Popov int  smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp,
158681a5bbeSBoris Popov 	const char *tname, int tnmlen, u_int16_t flags, struct smb_cred *scred);
159681a5bbeSBoris Popov int  smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len,
160681a5bbeSBoris Popov 	struct smb_cred *scred);
161681a5bbeSBoris Popov int  smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scred);
162681a5bbeSBoris Popov int  smbfs_findopen(struct smbnode *dnp, const char *wildcard, int wclen,
163681a5bbeSBoris Popov 	int attr, struct smb_cred *scred, struct smbfs_fctx **ctxpp);
164681a5bbeSBoris Popov int  smbfs_findnext(struct smbfs_fctx *ctx, int limit, struct smb_cred *scred);
165681a5bbeSBoris Popov int  smbfs_findclose(struct smbfs_fctx *ctx, struct smb_cred *scred);
166681a5bbeSBoris Popov int  smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp,
167681a5bbeSBoris Popov 	struct smbnode *dnp, const char *name, int nmlen);
168681a5bbeSBoris Popov int  smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen,
169681a5bbeSBoris Popov 	struct smbfattr *fap, struct smb_cred *scred);
170681a5bbeSBoris Popov 
1714ebd3ea1STakanori Watanabe int  smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt);
172681a5bbeSBoris Popov 
173681a5bbeSBoris Popov void  smb_time_local2server(struct timespec *tsp, int tzoff, u_long *seconds);
174681a5bbeSBoris Popov void  smb_time_server2local(u_long seconds, int tzoff, struct timespec *tsp);
175681a5bbeSBoris Popov void  smb_time_NT2local(int64_t nsec, int tzoff, struct timespec *tsp);
176681a5bbeSBoris Popov void  smb_time_local2NT(struct timespec *tsp, int tzoff, int64_t *nsec);
177681a5bbeSBoris Popov void  smb_time_unix2dos(struct timespec *tsp, int tzoff, u_int16_t *ddp,
178681a5bbeSBoris Popov 	     u_int16_t *dtp, u_int8_t *dhp);
179681a5bbeSBoris Popov void smb_dos2unixtime (u_int dd, u_int dt, u_int dh, int tzoff, struct timespec *tsp);
180681a5bbeSBoris Popov 
181afe09751SDavide Italiano void *smbfs_malloc_scred(void);
182afe09751SDavide Italiano void smbfs_free_scred(void *);
183681a5bbeSBoris Popov #endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */
184