[lkml]   [2000]   [Nov]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: What protects f_pos?
On 13 Nov 2000, David Wragg wrote:

> "David Schwartz" <> writes:

> So both threads read the same block, and f_pos only gets incremented
> once.
> (Pipes and sockets are a different matter, of course.)
> 2.2 has the same issue, since although the BKL is held, it will get
> dropped if one of the threads sleeps on I/O. (Earlier Linux versions
> might well have the same issue, but I don't have the source around to
> check.)
> POSIX doesn't seem to bar this behaviour. From
> On a regular file or other file capable of seeking, read() shall
> start at a position in the file given by the file offset
> associated with fildes. Before successful return from read(), the
> file offset shall be incremented by the number of bytes actually
> read.
> Which is exactly what Linux does. I can't find text anywhere else in
> POSIX.1 that strengthens that condition for the case of multiple
> processes/threads reading from the same file. I'll try to find out
> what the Austin Group has to say about this.

Anything that uses f_pos has a problem with multiple readers or multiple
writers. That's one of the problems that file locking is supposed to
handle. An application has got to know how to access a file when it can
be changed by another.

There is a more far-reaching problem that sooner or later will get us.
That's the built-in problem with lseek. Lseek is supposed to return -1
if it failed, with errno being set appropriately. This, in principle,
does not prevent seeking to the last byte of the file as long as errno
is checked by the caller if the function returns -1.

Linux, internally, uses "-errno" as a return value to show an
error. So what happens if we `lseek` to -EBADF or -EFAULT, etc.

An otherwise empty lseek routine in a module, that does nothing except
return the input value, will show errors once the offsets corresponding
to negative errno values are reached.

Dick Johnson

Penguin : Linux version 2.4.0 on an i686 machine (799.54 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:45    [W:0.048 / U:1.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site