Example #1
0
VOID
Ext2DeQueueCloseRequest (IN PVOID Context)
{
    PEXT2_IRP_CONTEXT IrpContext;

    IrpContext = (PEXT2_IRP_CONTEXT) Context;
    ASSERT(IrpContext);
    ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
           (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));

    __try {

        __try {

            FsRtlEnterFileSystem();
            Ext2Close(IrpContext);

        } __except (Ext2ExceptionFilter(IrpContext, GetExceptionInformation())) {

            Ext2ExceptionHandler(IrpContext);
        }

    } __finally {

        FsRtlExitFileSystem();
    }
}
Example #2
0
NTSTATUS
NTAPI
FatCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    PFAT_IRP_CONTEXT IrpContext;
    NTSTATUS Status;

    DPRINT("FatCleanup(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);

    /* FatCleanup works only with a volume device object */
    if (DeviceObject == FatGlobalData.DiskDeviceObject)
    {
        /* Complete the request and return success */
        Irp->IoStatus.Status = STATUS_SUCCESS;
        Irp->IoStatus.Information = FILE_OPENED;

        IoCompleteRequest(Irp, IO_DISK_INCREMENT);

        return STATUS_SUCCESS;
    }

    /* Enter FsRtl critical region */
    FsRtlEnterFileSystem();

    /* Build an irp context */
    IrpContext = FatBuildIrpContext(Irp, TRUE);

    /* Call internal function */
    Status = FatiCleanup(IrpContext, Irp);

    /* Leave FsRtl critical region */
    FsRtlExitFileSystem();

    return Status;
}
Example #3
0
VOID NTAPI
FFSDeQueueCloseRequest(
	IN PVOID Context)
{
	PFFS_IRP_CONTEXT IrpContext;

    PAGED_CODE();

	IrpContext = (PFFS_IRP_CONTEXT) Context;

	ASSERT(IrpContext);

	ASSERT((IrpContext->Identifier.Type == FFSICX) &&
			(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));

	_SEH2_TRY
	{
		_SEH2_TRY
		{
			FsRtlEnterFileSystem();
			FFSClose(IrpContext);
		}
		_SEH2_EXCEPT (FFSExceptionFilter(IrpContext, _SEH2_GetExceptionInformation()))
		{
			FFSExceptionHandler(IrpContext);
		} _SEH2_END;
	}
	_SEH2_FINALLY
	{
		FsRtlExitFileSystem();
	} _SEH2_END;
}
Example #4
0
VOID
FatCloseWorker (
    IN PDEVICE_OBJECT DeviceObject,
    IN PVOID Context
    )
