device.c
sys/device.h
ubixos/spinlock.h
lib/kmalloc.h
lib/kprintf.h
assert.h
ubixos/spinlock.h
ubixos/types.h
sys/_types.h
lib/kmalloc.h
lib/kprintf.h
src/sys/sys/device.c
assert.h
sys/device.h
int int device_add (int minor, char type, struct device_interface *devInfo) device_add int minor char type struct device_interface * devInfo devices deviceSpinLock device_node::devInfo device_interface::init device_interface::initialized kmalloc kprintf device_node::minor device_node::next NULL device_node::prev spinLock spinUnlock device_node::type fdc_init initHardDisk
device_node * struct device_node* device_find (int major, int minor) device_find int major int minor devices deviceSpinLock device_node::devInfo device_interface::major device_node::minor device_node::next spinLock spinUnlock devfs_open devfs_read devfs_write vfs_mount
int int device_remove (struct device_node *deviceToDelete) device_remove struct device_node * deviceToDelete devices deviceSpinLock kfree device_node::next NULL spinLock spinUnlock
struct device_node * struct device_node* devices devices 0x0 device_add device_find device_remove
spinLock_t spinLock_t deviceSpinLock deviceSpinLock SPIN_LOCK_INITIALIZER device_add device_find device_remove

    /*****************************************************************************************
    Copyright(c)2002-2005TheUbixOSProject
    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: device_8c.xml 88 2016-01-12 00:11:29Z reddawg $

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

    #include<sys/device.h>
    #include<ubixos/spinlock.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>
    #include<assert.h>

    /*Linkedlistofdriversloadedinthesystemaccessablebythesubsystemonly*/
    staticstructdevice_node*devices=0x0;
    staticspinLock_tdeviceSpinLock=SPIN_LOCK_INITIALIZER;

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

    Function:intdeviceAdd(intminor,chartype,structdevice_interface*devInfo);

    Description:Thiswilladdadevicetothesystem

    Notes:

    05/19/2004-ImprovingUponthespec

    *****************************************************************************************/
    intdevice_add(intminor,chartype,structdevice_interface*devInfo){
    structdevice_node*tmpDev=0x0;

    tmpDev=(structdevice_node*)kmalloc(sizeof(structdevice_node));
    if(tmpDev==NULL)
    kprintf("ErrorAddingDevice:memoryfailure\n");

    tmpDev->prev=0x0;
    tmpDev->minor=minor;
    tmpDev->type=type;
    tmpDev->devInfo=devInfo;

    spinLock(&deviceSpinLock);
    tmpDev->next=devices;
    devices=tmpDev;
    spinUnlock(&deviceSpinLock);

    if(tmpDev->devInfo->initialized==0x0)
    return(tmpDev->devInfo->init(tmpDev));
    else
    return(0x0);
    }

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

    Function:structdevice_node*deviceFind(intmajor,intminor);

    Description:Thiswillfindadevicebasedonmajorminor

    Notes:

    05/19/2004-ImprovingUponthespec

    *****************************************************************************************/
    structdevice_node*device_find(intmajor,intminor){
    structdevice_node*tmpDev=0x0;

    spinLock(&deviceSpinLock);

    for(tmpDev=devices;tmpDev;tmpDev=tmpDev->next){
    if((tmpDev->devInfo->major==major)&&(tmpDev->minor==minor)){
    spinUnlock(&deviceSpinLock);
    return(tmpDev);
    }
    }

    spinUnlock(&deviceSpinLock);
    return(0x0);
    }

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

    Function:intdeviceRemove(struct*device_node);

    Description:Thiswillremoveadevicebasedonit'spointer

    *********************************************************************************************/
    intdevice_remove(structdevice_node*deviceToDelete)
    {
    structdevice_node*current,*previous;

    current=devices;
    previous=NULL;
    spinLock(&deviceSpinLock);
    while(current!=NULL)
    {
    if(current==deviceToDelete)break;
    else
    {
    previous=current;
    current=current->next;
    }
    }
    if(current==NULL)
    {
    spinUnlock(&deviceSpinLock);
    return1;
    }
    else
    {
    if(current==devices)
    devices=devices->next;
    else
    previous->next=current->next;
    kfree(current);
    spinUnlock(&deviceSpinLock);
    return1;
    }

    spinUnlock(&deviceSpinLock);
    return0x0;
    }

    /***
    END
    ***/