ioctl, copy string from user
Lukáš Czerner
czerner.lukas at gmail.com
Thu Apr 29 17:57:04 UTC 2010
On Thu, 29 Apr 2010, Lukáš Czerner wrote:
> Date: Thu, 29 Apr 2010 19:52:45 +0200 (CEST)
> From: Lukáš Czerner <czerner.lukas at gmail.com>
> To: freebsd-hackers at freebsd.org
> Cc: czerner.lukas at gmail.com
> Subject: ioctl, copy string from user
>
> 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)) {
> ...
>
>
> *** Kernel ***
> case MYIOCTL: {
> char buffer[MAXLEN]; /* Yes I can allocate it dynamically,
> byt just for simplicity */
>
> retval = copyinstr(ap->a_data, buffer, MAXLEN - 1, NULL);
> uprintf("In kerne - name : %s\n", buffer)
> ...
Oh and I should probably note that structure ap is :
struct vop_ioctl_args *ap
so I am doing that in filesystem code.
>
> The output is still the same at userspace app it prints out the name
> properly (obviously), but in kernel space it just prints out
> nothing. So I want to ask what is the proper way to do this ??
>
> 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 ?
>
> Thanks!
> -Lukas.
>
More information about the freebsd-hackers
mailing list