Windows: Enforce Share Access
[openafs.git] / src / WINNT / afsrdr / kernel / lib / Include / AFSStructs.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_STRUCTS_H
36 #define _AFS_STRUCTS_H
37
38 //
39 // File: AFSStructs.h
40 //
41
42 typedef struct _AFS_DIR_HDR
43 {
44
45     struct _AFS_DIRECTORY_CB *CaseSensitiveTreeHead;
46
47     struct _AFS_DIRECTORY_CB *CaseInsensitiveTreeHead;
48
49     ERESOURCE               *TreeLock;
50
51     LONG                     ContentIndex;
52
53 } AFSDirHdr;
54
55 //
56 // Worker pool header
57 //
58
59 typedef struct _AFS_WORKER_QUEUE_HDR
60 {
61
62     struct _AFS_WORKER_QUEUE_HDR    *fLink;
63
64     KEVENT           WorkerThreadReady;
65
66     void            *WorkerThreadObject;
67
68     ULONG            State;
69
70 } AFSWorkQueueContext, *PAFSWorkQueueContext;
71
72 //
73 // These are the context control blocks for the open instance
74 //
75
76 typedef struct _AFS_CCB
77 {
78
79     USHORT        Size;
80     USHORT        Type;
81
82     ULONG         Flags;
83
84     //
85     // Directory enumeration informaiton
86     //
87
88     UNICODE_STRING MaskName;
89
90     struct _AFS_DIRECTORY_SS_HDR    *DirectorySnapshot;
91
92     ULONG          CurrentDirIndex;
93
94     //
95     // PIOCtl and share interface request id
96     //
97
98     ULONG          RequestID;
99
100     //
101     // Full path of how the instance was opened
102     //
103
104     UNICODE_STRING FullFileName;
105
106     //
107     // Name array for this open
108     //
109
110     struct _AFS_NAME_ARRAY_HEADER  *NameArray;
111
112     //
113     // Pointer to this entries meta data
114     //
115
116     struct _AFS_DIRECTORY_CB  *DirectoryCB;
117
118     //
119     // Notification name
120     //
121
122     UNICODE_STRING          NotifyMask;
123
124     //
125     // File unwind info
126     //
127
128     struct
129     {
130
131         ULONG           FileAttributes;
132
133         LARGE_INTEGER   CreationTime;
134
135         LARGE_INTEGER   LastAccessTime;
136
137         LARGE_INTEGER   LastWriteTime;
138
139         LARGE_INTEGER   ChangeTime;
140
141     } FileUnwindInfo;
142
143     //
144     // Granted File Access
145     //
146
147     ULONG               FileAccess;
148
149 } AFSCcb;
150
151 //
152 // Object information block
153 //
154
155 typedef struct _AFS_NONPAGED_OBJECT_INFO_CB
156 {
157
158     ERESOURCE           DirectoryNodeHdrLock;
159
160 } AFSNonPagedObjectInfoCB;
161
162 typedef struct _AFS_OBJECT_INFORMATION_CB
163 {
164
165     AFSBTreeEntry             TreeEntry;
166
167     AFSListEntry              ListEntry;
168
169     ULONG                     Flags;
170
171     LONG                      ObjectReferenceCount;
172
173     AFSNonPagedObjectInfoCB  *NonPagedInfo;
174
175     //
176     // The VolumeCB where this entry resides
177     //
178
179     struct _AFS_VOLUME_CB    *VolumeCB;
180
181     //
182     // Parent object information
183     //
184
185     struct _AFS_OBJECT_INFORMATION_CB   *ParentObjectInformation;
186
187     //
188     // Pointer to the current Fcb, if available
189     //
190
191     AFSFcb                   *Fcb;
192
193     //
194     // Last access time.
195     //
196
197     LARGE_INTEGER           LastAccessCount;
198
199     //
200     // Per file metadata information
201     //
202
203     AFSFileID               FileId;
204
205     AFSFileID               TargetFileId;
206
207     LARGE_INTEGER           Expiration;         /* FILETIME */
208
209     LARGE_INTEGER           DataVersion;
210
211     ULONG                   FileType;           /* File, Dir, MountPoint, Symlink */
212
213     LARGE_INTEGER           CreationTime;       /* FILETIME */
214
215     LARGE_INTEGER           LastAccessTime;     /* FILETIME */
216
217     LARGE_INTEGER           LastWriteTime;      /* FILETIME */
218
219     LARGE_INTEGER           ChangeTime;         /* FILETIME */
220
221     ULONG                   FileAttributes;     /* NTFS FILE_ATTRIBUTE_xxxx see below */
222
223     LARGE_INTEGER           EndOfFile;
224
225     LARGE_INTEGER           AllocationSize;
226
227     ULONG                   EaSize;
228
229     ULONG                   Links;
230
231     //
232     // Directory and file specific information
233     //
234
235         union
236         {
237
238                 struct
239                 {
240
241                         //
242                         // The directory search and listing information for the node
243                         //
244
245                         AFSDirHdr                  DirectoryNodeHdr;
246
247                         struct _AFS_DIRECTORY_CB  *DirectoryNodeListHead;
248
249                         struct _AFS_DIRECTORY_CB  *DirectoryNodeListTail;
250
251             LONG                       DirectoryNodeCount;
252
253                         struct _AFS_DIRECTORY_CB  *ShortNameTree;
254
255             //
256             // PIOCtl directory cb entry
257             //
258
259             struct _AFS_DIRECTORY_CB  *PIOCtlDirectoryCB;
260
261             //
262             // Open handle and reference count for this object
263             //
264
265             LONG                       ChildOpenHandleCount;
266
267             LONG                       ChildOpenReferenceCount;
268
269             //
270             // Index for the PIOCtl and share open count
271             //
272
273             LONG                OpenRequestIndex;
274
275                 } Directory;
276
277                 struct
278                 {
279
280             ULONG       Reserved;
281
282                 } File;
283
284         } Specific;
285
286 } AFSObjectInfoCB;
287
288 //
289 // Volume control block structure
290 //
291
292 typedef struct _AFS_NON_PAGED_VOLUME_CB
293 {
294
295     ERESOURCE           VolumeLock;
296
297     ERESOURCE           ObjectInfoTreeLock;
298
299     ERESOURCE           DirectoryNodeHdrLock;
300
301 }AFSNonPagedVolumeCB;
302
303 typedef struct _AFS_VOLUME_CB
304 {
305
306     //
307     // Our tree entry.
308     //
309
310     AFSBTreeEntry             TreeEntry;
311
312     //
313     // This is the linked list of nodes processed asynchronously by the respective worker thread
314     //
315
316     AFSListEntry              ListEntry;
317
318     ULONG                     Flags;
319
320     AFSNonPagedVolumeCB      *NonPagedVcb;
321
322     ERESOURCE                *VolumeLock;
323
324     //
325     // Reference count on the object
326     //
327
328     LONG                      VolumeReferenceCount;
329
330     //
331     // Object information tree
332     //
333
334     AFSTreeHdr                ObjectInfoTree;
335
336     AFSObjectInfoCB          *ObjectInfoListHead;
337
338     AFSObjectInfoCB          *ObjectInfoListTail;
339
340     //
341     // Object information for the volume
342     //
343
344     AFSObjectInfoCB           ObjectInformation;
345
346     //
347     // Root directory cb for this volume
348     //
349
350     struct _AFS_DIRECTORY_CB *DirectoryCB;
351
352     //
353     // The Fcb for this volume
354     //
355
356     AFSFcb                   *RootFcb;
357
358     //
359     // Volume worker thread
360     //
361
362     AFSWorkQueueContext       VolumeWorkerContext;
363
364     //
365     // Volume information
366     //
367
368     AFSVolumeInfoCB           VolumeInformation;
369
370 } AFSVolumeCB;
371
372 typedef struct _AFS_NAME_INFORMATION_CB
373 {
374
375     CCHAR           ShortNameLength;
376
377     WCHAR           ShortName[12];
378
379     UNICODE_STRING  FileName;
380
381     UNICODE_STRING  TargetName;
382
383 } AFSNameInfoCB;
384
385 typedef struct _AFS_NON_PAGED_DIRECTORY_CB
386 {
387
388     ERESOURCE       Lock;
389
390 } AFSNonPagedDirectoryCB;
391
392 typedef struct _AFS_DIRECTORY_CB
393 {
394
395     AFSBTreeEntry    CaseSensitiveTreeEntry;    // For entries in the NameEntry tree, the
396                                                 // Index is a CRC on the name. For Volume,
397                                                 // MP and SL nodes, the Index is the Cell, Volume
398                                                 // For all others it is the vnode, uniqueid
399
400     AFSBTreeEntry    CaseInsensitiveTreeEntry;
401
402     AFSListEntry     CaseInsensitiveList;
403
404     ULONG            Flags;
405
406     //
407     // Current open reference count on the directory entry. This count is used
408     // for tear down
409     //
410
411     LONG             OpenReferenceCount;
412
413     //
414     // File index used in directory enumerations
415     //
416
417     ULONG            FileIndex;
418
419     //
420     // Name information for this entry
421     //
422
423     AFSNameInfoCB    NameInformation;
424
425     //
426     // List entry for the directory enumeration list in a parent node
427     //
428
429     AFSListEntry     ListEntry;
430
431     //
432     // Back pointer to the ObjectInfo block for this entry
433     //
434
435     AFSObjectInfoCB *ObjectInformation;
436
437     //
438     // Non paged pointer
439     //
440
441     AFSNonPagedDirectoryCB  *NonPaged;
442
443     //
444     // Type specific information
445     //
446
447     union
448     {
449
450         struct
451         {
452
453             AFSBTreeEntry    ShortNameTreeEntry;
454
455         } Data;
456
457         struct
458         {
459
460             ULONG           Reserved;
461
462         } MountPoint;
463
464         struct
465         {
466
467             ULONG           Reserved;
468
469         } SymLink;
470
471     } Type;
472
473 } AFSDirectoryCB;
474
475 // Read and writes can fan out and so they are syncrhonized via one of
476 // these structures
477 //
478
479 typedef struct _AFS_GATHER_READWRITE
480 {
481     KEVENT     Event;
482
483     LONG       Count;
484
485     NTSTATUS   Status;
486
487     PIRP       MasterIrp;
488
489     BOOLEAN    Synchronous;
490
491     BOOLEAN    CompleteMasterIrp;
492
493     AFSFcb    *Fcb;
494
495 } AFSGatherIo;
496
497 typedef struct _AFS_IO_RUNS {
498
499     LARGE_INTEGER CacheOffset;
500     PIRP          ChildIrp;
501     ULONG         ByteCount;
502 } AFSIoRun;
503
504 //
505 // Name array element and header
506 //
507
508 typedef struct _AFS_NAME_ARRAY_ELEMENT
509 {
510
511     UNICODE_STRING      Component;
512
513     AFSFileID           FileId;
514
515     AFSDirectoryCB     *DirectoryCB;
516
517     ULONG               Flags;
518
519 } AFSNameArrayCB;
520
521 typedef struct _AFS_NAME_ARRAY_HEADER
522 {
523
524     AFSNameArrayCB      *CurrentEntry;
525
526     LONG                 Count;
527
528     LONG                 LinkCount;
529
530     ULONG                Flags;
531
532     ULONG                MaxElementCount;
533
534     AFSNameArrayCB       ElementArray[ 1];
535
536 } AFSNameArrayHdr;
537
538 typedef struct _AFS_FILE_INFO_CB
539 {
540
541     ULONG           FileAttributes;
542
543     LARGE_INTEGER   AllocationSize;
544
545     LARGE_INTEGER   EndOfFile;
546
547     LARGE_INTEGER   CreationTime;
548
549     LARGE_INTEGER   LastAccessTime;
550
551     LARGE_INTEGER   LastWriteTime;
552
553     LARGE_INTEGER   ChangeTime;
554
555 } AFSFileInfoCB;
556
557 //
558 // Work item
559 //
560
561 typedef struct _AFS_WORK_ITEM
562 {
563
564     struct _AFS_WORK_ITEM *next;
565
566     ULONG    RequestType;
567
568     ULONG    RequestFlags;
569
570     NTSTATUS Status;
571
572     KEVENT   Event;
573
574     ULONG    Size;
575
576     ULONGLONG   ProcessID;
577
578     union
579     {
580         struct
581         {
582             PIRP Irp;
583
584         } ReleaseExtents;
585
586         struct
587         {
588             AFSFcb *Fcb;
589
590             AFSFcb **TargetFcb;
591
592             AFSFileInfoCB   FileInfo;
593
594             struct _AFS_NAME_ARRAY_HEADER *NameArray;
595
596         } Fcb;
597
598         struct
599         {
600             PIRP Irp;
601
602             PDEVICE_OBJECT Device;
603
604             HANDLE CallingProcess;
605
606         } AsynchIo;
607
608         struct
609         {
610
611             UCHAR FunctionCode;
612
613             ULONG RequestFlags;
614
615             struct _AFS_IO_RUNS    *IoRuns;
616
617             ULONG RunCount;
618
619             struct _AFS_GATHER_READWRITE *GatherIo;
620
621             FILE_OBJECT *CacheFileObject;
622
623         } CacheAccess;
624
625         struct
626         {
627             char     Context[ 1];
628
629         } Other;
630
631     } Specific;
632
633 } AFSWorkItem, *PAFSWorkItem;
634
635 //
636 // Directory snapshot structures
637 //
638
639 typedef struct _AFS_DIRECTORY_SS_ENTRY
640 {
641
642     ULONG       NameHash;
643
644 } AFSSnapshotEntry;
645
646 typedef struct _AFS_DIRECTORY_SS_HDR
647 {
648
649     ULONG       EntryCount;
650
651     AFSSnapshotEntry    *TopEntry;
652
653 } AFSSnapshotHdr;
654
655 #endif /* _AFS_STRUCTS_H */