From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 22 07:18:24 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4D02A16A4CE for ; Sun, 22 Aug 2004 07:18:24 +0000 (GMT) Received: from mail3.speakeasy.net (mail3.speakeasy.net [216.254.0.203]) by mx1.FreeBSD.org (Postfix) with ESMTP id 17BDC43D3F for ; Sun, 22 Aug 2004 07:18:24 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 25625 invoked from network); 22 Aug 2004 07:18:23 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail3.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 22 Aug 2004 07:18:23 -0000 Received: from hydrogen.funkthat.com (mlifor@localhost.funkthat.com [127.0.0.1])i7M7IMuU031553; Sun, 22 Aug 2004 00:18:23 -0700 (PDT) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id i7M7IKCO031552; Sun, 22 Aug 2004 00:18:20 -0700 (PDT) Date: Sun, 22 Aug 2004 00:18:20 -0700 From: John-Mark Gurney To: Alfred Perlstein Message-ID: <20040822071820.GA29902@funkthat.com> Mail-Followup-To: Alfred Perlstein , Poul-Henning Kamp , hackers@freebsd.org References: <20040821200205.GE26612@elvis.mu.org> <46719.1093120181@critter.freebsd.dk> <20040822064707.GF26612@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040822064707.GF26612@elvis.mu.org> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: Poul-Henning Kamp cc: hackers@freebsd.org Subject: Re: sysctl hacks X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2004 07:18:24 -0000 Alfred Perlstein wrote this message on Sat, Aug 21, 2004 at 23:47 -0700: > * Poul-Henning Kamp [040821 13:29] wrote: > > In message <20040821200205.GE26612@elvis.mu.org>, Alfred Perlstein writes: > > >I'm doing some work that requires that I have a sysctl structure > > >be passed around, but inside that structure are several pointers I > > >may need to dereference. > > > > > >Basically: > > > > > >struct mysysctldata { > > > .... (data here) > > > void *moredata; > > > size_t morelen; > > >}; > > > > > >What is the proper way of sysctl'ing IN the data from moredata? > > > > > >I need to make a copy of the sysctl req, but... I'm not sure what > > >to initialize the 'lock' member to. > > > > Just use the SYSCTL_IN() and ..._OUT() functions. > > :( > > I wasn't clear. > > I have a sysctl node that takes a struct like so: > > struct mysysctldata { > .... (data here) > struct moredata * vc_ptr; > size_t len vc_len; > } > > If I use SYSCTL_IN(), then I can get "mysysctldata", but I only > get the pointer to "moredata", now I want to get a copy of > "moredata", what's a good way to do this? > > I have a macro that does this: > > #define VCTLTOREQ(vc, req) \ > do { \ > (req)->newptr = (vc)->vc_ptr; \ > (req)->newlen = (vc)->vc_len; \ > (req)->newidx = 0; \ > } while (0) > > Is that right? After reading the sysctl code, it appears that you can't do that.. SYSCTL_IN only lets you read serially from the buffer passed in... so you have to have all the data serially in userland... once you do a SYSCTL_IN of x bytes of data, the pointer is updated to skip those x, and the next call will read in the bytes following the first read... Hope this helps. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."