ioctl, copy string from user

Lukáš Czerner czerner.lukas at
Thu Apr 29 17:52:52 UTC 2010


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 ?


More information about the freebsd-hackers mailing list