ºìÁªLinuxÃÅ»§
Linux°ïÖú

Fedora 7ϱàÒë linuxÉ豸Çý¶¯3ed scullÄ£¿é

·¢²¼Ê±¼ä:2007-08-17 00:09:58À´Ô´:ºìÁª×÷Õß:hearer
Linux Device Driver(ldd) ÊDZ¾Äں˿ª·¢ÈëÃÅÊé¼®.ÆäÖÐscullÊǵÚÒ»¸öÀý×ÓÄ£¿é.ËùÒÔѧϰscullÊǺÜÖØÒªµÄ.ÓÉÓÚÄں˿ª·¢±ä¶¯½Ï¿ì.ËùÒÔlddÊéÖеÄһЩÀý×ÓÒѾ­²»ÄÜÔÚÏÖÓпª·¢»·¾³ÖбàÒëÁË.±¾ÎÄ˵Ã÷ÈçºÎÔÚfedora7ƽ̨ÐÞ¸Äscull³ÌÐò,ʹËûÄܹ»Ë³Àû±àÒë.
Fedora °²×°Ê±Ã»ÓÐÄں˿ª·¢µÄ²¿·Ö.ËùÒÔÎÒÃÇÏÈÒª°²×°Äں˿ª·¢Ïà¹Ø°ü.

1ÔÚfedoar¹Ù·½Õ¾µãµÄftpÖÐÏÂÔغÍÄã×Ô¼ºÄں˰汾ÏàͬµÄÔ´´úÂëºÍdevel°ü
±ÈÈçÎÒͨ¹ýuname -rÃüÁî¿´µ½ÎÒµÄÄں˰汾ÊÇ2.6.22.1-41.fc7
ÓÚÊǾÍÏÂÔØ
kernel-devel-2.6.22.1-41.fc7
kernel-2.6.21-1.3194.fc7.src.rpm
È»ºó°²×°ÕâÁ½¸ö°ü.kernel-devel¿ÉÒÔÖ±½Ó°²×°.Èç¹ûҪװsrcµÄ»°»¹ÒªrpmbuildÒ»ÏÂ.°Ñ²¹¶¡´ò½øÈ¥.¾ßÌå·½·¨ÍøÉÏÓкܶà¹ØÓÚÄں˱àÒëµÄÎÄÕÂ.

2.ÏÂÔØlddµÚÈý°æµÄÔ´´úÂë
http://examples.oreilly.com/linuxdrive3/examples.tar.gz
½Ó×Å°ÑËü½âѹËõ tar zxvf examples.tar.gz
½øÈëscullĿ¼
ÎÒÃÇ¿ÉÒÔ¿´µ½ÓÐmain.cÎļþ
´ò¿ªËû.ɾ³ýincludeÖеÄlinux/config.h ÓÉÓÚÔÚ2.6.19°æ±¾ÒÔºóconfig.hÎļþ±»È¡ÏûÁË.ËùÒÔÒÔºóÓÐconfig.hµÄµØ·½¶¼»á±¨´í
½ÓÏÂÀ´ÔÙmake,»¹ÊÇÓдí.·¢ÏÖÊÇif (! capable (CAP_SYS_ADMIN))ÕâÀï.CAP_SYS_ADMINÕÒ²»µ½.ÔÚÍøÉϲéÒ»ÏÂ,·¢ÏÖÕâ¸öºêÊǶ¨ÒåÔÚlinux/capability.hÖеÄ
ÓÚÊǼÓ#include
ÔÙ±àÒ뻹ÊDz»Í¨¹ý.Ô­Òò»¹ÊÇÓкêûÓж¨Òå.²»¹ýÕâ´ÎÊÇÔÚaccess.cÖÐ.
¸ù¾Ý䶨ÒåµÄºê²éÕÒ.·¢ÏÖËûÃÇÔÚinux/capability.hºÍsched.h.Á½¸öÎļþÖÐ

ÔÚaccess.cÖмÓÈë
#include
#include
¸ÄÕýÁËÕâЩÒÔºó
make»Ø³µ

ÏÂÃæÊÇÊä³ö
make -C /lib/modules/2.6.22.1-41.fc7/build M=/home/hide1713/Desktop/kernel/examples/scull LDDINC=/home/hide1713/Desktop/kernel/examples/scull/../include modules
make[1]: Entering directory `/usr/src/kernels/2.6.22.1-41.fc7-i686'
CC [M] /home/hide1713/Desktop/kernel/examples/scull/access.o
LD [M] /home/hide1713/Desktop/kernel/examples/scull/scull.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/hide1713/Desktop/kernel/examples/scull/scull.mod.o
LD [M] /home/hide1713/Desktop/kernel/examples/scull/scull.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.22.1-41.fc7-i686'

¿´µ½ÕâÑù¾ÍÊDZàÒëºÃÁË.

ÎÒÃÇÓÃchmod +x scull_load scull_unload °ÑÕâÁ©¸ö½Å±¾±äΪ¿ÉÖ´ÐÐ
./scull_load
/sbin/lsmod
ÔõôÑù.˳Àû×°ÈëÄÚºËÁË°É.ÉÏÃæµÄÄÚÈÝÊÇÎÒƾ¼ÇÒäдµÄ.Èç¹ûºÍʵ¼ÊÇé¿öÓгöÈëÇ뻹ÊÇ°´ÕÕÉÏÃæµÄ·½·¨.ÏȲîÊÇÄĸö¶¨ÒåÒýÆðµÄ.ÔٰѶÔÓ¦µÄÍ·Îļþ¼ÓÈë¾ÍÐÐÁË
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. kkk215215 ÓÚ 2008-01-08 20:06:15·¢±í:

    ¶àлLZÁË£¬ÕýºÃÐèÒªÄØ¡£
    ÀÏ°æ±¾Óø߰汾±àÒ룬ÎÊÌâ¶à¶à°¢