kernel - APC禁用时如何查询文件大小?

标签 kernel drivers wdk minifilter windows-kernel

在我的微过滤器的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/

相关文章:

linux - 到达 fops 内部的 "write"和 "ioctl"

ubuntu - "Invalid module format"插入自定义 Linux 内核模块时

c++ - 为 Windows 7 编译 Windows 8 微过滤器驱动程序

c++ - 什么 typedef BOOL (WINAPI *FN_SetupDiGetDeviceProperty)?

linux - 如何使kill命令更快

python - 无法在 jupyter notebook 上启动内核

android - 写安卓驱动?

odbc - Foxpro 是否有新的 ODBC 选项?

installation - android-sdks/build-tools/17.0.0/aapt : error while loading shared libraries: libz. so.1:无法打开共享对象文件:没有这样的文件或目录

c# - 如何在 Windows 中打开/关闭 radio ?