Çý¶¯³ÌÐòmoduleµÄ¹¤×÷Á÷³ÌÖ÷Òª·ÖΪËĸö²¿·Ö£º
1¡¢ insmod module
2¡¢ Çý¶¯moduleµÄ³õʼ»¯£¨³õʼ»¯½áÊøºó¼´½øÈ롰DZ·ü¡±×´Ì¬£¬Ö±µ½ÓÐϵͳµ÷Óã©
3¡¢ µ±²Ù×÷É豸ʱ£¬¼´ÓÐϵͳµ÷ÓÃʱ£¬µ÷ÓÃÇý¶¯moduleÌṩµÄ¸÷¸ö·þÎñº¯Êý
4¡¢ rmmod module
Ò»¡¢ Çý¶¯³ÌÐòµÄ¼ÓÔØ
LinuxÇý¶¯³ÌÐò·ÖΪÁ½ÖÖÐÎʽ£ºÒ»ÖÖÊÇÖ±½Ó±àÒë½øÄںˣ¬ÁíÒ»ÖÖÊDZàÒë³Émodule£¬È»ºóÔÚÐèÒª¸ÃÇý¶¯moduleʱÊÖ¶¯¼ÓÔØ¡£
ÔÚÓÃinsmod¼ÓÔØmoduleʱ£¬»¹¿ÉÒÔ¸øÌṩģ¿é²ÎÊý£¬È磺
static char *whom=¡±world¡±£»
static int howmany=10;
module_param(howmany,int,S_IRUGO);
module_param(whom,charp,S_IRUGO);
ÕâÑù£¬µ±Ê¹ÓÃinsmod scull.ko whom=¡±string¡± howmany=20ÕâÑùµÄÃüÁî¼ÓÔØÇý¶¯Ê±£¬whomºÍhowmayµÄÖµ¾Í»á´«ÈëscullÇý¶¯Ä£¿éÁË¡£
¶þ¡¢ Çý¶¯moduleµÄ³õʼ»¯
scull_init_moduleº¯ÊýÖÐÖ÷Òª×öÁËÒÔϼ¸¼þÊÂÇ飺
a) ·ÖÅä²¢×¢²áÖ÷É豸ºÅºÍ´ÎÉ豸ºÅ
int register_chrdev_region(dev_t first, unsigned int count, char *name)
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name)
b) ³õʼ»¯´ú±íÉ豸µÄstruct½á¹¹Ì壺scull_dev
c) ³õʼ»¯»¥³âÌåinit_MUTEX
d) ³õʼ»¯ÔÚÄÚºËÖдú±íÉ豸µÄcdev½á¹¹Ì壬×îÖ÷ÒªÊǽ«¸ÃÉ豸Óëfile_operations½á¹¹ÌåÁªÏµÆðÀ´¡£ÔÚLinuxÄÚºËÖУ¬cdev½á¹¹Ìå²ÅÊÇÕæÕý´ú±íÁËij¸öÉ豸¡£ÔÚÄں˵÷ÓÃÉ豸µÄopen£¬readµÈ²Ù×÷֮ǰ£¬±ØÐëÏÈ·ÖÅä²¢×¢²áÒ»¸ö»òÕ߶à¸öcdev½á¹¹¡£
Èý¡¢É豸²Ù×÷
Éæ¼°open ,close ioclt,releaseµÈº¯Êý
ËÄ¡¢Ð¶ÔØ
scull_cleanup_module
gongji110 ÓÚ 2008-04-14 20:22:11·¢±í:
ÎÒ×î½üÒ²ÔÚŪÇý¶¯±à³Ì£¬Äã˵µÄºÜÓеÀÀí¡£