公告
财富商城
积分规则
提问
发文
2019-04-13 00:40发布
混吃等死
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 <hdreg.h>"
ioctl HDIO_GET_IDENTITY
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("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); } }
最多设置5个标签!
"#include <hdreg.h>"
and useioctl HDIO_GET_IDENTITY
to obtain astruct hd_driveid
.On this structure, the
x->sector_bytes
field is the sector size.