3db9e7aa5842be46003611c7024d9b30709dfbf6
[Samba.git] / source3 / locking / proto.h
blob3db9e7aa5842be46003611c7024d9b30709dfbf6
1 /*
2 * Unix SMB/CIFS implementation.
3 * Locking functions
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 bool brl_have_read_oplocks(const struct byte_range_lock *brl);
34 void brl_set_have_read_oplocks(struct byte_range_lock *brl,
35 bool have_read_oplocks);
37 NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
38 struct lock_struct *plock,
39 bool blocking_lock);
41 NTSTATUS brl_lock(struct messaging_context *msg_ctx,
42 struct byte_range_lock *br_lck,
43 uint64_t smblctx,
44 struct server_id pid,
45 br_off start,
46 br_off size,
47 enum brl_type lock_type,
48 enum brl_flavour lock_flav,
49 bool blocking_lock,
50 uint64_t *psmblctx);
51 bool brl_unlock(struct messaging_context *msg_ctx,
52 struct byte_range_lock *br_lck,
53 uint64_t smblctx,
54 struct server_id pid,
55 br_off start,
56 br_off size,
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 uint64_t smblctx,
63 struct server_id pid,
64 br_off start,
65 br_off size,
66 enum brl_type lock_type,
67 enum brl_flavour lock_flav);
68 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
69 uint64_t *psmblctx,
70 struct server_id pid,
71 br_off *pstart,
72 br_off *psize,
73 enum brl_type *plock_type,
74 enum brl_flavour lock_flav);
75 bool brl_lock_cancel(struct byte_range_lock *br_lck,
76 uint64_t smblctx,
77 struct server_id pid,
78 br_off start,
79 br_off size,
80 enum brl_flavour lock_flav);
81 bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
82 struct lock_struct *plock);
83 bool brl_mark_disconnected(struct files_struct *fsp);
84 bool brl_reconnect_disconnected(struct files_struct *fsp);
85 void brl_close_fnum(struct messaging_context *msg_ctx,
86 struct byte_range_lock *br_lck);
87 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
88 enum brl_type lock_type,
89 enum brl_flavour lock_flav,
90 br_off start, br_off size,
91 void *private_data),
92 void *private_data);
93 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
94 files_struct *fsp);
95 struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp);
96 void brl_revalidate(struct messaging_context *msg_ctx,
97 void *private_data,
98 uint32_t msg_type,
99 struct server_id server_id,
100 DATA_BLOB *data);
101 bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
103 /* The following definitions come from locking/locking.c */
105 const char *lock_type_name(enum brl_type lock_type);
106 const char *lock_flav_name(enum brl_flavour lock_flav);
107 void init_strict_lock_struct(files_struct *fsp,
108 uint64_t smblctx,
109 br_off start,
110 br_off size,
111 enum brl_type lock_type,
112 struct lock_struct *plock);
113 bool strict_lock_default(files_struct *fsp,
114 struct lock_struct *plock);
115 void strict_unlock_default(files_struct *fsp,
116 struct lock_struct *plock);
117 NTSTATUS query_lock(files_struct *fsp,
118 uint64_t *psmblctx,
119 uint64_t *pcount,
120 uint64_t *poffset,
121 enum brl_type *plock_type,
122 enum brl_flavour lock_flav);
123 struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
124 files_struct *fsp,
125 uint64_t smblctx,
126 uint64_t count,
127 uint64_t offset,
128 enum brl_type lock_type,
129 enum brl_flavour lock_flav,
130 bool blocking_lock,
131 NTSTATUS *perr,
132 uint64_t *psmblctx);
133 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
134 files_struct *fsp,
135 uint64_t smblctx,
136 uint64_t count,
137 uint64_t offset,
138 enum brl_flavour lock_flav);
139 NTSTATUS do_lock_cancel(files_struct *fsp,
140 uint64 smblctx,
141 uint64_t count,
142 uint64_t offset,
143 enum brl_flavour lock_flav);
144 void locking_close_file(struct messaging_context *msg_ctx,
145 files_struct *fsp,
146 enum file_close_type close_type);
147 bool locking_init(void);
148 bool locking_init_readonly(void);
149 bool locking_end(void);
150 char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e);
151 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
152 struct file_id id);
153 struct share_mode_lock *get_share_mode_lock(
154 TALLOC_CTX *mem_ctx,
155 struct file_id id,
156 const char *servicepath,
157 const struct smb_filename *smb_fname,
158 const struct timespec *old_write_time);
159 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
160 struct file_id id);
161 bool rename_share_filename(struct messaging_context *msg_ctx,
162 struct share_mode_lock *lck,
163 struct file_id id,
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,
169 uint32_t name_hash,
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, files_struct *fsp,
175 uid_t uid, uint64_t mid, uint16 op_type);
176 void remove_stale_share_mode_entries(struct share_mode_data *d);
177 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
178 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
179 struct files_struct *fsp);
180 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
181 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
182 bool get_delete_on_close_token(struct share_mode_lock *lck,
183 uint32_t name_hash,
184 const struct security_token **pp_nt_tok,
185 const struct security_unix_token **pp_tok);
186 void set_delete_on_close_lck(files_struct *fsp,
187 struct share_mode_lock *lck,
188 bool delete_on_close,
189 const struct security_token *nt_tok,
190 const struct security_unix_token *tok);
191 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,
192 const struct security_token *nt_tok,
193 const struct security_unix_token *tok);
194 bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
195 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
196 bool set_write_time(struct file_id fileid, struct timespec write_time);
197 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
198 int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *,
199 const char *, void *),
200 void *private_data);
201 bool share_mode_cleanup_disconnected(struct file_id id,
202 uint64_t open_persistent_id);
205 /* The following definitions come from locking/posix.c */
207 bool is_posix_locked(files_struct *fsp,
208 uint64_t *pu_offset,
209 uint64_t *pu_count,
210 enum brl_type *plock_type,
211 enum brl_flavour lock_flav);
212 bool posix_locking_init(bool read_only);
213 bool posix_locking_end(void);
214 int fd_close_posix(struct files_struct *fsp);
215 bool set_posix_lock_windows_flavour(files_struct *fsp,
216 uint64_t u_offset,
217 uint64_t u_count,
218 enum brl_type lock_type,
219 const struct lock_context *lock_ctx,
220 const struct lock_struct *plocks,
221 int num_locks,
222 int *errno_ret);
223 bool release_posix_lock_windows_flavour(files_struct *fsp,
224 uint64_t u_offset,
225 uint64_t u_count,
226 enum brl_type deleted_lock_type,
227 const struct lock_context *lock_ctx,
228 const struct lock_struct *plocks,
229 int num_locks);
230 bool set_posix_lock_posix_flavour(files_struct *fsp,
231 uint64_t u_offset,
232 uint64_t u_count,
233 enum brl_type lock_type,
234 int *errno_ret);
235 bool release_posix_lock_posix_flavour(files_struct *fsp,
236 uint64_t u_offset,
237 uint64_t u_count,
238 const struct lock_context *lock_ctx,
239 const struct lock_struct *plocks,
240 int num_locks);
242 #endif /* _LOCKING_PROTO_H_ */