Changeset 1064 for Whitix

Show
Ignore:
Timestamp:
10/03/08 12:22:51 (3 months ago)
Author:
mwhitworth
Message:

Use a name pointer rather than copying the name into the structure.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/fs/kfs/dir.c

    r976 r1064  
    77#include <print.h> 
    88 
     9/* TODO: Create KeFsEntry cache. */ 
     10 
     11/* Returns number of entries in the directory. */ 
    912int KeFsDirSize(struct KeFsDir* dir) 
    1013{ 
     
    3336 
    3437        ListForEachEntry(entry,&dir->entries,next) 
    35         { 
    36                 struct KeObject* object; 
    37                 char* name; 
    38                  
    39                 object = (struct KeObject*)entry->file; 
    40                 name = KeObjGetName(object); 
    41                  
    42                 if (strlen( name ) == nameLength && 
    43                         !strnicmp(entry->name, name, nameLength)) 
     38                if (!strnicmp(name, entry->name, nameLength)) 
    4439                        goto found; 
    45         } 
    4640 
    4741        /* Cycled through the whole directory with no luck */ 
     
    143137        struct KeFsEntry* entry; 
    144138 
    145         dir=KeFsNameToDir(dir, &name); 
    146          
    147         if (!dir) 
    148                 return NULL; 
    149  
    150139        /* Check it doesn't exist already. */ 
    151140        ListForEachEntry(entry, &dir->entries, next) 
    152                 if (!strnicmp(entry->name, name, strlen(name))) 
     141                if (!strnicmp(entry->name, name, strlen(name)) && strlen(entry->name) == strlen(name)) 
    153142                        return entry; 
    154143         
     
    159148                return NULL; 
    160149                 
    161         entry->type=VFS_ATTR_DIR | VFS_ATTR_READ; 
    162         strcpy(entry->name, name); 
     150        entry->type = VFS_ATTR_DIR | VFS_ATTR_READ; 
     151        entry->name = name; 
    163152         
    164153        newDir=&entry->dir; 
     
    176165{ 
    177166        struct KeFsEntry* entry; 
    178  
    179         dir=KeFsNameToDir(dir, &name); 
    180          
    181         if (!dir) 
    182                 return NULL; 
    183167         
    184168        /* Check if the name exists already */ 
    185         ListForEachEntry(entry,&dir->entries,next) 
    186                 if (!strnicmp(entry->name, name, strlen(entry->name))) 
     169        ListForEachEntry(entry, &dir->entries, next) 
     170                if (!strnicmp(entry->name, name, strlen(name))) 
    187171                        return NULL; 
    188172 
    189173        /* Allocate the KeFsEntry, and the name with it */ 
    190         entry=(struct KeFsEntry*)MemAlloc(sizeof(struct KeFsEntry)+strlen(name)+1); 
     174        entry=(struct KeFsEntry*)MemAlloc(sizeof(struct KeFsEntry)); 
    191175        if (!entry) 
    192176                return NULL; 
    193177 
    194         entry->type=VFS_ATTR_FILE | permissions; 
    195         strcpy(entry->name, name); 
     178        entry->type = VFS_ATTR_FILE | permissions; 
     179        entry->name = name; 
    196180         
    197181        ListAddTail(&entry->next, &dir->entries); 
     
    204188void KeFsInitRoot(struct KeFsEntry* root) 
    205189{ 
    206         root->type=VFS_ATTR_DIR | VFS_ATTR_READ; 
    207         root->name[0]='\0'; 
     190        root->type = VFS_ATTR_DIR | VFS_ATTR_READ; 
     191        root->name = NULL; 
    208192        INIT_LIST_HEAD(&root->dir.entries); 
    209         root->dir.parent=NULL; 
     193        root->dir.parent = NULL; 
    210194} 
    211195