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

LinuxÄں˱à³Ì(Æô¶¯²ÎÊý)

·¢²¼Ê±¼ä:2005-05-28 00:19:09À´Ô´:ºìÁª×÷Õß:007
6£®Æô¶¯²ÎÊý
ÔÚÒÔÇ°µÄÐí¶àÀý×ÓÀÎÒÃÇÒª°ÑһЩ¶«Î÷Ç¿ÖƵØдÈëÄÚºËÄ£¿é£¬±ÈÈç/procÎļþÃû»òÉ豸Ö÷Â룬ÒÔÖÁÎÒÃÇ¿ÉÒÔÓÃioctl¡¯s´¦ÀíËü¡£ÕâÑù¾äÎ¥±³ÁËUnixÒÔ¼°LinuxµÄÔ­Ôò£ºÐ´Óû§¿ÉÒÔ×ÔÓÉÉ趨µÄÁé»î³ÌÐò¡£
ÔÚ³ÌÐò»òÕßÄÚºËÄ£¿éÆô¶¯Ö®Ç°Í¨ÖªËüһЩÏûÏ¢ÊÇͨ¹ýÃüÁîÐвÎÊý×öµ½µÄ¡£ÔÚÄÚºËÄ£¿éµÄÇé¿öÏ£¬ÎÒÃÇûÓÐargcºÍargv²ÎÊý£¬¶øÊÇÓиüºÃµÄ¶«Î÷¡£ÎÒÃÇ¿ÉÒÔÔÚÄÚºËÄ£¿éÀﶨÒåÈ«¾Ö±äÁ¿£¬insmod»á¸øÎÒÃǸ³Öµ¡£
ÔÚÕâ¸öÄÚºËÄ£¿éÖУ¬ÎÒÃǶ¨ÒåÁËÁ½¸ö±äÁ¿£ºstr1ºÍstr2¡£ÄãÐèÒª×öµÄÖ»ÊDZàÒëÄÚºËÄ£¿é£¬È»ºóÔËÐÐstr1=xxx str2=yyy¡£µ±µ÷ÓÃinit_moduleʱ£¬str1½«Ö¸Ïò´®xxx£¬str2½«Ö¸Ïò´®yyy¡£
ÔÚ2.0°æ¶ÔÕâЩ²ÎÊýûÓÐÀàÐͼì²é¡£Èç¹ûstr1ºÍstr2µÄµÚÒ»¸ö×Ö·ûÊÇÊý×Ö£¬Äں˾ͻá°ÑÕâЩ±äÁ¿¸³ÎªÕûÊý£¬¶ø²»ÊÇÖ¸Ïò´®µÄÖ¸Õë¡£ÕâÔÚʵ¼ÊÇé¿öÖÐÄãÒ»¶¨Òª¼ì²éÀàÐÍ¡£
ÁíÒ»·½Ã棬ÔÚ2.2°æ±¾ÖУ¬Äã¿ÉÒÔʹÓúêMACRO_PARM¸æËßinsmodÄãÐèÒªÒ»¸ö²ÎÊý£¬ËüµÄÃû×ÖºÍÀàÐÍ¡£ÕâÑù½â¾öÁËÀàÐÍÎÊÌ⣬²¢ÇÒÔÊÐíÄÚºËÄ£¿é½ÓÊÕÒÔÊý×Ö¿ªÊ¼µÄ´®¡£
ex param.c

/* param.c
*
* Receive command line parameters at module installation
*/

/* Copyright (C) 1998-99 by Ori Pomerantz */





/* The necessary header files */

/* Standard in kernel modules */
#include /* Were doing kernel work */
#include /* Specifically, a module */

/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include
#endif


#include /* I need NULL */


/* In 2.2.3 /usr/include/linux/version.h includes a
* macro for this, but 2.0.35 doesnt - so I add it
* here if necessary. */
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif



/* Emmanuel Papirakis:
*
* Prameter names are now (2.2) handled in a macro.
* The kernel doesnt resolve the symbol names
* like it seems to have once did.
*
* To pass parameters to a module, you have to use a macro
* defined in include/linux/modules.h (line 176).
* The macro takes two parameters. The parameters name and
* its type. The type is a letter in double quotes.
* For example, ""i"" should be an integer and ""s"" should
* be a string.
*/


char *str1, *str2;


#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
MODULE_PARM(str1, ""s"");
MODULE_PARM(str2, ""s"");
#endif


/* Initialize the module - show the parameters */
int init_module()
{
if (str1 == NULL || str2 == NULL) {
printk(""Next time, do insmod param str1="");
printk(""str2= "");
} else
printk(""Strings:%s and %s "", str1, str2);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
printk(""If you try to insmod this module twice,"");
printk(""(without rmmoding "");
printk(""it first), you might get the wrong"");
printk(""error message: "");
printk(""symbol for parameters str1 not found. "");
#endif

return 0;
}


/* Cleanup */
void cleanup_module()
{
}
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 4 ÌõÆÀÂÛ

  1. lcdstrongman ÓÚ 2011-11-20 23:15:48·¢±í:

    ²»´í Â¥Ö÷×ܽáµÃÏêϸ

  2. jianxin_pan_00 ÓÚ 2011-11-19 23:16:40·¢±í:

    ¸Õ¿ªÊ¼Ñ§¶«Î÷ ллÁË

  3. xuaibing ÓÚ 2011-10-23 23:15:26·¢±í:

    ¿´¿´

  4. ai0909 ÓÚ 2011-10-21 16:12:43·¢±í:

    ·¹ý¡£¡£¡£