- Update to r53061
[reactos.git] / 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 Vcb->DeviceFcb = Fcb;
93
94 /* Create the root directory FCB */
95 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NPFS_FCB), TAG_NPFS_FCB);
96 Fcb->Type = FCB_DIRECTORY;
97 Fcb->Vcb = Vcb;
98 Vcb->RootFcb = Fcb;
99
100 return STATUS_SUCCESS;
101 }
102
103
104 FCB_TYPE
105 NpfsGetFcb(PFILE_OBJECT FileObject,
106 PNPFS_FCB *Fcb)
107 {
108 PNPFS_FCB LocalFcb = NULL;
109 FCB_TYPE FcbType = FCB_INVALID;
110
111 _SEH2_TRY
112 {
113 LocalFcb = (PNPFS_FCB)FileObject->FsContext;
114 FcbType = LocalFcb->Type;
115 }
116 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
117 {
118 LocalFcb = NULL;
119 FcbType = FCB_INVALID;
120 }
121 _SEH2_END;
122
123 *Fcb = LocalFcb;
124
125 return FcbType;
126 }
127
128
129 CCB_TYPE
130 NpfsGetCcb(PFILE_OBJECT FileObject,
131 PNPFS_CCB *Ccb)
132 {
133 PNPFS_CCB LocalCcb = NULL;
134 CCB_TYPE CcbType = CCB_INVALID;
135
136 _SEH2_TRY
137 {
138 LocalCcb = (PNPFS_CCB)FileObject->FsContext2;
139 CcbType = LocalCcb->Type;
140 }
141 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
142 {
143 LocalCcb = NULL;
144 CcbType = CCB_INVALID;
145 }
146 _SEH2_END;
147
148 *Ccb = LocalCcb;
149
150 return CcbType;
151 }
152
153 /* EOF */