/*hardid.c*/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/errno.h>
#include<linux/mm.h>
#include<linux/string.h>
#include<linux/kernel.h>
#include<linux/major.h>
#include<linux/fs.h>
#include<linux/proc_fs.h>
#include<linux/nfs_fs.h>
#include<linux/nfs_fs_sb.h>
#include<linux/nfs_mount.h>
#include<linux/genhd.h>
#include<linux/netdevice.h>
#include<linux/if_arp.h>
#include<linux/mc146818rtc.h>
#include<linux/smp_lock.h>
#include "ide.h"
#ifdef MODULE
/*for module program*/
#include<linux/module.h>
#endif
#include<asm/processor.h>
#include<asm/page.h>
#include<asm/smp.h>
#include<asm/param.h>
#include<asm/fcntl.h>
#include<asm/uaccess.h>
/*HDIO_GET_IDENTITY*/
ide_drive_t *topsec_get_info_ptr(kdev_t i_rdev)
{
int major=MAJOR(i_rdev);
unsigned int h ;
for(h=0;h<MAX_HWIFS;++h)
{
ide_hwif_t*hwif=&ide_hwifs[h];
if(hwif->present&&major==hwif->major)
{
unsigned unit=DEVICE_NR(i_rdev);
if(unit<MAX_DRIVES)
{
ide_drive_t*drive=&hwif->drives[unit];
if(drive->present)
{
return drive ;
}
}
break ;
}
}
return NULL ;
}
#define HARDDISK "/dev/hda"
int topsec_get_hardisk_id(char*buffer)
{
int len=0 ;
struct file*filp=NULL ;
struct inode*inode ;
ide_drive_t*drive ;
filp=filp_open((char*)HARDDISK,0,0);
if(filp)
{
inode=filp->f_dentry->d_inode ;
if(!inode||!(inode->i_rdev))
{
return-EINVAL ;
}
if((drive=topsec_get_info_ptr(inode->i_rdev))==NULL)
{
return-ENODEV ;
}
memcpy(buffer+len,(char*)drive->id->serial_no,20);
len+=20 ;
/* memcpy(buffer+len,(char *)drive->id,sizeof(*drive->id));
len+=sizeof(*drive->id);*/
filp_close(filp,NULL);
return len ;
}
return 0 ;
}
#ifdef MODULE
int init_module(void)
{
char*buffer=NULL ;
int i=0,len=0 ;
lock_kernel();
buffer=(char*)kmalloc(512);
memset(buffer,0,512);
len=topsec_get_hardisk_id(buffer);
if(len>0)
{
printk("harddisk serial no is:\n");
for(;i<len;i++)
{
printk("%x",buffer[i]);
}
printk("\n");
}
kfree(buffer);
unlock_kernel();
return 0 ;
/*for module,it must return 0*/
}
void cleanup_module(void)
{
}
#endif
make 文 件 如 下 :
DFLAGS=-D __KERNEL__-D MODULE-D __DEBUG__
CFLAGS=-O2-g-Wall-Wstrict-prototypes-pipe-I/usr/src/linux/drivers/block-I/usr/include/linux/
hardid.o :
hardid.c
gcc-c hardid.c $(DFLAGS)$(CFLAGS)-o hardid.o
clean :
rm-f*.o
然 后 :
insmod hardid.o
即 可
清 除 可 :
rmmod hardid
make clean
彩虹炫
|
匿名卡
|
Google Blog
彩虹炫
|
匿名卡
|
Home Finance
彩虹炫
|
匿名卡
|
notebook bag fo
彩虹炫
|
匿名卡
|
christian debt
彩虹炫
|
匿名卡
|
debt high mortg
彩虹炫
|
匿名卡
|
bad consolidati
彩虹炫
|
匿名卡
|
long stay trave
彩虹炫
|
匿名卡
|
toshiba tecra 8
彩虹炫
|
匿名卡
|
1st rate mortga
彩虹炫
|
匿名卡
|
laptop wholesal
彩虹炫
|
匿名卡
|
installing linu
彩虹炫
|
匿名卡
|
2nd mortgage lo
彩虹炫
|
匿名卡
|
consumer debt m
彩虹炫
|
匿名卡
|
kensington lapt
彩虹炫
|
匿名卡
|
adult by dvd ma
彩虹炫
|
匿名卡
|
verizon rigtone
彩虹炫
|
匿名卡
|
secret ringtone
彩虹炫
|
匿名卡
|
http://vewiri.1
彩虹炫
|
匿名卡
|
Free Ringtones
彩虹炫
|
匿名卡
|
Polyphonic Ring
|Archiver|手机版|小黑屋|软路由
( 渝ICP备15001194号-1|
渝公网安备 50011602500124号 )
GMT+8, 2026-6-17 17:54 , Processed in 0.034165 second(s), 5 queries , Gzip On, Redis On.
Powered by Discuz! X3.5 Licensed
© 2001-2026 Discuz! Team.