如何在Linux中查找软盘\CD扇区大小? 如何通过C++代码获得Linux软盘和CD盘的扇区大小?
谢谢大家。如何在Linux中查找软盘\CD扇区大小? 如何通过C++代码获得Linux软盘和CD盘的扇区大小?,c++,linux,size,sector,C++,Linux,Size,Sector,谢谢大家。“#包括”并使用ioctl HDIO\u GET\u IDENTITY获取struct hd\u driveid 在此结构上,x->sector\u bytes字段是扇区大小 #include <stdlib.h> #include <stdio.h> #include <sys/ioctl.h> #include <linux/hdreg.h> #include <fcntl.h> #include <errno.h&
“#包括”
并使用ioctl HDIO\u GET\u IDENTITY
获取struct hd\u driveid
在此结构上,
x->sector\u bytes
字段是扇区大小
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <cctype>
#include <unistd.h>
int main(){
struct hd_driveid id;
char *dev = "/dev/hdb";
int fd;
fd = open(dev, O_RDONLY|O_NONBLOCK);
if(fd < 0) {
perror("cannot open");
}
if (ioctl(fd, HDIO_GET_IDENTITY, &id) < 0) {
close(fd);
perror("ioctl error");
} else {
close(fd);
printf("Sector size: %du\n", id.sector_bytes);
}
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(){
结构hd_驱动器id;
char*dev=“/dev/hdb”;
int-fd;
fd=打开(开发,仅O|U非块);
如果(fd<0){
perror(“无法打开”);
}
if(ioctl(fd、HDIO\u GET\u IDENTITY和id)<0){
关闭(fd);
perror(“ioctl错误”);
}否则{
关闭(fd);
printf(“扇区大小:%du\n”,id.Sector\u字节);
}
}
非常感谢。一个问题,为什么公开赛需要O_非阻塞标志?嘿,@clyfe,它不起作用。。。ioctl总是返回一个错误。