From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 29 17:57:04 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4624B1065670 for ; Thu, 29 Apr 2010 17:57:04 +0000 (UTC) (envelope-from czerner.lukas@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by mx1.freebsd.org (Postfix) with ESMTP id C1EBA8FC19 for ; Thu, 29 Apr 2010 17:57:03 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id l26so2003216fgb.13 for ; Thu, 29 Apr 2010 10:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:x-x-sender:to:cc :subject:in-reply-to:message-id:references:user-agent:mime-version :content-type; bh=by1HgbHFA3vLCp8pDTiHkmGjbGXn6jFCGgBX84Mjisg=; b=x4JJ4/V8yvKTouItJksyLUa3kOEcMKlxZFwVRubTnvdwIC+jtwh0qmOH0FC+4VWrhN Bo8rj7cgmT2NXa2/dTZeJvigA2LTLi5E9rr6rvJS3o8zEMqyjZidYTNiT+sAF2nedDy5 TCi06ezhMmeIH8k1cltCOWR8gGIG197/bXkGI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; b=E8dIUL70DtKVRTCb2v4REedZTR+iwald5HYatbGACOkeDIYvm0CA+qdK1Qy1opgdHo Sb0CcqIbWhXjSkNCO+OJSv970o189dOVENQ+w1RLIHvz+pBYSVXa+X01+uTijXCqrEGT iiOGxRoa3juLAh5SE781W1ypDlrWkLow9aOJU= Received: by 10.87.15.35 with SMTP id s35mr2152274fgi.12.1272563814833; Thu, 29 Apr 2010 10:56:54 -0700 (PDT) Received: from a04-0215a.kn.vutbr.cz (a04-0215a.kn.vutbr.cz [147.229.216.20]) by mx.google.com with ESMTPS id d8sm4097575fga.21.2010.04.29.10.56.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 29 Apr 2010 10:56:53 -0700 (PDT) Date: Thu, 29 Apr 2010 19:56:56 +0200 (CEST) From: "=?ISO-8859-15?Q?Luk=E1=A8_Czerner?=" X-X-Sender: bratt@a04-0215a.kn.vutbr.cz To: =?ISO-8859-15?Q?Luk=E1=A8_Czerner?= In-Reply-To: Message-ID: References: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1016914840-1272563817=:30007" Cc: freebsd-hackers@freebsd.org Subject: Re: ioctl, copy string from user X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2010 17:57:04 -0000 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 > 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--