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 struct byte_range_lock *br_lck,
46 enum brl_type lock_type,
47 enum brl_flavour lock_flav,
48 struct server_id *blocker_pid,
50 bool brl_unlock(struct messaging_context *msg_ctx,
51 struct byte_range_lock *br_lck,
56 enum brl_flavour lock_flav);
57 bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
58 struct byte_range_lock *br_lck,
59 const struct lock_struct *plock);
60 bool brl_locktest(struct byte_range_lock *br_lck,
61 const struct lock_struct *rw_probe);
62 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
67 enum brl_type *plock_type,
68 enum brl_flavour lock_flav);
69 bool brl_mark_disconnected(struct files_struct *fsp);
70 bool brl_reconnect_disconnected(struct files_struct *fsp);
71 void brl_close_fnum(struct messaging_context *msg_ctx,
72 struct byte_range_lock *br_lck);
73 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
74 enum brl_type lock_type,
75 enum brl_flavour lock_flav,
76 br_off start, br_off size,
79 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
81 struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp);
82 bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
84 /* The following definitions come from locking/locking.c */
86 const char *lock_type_name(enum brl_type lock_type);
87 const char *lock_flav_name(enum brl_flavour lock_flav);
88 void init_strict_lock_struct(files_struct *fsp,
92 enum brl_type lock_type,
93 struct lock_struct *plock);
94 bool strict_lock_check_default(files_struct *fsp,
95 struct lock_struct *plock);
96 NTSTATUS query_lock(files_struct *fsp,
100 enum brl_type *plock_type,
101 enum brl_flavour lock_flav);
102 NTSTATUS do_lock(files_struct *fsp,
106 enum brl_type lock_type,
107 enum brl_flavour lock_flav,
108 struct server_id *pblocker_pid,
110 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
115 enum brl_flavour lock_flav);
116 void locking_close_file(struct messaging_context *msg_ctx,
118 enum file_close_type close_type);
119 bool locking_init(void);
120 bool locking_init_readonly(void);
121 bool locking_end(void);
122 char *share_mode_str(TALLOC_CTX *ctx, int num,
123 const struct file_id *id,
124 const struct share_mode_entry *e);
125 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
127 struct share_mode_lock *get_share_mode_lock(
130 const char *servicepath,
131 const struct smb_filename *smb_fname,
132 const struct timespec *old_write_time);
133 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
135 struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx,
136 struct tevent_context *ev,
139 NTSTATUS fetch_share_mode_recv(struct tevent_req *req,
141 struct share_mode_lock **_lck);
142 bool rename_share_filename(struct messaging_context *msg_ctx,
143 struct share_mode_lock *lck,
145 const char *servicepath,
146 uint32_t orig_name_hash,
147 uint32_t new_name_hash,
148 const struct smb_filename *smb_fname);
149 void get_file_infos(struct file_id id,
151 bool *delete_on_close,
152 struct timespec *write_time);
153 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
154 bool share_mode_stale_pid(struct share_mode_data *d, uint32_t idx);
155 bool set_share_mode(struct share_mode_lock *lck,
156 struct files_struct *fsp,
160 const struct GUID *client_guid,
161 const struct smb2_lease_key *lease_key);
162 struct share_mode_entry *find_share_mode_entry(struct share_mode_lock *lck,
164 void remove_stale_share_mode_entries(struct share_mode_data *d);
165 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
166 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
167 struct files_struct *fsp);
168 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
169 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
170 bool get_delete_on_close_token(struct share_mode_lock *lck,
172 const struct security_token **pp_nt_tok,
173 const struct security_unix_token **pp_tok);
174 void reset_delete_on_close_lck(files_struct *fsp,
175 struct share_mode_lock *lck);
176 void set_delete_on_close_lck(files_struct *fsp,
177 struct share_mode_lock *lck,
178 const struct security_token *nt_tok,
179 const struct security_unix_token *tok);
180 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,
181 const struct security_token *nt_tok,
182 const struct security_unix_token *tok);
183 bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
184 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
185 bool set_write_time(struct file_id fileid, struct timespec write_time);
186 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
187 bool file_has_open_streams(files_struct *fsp);
188 int share_mode_forall(int (*fn)(struct file_id fid,
189 const struct share_mode_data *data,
192 int share_entry_forall(int (*fn)(struct file_id fid,
193 const struct share_mode_data *data,
194 const struct share_mode_entry *entry,
197 bool share_mode_cleanup_disconnected(struct file_id id,
198 uint64_t open_persistent_id);
199 bool share_mode_forall_leases(
200 struct share_mode_lock *lck,
201 bool (*fn)(struct share_mode_lock *lck,
202 struct share_mode_entry *e,
207 /* The following definitions come from locking/posix.c */
209 bool is_posix_locked(files_struct *fsp,
212 enum brl_type *plock_type,
213 enum brl_flavour lock_flav);
214 bool posix_locking_init(bool read_only);
215 bool posix_locking_end(void);
216 int fd_close_posix(const struct files_struct *fsp);
217 bool set_posix_lock_windows_flavour(files_struct *fsp,
220 enum brl_type lock_type,
221 const struct lock_context *lock_ctx,
222 const struct lock_struct *plocks,
225 bool release_posix_lock_windows_flavour(files_struct *fsp,
228 enum brl_type deleted_lock_type,
229 const struct lock_context *lock_ctx,
230 const struct lock_struct *plocks,
232 bool set_posix_lock_posix_flavour(files_struct *fsp,
235 enum brl_type lock_type,
236 const struct lock_context *lock_ctx,
238 bool release_posix_lock_posix_flavour(files_struct *fsp,
241 const struct lock_context *lock_ctx,
242 const struct lock_struct *plocks,
245 /* The following definitions come from locking/leases_util.c */
246 uint32_t map_oplock_to_lease_type(uint16_t op_type);
247 uint32_t fsp_lease_type(const struct files_struct *fsp);
248 uint32_t lease_type_is_exclusive(uint32_t lease_type);
249 bool fsp_lease_type_is_exclusive(const struct files_struct *fsp);
251 #endif /* _LOCKING_PROTO_H_ */