[NTFS]
[reactos.git] / reactos / drivers / filesystems / ntfs / dispatch.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2008 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/dispatch.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Pierre Schweitzer
24 * UPDATE HISTORY:
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "ntfs.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* FUNCTIONS ****************************************************************/
35
36 static
37 NTSTATUS
38 NtfsDispatch(PNTFS_IRP_CONTEXT IrpContext)
39 {
40 PIRP Irp = IrpContext->Irp;
41 NTSTATUS Status = STATUS_UNSUCCESSFUL;
42
43 TRACE_(NTFS, "NtfsDispatch()\n");
44
45 FsRtlEnterFileSystem();
46
47 NtfsIsIrpTopLevel(Irp);
48
49 switch (IrpContext->MajorFunction)
50 {
51 case IRP_MJ_QUERY_VOLUME_INFORMATION:
52 Status = NtfsQueryVolumeInformation(IrpContext);
53 break;
54
55 case IRP_MJ_SET_VOLUME_INFORMATION:
56 Status = NtfsSetVolumeInformation(IrpContext);
57 break;
58
59 case IRP_MJ_QUERY_INFORMATION:
60 Status = NtfsQueryInformation(IrpContext);
61 break;
62
63 case IRP_MJ_DIRECTORY_CONTROL:
64 Status = NtfsDirectoryControl(IrpContext);
65 break;
66
67 case IRP_MJ_READ:
68 Status = NtfsRead(IrpContext);
69 break;
70
71 case IRP_MJ_DEVICE_CONTROL:
72 Status = NtfsDeviceControl(IrpContext);
73 break;
74
75 case IRP_MJ_WRITE:
76 Status = NtfsWrite(IrpContext);
77 break;
78 }
79
80 ASSERT((!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
81 ((IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
82 (!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && (IrpContext->Flags & IRPCONTEXT_QUEUE)));
83
84 if (IrpContext->Flags & IRPCONTEXT_COMPLETE)
85 {
86 Irp->IoStatus.Status = Status;
87 IoCompleteRequest(Irp, IrpContext->PriorityBoost);
88 }
89
90 if (IrpContext->Flags & IRPCONTEXT_QUEUE)
91 {
92 /* Reset our status flags before queueing the IRP */
93 IrpContext->Flags |= IRPCONTEXT_COMPLETE;
94 IrpContext->Flags &= ~IRPCONTEXT_QUEUE;
95 UNIMPLEMENTED_DBGBREAK();
96 }
97 else
98 {
99 ExFreePoolWithTag(IrpContext, 'PRIN');
100 }
101
102 IoSetTopLevelIrp(NULL);
103 FsRtlExitFileSystem();
104
105 return Status;
106 }
107
108 /*
109 * FUNCTION: This function manages IRP for various major functions
110 * ARGUMENTS:
111 * DriverObject = object describing this driver
112 * Irp = IRP to be passed to internal functions
113 * RETURNS: Status of I/O Request
114 */
115 NTSTATUS
116 NTAPI
117 NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject,
118 PIRP Irp)
119 {
120 PNTFS_IRP_CONTEXT IrpContext = NULL;
121 NTSTATUS Status;
122
123 TRACE_(NTFS, "NtfsFsdDispatch()\n");
124
125 IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
126 if (IrpContext == NULL)
127 {
128 Status = STATUS_INSUFFICIENT_RESOURCES;
129 Irp->IoStatus.Status = Status;
130 IoCompleteRequest(Irp, IO_NO_INCREMENT);
131 }
132 else
133 {
134 Status = NtfsDispatch(IrpContext);
135 }
136
137 return Status;
138 }