这是网上的一段例子:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/hdreg.h>
#include <sys/ioctl.h>
static void dump_identity (const struct hd_driveid *id)
{
printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s",
id->model, id->fw_rev, id->serial_no);
}
int main(int argc,char **argv)
{
struct hd_driveid id;
char *devname = "/dev/hda";
int fd = -1;
fd = open(devname, O_RDONLY|O_NONBLOCK);
if (fd < 0)
{
perror(devname);
exit(errno);
}
if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
{
dump_identity(&id);
}
close(fd);
return 0;
}