/*++

Routine Description:

    This routine is a shim between the IO worker package and FatFspClose.

Arguments:

    DeviceObject - Registration device object, unused
    Context - Context value, unused

Return Value:

    None.

--*/
{
    FsRtlEnterFileSystem();
    
    FatFspClose (Context);
    
    FsRtlExitFileSystem();
}
Example #5
0
VOID
NTAPI
FatDequeueRequest(IN PVOID Context)
{
    PFAT_IRP_CONTEXT IrpContext;

    IrpContext = (PFAT_IRP_CONTEXT) Context;

    /* Enter critical region. */
    FsRtlEnterFileSystem();

    /* Handle top level IRP Correctly. */
    if (!FlagOn(IrpContext->Flags, IRPCONTEXT_TOPLEVEL))
        IoSetTopLevelIrp((PIRP) FSRTL_FSP_TOP_LEVEL_IRP);

    /* Enable Synchronous IO. */
    SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT);

    /* Invoke the handler routine. */
    IrpContext->QueuedOperationHandler(IrpContext);

    /* Restore top level IRP. */
	IoSetTopLevelIrp(NULL);

    /* Leave critical region. */
	FsRtlExitFileSystem();
}
Example #6
0
/*************************************************************************
*
* Function: Ext2FileSystemControl
*
* Description:
*	The I/O Manager will invoke this routine to handle a 
*   File System Control IRP
*
* Expected Interrupt Level (for execution) :
*  
*	???
*
* Arguments:
*
*    DeviceObject - Supplies the volume device object where the
*                   file exists
*
*    Irp - Supplies the Irp being processed
*
*
* Return Value:
*
*    NTSTATUS - The FSD status for the IRP
*
*************************************************************************/
NTSTATUS NTAPI
Ext2FileSystemControl(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
{
  
    NTSTATUS Status = STATUS_SUCCESS;
	PIO_STACK_LOCATION IrpSp;
    
	DebugTrace(DEBUG_TRACE_IRP_ENTRY,   "File System Control IRP Received...", 0);
		
	//	Ext2BreakPoint();

	FsRtlEnterFileSystem();

	ASSERT(DeviceObject);
	ASSERT(Irp);

	//
    //  Get a pointer to the current Irp stack location
    //
    IrpSp = IoGetCurrentIrpStackLocation( Irp );
	

	if( IrpSp->MinorFunction == IRP_MN_MOUNT_VOLUME )
	{
		DebugTrace(DEBUG_TRACE_MOUNT,   "Mount Request Received...", 0);
		Status = Ext2MountVolume ( Irp, IrpSp );
		Ext2CompleteRequest( Irp, Status );
	}
	else if( IrpSp->MinorFunction == IRP_MN_USER_FS_REQUEST )
	{
		DebugTrace(DEBUG_TRACE_FSCTRL,   "IRP_MN_USER_FS_REQUEST received...", 0);
		Status = Ext2UserFileSystemRequest( Irp, IrpSp );
		Ext2CompleteRequest( Irp, Status );
	}
	else 
	{
		if( IrpSp->MinorFunction == IRP_MN_VERIFY_VOLUME )
		{
			DebugTrace(DEBUG_TRACE_FSCTRL,   "IRP_MN_VERIFY_VOLUME received...", 0);
		}
		else if( IrpSp->MinorFunction == IRP_MN_LOAD_FILE_SYSTEM )
		{
			DebugTrace(DEBUG_TRACE_FSCTRL,   "IRP_MN_LOAD_FILE_SYSTEM received...", 0);
		}
		else
		{
			DebugTrace(DEBUG_TRACE_FSCTRL,   "Unknown Minor IRP code received...", 0);
		}

		Status = STATUS_INVALID_DEVICE_REQUEST;
		Ext2CompleteRequest( Irp, Status );
	}
	
	FsRtlExitFileSystem();

    return Status;
}
Example #7
0
NTSTATUS
NTAPI
NpFsdQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject,
                            IN PIRP Irp)
{
    NTSTATUS Status;
    PAGED_CODE();
    TRACE("Entered\n");

    FsRtlEnterFileSystem();
    NpAcquireSharedVcb();

    Status = NpCommonQueryVolumeInformation(DeviceObject, Irp);

    NpReleaseVcb();
    FsRtlExitFileSystem();

    if (Status != STATUS_PENDING)
    {
        Irp->IoStatus.Status = Status;
        IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
    }

    TRACE("Leaving, Status = %lx\n", Status);
    return Status;
}
Example #8
0
VOID DDKAPI LklDequeueRequest(IN PDEVICE_OBJECT device, IN PVOID context)
{
	NTSTATUS status;
	PIRPCONTEXT irp_context;

	irp_context = (PIRPCONTEXT) context;
	ASSERT(irp_context);
	ASSERT(irp_context->id.type == IRP_CONTEXT && irp_context->id.size == sizeof(IRPCONTEXT));

	IoFreeWorkItem(irp_context->work_item);

	if (FLAG_ON(irp_context->flags, VFS_IRP_CONTEXT_NOT_TOP_LEVEL))
		IoSetTopLevelIrp((PIRP)FSRTL_FSP_TOP_LEVEL_IRP);

	SET_FLAG(irp_context->flags, VFS_IRP_CONTEXT_CAN_BLOCK);

	FsRtlEnterFileSystem();

	status = LklDispatchRequest(irp_context);

	FsRtlExitFileSystem();

	IoSetTopLevelIrp(NULL);

}
Example #9
0
NTSTATUS
NTAPI
FatLockControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    PFAT_IRP_CONTEXT IrpContext;
    NTSTATUS Status;
    BOOLEAN TopLevel;

    DPRINT1("FatLockControl()\n");

    /* Enter FsRtl critical region */
    FsRtlEnterFileSystem();

    /* Set Top Level IRP if not set */
    TopLevel = FatIsTopLevelIrp(Irp);

    /* Build an irp context */
    IrpContext = FatBuildIrpContext(Irp, IoIsOperationSynchronous(Irp));

    /* Call internal function */
    Status = FatiLockControl(IrpContext, Irp);

    /* Reset Top Level IRP */
    if (TopLevel) IoSetTopLevelIrp(NULL);

    /* Leave FsRtl critical region */
    FsRtlExitFileSystem();

    return Status;
}
Example #10
0
NTSTATUS
NTAPI
FatFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    NTSTATUS Status = STATUS_SUCCESS;
    PFAT_IRP_CONTEXT IrpContext;
    BOOLEAN CanWait = TRUE;

    DPRINT("FatFileSystemControl(DeviceObject %p, Irp %p)\n", DeviceObject, Irp);

    /* Get CanWait flag */
    if (IoGetCurrentIrpStackLocation(Irp)->FileObject)
    {
        CanWait = IoIsOperationSynchronous(Irp);
    }

    /* Enter FsRtl critical region */
    FsRtlEnterFileSystem();

    /* Build an irp context */
    IrpContext = FatBuildIrpContext(Irp, CanWait);

    /* Call internal function */
    Status = FatiFileSystemControl(IrpContext, Irp);

    /* Leave FsRtl critical region */
    FsRtlExitFileSystem();

    return Status;
}
Example #11
0
VOID
FatCloseWorker (
    _In_        PDEVICE_OBJECT DeviceObject,
    _In_opt_    PVOID Context
    )
