Re: f_pos passing as a fouth argument in read and write

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

 



On 7/13/06, Om. <om.turyx@xxxxxxxxx> wrote:
On 7/11/06, Deepak Joshi <deepak_cins@xxxxxxxxxxx> wrote:
> Hi all,
>
Hi,

> While reading device drivers by rubini, i  found following statement related
> to loff_t fops.
>
> The current reading or writing position. loff_t is a 64-bit value (long long
> in gcc terminology). The driver can read this value if it needs to know the
> current position in the file, but should never change it (read and write
> should update a position using the pointer they receive as the last argument
> instead of acting on filp->f_pos directly).
vfs subsystem increments the f_pos immediately after the call to
VFS doesn't increment f_pos, but it just assigns the value of pos.

static inline void file_pos_write(struct file *file, loff_t pos)
{
       file->f_pos = pos;
}

f_ops->read()/write(). If you increment f_pos in read()/write(), this
value would be incorrect. (would be modified twice)

Its because the kernel writes to file->f_pos with the value that is
contained in pos after we return from the read/write. See the code
below:

               loff_t pos = file_pos_read(file);
               ret = vfs_read(file, buf, count, &pos);
               file_pos_write(file, pos);

The first and third statements could be avoided if the one who writes
the device driver can be more responsible for modifying the
file->f_pos in each call to read/write.

Look in fs/read_write.c for sys_read/sys_write implementations.

Jinesh.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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