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

Remove DevAddDevice, add new DevFs* functions that deal with KeDevices.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/fs/devfs/devfs.c

    r969 r1063  
    3535#include <fs/kfs.h> 
    3636#include <print.h> 
     37#include <panic.h> 
    3738 
    3839/* Root directory of the device filesystem. */ 
     
    117118{ 
    118119        struct KeFsEntry* entry=(struct KeFsEntry*)(vNode->id); 
    119         struct DevFsDevice* device; 
     120        struct KeDevice* device; 
    120121        struct StorageDevice* sDevice; 
    121122         
     
    126127        { 
    127128                vNode->mode |= VFS_ATTR_FILE; 
    128                 device=(struct DevFsDevice*)entry->file; 
     129                device=(struct KeDevice*)entry->file; 
    129130                vNode->devId = device->devId; 
    130                 if (entry->type & DEVICE_BLOCK) 
     131                 
     132                if (device->type == DEVICE_BLOCK) 
    131133                { 
    132134                        vNode->fileOps=&devFsBlockOps; 
     
    136138                        sDevice=(struct StorageDevice*)DeviceGetOps(vNode); 
    137139                        vNode->size=sDevice->blockSize*sDevice->totalSectors; 
    138                 }else if (entry->type & DEVICE_CHAR) 
     140                }else if (device->type == DEVICE_CHAR) 
    139141                { 
    140142                        vNode->mode |= VFS_ATTR_CHAR; 
    141143                        /* Just redirect to the usual char devices */ 
    142                         vNode->fileOps=device->ops; 
     144                        vNode->fileOps=device->fileOps; 
    143145                        vNode->size=0; 
    144                 } 
     146                }else 
     147                        KernelPanic("DevFs file is neither a block nor a character device"); 
    145148        }else if (entry->type & VFS_ATTR_DIR) 
    146149        { 
     
    153156} 
    154157 
    155 int DevAddDevice(char* name, WORD major, WORD minor, int type, void* ops) 
    156 { 
    157         struct KeFsDir* dir=rootDir; 
    158         struct KeFsEntry* entry; 
    159         struct DevFsDevice* device; 
    160  
    161         /* Sanity checks */ 
    162         if (!name || !ops) 
    163                 return -EFAULT; 
    164  
    165         if (!major) 
    166                 return -EINVAL; 
    167          
    168         entry=KeFsAddEntry(dir, name, VFS_ATTR_RW); 
    169          
    170         if (!entry) 
    171                 return -EFAULT; 
    172  
    173         device=(struct DevFsDevice*)MemAlloc(sizeof(struct DevFsDevice)); 
    174          
    175         device->ops=ops; 
    176         device->devId = DEV_ID_MAKE(major, minor); 
    177         entry->file=device; 
    178          
    179         entry->type |= type; 
    180  
    181         return 0; 
    182 } 
    183  
    184 SYMBOL_EXPORT(DevAddDevice); 
    185  
    186158int DevFsAddDevice(struct KeDevice* device, const char* name) 
    187159{ 
    188         struct KeSet* parent; 
    189160        struct KeFsDir* dir; 
    190161        struct KeFsEntry* entry; 
    191162         
    192163        dir = KeObjGetParentDevDir(&device->object); 
    193  
     164         
    194165        if (!dir) 
    195                 dir = rootDir;   
    196          
    197         entry = KeFsAddEntry(dir, name, VFS_ATTR_RW); 
     166                dir = rootDir; 
     167         
     168        entry = KeFsAddEntry(dir, (char*)name, VFS_ATTR_RW); 
    198169         
    199170        if (!entry) 
     
    208179SYMBOL_EXPORT(DevFsAddDevice); 
    209180 
    210 int DevAddDir(char* name) 
    211 { 
    212         char* endName; 
    213         DWORD offset;    
    214         struct KeFsDir* dir=rootDir; 
    215          
    216         /* Get to the directory */ 
    217         while ((endName=strchr(name,'/'))) 
    218         { 
    219                 offset=(DWORD)(endName-name); 
    220                 dir=KeFsDirLookup(name, strlen(name),dir); 
    221                 if (!dir) 
    222                         return -ENOENT; 
    223         } 
    224          
    225         KeFsAddDir(dir, name); 
    226          
    227         return 0; 
    228 } 
    229  
    230 int DevRemoveDevice(struct DevFsDevice* device) 
    231 { 
    232         KePrint("DevRemoveDevice\n"); 
    233         return 0; 
    234 } 
     181int DevFsAddDir(struct KeSet* set, char* name) 
     182{ 
     183        struct KeFsDir* dir; 
     184         
     185        dir = KeObjGetParentDevDir(&set->object); 
     186         
     187        if (!dir) 
     188                dir = rootDir; 
     189         
     190        set->devDir = KeFsAddDir(dir, name); 
     191         
     192        return 0; 
     193} 
     194 
     195SYMBOL_EXPORT(DevFsAddDir); 
    235196 
    236197int DevFsReadDir(struct File* file, void* dirEntries) 
     
    306267        rootDir=&rootEntry.dir; 
    307268 
    308         /* Add standard directories */ 
    309         DevAddDir("Consoles"); 
    310         DevAddDir("Special"); 
    311         DevAddDir("Storage"); 
    312         DevAddDir("Input"); 
    313  
    314         return 0; 
    315 } 
     269        return 0; 
     270}