Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 19:56:56 +0200 (CEST)
From:      "=?ISO-8859-15?Q?Luk=E1=A8_Czerner?=" <czerner.lukas@gmail.com>
To:        =?ISO-8859-15?Q?Luk=E1=A8_Czerner?= <czerner.lukas@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: ioctl, copy string from user
Message-ID:  <alpine.DEB.1.10.1004291955220.30007@a04-0215a.kn.vutbr.cz>
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
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323329-1016914840-1272563817=:30007
Content-Type: TEXT/PLAIN; charset=ISO-8859-15
Content-Transfer-Encoding: 8BIT

On Thu, 29 Apr 2010, LukᨠCzerner wrote:

> Date: Thu, 29 Apr 2010 19:52:45 +0200 (CEST)
> From: LukᨠCzerner <czerner.lukas@gmail.com>
> To: freebsd-hackers@freebsd.org
> Cc: czerner.lukas@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.
> 
--8323329-1016914840-1272563817=:30007--



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