From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 29 17:52:52 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 42889106566C for ; Thu, 29 Apr 2010 17:52:52 +0000 (UTC) (envelope-from czerner.lukas@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by mx1.freebsd.org (Postfix) with ESMTP id C3D448FC08 for ; Thu, 29 Apr 2010 17:52:51 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id 22so3340265fge.13 for ; Thu, 29 Apr 2010 10:52:44 -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:message-id:user-agent:mime-version:content-type; bh=JMlQigtUH1MgJZ4XiKM0Y24YCFW2cCQiRIv0l4G/nEg=; b=NIt3ecypjeARk6EE4ufmexGru/yeJdiwxUHFYsmwKQIa19Eh26ApSbYYzLfETEw5Q9 gt8caX6x+sL8UnqXK/qVUhyFZBBGw+8rAV8RsbHSlQkX0CufH3kKh8wzJK3CSPPoyJ5Y WV2eCjJ2AqVT/HrIwRWIz7aE0JEmhzwy/sCMA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:x-x-sender:to:cc:subject:message-id:user-agent :mime-version:content-type; b=rsFtmmLR69ZuCZRtPZiZSEkgPw7pW8Q1YaJQvm1l3RAAbVFlEeh2reLNeBKtl26zrL oMZqPTeUZEtIOsRsGyRUb8rkmM0UyLlAxhXOQH32PeRuf5MnzcIVbvXj8QU4qz9XAXIJ dbA/uBI0H2hRKqVbvnvucI+34KxELJ0D28uQQ= Received: by 10.87.58.6 with SMTP id l6mr163333fgk.15.1272563563964; Thu, 29 Apr 2010 10:52:43 -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 e11sm12748357fga.23.2010.04.29.10.52.42 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 29 Apr 2010 10:52:42 -0700 (PDT) Date: Thu, 29 Apr 2010 19:52:45 +0200 (CEST) From: "=?ISO-8859-15?Q?Luk=E1=A8_Czerner?=" X-X-Sender: bratt@a04-0215a.kn.vutbr.cz To: freebsd-hackers@freebsd.org Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: czerner.lukas@gmail.com Subject: 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:52:52 -0000 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.