Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Apr 2010 08:41:49 +0200
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        d@delphij.net
Cc:        freebsd-arch@freebsd.org
Subject:   Re: _IOWR when errno != 0
Message-ID:  <20100415064149.GB2252@garage.freebsd.pl>
In-Reply-To: <4BC39E93.7060906@delphij.net>
References:  <4BC39E93.7060906@delphij.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--+g7M9IMkV8truYOl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Apr 12, 2010 at 03:28:35PM -0700, Xin LI wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>=20
> Hi,
>=20
> Is there a sane way to copyout ioctl request when the returning errno !=3D
> 0?  Looking at the code, currently, in sys/kern/sys_generic.c, we have:
>=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>         error =3D kern_ioctl(td, uap->fd, com, data);
>=20
>         if (error =3D=3D 0 && (com & IOC_OUT))
>                 error =3D copyout(data, uap->data, (u_int)size);
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> Is there any objection if I change it to something like:
>=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>         saved_error =3D kern_ioctl(td, uap->fd, com, data);
>=20
>         if (com & IOC_OUT)
>                 error =3D copyout(data, uap->data, (u_int)size);
>         if (saved_error)
>                 error =3D saved_error;
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

I'd like to note that OpenSolaris does copy data back even if an error
occurs. I needed to change ZFS to return 0 for ioctl(2) and return an
error within zfs_cmd structure.

I think FreeBSD way is better, BTW. ioctl(2) can fail for other reasons,
for example data pointer is invalid, so we return EFAULT and we are
unable to copy data back in that case anyway.

--=20
Pawel Jakub Dawidek                       http://www.wheelsystems.com
pjd@FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!

--+g7M9IMkV8truYOl
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAkvGtSwACgkQForvXbEpPzTcNACg3Iq+vXbNNUIv2Irudz1D7rE3
gjUAoOUhQ2PkIM0C2u6I2OL2gPLkTnZ/
=y1Ws
-----END PGP SIGNATURE-----

--+g7M9IMkV8truYOl--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100415064149.GB2252>