2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef __LOCKING_SHARE_MODE_LOCK_H__
17 #define __LOCKING_SHARE_MODE_LOCK_H__
21 #include "librpc/gen_ndr/file_id.h"
22 #include "lib/util/time.h"
24 struct share_mode_data
;
25 struct share_mode_lock
;
26 struct share_mode_entry
;
29 struct smb2_lease_key
;
31 bool locking_init(void);
32 bool locking_init_readonly(void);
33 bool locking_end(void);
35 struct file_id
share_mode_lock_file_id(const struct share_mode_lock
*lck
);
37 struct share_mode_lock
*get_existing_share_mode_lock(TALLOC_CTX
*mem_ctx
,
40 bool del_share_mode_open_id(struct share_mode_lock
*lck
,
41 struct server_id open_pid
,
42 uint64_t open_file_id
);
43 bool del_share_mode(struct share_mode_lock
*lck
,
44 struct files_struct
*fsp
);
45 bool downgrade_share_oplock(struct share_mode_lock
*lck
,
46 struct files_struct
*fsp
);
47 bool remove_share_oplock(struct share_mode_lock
*lck
,
48 struct files_struct
*fsp
);
49 bool file_has_read_lease(struct files_struct
*fsp
);
52 struct share_mode_lock
*lck
,
53 struct files_struct
*fsp
,
57 const struct smb2_lease_key
*lease_key
,
58 uint32_t share_access
,
59 uint32_t access_mask
);
60 bool reset_share_mode_entry(
61 struct share_mode_lock
*lck
,
62 struct server_id old_pid
,
63 uint64_t old_share_file_id
,
64 struct server_id new_pid
,
66 uint64_t new_share_file_id
);
68 bool mark_share_mode_disconnected(
69 struct share_mode_lock
*lck
, struct files_struct
*fsp
);
71 struct share_mode_lock
*fetch_share_mode_unlocked(
75 struct tevent_req
*fetch_share_mode_send(
77 struct tevent_context
*ev
,
80 NTSTATUS
fetch_share_mode_recv(
81 struct tevent_req
*req
,
83 struct share_mode_lock
**_lck
);
85 int share_entry_forall(
86 int (*fn
)(struct file_id fid
,
87 const struct share_mode_data
*data
,
88 const struct share_mode_entry
*entry
,
92 NTSTATUS
share_mode_count_entries(struct file_id fid
, size_t *num_share_modes
);
93 int share_mode_forall(
94 int (*fn
)(struct file_id fid
,
95 const struct share_mode_data
*data
,
98 bool share_mode_forall_entries(
99 struct share_mode_lock
*lck
,
100 bool (*fn
)(struct share_mode_entry
*e
,
105 NTTIME
share_mode_changed_write_time(struct share_mode_lock
*lck
);
106 void share_mode_set_changed_write_time(struct share_mode_lock
*lck
, struct timespec write_time
);
107 void share_mode_set_old_write_time(struct share_mode_lock
*lck
, struct timespec write_time
);
108 const char *share_mode_servicepath(struct share_mode_lock
*lck
);
109 char *share_mode_filename(TALLOC_CTX
*mem_ctx
, struct share_mode_lock
*lck
);
110 char *share_mode_data_dump(
111 TALLOC_CTX
*mem_ctx
, struct share_mode_lock
*lck
);
113 void share_mode_flags_get(
114 struct share_mode_lock
*lck
,
115 uint32_t *access_mask
,
116 uint32_t *share_mode
,
117 uint32_t *lease_type
);
118 void share_mode_flags_set(
119 struct share_mode_lock
*lck
,
120 uint32_t access_mask
,
125 struct tevent_req
*share_mode_watch_send(
127 struct tevent_context
*ev
,
128 struct share_mode_lock
*lck
,
129 struct server_id blocker
);
130 NTSTATUS
share_mode_watch_recv(
131 struct tevent_req
*req
, bool *blockerdead
, struct server_id
*blocker
);
132 NTSTATUS
share_mode_wakeup_waiters(struct file_id id
);
134 typedef void (*share_mode_do_locked_vfs_fn_t
)(
135 struct share_mode_lock
*lck
,
137 NTSTATUS
_share_mode_do_locked_vfs_denied(
139 share_mode_do_locked_vfs_fn_t fn
,
141 const char *location
);
142 #define share_mode_do_locked_vfs_denied(__id, __fn, __private_data) \
143 _share_mode_do_locked_vfs_denied(__id, __fn, __private_data, __location__)
144 NTSTATUS
_share_mode_do_locked_vfs_allowed(
146 share_mode_do_locked_vfs_fn_t fn
,
148 const char *location
);
149 #define share_mode_do_locked_vfs_allowed(__id, __fn, __private_data) \
150 _share_mode_do_locked_vfs_allowed(__id, __fn, __private_data, __location__)
152 struct share_mode_entry_prepare_state
{
153 struct file_id __fid
;
154 struct share_mode_lock
*__lck_ptr
;
156 #define __SHARE_MODE_LOCK_SPACE 32
157 uint8_t __u8_space
[__SHARE_MODE_LOCK_SPACE
];
158 #ifdef SHARE_MODE_ENTRY_PREPARE_STATE_LCK_SPACE
159 struct share_mode_lock __lck_space
;
164 typedef void (*share_mode_entry_prepare_lock_fn_t
)(
165 struct share_mode_lock
*lck
,
168 NTSTATUS
_share_mode_entry_prepare_lock(
169 struct share_mode_entry_prepare_state
*prepare_state
,
171 const char *servicepath
,
172 const struct smb_filename
*smb_fname
,
173 const struct timespec
*old_write_time
,
174 share_mode_entry_prepare_lock_fn_t fn
,
176 const char *location
);
177 #define share_mode_entry_prepare_lock_add(__prepare_state, __id, \
178 __servicepath, __smb_fname, __old_write_time, \
179 __fn, __private_data) \
180 _share_mode_entry_prepare_lock(__prepare_state, __id, \
181 __servicepath, __smb_fname, __old_write_time, \
182 __fn, __private_data, __location__);
183 #define share_mode_entry_prepare_lock_del(__prepare_state, __id, \
184 __fn, __private_data) \
185 _share_mode_entry_prepare_lock(__prepare_state, __id, \
187 __fn, __private_data, __location__);
189 typedef void (*share_mode_entry_prepare_unlock_fn_t
)(
190 struct share_mode_lock
*lck
,
192 NTSTATUS
_share_mode_entry_prepare_unlock(
193 struct share_mode_entry_prepare_state
*prepare_state
,
194 share_mode_entry_prepare_unlock_fn_t fn
,
196 const char *location
);
197 #define share_mode_entry_prepare_unlock(__prepare_state, \
198 __fn, __private_data) \
199 _share_mode_entry_prepare_unlock(__prepare_state, \
200 __fn, __private_data, __location__);