| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5792 人关注过本帖
标题:ioctl() 获得硬盘序列号
只看楼主 加入收藏
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
结帖率:98.63%
收藏
 问题点数:0 回复次数:0 
ioctl() 获得硬盘序列号
程序代码:
#include <linux/types.h>
#include <linux/hdreg.h> 
#include <fcntl.h>
#include <sys/ioctl.h>

int main() {
     int fd,err,i;
     struct hd_driveid hd;  /*这个结构体是关键*/

     if( (fd=open("/dev/sda", O_RDONLY ) ) < 0 )

          perror("Device Open Error");

     if( (err = ioctl(fd,HDIO_GET_IDENTITY,&hd) ) < 0) /*用法很简单*/

          perror("ioctl err");

     else

          printf("Serial No = %s\n",hd.serial_no);

     return (0);
}


用命令
$ sudo hdparm -i /dev/sda

也可以获得
搜索更多相关主题的帖子: 序列号 return include 硬盘 linux 
2012-09-01 11:21
快速回复:ioctl() 获得硬盘序列号
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016847 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved