8a220ab50a33af5959bc253853ed9ec7d289e74f
[reactos.git] / reactos / drivers / fs / np / mount.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/np/mount.c
5 * PURPOSE: Named pipe filesystem
6 * PROGRAMMER: David Welch <welch@cwcom.net>
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ddk/ntddk.h>
12
13 //#define NDEBUG
14 #include <internal/debug.h>
15
16 #include "np.h"
17
18 /* GLOBALS *******************************************************************/
19
20 static PDRIVER_OBJECT DriverObject;
21
22 /* FUNCTIONS *****************************************************************/
23
24 NTSTATUS NpfsMount(PDEVICE_OBJECT DeviceToMount)
25 {
26 NTSTATUS Status;
27 PDEVICE_OBJECT DeviceObject;
28 PNPFS_DEVICE_EXTENSION DeviceExt;
29
30 Status = IoCreateDevice(DriverObject,
31 sizeof(NPFS_DEVICE_EXTENSION),
32 NULL,
33 FILE_DEVICE_FILE_SYSTEM,
34 0,
35 FALSE,
36 &DeviceObject);
37 if (!NT_SUCCESS(Status))
38 {
39 return(Status);
40 }
41
42 DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
43 DeviceExt = (PNPFS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
44
45 DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
46 DeviceToMount);
47
48 return(STATUS_SUCCESS);
49 }
50
51 NTSTATUS NpfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
52 PIRP Irp)
53 {
54 PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp);
55 PVPB Vpb = IoStack->Parameters.Mount.Vpb;
56 PDEVICE_OBJECT DeviceToMount = IoStack->Parameters.Mount.DeviceObject;
57 NTSTATUS Status;
58
59 Status = NpfsMount(DeviceToMount);
60
61 Irp->IoStatus.Status = Status;
62 Irp->IoStatus.Information = 0;
63
64 IoCompleteRequest(Irp, IO_NO_INCREMENT);
65
66 return(Status);
67
68 }
69
70 NTSTATUS DriverEntry(PDRIVER_OBJECT _DriverObject,
71 PUNICODE_STRING RegistryPath)
72 {
73 PDEVICE_OBJECT DeviceObject;
74 NTSTATUS Status;
75 UNICODE_STRING DeviceName;
76
77 DbgPrint("Named Pipe Filesystem\n");
78
79 DriverObject = _DriverObject;
80
81 RtlInitUnicodeString(&DeviceName, L"\\Device\\Npfs");
82 Status = IoCreateDevice(DriverObject,
83 0,
84 &DeviceName,
85 FILE_DEVICE_FILE_SYSTEM,
86 0,
87 FALSE,
88 &DeviceObject);
89 if (!NT_SUCCESS(Status))
90 {
91 return(Status);
92 }
93
94 DeviceObject->Flags = 0;
95 DeviceObject->MajorFunction[IRP_MJ_CLOSE] = NpfsClose;
96 DeviceObject->MajorFunction[IRP_MJ_CREATE] = NpfsCreate;
97 DeviceObject->MajorFunction[IRP_MJ_READ] = NpfsRead;
98 DeviceObject->MajorFunction[IRP_MJ_WRITE] = NpfsWrite;
99 DeviceObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
100 NpfsFileSystemControl;
101 DeviceObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
102 NpfsDirectoryControl;
103 DeviceObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
104 NpfsQueryInformation;
105 DeviceObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
106 NpfsSetInformation;
107 DeviceObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = NpfsFlushBuffers;
108 DeviceObject->MajorFunction[IRP_MJ_SHUTDOWN] = NpfsShutdown;
109 DeviceObject->MajorFunction[IRP_MJ_CLEANUP] = NpfsCleanup;
110 DeviceObject->MajorFunction[IRP_MJ_QUERY_SECURITY] =
111 NpfsQuerySecurity;
112 DeviceObject->MajorFunction[IRP_MJ_SET_SECURITY] =
113 NpfsSetSecurity;
114 DeviceObject->MajorFunction[IRP_MJ_QUERY_QUOTA] =
115 NpfsQueryQuota;
116 DeviceObject->MajorFunction[IRP_MJ_SET_QUOTA] =
117 NpfsSetQuota;
118
119 DriverObject->DriverUnload = NULL;
120
121 IoRegisterFileSystem(DeviceObject);
122
123 return(STATUS_SUCCESS);
124 }