Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 14:18:09 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        =?utf-8?q?Luk=C3=A1=C5=A1?= Czerner <czerner.lukas@gmail.com>
Subject:   Re: ioctl, copy string from user
Message-ID:  <201004291418.09768.jhb@freebsd.org>
In-Reply-To: <alpine.DEB.1.10.1004291938210.30007@a04-0215a.kn.vutbr.cz>
References:  <alpine.DEB.1.10.1004291938210.30007@a04-0215a.kn.vutbr.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday 29 April 2010 1:52:45 pm Luk=C3=A1=C5=A1 Czerner wrote:
> Hi,
>=20
> 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.
>=20
> 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.
>=20
> *** Userspace ***
> char name[MAXLEN];
>=20
> strncpy(name, argv[1], MAXLEN);
> fprintf(stdout,"Name: %s\n",name);
>=20
> if (ioctl(fd, MYIOCTL, name)) {

On BSD systems, ioctl() copies the data into the kernel for you ahead of ti=
me. =20
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=
=20
hold any locks to call them.

=2D-=20
John Baldwin



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