如何在Linux中找到floppy \ CD扇区大小? [英] How to find floppy\ CD sector size in Linux?
本文介绍了如何在Linux中找到floppy \ CD扇区大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过C ++代码获取Linux中软盘和CD盘的扇区大小?
谢谢大家。
< >
ioctl HDIO_GET_IDENTITY c> / code>获得 struct hd_driveid
。
在此结构上, x-> sector_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(can not open);
}
if(ioctl(fd,HDIO_GET_IDENTITY,& id)< 0){
close(fd);
perror(ioctl error);
} else {
close(fd);
printf(Sector size:%du\\\
,id.sector_bytes);
}
}
How can I get the sector size for floppy and CD disks in Linux, via C++ code?
Thank you all.
解决方案 "#include <hdreg.h>"
and use ioctl HDIO_GET_IDENTITY
to obtain a struct hd_driveid
.
On this structure, the x->sector_bytes
field is the sector size.
#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);
}
}
这篇关于如何在Linux中找到floppy \ CD扇区大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文