ioctl, copy string from user
John Baldwin
jhb at freebsd.org
Thu Apr 29 18:18:53 UTC 2010
On Thursday 29 April 2010 1:52:45 pm Lukáš Czerner wrote:
> Hi,
>
> I know that there are plenty of examples in the kernel code, but I
> just can not get it working, so maybe I am doing some stupid mistake
> I am not aware of. Please give me a hint if you can.
>
> What I want to do is simply call the ioctl from the userspace with
> (char *) argument. Then, in kernel ioctl handling function copy the
> string argument into the kernel space. I have tried it various ways,
> everything without any success.
>
> *** Userspace ***
> char name[MAXLEN];
>
> strncpy(name, argv[1], MAXLEN);
> fprintf(stdout,"Name: %s\n",name);
>
> if (ioctl(fd, MYIOCTL, name)) {
On BSD systems, ioctl() copies the data into the kernel for you ahead of time.
What does the definition of MYIOCTL look like?
> And the second question. I have commented that I can allocate buffer
> dynamically, but I suppose that there will be some locks involved so
> I think I can not just use M_WAITOK, am I right ?
malloc() and free() acquire their own locks internally, you do not need to
hold any locks to call them.
--
John Baldwin
More information about the freebsd-hackers
mailing list