r3545: initial support for using extended attributes to hold extended dos attributes...
[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 "smb_server/smb_server.h"
27
28 /* this is the private structure for the posix vfs backend. It is used
29    to hold per-connection (per tree connect) state information */
30 struct pvfs_state {
31         struct smbsrv_tcon *tcon;
32         const char *base_directory;
33
34         const char *share_name;
35         uint_t flags;
36
37         struct pvfs_file *open_files;
38
39         struct pvfs_mangle_context *mangle_ctx;
40
41         struct brl_context *brl_context;
42         struct odb_context *odb_context;
43
44         /* an id tree mapping open search ID to a pvfs_search_state structure */
45         struct idr_context *idtree_search;
46
47         /* an id tree mapping open file handle -> struct pvfs_file */
48         struct idr_context *idtree_fnum;
49
50         /* a list of pending async requests. Needed to support
51            ntcancel */
52         struct pvfs_wait *wait_list;
53
54         /* the sharing violation timeout */
55         uint_t sharing_violation_delay;
56 };
57
58
59 /* this is the basic information needed about a file from the filesystem */
60 struct pvfs_dos_fileinfo {
61         NTTIME create_time;
62         NTTIME access_time;
63         NTTIME write_time;
64         NTTIME change_time;
65         uint32_t attrib;
66         uint64_t alloc_size;
67         uint32_t nlink;
68         uint32_t ea_size;
69         uint64_t file_id;
70 };
71
72 /*
73   this is the structure returned by pvfs_resolve_name(). It holds the posix details of
74   a filename passed by the client to any function
75 */
76 struct pvfs_filename {
77         const char *original_name;
78         char *full_name;
79         const char *stream_name;
80         BOOL has_wildcard;
81         BOOL exists;
82         struct stat st;
83         struct pvfs_dos_fileinfo dos;
84 };
85
86
87 /* open file state */
88 struct pvfs_file {
89         struct pvfs_file *next, *prev;
90         int fd;
91         uint16_t fnum;
92         struct pvfs_filename *name;
93
94         /* we need to remember the session it was opened on,
95            as it is illegal to operate on someone elses fnum */
96         struct smbsrv_session *session;
97
98         /* we need to remember the client pid that 
99            opened the file so SMBexit works */
100         uint16_t smbpid;
101
102         /* a unique file key to be used for file locking */
103         DATA_BLOB locking_key;
104
105         /* we need this hook back to our parent for lock destruction */
106         struct pvfs_state *pvfs;
107
108         /* a list of pending locks - used for locking cancel operations */
109         struct pvfs_pending_lock *pending_list;
110
111         /* a count of active locks - used to avoid calling brl_close on
112            file close */
113         uint64_t lock_count;
114
115         uint32_t create_options;
116         uint32_t share_access;
117         uint32_t access_mask;
118
119         /* yes, we need 2 independent positions ... */
120         uint64_t seek_offset;
121         uint64_t position;
122
123         BOOL have_opendb_entry;
124 };
125
126
127 struct pvfs_mangle_context {
128         uint8_t char_flags[256];
129         /*
130           this determines how many characters are used from the original
131           filename in the 8.3 mangled name. A larger value leads to a weaker
132           hash and more collisions.  The largest possible value is 6.
133         */
134         int mangle_prefix;
135         uint32_t mangle_modulus;
136
137         /* we will use a very simple direct mapped prefix cache. The big
138            advantage of this cache structure is speed and low memory usage 
139
140            The cache is indexed by the low-order bits of the hash, and confirmed by
141            hashing the resulting cache entry to match the known hash
142         */
143         char **prefix_cache;
144         uint32_t *prefix_cache_hashes;
145
146         /* this is used to reverse the base 36 mapping */
147         unsigned char base_reverse[256];
148 };
149
150
151
152 /* flags to pvfs_resolve_name() */
153 #define PVFS_RESOLVE_NO_WILDCARD (1<<0)
154 #define PVFS_RESOLVE_STREAMS     (1<<1)
155
156 /* flags in pvfs->flags */
157 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
158 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
159 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
160 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
161 #define PVFS_FLAG_READONLY       (1<<4)
162 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
163 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
164 #define PVFS_FLAG_XATTR_ENABLE   (1<<7)
165
166 /* forward declare some anonymous structures */
167 struct pvfs_dir;
168
169 /* types of notification for pvfs wait events */
170 enum pvfs_wait_notice {PVFS_WAIT_EVENT, PVFS_WAIT_TIMEOUT, PVFS_WAIT_CANCEL};
171
172
173 /* putting this prototype here avoids us having to expose this whole header in the
174    rest of Samba */
175 void *pvfs_wait_message(struct pvfs_state *pvfs, 
176                          struct smbsrv_request *req, 
177                          int msg_type, 
178                          struct timeval end_time,
179                          void (*fn)(void *, enum pvfs_wait_notice),
180                          void *private);
181
182 #endif /* _VFS_POSIX_H_ */