Device driver query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 i know how to write a character device driver but the same will not work for
simple file why? that mean if i create a file /root/myfile and want to write
and read to it periodically from a kernel module it is not working cause i am doing
.....fragment of my code.........
static struct file_operations myfile_file_operations = {
    open:       myfile_open,
    release:    myfile_release,
    read:       myfile_read,
    write:      myfile_write,
};
int init_module(void)
{
    printk("Loading myfile Module\n");
 ent = filp_open("/root/myfile", O_RDWR,S_IRUSR | S_IWUSR);
  if ( ent == NULL)
                      printk(KERN_DEBUG, "Error opening file...\n");
    return 0;
}
void cleanup_module(void)
{
    printk("Unloading myfile Module\n");
    filp_close(ent,NULL);
}
int myfile_open(struct inode *inodep, struct file *filp)
{
    printk("Opening a file....\n");
    MOD_INC_USE_COUNT;
    return 0;
}
int myfile_release(struct inode *inodep, struct file *filp)
{
    MOD_DEC_USE_COUNT;
    return 0;
}
I want whenever module is loaded it should create a file and when it unloaded should
remove file. but above code is fail to create a file and also causing problem in unloading
a module with warning for arg 1 parameter of flip_close.
help to write a module to read/write a normal file from kernel module.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux