b5b0e2b28dd6544321cbfcbd54c68168544ac32b
[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 "system/filesys.h"
27 #include "smb_server/smb_server.h"
28
29 /* We use libblkid out of e2fsprogs to identify UUID of a volume */
30 #ifdef HAVE_LIBBLKID
31 #include <blkid/blkid.h>
32
33 typedef struct {
34         blkid_cache cache;
35         const char *devname;
36 } blkid_cache_wrap_t;
37 #endif
38
39 /* this is the private structure for the posix vfs backend. It is used
40    to hold per-connection (per tree connect) state information */
41 struct pvfs_state {
42         struct smbsrv_tcon *tcon;
43         const char *base_directory;
44
45         const char *share_name;
46         uint_t flags;
47
48         struct pvfs_file *open_files;
49
50         struct pvfs_mangle_context *mangle_ctx;
51
52         struct brl_context *brl_context;
53         struct odb_context *odb_context;
54         struct sidmap_context *sidmap;
55
56         /* an id tree mapping open search ID to a pvfs_search_state structure */
57         struct idr_context *idtree_search;
58
59         /* an id tree mapping open file handle -> struct pvfs_file */
60         struct idr_context *idtree_fnum;
61
62         /* a list of pending async requests. Needed to support
63            ntcancel */
64         struct pvfs_wait *wait_list;
65
66         /* the sharing violation timeout */
67         uint_t sharing_violation_delay;
68
69         /* filesystem attributes (see FS_ATTR_*) */
70         uint32_t fs_attribs;
71
72         /* if posix:eadb is set, then this gets setup */
73         struct tdb_wrap *ea_db;
74
75         /* the allocation size rounding */
76         uint32_t alloc_size_rounding;
77         
78         /* used to accelerate acl mapping */
79         struct {
80                 const struct dom_sid *creator_owner;
81                 const struct dom_sid *creator_group;            
82         } sid_cache;
83
84 #ifdef HAVE_LIBBLKID
85         blkid_cache_wrap_t *blkid_cache;
86 #endif
87 };
88
89 /* this is the basic information needed about a file from the filesystem */
90 struct pvfs_dos_fileinfo {
91         NTTIME create_time;
92         NTTIME access_time;
93         NTTIME write_time;
94         NTTIME change_time;
95         uint32_t attrib;
96         uint64_t alloc_size;
97         uint32_t nlink;
98         uint32_t ea_size;
99         uint64_t file_id;
100         uint32_t flags;
101 };
102
103 /*
104   this is the structure returned by pvfs_resolve_name(). It holds the posix details of
105   a filename passed by the client to any function
106 */
107 struct pvfs_filename {
108         const char *original_name;
109         char *full_name;
110         const char *stream_name; /* does not include :$DATA suffix */
111         uint32_t stream_id;      /* this uses a hash, so is probabilistic */
112         BOOL has_wildcard;
113         BOOL exists;          /* true if the base filename exists */
114         BOOL stream_exists;   /* true if the stream exists */
115         struct stat st;
116         struct pvfs_dos_fileinfo dos;
117 };
118
119
120 /* open file handle state - encapsulates the posix fd
121
122    Note that this is separated from the pvfs_file structure in order
123    to cope with the openx DENY_DOS semantics where a 2nd DENY_DOS open
124    on the same connection gets the same low level filesystem handle,
125    rather than a new handle
126 */
127 struct pvfs_file_handle {
128         int fd;
129
130         struct pvfs_filename *name;
131
132         /* a unique file key to be used for open file locking */
133         DATA_BLOB odb_locking_key;
134
135         /* a unique file key to be used for byte range locking */
136         DATA_BLOB brl_locking_key;
137
138         uint32_t create_options;
139
140         /* this is set by the mode_information level. What does it do? */
141         uint32_t mode;
142
143         /* yes, we need 2 independent positions ... */
144         uint64_t seek_offset;
145         uint64_t position;
146
147         BOOL have_opendb_entry;
148
149         /* we need this hook back to our parent for lock destruction */
150         struct pvfs_state *pvfs;
151
152         /* have we set a sticky write time that we should remove on close */
153         BOOL sticky_write_time;
154 };
155
156 /* open file state */
157 struct pvfs_file {
158         struct pvfs_file *next, *prev;
159         struct pvfs_file_handle *handle;
160         uint16_t fnum;
161
162         struct pvfs_state *pvfs;
163
164         uint32_t impersonation;
165         uint32_t share_access;
166         uint32_t access_mask;
167
168         /* we need to remember the session it was opened on,
169            as it is illegal to operate on someone elses fnum */
170         struct smbsrv_session *session;
171
172         /* we need to remember the client pid that 
173            opened the file so SMBexit works */
174         uint16_t smbpid;
175
176         /* a list of pending locks - used for locking cancel operations */
177         struct pvfs_pending_lock *pending_list;
178
179         /* a count of active locks - used to avoid calling brl_close on
180            file close */
181         uint64_t lock_count;
182 };
183
184
185 /* flags to pvfs_resolve_name() */
186 #define PVFS_RESOLVE_WILDCARD    (1<<0)
187 #define PVFS_RESOLVE_STREAMS     (1<<1)
188
189 /* flags in pvfs->flags */
190 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
191 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
192 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
193 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
194 #define PVFS_FLAG_READONLY       (1<<4)
195 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
196 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
197 #define PVFS_FLAG_XATTR_ENABLE   (1<<7)
198 #define PVFS_FLAG_FAKE_OPLOCKS   (1<<8)
199
200 /* forward declare some anonymous structures */
201 struct pvfs_dir;
202
203 /* types of notification for pvfs wait events */
204 enum pvfs_wait_notice {PVFS_WAIT_EVENT, PVFS_WAIT_TIMEOUT, PVFS_WAIT_CANCEL};
205
206
207 /* putting this prototype here avoids us having to expose this whole header in the
208    rest of Samba */
209 void *pvfs_wait_message(struct pvfs_state *pvfs, 
210                          struct smbsrv_request *req, 
211                          int msg_type, 
212                          struct timeval end_time,
213                          void (*fn)(void *, enum pvfs_wait_notice),
214                          void *private);
215
216 #endif /* _VFS_POSIX_H_ */