smbd: Add brl_num_locks access function
[mat/samba.git] / source3 / locking / proto.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Locking functions
4  *
5  *  Copyright (C) Andrew Tridgell       1992-2000
6  *  Copyright (C) Jeremy Allison        1992-2006
7  *  Copyright (C) Volker Lendecke       2005
8  *
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.
13  *
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.
18  *
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/>.
21  */
22
23 #ifndef _LOCKING_PROTO_H_
24 #define _LOCKING_PROTO_H_
25
26 /* The following definitions come from locking/brlock.c  */
27
28 void brl_init(bool read_only);
29 void brl_shutdown(void);
30
31 unsigned int brl_num_locks(const struct byte_range_lock *brl);
32
33 NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
34                 struct lock_struct *plock,
35                 bool blocking_lock);
36
37 NTSTATUS brl_lock(struct messaging_context *msg_ctx,
38                 struct byte_range_lock *br_lck,
39                 uint64_t smblctx,
40                 struct server_id pid,
41                 br_off start,
42                 br_off size,
43                 enum brl_type lock_type,
44                 enum brl_flavour lock_flav,
45                 bool blocking_lock,
46                 uint64_t *psmblctx,
47                 struct blocking_lock_record *blr);
48 bool brl_unlock(struct messaging_context *msg_ctx,
49                 struct byte_range_lock *br_lck,
50                 uint64_t smblctx,
51                 struct server_id pid,
52                 br_off start,
53                 br_off size,
54                 enum brl_flavour lock_flav);
55 bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
56                                struct byte_range_lock *br_lck,
57                                const struct lock_struct *plock);
58 bool brl_locktest(struct byte_range_lock *br_lck,
59                 uint64_t smblctx,
60                 struct server_id pid,
61                 br_off start,
62                 br_off size,
63                 enum brl_type lock_type,
64                 enum brl_flavour lock_flav);
65 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
66                 uint64_t *psmblctx,
67                 struct server_id pid,
68                 br_off *pstart,
69                 br_off *psize,
70                 enum brl_type *plock_type,
71                 enum brl_flavour lock_flav);
72 bool brl_lock_cancel(struct byte_range_lock *br_lck,
73                 uint64_t smblctx,
74                 struct server_id pid,
75                 br_off start,
76                 br_off size,
77                 enum brl_flavour lock_flav,
78                 struct blocking_lock_record *blr);
79 bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
80                 struct lock_struct *plock);
81 bool brl_mark_disconnected(struct files_struct *fsp);
82 bool brl_reconnect_disconnected(struct files_struct *fsp);
83 void brl_close_fnum(struct messaging_context *msg_ctx,
84                     struct byte_range_lock *br_lck);
85 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
86                           enum brl_type lock_type,
87                           enum brl_flavour lock_flav,
88                           br_off start, br_off size,
89                           void *private_data),
90                void *private_data);
91 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
92                                         files_struct *fsp);
93 struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp);
94 void brl_revalidate(struct messaging_context *msg_ctx,
95                     void *private_data,
96                     uint32_t msg_type,
97                     struct server_id server_id,
98                     DATA_BLOB *data);
99 bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
100
101 /* The following definitions come from locking/locking.c  */
102
103 const char *lock_type_name(enum brl_type lock_type);
104 const char *lock_flav_name(enum brl_flavour lock_flav);
105 void init_strict_lock_struct(files_struct *fsp,
106                                 uint64_t smblctx,
107                                 br_off start,
108                                 br_off size,
109                                 enum brl_type lock_type,
110                                 struct lock_struct *plock);
111 bool strict_lock_default(files_struct *fsp,
112                                 struct lock_struct *plock);
113 void strict_unlock_default(files_struct *fsp,
114                                 struct lock_struct *plock);
115 NTSTATUS query_lock(files_struct *fsp,
116                         uint64_t *psmblctx,
117                         uint64_t *pcount,
118                         uint64_t *poffset,
119                         enum brl_type *plock_type,
120                         enum brl_flavour lock_flav);
121 struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
122                         files_struct *fsp,
123                         uint64_t smblctx,
124                         uint64_t count,
125                         uint64_t offset,
126                         enum brl_type lock_type,
127                         enum brl_flavour lock_flav,
128                         bool blocking_lock,
129                         NTSTATUS *perr,
130                         uint64_t *psmblctx,
131                         struct blocking_lock_record *blr);
132 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
133                         files_struct *fsp,
134                         uint64_t smblctx,
135                         uint64_t count,
136                         uint64_t offset,
137                         enum brl_flavour lock_flav);
138 NTSTATUS do_lock_cancel(files_struct *fsp,
139                         uint64 smblctx,
140                         uint64_t count,
141                         uint64_t offset,
142                         enum brl_flavour lock_flav,
143                         struct blocking_lock_record *blr);
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                         const char *servicepath,
164                         uint32_t orig_name_hash,
165                         uint32_t new_name_hash,
166                         const struct smb_filename *smb_fname);
167 void get_file_infos(struct file_id id,
168                     uint32_t name_hash,
169                     bool *delete_on_close,
170                     struct timespec *write_time);
171 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
172 bool share_mode_stale_pid(struct share_mode_data *d, unsigned idx);
173 void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
174                     uid_t uid, uint64_t mid, uint16 op_type);
175 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
176 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
177                                   struct files_struct *fsp);
178 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
179 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
180 bool get_delete_on_close_token(struct share_mode_lock *lck,
181                                 uint32_t name_hash,
182                                 const struct security_token **pp_nt_tok,
183                                 const struct security_unix_token **pp_tok);
184 void set_delete_on_close_lck(files_struct *fsp,
185                         struct share_mode_lock *lck,
186                         bool delete_on_close,
187                         const struct security_token *nt_tok,
188                         const struct security_unix_token *tok);
189 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,
190                         const struct security_token *nt_tok,
191                         const struct security_unix_token *tok);
192 bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
193 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
194 bool set_write_time(struct file_id fileid, struct timespec write_time);
195 int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *,
196                                  const char *, void *),
197                       void *private_data);
198 bool share_mode_cleanup_disconnected(struct file_id id,
199                                      uint64_t open_persistent_id);
200
201
202 /* The following definitions come from locking/posix.c  */
203
204 bool is_posix_locked(files_struct *fsp,
205                         uint64_t *pu_offset,
206                         uint64_t *pu_count,
207                         enum brl_type *plock_type,
208                         enum brl_flavour lock_flav);
209 bool posix_locking_init(bool read_only);
210 bool posix_locking_end(void);
211 int fd_close_posix(struct files_struct *fsp);
212 bool set_posix_lock_windows_flavour(files_struct *fsp,
213                         uint64_t u_offset,
214                         uint64_t u_count,
215                         enum brl_type lock_type,
216                         const struct lock_context *lock_ctx,
217                         const struct lock_struct *plocks,
218                         int num_locks,
219                         int *errno_ret);
220 bool release_posix_lock_windows_flavour(files_struct *fsp,
221                                 uint64_t u_offset,
222                                 uint64_t u_count,
223                                 enum brl_type deleted_lock_type,
224                                 const struct lock_context *lock_ctx,
225                                 const struct lock_struct *plocks,
226                                 int num_locks);
227 bool set_posix_lock_posix_flavour(files_struct *fsp,
228                         uint64_t u_offset,
229                         uint64_t u_count,
230                         enum brl_type lock_type,
231                         int *errno_ret);
232 bool release_posix_lock_posix_flavour(files_struct *fsp,
233                                 uint64_t u_offset,
234                                 uint64_t u_count,
235                                 const struct lock_context *lock_ctx,
236                                 const struct lock_struct *plocks,
237                                 int num_locks);
238
239 #endif /* _LOCKING_PROTO_H_ */