打开共享文件时出现问题。 [英] Problem while opening a shared file.
问题描述
您好,对不起基本问题。我需要在内核模式下创建一个用于写访问的文件,并允许其他线程读取它,这可以同时发生。这就是我在创建文件时所做的事情。
Hello, Sorry for the basic question. I need to create a file for write access in kernel mode and and allow other thread to read it, this can happen simultaneously. so This what I do when creating the file.
status = ZwCreateFile(&hfile,
GENERIC_WRITE,
&oa,
&iostatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OVERWRITE_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
}
效果很好,文件创建用于写入,稍后当我尝试创建另一个句柄来阅读它我总是得到STATUS_SHARING_VIOLATION
这是我的工作方式。
works well, the file is created for write and later when I try to create another handle to read it I always get "STATUS_SHARING_VIOLATION"
here is how I do it.
ntstatus = ZwCreateFile(&OriFileHandle,
FILE_READ_DATA,
&objOriAttr,
&ioOriStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE,
NULL,
0);
有谁可以告诉我,我做错了什么?
我尝试了什么:
我已经阅读过关于ZwCreatefile以及如何共享文件以供其他线程访问但我仍然收到该错误。
Can anybody tell me what is it that I am doing wrong?
What I have tried:
I already read about ZwCreatefile and how to share a file for access by other thread but I am still getting that error.
推荐答案
看起来你正在混合访问标志与其他r种标志。另外,你在第二个ZwCreateFile中省略了FILE_SHARE_WRITE。
试试这个:
It looks like you are mixing access flags with other types of flags. Also, you omit FILE_SHARE_WRITE in the second ZwCreateFile.
Try this:
ntstatus = ZwCreateFile(&OriFileHandle,
GENERIC_READ,
&objOriAttr,
&ioOriStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_WRITE,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE, // I've never used these.
NULL,
0);
这篇关于打开共享文件时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!