summaryrefslogtreecommitdiffstats
path: root/source3/locking/share_mode_lock.h
blob: 4f47b6fbcbe5203cd719eda3d6e710f889a6120b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __LOCKING_SHARE_MODE_LOCK_H__
#define __LOCKING_SHARE_MODE_LOCK_H__

#include "replace.h"
#include <tevent.h>
#include "librpc/gen_ndr/file_id.h"
#include "lib/util/time.h"

struct share_mode_data;
struct share_mode_lock;
struct share_mode_entry;
struct smb_filename;
struct files_struct;
struct smb2_lease_key;

bool locking_init(void);
bool locking_init_readonly(void);
bool locking_end(void);

struct share_mode_lock *get_share_mode_lock(
	TALLOC_CTX *mem_ctx,
	struct file_id id,
	const char *servicepath,
	const struct smb_filename *smb_fname,
	const struct timespec *old_write_time);
struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
						     struct file_id id);

bool del_share_mode(struct share_mode_lock *lck,
		    struct files_struct *fsp);
bool downgrade_share_oplock(struct share_mode_lock *lck,
			    struct files_struct *fsp);
bool remove_share_oplock(struct share_mode_lock *lck,
			 struct files_struct *fsp);
bool file_has_read_lease(struct files_struct *fsp);

bool set_share_mode(
	struct share_mode_lock *lck,
	struct files_struct *fsp,
	uid_t uid,
	uint64_t mid,
	uint16_t op_type,
	const struct smb2_lease_key *lease_key,
	uint32_t share_access,
	uint32_t access_mask);
bool reset_share_mode_entry(
	struct share_mode_lock *lck,
	struct server_id old_pid,
	uint64_t old_share_file_id,
	struct server_id new_pid,
	uint64_t new_mid,
	uint64_t new_share_file_id);

bool mark_share_mode_disconnected(
	struct share_mode_lock *lck, struct files_struct *fsp);

struct share_mode_lock *fetch_share_mode_unlocked(
	TALLOC_CTX *mem_ctx,
	struct file_id id);

struct tevent_req *fetch_share_mode_send(
	TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct file_id id,
	bool *queued);
NTSTATUS fetch_share_mode_recv(
	struct tevent_req *req,
	TALLOC_CTX *mem_ctx,
	struct share_mode_lock **_lck);

int share_entry_forall(
	int (*fn)(struct file_id fid,
		  const struct share_mode_data *data,
		  const struct share_mode_entry *entry,
		  void *private_data),
	void *private_data);

NTSTATUS share_mode_count_entries(struct file_id fid, size_t *num_share_modes);
NTSTATUS share_mode_do_locked(
	struct file_id id,
	void (*fn)(const uint8_t *buf,
		   size_t buflen,
		   bool *modified_dependent,
		   void *private_data),
	void *private_data);
int share_mode_forall(
	int (*fn)(struct file_id fid,
		  const struct share_mode_data *data,
		  void *private_data),
	void *private_data);
bool share_mode_forall_entries(
	struct share_mode_lock *lck,
	bool (*fn)(struct share_mode_entry *e,
		   bool *modified,
		   void *private_data),
	void *private_data);

NTTIME share_mode_changed_write_time(struct share_mode_lock *lck);
const char *share_mode_servicepath(struct share_mode_lock *lck);
char *share_mode_filename(TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);
char *share_mode_data_dump(
	TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);

void share_mode_flags_get(
	struct share_mode_lock *lck,
	uint32_t *access_mask,
	uint32_t *share_mode,
	uint32_t *lease_type);
void share_mode_flags_set(
	struct share_mode_lock *lck,
	uint32_t access_mask,
	uint32_t share_mode,
	uint32_t lease_type,
	bool *modified);

struct tevent_req *share_mode_watch_send(
	TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct share_mode_lock *lck,
	struct server_id blocker);
NTSTATUS share_mode_watch_recv(
	struct tevent_req *req, bool *blockerdead, struct server_id *blocker);
NTSTATUS share_mode_wakeup_waiters(struct file_id id);

#endif