Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-trivial
[metze/samba/wip.git] / source4 / ntvfs / posix / vfs_posix.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - structure definitions
5
6    Copyright (C) Andrew Tridgell 2004
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _VFS_POSIX_H_
23 #define _VFS_POSIX_H_
24
25 #include "librpc/gen_ndr/xattr.h"
26 #include "system/filesys.h"
27 #include "ntvfs/ntvfs.h"
28 #include "ntvfs/common/ntvfs_common.h"
29 #include "dsdb/samdb/samdb.h"
30
31 struct pvfs_wait;
32 struct pvfs_oplock;
33
34 /* this is the private structure for the posix vfs backend. It is used
35    to hold per-connection (per tree connect) state information */
36 struct pvfs_state {
37         struct ntvfs_module_context *ntvfs;
38         const char *base_directory;
39         struct GUID *base_fs_uuid;
40
41         const char *share_name;
42         uint_t flags;
43
44         struct pvfs_mangle_context *mangle_ctx;
45
46         struct brl_context *brl_context;
47         struct odb_context *odb_context;
48         struct notify_context *notify_context;
49         struct sidmap_context *sidmap;
50
51         /* a list of pending async requests. Needed to support
52            ntcancel */
53         struct pvfs_wait *wait_list;
54
55         /* the sharing violation timeout (nsecs) */
56         uint_t sharing_violation_delay;
57
58         /* the oplock break timeout (secs) */
59         uint_t oplock_break_timeout;
60
61         /* filesystem attributes (see FS_ATTR_*) */
62         uint32_t fs_attribs;
63
64         /* if posix:eadb is set, then this gets setup */
65         struct tdb_wrap *ea_db;
66
67         /* the allocation size rounding */
68         uint32_t alloc_size_rounding;
69
70         struct {
71                 /* the open files as DLINKLIST */
72                 struct pvfs_file *list;
73         } files;
74
75         struct {
76                 /* an id tree mapping open search ID to a pvfs_search_state structure */
77                 struct idr_context *idtree;
78
79                 /* the open searches as DLINKLIST */
80                 struct pvfs_search_state *list;
81
82                 /* how long to keep inactive searches around for */
83                 uint_t inactivity_time;
84         } search;
85
86         /* used to accelerate acl mapping */
87         struct {
88                 const struct dom_sid *creator_owner;
89                 const struct dom_sid *creator_group;            
90         } sid_cache;
91
92         /* the acl backend */
93         const struct pvfs_acl_ops *acl_ops;
94
95         /* non-flag share options */
96         struct {
97                 mode_t dir_mask;
98                 mode_t force_dir_mode;
99                 mode_t create_mask;
100                 mode_t force_create_mode;
101         } options;
102 };
103
104 /* this is the basic information needed about a file from the filesystem */
105 struct pvfs_dos_fileinfo {
106         NTTIME create_time;
107         NTTIME access_time;
108         NTTIME write_time;
109         NTTIME change_time;
110         uint32_t attrib;
111         uint64_t alloc_size;
112         uint32_t nlink;
113         uint32_t ea_size;
114         uint64_t file_id;
115         uint32_t flags;
116 };
117
118 /*
119   this is the structure returned by pvfs_resolve_name(). It holds the posix details of
120   a filename passed by the client to any function
121 */
122 struct pvfs_filename {
123         const char *original_name;
124         char *full_name;
125         const char *stream_name; /* does not include :$DATA suffix */
126         uint32_t stream_id;      /* this uses a hash, so is probabilistic */
127         bool has_wildcard;
128         bool exists;          /* true if the base filename exists */
129         bool stream_exists;   /* true if the stream exists */
130         struct stat st;
131         struct pvfs_dos_fileinfo dos;
132 };
133
134
135 /* open file handle state - encapsulates the posix fd
136
137    Note that this is separated from the pvfs_file structure in order
138    to cope with the openx DENY_DOS semantics where a 2nd DENY_DOS open
139    on the same connection gets the same low level filesystem handle,
140    rather than a new handle
141 */
142 struct pvfs_file_handle {
143         int fd;
144
145         struct pvfs_filename *name;
146
147         /* a unique file key to be used for open file locking */
148         DATA_BLOB odb_locking_key;
149
150         uint32_t create_options;
151
152         /* this is set by the mode_information level. What does it do? */
153         uint32_t mode;
154
155         /* yes, we need 2 independent positions ... */
156         uint64_t seek_offset;
157         uint64_t position;
158
159         bool have_opendb_entry;
160
161         /*
162          * we need to wait for oplock break requests from other processes,
163          * and we need to remember the pvfs_file so we can correctly
164          * forward the oplock break to the client
165          */
166         struct pvfs_oplock *oplock;
167
168         /* we need this hook back to our parent for lock destruction */
169         struct pvfs_state *pvfs;
170
171         /* have we set a sticky write time that we should remove on close */
172         bool sticky_write_time;
173
174         /* the open went through to completion */
175         bool open_completed;
176 };
177
178 /* open file state */
179 struct pvfs_file {
180         struct pvfs_file *next, *prev;
181         struct pvfs_file_handle *handle;
182         struct ntvfs_handle *ntvfs;
183
184         struct pvfs_state *pvfs;
185
186         uint32_t impersonation;
187         uint32_t share_access;
188         uint32_t access_mask;
189
190         /* a list of pending locks - used for locking cancel operations */
191         struct pvfs_pending_lock *pending_list;
192
193         /* a file handle to be used for byte range locking */
194         struct brl_handle *brl_handle;
195
196         /* a count of active locks - used to avoid calling brl_close on
197            file close */
198         uint64_t lock_count;
199
200         /* for directories, a buffer of pending notify events */
201         struct pvfs_notify_buffer *notify_buffer;
202
203         /* for directories, the state of an incomplete SMB2 Find */
204         struct pvfs_search_state *search;
205 };
206
207 /* the state of a search started with pvfs_search_first() */
208 struct pvfs_search_state {
209         struct pvfs_search_state *prev, *next;
210         struct pvfs_state *pvfs;
211         uint16_t handle;
212         off_t current_index;
213         uint16_t search_attrib;
214         uint16_t must_attrib;
215         struct pvfs_dir *dir;
216         time_t last_used;
217         uint_t num_ea_names;
218         struct ea_name *ea_names;
219         struct timed_event *te;
220 };
221
222 /* flags to pvfs_resolve_name() */
223 #define PVFS_RESOLVE_WILDCARD    (1<<0)
224 #define PVFS_RESOLVE_STREAMS     (1<<1)
225
226 /* flags in pvfs->flags */
227 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
228 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
229 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
230 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
231 #define PVFS_FLAG_READONLY       (1<<4)
232 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
233 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
234 #define PVFS_FLAG_XATTR_ENABLE   (1<<7)
235 #define PVFS_FLAG_FAKE_OPLOCKS   (1<<8)
236 #define PVFS_FLAG_LINUX_AIO      (1<<9)
237
238 /* forward declare some anonymous structures */
239 struct pvfs_dir;
240
241 /* types of notification for pvfs wait events */
242 enum pvfs_wait_notice {PVFS_WAIT_EVENT, PVFS_WAIT_TIMEOUT, PVFS_WAIT_CANCEL};
243
244 /*
245   state of a pending retry
246 */
247 struct pvfs_odb_retry;
248
249 #define PVFS_EADB                       "posix:eadb"
250 #define PVFS_XATTR                      "posix:xattr"
251 #define PVFS_FAKE_OPLOCKS               "posix:fakeoplocks"
252 #define PVFS_SHARE_DELAY                "posix:sharedelay"
253 #define PVFS_OPLOCK_TIMEOUT             "posix:oplocktimeout"
254 #define PVFS_ALLOCATION_ROUNDING        "posix:allocationrounding"
255 #define PVFS_SEARCH_INACTIVITY          "posix:searchinactivity"
256 #define PVFS_ACL                        "posix:acl"
257 #define PVFS_AIO                        "posix:aio"
258
259 #define PVFS_XATTR_DEFAULT                      true
260 #define PVFS_FAKE_OPLOCKS_DEFAULT               false
261 #define PVFS_SHARE_DELAY_DEFAULT                1000000 /* nsecs */
262 #define PVFS_OPLOCK_TIMEOUT_DEFAULT             30 /* secs */
263 #define PVFS_ALLOCATION_ROUNDING_DEFAULT        512
264 #define PVFS_SEARCH_INACTIVITY_DEFAULT          300
265
266 struct pvfs_acl_ops {
267         const char *name;
268         NTSTATUS (*acl_load)(struct pvfs_state *, struct pvfs_filename *, int , TALLOC_CTX *, 
269                              struct security_descriptor **);
270         NTSTATUS (*acl_save)(struct pvfs_state *, struct pvfs_filename *, int , struct security_descriptor *);
271 };
272
273 #include "ntvfs/posix/vfs_posix_proto.h"
274
275 NTSTATUS pvfs_aio_pread(struct ntvfs_request *req, union smb_read *rd,
276                         struct pvfs_file *f, uint32_t maxcnt);
277 NTSTATUS pvfs_aio_pwrite(struct ntvfs_request *req, union smb_write *wr,
278                          struct pvfs_file *f);
279
280 #endif /* _VFS_POSIX_H_ */