我正在 Linux、macOS 和 Windows 上使用 Posix stat()
函数,想在不同的设备上尝试一下,看看结果。支持某些类型,例如Windows 上不存在套接字和 FIFO,但我想至少检查 block 设备和字符设备。我发现 AUX
(以及其他一些类似的设备)是字符设备,但是我找不到默认情况下在 Windows 上可用的任何 block 设备。有人可以举个例子吗?
最佳答案
Windows 不是 POSIX 操作系统,不支持 stat
。它具有类似的功能,_stat
,它试图模拟该功能。
但是,即使 Windows 确实有 block 设备的概念,在 Windows 实现中也没有 S_IFBLK
( block 设备)标志;如果您查看 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
而失败。
关于c++ - Windows 上的 block 设备示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46768204/