dirCache.c
assert.h
ubixfs/dirCache.h
ubixfs/ubixfs.h
lib/kmalloc.h
lib/kprintf.h
lib/string.h
ubixos/spinlock.h
sys/thread.h
ubixos/sched.h
ubixos/spinlock.h
ubixos/types.h
sys/_types.h
lib/string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
mpi/mpi.h
src/sys/ubixfs/dirCache.c
vfs/vfs.h
vfs/mount.h
lib/kprintf.h
ubixfs/ubixfs.h
assert.h
ubixfs/dirCache.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
sys/device.h
cacheNode * struct cacheNode* ubixfs_cacheAdd (struct cacheNode *node, struct cacheNode *newNode) ubixfs_cacheAdd struct cacheNode * node struct cacheNode * newNode assert dca_spinLock cacheNode::fileListHead cacheNode::fileListTail cacheNode::next NULL cacheNode::parent cacheNode::prev spinLock spinUnlock ubixfs_cacheFind
void void ubixfs_cacheDelete (struct cacheNode **head) ubixfs_cacheDelete struct cacheNode ** head cacheNode::fileListHead cacheNode::info kfree cacheNode::name cacheNode::next NULL ubixfs_cacheDelete ubixfs_cacheDelete
cacheNode * struct cacheNode* ubixfs_cacheFind (struct cacheNode *head, char *name) ubixfs_cacheFind struct cacheNode * head char * name assert cacheNode::attributes dca_spinLock dirList cacheNode::fileListHead cacheNode::fileListTail cacheNode::info cacheNode::name cacheNode::next NULL cacheNode::parent cacheNode::permissions cacheNode::present cacheNode::prev cacheNode::size spinLock spinUnlock cacheNode::startCluster strcmp typeFile ubixfs_cacheAdd ubixfs_cacheFind ubixfs_cacheNew ubixfs_findName openFileUbixFS ubixfs_cacheFind
cacheNode * struct cacheNode* ubixfs_cacheNew (const char *name) ubixfs_cacheNew const char * name assert cacheNode::attributes cacheNode::dirty cacheNode::fileListHead cacheNode::fileListTail cacheNode::info kmalloc cacheNode::name cacheNode::next NULL cacheNode::parent cacheNode::permissions cacheNode::present cacheNode::prev cacheNode::size cacheNode::startCluster strcpy strlen ubixfs_cacheFind ubixfs_initialize
struct directoryEntry * static struct directoryEntry* ubixfs_findName (struct directoryEntry *dirList, uInt32 size, char *name) ubixfs_findName struct directoryEntry * dirList uInt32 size char * name dirList directoryEntry::fileName NULL strcmp ubixfs_cacheFind
spinLock_t spinLock_t dca_spinLock dca_spinLock SPIN_LOCK_INITIALIZER ubixfs_cacheAdd ubixfs_cacheFind

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

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

    #include<assert.h>
    #include<ubixfs/dirCache.h>
    #include<ubixfs/ubixfs.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>
    #include<lib/string.h>

    #include<ubixos/spinlock.h>

    staticspinLock_tdca_spinLock=SPIN_LOCK_INITIALIZER;

    static
    structdirectoryEntry*
    ubixfs_findName(structdirectoryEntry*dirList,uInt32size,char*name){
    unsignedinti;

    if(dirList==NULL||name==NULL)returnNULL;
    //UBUkprintf("dirList:[0x%X],name:[0x%X]\n",dirList,name);
    for(i=0;i<(size/sizeof(structdirectoryEntry));i++){
    if(strcmp(dirList[i].fileName,name)==0)return&dirList[i];
    }/*for*/
    returnNULL;
    }/*ubixfs_findName*/

    structcacheNode*
    ubixfs_cacheFind(structcacheNode*head,char*name){
    structcacheNode*tmp=head;
    structdirectoryEntry*dirList=NULL;
    unsignedinti=0x0;
    chardirName[256];
    char*nextDir=NULL;
    /*kprintf("lookingfor%s\n",name);*/
    assert(name);
    assert(head);
    assert(*name);
    spinLock(&dca_spinLock);
    spinUnlock(&dca_spinLock);
    if(name==NULL||head==NULL)returnNULL;
    if(*name=='\0')returnNULL;

    /*
    *walkdownthetreerecursivelyuntilwefindthenodewe'relooking
    *for
    */
    i=0;
    while(name[i]!='\0'&&name[i]!='/'&&i<sizeof(dirName)){
    dirName[i]=name[i];
    i++;
    }/*while*/
    assert(i<sizeof(dirName));
    if(i==sizeof(dirName))returnNULL;

    if(i==0)dirName[i++]='/';

    dirName[i]='\0';

    nextDir=&name[i];
    if(*nextDir=='/')nextDir++;

    /*
    *nextDirpointstothenextdir
    *namepointstoanullterminateddirectoryname
    *ifnextDirisn'tnull,thenmakesurethatthisdirispresent
    */
    /*kprintf("nextdir:%s--dirName:%s\n",nextDir,dirName);*/
    if(*nextDir!='\0'){
    while(tmp!=NULL){
    //UBUkprintf("tmp->name:[0x%X],dirName:[0x%X]\n",tmp->name,dirName);
    if(strcmp(tmp->name,dirName)==0){

    if((*tmp->attributes&typeFile)==typeFile
    ||tmp->fileListHead==NULL){

    /*ifwe'rehere,thentherearenosubdirscachedtolookthrough*/
    dirList=ubixfs_findName((structdirectoryEntry*)head->info,
    *head->size,nextDir);
    if(dirList==NULL)returnNULL;
    /*kprintf("creatingnewnode%s",dirList->fileName);*/
    tmp=ubixfs_cacheAdd(tmp,ubixfs_cacheNew(dirList->fileName));
    tmp->attributes=&dirList->attributes;
    tmp->permissions=&dirList->permissions;
    tmp->size=&dirList->size;
    /*kprintf("size:%d\n",*tmp->size);*/
    tmp->startCluster=&dirList->startCluster;
    tmp->present=0;
    returntmp;
    }else{
    returnubixfs_cacheFind(tmp->fileListHead,nextDir);
    }
    }/*if*/
    tmp=tmp->next;
    }/*while*/
    /*itwasn'tpresent,returnNULL*/
    returnNULL;
    }/*if*/

    /*
    *ifnextDirwasnull,thenwe'reatthebottomlevel.Lookforthe
    *dirlistinghere
    */
    while(tmp!=NULL){

    assert(tmp->name);
    assert(name);
    /*don'tforgettochecktoseeifit'sadirectory*/
    //UBUkprintf("tmpName:[0x%X],name:[0x%X]\n",tmp->name,name);
    if(strcmp(tmp->name,name)==0){

    /*
    *wefoundthenode.Moveittothefrontofthelist
    *(ifitisn'talready)
    */
    #if0
    assert(tmp->parent);
    if(tmp!=tmp->parent->fileListHead){

    /*ifwe'rethetail,pointthetailtoourprev*/
    if(tmp==tmp->parent->fileListTail){
    tmp->parent->fileListTail=tmp->prev;
    }/*if*/

    if(tmp->next!=NULL)tmp->next->prev=tmp->prev;
    if(tmp->prev!=NULL)tmp->prev->next=tmp->next;
    tmp->next=tmp->parent->fileListHead;
    tmp->prev=NULL;
    tmp->parent->fileListHead=tmp;
    }/*if*/
    #endif
    returntmp;
    }/*if*/
    tmp=tmp->next;
    }/*while*/
    /*ifwe'rehere,thenonelevelofthedirisn'tcached*/

    tmp=head->parent;
    assert(tmp);
    assert(tmp->info);
    dirList=ubixfs_findName((structdirectoryEntry*)tmp->info,
    *tmp->size,name);
    if(dirList==NULL)returnNULL;
    /*kprintf("creatingnewnode/size%s/%d",dirList->fileName,dirList->size);*/
    tmp=ubixfs_cacheAdd(tmp,ubixfs_cacheNew(dirList->fileName));
    tmp->attributes=&dirList->attributes;
    tmp->permissions=&dirList->permissions;
    tmp->size=&dirList->size;
    /*kprintf("size:%d\n",*tmp->size);*/
    tmp->startCluster=&dirList->startCluster;
    tmp->present=0;
    returntmp;
    #if0
    returnNULL;/*couldn'tfindit*/
    #endif
    }/*ubixfs_cacheFind*/

    structcacheNode*
    ubixfs_cacheNew(constchar*name){
    structcacheNode*tmp=kmalloc(sizeof(structcacheNode));
    assert(tmp);
    tmp->parent=tmp;
    tmp->prev=tmp->next=tmp->fileListHead=tmp->fileListTail=NULL;
    tmp->info=NULL;
    tmp->size=NULL;
    tmp->present=tmp->dirty=0;
    tmp->startCluster=NULL;
    tmp->attributes=NULL;
    tmp->permissions=NULL;
    tmp->name=(char*)kmalloc(strlen(name)+1);
    strcpy(tmp->name,name);
    returntmp;
    }/*ubixfs_cacheNew*/

    void
    ubixfs_cacheDelete(structcacheNode**head){
    structcacheNode*tmp=NULL;
    structcacheNode*del=NULL;

    if(head==NULL)return;
    if(*head==NULL)return;

    tmp=*head;
    while(tmp!=NULL){
    /*ifthereareanychildnodes,deletethemfirst*/

    /*
    *thefollowingcommentedout``if''statementisredundant,sinceit
    *willbecaughtwiththeabovechecks
    */
    /*if(tmp->fileListHead!=NULL)*/
    ubixfs_cacheDelete(&tmp->fileListHead);

    kfree(tmp->info);
    kfree(tmp->name);
    del=tmp;
    tmp=tmp->next;
    kfree(del);
    }/*while*/
    *head=NULL;
    return;
    }/*deleteNode*/
    #if0
    void
    addNode(structcacheNode**node,structcacheNode*newNode){
    if(node==NULL)return;
    newNode->next=*node;
    if(*node!=NULL)(*node)->prev=newNode;
    newNode->prev=NULL;
    *node=newNode;
    return;
    }/*addNode*/
    #endif

    structcacheNode*
    ubixfs_cacheAdd(structcacheNode*node,structcacheNode*newNode){
    structcacheNode*tmp;

    assert(node);
    spinLock(&dca_spinLock);
    newNode->parent=node;
    newNode->next=node->fileListHead;
    newNode->prev=NULL;
    if(node->fileListHead==NULL)
    node->fileListTail=newNode;
    else
    node->fileListHead->prev=newNode;

    node->fileListHead=newNode;
    tmp=node->fileListHead;
    spinUnlock(&dca_spinLock);
    returntmp;
    }/*ubixfs_cacheAdd*/

    /***
    $Log: dirCache_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:51  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:17reddawg
    ubix2

    Revision1.22005/10/1200:13:37reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:40reddawg
    nomessage

    Revision1.302004/08/1411:23:02reddawg
    Changes

    Revision1.292004/08/0912:58:05reddawg
    letmeknowwhenyougotthesurce

    Revision1.282004/08/0117:58:39flameshadow
    chg:fixedstringallocationbuginubixfs_cacheNew()

    Revision1.272004/07/2817:24:13flameshadow
    chg:nocomment

    Revision1.262004/07/2817:07:29flameshadow
    chg:re-addedmovingcachednodestothefrontofthelistwhenfound
    add:addedanassert()inubixfs.c

    Revision1.252004/07/2719:24:31flameshadow
    chg:reducedthenumberofdebuggingstatementsinthekernel.

    Revision1.242004/07/2712:02:01reddawg
    chg:fixedmarksbugreadFiledidalookupwhichiswhyitlookedlikeitwaslooppingsomuch

    Revision1.232004/07/2709:05:43flameshadow
    chg:fixedfilenotfoundbug.Stillcan'tfindloopingissue

    Revision1.222004/07/2704:05:20flameshadow
    chg:kindafixedit.Addedbunchesofdebuginfo

    Revision1.212004/07/2522:21:52flameshadow
    chg:re-enabledkprintf()inubixfs_cacheFind()

    Revision1.202004/07/2417:19:24flameshadow
    chg:Temporarilydisabledthemovingofthefoundcachenodetothefront
    ofthelist.Itseemstocauseproblemslater(racecondition,possibly)

    Revision1.192004/07/2223:01:51reddawg
    OkcheckinginbeforeIsleep

    Revision1.182004/07/2219:54:50flameshadow
    chg:worksnow.Thanxubu

    Revision1.172004/07/2219:01:59flameshadow
    chg:moredirectoryandfilecaching

    Revision1.162004/07/2216:34:32flameshadow
    add:fileanddircachingkindawork

    Revision1.152004/07/2122:43:18flameshadow
    onemoretry

    Revision1.142004/07/2122:42:25flameshadow
    tryitnow

    Revision1.132004/07/2122:40:27flameshadow
    weird

    Revision1.122004/07/2122:18:37flameshadow
    chg:renamedsubDirsHead/TailmembersofcacheNodetofileListHead/Tail

    Revision1.112004/07/2122:12:22flameshadow
    add:attributestagincacheNode
    add:settingofattributesinubixfx_cacheNew()andubixfs_cacheFind()

    Revision1.102004/07/2122:07:18flameshadow
    chg:renamedcachingfunctions(again)

    Revision1.92004/07/2122:00:04flameshadow
    chg:ubixfws_dirCacheAddnowreturnsapointertothenodeitadded
    chg:minorfixinubixfs_dirCacheFind()

    Revision1.62004/07/2114:43:14flameshadow
    add:addedcwc(currentworkingcontainer)totheosInfostrut

    Revision1.52004/07/2019:21:30reddawg
    Youlikeleavingout$Log: dirCache_8c.xml,v $
    YoulikeleavingoutRevision 1.6  2006/12/19 14:12:51  reddawg
    Youlikeleavingoutrtld-elf almost workign
    Youlikeleavingout
    YoulikeleavingoutRevision1.1.1.12006/06/0112:46:17reddawg
    Youlikeleavingoutubix2
    Youlikeleavingout
    YoulikeleavingoutRevision1.22005/10/1200:13:37reddawg
    YoulikeleavingoutRemoved
    Youlikeleavingout
    YoulikeleavingoutRevision1.1.1.12005/09/2617:24:40reddawg
    Youlikeleavingoutnomessage
    Youlikeleavingout
    YoulikeleavingoutRevision1.302004/08/1411:23:02reddawg
    YoulikeleavingoutChanges
    Youlikeleavingout
    YoulikeleavingoutRevision1.292004/08/0912:58:05reddawg
    Youlikeleavingoutletmeknowwhenyougotthesurce
    Youlikeleavingout
    YoulikeleavingoutRevision1.282004/08/0117:58:39flameshadow
    Youlikeleavingoutchg:fixedstringallocationbuginubixfs_cacheNew()
    Youlikeleavingout
    YoulikeleavingoutRevision1.272004/07/2817:24:13flameshadow
    Youlikeleavingoutchg:nocomment
    Youlikeleavingout
    YoulikeleavingoutRevision1.262004/07/2817:07:29flameshadow
    Youlikeleavingoutchg:re-addedmovingcachednodestothefrontofthelistwhenfound
    Youlikeleavingoutadd:addedanassert()inubixfs.c
    Youlikeleavingout
    YoulikeleavingoutRevision1.252004/07/2719:24:31flameshadow
    Youlikeleavingoutchg:reducedthenumberofdebuggingstatementsinthekernel.
    Youlikeleavingout
    YoulikeleavingoutRevision1.242004/07/2712:02:01reddawg
    Youlikeleavingoutchg:fixedmarksbugreadFiledidalookupwhichiswhyitlookedlikeitwaslooppingsomuch
    Youlikeleavingout
    YoulikeleavingoutRevision1.232004/07/2709:05:43flameshadow
    Youlikeleavingoutchg:fixedfilenotfoundbug.Stillcan'tfindloopingissue
    Youlikeleavingout
    YoulikeleavingoutRevision1.222004/07/2704:05:20flameshadow
    Youlikeleavingoutchg:kindafixedit.Addedbunchesofdebuginfo
    Youlikeleavingout
    YoulikeleavingoutRevision1.212004/07/2522:21:52flameshadow
    Youlikeleavingoutchg:re-enabledkprintf()inubixfs_cacheFind()
    Youlikeleavingout
    YoulikeleavingoutRevision1.202004/07/2417:19:24flameshadow
    Youlikeleavingoutchg:Temporarilydisabledthemovingofthefoundcachenodetothefront
    Youlikeleavingoutofthelist.Itseemstocauseproblemslater(racecondition,possibly)
    Youlikeleavingout
    YoulikeleavingoutRevision1.192004/07/2223:01:51reddawg
    YoulikeleavingoutOkcheckinginbeforeIsleep
    Youlikeleavingout
    YoulikeleavingoutRevision1.182004/07/2219:54:50flameshadow
    Youlikeleavingoutchg:worksnow.Thanxubu
    Youlikeleavingout
    YoulikeleavingoutRevision1.172004/07/2219:01:59flameshadow
    Youlikeleavingoutchg:moredirectoryandfilecaching
    Youlikeleavingout
    YoulikeleavingoutRevision1.162004/07/2216:34:32flameshadow
    Youlikeleavingoutadd:fileanddircachingkindawork
    Youlikeleavingout
    YoulikeleavingoutRevision1.152004/07/2122:43:18flameshadow
    Youlikeleavingoutonemoretry
    Youlikeleavingout
    YoulikeleavingoutRevision1.142004/07/2122:42:25flameshadow
    Youlikeleavingouttryitnow
    Youlikeleavingout
    YoulikeleavingoutRevision1.132004/07/2122:40:27flameshadow
    Youlikeleavingoutweird
    Youlikeleavingout
    YoulikeleavingoutRevision1.122004/07/2122:18:37flameshadow
    Youlikeleavingoutchg:renamedsubDirsHead/TailmembersofcacheNodetofileListHead/Tail
    Youlikeleavingout
    YoulikeleavingoutRevision1.112004/07/2122:12:22flameshadow
    Youlikeleavingoutadd:attributestagincacheNode
    Youlikeleavingoutadd:settingofattributesinubixfx_cacheNew()andubixfs_cacheFind()
    Youlikeleavingout
    YoulikeleavingoutRevision1.102004/07/2122:07:18flameshadow
    Youlikeleavingoutchg:renamedcachingfunctions(again)
    Youlikeleavingout
    YoulikeleavingoutRevision1.92004/07/2122:00:04flameshadow
    Youlikeleavingoutchg:ubixfws_dirCacheAddnowreturnsapointertothenodeitadded
    Youlikeleavingoutchg:minorfixinubixfs_dirCacheFind()
    Youlikeleavingout
    YoulikeleavingoutRevision1.62004/07/2114:43:14flameshadow
    Youlikeleavingoutadd:addedcwc(currentworkingcontainer)totheosInfostrut
    Youlikeleavingoutsoidon'tknowwhatisgoingoneh?

    END
    ***/