j_k*_*bik 5 linux block-device
我试图在Linux中用C++获取块设备的一些信息(特别是块大小).是否可以在不安装设备的情况下获得设备的块大小,并且可能无需查看动态文件(如中的那些/sys),但仅限系统调用.
我正在尝试stat,但/dev如果我问的话,它会返回有关文件系统的数据/dev/sdb2.
如果系统调用不可能,我应该在哪里查看动态文件(也无法找到它.)
ioctl特别是你想要使用BLKSSZGET.
引用linux/fs.h:
#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
Run Code Online (Sandbox Code Playgroud)
未经测试的例子:
#include <sys/ioctl.h>
#include <linux/fs.h>
int fd = open("/dev/sda");
size_t blockSize;
int rc = ioctl(fd, BLKSSZGET, &blockSize);
Run Code Online (Sandbox Code Playgroud)