devfs.c
devfs/devfs.h
vfs/vfs.h
sys/device.h
ubixos/types.h
ubixos/spinlock.h
ubixos/kpanic.h
lib/kmalloc.h
lib/string.h
lib/kprintf.h
sys/thread.h
ubixos/kpanic.h
ubixos/spinlock.h
devfs/devfs.h
ubixos/types.h
sys/_types.h
lib/string.h
vfs/file.h
lib/kmalloc.h
vfs/vfs.h
vfs/mount.h
lib/kprintf.h
ubixfs/dirCache.h
src/sys/devfs/devfs.c
sys/sysproto.h
sys/signal.h
sys/device.h
int int devfs_init () devfs_init devfs_initialize devfs_open devfs_read devfs_write NULL vfs_mount vfsRegisterFS x1
void static void devfs_initialize (struct vfs_mountPoint *mp) devfs_initialize struct vfs_mountPoint * mp

This is the initialized called by the vfs system when enabling devfs basically it allocates memory for the devfs module

devfs_info::deviceList
vfs_mountPoint::fsInfo
K_PANIC
kmalloc
devfs_init
int int devfs_makeNode (char *name, uInt8 type, uInt16 major, uInt16 minor) devfs_makeNode char * name uInt8 type uInt16 major uInt16 minor devfs_len devfsSpinLock devfs_info::deviceList devfs_devices::devMajor devfs_devices::devMinor devfs_devices::devName devfs_devices::devType vfs_mountPoint::fsInfo kmalloc kprintf devfs_devices::next devfs_devices::prev spinLock spinUnlock sprintf strlen vfs_findMount fdc_init initHardDisk
int static int devfs_open (char *file, fileDescriptor *fd) devfs_open char * file fileDescriptor * fd

This is the open routine called by the vfs when a fopen or open is called within the user or kernel space file - this is the file node fd - this is the file descriptor

This format will be changing down the road

devfs_len
devfsSpinLock
device_find
devfs_info::deviceList
device_node::devInfo
devfs_devices::devMajor
devfs_devices::devMinor
devfs_devices::devName
vfs_mountPoint::fsInfo
kprintf
fileDescriptorStruct::mode
fileDescriptorStruct::mp
devfs_devices::next
device_interface::size
fileDescriptorStruct::size
spinLock
spinUnlock
fileDescriptorStruct::start
strcmp
x1
devfs_init
int static int devfs_read (fileDescriptor *fd, char *data, long offset, long size) devfs_read fileDescriptor * fd char * data long offset long size

Function: int readDevFS(fileDescriptor *fd,char *data,long offset,long size) Description: Read File Into Data Notes:

