Why doesn't this driver work
Hi guys,
this things got the hell out of me. I've built a very small character driver but it doesn't compile. Sinc it's small I'm pasting the code here. Could someone hep me out. The site unixworldonline didn't help, it's got some functions mentioned that don't in my kernel source code.
My kernel version is 2.4
Program:
///////////////////////////////////////////////////////////////////////////////////
#define __KERNEL__
#define __NO_VERSION__
#include <linux/config.h>
#include <asm/io.h>
#include <linux/ioport.h>
#include <linux/fs.h>
#ifdef CONFIG_SMP
#define __SMP__
#endif
#define TEST_MAJOR 244
struct file_operations test_fops = {
write: write_driver,
open: open_driver,
release: release_driver,
};
int init_module(void)
{
int result1,result2;
result1=register_chrdev(TEST_MAJOR,"test_driver",&test_fops);
if(result1 < 0)
{
printk(KERN_WARNING "test: can't get major %d \n",TEST_MAJOR);
return result1;
} //END OF REGISTRY
result2=check_region(0x378,0x100);
if(result2 < 0)
{
printk(KERN_WARNING "test: can't get requested region");
return result2;
}
request_region(0x378,0x100,"test_driver");
return 0;
}
int open_driver(struct inode *inode, struct file *filp)
{
MOD_INC_USE_COUNT;
return 0;
}
int release_driver(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
return 0;
}
ssize_t write_driver(struct file *filp, char *buff, size_t count, loff_t *offp)
{
while(count--)
{
outb( *(buff++), offp++);
wmb();
}
}
void cleanup_module(void)
{
release_region(0x378,0x100);
unregister_chrdev(TEST_MAJOR,"test_driver");
}
///////////////////////////////////////////////////////////////////////////////////
ASSUME THE FILENAME IS TEST_DRV.C FOR EASY EXPLANATION :-0
I AM NOT BUILDING IT AS A MODULE, I WANT TO INTEGRATE IT WITH MY KERNEL CODE DIRECTLY.
THANKS EVERYBODY.
aditya
|