【发布时间】:2014-08-08 17:00:03
【问题描述】:
我正在开发示例内核模块driver.ko。我想用模块参数BlockSize 指定data_node 结构的块大小。当我单独运行 insmod driver.ko 时,它可以工作,但是当我指定 BlockSize insmod driver.ko BlockSize = 10 时,我得到了这个错误:
Error: could not insert module driver.ko: Invalid parameters
modinfo -p ./driver.ko 命令给我这个:
BlockSize: size of buffer (int)
驱动程序.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/slab.h>
/* parametter */
static int BlockNumber = 8;
static int BlockSize = 512;
module_param( variable name, type, permission); */
module_param(BlockSize, int, S_IRUGO);
MODULE_PARM_DESC(BlockSize , " size of buffer");
/* using 'k' as magic number */
#define SAMPLE_IOC_MAGIC 'k'
#define SAMPLE_IOCRESET _IOWR(SAMPLE_IOC_MAGIC, 0, int)
#define SAMPLE_IOC_MAXNR 0
struct cdev* my_cdev;
dev_t dev;
static int size_to_read;
/* Macro used to compute the minimum */
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
/* data buffer structure */
typedef struct dnode
{
int bufSize;
char *buffer;
struct dnode *next;
} data_node;
/* liste stucture */
typedef struct lnode
{
data_node *head;
data_node *cur_write_node;
data_node *cur_read_node;
int cur_read_offset;
int cur_write_offset;
}liste;
code ..........................
..
【问题讨论】:
-
不难找到这样的例子,包括代码和命令行。作为一个疯狂的猜测,因为我有一段时间没看这个了,你试过没有空格,即
insmod driver.ko BlockSize=10? -
@ChrisStratton 非常感谢,它可以在没有空间的情况下工作:) 我没有注意到
标签: linux-kernel kernel-module device-driver insmod