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