On Sun, Sep 26, 2010 at 12:21 AM, Bond <jamesbond.2k.g@xxxxxxxxx> wrote:
Try writing a user space file handling program in C. I repeat what other have already said before. Before starting kernel development, you need to know the user space basics.
The first read comes in with a *f_pos of 0. If you dont update the file pointer, the user space program will keep reading from f_pos 0 indefinitely. As file pointer is at offset 0 always because you dont update *f_pos, every read(..) called by user space will succeed. So, your command cat /dev/bond will never return. user space programs generally look for a specific return code to know that it is the end of the file.
Why is that important to update the pointer?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.
Can this be not done without updating.
Try writing a user space file handling program in C. I repeat what other have already said before. Before starting kernel development, you need to know the user space basics.
The first read comes in with a *f_pos of 0. If you dont update the file pointer, the user space program will keep reading from f_pos 0 indefinitely. As file pointer is at offset 0 always because you dont update *f_pos, every read(..) called by user space will succeed. So, your command cat /dev/bond will never return. user space programs generally look for a specific return code to know that it is the end of the file.
I am not able to understand why one needs to update f_pos
Your read function is
ssize_t memory_read(struct file *filp, char __user *buf,
size_t count, loff_t *f_pos){if (count > strlen(memory_buffer))
if (*f_pos > 0)
return 0;
count = strlen(memory_buffer);
copy_to_user(buf,memory_buffer,count);return count;
*f_pos = *f_pos + count;
}
to be able to write to userspace or when I am doing a cat /dev/bond