8cf4651b887801387def894e87ce0b60c8ec731c
[reactos.git] / reactos / drivers / filesystems / npfs / npfs.h
1 #ifndef __DRIVERS_FS_NP_NPFS_H
2 #define __DRIVERS_FS_NP_NPFS_H
3
4 #include <ntifs.h>
5 #include <ndk/iotypes.h>
6 #include <pseh/pseh2.h>
7
8 #define TAG_NPFS_CCB 'cFpN'
9 #define TAG_NPFS_CCB_DATA 'iFpN' /* correct? */
10 #define TAG_NPFS_FCB 'FFpN'
11 #define TAG_NPFS_NAMEBLOCK 'nFpN'
12 #define TAG_NPFS_THREAD_CONTEXT 'tFpN'
13
14 #define ROUND_DOWN(n, align) \
15 (((ULONG)n) & ~((align) - 1l))
16
17 #define ROUND_UP(n, align) \
18 ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
19
20 typedef enum _FCB_TYPE
21 {
22 FCB_INVALID,
23 FCB_DEVICE,
24 FCB_DIRECTORY,
25 FCB_PIPE
26 } FCB_TYPE;
27
28 typedef enum _CCB_TYPE
29 {
30 CCB_INVALID,
31 CCB_DEVICE,
32 CCB_DIRECTORY,
33 CCB_PIPE
34 } CCB_TYPE;
35
36 /* Volume Control Block (VCB) aka Device Extension */
37 typedef struct _NPFS_VCB
38 {
39 LIST_ENTRY PipeListHead;
40 LIST_ENTRY ThreadListHead;
41 KMUTEX PipeListLock;
42 ULONG EmptyWaiterCount;
43 ULONG MinQuota;
44 ULONG DefaultQuota;
45 ULONG MaxQuota;
46 struct _NPFS_FCB *DeviceFcb;
47 struct _NPFS_FCB *RootFcb;
48 } NPFS_VCB, *PNPFS_VCB;
49
50 typedef struct _NPFS_FCB
51 {
52 FCB_TYPE Type;
53 PNPFS_VCB Vcb;
54 volatile LONG RefCount;
55 UNICODE_STRING PipeName;
56 LIST_ENTRY PipeListEntry;
57 KMUTEX CcbListLock;
58 LIST_ENTRY ServerCcbListHead;
59 LIST_ENTRY ClientCcbListHead;
60 LIST_ENTRY WaiterListHead;
61 LIST_ENTRY EmptyBufferListHead;
62 ULONG PipeType;
63 ULONG ClientReadMode;
64 ULONG ServerReadMode;
65 ULONG CompletionMode;
66 ULONG PipeConfiguration;
67 ULONG MaximumInstances;
68 ULONG CurrentInstances;
69 ULONG InboundQuota;
70 ULONG OutboundQuota;
71 LARGE_INTEGER TimeOut;
72 } NPFS_FCB, *PNPFS_FCB;
73
74
75 typedef struct _NPFS_CCB_DIRECTORY_DATA
76 {
77 UNICODE_STRING SearchPattern;
78 ULONG FileIndex;
79 } NPFS_CCB_DIRECTORY_DATA, *PNPFS_CCB_DIRECTORY_DATA;
80
81
82 typedef struct _NPFS_CCB
83 {
84 LIST_ENTRY CcbListEntry;
85 CCB_TYPE Type;
86 PNPFS_FCB Fcb;
87 PFILE_OBJECT FileObject;
88
89 struct _NPFS_CCB* OtherSide;
90 struct ETHREAD *Thread;
91 KEVENT ConnectEvent;
92 KEVENT ReadEvent;
93 KEVENT WriteEvent;
94 ULONG PipeEnd;
95 ULONG PipeState;
96 ULONG ReadDataAvailable;
97 ULONG WriteQuotaAvailable;
98 volatile LONG RefCount;
99
100 LIST_ENTRY ReadRequestListHead;
101
102 PVOID Data;
103 PVOID ReadPtr;
104 PVOID WritePtr;
105 ULONG MaxDataLength;
106
107 FAST_MUTEX DataListLock; /* Data queue lock */
108
109 union
110 {
111 NPFS_CCB_DIRECTORY_DATA Directory;
112 } u;
113
114 } NPFS_CCB, *PNPFS_CCB;
115
116 typedef struct _NPFS_CONTEXT
117 {
118 LIST_ENTRY ListEntry;
119 PKEVENT WaitEvent;
120 } NPFS_CONTEXT, *PNPFS_CONTEXT;
121
122 typedef struct _NPFS_THREAD_CONTEXT
123 {
124 ULONG Count;
125 KEVENT Event;
126 PNPFS_VCB Vcb;
127 LIST_ENTRY ListEntry;
128 PVOID WaitObjectArray[MAXIMUM_WAIT_OBJECTS];
129 KWAIT_BLOCK WaitBlockArray[MAXIMUM_WAIT_OBJECTS];
130 PIRP WaitIrpArray[MAXIMUM_WAIT_OBJECTS];
131 } NPFS_THREAD_CONTEXT, *PNPFS_THREAD_CONTEXT;
132
133 typedef struct _NPFS_WAITER_ENTRY
134 {
135 LIST_ENTRY Entry;
136 PNPFS_CCB Ccb;
137 } NPFS_WAITER_ENTRY, *PNPFS_WAITER_ENTRY;
138
139
140 extern NPAGED_LOOKASIDE_LIST NpfsPipeDataLookasideList;
141
142
143 #define KeLockMutex(x) KeWaitForSingleObject(x, \
144 UserRequest, \
145 KernelMode, \
146 FALSE, \
147 NULL);
148
149 #define KeUnlockMutex(x) KeReleaseMutex(x, FALSE);
150
151 #define PAGE_ROUND_UP(x) ( (((ULONG_PTR)x)%PAGE_SIZE) ? ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG_PTR)x) )
152
153 DRIVER_DISPATCH NpfsCreate;
154 NTSTATUS NTAPI NpfsCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
155
156 DRIVER_DISPATCH NpfsCreateNamedPipe;
157 NTSTATUS NTAPI NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject, PIRP Irp);
158
159 DRIVER_DISPATCH NpfsCleanup;
160 NTSTATUS NTAPI NpfsCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp);
161
162 DRIVER_DISPATCH NpfsClose;
163 NTSTATUS NTAPI NpfsClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
164
165 DRIVER_DISPATCH NpfsDirectoryControl;
166 NTSTATUS NTAPI NpfsDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
167
168 DRIVER_DISPATCH NpfsRead;
169 NTSTATUS NTAPI NpfsRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
170
171 DRIVER_DISPATCH NpfsWrite;
172 NTSTATUS NTAPI NpfsWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
173
174 DRIVER_DISPATCH NpfsFlushBuffers;
175 NTSTATUS NTAPI NpfsFlushBuffers(PDEVICE_OBJECT DeviceObject, PIRP Irp);
176
177 DRIVER_DISPATCH NpfsFileSystemControl;
178 NTSTATUS NTAPI NpfsFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
179
180 DRIVER_DISPATCH NpfsQueryInformation;
181 NTSTATUS NTAPI NpfsQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
182
183 DRIVER_DISPATCH NpfsSetInformation;
184 NTSTATUS NTAPI NpfsSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
185
186 DRIVER_DISPATCH NpfsQueryVolumeInformation;
187 NTSTATUS NTAPI NpfsQueryVolumeInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp);
188
189 NTSTATUS NTAPI
190 DriverEntry(PDRIVER_OBJECT DriverObject,
191 PUNICODE_STRING RegistryPath);
192
193 VOID
194 NpfsDereferenceFcb(PNPFS_FCB Fcb);
195
196 PNPFS_FCB
197 NpfsFindPipe(PNPFS_VCB Vcb,
198 PUNICODE_STRING PipeName);
199
200 FCB_TYPE
201 NpfsGetFcb(PFILE_OBJECT FileObject,
202 PNPFS_FCB *Fcb);
203
204 CCB_TYPE
205 NpfsGetCcb(PFILE_OBJECT FileObject,
206 PNPFS_CCB *Ccb);
207
208 #endif /* __DRIVERS_FS_NP_NPFS_H */