Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 19:52:45 +0200 (CEST)
From:      "=?ISO-8859-15?Q?Luk=E1=A8_Czerner?=" <czerner.lukas@gmail.com>
To:        freebsd-hackers@freebsd.org
Cc:        czerner.lukas@gmail.com
Subject:   ioctl, copy string from user
Message-ID:  <alpine.DEB.1.10.1004291938210.30007@a04-0215a.kn.vutbr.cz>

next in thread | raw e-mail | index | archive | help
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)
	...

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.



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