简体   繁体   中英

Example for a block device on Windows

I'm playing with the Posix stat() function on Linux, macOS and Windows and want to try it out with different devices, to see the outcome. Support for certain types, eg sockets and FIFOs is non-existent on Windows, but I'd like to check at least block and character devices. I found AUX (and a few others like that) to be character devices, however I cannot find any block device that's available on Windows by default. Can someone please suggest an example?

Windows, not being a POSIX OS, does not support stat . It has a similar function, _stat , which attempts to emulate the functionality.

However, even though Windows does have a notion of a block device, there is no S_IFBLK (block device) flag in the Windows implementation; if you look in stat.h you'll see that only the following mode flags are supported:

#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

From this it can be concluded that what you're asking is impossible.

Indeed, _stat("C:") fails with ENOENT and _stat("\\\\\\\\.\\\\C:") fails with EINVAL .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM