|
|
1.1 root 1: /*
1.1.1.6 root 2: Copyright (c) 2008-2009 TrueCrypt Foundation. All rights reserved.
1.1 root 3:
1.1.1.8 ! root 4: Governed by the TrueCrypt License 2.8 the full text of which is contained
1.1 root 5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
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;
54: int64 EncryptedAreaEnd;
1.1.1.4 root 55: BOOL RemapEncryptedArea;
56: int64 RemappedAreaOffset;
57: int64 RemappedAreaDataUnitOffset;
1.1 root 58: IO_REMOVE_LOCK RemoveLock;
59:
60: // Main tread
61: PKTHREAD MainThread;
62: LIST_ENTRY MainThreadQueue;
63: KSPIN_LOCK MainThreadQueueLock;
64: KEVENT MainThreadQueueNotEmptyEvent;
65:
66: // IO thread
67: PKTHREAD IoThread;
68: LIST_ENTRY IoThreadQueue;
69: KSPIN_LOCK IoThreadQueueLock;
70: KEVENT IoThreadQueueNotEmptyEvent;
71:
72: // Completion thread
73: PKTHREAD CompletionThread;
74: LIST_ENTRY CompletionThreadQueue;
75: KSPIN_LOCK CompletionThreadQueueLock;
76: KEVENT CompletionThreadQueueNotEmptyEvent;
77:
1.1.1.6 root 78: // Fragment buffers
1.1 root 79: byte *FragmentBufferA;
80: byte *FragmentBufferB;
81: KEVENT FragmentBufferAFreeEvent;
82: KEVENT FragmentBufferBFreeEvent;
83:
1.1.1.6 root 84: // Read-ahead buffer
85: BOOL ReadAheadBufferValid;
86: LARGE_INTEGER LastReadOffset;
87: ULONG LastReadLength;
88: LARGE_INTEGER ReadAheadOffset;
89: ULONG ReadAheadLength;
90: byte *ReadAheadBuffer;
91: LARGE_INTEGER MaxReadAheadOffset;
92:
1.1 root 93: LONG OutstandingIoCount;
94: KEVENT NoOutstandingIoEvent;
1.1.1.6 root 95: LONG IoThreadPendingRequestCount;
96:
1.1.1.7 root 97: KEVENT PoolBufferFreeEvent;
1.1.1.3 root 98:
1.1 root 99: __int64 TotalBytesRead;
100: __int64 TotalBytesWritten;
101:
1.1.1.6 root 102: volatile BOOL StartPending;
1.1 root 103: volatile BOOL ThreadExitRequested;
104:
105: volatile BOOL Suspended;
106: volatile BOOL SuspendPending;
107: volatile BOOL StopPending;
108:
109: KEVENT QueueResumedEvent;
110:
1.1.1.6 root 111: #ifdef TC_TRACE_IO_QUEUE
112: LARGE_INTEGER LastPerformanceCounter;
113: #endif
114:
1.1 root 115: } EncryptedIoQueue;
116:
117:
118: typedef struct
119: {
120: EncryptedIoQueue *Queue;
121: PIRP OriginalIrp;
122: BOOL Write;
123: ULONG OriginalLength;
124: LARGE_INTEGER OriginalOffset;
125: NTSTATUS Status;
1.1.1.6 root 126:
127: #ifdef TC_TRACE_IO_QUEUE
128: LARGE_INTEGER OriginalIrpOffset;
129: #endif
130:
1.1 root 131: } EncryptedIoQueueItem;
132:
133:
134: typedef struct
135: {
136: EncryptedIoQueueItem *Item;
137:
138: BOOL CompleteOriginalIrp;
139: LARGE_INTEGER Offset;
140: ULONG Length;
141: int64 EncryptedOffset;
142: ULONG EncryptedLength;
143: byte *Data;
144: byte *OrigDataBufferFragment;
145:
146: LIST_ENTRY ListEntry;
147: LIST_ENTRY CompletionListEntry;
148: } EncryptedIoRequest;
149:
150:
151: NTSTATUS EncryptedIoQueueAddIrp (EncryptedIoQueue *queue, PIRP irp);
152: BOOL EncryptedIoQueueIsRunning (EncryptedIoQueue *queue);
153: BOOL EncryptedIoQueueIsSuspended (EncryptedIoQueue *queue);
154: NTSTATUS EncryptedIoQueueResumeFromHold (EncryptedIoQueue *queue);
1.1.1.5 root 155: NTSTATUS EncryptedIoQueueStart (EncryptedIoQueue *queue);
1.1 root 156: NTSTATUS EncryptedIoQueueStop (EncryptedIoQueue *queue);
157: NTSTATUS EncryptedIoQueueHoldWhenIdle (EncryptedIoQueue *queue, int64 timeout);
158:
159:
160: #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.