3 * Copyright (C) 2008 ReactOS Team
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.
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.
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.
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
27 /* INCLUDES *****************************************************************/
34 static LONG QueueCount
= 0;
36 /* FUNCTIONS ****************************************************************/
38 static WORKER_THREAD_ROUTINE NtfsDoRequest
;
42 NtfsQueueRequest(PNTFS_IRP_CONTEXT IrpContext
)
44 InterlockedIncrement(&QueueCount
);
45 DPRINT("NtfsQueueRequest(IrpContext %p), %d\n", IrpContext
, QueueCount
);
47 ASSERT(!(IrpContext
->Flags
& IRPCONTEXT_QUEUE
) &&
48 (IrpContext
->Flags
& IRPCONTEXT_COMPLETE
));
49 IrpContext
->Flags
|= IRPCONTEXT_CANWAIT
;
50 IoMarkIrpPending(IrpContext
->Irp
);
51 ExInitializeWorkItem(&IrpContext
->WorkQueueItem
, NtfsDoRequest
, IrpContext
);
52 ExQueueWorkItem(&IrpContext
->WorkQueueItem
, CriticalWorkQueue
);
54 return STATUS_PENDING
;
59 NtfsDispatch(PNTFS_IRP_CONTEXT IrpContext
)
61 PIRP Irp
= IrpContext
->Irp
;
62 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
64 TRACE_(NTFS
, "NtfsDispatch()\n");
66 FsRtlEnterFileSystem();
68 NtfsIsIrpTopLevel(Irp
);
70 switch (IrpContext
->MajorFunction
)
72 case IRP_MJ_QUERY_VOLUME_INFORMATION
:
73 Status
= NtfsQueryVolumeInformation(IrpContext
);
76 case IRP_MJ_SET_VOLUME_INFORMATION
:
77 Status
= NtfsSetVolumeInformation(IrpContext
);
80 case IRP_MJ_QUERY_INFORMATION
:
81 Status
= NtfsQueryInformation(IrpContext
);
84 case IRP_MJ_SET_INFORMATION
:
85 if (!NtfsGlobalData
->EnableWriteSupport
)
87 DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
88 Status
= STATUS_ACCESS_DENIED
;
92 Status
= NtfsSetInformation(IrpContext
);
96 case IRP_MJ_DIRECTORY_CONTROL
:
97 Status
= NtfsDirectoryControl(IrpContext
);
101 Status
= NtfsRead(IrpContext
);
104 case IRP_MJ_DEVICE_CONTROL
:
105 Status
= NtfsDeviceControl(IrpContext
);
109 if (!NtfsGlobalData
->EnableWriteSupport
)
111 DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
112 Status
= STATUS_ACCESS_DENIED
;
116 Status
= NtfsWrite(IrpContext
);
121 Status
= NtfsClose(IrpContext
);
125 Status
= NtfsCleanup(IrpContext
);
129 Status
= NtfsCreate(IrpContext
);
132 case IRP_MJ_FILE_SYSTEM_CONTROL
:
133 Status
= NtfsFileSystemControl(IrpContext
);
137 ASSERT((!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
138 ((IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
139 (!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)));
141 if (IrpContext
->Flags
& IRPCONTEXT_COMPLETE
)
143 Irp
->IoStatus
.Status
= Status
;
144 IoCompleteRequest(Irp
, IrpContext
->PriorityBoost
);
147 if (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)
149 /* Reset our status flags before queueing the IRP */
150 IrpContext
->Flags
|= IRPCONTEXT_COMPLETE
;
151 IrpContext
->Flags
&= ~IRPCONTEXT_QUEUE
;
152 Status
= NtfsQueueRequest(IrpContext
);
156 ExFreeToNPagedLookasideList(&NtfsGlobalData
->IrpContextLookasideList
, IrpContext
);
159 IoSetTopLevelIrp(NULL
);
160 FsRtlExitFileSystem();
168 NtfsDoRequest(PVOID IrpContext
)
170 InterlockedDecrement(&QueueCount
);
171 DPRINT("NtfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
172 IrpContext
, ((PNTFS_IRP_CONTEXT
)IrpContext
)->MajorFunction
, QueueCount
);
173 NtfsDispatch((PNTFS_IRP_CONTEXT
)IrpContext
);
177 * FUNCTION: This function manages IRP for various major functions
179 * DriverObject = object describing this driver
180 * Irp = IRP to be passed to internal functions
181 * RETURNS: Status of I/O Request
185 NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject
,
188 PNTFS_IRP_CONTEXT IrpContext
= NULL
;
191 TRACE_(NTFS
, "NtfsFsdDispatch()\n");
193 IrpContext
= NtfsAllocateIrpContext(DeviceObject
, Irp
);
194 if (IrpContext
== NULL
)
196 Status
= STATUS_INSUFFICIENT_RESOURCES
;
197 Irp
->IoStatus
.Status
= Status
;
198 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
202 Status
= NtfsDispatch(IrpContext
);