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