在我的微型过滤器的PostCreate期间,必须使用全局推锁来按设计同步线程,并且必须调用FltQueryInformationFile来查询文件大小。

然而,

1,在我调用FltAcquirePushLockExclusive之后,禁用了APC传递;

2,如果禁用了APC传递,则FltQueryInformationFile将失败,因为必须在PASSIVE_LEVEL处调用它并启用APC。

在这种情况下,应如何查询文件大小?建立IRP有帮助吗?

提前致谢。

最佳答案

您可以使用它来获取文件大小

NTSTATUS
GetFileSize (
    _In_ PFLT_INSTANCE Instance,
    _In_ PFILE_OBJECT FileObject,
    _Out_ PLONGLONG Size
    )
/*++

Routine Description:

    This routine obtains the size.

Arguments:

    Instance - Opaque filter pointer for the caller. This parameter is required and cannot be NULL.

    FileObject - File object pointer for the file. This parameter is required and cannot be NULL.

    Size - Pointer to a LONGLONG indicating the file size. This is the output.

Return Value:

    Returns statuses forwarded from FltQueryInformationFile.

--*/
{
    NTSTATUS status = STATUS_SUCCESS;
    FILE_STANDARD_INFORMATION standardInfo;

    //
    //  Querying for FileStandardInformation gives you the offset of EOF.
    //

    status = FltQueryInformationFile( Instance,
                                      FileObject,
                                      &standardInfo,
                                      sizeof(FILE_STANDARD_INFORMATION),
                                      FileStandardInformation,
                                      NULL );

    if (NT_SUCCESS( status )) {

        *Size = standardInfo.EndOfFile.QuadPart;
    }

    return status;
}

关于kernel - 禁用APC时如何查询文件大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14176550/

10-10 03:32