2008-02-10 11:20:29 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2008 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2008-03-08 21:45:51 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-02-10 11:20:29 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: drivers/filesystem/ntfs/dispatch.c
|
|
|
|
* PURPOSE: NTFS filesystem driver
|
|
|
|
* PROGRAMMER: Pierre Schweitzer
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include "ntfs.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-05-24 12:28:51 +00:00
|
|
|
static LONG QueueCount = 0;
|
|
|
|
|
2008-02-10 11:20:29 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2015-05-24 12:28:51 +00:00
|
|
|
static WORKER_THREAD_ROUTINE NtfsDoRequest;
|
|
|
|
|
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
NtfsQueueRequest(PNTFS_IRP_CONTEXT IrpContext)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&QueueCount);
|
|
|
|
DPRINT("NtfsQueueRequest(IrpContext %p), %d\n", IrpContext, QueueCount);
|
|
|
|
|
|
|
|
ASSERT(!(IrpContext->Flags & IRPCONTEXT_QUEUE) &&
|
|
|
|
(IrpContext->Flags & IRPCONTEXT_COMPLETE));
|
|
|
|
IrpContext->Flags |= IRPCONTEXT_CANWAIT;
|
|
|
|
IoMarkIrpPending(IrpContext->Irp);
|
|
|
|
ExInitializeWorkItem(&IrpContext->WorkQueueItem, NtfsDoRequest, IrpContext);
|
|
|
|
ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
|
|
|
|
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
|
2015-05-24 10:48:15 +00:00
|
|
|
static
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS
|
2015-05-24 10:48:15 +00:00
|
|
|
NtfsDispatch(PNTFS_IRP_CONTEXT IrpContext)
|
2008-02-10 11:20:29 +00:00
|
|
|
{
|
2015-05-24 10:48:15 +00:00
|
|
|
PIRP Irp = IrpContext->Irp;
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS Status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
2015-05-24 10:48:15 +00:00
|
|
|
TRACE_(NTFS, "NtfsDispatch()\n");
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
|
|
|
NtfsIsIrpTopLevel(Irp);
|
|
|
|
|
2015-05-24 10:48:15 +00:00
|
|
|
switch (IrpContext->MajorFunction)
|
2008-02-10 11:20:29 +00:00
|
|
|
{
|
2015-05-24 10:48:15 +00:00
|
|
|
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
|
|
|
Status = NtfsQueryVolumeInformation(IrpContext);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_SET_VOLUME_INFORMATION:
|
|
|
|
Status = NtfsSetVolumeInformation(IrpContext);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_QUERY_INFORMATION:
|
|
|
|
Status = NtfsQueryInformation(IrpContext);
|
|
|
|
break;
|
|
|
|
|
2017-05-27 03:20:31 +00:00
|
|
|
case IRP_MJ_SET_INFORMATION:
|
2017-05-27 19:32:43 +00:00
|
|
|
if (!NtfsGlobalData->EnableWriteSupport)
|
|
|
|
{
|
|
|
|
DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
|
|
|
|
Status = STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = NtfsSetInformation(IrpContext);
|
|
|
|
}
|
2017-05-27 03:20:31 +00:00
|
|
|
break;
|
|
|
|
|
2015-05-24 10:48:15 +00:00
|
|
|
case IRP_MJ_DIRECTORY_CONTROL:
|
|
|
|
Status = NtfsDirectoryControl(IrpContext);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_READ:
|
|
|
|
Status = NtfsRead(IrpContext);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
|
|
|
Status = NtfsDeviceControl(IrpContext);
|
|
|
|
break;
|
2015-05-24 12:17:43 +00:00
|
|
|
|
|
|
|
case IRP_MJ_WRITE:
|
2017-05-27 19:32:43 +00:00
|
|
|
if (!NtfsGlobalData->EnableWriteSupport)
|
|
|
|
{
|
|
|
|
DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
|
|
|
|
Status = STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = NtfsWrite(IrpContext);
|
|
|
|
}
|
2015-05-24 12:17:43 +00:00
|
|
|
break;
|
2015-05-24 21:29:34 +00:00
|
|
|
|
|
|
|
case IRP_MJ_CLOSE:
|
|
|
|
Status = NtfsClose(IrpContext);
|
|
|
|
break;
|
2015-05-25 11:58:23 +00:00
|
|
|
|
2016-02-22 22:20:54 +00:00
|
|
|
case IRP_MJ_CLEANUP:
|
|
|
|
Status = NtfsCleanup(IrpContext);
|
|
|
|
break;
|
|
|
|
|
2015-05-25 11:58:23 +00:00
|
|
|
case IRP_MJ_CREATE:
|
|
|
|
Status = NtfsCreate(IrpContext);
|
|
|
|
break;
|
2015-05-25 12:55:51 +00:00
|
|
|
|
|
|
|
case IRP_MJ_FILE_SYSTEM_CONTROL:
|
|
|
|
Status = NtfsFileSystemControl(IrpContext);
|
|
|
|
break;
|
2008-02-10 11:20:29 +00:00
|
|
|
}
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2015-05-10 20:56:48 +00:00
|
|
|
ASSERT((!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
|
|
|
|
((IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
|
2015-05-10 20:47:44 +00:00
|
|
|
(!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && (IrpContext->Flags & IRPCONTEXT_QUEUE)));
|
|
|
|
|
|
|
|
if (IrpContext->Flags & IRPCONTEXT_COMPLETE)
|
2015-05-10 20:56:48 +00:00
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
2015-05-10 20:47:44 +00:00
|
|
|
IoCompleteRequest(Irp, IrpContext->PriorityBoost);
|
2015-05-10 20:56:48 +00:00
|
|
|
}
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2015-05-24 12:20:51 +00:00
|
|
|
if (IrpContext->Flags & IRPCONTEXT_QUEUE)
|
|
|
|
{
|
|
|
|
/* Reset our status flags before queueing the IRP */
|
|
|
|
IrpContext->Flags |= IRPCONTEXT_COMPLETE;
|
|
|
|
IrpContext->Flags &= ~IRPCONTEXT_QUEUE;
|
2015-05-24 12:28:51 +00:00
|
|
|
Status = NtfsQueueRequest(IrpContext);
|
2015-05-24 12:20:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-24 15:26:15 +00:00
|
|
|
ExFreeToNPagedLookasideList(&NtfsGlobalData->IrpContextLookasideList, IrpContext);
|
2015-05-24 12:20:51 +00:00
|
|
|
}
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
IoSetTopLevelIrp(NULL);
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return Status;
|
2008-02-10 11:20:29 +00:00
|
|
|
}
|
2015-05-24 10:48:15 +00:00
|
|
|
|
2015-05-24 12:28:51 +00:00
|
|
|
static
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
NtfsDoRequest(PVOID IrpContext)
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&QueueCount);
|
|
|
|
DPRINT("NtfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
|
|
|
|
IrpContext, ((PNTFS_IRP_CONTEXT)IrpContext)->MajorFunction, QueueCount);
|
|
|
|
NtfsDispatch((PNTFS_IRP_CONTEXT)IrpContext);
|
|
|
|
}
|
|
|
|
|
2015-05-24 10:48:15 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: This function manages IRP for various major functions
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DriverObject = object describing this driver
|
|
|
|
* Irp = IRP to be passed to internal functions
|
|
|
|
* RETURNS: Status of I/O Request
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PNTFS_IRP_CONTEXT IrpContext = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE_(NTFS, "NtfsFsdDispatch()\n");
|
|
|
|
|
|
|
|
IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
|
|
|
|
if (IrpContext == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = NtfsDispatch(IrpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|