Re: ioctl() and driver function d_ioctl return values

Martin Husemann <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
On Mon, May 19, 2025 at 05:12:37PM +0200, Beesdeckar wrote:
> Hello,
> 
> I am calling ioctl() with control code created with __IOWR() macro and third
> argument contains address of user-mode structure.
> When module's d_ioctl() returns non-zero value then user-mode ioctl()
> returns always -1 and structure in user mode does not contain data filled by
> module.
> 
> Are both above things by design ?

Yes, see src/sys/kern/sys_generic.c line 677ff:

                /*
                 * Copy any data to user, size was
                 * already set and checked above.
                 */
                if (error == 0 && (com&IOC_OUT) && size) {
                        error = copyout(data, SCARG(uap, data),
                            zero_size(size));
                        ktrgenio(SCARG(uap, fd), UIO_READ, SCARG(uap, data),
                            size, error);
                }

Only if the ioctl() succeeds (errror == 0) the copyout of the output structure
is done.

Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.