linux_sysctl.c revision 83366
183221Smarcel/*- 283221Smarcel * Copyright (c) 2001 Marcel Moolenaar 383221Smarcel * All rights reserved. 483221Smarcel * 583221Smarcel * Redistribution and use in source and binary forms, with or without 683221Smarcel * modification, are permitted provided that the following conditions 783221Smarcel * are met: 883221Smarcel * 1. Redistributions of source code must retain the above copyright 983221Smarcel * notice, this list of conditions and the following disclaimer 1083221Smarcel * in this position and unchanged. 1183221Smarcel * 2. Redistributions in binary form must reproduce the above copyright 1283221Smarcel * notice, this list of conditions and the following disclaimer in the 1383221Smarcel * documentation and/or other materials provided with the distribution. 1483221Smarcel * 3. The name of the author may not be used to endorse or promote products 1583221Smarcel * derived from this software without specific prior written permission. 1683221Smarcel * 1783221Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1883221Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1983221Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2083221Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2183221Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2283221Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2383221Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2483221Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2583221Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2683221Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2783221Smarcel * 2883221Smarcel * $FreeBSD: head/sys/compat/linux/linux_sysctl.c 83366 2001-09-12 08:38:13Z julian $ 2983221Smarcel */ 3083221Smarcel 3183221Smarcel#include "opt_compat.h" 3283221Smarcel 3383221Smarcel#include <sys/param.h> 3483221Smarcel#include <sys/systm.h> 3583221Smarcel#include <sys/proc.h> 3683221Smarcel#include <sys/sysproto.h> 3783221Smarcel 3883221Smarcel#include <machine/../linux/linux.h> 3983221Smarcel#include <machine/../linux/linux_proto.h> 4083221Smarcel#include <compat/linux/linux_util.h> 4183221Smarcel 4283221Smarcel#define LINUX_CTL_KERN 1 4383221Smarcel#define LINUX_CTL_VM 2 4483221Smarcel#define LINUX_CTL_NET 3 4583221Smarcel#define LINUX_CTL_PROC 4 4683221Smarcel#define LINUX_CTL_FS 5 4783221Smarcel#define LINUX_CTL_DEBUG 6 4883221Smarcel#define LINUX_CTL_DEV 7 4983221Smarcel#define LINUX_CTL_BUS 8 5083221Smarcel 5183221Smarcel/* CTL_KERN names */ 5283221Smarcel#define LINUX_KERN_OSTYPE 1 5383221Smarcel#define LINUX_KERN_OSRELEASE 2 5483221Smarcel#define LINUX_KERN_OSREV 3 5583221Smarcel#define LINUX_KERN_VERSION 4 5683221Smarcel 5783221Smarcelstatic int 5883221Smarcelhandle_string(struct l___sysctl_args *la, char *value) 5983221Smarcel{ 6083221Smarcel int error; 6183221Smarcel 6283221Smarcel if (la->oldval != NULL) { 6383221Smarcel l_int len = strlen(value); 6483221Smarcel error = copyout(value, la->oldval, len + 1); 6583221Smarcel if (!error && la->oldlenp != NULL) 6683221Smarcel error = copyout(&len, la->oldlenp, sizeof(len)); 6783221Smarcel if (error) 6883221Smarcel return (error); 6983221Smarcel } 7083221Smarcel 7183221Smarcel if (la->newval != NULL) 7283221Smarcel return (ENOTDIR); 7383221Smarcel 7483221Smarcel return (0); 7583221Smarcel} 7683221Smarcel 7783221Smarcelint 7883366Sjulianlinux_sysctl(struct thread *td, struct linux_sysctl_args *args) 7983221Smarcel{ 8083221Smarcel struct l___sysctl_args la; 8183221Smarcel l_int *mib; 8283221Smarcel int error, i; 8383221Smarcel caddr_t sg; 8483221Smarcel 8583221Smarcel error = copyin((caddr_t)args->args, &la, sizeof(la)); 8683221Smarcel if (error) 8783221Smarcel return (error); 8883221Smarcel 8983221Smarcel if (la.nlen == 0 || la.nlen > LINUX_CTL_MAXNAME) 9083221Smarcel return (ENOTDIR); 9183221Smarcel 9283221Smarcel sg = stackgap_init(); 9383221Smarcel mib = stackgap_alloc(&sg, la.nlen * sizeof(l_int)); 9483221Smarcel error = copyin(la.name, mib, la.nlen * sizeof(l_int)); 9583221Smarcel if (error) 9683221Smarcel return (error); 9783221Smarcel 9883221Smarcel switch (mib[0]) { 9983221Smarcel case LINUX_CTL_KERN: 10083221Smarcel if (la.nlen < 2) 10183221Smarcel break; 10283221Smarcel 10383221Smarcel switch (mib[1]) { 10483221Smarcel case LINUX_KERN_VERSION: 10583221Smarcel return (handle_string(&la, version)); 10683221Smarcel default: 10783221Smarcel break; 10883221Smarcel } 10983221Smarcel break; 11083221Smarcel default: 11183221Smarcel break; 11283221Smarcel } 11383221Smarcel 11483221Smarcel printf("linux: sysctl: unhandled name="); 11583221Smarcel for (i = 0; i < la.nlen; i++) 11683221Smarcel printf("%c%d", (i) ? ',' : '{', mib[i]); 11783221Smarcel printf("}\n"); 11883221Smarcel 11983221Smarcel return (ENOTDIR); 12083221Smarcel} 121