⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 param.c

📁 对linux内核编程做了详细的解析和举例
💻 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 <linux/kernel.h>   /* We're doing kernel work */#include <linux/module.h>   /* Specifically, a module *//* Deal with CONFIG_MODVERSIONS */#if CONFIG_MODVERSIONS==1#define MODVERSIONS#include <linux/modversions.h>#endif        #include <stdio.h>  /* I need NULL *//* In 2.2.3 /usr/include/linux/version.h includes a  * macro for this, but 2.0.35 doesn't - 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 doesn't 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 parameter's name and * it's 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=<something>");    printk("str2=<something>\n");  } else    printk("Strings:%s and %s\n", str1, str2);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)  printk("If you try to insmod this module twice,");  printk("(without rmmod'ing\n");  printk("it first), you might get the wrong");   printk("error message:\n");  printk("'symbol for parameters str1 not found'.\n");#endif  return 0;}/* Cleanup */void cleanup_module(){}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -