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 byte_range_lock *br_lck,
58 const struct lock_struct *plock);
59 bool brl_locktest(struct byte_range_lock *br_lck,
60 const struct lock_struct *rw_probe);
61 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
66 enum brl_type *plock_type,
67 enum brl_flavour lock_flav);
68 bool brl_mark_disconnected(struct files_struct *fsp);
69 bool brl_reconnect_disconnected(struct files_struct *fsp);
70 void brl_close_fnum(struct messaging_context *msg_ctx,
71 struct byte_range_lock *br_lck);
72 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
73 enum brl_type lock_type,
74 enum brl_flavour lock_flav,
75 br_off start, br_off size,
78 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
80 struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp);
81 bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
83 /* The following definitions come from locking/locking.c */
85 const char *lock_type_name(enum brl_type lock_type);
86 const char *lock_flav_name(enum brl_flavour lock_flav);
87 void init_strict_lock_struct(files_struct *fsp,
91 enum brl_type lock_type,
92 struct lock_struct *plock);
93 bool strict_lock_check_default(files_struct *fsp,
94 struct lock_struct *plock);
95 NTSTATUS query_lock(files_struct *fsp,
99 enum brl_type *plock_type,
100 enum brl_flavour lock_flav);
101 NTSTATUS do_lock(files_struct *fsp,
105 enum brl_type lock_type,
106 enum brl_flavour lock_flav,
107 struct server_id *pblocker_pid,
109 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
114 enum brl_flavour lock_flav);
115 void locking_close_file(struct messaging_context *msg_ctx,
117 enum file_close_type close_type);
118 bool locking_init(void);
119 bool locking_init_readonly(void);
120 bool locking_end(void);
121 char *share_mode_str(TALLOC_CTX *ctx, int num,
122 const struct file_id *id,
123 const struct share_mode_entry *e);
124 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
126 struct share_mode_lock *get_share_mode_lock(
129 const char *servicepath,
130 const struct smb_filename *smb_fname,
131 const struct timespec *old_write_time);
132 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
134 struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx,
135 struct tevent_context *ev,
138 NTSTATUS fetch_share_mode_recv(struct tevent_req *req,
140 struct share_mode_lock **_lck);
141 bool rename_share_filename(struct messaging_context *msg_ctx,
142 struct share_mode_lock *lck,
144 const char *servicepath,
145 uint32_t orig_name_hash,
146 uint32_t new_name_hash,
147 const struct smb_filename *smb_fname);
148 void get_file_infos(struct file_id id,
150 bool *delete_on_close,
151 struct timespec *write_time);
152 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
153 bool share_mode_stale_pid(struct share_mode_data *d, uint32_t idx);
154 bool set_share_mode(struct share_mode_lock *lck,
155 struct files_struct *fsp,
159 const struct GUID *client_guid,
160 const struct smb2_lease_key *lease_key);
161 struct share_mode_entry *find_share_mode_entry(struct share_mode_lock *lck,
163 void remove_stale_share_mode_entries(struct share_mode_data *d);
164 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
165 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
166 struct files_struct *fsp);
167 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
168 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
169 bool get_delete_on_close_token(struct share_mode_lock *lck,
171 const struct security_token **pp_nt_tok,
172 const struct security_unix_token **pp_tok);
173 void reset_delete_on_close_lck(files_struct *fsp,
174 struct share_mode_lock *lck);
175 void set_delete_on_close_lck(files_struct *fsp,
176 struct share_mode_lock *lck,
177 const struct security_token *nt_tok,
178 const struct security_unix_token *tok);
179 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,
180 const struct security_token *nt_tok,
181 const struct security_unix_token *tok);
182 bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
183 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
184 bool set_write_time(struct file_id fileid, struct timespec write_time);
185 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
186 bool file_has_open_streams(files_struct *fsp);
187 int share_mode_forall(int (*fn)(struct file_id fid,
188 const struct share_mode_data *data,
191 int share_entry_forall(int (*fn)(struct file_id fid,
192 const struct share_mode_data *data,
193 const struct share_mode_entry *entry,
196 bool share_mode_cleanup_disconnected(struct file_id id,
197 uint64_t open_persistent_id);
198 bool share_mode_forall_leases(
199 struct share_mode_lock *lck,
200 bool (*fn)(struct share_mode_lock *lck,
201 struct share_mode_entry *e,
206 /* The following definitions come from locking/posix.c */
208 bool is_posix_locked(files_struct *fsp,
211 enum brl_type *plock_type,
212 enum brl_flavour lock_flav);
213 bool posix_locking_init(bool read_only);
214 bool posix_locking_end(void);
215 int fd_close_posix(const struct files_struct *fsp);
216 bool set_posix_lock_windows_flavour(files_struct *fsp,
219 enum brl_type lock_type,
220 const struct lock_context *lock_ctx,
221 const struct lock_struct *plocks,
224 bool release_posix_lock_windows_flavour(files_struct *fsp,
227 enum brl_type deleted_lock_type,
228 const struct lock_context *lock_ctx,
229 const struct lock_struct *plocks,
231 bool set_posix_lock_posix_flavour(files_struct *fsp,
234 enum brl_type lock_type,
235 const struct lock_context *lock_ctx,
237 bool release_posix_lock_posix_flavour(files_struct *fsp,
240 const struct lock_context *lock_ctx,
241 const struct lock_struct *plocks,
244 /* The following definitions come from locking/leases_util.c */
245 uint32_t map_oplock_to_lease_type(uint16_t op_type);
246 uint32_t fsp_lease_type(const struct files_struct *fsp);
247 uint32_t lease_type_is_exclusive(uint32_t lease_type);
248 bool fsp_lease_type_is_exclusive(const struct files_struct *fsp);
250 #endif /* _LOCKING_PROTO_H_ */