88af69f4c9144629c1b282c0650dfdb709838f8d
[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 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);
36
37 NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
38                                   struct lock_struct *plock);
39
40 NTSTATUS brl_lock(
41         struct byte_range_lock *br_lck,
42         uint64_t smblctx,
43         struct server_id pid,
44         br_off start,
45         br_off size,
46         enum brl_type lock_type,
47         enum brl_flavour lock_flav,
48         struct server_id *blocker_pid,
49         uint64_t *psmblctx);
50 bool brl_unlock(struct messaging_context *msg_ctx,
51                 struct byte_range_lock *br_lck,
52                 uint64_t smblctx,
53                 struct server_id pid,
54                 br_off start,
55                 br_off size,
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,
63                 uint64_t *psmblctx,
64                 struct server_id pid,
65                 br_off *pstart,
66                 br_off *psize,
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,
77                           void *private_data),
78                void *private_data);
79 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
80                                         files_struct *fsp);
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);
83
84 /* The following definitions come from locking/locking.c  */
85
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,
89                                 uint64_t smblctx,
90                                 br_off start,
91                                 br_off size,
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,
97                         uint64_t *psmblctx,
98                         uint64_t *pcount,
99                         uint64_t *poffset,
100                         enum brl_type *plock_type,
101                         enum brl_flavour lock_flav);
102 NTSTATUS do_lock(files_struct *fsp,
103                  uint64_t smblctx,
104                  uint64_t count,
105                  uint64_t offset,
106                  enum brl_type lock_type,
107                  enum brl_flavour lock_flav,
108                  struct server_id *pblocker_pid,
109                  uint64_t *psmblctx);
110 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
111                         files_struct *fsp,
112                         uint64_t smblctx,
113                         uint64_t count,
114                         uint64_t offset,
115                         enum brl_flavour lock_flav);
116 void locking_close_file(struct messaging_context *msg_ctx,
117                         files_struct *fsp,
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,
126                                                      struct file_id id);
127 struct share_mode_lock *get_share_mode_lock(
128         TALLOC_CTX *mem_ctx,
129         struct file_id id,
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,
134                                                   struct file_id id);
135 struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx,
136                                          struct tevent_context *ev,
137                                          struct file_id id,
138                                          bool *queued);
139 NTSTATUS fetch_share_mode_recv(struct tevent_req *req,
140                                TALLOC_CTX *mem_ctx,
141                                struct share_mode_lock **_lck);
142 bool rename_share_filename(struct messaging_context *msg_ctx,
143                         struct share_mode_lock *lck,
144                         struct file_id id,
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,
150                     uint32_t name_hash,
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,
157                     uid_t uid,
158                     uint64_t mid,
159                     uint16_t op_type,
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,
163                                                files_struct *fsp);
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,
171                                 uint32_t name_hash,
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,
190                                 void *private_data),
191                       void *private_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,
195                                  void *private_data),
196                       void *private_data);
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,
203                    void *private_data),
204         void *private_data);
205
206
207 /* The following definitions come from locking/posix.c  */
208
209 bool is_posix_locked(files_struct *fsp,
210                         uint64_t *pu_offset,
211                         uint64_t *pu_count,
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,
218                         uint64_t u_offset,
219                         uint64_t u_count,
220                         enum brl_type lock_type,
221                         const struct lock_context *lock_ctx,
222                         const struct lock_struct *plocks,
223                         int num_locks,
224                         int *errno_ret);
225 bool release_posix_lock_windows_flavour(files_struct *fsp,
226                                 uint64_t u_offset,
227                                 uint64_t u_count,
228                                 enum brl_type deleted_lock_type,
229                                 const struct lock_context *lock_ctx,
230                                 const struct lock_struct *plocks,
231                                 int num_locks);
232 bool set_posix_lock_posix_flavour(files_struct *fsp,
233                         uint64_t u_offset,
234                         uint64_t u_count,
235                         enum brl_type lock_type,
236                         const struct lock_context *lock_ctx,
237                         int *errno_ret);
238 bool release_posix_lock_posix_flavour(files_struct *fsp,
239                                 uint64_t u_offset,
240                                 uint64_t u_count,
241                                 const struct lock_context *lock_ctx,
242                                 const struct lock_struct *plocks,
243                                 int num_locks);
244
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);
250
251 #endif /* _LOCKING_PROTO_H_ */