Re: extattr_set_*() return type

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Wed, 21 Dec 2011 22:28:42 +0200
On Wed, Dec 21, 2011 at 12:25:18PM -0500, John Baldwin wrote:
> On Wednesday, December 21, 2011 11:13:10 am Kostik Belousov wrote:
> > On Wed, Dec 21, 2011 at 10:31:11AM -0500, John Baldwin wrote:
> > > On Tuesday, December 20, 2011 5:18:58 pm mdf_at_freebsd.org wrote:
> > > > On Tue, Dec 20, 2011 at 1:49 PM, John Baldwin <jhb_at_freebsd.org> wrote:
> > > > > Hmm, if these functions are expected to operate like 'write(2)' and are
> > > > > supposed to return the number of bytes written, shouldn't their return value
> > > > > be 'ssize_t' instead of 'int'?  It looks like the system calls themselves
> > > > > already do the right thing in setting td_retval[] (they assign a ssize_t to it
> > > > > and td_retval[0] can hold a ssize_t on all of our current platforms).  It
> > > > > would seem that the only change would be to the header and probably
> > > > > syscalls.master.  I guess this would require a symver bump to fix though.
> > > > 
> > > > An extended attribute larger than 2GB is a programming abuse, though.
> > > > Technically int may not be 32 bits but it is on all supported
> > > > platforms now.
> > > 
> > > Today it is an abuse.  In the 90's a 64-bit off_t was considered an abuse by
> > > some. :)
> > > 
> > > The type should match the documented behavior.  On OS X the set operation
> > > doesn't return a size but instead returns a simple success/failure (0 or -1)
> > > for which an int is appropriate.  However, the FreeBSD API documents that it
> > > operates like write and consumes the buffer.   Note that the size of the
> > > buffer passed to the 'set' and 'get' operations is a size_t, not an int, and
> > > the 'get' operations already return a ssize_t, not an int.
> > 
> > Note that read(2)/write(2) do return int. I still have WIP patch to fix
> > this, but after some conversations with Bruce I am not sure it is worth
> > finishing.
> 
> The manpages and /usr/include/unistd.h claim they return ssize_t.  Is this
> related to the changes to make uio_resid a size_t (I thought that went into
> the tree)?  If the problem is that the values read/write return may fall into
> the range of only an int even on 64-bit platforms, that is different from the
> return type which is part of the ABI.
Yes, it is related. The type change for uio was done in advance.

Take a look at the first statement of sys_read() and sys_write():
	if (uap->nbyte > INT_MAX)
		return (EINVAL);
and at the copyinio(), which is used by scatter/gather versions of i/o
syscalls to copy in uiovec:
	if (iov->iov_len > INT_MAX - uio->uio_resid) {
		free(uio, M_IOV);
		return (EINVAL);


Received on Wed Dec 21 2011 - 19:28:48 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:22 UTC