r23792: convert Samba4 to GPLv3
[samba.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 /* this is the private structure for the posix vfs backend. It is used
32    to hold per-connection (per tree connect) state information */
33 struct pvfs_state {
34         struct ntvfs_module_context *ntvfs;
35         const char *base_directory;
36         struct GUID *base_fs_uuid;
37
38         const char *share_name;
39         uint_t flags;
40
41         struct pvfs_mangle_context *mangle_ctx;
42
43         struct brl_context *brl_context;
44         struct odb_context *odb_context;
45         struct notify_context *notify_context;
46         struct sidmap_context *sidmap;
47
48         /* a list of pending async requests. Needed to support
49            ntcancel */
50         struct pvfs_wait *wait_list;
51
52         /* the sharing violation timeout */
53         uint_t sharing_violation_delay;
54
55         /* filesystem attributes (see FS_ATTR_*) */
56         uint32_t fs_attribs;
57
58         /* if posix:eadb is set, then this gets setup */
59         struct tdb_wrap *ea_db;
60
61         /* the allocation size rounding */
62         uint32_t alloc_size_rounding;
63
64         struct {
65                 /* the open files as DLINKLIST */
66                 struct pvfs_file *list;
67         } files;
68
69         struct {
70                 /* an id tree mapping open search ID to a pvfs_search_state structure */
71                 struct idr_context *idtree;
72
73                 /* the open searches as DLINKLIST */
74                 struct pvfs_search_state *list;
75
76                 /* how long to keep inactive searches around for */
77                 uint_t inactivity_time;
78         } search;
79
80         /* used to accelerate acl mapping */
81         struct {
82                 const struct dom_sid *creator_owner;
83                 const struct dom_sid *creator_group;            
84         } sid_cache;
85
86         /* the acl backend */
87         const struct pvfs_acl_ops *acl_ops;
88
89         /* non-flag share options */
90         struct {
91                 mode_t dir_mask;
92                 mode_t force_dir_mode;
93                 mode_t create_mask;
94                 mode_t force_create_mode;
95         } options;
96 };
97
98 /* this is the basic information needed about a file from the filesystem */
99 struct pvfs_dos_fileinfo {
100         NTTIME create_time;
101         NTTIME access_time;
102         NTTIME write_time;
103         NTTIME change_time;
104         uint32_t attrib;
105         uint64_t alloc_size;
106         uint32_t nlink;
107         uint32_t ea_size;
108         uint64_t file_id;
109         uint32_t flags;
110 };
111
112 /*
113   this is the structure returned by pvfs_resolve_name(). It holds the posix details of
114   a filename passed by the client to any function
115 */
116 struct pvfs_filename {
117         const char *original_name;
118         char *full_name;
119         const char *stream_name; /* does not include :$DATA suffix */
120         uint32_t stream_id;      /* this uses a hash, so is probabilistic */
121         BOOL has_wildcard;
122         BOOL exists;          /* true if the base filename exists */
123         BOOL stream_exists;   /* true if the stream exists */
124         struct stat st;
125         struct pvfs_dos_fileinfo dos;
126 };
127
128
129 /* open file handle state - encapsulates the posix fd
130
131    Note that this is separated from the pvfs_file structure in order
132    to cope with the openx DENY_DOS semantics where a 2nd DENY_DOS open
133    on the same connection gets the same low level filesystem handle,
134    rather than a new handle
135 */
136 struct pvfs_file_handle {
137         int fd;
138
139         struct pvfs_filename *name;
140
141         /* a unique file key to be used for open file locking */
142         DATA_BLOB odb_locking_key;
143
144         uint32_t create_options;
145
146         /* this is set by the mode_information level. What does it do? */
147         uint32_t mode;
148
149         /* yes, we need 2 independent positions ... */
150         uint64_t seek_offset;
151         uint64_t position;
152
153         BOOL have_opendb_entry;
154
155         /* we need this hook back to our parent for lock destruction */
156         struct pvfs_state *pvfs;
157
158         /* have we set a sticky write time that we should remove on close */
159         BOOL sticky_write_time;
160
161         /* the open went through to completion */
162         BOOL open_completed;
163 };
164
165 /* open file state */
166 struct pvfs_file {
167         struct pvfs_file *next, *prev;
168         struct pvfs_file_handle *handle;
169         struct ntvfs_handle *ntvfs;
170
171         struct pvfs_state *pvfs;
172
173         uint32_t impersonation;
174         uint32_t share_access;
175         uint32_t access_mask;
176
177         /* a list of pending locks - used for locking cancel operations */
178         struct pvfs_pending_lock *pending_list;
179
180         /* a file handle to be used for byte range locking */
181         struct brl_handle *brl_handle;
182
183         /* a count of active locks - used to avoid calling brl_close on
184            file close */
185         uint64_t lock_count;
186
187         /* for directories, a buffer of pending notify events */
188         struct pvfs_notify_buffer *notify_buffer;
189
190         /* for directories, the state of an incomplete SMB2 Find */
191         struct pvfs_search_state *search;
192 };
193
194 /* the state of a search started with pvfs_search_first() */
195 struct pvfs_search_state {
196         struct pvfs_search_state *prev, *next;
197         struct pvfs_state *pvfs;
198         uint16_t handle;
199         off_t current_index;
200         uint16_t search_attrib;
201         uint16_t must_attrib;
202         struct pvfs_dir *dir;
203         time_t last_used;
204         uint_t num_ea_names;
205         struct ea_name *ea_names;
206         struct timed_event *te;
207 };
208
209 /* flags to pvfs_resolve_name() */
210 #define PVFS_RESOLVE_WILDCARD    (1<<0)
211 #define PVFS_RESOLVE_STREAMS     (1<<1)
212
213 /* flags in pvfs->flags */
214 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
215 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
216 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
217 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
218 #define PVFS_FLAG_READONLY       (1<<4)
219 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
220 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
221 #define PVFS_FLAG_XATTR_ENABLE   (1<<7)
222 #define PVFS_FLAG_FAKE_OPLOCKS   (1<<8)
223 #define PVFS_FLAG_LINUX_AIO      (1<<9)
224
225 /* forward declare some anonymous structures */
226 struct pvfs_dir;
227
228 /* types of notification for pvfs wait events */
229 enum pvfs_wait_notice {PVFS_WAIT_EVENT, PVFS_WAIT_TIMEOUT, PVFS_WAIT_CANCEL};
230
231 #define PVFS_EADB                       "posix:eadb"
232 #define PVFS_XATTR                      "posix:xattr"
233 #define PVFS_FAKE_OPLOCKS               "posix:fakeoplocks"
234 #define PVFS_SHARE_DELAY                "posix:sharedelay"
235 #define PVFS_ALLOCATION_ROUNDING        "posix:allocationrounding"
236 #define PVFS_SEARCH_INACTIVITY          "posix:searchinactivity"
237 #define PVFS_ACL                        "posix:acl"
238 #define PVFS_AIO                        "posix:aio"
239
240 #define PVFS_XATTR_DEFAULT                      True
241 #define PVFS_FAKE_OPLOCKS_DEFAULT               False
242 #define PVFS_SHARE_DELAY_DEFAULT                1000000
243 #define PVFS_ALLOCATION_ROUNDING_DEFAULT        512
244 #define PVFS_SEARCH_INACTIVITY_DEFAULT          300
245
246 struct pvfs_acl_ops {
247         const char *name;
248         NTSTATUS (*acl_load)(struct pvfs_state *, struct pvfs_filename *, int , TALLOC_CTX *, 
249                              struct security_descriptor **);
250         NTSTATUS (*acl_save)(struct pvfs_state *, struct pvfs_filename *, int , struct security_descriptor *);
251 };
252
253 #include "ntvfs/posix/vfs_posix_proto.h"
254
255 NTSTATUS pvfs_aio_pread(struct ntvfs_request *req, union smb_read *rd,
256                         struct pvfs_file *f, uint32_t maxcnt);
257 NTSTATUS pvfs_aio_pwrite(struct ntvfs_request *req, union smb_write *wr,
258                          struct pvfs_file *f);
259
260 #endif /* _VFS_POSIX_H_ */