문자 디바이스 샘플 작성 에러입니다.
안녕하세요.
현재 문자 디바이스 드라이버를 공부하고 있는데요 sample code를 보고 따라하는데 모듈 적재에서 계속 에러가 발생하네요.
소스코드 컴파일시에는 에러가 나지 않다가 insmod에서 다음과 같이 에러가 발생하네요.
현재 linux 버전은 2.6.35.6-45 입니다.
[root@~]#insmod: error inserting 'kernel.ko': -1 Invalid parameters
소스코드는 아래와 같습니다. 조언 부탁드리겠습니다.
#include
#include
#include /* device file operactions */
#include /* kmalloc */
#include
#include
#include
#include
#include
/* Device Definitions */
#define DEVICE_MAJOR 240
#define DEVICE_NAME "SAMPLE_DRIVER"
#define REG_LEN 10
/* Global Variables */
static char READ_Register[REG_LEN];
static char WRITE_Register[REG_LEN];
/* Function Prototypes */
static int Sample_open(struct inode *inode, struct file *filp);
static int Sample_release(struct inode *inode, struct file *filp);
static ssize_t Sample_read(struct file *filp, char *buffer, size_t length, loff_t *offset);
static ssize_t Sample_write(struct file *filp, const char *buffer, size_t length, loff_t *offset);
struct file_operations sample_fops = {
.owner = THIS_MODULE,
.open = Sample_open,
.release = Sample_release,
.read = Sample_read,
.write = Sample_write,
};
int sample_init(void)
{
int result;
printk(" sample_init \n");
if ((result = (register_chrdev(DEVICE_MAJOR, DEVICE_NAME, &sample_fops))) < 0)
{
printk(DEVICE_NAME " : Device registration failed (%d) \n",result);
return result;
}
printk(DEVICE_NAME " : sample_init() OK, Major Number = %d\n", DEVICE_MAJOR);
return 0;
}
int Sample_open(struct inode *inode, struct file *filp)
{
int minor = MINOR(inode->i_rdev);
printk(DEVICE_NAME ":Device open OK minor : %d \n", minor);
return 0;
}
int Sample_release(struct inode *inode, struct file *filp)
{
printk(DEVICE_NAME ":Device close OK (%d, %d)\n", MAJOR(inode->i_rdev), MINOR(inode->i_rdev));
return 0;
}
ssize_t Sample_read(struct file *filp, char *buffer, size_t length, loff_t *f_pos)
{
int count;
count = 0;
printk("READ: length = %d\n", length);
while (count
{
put_user(READ_Register[count], buffer);
buffer++;
count++;
if (count >= REG_LEN)
break;
}
memset(READ_Register, 0, REG_LEN);
return count;
}
ssize_t Sample_write(struct file *filp, const char *buffer, size_t length, loff_t *f_pos)
{
int count;
count = 0;
printk("WRITE: length = %d\n", length);
while (count
get_user(WRITE_Register[count], buffer);
buffer++;
count++;
if (count >= REG_LEN)
break;
}
memcpy(READ_Register, WRITE_Register, count);
return count;
}
void sample_exit(void){
int nRetCode;
if ((nRetCode = unregister_chrdev(DEVICE_MAJOR, DEVICE_NAME)) < 0)
printk(DEVICE_NAME ":Device unregistration failed (%d)\n", nRetCode);
printk(DEVICE_NAME " : sample_exit() OK\n");
}
module_init(sample_init);
module_exit(sample_exit);
MODULE_LICENSE ("Dual BSD/GPL");
댓글 달기