- Update to r53061
[reactos.git] / 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 UNICODE_STRING PipeName;
55 LIST_ENTRY PipeListEntry;
56 KMUTEX CcbListLock;
57 LIST_ENTRY ServerCcbListHead;
58 LIST_ENTRY ClientCcbListHead;
59 LIST_ENTRY WaiterListHead;
60 LIST_ENTRY EmptyBufferListHead;
61 ULONG PipeType;
62 ULONG ClientReadMode;
63 ULONG ServerReadMode;
64 ULONG CompletionMode;
65 ULONG PipeConfiguration;
66 ULONG MaximumInstances;
67 ULONG CurrentInstances;
68 ULONG InboundQuota;
69 ULONG OutboundQuota;
70 LARGE_INTEGER TimeOut;
71 } NPFS_FCB, *PNPFS_FCB;
72
73
74 typedef struct _NPFS_CCB_DIRECTORY_DATA
75 {
76 UNICODE_STRING SearchPattern;
77 ULONG FileIndex;
78 } NPFS_CCB_DIRECTORY_DATA, *PNPFS_CCB_DIRECTORY_DATA;
79
80
81 typedef struct _NPFS_CCB
82 {
83 LIST_ENTRY CcbListEntry;
84 CCB_TYPE Type;
85 PNPFS_FCB Fcb;
86
87 struct _NPFS_CCB* OtherSide;
88 struct ETHREAD *Thread;
89 KEVENT ConnectEvent;
90 KEVENT ReadEvent;
91 KEVENT WriteEvent;
92 ULONG PipeEnd;
93 ULONG PipeState;
94 ULONG ReadDataAvailable;
95 ULONG WriteQuotaAvailable;
96 ULONG RefCount;
97
98 LIST_ENTRY ReadRequestListHead;
99
100 PVOID Data;
101 PVOID ReadPtr;
102 PVOID WritePtr;
103 ULONG MaxDataLength;
104
105 FAST_MUTEX DataListLock; /* Data queue lock */
106
107 union
108 {
109 NPFS_CCB_DIRECTORY_DATA Directory;
110 } u;
111
112 } NPFS_CCB, *PNPFS_CCB;
113
114 typedef struct _NPFS_CONTEXT
115 {
116 LIST_ENTRY ListEntry;
117 PKEVENT WaitEvent;
118 } NPFS_CONTEXT, *PNPFS_CONTEXT;
119
120 typedef struct _NPFS_THREAD_CONTEXT
121 {
122 ULONG Count;
123 KEVENT Event;
124 PNPFS_VCB Vcb;
125 LIST_ENTRY ListEntry;
126 PVOID WaitObjectArray[MAXIMUM_WAIT_OBJECTS];
127 KWAIT_BLOCK WaitBlockArray[MAXIMUM_WAIT_OBJECTS];
128 PIRP WaitIrpArray[MAXIMUM_WAIT_OBJECTS];
129 } NPFS_THREAD_CONTEXT, *PNPFS_THREAD_CONTEXT;
130
131 typedef struct _NPFS_WAITER_ENTRY
132 {
133 LIST_ENTRY Entry;
134 PNPFS_CCB Ccb;
135 } NPFS_WAITER_ENTRY, *PNPFS_WAITER_ENTRY;
136
137
138 extern NPAGED_LOOKASIDE_LIST NpfsPipeDataLookasideList;
139
140
141 #define KeLockMutex(x) KeWaitForSingleObject(x, \
142 UserRequest, \
143 KernelMode, \
144 FALSE, \
145 NULL);
146
147 #define KeUnlockMutex(x) KeReleaseMutex(x, FALSE);
148
149 #define PAGE_ROUND_UP(x) ( (((ULONG_PTR)x)%PAGE_SIZE) ? ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG_PTR)x) )
150
151 DRIVER_DISPATCH NpfsCreate;
152 NTSTATUS NTAPI NpfsCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
153
154 DRIVER_DISPATCH NpfsCreateNamedPipe;
155 NTSTATUS NTAPI NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject, PIRP Irp);
156
157 DRIVER_DISPATCH NpfsCleanup;
158 NTSTATUS NTAPI NpfsCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp);
159
160 DRIVER_DISPATCH NpfsClose;
161 NTSTATUS NTAPI NpfsClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
162
163 DRIVER_DISPATCH NpfsDirectoryControl;
164 NTSTATUS NTAPI NpfsDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
165
166 DRIVER_DISPATCH NpfsRead;
167 NTSTATUS NTAPI NpfsRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
168
169 DRIVER_DISPATCH NpfsWrite;
170 NTSTATUS NTAPI NpfsWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
171
172 DRIVER_DISPATCH NpfsFlushBuffers;
173 NTSTATUS NTAPI NpfsFlushBuffers(PDEVICE_OBJECT DeviceObject, PIRP Irp);
174
175 DRIVER_DISPATCH NpfsFileSystemControl;
176 NTSTATUS NTAPI NpfsFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
177
178 DRIVER_DISPATCH NpfsQueryInformation;
179 NTSTATUS NTAPI NpfsQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
180
181 DRIVER_DISPATCH NpfsSetInformation;
182 NTSTATUS NTAPI NpfsSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
183
184 DRIVER_DISPATCH NpfsQueryVolumeInformation;
185 NTSTATUS NTAPI NpfsQueryVolumeInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp);
186
187 NTSTATUS NTAPI
188 DriverEntry(PDRIVER_OBJECT DriverObject,
189 PUNICODE_STRING RegistryPath);
190
191 PNPFS_FCB
192 NpfsFindPipe(PNPFS_VCB Vcb,
193 PUNICODE_STRING PipeName);
194
195 FCB_TYPE
196 NpfsGetFcb(PFILE_OBJECT FileObject,
197 PNPFS_FCB *Fcb);
198
199 CCB_TYPE
200 NpfsGetCcb(PFILE_OBJECT FileObject,
201 PNPFS_CCB *Ccb);
202
203 #endif /* __DRIVERS_FS_NP_NPFS_H */