获取硬盘信息
时间:2006-07-21 来源:nahuat
#include <stdio.h>
#include <fcntl.h>
#include <linux/hdreg.h>
int
main(void)
{
int fd, rc;
struct hd_driveid info;
if ((fd = open("/dev/hda", O_RDONLY)) < 0)
{
perror("/dev/hda");
return 1;
}
memset(&info, 0, sizeof(info));
rc = ioctl(fd, HDIO_GET_IDENTITY, &info);
close(fd);
if (rc < 0)
{
perror("HDIO_GET_IDENTITY");
return 2;
}
printf("model '%s'\nserial: '%s'\n", info.model, info.serial_no);
return 0;
}
#include <fcntl.h>
#include <linux/hdreg.h>
int
main(void)
{
int fd, rc;
struct hd_driveid info;
if ((fd = open("/dev/hda", O_RDONLY)) < 0)
{
perror("/dev/hda");
return 1;
}
memset(&info, 0, sizeof(info));
rc = ioctl(fd, HDIO_GET_IDENTITY, &info);
close(fd);
if (rc < 0)
{
perror("HDIO_GET_IDENTITY");
return 2;
}
printf("model '%s'\nserial: '%s'\n", info.model, info.serial_no);
return 0;
}
|
相关阅读 更多 +