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