Show
Ignore:
Timestamp:
09/01/08 18:28:34 (4 years ago)
Author:
mwhitworth
Message:

Add various read function, add soft link functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/fs/infofs/info.c

    r851 r865  
    88static struct KeFsEntry root; 
    99 
    10 int InfoAddIntEntry(struct KeFsEntry* dir, char* name, int* value) 
     10int InfoReadInt(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     11{ 
     12        int copied; 
     13         
     14        copied=MIN(size-*position, sizeof(int)-*position); 
     15         
     16        memcpy(data, iEnt->iVal+*position, copied); 
     17         
     18        *position+=copied; 
     19         
     20        return copied; 
     21} 
     22 
     23int InfoReadStr(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     24{ 
     25        int copied; 
     26         
     27        copied=MIN(size-*position, strlen(iEnt->sVal)-*position); 
     28         
     29        memcpy(data, iEnt->sVal+*position, copied); 
     30         
     31        *position+=copied; 
     32         
     33        return copied; 
     34} 
     35 
     36int InfoReadArray(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     37{ 
     38        int copied; 
     39         
     40        copied=MIN(size-*position, iEnt->size-*position); 
     41         
     42        memcpy(data, iEnt->csVal+*position, copied); 
     43         
     44        *position+=copied; 
     45         
     46        return copied; 
     47} 
     48 
     49int IcRead(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     50{ 
     51        switch (iEnt->type) 
     52        { 
     53                case ICFS_TYPE_INT: 
     54                        return InfoReadInt(position, iEnt, data, size); 
     55                         
     56                case ICFS_TYPE_STR: 
     57                        return InfoReadStr(position, iEnt, data, size); 
     58                         
     59                case ICFS_TYPE_BYTE: 
     60                        return InfoReadArray(position, iEnt, data, size); 
     61                         
     62                default: 
     63                        KePrint("TODO: %d\n", iEnt->type); 
     64        } 
     65         
     66        return -EINVAL; 
     67} 
     68 
     69SYMBOL_EXPORT(IcRead); 
     70 
     71int IcWriteInt(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     72{ 
     73        int copied; 
     74         
     75        copied=MIN(size-*position, sizeof(int)-*position); 
     76         
     77        memcpy(iEnt->iVal+*position, data, copied); 
     78         
     79        *position+=copied; 
     80         
     81        return copied; 
     82} 
     83 
     84int IcWrite(int* position, struct IcFsEntry* iEnt, char* data, DWORD size) 
     85{ 
     86        switch (iEnt->type) 
     87        { 
     88                case ICFS_TYPE_INT: 
     89                        return IcWriteInt(position, iEnt, data, size); 
     90                         
     91                default: 
     92                        KePrint("TODO: %d\n", iEnt->type);               
     93        } 
     94         
     95        return -EINVAL; 
     96} 
     97 
     98SYMBOL_EXPORT(IcWrite); 
     99 
     100int IcFsAddIntEntry(struct KeFsEntry* fsRoot, struct KeFsEntry* dir, char* name, int* value) 
    11101{ 
    12102        struct KeFsEntry* entry; 
     
    14104         
    15105        if (!dir) 
    16                 dir=&root; 
     106                dir=fsRoot; 
    17107         
    18108        entry=KeFsAddEntry(&dir->dir, name); 
     
    27117} 
    28118 
    29 int InfoAddStrEntry(struct KeFsEntry* dir, char* name, char* str) 
     119int InfoAddIntEntry(struct KeFsEntry* dir, char* name, int* value) 
     120{ 
     121        return IcFsAddIntEntry(&root, dir, name, value); 
     122} 
     123 
     124struct IcFsEntry* IcFsAddStrEntry(struct KeFsEntry* fsRoot, struct KeFsEntry* dir, char* name, char* str) 
    30125{ 
    31126        struct KeFsEntry* entry; 
     
    33128         
    34129        if (!dir) 
    35                 dir=&root; 
     130                dir=&fsRoot; 
    36131                 
    37132        entry=KeFsAddEntry(&dir->dir, name); 
     
    43138        entry->file=newEnt; 
    44139         
    45         return 0; 
    46 } 
    47  
    48 struct KeFsEntry* InfoCreateDir(struct KeFsEntry* dir, char* name) 
    49 { 
    50         if (!dir) 
    51                 dir=&root; 
     140        return newEnt; 
     141} 
     142 
     143int IcFsAddSoftLink(struct KeFsEntry* fsRoot, struct KeFsEntry* dir, char* name, int (*followLink)(char* buffer, int size)) 
     144{ 
     145        struct KeFsEntry* entry; 
     146         
     147        if (!dir) 
     148                dir=&fsRoot; 
     149                 
     150        entry=KeFsAddEntry(&dir->dir, name); 
     151         
     152        entry->type &= ~VFS_ATTR_FILE; 
     153        entry->type |= VFS_ATTR_SOFTLINK; 
     154         
     155        entry->followLink=followLink; 
     156         
     157        return 0; 
     158} 
     159 
     160int InfoAddStrEntry(struct KeFsEntry* dir, char* name, char* str) 
     161{ 
     162        IcFsAddStrEntry(&root, dir, name, str); 
     163        return 0; 
     164} 
     165 
     166struct KeFsEntry* IcFsCreateDir(struct KeFsEntry* fsRoot, struct KeFsEntry* dir, char* name) 
     167{ 
     168        if (!dir) 
     169                dir=fsRoot; 
    52170                 
    53171        return KeFsAddDir(&dir->dir, name); 
    54172} 
     173 
     174struct KeFsEntry* InfoCreateDir(struct KeFsEntry* dir, char* name) 
     175{ 
     176        return IcFsCreateDir(&root, dir, name); 
     177} 
     178 
     179SYMBOL_EXPORT(InfoCreateDir); 
    55180 
    56181DWORD InfoGetRootId() 
     
    76201        InfoCreateDir(NULL, "Memory"); 
    77202        InfoCreateDir(NULL, "Processes"); 
    78 } 
     203 
     204        return 0; 
     205}