Windows: Switch to Interlocked ops for RDR Set/Clear
[openafs.git] / src / WINNT / afsrdr / kernel / fs / Include / AFSDefines.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3  * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  *   this list of conditions and the following disclaimer.
12  * - Redistributions in binary form must reproduce the above copyright
13  *   notice,
14  *   this list of conditions and the following disclaimer in the
15  *   documentation
16  *   and/or other materials provided with the distribution.
17  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18  *   nor the names of their contributors may be used to endorse or promote
19  *   products derived from this software without specific prior written
20  *   permission from Kernel Drivers, LLC and Your File System, Inc.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef _AFS_DEFINES_H
36 #define _AFS_DEFINES_H
37 //
38 // File: AFSDefines.h
39 //
40
41 //
42 // Registry names
43 //
44
45 #define AFS_REG_DEBUG_FLAGS              L"DebugFlags"
46 #define AFS_REG_TRACE_LEVEL              L"TraceLevel"
47 #define AFS_REG_TRACE_SUBSYSTEM          L"TraceSubsystem"
48 #define AFS_REG_TRACE_BUFFER_LENGTH      L"TraceBufferSize"  // in KB
49 #define AFS_REG_MAX_DIRTY                L"MaxDirtyMb"
50 #define AFS_REG_MAX_IO                   L"MaxIOMb"
51 #define AFS_REG_NETBIOS_NAME             L"NetbiosName"
52 #define AFS_REG_MOUNT_ROOT               L"MountRoot"
53 #define AFS_REG_SHUTDOWN_STATUS          L"ShutdownStatus"
54 #define AFS_REG_REQUIRE_CLEAN_SHUTDOWN   L"RequireCleanShutdown"
55
56 //
57 // Control Device name
58 //
59
60 #define AFS_CONTROL_DEVICE_NAME     L"\\Device\\AFSControlDevice"
61 #define AFS_SYMLINK_NAME            L"\\??\\AFSRedirector"
62
63 //
64 // How big to make the runs
65 //
66 #define AFS_MAX_STACK_IO_RUNS              5
67
68 #ifndef FlagOn
69 #define FlagOn(_F,_SF)        ((_F) & (_SF))
70 #endif
71
72 #ifndef BooleanFlagOn
73 #define BooleanFlagOn(F,SF)   ((BOOLEAN)(((F) & (SF)) != 0))
74 #endif
75
76 #ifndef SetFlag
77 #define SetFlag(_F,_SF)       InterlockedOr(&(_F), (_SF))
78 #endif
79
80 #ifndef ClearFlag
81 #define ClearFlag(_F,_SF)     InterlockedAnd(&(_F), ~(_SF))
82 #endif
83
84 #define QuadAlign(Ptr) (                \
85     ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
86     )
87
88 #define CRC32_POLYNOMIAL     0xEDB88320L;
89
90 //
91 // Define one second in terms of 100 nS units
92 //
93
94 #define AFS_ONE_SECOND          10000000
95
96 #define AFS_SERVER_FLUSH_DELAY  30
97 #define AFS_SERVER_PURGE_DELAY  60
98 //
99 // PURGE_SLEEP is the number of PURGE_DELAYS we wait before we will unilaterally
100 // give back extents.
101 //
102 // If the Service asks us, we will start at PURGE_SLEEP of delays and then work back
103 //
104 #define AFS_SERVER_PURGE_SLEEP  6
105
106 //
107 // Read ahead granularity
108 //
109
110 #define READ_AHEAD_GRANULARITY      0x10000     // 64KB
111
112 #define AFS_DIR_ENUM_BUFFER_LEN   (16 * 1024)
113
114 //
115 // IS_BYTE_OFFSET_WRITE_TO_EOF
116 // liOffset - should be from Irp.StackLocation.Parameters.Write.ByteOffset
117 // this macro checks to see if the Offset Large_Integer points to the
118 // special constant value which denotes to start the write at EndOfFile
119 //
120 #define IS_BYTE_OFFSET_WRITE_TO_EOF(liOffset) \
121     (((liOffset).LowPart == FILE_WRITE_TO_END_OF_FILE) \
122       && ((liOffset).HighPart == 0xFFFFFFFF))
123
124 //
125 // Ccb Directory enum flags
126 //
127
128 #define CCB_FLAG_DIR_OF_DIRS_ONLY           0x00000001
129 #define CCB_FLAG_FULL_DIRECTORY_QUERY       0x00000002
130 #define CCB_FLAG_MASK_CONTAINS_WILD_CARDS   0x00000004
131 #define CCB_FLAG_FREE_FULL_PATHNAME         0x00000008
132 #define CCB_FLAG_RETURN_RELATIVE_ENTRIES    0x00000010
133 #define CCB_FLAGS_DIRECTORY_QUERY_MAPPED    0x00000020
134
135 //
136 // DirEntry flags
137 //
138
139 #define AFS_DIR_RELEASE_NAME_BUFFER             0x00000001
140 #define AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD 0x00000004
141 #define AFS_DIR_ENTRY_NOT_IN_PARENT_TREE        0x00000008
142 // Use this entry
143 #define AFS_DIR_ENTRY_FAKE                      0x00000020
144 #define AFS_DIR_RELEASE_TARGET_NAME_BUFFER      0x00000040
145 #define AFS_DIR_ENTRY_VALID                     0x00000080
146 #define AFS_DIR_ENTRY_PENDING_DELETE            0x00000100
147 #define AFS_DIR_ENTRY_DELETED                   0x00000200
148 #define AFS_DIR_ENTRY_SERVER_SERVICE            0x00000400
149 #define AFS_DIR_ENTRY_WORKSTATION_SERVICE       0x00000800
150 #define AFS_DIR_ENTRY_IPC                       0x00001000
151
152 //
153 // Network provider errors
154 //
155
156 #define WN_SUCCESS                              0L
157 #define WN_ALREADY_CONNECTED                    85L
158 #define WN_OUT_OF_MEMORY                        8L
159 #define WN_NOT_CONNECTED                        2250L
160 #define WN_BAD_NETNAME                          67L
161
162 #define RESOURCE_CONNECTED      0x00000001
163 #define RESOURCE_GLOBALNET      0x00000002
164 #define RESOURCE_REMEMBERED     0x00000003
165 #define RESOURCE_RECENT         0x00000004
166 #define RESOURCE_CONTEXT        0x00000005
167
168 #define RESOURCETYPE_ANY        0x00000000
169 #define RESOURCETYPE_DISK       0x00000001
170 #define RESOURCETYPE_PRINT      0x00000002
171 #define RESOURCETYPE_RESERVED   0x00000008
172 #define RESOURCETYPE_UNKNOWN    0xFFFFFFFF
173
174 #define RESOURCEUSAGE_CONNECTABLE   0x00000001
175 #define RESOURCEUSAGE_CONTAINER     0x00000002
176 #define RESOURCEUSAGE_NOLOCALDEVICE 0x00000004
177 #define RESOURCEUSAGE_SIBLING       0x00000008
178 #define RESOURCEUSAGE_ATTACHED      0x00000010
179 #define RESOURCEUSAGE_ALL           (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED)
180 #define RESOURCEUSAGE_RESERVED      0x80000000
181
182 #define RESOURCEDISPLAYTYPE_GENERIC        0x00000000
183 #define RESOURCEDISPLAYTYPE_DOMAIN         0x00000001
184 #define RESOURCEDISPLAYTYPE_SERVER         0x00000002
185 #define RESOURCEDISPLAYTYPE_SHARE          0x00000003
186 #define RESOURCEDISPLAYTYPE_FILE           0x00000004
187 #define RESOURCEDISPLAYTYPE_GROUP          0x00000005
188 #define RESOURCEDISPLAYTYPE_NETWORK        0x00000006
189 #define RESOURCEDISPLAYTYPE_ROOT           0x00000007
190 #define RESOURCEDISPLAYTYPE_SHAREADMIN     0x00000008
191 #define RESOURCEDISPLAYTYPE_DIRECTORY      0x00000009
192 #define RESOURCEDISPLAYTYPE_TREE           0x0000000A
193 #define RESOURCEDISPLAYTYPE_NDSCONTAINER   0x0000000B
194
195 //
196 // Method for determining the different control device open requests
197 //
198
199 #define AFS_CONTROL_INSTANCE            0x00000001
200 #define AFS_REDIRECTOR_INSTANCE         0x00000002
201
202 //
203 // Extent flags
204 //
205
206 #define AFS_EXTENT_DIRTY                0x00000001
207
208 //
209 // Extent skip list sizes
210 //
211 #define AFS_NUM_EXTENT_LISTS    3
212
213 //
214 // Extents skip lists
215 //
216 // We use constant sizes.
217 //
218 #define AFS_EXTENT_SIZE         (4*1024)
219 #define AFS_EXTENTS_LIST        0
220 //
221 // A max of 64 extents in ther first skip list
222 #define AFS_EXTENT_SKIP1_BITS   6
223
224 //
225 // Then 128 bits in the second skip list
226 #define AFS_EXTENT_SKIP2_BITS   7
227
228 //
229 // This means that the top list skips in steps of 2^25 (=12+6+7) which
230 // is 32 Mb.  It is to be expected that files which are massively
231 // larger that this will not be fully mapped.
232 //
233 #define AFS_EXTENT_SKIP1_SIZE (AFS_EXTENT_SIZE << AFS_EXTENT_SKIP1_BITS)
234 #define AFS_EXTENT_SKIP2_SIZE (AFS_EXTENT_SKIP1_SIZE << AFS_EXTENT_SKIP2_BITS)
235
236 #define AFS_EXTENTS_MASKS { (AFS_EXTENT_SIZE-1),       \
237                             (AFS_EXTENT_SKIP1_SIZE-1), \
238                             (AFS_EXTENT_SKIP2_SIZE-1) }
239
240 //
241 // Maximum count to release at a time
242 //
243
244 #define AFS_MAXIMUM_EXTENT_RELEASE_COUNT        100
245
246 // {41966169-3FD7-4392-AFE4-E6A9D0A92C72}  - generated using guidgen.exe
247 DEFINE_GUID (GUID_SD_AFS_REDIRECTOR_CONTROL_OBJECT,
248         0x41966169, 0x3fd7, 0x4392, 0xaf, 0xe4, 0xe6, 0xa9, 0xd0, 0xa9, 0x2c, 0x72);
249
250 //
251 // Debug log length
252 //
253
254 #define AFS_DBG_LOG_LENGTH              256
255
256 //
257 // Debug log flags
258 //
259
260 #define AFS_DBG_LOG_WRAPPED             0x00000001
261
262 //
263 // Connection flags
264 //
265
266 #define AFS_CONNECTION_FLAG_GLOBAL_SHARE        0x00000001
267
268 //
269 // Process CB flags
270 //
271
272 #define AFS_PROCESS_FLAG_IS_64BIT           0x00000001
273 #define AFS_PROCESS_FLAG_ACE_SET            0x00000002
274 #define AFS_PROCESS_LOCAL_SYSTEM_AUTH       0x00000004
275
276 //
277 // Auth group flags
278 //
279
280 #define AFS_AUTHGROUP_ACTIVE_SESSION        0x00000001
281
282 //
283 // Maximum number of special share names
284 //
285
286 #define AFS_SPECIAL_SHARE_NAME_COUNT_MAX    10
287
288 //
289 // Reparse tag information
290 //
291
292 //
293 //  Tag allocated to OpenAFS for DFS by Microsoft
294 //  GUID: EF21A155-5C92-4470-AB3B-370403D96369
295 //
296
297 #ifndef IO_REPARSE_TAG_OPENAFS_DFS
298 #define IO_REPARSE_TAG_OPENAFS_DFS              0x00000037L
299 #endif
300
301 //  {EF21A155-5C92-4470-AB3B-370403D96369}
302 DEFINE_GUID (GUID_AFS_REPARSE_GUID,
303         0xEF21A155, 0x5C92, 0x4470, 0xAB, 0x3B, 0x37, 0x04, 0x03, 0xD9, 0x63, 0x69);
304
305 //
306 // Enumeration constants
307 //
308
309 #define AFS_DIR_ENTRY_INITIAL_DIR_INDEX   (ULONG)-3
310 #define AFS_DIR_ENTRY_INITIAL_ROOT_INDEX  (ULONG)-1
311
312 #define AFS_DIR_ENTRY_DOT_INDEX           (ULONG)-2
313 #define AFS_DIR_ENTRY_DOT_DOT_INDEX       (ULONG)-1
314
315 //
316 // Library flags
317 //
318
319 #define AFS_LIBRARY_LOADED                  0x00000001
320 #define AFS_LIBRARY_QUEUE_CANCELLED         0x00000002
321
322 //
323 // Custom ACE Information
324 //
325
326 // {7E5D0E2F-7500-45df-857A-C0C8A2CC6BE8}
327 static const GUID AFSSidGuid = { 0x7f5d0e2f, 0x7500, 0x45df, { 0x85, 0x7a, 0xc0, 0xc8, 0xa2, 0xcc, 0x6b, 0xe8 } };
328
329 // size of our special DACL SID...  S-1-8-GuidDword1-GuidDword2-GuidDword3-GuidDword4-AuthGroupGUIDDword1-AuthGroupGUIDDword2-AuthGroupGUIDDword3-AuthGroupGUIDDword4
330 // Revision (1) + SubAuthorityCount (1) + IdentifierAuthority (6) + GUID (16) + AuthGruopGUID( 16)
331 #define AFS_DACL_SID_LENGTH 40
332
333 typedef
334 NTSTATUS
335 (*PAFSSetInformationToken) (
336     __in HANDLE TokenHandle,
337     __in TOKEN_INFORMATION_CLASS TokenInformationClass,
338     __in_bcount(TokenInformationLength) PVOID TokenInformation,
339     __in ULONG TokenInformationLength
340     );
341
342 #endif /* _AFS_DEFINES_H */