Windows 上的块设备示例
Example for a block device on Windows
我正在 Linux、macOS 和 Windows 上使用 Posix stat()
功能,想在不同的设备上尝试一下,看看结果.支持某些类型,例如Windows 上不存在套接字和 FIFO,但我想至少检查块设备和字符设备。我发现 AUX
(以及其他一些类似的)是字符设备,但是我找不到默认情况下在 Windows 上可用的任何块设备。有人可以举个例子吗?
Windows,不是 POSIX OS,不支持 stat
。它有一个类似的功能,_stat
,试图模拟功能。
然而,尽管 Windows 确实有块设备的概念,但在 Windows 实现中没有 S_IFBLK
(块设备)标志;如果您查看 stat.h
,您会看到仅支持以下模式标志:
#define _S_IFMT 0xF000 // File type mask
#define _S_IFDIR 0x4000 // Directory
#define _S_IFCHR 0x2000 // Character special
#define _S_IFIFO 0x1000 // Pipe
#define _S_IFREG 0x8000 // Regular
#define _S_IREAD 0x0100 // Read permission, owner
#define _S_IWRITE 0x0080 // Write permission, owner
#define _S_IEXEC 0x0040 // Execute/search permission, owner
由此可以得出结论,你问的是不可能的。
确实,_stat("C:")
失败并显示 ENOENT
,_stat("\\.\C:")
失败并显示 EINVAL
。
我正在 Linux、macOS 和 Windows 上使用 Posix stat()
功能,想在不同的设备上尝试一下,看看结果.支持某些类型,例如Windows 上不存在套接字和 FIFO,但我想至少检查块设备和字符设备。我发现 AUX
(以及其他一些类似的)是字符设备,但是我找不到默认情况下在 Windows 上可用的任何块设备。有人可以举个例子吗?
Windows,不是 POSIX OS,不支持 stat
。它有一个类似的功能,_stat
,试图模拟功能。
然而,尽管 Windows 确实有块设备的概念,但在 Windows 实现中没有 S_IFBLK
(块设备)标志;如果您查看 stat.h
,您会看到仅支持以下模式标志:
#define _S_IFMT 0xF000 // File type mask
#define _S_IFDIR 0x4000 // Directory
#define _S_IFCHR 0x2000 // Character special
#define _S_IFIFO 0x1000 // Pipe
#define _S_IFREG 0x8000 // Regular
#define _S_IREAD 0x0100 // Read permission, owner
#define _S_IWRITE 0x0080 // Write permission, owner
#define _S_IEXEC 0x0040 // Execute/search permission, owner
由此可以得出结论,你问的是不可能的。
确实,_stat("C:")
失败并显示 ENOENT
,_stat("\\.\C:")
失败并显示 EINVAL
。