Writing to a file from kernel

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

 



Hi,

  I am having a weird problem writing to a file from the kernel.  At the 
statement ' file->f_op->write(...)' the module just seems to hang during 
insmod.  Could anyone tell me why this might be the case?  The code is 
pasted below.

Thanks,
-Amit

PS - My earlier mail didn't go completely through.  Sorry about that.

-----------------------------------------------------------------------------------

int init_module()
{
        struct file *file = NULL;
        struct inode *inode;
        mm_segment_t fs;
        char *str = "foo";

       
/* the file test.log was 'touched' before insmod-ing' */
        file = filp_open("/tmp/test.log", O_WRONLY|O_APPEND,0);

        if (IS_ERR(file)||(file==NULL)) {
                printk("Error in opening file \n");
        }

        if (!file->f_op->write) {
                fput(file);
        }

        fs = get_fs();
        inode = file->f_dentry->d_inode;
        down(&inode->i_sem);

        set_fs(KERNEL_DS);
        /* this line seems to hang */
        file->f_op->write(file, str, 3, &file->f_pos);
        set_fs(fs);

        up(&inode->i_sem);
        return 0;
}


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[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