Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
VOID
NTAPI
NpCancelDataQueueIrp(IN PDEVICE_OBJECT DeviceObject,
                     IN PIRP Irp)
{
    PNP_DATA_QUEUE DataQueue;
    PNP_DATA_QUEUE_ENTRY DataEntry;
    LIST_ENTRY DeferredList;
    PSECURITY_CLIENT_CONTEXT ClientSecurityContext;
    BOOLEAN CompleteWrites, FirstEntry;

    if (DeviceObject) IoReleaseCancelSpinLock(Irp->CancelIrql);

    InitializeListHead(&DeferredList);

    DataQueue = Irp->Tail.Overlay.DriverContext[2];
    ClientSecurityContext = NULL;

    if (DeviceObject)
    {
        FsRtlEnterFileSystem();
        NpAcquireExclusiveVcb();
    }

    DataEntry = Irp->Tail.Overlay.DriverContext[3];
    if (DataEntry)
    {
        if (DataEntry->QueueEntry.Blink == &DataQueue->Queue)
        {
            DataQueue->ByteOffset = 0;
            FirstEntry = TRUE;
        }
        else
        {
            FirstEntry = FALSE;
        }

        RemoveEntryList(&DataEntry->QueueEntry);

        ClientSecurityContext = DataEntry->ClientSecurityContext;

        CompleteWrites = TRUE;
        if (DataQueue->QueueState != WriteEntries ||
            DataQueue->QuotaUsed < DataQueue->Quota ||
            !DataEntry->QuotaInEntry)
        {
            CompleteWrites = FALSE;
        }

        DataQueue->BytesInQueue -= DataEntry->DataSize;
        DataQueue->QuotaUsed -= DataEntry->QuotaInEntry;
        --DataQueue->EntriesInQueue;

        if (IsListEmpty(&DataQueue->Queue))
        {
            DataQueue->QueueState = Empty;
            ASSERT(DataQueue->BytesInQueue == 0);
            ASSERT(DataQueue->EntriesInQueue == 0);
            ASSERT(DataQueue->QuotaUsed == 0);
        }
        else
        {
            if (FirstEntry)
            {
                NpGetNextRealDataQueueEntry(DataQueue, &DeferredList);
            }
            if (CompleteWrites)
            {
                NpCompleteStalledWrites(DataQueue, &DeferredList);
            }
        }
    }

    if (DeviceObject)
    {
        NpReleaseVcb();
        FsRtlExitFileSystem();
    }

    if (DataEntry) ExFreePool(DataEntry);

    NpFreeClientSecurityContext(ClientSecurityContext);
    Irp->IoStatus.Status = STATUS_CANCELLED;
    IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);

    NpCompleteDeferredIrps(&DeferredList);
}