On Wed, Oct 19, 2005 at 00:17:44 -0700, santosh pattar wrote: > Hi, > > I am getting a problem when reading a file in kernel space. can any one help me with this. Don't do it. Read the file in user-space and feed it in kernel via device, procfs entry or netlink. > #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(); Don't mess with file descriptors in kernel. Use the struct file * directly. > 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. *WHICH* error? Learn about kernel and user-space memory and copy_to_user/copy_from_user means and come back when you understand it. > printk("nbr= %d", nbr); > printk( "%s", buff); > return 0; > } > void cleanup_module(void) > { > printk("Unloading hello\n"); > } -- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature