kern_sysctl.c
ubixos/types.h
sys/sysproto.h
sys/thread.h
sys/kern_sysctl.h
ubixos/endtask.h
ubixos/kpanic.h
lib/kprintf.h
lib/kmalloc.h
assert.h
string.h
sys/thread.h
ubixos/kpanic.h
ubixos/sched.h
ubixos/endtask.h
src/sys/kernel/kern_sysctl.c
ubixos/types.h
sys/_types.h
string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
sys/kern_sysctl.h
vfs/mount.h
lib/kprintf.h
assert.h
ubixfs/dirCache.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
int int __sysctl (struct thread *td, struct sysctl_args *uap) __sysctl struct thread * td struct sysctl_args * uap _current ctls endTask taskStruct::id K_PANIC kprintf memcpy sysctl_args::name sysctl_args::namelen sysctl_args::newlen sysctl_args::old sysctl_args::oldlenp sysctl_find thread::td_retval sysctl_entry::val_len sysctl_entry::value
void static void def_ctls () def_ctls CTL_MAXNAME name sysctl_add sysctl_init
int int sysctl_add (int *name, int namelen, char *str_name, void *buf, int buf_size) sysctl_add int * name int namelen char * str_name void * buf int buf_size sysctl_entry::children sysctl_entry::id kmalloc kprintf memcpy sysctl_entry::name sysctl_entry::next sysctl_entry::prev sprintf sysctl_find sysctl_entry::val_len sysctl_entry::value def_ctls
struct sysctl_entry * static struct sysctl_entry * sysctl_find (int *, int) sysctl_find int * name int namelen sysctl_entry::children ctls sysctl_entry::id sysctl_entry::next __sysctl sysctl_add
int int sysctl_init () sysctl_init sysctl_entry::children CTL_DEBUG CTL_HW CTL_KERN CTL_MACHDEP CTL_NET CTL_P1003_1B CTL_UBIX CTL_UNSPEC CTL_USER CTL_VFS CTL_VM ctls def_ctls sysctl_entry::id kmalloc kprintf sysctl_entry::name sysctl_entry::next sysctl_entry::prev sprintf
struct sysctl_entry * struct sysctl_entry* ctls ctls 0x0 __sysctl sysctl_find sysctl_init

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: kern__sysctl_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<ubixos/types.h>
    #include<sys/sysproto.h>
    #include<sys/thread.h>
    #include<sys/kern_sysctl.h>
    #include<ubixos/endtask.h>
    #include<ubixos/kpanic.h>
    #include<lib/kprintf.h>
    #include<lib/kmalloc.h>
    #include<assert.h>
    #include<string.h>

    staticstructsysctl_entry*ctls=0x0;

    staticstructsysctl_entry*sysctl_find(int*,int);

    /*Thisisacheatfornow*/
    staticvoiddef_ctls(){
    intname[CTL_MAXNAME],name_len;
    uInt32page_val=0x1000;
    name[0]=6;
    name[1]=7;
    name_len=2;
    sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32));
    /*ClockRate*/
    name[0]=1;
    name[1]=12;
    page_val=0x3E8;
    sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32));
    /*UserStack*/
    name[0]=1;
    name[1]=33;
    page_val=0xCBE8000;
    sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32));
    }

    intsysctl_init(){
    structsysctl_entry*tmpCtl=0x0;
    if(ctls!=0x0){
    kprintf("sysctlalreadyInitialized\n");
    while(1);
    }

    ctls=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    ctls->prev=0x0;
    ctls->id=CTL_UNSPEC;
    ctls->children=0x0;
    sprintf(ctls->name,"unspec");

    tmpCtl=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->prev=ctls;
    tmpCtl->id=CTL_KERN;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"kern");
    ctls->next=tmpCtl;

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_VM;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"vm");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_VFS;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"vfs");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_NET;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"net");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_DEBUG;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"debug");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_HW;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"hw");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_MACHDEP;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"machdep");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_USER;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"user");

    tmpCtl->next=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_P1003_1B;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"p1003_1b");

    tmpCtl->next=(structsysctl_enctry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->next->prev=tmpCtl;
    tmpCtl=tmpCtl->next;
    tmpCtl->id=CTL_UBIX;
    tmpCtl->children=0x0;
    sprintf(tmpCtl->name,"ubix");

    def_ctls();

    return(0x0);
    }

    int__sysctl(structthread*td,structsysctl_args*uap){
    structsysctl_entry*tmpCtl=0x0;
    inti=0;

    if(ctls==0x0)
    K_PANIC("sysctlnotinitialized");

    if(uap->newlen<0){
    kprintf("ChangingNotsupportedyet.\n");
    endTask(_current->id);
    }

    tmpCtl=sysctl_find(uap->name,uap->namelen);
    if(tmpCtl==0x0){
    kprintf("InvalidCTL\n");
    for(i=0x0;i<uap->namelen;i++)
    kprintf("(%i)",uap->name[i]);
    kprintf("\n");
    endTask(_current->id);
    }

    if((uint32_t)uap->oldlenp<tmpCtl->val_len)
    memcpy(uap->old,tmpCtl->value,(uInt32)uap->oldlenp);
    else
    memcpy(uap->old,tmpCtl->value,tmpCtl->val_len);

    td->td_retval[0]=0x0;

    return(0x0);
    }

    staticstructsysctl_entry*sysctl_find(int*name,intnamelen){
    inti=0x0;
    structsysctl_entry*tmpCtl=0x0;
    structsysctl_entry*lCtl=ctls;

    /*LoopNameLen*/
    for(i=0x0;i<namelen;i++){
    for(tmpCtl=lCtl;tmpCtl!=0x0;tmpCtl=tmpCtl->next){
    //kprintf("ctlName:[%s],ctlId;[%i]\n",tmpCtl->name,tmpCtl->id);
    if(tmpCtl->id==name[i]){
    if((i+1)==namelen){
    return(tmpCtl);
    }
    lCtl=tmpCtl->children;
    break;
    }
    }
    }
    return(0x0);
    }

    intsysctl_add(int*name,intnamelen,char*str_name,void*buf,intbuf_size){
    structsysctl_entry*tmpCtl=0x0;
    structsysctl_entry*newCtl=0x0;

    /*Checkifitexists*/
    tmpCtl=sysctl_find(name,namelen);
    if(tmpCtl!=0x0){
    kprintf("NodeExists!\n");
    while(1);
    }

    /*GetParentNode*/
    tmpCtl=sysctl_find(name,namelen-1);
    if(tmpCtl==0x0){
    kprintf("ParentNodeNonExistant\n");
    return(-1);
    }
    if(tmpCtl->children==0x0){
    tmpCtl->children=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    tmpCtl->children->children=0x0;
    tmpCtl->children->prev=0x0;
    tmpCtl->children->next=0x0;
    tmpCtl->children->id=name[namelen-1];
    sprintf(tmpCtl->children->name,str_name);
    tmpCtl->children->value=(void*)kmalloc(buf_size);
    memcpy(tmpCtl->children->value,buf,buf_size);
    tmpCtl->children->val_len=buf_size;
    }
    else{
    newCtl=(structsysctl_entry*)kmalloc(sizeof(structsysctl_entry));
    newCtl->prev=0x0;
    newCtl->next=tmpCtl->children;
    newCtl->children=0x0;
    newCtl->id=name[namelen-1];
    sprintf(newCtl->name,str_name);
    newCtl->value=(void*)kmalloc(buf_size);
    memcpy(newCtl->value,buf,buf_size);
    newCtl->val_len=buf_size;
    tmpCtl->children->prev=newCtl;
    tmpCtl->children=newCtl;
    }

    return(0x0);
    }

    /***
    END
    ***/