13f92ab75542b5d2165d3d65e8e055d1b250a38a
[reactos.git] / reactos / drivers / filesystems / npfs / npfs.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/fs/np/mount.c
5 * PURPOSE: Named pipe filesystem
6 * PROGRAMMER: David Welch <welch@cwcom.net>
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "npfs.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 NTSTATUS NTAPI
19 DriverEntry(PDRIVER_OBJECT DriverObject,
20 PUNICODE_STRING RegistryPath)
21 {
22 PDEVICE_OBJECT DeviceObject;
23 UNICODE_STRING DeviceName;
24 PNPFS_VCB Vcb;
25 PNPFS_FCB Fcb;
26 NTSTATUS Status;
27
28 DPRINT("Named Pipe FSD 0.0.2\n");
29
30 ASSERT (sizeof(NPFS_CONTEXT) <= FIELD_OFFSET(IRP, Tail.Overlay.DriverContext));
31 ASSERT (sizeof(NPFS_WAITER_ENTRY) <= FIELD_OFFSET(IRP, Tail.Overlay.DriverContext));
32
33 DriverObject->MajorFunction[IRP_MJ_CREATE] = NpfsCreate;
34 DriverObject->MajorFunction[IRP_MJ_CREATE_NAMED_PIPE] =
35 NpfsCreateNamedPipe;
36 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NpfsClose;
37 DriverObject->MajorFunction[IRP_MJ_READ] = NpfsRead;
38 DriverObject->MajorFunction[IRP_MJ_WRITE] = NpfsWrite;
39 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
40 NpfsQueryInformation;
41 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
42 NpfsSetInformation;
43 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
44 NpfsQueryVolumeInformation;
45 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NpfsCleanup;
46 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = NpfsFlushBuffers;
47 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
48 NpfsDirectoryControl;
49 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
50 NpfsFileSystemControl;
51 // DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] =
52 // NpfsQuerySecurity;
53 // DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] =
54 // NpfsSetSecurity;
55
56 DriverObject->DriverUnload = NULL;
57
58 RtlInitUnicodeString(&DeviceName, L"\\Device\\NamedPipe");
59 Status = IoCreateDevice(DriverObject,
60 sizeof(NPFS_VCB),
61 &DeviceName,
62 FILE_DEVICE_NAMED_PIPE,
63 0,
64 FALSE,
65 &DeviceObject);
66 if (!NT_SUCCESS(Status))
67 {
68 DPRINT("Failed to create named pipe device! (Status %x)\n", Status);
69 return Status;
70 }
71
72 /* Initialize the device object */
73 DeviceObject->Flags |= DO_DIRECT_IO;
74 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
75
76 /* Initialize the Volume Control Block (VCB) */
77 Vcb = (PNPFS_VCB)DeviceObject->DeviceExtension;
78 InitializeListHead(&Vcb->PipeListHead);
79 InitializeListHead(&Vcb->ThreadListHead);
80 KeInitializeMutex(&Vcb->PipeListLock, 0);
81 Vcb->EmptyWaiterCount = 0;
82
83 /* set the size quotas */
84 Vcb->MinQuota = PAGE_SIZE;
85 Vcb->DefaultQuota = 8 * PAGE_SIZE;
86 Vcb->MaxQuota = 64 * PAGE_SIZE;
87
88 /* Create the device FCB */
89 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NPFS_FCB), TAG_NPFS_FCB);
90 Fcb->Type = FCB_DEVICE;
91 Fcb->Vcb = Vcb;
92 Fcb->RefCount = 1;
93 Vcb->DeviceFcb = Fcb;
94
95 /* Create the root directory FCB */
96 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NPFS_FCB), TAG_NPFS_FCB);
97 Fcb->Type = FCB_DIRECTORY;
98 Fcb->Vcb = Vcb;
99 Fcb->RefCount = 1;
100 Vcb->RootFcb = Fcb;
101
102 return STATUS_SUCCESS;
103 }
104
105
106 FCB_TYPE
107 NpfsGetFcb(PFILE_OBJECT FileObject,
108 PNPFS_FCB *Fcb)
109 {
110 PNPFS_FCB LocalFcb = NULL;
111 FCB_TYPE FcbType = FCB_INVALID;
112
113 _SEH2_TRY
114 {
115 LocalFcb = (PNPFS_FCB)FileObject->FsContext;
116 FcbType = LocalFcb->Type;
117 }
118 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
119 {
120 LocalFcb = NULL;
121 FcbType = FCB_INVALID;
122 }
123 _SEH2_END;
124
125 *Fcb = LocalFcb;
126
127 return FcbType;
128 }
129
130
131 CCB_TYPE
132 NpfsGetCcb(PFILE_OBJECT FileObject,
133 PNPFS_CCB *Ccb)
134 {
135 PNPFS_CCB LocalCcb = NULL;
136 CCB_TYPE CcbType = CCB_INVALID;
137
138 _SEH2_TRY
139 {
140 LocalCcb = (PNPFS_CCB)FileObject->FsContext2;
141 CcbType = LocalCcb->Type;
142 }
143 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
144 {
145 LocalCcb = NULL;
146 CcbType = CCB_INVALID;
147 }
148 _SEH2_END;
149
150 *Ccb = LocalCcb;
151
152 return CcbType;
153 }
154
155 /* EOF */