xref: /freebsd/sys/fs/smbfs/smbfs_subr.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2000-2001 Boris Popov
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 #ifndef _FS_SMBFS_SMBFS_SUBR_H_
31 #define _FS_SMBFS_SMBFS_SUBR_H_
32 
33 #ifdef MALLOC_DECLARE
34 MALLOC_DECLARE(M_SMBFSDATA);
35 MALLOC_DECLARE(M_SMBFSCRED);
36 #endif
37 
38 #define SMBFSERR(format, args...) printf("%s: "format, __func__ ,## args)
39 
40 #ifdef SMB_VNODE_DEBUG
41 #define SMBVDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
42 #else
43 #define SMBVDEBUG(format, args...)
44 #endif
45 
46 /*
47  * Possible lock commands
48  */
49 #define SMB_LOCK_EXCL		0
50 #define	SMB_LOCK_SHARED		1
51 #define	SMB_LOCK_RELEASE	2
52 
53 struct smbmount;
54 struct proc;
55 struct timespec;
56 struct ucred;
57 struct vattr;
58 struct vnode;
59 struct statfs;
60 
61 struct smbfattr {
62 	int		fa_attr;
63 	int64_t		fa_size;
64 	struct timespec	fa_atime;
65 	struct timespec	fa_ctime;
66 	struct timespec	fa_mtime;
67 	long		fa_ino;
68 };
69 
70 /*
71  * Context to perform findfirst/findnext/findclose operations
72  */
73 #define	SMBFS_RDD_FINDFIRST	0x01
74 #define	SMBFS_RDD_EOF		0x02
75 #define	SMBFS_RDD_FINDSINGLE	0x04
76 #define	SMBFS_RDD_USESEARCH	0x08
77 #define	SMBFS_RDD_NOCLOSE	0x10
78 #define	SMBFS_RDD_GOTRNAME	0x1000
79 
80 /*
81  * Search context supplied by server
82  */
83 #define	SMB_SKEYLEN		21			/* search context */
84 #define SMB_DENTRYLEN		(SMB_SKEYLEN + 22)	/* entire entry */
85 
86 struct smbfs_fctx {
87 	/*
88 	 * Setable values
89 	 */
90 	int		f_flags;	/* SMBFS_RDD_ */
91 	/*
92 	 * Return values
93 	 */
94 	struct smbfattr	f_attr;		/* current attributes */
95 	char *		f_name;		/* current file name */
96 	int		f_nmlen;	/* name len */
97 	/*
98 	 * Internal variables
99 	 */
100 	int		f_limit;	/* maximum number of entries */
101 	int		f_attrmask;	/* SMB_FA_ */
102 	int		f_wclen;
103 	const char *	f_wildcard;
104 	struct smbnode*	f_dnp;
105 	struct smb_cred*f_scred;
106 	struct smb_share *f_ssp;
107 	union {
108 		struct smb_rq *	uf_rq;
109 		struct smb_t2rq * uf_t2;
110 	} f_urq;
111 	int		f_left;		/* entries left */
112 	int		f_ecnt;		/* entries left in the current response */
113 	int		f_eofs;		/* entry offset in the parameter block */
114 	u_char 		f_skey[SMB_SKEYLEN]; /* server side search context */
115 	u_char		f_fname[8 + 1 + 3 + 1]; /* common case for 8.3 filenames */
116 	u_int16_t	f_Sid;
117 	u_int16_t	f_infolevel;
118 	int		f_rnamelen;
119 	char *		f_rname;	/* resume name/key */
120 	int		f_rnameofs;
121 };
122 
123 #define f_rq	f_urq.uf_rq
124 #define f_t2	f_urq.uf_t2
125 
126 /*
127  * smb level
128  */
129 int  smbfs_smb_lock(struct smbnode *np, int op, caddr_t id,
130 	off_t start, off_t end,	struct smb_cred *scred);
131 int  smbfs_smb_statfs(struct smb_share *ssp, struct statfs *sbp,
132 	struct smb_cred *scred);
133 int  smbfs_smb_setfsize(struct smbnode *np, int64_t newsize,
134 	struct smb_cred *scred);
135 
136 int  smbfs_smb_query_info(struct smbnode *np, const char *name, int len,
137 	struct smbfattr *fap, struct smb_cred *scred);
138 int  smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr,
139 	struct timespec *mtime, struct smb_cred *scred);
140 int  smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime,
141 	struct timespec *atime, int attr, struct smb_cred *scred);
142 int  smbfs_smb_setpattrNT(struct smbnode *np, u_int16_t attr,
143 	struct timespec *mtime, struct timespec *atime, struct smb_cred *scred);
144 
145 int  smbfs_smb_setftime(struct smbnode *np, struct timespec *mtime,
146 	struct timespec *atime, struct smb_cred *scred);
147 int  smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr,
148 	struct timespec *mtime,	struct timespec *atime, struct smb_cred *scred);
149 
150 int  smbfs_smb_open(struct smbnode *np, int accmode, struct smb_cred *scred);
151 int  smbfs_smb_close(struct smb_share *ssp, u_int16_t fid,
152 	 struct timespec *mtime, struct smb_cred *scred);
153 int  smbfs_smb_create(struct smbnode *dnp, const char *name, int len,
154 	struct smb_cred *scred);
155 int  smbfs_smb_delete(struct smbnode *np, struct smb_cred *scred);
156 int  smbfs_smb_flush(struct smbnode *np, struct smb_cred *scred);
157 int  smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp,
158 	const char *tname, int tnmlen, struct smb_cred *scred);
159 int  smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp,
160 	const char *tname, int tnmlen, u_int16_t flags, struct smb_cred *scred);
161 int  smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len,
162 	struct smb_cred *scred);
163 int  smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scred);
164 int  smbfs_findopen(struct smbnode *dnp, const char *wildcard, int wclen,
165 	int attr, struct smb_cred *scred, struct smbfs_fctx **ctxpp);
166 int  smbfs_findnext(struct smbfs_fctx *ctx, int limit, struct smb_cred *scred);
167 int  smbfs_findclose(struct smbfs_fctx *ctx, struct smb_cred *scred);
168 int  smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp,
169 	struct smbnode *dnp, const char *name, int nmlen);
170 int  smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen,
171 	struct smbfattr *fap, struct smb_cred *scred);
172 
173 int  smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt);
174 
175 void  smb_time_local2server(struct timespec *tsp, int tzoff, u_long *seconds);
176 void  smb_time_server2local(u_long seconds, int tzoff, struct timespec *tsp);
177 void  smb_time_NT2local(int64_t nsec, int tzoff, struct timespec *tsp);
178 void  smb_time_local2NT(struct timespec *tsp, int tzoff, int64_t *nsec);
179 void  smb_time_unix2dos(struct timespec *tsp, int tzoff, u_int16_t *ddp,
180 	     u_int16_t *dtp, u_int8_t *dhp);
181 void smb_dos2unixtime (u_int dd, u_int dt, u_int dh, int tzoff, struct timespec *tsp);
182 
183 void *smbfs_malloc_scred(void);
184 void smbfs_free_scred(void *);
185 #endif /* !_FS_SMBFS_SMBFS_SUBR_H_ */
186