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