Removed sysctl(), there is no need for this BSD-ish call.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17954 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -284,10 +284,6 @@ extern int64 _kern_atomic_or64(vint64 *value, int64 orValue);
|
||||
extern int64 _kern_atomic_get64(vint64 *value);
|
||||
#endif // ATOMIC64_FUNCS_ARE_SYSCALLS
|
||||
|
||||
int sys_sysctl(int *name, uint namlen, void *oldp, size_t *oldlen,
|
||||
void *newp, size_t newlen);
|
||||
int sys_socket(int family, int type, int proto);
|
||||
|
||||
/* System informations */
|
||||
extern status_t _kern_get_system_info(system_info *info, size_t size);
|
||||
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/* sysctl.h
|
||||
* should really be installed as sys/sysctl.h
|
||||
*/
|
||||
|
||||
#ifndef _SYS_SYSCTL_H
|
||||
#define _SYS_SYSCTL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* This file contains definitions for the sysctl call.
|
||||
* The call uses a heirachy of names for objects that can be
|
||||
* examined or modified. The name is expressed as a sequence
|
||||
* of integers and works in a similar manner to a filename, ie each
|
||||
* component is dependant upon it's place in the heirachy.
|
||||
*
|
||||
* NB this file defines only the top level and kernel level (_KERN)
|
||||
* identifiers with others being defined in files specific to
|
||||
* the subsystem concerned.
|
||||
*/
|
||||
|
||||
#define CTL_MAXNAME 12 /* This is the largest no. of components we support */
|
||||
|
||||
/* Each subsystem defines a list of variables for that subsystem.
|
||||
* The name can either be:
|
||||
* - a node that has further levels defined below it, or
|
||||
* - a leaf in a particular type.
|
||||
* Each level of sysctl has a set of name/type pairs used when manipulating
|
||||
* that level.
|
||||
*/
|
||||
|
||||
struct ctlname {
|
||||
char *ctl_name; /* the subsystem name */
|
||||
int ctl_type; /* type of name */
|
||||
};
|
||||
|
||||
#define CTLTYPE_NODE 1 /* it's a node */
|
||||
#define CTLTYPE_INT 2 /* integer */
|
||||
#define CTLTYPE_STRING 3 /* string */
|
||||
#define CTLTYPE_QUAD 4 /* 64-bit number */
|
||||
#define CTLTYPE_STRUCT 5 /* it's a structure */
|
||||
|
||||
/* The top level identifiers we support */
|
||||
#define CTL_UNSPEC 0 /* unused */
|
||||
#define CTL_KERN 1 /* Kernel level */
|
||||
#define CTL_VM 2 /* VM */
|
||||
#define CTL_FS 3 /* Filesystem */
|
||||
#define CTL_NET 4 /* networking (socket.h) */
|
||||
#define CTL_HW 5 /* hardware */
|
||||
|
||||
#define CTL_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "kern", CTLTYPE_NODE }, \
|
||||
{ "vm" , CTLTYPE_NODE }, \
|
||||
{ "fs" , CTLTYPE_NODE }, \
|
||||
{ "net" , CTLTYPE_NODE }, \
|
||||
{ "hardware", CTL_TYPE_NODE }, \
|
||||
}
|
||||
|
||||
/* Identifiers for use in the CTL_KERN subsystem */
|
||||
#define KERN_OSTYPE 1 /* string: system type string */
|
||||
#define KERN_OSRELEASE 2 /* string: system release */
|
||||
#define KERN_OSVERSION 3 /* int: system revision */
|
||||
#define KERN_HOSTNAME 4 /* string: hostname of system */
|
||||
#define KERN_DOMAINNAME 5 /* string: (YP) domain name */
|
||||
#define KERN_VERSION 6 /* string: system version string */
|
||||
|
||||
#define CTL_KERN_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "ostype" , CTLTYPE_STRING }, \
|
||||
{ "osrelease" , CTLTYPE_STRING }, \
|
||||
{ "osversion" , CTLTYPE_STRING }, \
|
||||
{ "hostname" , CTLTYPE_STRING }, \
|
||||
{ "domainname" , CTLTYPE_STRING }, \
|
||||
{ "version" , CTLTYPE_STRING }, \
|
||||
}
|
||||
|
||||
/*
|
||||
* CTL_HW identifiers
|
||||
*/
|
||||
#define HW_MACHINE 1 /* string: machine class */
|
||||
#define HW_MODEL 2 /* string: specific machine model */
|
||||
#define HW_NCPU 3 /* int: number of cpus */
|
||||
#define HW_BYTEORDER 4 /* int: machine byte order */
|
||||
#define HW_PHYSMEM 5 /* int: total memory */
|
||||
#define HW_USERMEM 6 /* int: non-kernel memory */
|
||||
#define HW_PAGESIZE 7 /* int: software page size */
|
||||
#define HW_DISKNAMES 8 /* strings: disk drive names */
|
||||
#define HW_DISKSTATS 9 /* struct: diskstats[] */
|
||||
#define HW_DISKCOUNT 10 /* int: number of disks */
|
||||
#define HW_MAXID 11 /* number of valid hw ids */
|
||||
|
||||
#define CTL_HW_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "machine", CTLTYPE_STRING }, \
|
||||
{ "model", CTLTYPE_STRING }, \
|
||||
{ "ncpu", CTLTYPE_INT }, \
|
||||
{ "byteorder", CTLTYPE_INT }, \
|
||||
{ "physmem", CTLTYPE_INT }, \
|
||||
{ "usermem", CTLTYPE_INT }, \
|
||||
{ "pagesize", CTLTYPE_INT }, \
|
||||
{ "disknames", CTLTYPE_STRING }, \
|
||||
{ "diskstats", CTLTYPE_STRUCT }, \
|
||||
{ "diskcount", CTLTYPE_INT }, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
int _user_sysctl(int *, uint, void *, size_t *, void *, size_t);
|
||||
#endif
|
||||
|
||||
int sysctl(int *, uint, void *, size_t *, void *, size_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_SYSCTL_H */
|
||||
|
||||
@@ -33,7 +33,6 @@ KernelMergeObject kernel_core.o :
|
||||
system_info.c
|
||||
smp.c
|
||||
syscalls.c
|
||||
sysctl.c
|
||||
team.c
|
||||
thread.c
|
||||
timer.c
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2005, Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2006, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <sys/resource.h>
|
||||
#include <fs/fd.h>
|
||||
#include <fs/node_monitor.h>
|
||||
#include <sysctl.h>
|
||||
#include <kimage.h>
|
||||
#include <ksignal.h>
|
||||
#include <real_time_clock.h>
|
||||
|
||||
@@ -1,269 +0,0 @@
|
||||
// ToDo: do we really need sysctl? And if so, for what?
|
||||
// It is not part of the POSIX spec.
|
||||
|
||||
#include <kernel.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <vm.h>
|
||||
#include <debug.h>
|
||||
#include <malloc.h>
|
||||
#include <sysctl.h>
|
||||
#include <KernelExport.h>
|
||||
#include <Errors.h>
|
||||
|
||||
/* Not sure where to put this definition yet (sys/param.h?),
|
||||
* so just add it here
|
||||
* XXX - horrible hack!
|
||||
*/
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
# define MAXHOSTNAMELEN 256 /* max hostname size */
|
||||
#endif
|
||||
|
||||
/* This is the place we store a few of the "global variables" that the OS
|
||||
* needs.
|
||||
*/
|
||||
char hostname[MAXHOSTNAMELEN] = "openbeos\0";
|
||||
int hostnamelen = 9;
|
||||
char domainname[MAXHOSTNAMELEN] = "rocks.my.world.com\0";
|
||||
int domainnamelen = 19;
|
||||
|
||||
/* These really don't belong here, but just for the moment until we figure out where
|
||||
* these should live...
|
||||
*/
|
||||
|
||||
char ostype[] = "OpenBeOS";
|
||||
char osrelease[] = "0.01";
|
||||
char osversion[] = "alpha";
|
||||
char version[] = "0.0.1";
|
||||
char kernel[] = "DEV";
|
||||
|
||||
char machine[] = "Intel";
|
||||
char model[] = "MODEL";
|
||||
|
||||
|
||||
typedef int (sysctlfn)(int *, uint, void *, size_t *, void *, size_t);
|
||||
|
||||
// currently unused
|
||||
#if 0
|
||||
static int
|
||||
sysctl_int(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int *valp)
|
||||
{
|
||||
if (oldp && *oldlenp < sizeof(int))
|
||||
return ENOMEM;
|
||||
if (newp && newlen != sizeof(int))
|
||||
return EINVAL;
|
||||
|
||||
*oldlenp = sizeof(int);
|
||||
if (oldp)
|
||||
*(int*)oldp = *valp;
|
||||
if (newp)
|
||||
*valp = *(int*)newp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sysctl_rdint(void *oldp, size_t *oldlenp, void *newp, int val)
|
||||
{
|
||||
if (oldp && *oldlenp < sizeof(int))
|
||||
return ENOMEM;
|
||||
if (newp)
|
||||
return EPERM;
|
||||
|
||||
*oldlenp = sizeof(int);
|
||||
if (oldp)
|
||||
*(int*)oldp = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
sysctl__string(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
|
||||
char *str, size_t maxlen, int trunc)
|
||||
{
|
||||
size_t len = strlen(str) + 1;
|
||||
int c;
|
||||
|
||||
if (oldp && *oldlenp < len) {
|
||||
if (trunc == 0 || *oldlenp == 0)
|
||||
return ENOMEM;
|
||||
}
|
||||
if (newp && newlen >= maxlen)
|
||||
return EINVAL;
|
||||
|
||||
if (oldp) {
|
||||
if (trunc && *oldlenp < len) {
|
||||
/* need to truncate */
|
||||
c = str[*oldlenp - 1];
|
||||
str[*oldlenp - 1] = '\0';
|
||||
memcpy(oldp, str, *oldlenp);
|
||||
str[*oldlenp - 1] = c;
|
||||
} else {
|
||||
/* just copy */
|
||||
*oldlenp = len;
|
||||
memcpy(oldp, str, len);
|
||||
}
|
||||
}
|
||||
if (newp) {
|
||||
memcpy(str, newp, newlen);
|
||||
str[newlen] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Copy string, truncating if required */
|
||||
|
||||
static int
|
||||
sysctl_tstring(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str, int maxlen)
|
||||
{
|
||||
return sysctl__string(oldp, oldlenp, newp, newlen, str, maxlen, 1);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, char *str)
|
||||
{
|
||||
size_t len = strlen(str) + 1;
|
||||
if (oldp && *oldlenp < len)
|
||||
return ENOMEM;
|
||||
if (newp)
|
||||
return EPERM;
|
||||
*oldlenp = len;
|
||||
if (oldp)
|
||||
memcpy(oldp, str, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sys_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (name[0]) {
|
||||
case KERN_OSTYPE:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, ostype);
|
||||
case KERN_OSRELEASE:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, osrelease);
|
||||
case KERN_OSVERSION:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, osversion);
|
||||
case KERN_HOSTNAME:
|
||||
error = sysctl_tstring(oldp, oldlenp, newp, newlen,
|
||||
hostname, sizeof(hostname));
|
||||
if (newp && !error)
|
||||
hostnamelen = newlen;
|
||||
return (error);
|
||||
case KERN_DOMAINNAME:
|
||||
error = sysctl_tstring(oldp, oldlenp, newp, newlen,
|
||||
domainname, sizeof(domainname));
|
||||
if (newp && !error)
|
||||
domainnamelen = newlen;
|
||||
return (error);
|
||||
case KERN_VERSION:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, kernel);
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
/* If we get here we're in trouble... */
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
hw_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
|
||||
{
|
||||
switch (name[0]) {
|
||||
case HW_MACHINE:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, machine);
|
||||
case HW_MODEL:
|
||||
return sysctl_rdstring(oldp, oldlenp, newp, model);
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
/* If we get here we're in trouble... */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
|
||||
{
|
||||
sysctlfn *fn = NULL;
|
||||
int error = 0;
|
||||
|
||||
switch (name[0]) {
|
||||
case CTL_KERN:
|
||||
fn = sys_sysctl;
|
||||
break;
|
||||
case CTL_HW:
|
||||
fn = hw_sysctl;
|
||||
break;
|
||||
default:
|
||||
dprintf("sysctl: no suppport added yet for %d\n", name[0]);
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
error = (fn)(name + 1, namelen - 1, oldp, oldlenp, newp, newlen);
|
||||
|
||||
return B_NO_ERROR;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_user_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
{
|
||||
void *a1 = NULL, *a2 = NULL;
|
||||
int *nam = NULL, rc;
|
||||
size_t olen = *oldlenp, *ov=NULL;
|
||||
|
||||
if (namelen < 2 || namelen > CTL_MAXNAME)
|
||||
return EINVAL;
|
||||
|
||||
if (name && namelen > 0) {
|
||||
nam = (int *)malloc(namelen * sizeof(int));
|
||||
if (!nam)
|
||||
return ENOMEM;
|
||||
user_memcpy(nam, name, namelen * sizeof(int));
|
||||
}
|
||||
if (oldp && oldlenp) {
|
||||
a1 = malloc(olen);
|
||||
user_memcpy(a1, oldp, olen);
|
||||
}
|
||||
if (oldlenp) {
|
||||
ov = (size_t*)malloc(sizeof(oldlenp));
|
||||
user_memcpy(ov, oldlenp, sizeof(oldlenp));
|
||||
}
|
||||
if (newp && newlen > 0) {
|
||||
a2 = malloc(newlen);
|
||||
user_memcpy(a2, newp, newlen);
|
||||
}
|
||||
|
||||
rc = sysctl(nam, namelen, a1, ov, a2, newlen);
|
||||
|
||||
if (nam)
|
||||
free(nam);
|
||||
|
||||
if (rc != 0)
|
||||
goto bailout;
|
||||
|
||||
/* We don't need to copy back the name settings as they won't have changed. */
|
||||
if (oldp && *ov > 0) {
|
||||
memcpy(oldp, a1, *ov);
|
||||
memcpy(oldlenp, ov, sizeof(oldlenp));
|
||||
}
|
||||
if (newp && newlen > 0) {
|
||||
/* We passed namelen thru so don't worry about updating it here... */
|
||||
memcpy(newp, a2, newlen);
|
||||
}
|
||||
|
||||
bailout:
|
||||
free(a1);
|
||||
free(a2);
|
||||
free(ov);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ MergeObject posix_sys.o :
|
||||
select.c
|
||||
stat.c
|
||||
statvfs.c
|
||||
sysctl.c
|
||||
times.c
|
||||
uio.c
|
||||
umask.c
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
** Copyright 2002, Axel Dörfler, [email protected]. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
#include <sysctl.h>
|
||||
#include <errno.h>
|
||||
#include "syscalls.h"
|
||||
|
||||
|
||||
#define RETURN_AND_SET_ERRNO(err) \
|
||||
if (err < 0) { \
|
||||
errno = err; \
|
||||
return -1; \
|
||||
} \
|
||||
return err;
|
||||
|
||||
|
||||
int
|
||||
sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
|
||||
{
|
||||
/* ToDo: we should handle CTL_USER here, but as we don't even define it yet :) */
|
||||
int err = sys_sysctl(name, namelen, oldp, oldlenp, newp, newlen);
|
||||
|
||||
RETURN_AND_SET_ERRNO(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user