|
|
1.1 root 1: /*
1.1.1.9 root 2: Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.
1.1 root 3:
1.1.1.10 root 4: Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.9 root 5: the file License.txt included in TrueCrypt binary and source code distribution
6: packages.
1.1 root 7: */
8:
9: #ifndef TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE
10: #define TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE
11:
12: #include "TCdefs.h"
13: #include "Apidrvr.h"
14:
1.1.1.6 root 15: #if 0
16: # define TC_TRACE_IO_QUEUE
17: #endif
18:
1.1.1.5 root 19: #define TC_ENC_IO_QUEUE_MAX_FRAGMENT_SIZE (256 * 1024)
1.1.1.6 root 20:
1.1.1.7 root 21: #define TC_ENC_IO_QUEUE_PREALLOCATED_ITEM_COUNT 8
22: #define TC_ENC_IO_QUEUE_PREALLOCATED_IO_REQUEST_COUNT 16
1.1.1.6 root 23:
24:
25: typedef struct EncryptedIoQueueBufferStruct
26: {
27: struct EncryptedIoQueueBufferStruct *NextBuffer;
28:
29: void *Address;
30: ULONG Size;
31: BOOL InUse;
32:
33: } EncryptedIoQueueBuffer;
34:
1.1 root 35:
36: typedef struct
37: {
38: PDEVICE_OBJECT DeviceObject;
39:
1.1.1.6 root 40: KMUTEX BufferPoolMutex;
41: EncryptedIoQueueBuffer *FirstPoolBuffer;
42:
1.1 root 43: CRYPTO_INFO *CryptoInfo;
44:
45: // File-handle-based IO
46: HANDLE HostFileHandle;
47: int64 VirtualDeviceLength;
1.1.1.5 root 48: SECURITY_CLIENT_CONTEXT *SecurityClientContext;
1.1 root 49:
50: // Filter device
51: BOOL IsFilterDevice;
52: PDEVICE_OBJECT LowerDeviceObject;
53: int64 EncryptedAreaStart;
1.1.1.11! root 54: volatile int64 EncryptedAreaEnd;
! 55: volatile BOOL EncryptedAreaEndUpdatePending;
1.1.1.4 root 56: BOOL RemapEncryptedArea;
57: int64 RemappedAreaOffset;
58: int64 RemappedAreaDataUnitOffset;
1.1 root 59: IO_REMOVE_LOCK RemoveLock;
60:
61: // Main tread
62: PKTHREAD MainThread;
63: LIST_ENTRY MainThreadQueue;
64: KSPIN_LOCK MainThreadQueueLock;
65: KEVENT MainThreadQueueNotEmptyEvent;
66:
67: // IO thread
68: PKTHREAD IoThread;
69: LIST_ENTRY IoThreadQueue;
70: KSPIN_LOCK IoThreadQueueLock;
71: KEVENT IoThreadQueueNotEmptyEvent;
72:
73: // Completion thread
74: PKTHREAD CompletionThread;
75: LIST_ENTRY CompletionThreadQueue;
76: KSPIN_LOCK CompletionThreadQueueLock;
77: KEVENT CompletionThreadQueueNotEmptyEvent;
78:
1.1.1.6 root 79: // Fragment buffers
1.1 root 80: byte *FragmentBufferA;
81: byte *FragmentBufferB;
82: KEVENT FragmentBufferAFreeEvent;
83: KEVENT FragmentBufferBFreeEvent;
84:
1.1.1.6 root 85: // Read-ahead buffer
86: BOOL ReadAheadBufferValid;
87: LARGE_INTEGER LastReadOffset;
88: ULONG LastReadLength;
89: LARGE_INTEGER ReadAheadOffset;
90: ULONG ReadAheadLength;
91: byte *ReadAheadBuffer;
92: LARGE_INTEGER MaxReadAheadOffset;
93:
1.1 root 94: LONG OutstandingIoCount;
95: KEVENT NoOutstandingIoEvent;
1.1.1.6 root 96: LONG IoThreadPendingRequestCount;
97:
1.1.1.7 root 98: KEVENT PoolBufferFreeEvent;
1.1.1.3 root 99:
1.1 root 100: __int64 TotalBytesRead;
101: __int64 TotalBytesWritten;
102:
1.1.1.6 root 103: volatile BOOL StartPending;
1.1 root 104: volatile BOOL ThreadExitRequested;
105:
106: volatile BOOL Suspended;
107: volatile BOOL SuspendPending;
108: volatile BOOL StopPending;
109:
110: KEVENT QueueResumedEvent;
111:
1.1.1.6 root 112: #ifdef TC_TRACE_IO_QUEUE
113: LARGE_INTEGER LastPerformanceCounter;
114: #endif
115:
1.1 root 116: } EncryptedIoQueue;
117:
118:
119: typedef struct
120: {
121: EncryptedIoQueue *Queue;
122: PIRP OriginalIrp;
123: BOOL Write;
124: ULONG OriginalLength;
125: LARGE_INTEGER OriginalOffset;
126: NTSTATUS Status;
1.1.1.6 root 127:
128: #ifdef TC_TRACE_IO_QUEUE
129: LARGE_INTEGER OriginalIrpOffset;
130: #endif
131:
1.1 root 132: } EncryptedIoQueueItem;
133:
134:
135: typedef struct
136: {
137: EncryptedIoQueueItem *Item;
138:
139: BOOL CompleteOriginalIrp;
140: LARGE_INTEGER Offset;
141: ULONG Length;
142: int64 EncryptedOffset;
143: ULONG EncryptedLength;
144: byte *Data;
145: byte *OrigDataBufferFragment;
146:
147: LIST_ENTRY ListEntry;
148: LIST_ENTRY CompletionListEntry;
149: } EncryptedIoRequest;
150:
151:
152: NTSTATUS EncryptedIoQueueAddIrp (EncryptedIoQueue *queue, PIRP irp);
153: BOOL EncryptedIoQueueIsRunning (EncryptedIoQueue *queue);
154: BOOL EncryptedIoQueueIsSuspended (EncryptedIoQueue *queue);
155: NTSTATUS EncryptedIoQueueResumeFromHold (EncryptedIoQueue *queue);
1.1.1.5 root 156: NTSTATUS EncryptedIoQueueStart (EncryptedIoQueue *queue);
1.1 root 157: NTSTATUS EncryptedIoQueueStop (EncryptedIoQueue *queue);
158: NTSTATUS EncryptedIoQueueHoldWhenIdle (EncryptedIoQueue *queue, int64 timeout);
159:
160:
161: #endif // TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.