Adding sysctl command line tool
This commit is contained in:
parent
ae809dd23a
commit
afd9cdc068
@ -64,6 +64,7 @@ if env["WITH_GPROF"] == "1":
|
||||
env.Append(CPPFLAGS = [ "-pg" ])
|
||||
env.Append(LINKFLAGS = [ "-pg" ])
|
||||
|
||||
env.Append(CPPFLAGS = "-DBUILDTYPE=" + env["BUILDTYPE"])
|
||||
if env["BUILDTYPE"] == "DEBUG":
|
||||
env.Append(CPPFLAGS = [ "-g", "-DDEBUG", "-Wall",
|
||||
"-Wno-deprecated-declarations" ])
|
||||
@ -175,6 +176,7 @@ SConscript('bin/ethinject/SConscript', variant_dir='build/bin/ethinject')
|
||||
SConscript('bin/shell/SConscript', variant_dir='build/bin/shell')
|
||||
SConscript('sbin/ifconfig/SConscript', variant_dir='build/sbin/ifconfig')
|
||||
SConscript('sbin/init/SConscript', variant_dir='build/sbin/init')
|
||||
SConscript('sbin/sysctl/SConscript', variant_dir='build/sbin/sysctl')
|
||||
SConscript('tests/SConscript', variant_dir='build/tests')
|
||||
|
||||
# Build Tools
|
||||
@ -199,6 +201,7 @@ if env["BOOTDISK"] == "1":
|
||||
Depends(bootdisk, "#build/bin/shell/shell")
|
||||
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
|
||||
Depends(bootdisk, "#build/sbin/init/init")
|
||||
Depends(bootdisk, "#build/sbin/sysctl/sysctl")
|
||||
Depends(bootdisk, "#build/sys/castor")
|
||||
Depends(bootdisk, "#build/tests/lwiptest")
|
||||
Depends(bootdisk, "#build/tests/pthreadtest")
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/nic.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
uint64_t OSTime();
|
||||
uint64_t OSGetPID();
|
||||
@ -40,5 +41,11 @@ int OSNICStat(uint64_t nicNo, NIC *nic);
|
||||
int OSNICSend(uint64_t nicNo, MBuf *mbuf);
|
||||
int OSNICRecv(uint64_t nicNo, MBuf *mbuf);
|
||||
|
||||
// System
|
||||
int OSSysCtl(const char *node, void *oldval, void *newval);
|
||||
int OSFSMount(const char *mntpt, const char *device, uint64_t flags);
|
||||
int OSFSUnmount(const char *mntpt);
|
||||
int OSFSInfo(struct statfs *info, uint64_t max);
|
||||
|
||||
#endif /* __SYSCALL_H__ */
|
||||
|
||||
|
@ -145,3 +145,27 @@ OSNICRecv(uint64_t nicNo, MBuf *mbuf)
|
||||
return syscall(SYSCALL_NICRECV, nicNo, mbuf);
|
||||
}
|
||||
|
||||
int
|
||||
OSSysCtl(const char *node, void *oldvar, void *newvar)
|
||||
{
|
||||
return syscall(SYSCALL_SYSCTL, node, oldvar, newvar);
|
||||
}
|
||||
|
||||
int
|
||||
OS_FSMount(const char *mntpt, const char *device, uint64_t flags)
|
||||
{
|
||||
return syscall(SYSCALL_FSMOUNT, mntpt, device, flags);
|
||||
}
|
||||
|
||||
int
|
||||
OS_FSUnmount(const char *mntpt)
|
||||
{
|
||||
return syscall(SYSCALL_FSUNMOUNT, mntpt);
|
||||
}
|
||||
|
||||
int
|
||||
OS_FSInfo(struct statfs *info, uint64_t max)
|
||||
{
|
||||
return syscall(SYSCALL_FSINFO, info, max);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ DIR /
|
||||
DIR sbin
|
||||
FILE ifconfig build/sbin/ifconfig/ifconfig
|
||||
FILE init build/sbin/init/init
|
||||
FILE sysctl build/sbin/sysctl/sysctl
|
||||
END
|
||||
DIR tests
|
||||
FILE lwiptest build/tests/lwiptest
|
||||
|
23
sbin/sysctl/SConscript
Normal file
23
sbin/sysctl/SConscript
Normal file
@ -0,0 +1,23 @@
|
||||
import sys
|
||||
|
||||
Import('env')
|
||||
|
||||
sysctl_env = env.Clone()
|
||||
|
||||
src = [ ]
|
||||
|
||||
src_common = [
|
||||
"sysctl.c"
|
||||
]
|
||||
|
||||
src.append(env["CRTBEGIN"])
|
||||
src.append(src_common)
|
||||
src.append(env["CRTEND"])
|
||||
|
||||
sysctl_env.Append(LINKFLAGS = ['-nostdlib'])
|
||||
sysctl_env.Append(CPPFLAGS = ['-nostdinc'])
|
||||
sysctl_env.Append(CPPPATH = ['#build/include'])
|
||||
sysctl_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
|
||||
|
||||
sysctl_env.Program("sysctl", src)
|
||||
|
77
sbin/sysctl/sysctl.c
Normal file
77
sbin/sysctl/sysctl.c
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
typedef struct SysCtlEntry {
|
||||
char path[64];
|
||||
int type;
|
||||
int flags;
|
||||
char description[128];
|
||||
} SysCtlEntry;
|
||||
|
||||
#define SYSCTL_STR(_PATH, _FLAGS, _DESCRIPTION, _DEFAULT) \
|
||||
{ #_PATH, SYSCTL_TYPE_STR, _FLAGS, _DESCRIPTION },
|
||||
#define SYSCTL_INT(_PATH, _FLAGS, _DESCRIPTION, _DEFAULT) \
|
||||
{ #_PATH, SYSCTL_TYPE_INT, _FLAGS, _DESCRIPTION },
|
||||
#define SYSCTL_BOOL(_PATH, _FLAGS, _DESCRIPTION, _DEFAULT) \
|
||||
{ #_PATH, SYSCTL_TYPE_BOOL, _FLAGS, _DESCRIPTION },
|
||||
SysCtlEntry SYSCTLTable[] = {
|
||||
SYSCTL_LIST
|
||||
{ "", 0, 0, "" },
|
||||
};
|
||||
#undef SYSCTL_STR
|
||||
#undef SYSCTL_INT
|
||||
#undef SYSCTL_BOOL
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
int i;
|
||||
uint64_t status;
|
||||
|
||||
printf("%d\n", argc);
|
||||
if (true) {
|
||||
printf("%-20s %s\n", "Name", "Description");
|
||||
for (i = 0; SYSCTLTable[i].type != 0; i++) {
|
||||
printf("%-20s %s\n",
|
||||
SYSCTLTable[i].path,
|
||||
SYSCTLTable[i].description);
|
||||
}
|
||||
}
|
||||
|
||||
if (false) {
|
||||
printf("Usage: sysctl [NODE] [VALUE]\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; SYSCTLTable[i].type != 0; i++) {
|
||||
SysCtlString scStr;
|
||||
SysCtlInt scInt;
|
||||
SysCtlBool scBool;
|
||||
|
||||
switch (SYSCTLTable[i].type) {
|
||||
case SYSCTL_TYPE_STR:
|
||||
OSSysCtl(SYSCTLTable[i].path, &scStr, NULL);
|
||||
printf("%s: %s\n", SYSCTLTable[i].path, scStr.value);
|
||||
break;
|
||||
case SYSCTL_TYPE_INT:
|
||||
OSSysCtl(SYSCTLTable[i].path, &scInt, NULL);
|
||||
printf("%s: %ld\n", SYSCTLTable[i].path, scInt.value);
|
||||
break;
|
||||
case SYSCTL_TYPE_BOOL:
|
||||
OSSysCtl(SYSCTLTable[i].path, &scBool, NULL);
|
||||
printf("%s: %s\n", SYSCTLTable[i].path,
|
||||
scBool.value ? "true" : "false");
|
||||
break;
|
||||
default:
|
||||
printf("%s: Unsupported type\n", SYSCTLTable[i].path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
13
sys/include/mount.h
Normal file
13
sys/include/mount.h
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#ifndef __SYS_MOUNT_H__
|
||||
#define __SYS_MOUNT_H__
|
||||
|
||||
struct statfs {
|
||||
};
|
||||
|
||||
#define MNT_RDONLY 0x0001 /* Read-only */
|
||||
#define MNT_SYNC 0x0002 /* Synchronous */
|
||||
#define MNT_ASYNC 0x0004 /* Asynchronous */
|
||||
|
||||
#endif /* __SYS_MOUNT_H__ */
|
||||
|
@ -40,6 +40,12 @@
|
||||
#define SYSCALL_NICSEND 0x41
|
||||
#define SYSCALL_NICRECV 0x42
|
||||
|
||||
// System
|
||||
#define SYSCALL_SYSCTL 0x80
|
||||
#define SYSCALL_FSMOUNT 0x81
|
||||
#define SYSCALL_FSUNMOUNT 0x82
|
||||
#define SYSCALL_FSINFO 0x83
|
||||
|
||||
uint64_t Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
|
||||
uint64_t a3, uint64_t a4, uint64_t a5);
|
||||
|
||||
|
@ -12,6 +12,11 @@
|
||||
* SYSCTL_END()
|
||||
*/
|
||||
|
||||
#define SYSCTL_TYPE_INVALID 0
|
||||
#define SYSCTL_TYPE_STR 1
|
||||
#define SYSCTL_TYPE_INT 2
|
||||
#define SYSCTL_TYPE_BOOL 3
|
||||
|
||||
#define SYSCTL_FLAG_RO 1
|
||||
#define SYSCTL_FLAG_RW 2
|
||||
|
||||
@ -58,5 +63,8 @@ SYSCTL_LIST
|
||||
#define SYSCTL_GETBOOL(_PATH) SYSCTL_##_PATH.value
|
||||
#define SYSCTL_SETBOOL(_PATH, _VALUE) SYSCTL_##_PATH.value = _VALUE
|
||||
|
||||
uint64_t SysCtl_GetType(const char *node);
|
||||
void *SysCtl_GetObject(const char *node);
|
||||
|
||||
#endif /* __SYS_SYSCTL_H__ */
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/vfsuio.h>
|
||||
#include <sys/nic.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
Handle *Console_OpenHandle();
|
||||
|
||||
@ -531,6 +532,68 @@ Syscall_NICRecv(uint64_t nicNo, uint64_t user_mbuf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_SysCtl(uint64_t user_node, uint64_t user_oldval, uint64_t user_newval)
|
||||
{
|
||||
uint64_t status;
|
||||
char node[64];
|
||||
|
||||
status = CopyStrIn(user_node, &node, sizeof(node));
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
uint64_t scType = SysCtl_GetType(node);
|
||||
if (scType == SYSCTL_TYPE_INVALID) {
|
||||
return SYSCALL_PACK(ENOENT, 0);
|
||||
}
|
||||
|
||||
switch (scType) {
|
||||
case SYSCTL_TYPE_STR: {
|
||||
SysCtlString *scStr = SysCtl_GetObject(node);
|
||||
status = CopyOut(scStr, user_oldval, sizeof(*scStr));
|
||||
break;
|
||||
}
|
||||
case SYSCTL_TYPE_INT: {
|
||||
SysCtlInt *scInt = SysCtl_GetObject(node);
|
||||
status = CopyOut(scInt, user_oldval, sizeof(*scInt));
|
||||
break;
|
||||
}
|
||||
case SYSCTL_TYPE_BOOL: {
|
||||
SysCtlBool *scBool = SysCtl_GetObject(node);
|
||||
status = CopyOut(scBool, user_oldval, sizeof(scBool));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = SYSCALL_PACK(ENOENT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// XXX: Support setting
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_FSMount(uint64_t user_mntpt, uint64_t user_device, uint64_t flags)
|
||||
{
|
||||
return SYSCALL_PACK(ENOSYS, 0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_FSUnmount(uint64_t user_mntpt)
|
||||
{
|
||||
return SYSCALL_PACK(ENOSYS, 0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_FSInfo(uint64_t user_fsinfo, uint64_t max)
|
||||
{
|
||||
return SYSCALL_PACK(ENOSYS, 0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
|
||||
uint64_t a3, uint64_t a4, uint64_t a5)
|
||||
@ -587,6 +650,14 @@ Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
|
||||
return Syscall_NICSend(a1, a2);
|
||||
case SYSCALL_NICRECV:
|
||||
return Syscall_NICRecv(a1, a2);
|
||||
case SYSCALL_SYSCTL:
|
||||
return Syscall_SysCtl(a1, a2, a3);
|
||||
case SYSCALL_FSMOUNT:
|
||||
return Syscall_FSMount(a1, a2, a3);
|
||||
case SYSCALL_FSUNMOUNT:
|
||||
return Syscall_FSUnmount(a1);
|
||||
case SYSCALL_FSINFO:
|
||||
return Syscall_FSInfo(a1, a2);
|
||||
default:
|
||||
return (uint64_t)-1;
|
||||
}
|
||||
|
@ -7,10 +7,6 @@
|
||||
#include <sys/kdebug.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#define SYSCTL_TYPE_STR 1
|
||||
#define SYSCTL_TYPE_INT 2
|
||||
#define SYSCTL_TYPE_BOOL 3
|
||||
|
||||
typedef struct SysCtlEntry {
|
||||
char path[64];
|
||||
int type;
|
||||
@ -57,6 +53,28 @@ SysCtl_Lookup(const char *path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
SysCtl_GetType(const char *node)
|
||||
{
|
||||
int i = SysCtl_Lookup(node);
|
||||
if (i == -1) {
|
||||
return SYSCTL_TYPE_INVALID;
|
||||
}
|
||||
|
||||
return SYSCTLTable[i].type;
|
||||
}
|
||||
|
||||
void *
|
||||
SysCtl_GetObject(const char *node)
|
||||
{
|
||||
int i = SysCtl_Lookup(node);
|
||||
if (i == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SYSCTLTable[i].node;
|
||||
}
|
||||
|
||||
void
|
||||
Debug_SysCtl(int argc, const char *argv[])
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user