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