ioctl: uiomove, copyin, copyout

Matthew Jacob lydianconcepts at gmail.com
Wed Sep 6 00:01:17 UTC 2006


>
> 1) Finding the equivalent of the Linux copy_to_user and copy_from_user
> routines. Are those copyin, and copyout ?

Yes.


>
>
> 2) Getting the ioctl operation to work. When issuing an ioctl from
> userspace I get:
>

My guess is that your ioctl codes are being interpred.

Check the format of your ioctl code to make sure that it follows BSD
rules for getting passed to your driver w/o interpretation. Linux IIRC
follows SYSV ioctl semantics, which means that the ioctl is never
interpreted by the kernel above the driver. BSD ioctls semantics looks
at the type nibble to decide whether the ioctl parameters can be
copied directly to the kernel and presented to driver as a pointer you
can just de-reference rather than a pointer you have to perform copyin
on.

Check sys/ioccom.h.


> # dynamos_control -o 9
> ioctl error for command 9: Inappropriate ioctl for device
> errno is 25
> it's an ENOTTY
>
> ... while in the driver I have:
>
> static d_read_t dynreplace_file_operations_read;
> static d_ioctl_t dynreplace_file_operations_ioctl;
>
> static struct cdevsw dynreplace_cdevsw = {
>   .d_version = D_VERSION,
>   .d_open = dynreplace_file_operations_open,
>   .d_close = dynreplace_file_operations_release,
>   .d_read = dynreplace_file_operations_read,
>   .d_ioctl = dynreplace_file_operations_ioctl,
>   .d_name = MODULE_NAME_STR,
> };
>
>
> int dynreplace_file_operations_ioctl(struct cdev *dev, u_long cmd,
> caddr_t data, int flags, struct thread *td)
> {
>   print( "ioctl - MAIN\n");
>   return 0;
> }
>
> ... the _read operation works as expected, but I don't even see the
> print statement from _ioctl.
>
>
> The ioctl(2) manpage reads:
>
>      [ENOTTY]           The d argument is not associated with a
>                         character special device.
>
> This can't be true since the read operation works, and:
>
> # ls -lrta /dev/dynamos
> crwx------  1 root  wheel    0,  95 Sep  2 16:31 /dev/dynamos
>
> and...
>
>      [ENOTTY]           The specified request does not apply to the kind
>                         of object that the descriptor d references.
>
> Is this last part somehow enforced by the kernel ?
>
> I know I have an uncommon build process, since the driver is built for
> multiple OSs, but if I can get the read operation to work why would
> ioctl be so difficult ?
>
> Am I missing something ?
>
>
> _______________________________________________
> freebsd-drivers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-drivers
> To unsubscribe, send any mail to "freebsd-drivers-unsubscribe at freebsd.org"
>


More information about the freebsd-drivers mailing list