/*++

Routine Description:

    This routine is a shim between the IO worker package and FatFspClose.

Arguments:

    DeviceObject - Registration device object, unused
    Context - Context value, unused

Return Value:

    None.

--*/
{
    PAGED_CODE();

    UNREFERENCED_PARAMETER( DeviceObject );
    
    FsRtlEnterFileSystem();
    
    FatFspClose (Context);
    
    FsRtlExitFileSystem();
}
Example #12
0
BOOLEAN
Ext2FastIoWrite (
    IN PFILE_OBJECT         FileObject,
    IN PLARGE_INTEGER       FileOffset,
    IN ULONG                Length,
    IN BOOLEAN              Wait,
    IN ULONG                LockKey,
    OUT PVOID               Buffer,
    OUT PIO_STATUS_BLOCK    IoStatus,
    IN PDEVICE_OBJECT       DeviceObject)
{
    PEXT2_FCB   Fcb = NULL;
    BOOLEAN     Status = FALSE;
    BOOLEAN     Locked = FALSE;

    Fcb = (PEXT2_FCB) FileObject->FsContext;
    if (Fcb == NULL)
        return FALSE;

    __try {

        FsRtlEnterFileSystem();

        ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
               (Fcb->Identifier.Size == sizeof(EXT2_FCB)));

        if (IsFlagOn(Fcb->Vcb->Flags, VCB_READ_ONLY)) {
            __leave;
        }

        ExAcquireResourceSharedLite(&Fcb->MainResource, TRUE);
        Locked = TRUE;

        if (IsEndOfFile(*FileOffset) || ((LONGLONG)(Fcb->Inode->i_size) <
                                         (FileOffset->QuadPart + Length)) ) {
        } else {
            ExReleaseResourceLite(&Fcb->MainResource);
            Locked = FALSE;
            Status = FsRtlCopyWrite(FileObject, FileOffset, Length, Wait,
                                    LockKey, Buffer, IoStatus, DeviceObject);
        }

    } __finally {

        if (Locked) {
            ExReleaseResourceLite(&Fcb->MainResource);
        }

        FsRtlExitFileSystem();
    }

    DEBUG(DL_IO, ("Ext2FastIoWrite: %wZ Offset: %I64xh Length: %xh Key: %xh Status=%d\n",
                   &Fcb->Mcb->ShortName,  FileOffset->QuadPart, Length, LockKey, Status));

    return Status;
}
Example #13
0
/*************************************************************************
*
* Function: UDFClose()
*
* Description:
*   The I/O Manager will invoke this routine to handle a close
*   request
*
* Expected Interrupt Level (for execution) :
*
*  IRQL_PASSIVE_LEVEL (invocation at higher IRQL will cause execution
*   to be deferred to a worker thread context)
*
* Return Value: STATUS_SUCCESS
*
*************************************************************************/
NTSTATUS
NTAPI
UDFClose(
    PDEVICE_OBJECT  DeviceObject,  // the logical volume device object
    PIRP            Irp            // I/O Request Packet
    )
{
    NTSTATUS            RC = STATUS_SUCCESS;
    PtrUDFIrpContext    PtrIrpContext = NULL;
    BOOLEAN             AreWeTopLevel = FALSE;

    AdPrint(("UDFClose: \n"));

    FsRtlEnterFileSystem();
    ASSERT(DeviceObject);
    ASSERT(Irp);

    //  If we were called with our file system device object instead of a
    //  volume device object, just complete this request with STATUS_SUCCESS
    if (UDFIsFSDevObj(DeviceObject)) {
        // this is a close of the FSD itself
        Irp->IoStatus.Status = RC;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);
        FsRtlExitFileSystem();
        return(RC);
    }

    // set the top level context
    AreWeTopLevel = UDFIsIrpTopLevel(Irp);

    _SEH2_TRY {

        // get an IRP context structure and issue the request
        PtrIrpContext = UDFAllocateIrpContext(Irp, DeviceObject);
        ASSERT(PtrIrpContext);

        RC = UDFCommonClose(PtrIrpContext, Irp);

    } _SEH2_EXCEPT(UDFExceptionFilter(PtrIrpContext, _SEH2_GetExceptionInformation())) {

        RC = UDFExceptionHandler(PtrIrpContext, Irp);

        UDFLogEvent(UDF_ERROR_INTERNAL_ERROR, RC);
    } _SEH2_END;

    if (AreWeTopLevel) {
        IoSetTopLevelIrp(NULL);
    }

    FsRtlExitFileSystem();

    return(RC);
}
Example #14
0
NTSTATUS
DfsFsdCleanup (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
) {
    NTSTATUS Status;
    PIRP_CONTEXT IrpContext;

    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
    PFILE_OBJECT FileObject = IrpSp->FileObject;

    TYPE_OF_OPEN TypeOfOpen;
    PDFS_VCB Vcb;
    PDFS_FCB Fcb;

    DfsDbgTrace(+1, Dbg, "DfsFsdCleanup:  Entered\n", 0);

    ASSERT(IoIsOperationSynchronous(Irp) == TRUE);

    //
    // Now, pass through to the device that opened the file for us if the
    // file was a redirected open of some kind.
    //

    if (DeviceObject->DeviceType == FILE_DEVICE_DFS) {
        TypeOfOpen = DfsDecodeFileObject( FileObject, &Vcb, &Fcb);
        if (TypeOfOpen == RedirectedFileOpen) {
            Status = DfsVolumePassThrough(DeviceObject, Irp);
            DfsDbgTrace(-1, Dbg, "DfsFsdCleanup: RedirectedOpen.Exit -> %08lx\n", Status );
            return Status;
        }
    }

    //
    //  TypeOfOpen != RedirectedFileOpen. We do nothing special for cleanup;
    //  everything is done in the close routine.
    //

    FsRtlEnterFileSystem();

    Status = STATUS_SUCCESS;

    DfsCompleteRequest( NULL, Irp, Status );

    FsRtlExitFileSystem();

    //
    //  And return to our caller
    //

    DfsDbgTrace(-1, Dbg, "DfsFsdCleanup:  Exit -> %08lx\n", Status);

    return Status;

}
Example #15
0
NTSTATUS
DfsFsdClose (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
) {
    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
    NTSTATUS Status;
    PIRP_CONTEXT IrpContext;

    DfsDbgTrace(+1, Dbg, "DfsFsdClose:  Entered\n", 0);
    ASSERT(IoIsOperationSynchronous(Irp) == TRUE);

    if (DeviceObject->DeviceType == FILE_DEVICE_DFS_VOLUME) {
        if (DfsLookupFcb(IrpSp->FileObject) == NULL) {
            Status = DfsVolumePassThrough(DeviceObject, Irp);
            DfsDbgTrace(-1, Dbg, "DfsFsdClose:  Exit -> %08lx\n", Status );
            return Status;
        }
    }

    //
    //  Call the common close routine, with blocking allowed if synchronous
    //
    FsRtlEnterFileSystem();

    try {

        IrpContext = DfsCreateIrpContext( Irp, CanFsdWait( Irp ) );

        Status = DfsCommonClose( IrpContext, Irp );

    } except(DfsExceptionFilter( IrpContext, GetExceptionCode(), GetExceptionInformation() )) {

        //
        //  We had some trouble trying to perform the requested
        //  operation, so we'll abort the I/O request with
        //  the error status that we get back from the
        //  execption code
        //

        Status = DfsProcessException( IrpContext, Irp, GetExceptionCode() );
    }

    FsRtlExitFileSystem();

    //
    //  And return to our caller
    //

    DfsDbgTrace(-1, Dbg, "DfsFsdClose:  Exit -> %08lx\n", Status);

    return Status;
}
Example #16
0
/*************************************************************************
*
* Function: UDFShutdown()
*
* Description:
*   All disk-based FSDs can expect to receive this shutdown notification
*   request whenever the system is about to be halted gracefully. If you
*   design and implement a network redirector, you must register explicitly
*   for shutdown notification by invoking the IoRegisterShutdownNotification()
*   routine from your driver entry.
*
*   Note that drivers that register to receive shutdown notification get
*   invoked BEFORE disk-based FSDs are told about the shutdown notification.
*
* Expected Interrupt Level (for execution) :
*
*  IRQL_PASSIVE_LEVEL
*
* Return Value: Irrelevant.
*
*************************************************************************/
NTSTATUS
NTAPI
UDFShutdown(
    PDEVICE_OBJECT   DeviceObject,       // the logical volume device object
    PIRP             Irp                 // I/O Request Packet
    )
{
    NTSTATUS         RC = STATUS_SUCCESS;
    PtrUDFIrpContext PtrIrpContext = NULL;
    BOOLEAN          AreWeTopLevel = FALSE;

    KdPrint(("UDFShutDown\n"));
//    BrutePoint();

    FsRtlEnterFileSystem();
    ASSERT(DeviceObject);
    ASSERT(Irp);

    // set the top level context
    AreWeTopLevel = UDFIsIrpTopLevel(Irp);
    //ASSERT(!UDFIsFSDevObj(DeviceObject));

    _SEH2_TRY {

        // get an IRP context structure and issue the request
        PtrIrpContext = UDFAllocateIrpContext(Irp, DeviceObject);
        if(PtrIrpContext) {
            RC = UDFCommonShutdown(PtrIrpContext, Irp);
        } else {
            RC = STATUS_INSUFFICIENT_RESOURCES;
            Irp->IoStatus.Status = RC;
            Irp->IoStatus.Information = 0;
            // complete the IRP
            IoCompleteRequest(Irp, IO_DISK_INCREMENT);
        }

    } _SEH2_EXCEPT(UDFExceptionFilter(PtrIrpContext, _SEH2_GetExceptionInformation())) {

        RC = UDFExceptionHandler(PtrIrpContext, Irp);

        UDFLogEvent(UDF_ERROR_INTERNAL_ERROR, RC);
    } _SEH2_END;

    if (AreWeTopLevel) {
        IoSetTopLevelIrp(NULL);
    }

    FsRtlExitFileSystem();

    return(RC);
} // end UDFShutdown()
Example #17
0
static void do_flush(device_extension* Vcb) {
    FsRtlEnterFileSystem();

    acquire_tree_lock(Vcb, TRUE);

    if (Vcb->write_trees > 0)
        do_write(Vcb);
    
    free_tree_cache(&Vcb->tree_cache);

    release_tree_lock(Vcb, TRUE);

    FsRtlExitFileSystem();
}
Example #18
0
NTSTATUS
NTAPI
NtfsFsdDirectoryControl(PDEVICE_OBJECT DeviceObject,
                        PIRP Irp)
{
    PNTFS_IRP_CONTEXT IrpContext = NULL;
    NTSTATUS Status = STATUS_UNSUCCESSFUL;

    DPRINT1("NtfsDirectoryControl() called\n");

    FsRtlEnterFileSystem();
    ASSERT(DeviceObject);
    ASSERT(Irp);

    NtfsIsIrpTopLevel(Irp);

    IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
    if (IrpContext)
    {
        switch (IrpContext->MinorFunction)
        {
            case IRP_MN_QUERY_DIRECTORY:
                Status = NtfsQueryDirectory(IrpContext);
                break;

            case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
                DPRINT1("IRP_MN_NOTIFY_CHANGE_DIRECTORY\n");
                Status = STATUS_NOT_IMPLEMENTED;
                break;

            default:
                Status = STATUS_INVALID_DEVICE_REQUEST;
                break;
        }
    }
    else
        Status = STATUS_INSUFFICIENT_RESOURCES;

    Irp->IoStatus.Status = Status;
    Irp->IoStatus.Information = 0;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    if (IrpContext)
        ExFreePoolWithTag(IrpContext, 'PRIN');

    IoSetTopLevelIrp(NULL);
    FsRtlExitFileSystem();
    return Status;
}
Example #19
0
NTSTATUS
DokanBuildRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    BOOLEAN             AtIrqlPassiveLevel = FALSE;
    BOOLEAN             IsTopLevelIrp = FALSE;
    NTSTATUS            Status = STATUS_UNSUCCESSFUL;

    __try {

        __try {

            AtIrqlPassiveLevel = (KeGetCurrentIrql() == PASSIVE_LEVEL);

            if (AtIrqlPassiveLevel) {
                FsRtlEnterFileSystem();
            }

            if (!IoGetTopLevelIrp()) {
                IsTopLevelIrp = TRUE;
                IoSetTopLevelIrp(Irp);
            }

            Status = DokanDispatchRequest(DeviceObject, Irp);

        }
        __except (DokanExceptionFilter(Irp, GetExceptionInformation()))
        {

            Status = DokanExceptionHandler(DeviceObject, Irp, GetExceptionCode());
        }

    }
    __finally {

        if (IsTopLevelIrp) {
            IoSetTopLevelIrp(NULL);
        }

        if (AtIrqlPassiveLevel) {
            FsRtlExitFileSystem();
        }
    }

    return Status;
}
Example #20
0
/*************************************************************************
*
* Function: Ext2Close()
*
* Description:
*	The I/O Manager will invoke this routine to handle a close
*	request
*
* Expected Interrupt Level (for execution) :
*
*  IRQL_PASSIVE_LEVEL (invocation at higher IRQL will cause execution
*	to be deferred to a worker thread context)
*
* Return Value: Does not matter!
*
*************************************************************************/
NTSTATUS NTAPI Ext2Close(
PDEVICE_OBJECT		DeviceObject,		// the logical volume device object
PIRP					Irp)					// I/O Request Packet
{
	NTSTATUS				RC = STATUS_SUCCESS;
	PtrExt2IrpContext	PtrIrpContext = NULL;
	BOOLEAN				AreWeTopLevel = FALSE;

	DebugTrace(DEBUG_TRACE_IRP_ENTRY, "Close IRP Received...", 0);
	

	FsRtlEnterFileSystem();

	ASSERT(DeviceObject);
	ASSERT(Irp);

	// set the top level context
	AreWeTopLevel = Ext2IsIrpTopLevel(Irp);

	try 
	{

		// get an IRP context structure and issue the request
		PtrIrpContext = Ext2AllocateIrpContext(Irp, DeviceObject);
		ASSERT(PtrIrpContext);

		RC = Ext2CommonClose(PtrIrpContext, Irp, TRUE);

	}
	except (Ext2ExceptionFilter(PtrIrpContext, GetExceptionInformation())) 
	{

		RC = Ext2ExceptionHandler(PtrIrpContext, Irp);
		Ext2LogEvent(EXT2_ERROR_INTERNAL_ERROR, RC);
	}

	if (AreWeTopLevel) 
	{
		IoSetTopLevelIrp(NULL);
	}

	FsRtlExitFileSystem();

	return(RC);
}
Example #21
0
/*
 * 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 = STATUS_UNSUCCESSFUL;
  
  TRACE_(NTFS, "NtfsFsdDispatch()\n");
  
  FsRtlEnterFileSystem();
  ASSERT(DeviceObject);
  ASSERT(Irp);
  
  NtfsIsIrpTopLevel(Irp);
  
  IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
  if (IrpContext)
  {
    switch (IrpContext->MajorFunction)
    {
      case IRP_MJ_QUERY_VOLUME_INFORMATION:
      {
        Status = NtfsQueryVolumeInformation(IrpContext);
        break;
      }
      case IRP_MJ_SET_VOLUME_INFORMATION:
      {
        Status = NtfsSetVolumeInformation(IrpContext);
        break;
      }
    }
  }
  else
    Status = STATUS_INSUFFICIENT_RESOURCES;
	
  Irp->IoStatus.Status = Status;
  IoCompleteRequest(Irp, IO_NO_INCREMENT);
	
	if (IrpContext)
    ExFreePoolWithTag(IrpContext, 'PRIN');
	
  IoSetTopLevelIrp(NULL);
  FsRtlExitFileSystem();
  return Status;
}
Example #22
0
VOID
NTAPI
NpCancelListeningQueueIrp(IN PDEVICE_OBJECT DeviceObject,
                          IN PIRP Irp)
{
    IoReleaseCancelSpinLock(Irp->CancelIrql);

    FsRtlEnterFileSystem();
    NpAcquireExclusiveVcb();

    RemoveEntryList(&Irp->Tail.Overlay.ListEntry);

    FsRtlExitFileSystem();
    NpReleaseVcb();

    Irp->IoStatus.Status = STATUS_CANCELLED;
    IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
}
Example #23
0
static void do_flush(device_extension* Vcb) {
    LIST_ENTRY rollback;
    
    InitializeListHead(&rollback);
    
    FsRtlEnterFileSystem();

    ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);

    if (Vcb->need_write)
        do_write(Vcb, &rollback);
    
    free_trees(Vcb);
    
    clear_rollback(&rollback);

    ExReleaseResourceLite(&Vcb->tree_lock);

    FsRtlExitFileSystem();
}
Example #24
0
NTSTATUS DDKAPI VfsDirectoryControl(PDEVICE_OBJECT device, PIRP irp)
{
	NTSTATUS status = STATUS_SUCCESS;
	PIRPCONTEXT irp_context = NULL;
	BOOLEAN top_level = FALSE;
	
	FsRtlEnterFileSystem();

	top_level = LklIsIrpTopLevel(irp);

	irp_context = AllocIrpContext(irp, device);
	status = CommonDirectoryControl(irp_context, irp);

	if (top_level) 
		IoSetTopLevelIrp(NULL);

	FsRtlExitFileSystem();

	return status;
}
Example #25
0
_IRQL_requires_same_
BOOLEAN
NTAPI
NpFastWrite(
    _In_ PFILE_OBJECT FileObject,
    _In_ PLARGE_INTEGER FileOffset,
    _In_ ULONG Length,
    _In_ BOOLEAN Wait,
    _In_ ULONG LockKey,
    _In_ PVOID Buffer,
    _Out_ PIO_STATUS_BLOCK IoStatus,
    _In_ PDEVICE_OBJECT DeviceObject)
{
    LIST_ENTRY DeferredList;
    BOOLEAN Result;
    PAGED_CODE();

    InitializeListHead(&DeferredList);

    FsRtlEnterFileSystem();
    NpAcquireSharedVcb();

    Result = NpCommonWrite(FileObject,
                           Buffer,
                           Length,
                           PsGetCurrentThread(),
                           IoStatus,
                           NULL,
                           &DeferredList);
    if (Result)
        ++NpFastWriteTrue;
    else
        ++NpFastWriteFalse;

    NpReleaseVcb();
    NpCompleteDeferredIrps(&DeferredList);
    FsRtlExitFileSystem();

    return Result;
}
Example #26
0
VOID FspIopCompleteCanceledIrp(PIRP Irp)
{
    PAGED_CODE();

    DEBUGLOGIRP(Irp, STATUS_CANCELLED);

    /*
     * An IRP cancel may happen at any time including when APC's are still enabled.
     * For this reason we execute FsRtlEnterFileSystem/FsRtlExitFileSystem here.
     * This will protect ERESOURCE operations during Request finalizations.
     */
    FsRtlEnterFileSystem();

    PIRP TopLevelIrp = IoGetTopLevelIrp();
    IoSetTopLevelIrp(Irp);

    FspIopCompleteIrpEx(Irp, STATUS_CANCELLED, TRUE);

    IoSetTopLevelIrp(TopLevelIrp);

    FsRtlExitFileSystem();
}
Example #27
0
NTSTATUS
NTAPI
FatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    NTSTATUS Status;
    BOOLEAN TopLevel, CanWait;
    PFAT_IRP_CONTEXT IrpContext;

    CanWait = TRUE;
    TopLevel = FALSE;
    Status = STATUS_INVALID_DEVICE_REQUEST;
    /* Get CanWait flag */
    if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL)
        CanWait = IoIsOperationSynchronous(Irp);

    /* Enter FsRtl critical region */
    FsRtlEnterFileSystem();

    if (DeviceObject != FatGlobalData.DiskDeviceObject)
    {
        /* Set Top Level IRP if not set */
        TopLevel = FatIsTopLevelIrp(Irp);

        /* Build an irp context */
        IrpContext = FatBuildIrpContext(Irp, CanWait);

        /* Perform the actual read */
        Status = FatiRead(IrpContext);

        /* Restore top level Irp */
        if (TopLevel)
            IoSetTopLevelIrp(NULL);
    }
    /* Leave FsRtl critical region */
    FsRtlExitFileSystem();

    return Status;
}
Example #28
0
NTSTATUS
NTAPI
NpFsdWrite(IN PDEVICE_OBJECT DeviceObject,
           IN PIRP Irp)
{
    PIO_STACK_LOCATION IoStack;
    IO_STATUS_BLOCK IoStatus;
    LIST_ENTRY DeferredList;
    PAGED_CODE();
    NpSlowWriteCalls++;

    InitializeListHead(&DeferredList);
    IoStack = IoGetCurrentIrpStackLocation(Irp);

    FsRtlEnterFileSystem();
    NpAcquireSharedVcb();

    NpCommonWrite(IoStack->FileObject,
                  Irp->UserBuffer,
                  IoStack->Parameters.Write.Length,
                  Irp->Tail.Overlay.Thread,
                  &IoStatus,
                  Irp,
                  &DeferredList);

    NpReleaseVcb();
    NpCompleteDeferredIrps(&DeferredList);
    FsRtlExitFileSystem();

    if (IoStatus.Status != STATUS_PENDING)
    {
        Irp->IoStatus.Information = IoStatus.Information;
        Irp->IoStatus.Status = IoStatus.Status;
        IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
    }

    return IoStatus.Status;
}
Example #29
0
//
//	IRP_MJ_FILE_SYSTEM_CONTROL - is synchronous
//
NTSTATUS DDKAPI VfsFileSystemControl(PDEVICE_OBJECT device, PIRP irp)
{
	NTSTATUS status = STATUS_SUCCESS;
	PIO_STACK_LOCATION stack_location = NULL;

	ASSERT(device);
	ASSERT(irp);

	FsRtlEnterFileSystem();

	stack_location = IoGetCurrentIrpStackLocation(irp);

	switch (stack_location->MinorFunction) {
	case IRP_MN_MOUNT_VOLUME:
		status = VfsMountVolume(irp, stack_location);
		LklCompleteRequest(irp, status);
		break;
	case IRP_MN_USER_FS_REQUEST:
		status = VfsUserFileSystemRequest(irp, stack_location);
		LklCompleteRequest(irp, status);
		break;
	case IRP_MN_VERIFY_VOLUME:
		status = VfsVerifyVolume(irp, stack_location);
		LklCompleteRequest(irp, status);
		break;
	case IRP_MN_LOAD_FILE_SYSTEM:
	case IRP_MN_KERNEL_CALL:
	    LklCompleteRequest(irp, STATUS_NOT_IMPLEMENTED);
		break;
	default:
		LklCompleteRequest(irp, STATUS_INVALID_DEVICE_REQUEST);
		break;
	}

	FsRtlExitFileSystem();

	return status;
}
Example #30
0
VOID
FFSDeQueueRequest(
	IN PVOID Context)
{
	PFFS_IRP_CONTEXT IrpContext;

	IrpContext = (PFFS_IRP_CONTEXT) Context;

	ASSERT(IrpContext);

	ASSERT((IrpContext->Identifier.Type == FFSICX) &&
			(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));

	__try
	{
		__try
		{
			FsRtlEnterFileSystem();

			if (!IrpContext->IsTopLevel)
			{
				IoSetTopLevelIrp((PIRP) FSRTL_FSP_TOP_LEVEL_IRP);
			}

			FFSDispatchRequest(IrpContext);
		}
		__except (FFSExceptionFilter(IrpContext, GetExceptionInformation()))
		{
			FFSExceptionHandler(IrpContext);
		}
	}
	__finally
	{
		IoSetTopLevelIrp(NULL);

		FsRtlExitFileSystem();
	}
}