Cygwin:打开角色设备

时间:2015-05-18 12:28:18

标签: cygwin

我需要使用userland程序打开在Windows中创建的内核模块 用Cygwin编译;从Windows我可以使用

打开它
CreateFile("\\\\.\\deviceName",
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_ALWAYS,
    FILE_ATTRIBUTE_NORMAL,
    NULL)

但是在Cygwin中,如果我尝试使用

open("//deviceName", O_RDWR);
没有任何反应;我试过使用“\ DosDevices \ deviceName”,// deviceName, // DosDevices / deviceName等....但我无法打开设备。

有一种方法可以在Cygwin中执行此操作,或者我必须在中使用CreateFile 用户地申请?

编辑: 内核模块中的FYI在正确调用IoCreateDevice(....)之后以这种方式创建链接

#define DOS_DEVICE_NAME         L"\\DosDevices\\deviceName"
...
RtlInitUnicodeString( &ntWin32NameString, DOS_DEVICE_NAME );
ntStatus = IoCreateSymbolicLink(&ntWin32NameString, &ntUnicodeString );
....

EDIT2: 使用Sysinternals WinObj我可以正确地看到我的设备 \全球??使用符号链接\ Device \ deviceName

1 个答案:

答案 0 :(得分:2)

好吧,似乎我已经能够找到它:它在

下指定
"/proc/sys/DosDevices/Global/deviceName"

可以用

打开
fd = open("/proc/sys/DosDevices/Global/deviceName", O_RDWR);
相关问题