Re: character device driver reading only last character of buffer

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

 






On Sun, Sep 26, 2010 at 12:30 PM, Venkatram Tummala <venkatram867@xxxxxxxxx> wrote:
in your code you have done  in memory_read
  *f_pos = *f_pos + count;

why have you done this?
What purpose it serves?

It updates the file pointer.

Why is that important to update the pointer?
Can this be not done without updating.

Your read function is

ssize_t memory_read(struct file *filp, char __user *buf,
                size_t count, loff_t *f_pos)
{
        if (*f_pos > 0)
                return 0;
        if (count > strlen(memory_buffer))
                count = strlen(memory_buffer);
        copy_to_user(buf,memory_buffer,count);
        *f_pos = *f_pos + count;

        return count;
}

I am not able to understand why one needs to update f_pos
to be able to write to userspace or when I am doing a cat /dev/bond

[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