?????????????????????????д?????????????????????????????????????????????????????????????????????????????μ????????????????????????????????????????????????????С????????????????????????????????????????????е??????????

????4.1 printk

????printk????????????????????????????????????????????dmesg??????????????????????????????/var/log/kernel ?????????????????log????kernel module?е???printk?????????????????????????printk????????÷??????????μ?printf????????????????? KERN_INFO????????0-7??????????log?????????????÷?????£?

????char myname[] = "chinacodec ";

????printk(KERN_INFO "Hello?? world %s! "?? myname);

????4.2 α????豸

??????linux?У???????豸??????????????????????????????????????????????????????α????豸??????????????????????????????????????????ж??α?豸??open/read/write /ioctl/mmap/release??????????Щ????????????????????????????????????????????????????????????????????????KAPI???????

???????巽????????????kernel module?????register_chrdev??????α????豸?????????????????豸??major???????????????豸?????;?豸??????name;?????????????fops??register_chrdev????????£?

????int register_chrdev(unsigned int major?? const char *name?? struct file_operations *fops);

???????У???file_operations?а??????е???????????????????(????read/write/open??)??????У??????????μ??????(??????????????????)????Щδ????????????????null??

static struct file_operations fops = {
.read = device_read??
.write = device_write??
.ioctl = device_ioctl??
.open = device_open??
.release = device_release
};
????register_chrdev?????kernel module?е?init????????У???insmod???module????豸?????????С??????????????mknod???????????????????豸???????????open/write/read/ioctl/mmap/release??????????????豸???????????????豸?????????????е???????豸???????????????????????????????register_chrdev???????ж???α?豸?????????? unregister_chrdev??

??????ioctl??????????????file_operations?????α????豸?????????α?豸??????ioctl??????????????????? device_ioctl?????????????????????device_ioctl???????????KAPI???????????????KAPI??????

????4.3 ????????д

?????????У???????????????????????????????????????????????????????д???????д????????????????????????????????????????????????????????????£?????????з??????ú??????????μ??????????????????????÷????????filp_open????????????????????????????????????????????д??????????????????£?

tmp _filp = filp_open(dst_file_name?? O_RDWR | O_CREAT?? 00);
tmp _copied = dst_filp->f_op->write(tmp_filep?? buffer?? size?? offset);
tmp _len = dst_filp->f_op->read(tmp _filep?? buffer?? size?? offset);
???????????????ж???????????????????????????ж??????????????????飬?????????????Χ??????????read??write????????set_fs?????????????????????setfs???????????????Χ?????巽?????

orig_fs = get_fs();
set_fs(KERNEL_DS);
//write or read
set_fs(orig_fs);
????4.4 Proc?????

????proc????????????????????飬??????????????????????????????????????????/proc?£??????????????д????????????????????????????飬??????/proc??????μ??????????????д??????????????;?????????????д???????????????????????????????????????????й??????