fileDescriptorStruct::buffer
device_find
device_node::devInfo
devfs_devices::devMajor
devfs_devices::devMinor
device_interface::info
kprintf
device_interface::read
fileDescriptorStruct::start
devfs_init
int static int devfs_write (fileDescriptor *fd, char *data, long offset, long size) devfs_write fileDescriptor * fd char * data long offset long size fileDescriptorStruct::buffer device_find device_node::devInfo devfs_devices::devMajor devfs_devices::devMinor device_interface::info device_interface::read fileDescriptorStruct::start device_interface::write devfs_init
int int devfs_len devfs_len 0x0 devfs_makeNode devfs_open
spinLock_t spinLock_t devfsSpinLock devfsSpinLock SPIN_LOCK_INITIALIZER devfs_makeNode devfs_open

    /*****************************************************************************************
    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: devfs_8c.xml 88 2016-01-12 00:11:29Z reddawg $

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

    #include<devfs/devfs.h>
    #include<vfs/vfs.h>
    #include<sys/device.h>
    #include<ubixos/types.h>
    #include<ubixos/spinlock.h>
    #include<ubixos/kpanic.h>
    #include<lib/kmalloc.h>
    #include<lib/string.h>
    #include<lib/kprintf.h>

    /*Spinlockfordevfsweshouldstartconvertingtosem/mutex*/
    staticspinLock_tdevfsSpinLock=SPIN_LOCK_INITIALIZER;

    /*Lengthofdevlist*/
    staticintdevfs_len=0x0;

    staticvoiddevfs_initialize(structvfs_mountPoint*mp){
    structdevfs_info*fsInfo=0x0;

    /*AllocatememoryforthefsInfo*/
    if((mp->fsInfo=(structdevfs_info*)kmalloc(sizeof(structdevfs_info)))==0x0)
    K_PANIC("devfs:failedtoallocatememor\n");

    fsInfo=mp->fsInfo;
    fsInfo->deviceList=0x0;

    /*Return*/
    return;
    }

    staticintdevfs_open(char*file,fileDescriptor*fd){
    structdevfs_info*fsInfo=fd->mp->fsInfo;
    structdevfs_devices*tmpDev=0x0;
    structdevice_node*device=0x0;

    spinLock(&devfsSpinLock);

    if(strcmp(file,"/")==0x0){
    fd->start=-1;
    fd->size=devfs_len;
    spinUnlock(&devfsSpinLock);
    return(0x1);
    }
    if(file[0]=='/')
    file++;
    for(tmpDev=fsInfo->deviceList;tmpDev!=0x0;tmpDev=tmpDev->next){
    if(strcmp(tmpDev->devName,file)==0x0){
    switch((fd->mode&0x3)){
    case0:
    case1:
    device=device_find(tmpDev->devMajor,tmpDev->devMinor);
    (void*)fd->start=tmpDev;
    fd->size=device->devInfo->size;
    break;
    default:
    kprintf("InvalidFileMode\n");
    spinUnlock(&devfsSpinLock);
    return(-1);
    break;
    }
    spinUnlock(&devfsSpinLock);
    return(0x1);
    }
    }
    spinUnlock(&devfsSpinLock);
    return(0x0);
    }

    staticintdevfs_read(fileDescriptor*fd,char*data,longoffset,longsize){
    inti=0x0,x=0x0;
    uInt32sectors=0x0;
    uInt16diff=0x0;
    structdevice_node*device=0x0;
    structdevfs_devices*tmpDev=(void*)fd->start;

    if(tmpDev==-1){
    kprintf("HiUbie[%i]!!!\n",size);
    for(i=0;i<size;i++){
    data[i]='a';
    fd->buffer[i]='a';
    }
    data[size-1]='\n';
    return(size);
    }

    device=device_find(tmpDev->devMajor,tmpDev->devMinor);

    sectors=((size+511)/512);
    diff=(offset-((offset/512)*512));

    for(i=0x0;i<sectors;i++){
    device->devInfo->read(device->devInfo->info,fd->buffer,i+(offset/512),1);
    for(x=0x0;x<(size-(i*512));x++){
    if(diff>0){
    data[x]=fd->buffer[x+diff];
    }
    else{
    data[x]=fd->buffer[x];
    }
    }
    diff=0x0;
    data+=512;
    }

    return(size);
    }

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

    Function:intwriteDevFS(fileDescriptor*fd,char*data,longoffset,longsize)
    Description:WriteDataIntoFile
    Notes:

    ************************************************************************/
    staticintdevfs_write(fileDescriptor*fd,char*data,longoffset,longsize){
    inti=0x0,x=0x0;
    structdevice_node*device=0x0;
    structdevfs_devices*tmpDev=(void*)fd->start;

    device=device_find(tmpDev->devMajor,tmpDev->devMinor);
    for(i=0x0;i<((size+511)/512);i++){
    device->devInfo->read(device->devInfo->info,fd->buffer,i+(offset/512),1);
    for(x=0x0;((x<512)&&((x+(i*512))<size));x++){
    fd->buffer[x]=data[x];
    }
    device->devInfo->write(device->devInfo->info,fd->buffer,i+(offset/512),1);
    data+=512;
    }
    return(size);
    }

    intdevfs_makeNode(char*name,uInt8type,uInt16major,uInt16minor){
    structvfs_mountPoint*mp=0x0;
    structdevfs_info*fsInfo=0x0;
    structdevfs_devices*tmpDev=0x0;

    spinLock(&devfsSpinLock);

    mp=vfs_findMount("devfs");

    if(mp==0x0){
    kprintf("Error:Can'tFindMountPoint\n");
    spinUnlock(&devfsSpinLock);
    return(-1);
    }

    fsInfo=mp->fsInfo;

    tmpDev=(structdevfs_devices*)kmalloc(sizeof(structdevfs_devices));

    tmpDev->devType=type;
    tmpDev->devMajor=major;
    tmpDev->devMinor=minor;
    sprintf(tmpDev->devName,name);
    devfs_len+=strlen(name)+1;

    tmpDev->next=fsInfo->deviceList;
    tmpDev->prev=0x0;
    if(fsInfo->deviceList!=0x0){
    fsInfo->deviceList->prev=tmpDev;
    }

    fsInfo->deviceList=tmpDev;

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

    intdevfs_init(){
    /*Buildourdevfsstruct*/
    structfileSystemdevFS=
    {NULL,/*prev*/
    NULL,/*next*/
    (void*)devfs_initialize,/*vfsInitFS*/
    (void*)devfs_read,/*vfsRead*/
    (void*)devfs_write,/*vfsWrite*/
    (void*)devfs_open,/*vfsOpenFile*/
    NULL,/*vfsUnlink*/
    NULL,/*vfsMakeDir*/
    NULL,/*vfsRemDir*/
    NULL,/*vfsSync*/
    1/*vfsType*/
    };/*devFS*/

    if(vfsRegisterFS(devFS)!=0x0){
    //sysErr(systemErr,"UnableToEnableDevFS");
    return(0x1);
    }
    /*Mountourdevfsthiswillbuildthedevfscontainernode*/
    vfs_mount(0x0,0x0,0x0,0x1,"devfs","rw");//MountDeviceFileSystem

    /*Return*/
    return(0x0);
    }

    /***
    END
    ***/