problem in reading a file in kernel space

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

 



Hi,
 
I am getting a problem when reading a file in kernel space. can any one help me with this.
 
 
 
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/syscalls.h>
MODULE_LICENSE("GPL");
static char buff[100];
int init_module(void)
{
 struct file *filp;
 int unused_fd, nbr;
 printk("loading hello\n");
 filp = filp_open("a.txt",O_RDWR,0);    // a.txt is a file which i need to read
 unused_fd = get_unused_fd();
 printk("unused_fd = %d\n", unused_fd);
 fd_install(unused_fd, filp);
 nbr = sys_read(unused_fd, buff, 100);    // problem is here. nbr returning error.
 printk("nbr= %d", nbr);
 printk( "%s", buff);
 return 0;
}
void cleanup_module(void)
{
 printk("Unloading hello\n");
}
 
thanks
santosh


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.

[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