r3147: added basic share modes support for pvfs (or more precisely, ntcreatex
[sfrench/samba-autobuild/.git] / source / 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 /* this is the private structure for the posix vfs backend. It is used
27    to hold per-connection (per tree connect) state information */
28 struct pvfs_state {
29         struct smbsrv_tcon *tcon;
30         const char *base_directory;
31
32         const char *share_name;
33         uint_t flags;
34
35         struct pvfs_file *open_files;
36
37         struct pvfs_mangle_context *mangle_ctx;
38
39         struct brl_context *brl_context;
40         struct odb_context *odb_context;
41
42         /* an id tree mapping open search ID to a pvfs_search_state structure */
43         struct idr_context *idtree_search;
44
45         /* an id tree mapping open file handle -> struct pvfs_file */
46         struct idr_context *idtree_fnum;
47 };
48
49
50 /* this is the basic information needed about a file from the filesystem */
51 struct pvfs_dos_fileinfo {
52         NTTIME create_time;
53         NTTIME access_time;
54         NTTIME write_time;
55         NTTIME change_time;
56         uint32_t attrib;
57         uint64_t alloc_size;
58         uint32_t nlink;
59         uint32_t ea_size;
60         uint64_t file_id;
61 };
62
63 /*
64   this is the structure returned by pvfs_resolve_name(). It holds the posix details of
65   a filename passed by the client to any function
66 */
67 struct pvfs_filename {
68         const char *original_name;
69         char *full_name;
70         const char *stream_name;
71         BOOL has_wildcard;
72         BOOL exists;
73         struct stat st;
74         struct pvfs_dos_fileinfo dos;
75 };
76
77
78 /* this holds a list of file names for a search. We deliberately do
79    not hold the file stat information here to minimise the memory
80    overhead of idle searches */
81 struct pvfs_dir {
82         uint_t count;
83         const char *unix_path;
84         const char **names;
85 };
86
87 /* the state of a search started with pvfs_search_first() */
88 struct pvfs_search_state {
89         struct pvfs_state *pvfs;
90         uint16_t handle;
91         uint_t current_index;
92         uint16_t search_attrib;
93         struct pvfs_dir *dir;
94 };
95
96 /* open file state - this is a temporary implementation
97    to allow some tests to work */
98 struct pvfs_file {
99         struct pvfs_file *next, *prev;
100         int fd;
101         uint16_t fnum;
102         struct pvfs_filename *name;
103
104         /* we need to remember the session it was opened on,
105            as it is illegal to operate on someone elses fnum */
106         struct smbsrv_session *session;
107
108         /* we need to remember the client pid that 
109            opened the file so SMBexit works */
110         uint16_t smbpid;
111
112         /* a unique file key to be used for file locking */
113         DATA_BLOB locking_key;
114
115         /* we need this hook back to our parent for lock destruction */
116         struct pvfs_state *pvfs;
117
118         /* a list of pending locks - used for locking cancel operations */
119         struct pvfs_pending_lock *pending_list;
120
121         /* a count of active locks - used to avoid calling brl_close on
122            file close */
123         uint64_t lock_count;
124
125         uint32_t create_options;
126         uint32_t share_access;
127         uint32_t access_mask;
128 };
129
130
131 struct pvfs_mangle_context {
132         uint8_t char_flags[256];
133         /*
134           this determines how many characters are used from the original
135           filename in the 8.3 mangled name. A larger value leads to a weaker
136           hash and more collisions.  The largest possible value is 6.
137         */
138         int mangle_prefix;
139         uint32_t mangle_modulus;
140
141         /* we will use a very simple direct mapped prefix cache. The big
142            advantage of this cache structure is speed and low memory usage 
143
144            The cache is indexed by the low-order bits of the hash, and confirmed by
145            hashing the resulting cache entry to match the known hash
146         */
147         char **prefix_cache;
148         uint32_t *prefix_cache_hashes;
149
150         /* this is used to reverse the base 36 mapping */
151         unsigned char base_reverse[256];
152 };
153
154
155
156 /* flags to pvfs_resolve_name() */
157 #define PVFS_RESOLVE_NO_WILDCARD (1<<0)
158 #define PVFS_RESOLVE_STREAMS     (1<<1)
159
160 /* flags in pvfs->flags */
161 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
162 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
163 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
164 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
165 #define PVFS_FLAG_READONLY       (1<<4)
166 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
167 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
168
169 #endif /* _VFS_POSIX_H_ */