4a28fb0837318c843323b0796f953dcdb86e6f83
[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)
91 ExFreePoolWithTag(IrpContext, 'PRIN');
92
93 IoSetTopLevelIrp(NULL);
94 FsRtlExitFileSystem();
95
96 return Status;
97 }
98
99 /*
100 * FUNCTION: This function manages IRP for various major functions
101 * ARGUMENTS:
102 * DriverObject = object describing this driver
103 * Irp = IRP to be passed to internal functions
104 * RETURNS: Status of I/O Request
105 */
106 NTSTATUS
107 NTAPI
108 NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject,
109 PIRP Irp)
110 {
111 PNTFS_IRP_CONTEXT IrpContext = NULL;
112 NTSTATUS Status;
113
114 TRACE_(NTFS, "NtfsFsdDispatch()\n");
115
116 IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
117 if (IrpContext == NULL)
118 {
119 Status = STATUS_INSUFFICIENT_RESOURCES;
120 Irp->IoStatus.Status = Status;
121 IoCompleteRequest(Irp, IO_NO_INCREMENT);
122 }
123 else
124 {
125 Status = NtfsDispatch(IrpContext);
126 }
127
128 return Status;
129 }