2 * Copyright (c) 2008-2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009-2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the name of Kernel Drivers, LLC nor the names of its
19 * used to endorse or promote products derived from this software without
20 * specific prior written permission from Kernel Drivers, LLC
21 * and Your File System, Inc.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef _AFS_REDIR_COMMON_STRUCTS_H
37 #define _AFS_REDIR_COMMON_STRUCTS_H
43 typedef struct AFS_BTREE_ENTRY
54 } AFSBTreeEntry, *PAFSBTreeEntry;
56 typedef struct AFS_LIST_ENTRY
65 typedef struct _AFS_TREE_HDR
68 AFSBTreeEntry *TreeHead;
75 // Sys Name Information CB
78 typedef struct _AFS_SYS_NAME_CB
81 struct _AFS_SYS_NAME_CB *fLink;
83 UNICODE_STRING SysName;
88 // Communication service control structures
91 typedef struct _AFSFSD_SRVC_CONTROL_BLOCK
94 ULONG IrpPoolRequestIndex;
96 struct _POOL_ENTRY *RequestPoolHead;
98 struct _POOL_ENTRY *RequestPoolTail;
100 ERESOURCE IrpPoolLock;
102 struct _POOL_ENTRY *ResultPoolHead;
104 struct _POOL_ENTRY *ResultPoolTail;
106 ERESOURCE ResultPoolLock;
108 KEVENT IrpPoolHasEntries;
110 KEVENT IrpPoolHasReleaseEntries;
112 ULONG IrpPoolControlFlag;
116 } AFSCommSrvcCB, *PAFSCommSrvcCB;
122 typedef struct _POOL_ENTRY
125 struct _POOL_ENTRY *fLink;
127 struct _POOL_ENTRY *bLink;
135 UNICODE_STRING FileName;
151 ULONG *ResultBufferLength;
156 // The first portion is the non-paged section of the Fcb
159 typedef struct _AFS_NONPAGED_FCB
166 // Ranking - File Resource, Paging Resource,
167 // then SectionObject Resource
172 ERESOURCE PagingResource;
174 ERESOURCE SectionObjectResource;
177 // The section object pointer
180 SECTION_OBJECT_POINTERS SectionObjectPointers;
182 FAST_MUTEX AdvancedHdrMutex;
184 ERESOURCE CcbListLock;
192 ERESOURCE ExtentsResource;
195 // This is set when an Extents Request completes. Do not wait for this
196 // with the Extents resource held!
198 KEVENT ExtentsRequestComplete;
200 NTSTATUS ExtentsRequestStatus;
202 GUID ExtentsRequestAuthGroup;
204 struct _AFS_FSD_EXTENT *DirtyListHead;
206 struct _AFS_FSD_EXTENT *DirtyListTail;
208 ERESOURCE DirtyExtentsListLock;
213 // Queued Flush event. This event is set when the queued flush count
214 // is zero, cleared otherwise.
216 KEVENT QueuedFlushEvent;
223 LONG DirectoryEnumCount;
229 } AFSNonPagedFcb, *PAFSNonPagedFcb;
231 typedef struct _AFS_FSD_EXTENT
234 // Linked list first - the extents and then the skip list
237 LIST_ENTRY Lists[AFS_NUM_EXTENT_LISTS];
239 AFSListEntry DirtyList;
242 // And the extent itself
245 LARGE_INTEGER FileOffset;
247 LARGE_INTEGER CacheOffset;
259 } AFSExtent, *PAFSExtent;
261 typedef struct AFS_FCB
264 FSRTL_ADVANCED_FCB_HEADER Header;
267 // This is the linked list of nodes processed asynchronously by the respective worker thread
270 AFSListEntry ListEntry;
273 // The NP portion of the Fcb
276 AFSNonPagedFcb *NPFcb;
285 // Share access mapping
288 SHARE_ACCESS ShareAccess;
291 // Open pointer count on this file
294 LONG OpenReferenceCount;
297 // Open handle count on this file
300 LONG OpenHandleCount;
306 struct _AFS_OBJECT_INFORMATION_CB *ObjectInformation;
312 struct _AFS_CCB *CcbListHead;
314 struct _AFS_CCB *CcbListTail;
317 // Union for node type specific information
326 // We set this when a flush has been sent to the
327 // server sucessfully. We use this to influence when we
330 LARGE_INTEGER LastServerFlush;
333 // We set this when the extent ref count goes to zero.
334 // we use this to influence which files to purge
336 LARGE_INTEGER LastExtentAccess;
339 // If there has been a RELEASE_FILE_EXTENTS - this is
340 // where we stopped last time this stops us from
341 // constantly refreeing the same extents and then grabbing
344 LARGE_INTEGER LastPurgePoint;
356 LIST_ENTRY ExtentsLists[AFS_NUM_EXTENT_LISTS];
359 // There is only ever one request active, so we embed it
362 AFSRequestExtentsCB ExtentsRequest;
365 // Last PID that requested extents, NOT the system process
368 ULONGLONG ExtentRequestProcessId;
371 // Dirty extent count
374 LONG ExtentsDirtyCount;
377 // Extent count for this file
383 // Current count of queued flush items for the file
386 LONG QueuedFlushCount;
389 // Cache space currently held by extents for the file
392 LONG ExtentLength; // in KBs
407 typedef struct _AFS_DEVICE_EXTENSION
417 // List of device isntances
420 struct _AFS_DEVICE_EXTENSION *DeviceLink;
437 // Volume worker tracking information
440 KEVENT VolumeWorkerCloseEvent;
442 LONG VolumeWorkerThreadCount;
445 // Fcb lifetime & flush time tickcount. This is calculated
446 // in DriverEntry() for the control device.
449 LARGE_INTEGER ObjectLifeTimeCount;
450 LARGE_INTEGER FcbFlushTimeCount;
451 LARGE_INTEGER FcbPurgeTimeCount;
452 LARGE_INTEGER ExtentRequestTimeCount;
458 AFSCommSrvcCB CommServiceCB;
461 // Extent Release Interface
464 ERESOURCE ExtentReleaseResource;
466 KEVENT ExtentReleaseEvent;
468 ULONG ExtentReleaseSequence;
470 PKPROCESS ServiceProcess;
473 // SysName information control block
476 ERESOURCE SysName32ListLock;
478 AFSSysNameCB *SysName32ListHead;
480 AFSSysNameCB *SysName32ListTail;
482 ERESOURCE SysName64ListLock;
484 AFSSysNameCB *SysName64ListHead;
486 AFSSysNameCB *SysName64ListTail;
489 // Our process tree information
492 AFSTreeHdr ProcessTree;
494 ERESOURCE ProcessTreeLock;
500 AFSTreeHdr AuthGroupTree;
502 ERESOURCE AuthGroupTreeLock;
505 // Notificaiton information. This is used for change notification
508 LIST_ENTRY DirNotifyList;
510 PNOTIFY_SYNC NotifySync;
513 // Library load information
516 KEVENT LoadLibraryEvent;
520 ERESOURCE LibraryStateLock;
522 LONG InflightLibraryRequests;
524 KEVENT InflightLibraryEvent;
526 ERESOURCE LibraryQueueLock;
528 struct _AFS_LIBRARY_QUEUE_REQUEST_CB *LibraryQueueHead;
530 struct _AFS_LIBRARY_QUEUE_REQUEST_CB *LibraryQueueTail;
532 UNICODE_STRING LibraryServicePath;
534 DEVICE_OBJECT *LibraryDeviceObject;
536 FILE_OBJECT *LibraryFileObject;
539 // Extent processing information within the library
544 LONG ExtentsHeldLength;
546 KEVENT ExtentsHeldEvent;
549 // Outstanding service request information
552 LONG OutstandingServiceRequestCount;
554 KEVENT OutstandingServiceRequestEvent;
557 // Out of memory signalling
560 LONG WaitingForMemoryCount;
562 KEVENT MemoryAvailableEvent;
570 // Cache file information
573 HANDLE CacheFileHandle;
575 PFILE_OBJECT CacheFileObject;
577 ULONG CacheBlockSize;
579 UNICODE_STRING CacheFile;
581 LARGE_INTEGER CacheBlockCount; // Total number of cache blocks in the cache file
583 void *CacheBaseAddress;
585 LARGE_INTEGER CacheLength;
590 // Throttles on behavior
594 LARGE_INTEGER MaxDirty;
597 // Maximum RPC length that is issued by the service. We should limit our
598 // data requests such as for extents to this length
601 ULONG MaximumRPCLength;
607 AFSTreeHdr VolumeTree;
609 ERESOURCE VolumeTreeLock;
611 struct _AFS_VOLUME_CB *VolumeListHead;
613 struct _AFS_VOLUME_CB *VolumeListTail;
615 ERESOURCE VolumeListLock;
618 // Queued extent release count and event
621 LONG QueuedReleaseExtentCount;
623 KEVENT QueuedReleaseExtentEvent;
626 // Name array related information
629 ULONG NameArrayLength;
634 // Our root cell tree
637 AFSTreeHdr RootCellTree;
639 ERESOURCE RootCellTreeLock;
642 // Cache file object access
645 ERESOURCE CacheFileLock;
648 // NP Connection list information
651 ERESOURCE ProviderListLock;
653 struct _AFSFSD_PROVIDER_CONNECTION_CB *ProviderConnectionList;
655 struct _AFSFSD_PROVIDER_CONNECTION_CB *ProviderEnumerationList;
663 // Worker pool information
668 struct _AFS_WORKER_QUEUE_HDR *PoolHead;
672 struct _AFS_WORK_ITEM *QueueHead;
674 struct _AFS_WORK_ITEM *QueueTail;
676 KEVENT WorkerQueueHasItems;
686 struct _AFS_WORKER_QUEUE_HDR *IOPoolHead;
688 ERESOURCE IOQueueLock;
690 struct _AFS_WORK_ITEM *IOQueueHead;
692 struct _AFS_WORK_ITEM *IOQueueTail;
694 KEVENT IOWorkerQueueHasItems;
696 LONG IOQueueItemCount;
702 } AFSDeviceExt, *PAFSDeviceExt;
705 // Network provider connection cb
707 #pragma pack(push, 1)
708 typedef struct _AFSFSD_PROVIDER_CONNECTION_CB
711 struct _AFSFSD_PROVIDER_CONNECTION_CB *fLink;
713 struct _AFSFSD_PROVIDER_CONNECTION_CB *EnumerationList;
725 LARGE_INTEGER AuthenticationId;
729 UNICODE_STRING RemoteName;
731 UNICODE_STRING ComponentName;
733 UNICODE_STRING Comment;
735 } AFSProviderConnectionCB;
739 // Callbacks defined in the framework
744 (*PAFSProcessRequest)( IN ULONG RequestType,
745 IN ULONG RequestFlags,
747 IN PUNICODE_STRING FileName,
748 IN AFSFileID *FileId,
751 IN OUT void *ResultBuffer,
752 IN OUT PULONG ResultBufferLength);
756 (*PAFSDbgLogMsg)( IN ULONG Subsystem,
763 (*PAFSAddConnectionEx)( IN UNICODE_STRING *RemoteName,
764 IN ULONG DisplayType,
769 (*PAFSExAllocatePoolWithTag)( IN POOL_TYPE PoolType,
770 IN SIZE_T NumberOfBytes,
775 (*PAFSExFreePoolWithTag)( IN void *Pointer, IN ULONG Tag);
779 (*PAFSRetrieveAuthGroup)( IN ULONGLONG ProcessId,
780 IN ULONGLONG ThreadId,
781 OUT GUID *AuthGroup);
783 typedef struct _AFS_LIBRARY_INIT_CB
786 PDEVICE_OBJECT AFSControlDeviceObject;
788 PDEVICE_OBJECT AFSRDRDeviceObject;
790 UNICODE_STRING AFSServerName;
792 UNICODE_STRING AFSMountRootName;
796 AFSFileID GlobalRootFid;
798 CACHE_MANAGER_CALLBACKS *AFSCacheManagerCallbacks;
800 void *AFSCacheBaseAddress;
802 LARGE_INTEGER AFSCacheLength;
805 // Callbacks in the framework
808 PAFSProcessRequest AFSProcessRequest;
810 PAFSDbgLogMsg AFSDbgLogMsg;
812 PAFSAddConnectionEx AFSAddConnectionEx;
814 PAFSExAllocatePoolWithTag AFSExAllocatePoolWithTag;
816 PAFSExFreePoolWithTag AFSExFreePoolWithTag;
818 PAFSDumpTraceFiles AFSDumpTraceFiles;
820 PAFSRetrieveAuthGroup AFSRetrieveAuthGroup;