2 * Unix SMB/CIFS implementation.
5 * Copyright (C) Andrew Tridgell 1992-2000
6 * Copyright (C) Jeremy Allison 1992-2006
7 * Copyright (C) Volker Lendecke 2005
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _LOCKING_PROTO_H_
24 #define _LOCKING_PROTO_H_
26 /* The following definitions come from locking/brlock.c */
28 void brl_init(bool read_only
);
29 void brl_shutdown(void);
31 unsigned int brl_num_locks(const struct byte_range_lock
*brl
);
32 struct files_struct
*brl_fsp(struct byte_range_lock
*brl
);
33 uint32_t brl_num_read_oplocks(const struct byte_range_lock
*brl
);
34 void brl_set_num_read_oplocks(struct byte_range_lock
*brl
,
35 uint32_t num_read_oplocks
);
37 NTSTATUS
brl_lock_windows_default(struct byte_range_lock
*br_lck
,
38 struct lock_struct
*plock
,
41 NTSTATUS
brl_lock(struct messaging_context
*msg_ctx
,
42 struct byte_range_lock
*br_lck
,
47 enum brl_type lock_type
,
48 enum brl_flavour lock_flav
,
51 bool brl_unlock(struct messaging_context
*msg_ctx
,
52 struct byte_range_lock
*br_lck
,
57 enum brl_flavour lock_flav
);
58 bool brl_unlock_windows_default(struct messaging_context
*msg_ctx
,
59 struct byte_range_lock
*br_lck
,
60 const struct lock_struct
*plock
);
61 bool brl_locktest(struct byte_range_lock
*br_lck
,
62 const struct lock_struct
*rw_probe
);
63 NTSTATUS
brl_lockquery(struct byte_range_lock
*br_lck
,
68 enum brl_type
*plock_type
,
69 enum brl_flavour lock_flav
);
70 bool brl_lock_cancel(struct byte_range_lock
*br_lck
,
75 enum brl_flavour lock_flav
);
76 bool brl_lock_cancel_default(struct byte_range_lock
*br_lck
,
77 struct lock_struct
*plock
);
78 bool brl_mark_disconnected(struct files_struct
*fsp
);
79 bool brl_reconnect_disconnected(struct files_struct
*fsp
);
80 void brl_close_fnum(struct messaging_context
*msg_ctx
,
81 struct byte_range_lock
*br_lck
);
82 int brl_forall(void (*fn
)(struct file_id id
, struct server_id pid
,
83 enum brl_type lock_type
,
84 enum brl_flavour lock_flav
,
85 br_off start
, br_off size
,
88 struct byte_range_lock
*brl_get_locks(TALLOC_CTX
*mem_ctx
,
90 struct byte_range_lock
*brl_get_locks_readonly(files_struct
*fsp
);
91 void brl_revalidate(struct messaging_context
*msg_ctx
,
94 struct server_id server_id
,
96 bool brl_cleanup_disconnected(struct file_id fid
, uint64_t open_persistent_id
);
98 /* The following definitions come from locking/locking.c */
100 const char *lock_type_name(enum brl_type lock_type
);
101 const char *lock_flav_name(enum brl_flavour lock_flav
);
102 void init_strict_lock_struct(files_struct
*fsp
,
106 enum brl_type lock_type
,
107 struct lock_struct
*plock
);
108 bool strict_lock_check_default(files_struct
*fsp
,
109 struct lock_struct
*plock
);
110 NTSTATUS
query_lock(files_struct
*fsp
,
114 enum brl_type
*plock_type
,
115 enum brl_flavour lock_flav
);
116 struct byte_range_lock
*do_lock(struct messaging_context
*msg_ctx
,
121 enum brl_type lock_type
,
122 enum brl_flavour lock_flav
,
126 NTSTATUS
do_unlock(struct messaging_context
*msg_ctx
,
131 enum brl_flavour lock_flav
);
132 NTSTATUS
do_lock_cancel(files_struct
*fsp
,
136 enum brl_flavour lock_flav
);
137 void locking_close_file(struct messaging_context
*msg_ctx
,
139 enum file_close_type close_type
);
140 bool locking_init(void);
141 bool locking_init_readonly(void);
142 bool locking_end(void);
143 char *share_mode_str(TALLOC_CTX
*ctx
, int num
, const struct share_mode_entry
*e
);
144 struct share_mode_lock
*get_existing_share_mode_lock(TALLOC_CTX
*mem_ctx
,
146 struct share_mode_lock
*get_share_mode_lock(
149 const char *servicepath
,
150 const struct smb_filename
*smb_fname
,
151 const struct timespec
*old_write_time
);
152 struct share_mode_lock
*fetch_share_mode_unlocked(TALLOC_CTX
*mem_ctx
,
154 struct tevent_req
*fetch_share_mode_send(TALLOC_CTX
*mem_ctx
,
155 struct tevent_context
*ev
,
158 NTSTATUS
fetch_share_mode_recv(struct tevent_req
*req
,
160 struct share_mode_lock
**_lck
);
161 bool rename_share_filename(struct messaging_context
*msg_ctx
,
162 struct share_mode_lock
*lck
,
164 const char *servicepath
,
165 uint32_t orig_name_hash
,
166 uint32_t new_name_hash
,
167 const struct smb_filename
*smb_fname
);
168 void get_file_infos(struct file_id id
,
170 bool *delete_on_close
,
171 struct timespec
*write_time
);
172 bool is_valid_share_mode_entry(const struct share_mode_entry
*e
);
173 bool share_mode_stale_pid(struct share_mode_data
*d
, uint32_t idx
);
174 bool set_share_mode(struct share_mode_lock
*lck
, struct files_struct
*fsp
,
175 uid_t uid
, uint64_t mid
, uint16_t op_type
,
177 struct share_mode_entry
*find_share_mode_entry(struct share_mode_lock
*lck
,
179 void remove_stale_share_mode_entries(struct share_mode_data
*d
);
180 bool del_share_mode(struct share_mode_lock
*lck
, files_struct
*fsp
);
181 bool mark_share_mode_disconnected(struct share_mode_lock
*lck
,
182 struct files_struct
*fsp
);
183 bool remove_share_oplock(struct share_mode_lock
*lck
, files_struct
*fsp
);
184 bool downgrade_share_oplock(struct share_mode_lock
*lck
, files_struct
*fsp
);
185 struct share_mode_lease
;
186 NTSTATUS
downgrade_share_lease(struct smbd_server_connection
*sconn
,
187 struct share_mode_lock
*lck
,
188 const struct smb2_lease_key
*key
,
189 uint32_t new_lease_state
,
190 struct share_mode_lease
**_l
);
191 bool get_delete_on_close_token(struct share_mode_lock
*lck
,
193 const struct security_token
**pp_nt_tok
,
194 const struct security_unix_token
**pp_tok
);
195 void reset_delete_on_close_lck(files_struct
*fsp
,
196 struct share_mode_lock
*lck
);
197 void set_delete_on_close_lck(files_struct
*fsp
,
198 struct share_mode_lock
*lck
,
199 const struct security_token
*nt_tok
,
200 const struct security_unix_token
*tok
);
201 bool set_delete_on_close(files_struct
*fsp
, bool delete_on_close
,
202 const struct security_token
*nt_tok
,
203 const struct security_unix_token
*tok
);
204 bool is_delete_on_close_set(struct share_mode_lock
*lck
, uint32_t name_hash
);
205 bool set_sticky_write_time(struct file_id fileid
, struct timespec write_time
);
206 bool set_write_time(struct file_id fileid
, struct timespec write_time
);
207 struct timespec
get_share_mode_write_time(struct share_mode_lock
*lck
);
208 bool file_has_open_streams(files_struct
*fsp
);
209 int share_mode_forall(int (*fn
)(struct file_id fid
,
210 const struct share_mode_data
*data
,
213 int share_entry_forall(int (*fn
)(const struct share_mode_entry
*,
214 const char *, const char *,
215 const char *, void *),
217 bool share_mode_cleanup_disconnected(struct file_id id
,
218 uint64_t open_persistent_id
);
221 /* The following definitions come from locking/posix.c */
223 bool is_posix_locked(files_struct
*fsp
,
226 enum brl_type
*plock_type
,
227 enum brl_flavour lock_flav
);
228 bool posix_locking_init(bool read_only
);
229 bool posix_locking_end(void);
230 int fd_close_posix(const struct files_struct
*fsp
);
231 bool set_posix_lock_windows_flavour(files_struct
*fsp
,
234 enum brl_type lock_type
,
235 const struct lock_context
*lock_ctx
,
236 const struct lock_struct
*plocks
,
239 bool release_posix_lock_windows_flavour(files_struct
*fsp
,
242 enum brl_type deleted_lock_type
,
243 const struct lock_context
*lock_ctx
,
244 const struct lock_struct
*plocks
,
246 bool set_posix_lock_posix_flavour(files_struct
*fsp
,
249 enum brl_type lock_type
,
250 const struct lock_context
*lock_ctx
,
252 bool release_posix_lock_posix_flavour(files_struct
*fsp
,
255 const struct lock_context
*lock_ctx
,
256 const struct lock_struct
*plocks
,
259 /* The following definitions come from locking/leases_util.c */
260 uint32_t map_oplock_to_lease_type(uint16_t op_type
);
261 uint32_t fsp_lease_type(const struct files_struct
*fsp
);
262 uint32_t lease_type_is_exclusive(uint32_t lease_type
);
263 bool fsp_lease_type_is_exclusive(const struct files_struct
*fsp
);
265 #endif /* _LOCKING_PROTO_H_ */