示例#1
0
NTSTATUS
NTAPI
NpCreateRootDcb(VOID)
{
    PNP_DCB Dcb;
    PAGED_CODE();

    if (NpVcb->RootDcb)
    {
        NpBugCheck(0, 0, 0);
    }

    NpVcb->RootDcb = ExAllocatePoolWithTag(PagedPool, sizeof(*Dcb), NPFS_DCB_TAG);
    if (!NpVcb->RootDcb)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    Dcb = NpVcb->RootDcb;
    RtlZeroMemory(Dcb, sizeof(*Dcb));
    Dcb->NodeType = NPFS_NTC_ROOT_DCB;

    InitializeListHead(&Dcb->DcbEntry);
    InitializeListHead(&Dcb->NotifyList);
    InitializeListHead(&Dcb->NotifyList2);
    InitializeListHead(&Dcb->FcbList);

    Dcb->FullName.Buffer = NpRootDCBName;
    Dcb->FullName.Length = 2;
    Dcb->FullName.MaximumLength = 4;

    Dcb->ShortName.Length = Dcb->FullName.Length;
    Dcb->ShortName.MaximumLength = Dcb->FullName.MaximumLength;
    Dcb->ShortName.Buffer = Dcb->FullName.Buffer;

    if (!RtlInsertUnicodePrefix(&NpVcb->PrefixTable,
                                &Dcb->FullName,
                                &Dcb->PrefixTableEntry))
    {
        NpBugCheck(0, 0, 0);
    }

    return STATUS_SUCCESS;
}
示例#2
0
NTSTATUS
NTAPI
NpCreateFcb(IN PNP_DCB Dcb,
            IN PUNICODE_STRING PipeName,
            IN ULONG MaximumInstances,
            IN LARGE_INTEGER Timeout,
            IN USHORT NamedPipeConfiguration,
            IN USHORT NamedPipeType,
            OUT PNP_FCB *NewFcb)
{
    PNP_FCB Fcb;
    BOOLEAN RootPipe;
    PWCHAR NameBuffer;
    ULONG BufferOffset;
    USHORT Length, MaximumLength;
    PAGED_CODE();

    Length = PipeName->Length;
    MaximumLength = Length + sizeof(UNICODE_NULL);

    if ((Length < sizeof(WCHAR)) || (MaximumLength < Length))
    {
        return STATUS_INVALID_PARAMETER;
    }

    RootPipe = FALSE;
    if (PipeName->Buffer[0] != OBJ_NAME_PATH_SEPARATOR)
    {
        MaximumLength += sizeof(OBJ_NAME_PATH_SEPARATOR);
        RootPipe = TRUE;
        if (MaximumLength < sizeof(WCHAR))
        {
            return STATUS_INVALID_PARAMETER;
        }
    }

    Fcb = ExAllocatePoolWithTag(PagedPool, sizeof(*Fcb), NPFS_FCB_TAG);
    if (!Fcb) return STATUS_INSUFFICIENT_RESOURCES;

    RtlZeroMemory(Fcb, sizeof(*Fcb));
    Fcb->MaximumInstances = MaximumInstances;
    Fcb->Timeout = Timeout;
    Fcb->NodeType = NPFS_NTC_FCB;
    Fcb->ParentDcb = Dcb;
    InitializeListHead(&Fcb->CcbList);

    NameBuffer = ExAllocatePoolWithTag(PagedPool,
                                       MaximumLength,
                                       NPFS_NAME_BLOCK_TAG);
    if (!NameBuffer)
    {
        ExFreePool(Fcb);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    InsertTailList(&Dcb->FcbList, &Fcb->DcbEntry);

    BufferOffset = 0;
    if (RootPipe)
    {
        NameBuffer[0] = OBJ_NAME_PATH_SEPARATOR;
        BufferOffset = 1;
    }

    RtlCopyMemory(NameBuffer + BufferOffset, PipeName->Buffer, Length);
    NameBuffer[BufferOffset + (Length / sizeof(WCHAR))] = UNICODE_NULL;

    Fcb->FullName.Length = Length;
    Fcb->FullName.MaximumLength = MaximumLength;
    Fcb->FullName.Buffer = NameBuffer;

    Fcb->ShortName.MaximumLength = Length;
    Fcb->ShortName.Length = Length - sizeof(OBJ_NAME_PATH_SEPARATOR);
    Fcb->ShortName.Buffer = NameBuffer + 1;

    if (!RtlInsertUnicodePrefix(&NpVcb->PrefixTable,
                                &Fcb->FullName,
                                &Fcb->PrefixTableEntry))
    {
        NpBugCheck(0, 0, 0);
    }

    Fcb->NamedPipeConfiguration = NamedPipeConfiguration;
    Fcb->NamedPipeType = NamedPipeType;
    *NewFcb = Fcb;
    return STATUS_SUCCESS;
}
示例#3
0
PFCB
MsCreateFcb (
    IN PVCB Vcb,
    IN PDCB ParentDcb,
    IN PUNICODE_STRING FileName,
    IN PEPROCESS CreatorProcess,
    IN ULONG MailslotQuota,
    IN ULONG MaximumMessageSize
    )

/*++

Routine Description:

    This routine allocates, initializes, and inserts a new Fcb record into
    the in memory data structures.

Arguments:

    Vcb - Supplies the Vcb to associate the new FCB under.

    ParentDcb - Supplies the parent dcb that the new FCB is under.

    FileName - Supplies the file name of the file relative to the directory
        it's in (e.g., the file \config.sys is called "CONFIG.SYS" without
        the preceding backslash).

    CreatorProcess - Supplies a pointer to our creator process

    MailslotQuota - Supplies the initial quota

    MaximumMessageSize - Supplies the size of the largest message that
        can be written to the mailslot

Return Value:

    PFCB - Returns a pointer to the newly allocated FCB

--*/

{
    PFCB fcb;

    PAGED_CODE();
    DebugTrace(+1, Dbg, "MsCreateFcb\n", 0);

    //
    // Allocate a new FCB record, and zero its fields.
    //

    fcb = FsRtlAllocatePool( NonPagedPool, sizeof(FCB) );
    RtlZeroMemory( fcb, sizeof(FCB) );

    //
    // Set the proper node type code, node byte size, and reference count.
    //

    fcb->Header.NodeTypeCode = MSFS_NTC_FCB;
    fcb->Header.NodeByteSize = sizeof(FCB);
    fcb->Header.ReferenceCount = 1;
    fcb->Header.NodeState = NodeStateActive;

    //
    // Insert this FCB into our parent DCB's queue.
    //

    InsertTailList( &ParentDcb->Specific.Dcb.ParentDcbQueue,
                    &fcb->ParentDcbLinks );

    //
    // Initialize other FCB fields.
    //

    fcb->ParentDcb = ParentDcb;
    fcb->Vcb = Vcb;

    MsAcquireGlobalLock();
    MsReferenceNode ( &Vcb->Header );
    if (Vcb->Header.ReferenceCount == 2) {
        //
        // Set the driver paging back to normal
        //
        MmResetDriverPaging(MsCreateFcb);
    }
    MsReleaseGlobalLock();

    fcb->CreatorProcess =  CreatorProcess;
    ExInitializeResource( &(fcb->Resource) );

    //
    // Initialize the CCB queue.
    //

    InitializeListHead( &fcb->Specific.Fcb.CcbQueue );

    //
    // Set the file name.
    //

    {
        PWCH Name;
        ULONG Length;

        Length = FileName->Length;

        Name = FsRtlAllocatePool( PagedPool, Length + 2 );

        RtlMoveMemory( Name, FileName->Buffer, Length );
        *(PWCH)( (PCH)Name + Length ) = L'\0';

        RtlInitUnicodeString( &fcb->FullFileName, Name );
        RtlInitUnicodeString( &fcb->LastFileName, &Name[1] );
    }

    //
    // Insert this FCB into the prefix table.
    //

    MsAcquirePrefixTableLock();
    if (!RtlInsertUnicodePrefix( &Vcb->PrefixTable,
                                 &fcb->FullFileName,
                                 &fcb->PrefixTableEntry )) {

        DebugDump("Error trying to name into prefix table\n", 0, fcb);
        KeBugCheck( MAILSLOT_FILE_SYSTEM );
    }
    MsReleasePrefixTableLock();

    //
    // Initialize the data queue.
    //

    MsInitializeDataQueue( &fcb->DataQueue,
                           CreatorProcess,
                           MailslotQuota,
                           MaximumMessageSize);

    //
    // Return to the caller.
    //

    DebugTrace(-1, Dbg, "MsCreateFcb -> %08lx\n", (ULONG)fcb);

    return fcb;
}
示例#4
0
PROOT_DCB
MsCreateRootDcb (
    IN PVCB Vcb
    )

/*++

Routine Description:

    This routine allocates, initializes, and inserts a new root DCB record
    into the in memory data structure.

Arguments:

    Vcb - Supplies the Vcb to associate the new DCB under

Return Value:

    PROOT_DCB - returns pointer to the newly allocated root DCB.

--*/

{
    PROOT_DCB rootDcb;

    PAGED_CODE();
    DebugTrace(+1, Dbg, "MsCreateRootDcb, Vcb = %08lx\n", (ULONG)Vcb);

    //
    // Make sure we don't already have a root dcb for this vcb
    //

    rootDcb = Vcb->RootDcb;

    if (rootDcb != NULL) {
        DebugDump("Error trying to create multiple root dcbs\n", 0, Vcb);
        KeBugCheck( MAILSLOT_FILE_SYSTEM );
    }

    //
    // Allocate a new DCB and zero its fields.
    //

    rootDcb = FsRtlAllocatePool( NonPagedPool, sizeof(DCB) );
    RtlZeroMemory( rootDcb, sizeof(DCB));

    //
    // Set the proper node type code, node byte size, and reference count.
    //

    rootDcb->Header.NodeTypeCode = MSFS_NTC_ROOT_DCB;
    rootDcb->Header.NodeByteSize = sizeof(ROOT_DCB);
    rootDcb->Header.ReferenceCount = 1;
    rootDcb->Header.NodeState = NodeStateActive;

    //
    // The root Dcb has an empty parent dcb links field
    //

    InitializeListHead( &rootDcb->ParentDcbLinks );

    //
    // Set the Vcb and give it a pointer to the new root DCB.
    //

    rootDcb->Vcb = Vcb;
    Vcb->RootDcb = rootDcb;

    //
    // Initialize the notify queues, and the parent dcb queue.
    //

    InitializeListHead( &rootDcb->Specific.Dcb.NotifyFullQueue );
    InitializeListHead( &rootDcb->Specific.Dcb.NotifyPartialQueue );
    InitializeListHead( &rootDcb->Specific.Dcb.ParentDcbQueue );

    //
    // Set the full file name
    //

    {
        PWCH Name;

        Name = FsRtlAllocatePool(PagedPool, 2 * sizeof(WCHAR));

        Name[0] = L'\\';
        Name[1] = L'\0';

        RtlInitUnicodeString( &rootDcb->FullFileName, Name );
        RtlInitUnicodeString( &rootDcb->LastFileName, Name );
    }

    //
    // Insert this DCB into the prefix table.
    //

    MsAcquirePrefixTableLock();
    if (!RtlInsertUnicodePrefix( &Vcb->PrefixTable,
                                 &rootDcb->FullFileName,
                                 &rootDcb->PrefixTableEntry )) {

        DebugDump("Error trying to insert root dcb into prefix table\n", 0, Vcb);
        KeBugCheck( MAILSLOT_FILE_SYSTEM );
    }

    MsReleasePrefixTableLock();


    //
    // Initialize the resource variable.
    //

    ExInitializeResource( &(rootDcb->Resource) );

    //
    // Return to the caller.
    //

    DebugTrace(-1, Dbg, "MsCreateRootDcb -> %8lx\n", (ULONG)rootDcb);

    return rootDcb;
}