semantics of fcntl() with l_len being 0

Kostik Belousov kostikbel at gmail.com
Wed Aug 26 14:06:50 UTC 2009


On Wed, Aug 26, 2009 at 09:57:04AM -0400, Mikhail T. wrote:
> Kostik Belousov написав(ла):
> > On Wed, Aug 26, 2009 at 12:20:57AM -0400, Mikhail T. wrote:
> >   
> >> Hello!
> >>
> >> I'm curious, whether a file, that's locked (via fcntl) with l_start and
> >> l_len being 0 is supposed to be appendable...
> >>
> >> I would think so, but I notice, that when spamprobe (see mail/spamprobe)
> >> chews on my spam mailbox, I can not append a new piece of spam to the
> >> file -- my imap-server is waiting for spamprobe to finish.
> >>
> >> The fcntl(2) says: ``len = 0 means until end of file''. Is that ``until
> >> the end of file AT THE TIME OF LOCKING'' or simply ``no other lock until
> >> we are done''? Thanks. Yours,
> >>     
> >
> > SUSv3 is definitive on the subject:
> > A lock shall be set to extend to the largest possible value of the file
> > offset for that file by setting l_len to 0. If such a lock also has
> > l_start set to 0 and l_whence is set to SEEK_SET, the whole file shall
> > be locked.
> >   
> I would not say, this is definitive -- if one attempts to grow a locked
> file, "the whole file" (as existed at the lock-time) will remain
> non-violated... The code is more explicit, of course:
> > From sys/kern/kern_lockf.c, line 464:
> > 	} else if (fl->l_len == 0) {
> > 		end = OFF_MAX;
> >   
> So, how can one properly lock only the area, that exists at the time of
> locking? Perform a stat() first? Thanks!

You might lock the maximal range, to prevent the modifications from other
accessors that honour the protocol, do stat call, and then unlock
the range from EOF to 0 (AKA max offset).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20090826/63c10ba0/attachment.pgp


More information about the freebsd-fs mailing list