e83f0479a9164de254e77dbd565149536216fd34
[bbaumbach/samba-autobuild/.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 /* 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 {
36                 /* a linked list of open searches */
37                 struct pvfs_search_state *open_searches;
38
39                 /* search handles are returned to the clients so they
40                    can continue searches */
41                 uint16_t next_search_handle;
42
43                 /* count of active searches */
44                 uint_t num_active_searches;
45
46                 /* during trans2 search continuations we need to use
47                    the initial search attributes */
48                 uint16_t search_attrib;
49         } search;
50
51         struct pvfs_file *open_files;
52
53         struct pvfs_mangle_context *mangle_ctx;
54
55         void *brl_context;
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 /* this holds a list of file names for a search. We deliberately do
88    not hold the file stat information here to minimise the memory
89    overhead of idle searches */
90 struct pvfs_dir {
91         uint_t count;
92         const char *unix_path;
93         const char **names;
94 };
95
96 /* the state of a search started with pvfs_search_first() */
97 struct pvfs_search_state {
98         struct pvfs_search_state *next, *prev;
99         uint16_t handle;
100         uint_t current_index;
101         uint16_t search_attrib;
102         struct pvfs_dir *dir;
103 };
104
105 /* open file state - this is a temporary implementation
106    to allow some tests to work */
107 struct pvfs_file {
108         struct pvfs_file *next, *prev;
109         int fd;
110         uint16_t fnum;
111         struct pvfs_filename *name;
112
113         /* we need to remember the session it was opened on,
114            as it is illegal to operate on someone elses fnum */
115         struct smbsrv_session *session;
116
117         /* we need to remember the client pid that 
118            opened the file so SMBexit works */
119         uint16_t smbpid;
120
121         /* a unique file key to be used for file locking */
122         DATA_BLOB locking_key;
123
124         /* we need this hook back to our parent for lock destruction */
125         struct pvfs_state *pvfs;
126 };
127
128 struct pvfs_mangle_context {
129         uint8_t char_flags[256];
130         /*
131           this determines how many characters are used from the original
132           filename in the 8.3 mangled name. A larger value leads to a weaker
133           hash and more collisions.  The largest possible value is 6.
134         */
135         int mangle_prefix;
136         uint32_t mangle_modulus;
137
138         /* we will use a very simple direct mapped prefix cache. The big
139            advantage of this cache structure is speed and low memory usage 
140
141            The cache is indexed by the low-order bits of the hash, and confirmed by
142            hashing the resulting cache entry to match the known hash
143         */
144         char **prefix_cache;
145         uint32_t *prefix_cache_hashes;
146
147         /* this is used to reverse the base 36 mapping */
148         unsigned char base_reverse[256];
149 };
150
151
152
153 /* flags to pvfs_resolve_name() */
154 #define PVFS_RESOLVE_NO_WILDCARD (1<<0)
155 #define PVFS_RESOLVE_STREAMS     (1<<1)
156
157 /* flags in pvfs->flags */
158 #define PVFS_FLAG_CI_FILESYSTEM  (1<<0) /* the filesystem is case insensitive */
159 #define PVFS_FLAG_MAP_ARCHIVE    (1<<1)
160 #define PVFS_FLAG_MAP_SYSTEM     (1<<2)
161 #define PVFS_FLAG_MAP_HIDDEN     (1<<3)
162 #define PVFS_FLAG_READONLY       (1<<4)
163 #define PVFS_FLAG_STRICT_SYNC    (1<<5)
164 #define PVFS_FLAG_STRICT_LOCKING (1<<6)
165
166 #endif /* _VFS_POSIX_H_ */