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