X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Ffs%2Fdevfs.c;h=162f11134cdebcc3cbbc3451cb8702886c9a1a7f;hb=f3d0d7fcf0496a63625c92e5ab95471e202e958e;hp=90770a755d7cd6078a77679c69f74cb373cea95d;hpb=95a7eaaa4a1065334125b65130866f8d1048ddb7;p=tpg%2Facess2.git diff --git a/Kernel/vfs/fs/devfs.c b/Kernel/vfs/fs/devfs.c index 90770a75..162f1113 100644 --- a/Kernel/vfs/fs/devfs.c +++ b/Kernel/vfs/fs/devfs.c @@ -3,15 +3,18 @@ * Device Filesystem (DevFS) * - vfs/fs/devfs.c */ -#include +#include #include #include // === PROTOTYPES === - int DevFS_AddDevice(tDevFS_Driver *Dev); -tVFS_Node *DevFS_InitDevice(char *Device, char **Options); +#if 0 + int DevFS_AddDevice(tDevFS_Driver *Device); +void DevFS_DelDevice(tDevFS_Driver *Device); +#endif +tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options); char *DevFS_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name); // === GLOBALS === tVFS_Driver gDevFS_Info = { @@ -21,31 +24,86 @@ tVFS_Node gDevFS_RootNode = { .Size = 0, .Flags = VFS_FFLAG_DIRECTORY, .NumACLs = 1, - .ACLs = &gVFS_ACL_EveryoneRW, + .ACLs = &gVFS_ACL_EveryoneRX, .ReadDir = DevFS_ReadDir, .FindDir = DevFS_FindDir }; tDevFS_Driver *gDevFS_Drivers = NULL; int giDevFS_NextID = 1; +tShortSpinlock glDevFS_ListLock; // === CODE === /** - * \fn int DevFS_AddDevice(tDevFS_Driver *Dev) + * \fn int DevFS_AddDevice(tDevFS_Driver *Device) */ -int DevFS_AddDevice(tDevFS_Driver *Dev) +int DevFS_AddDevice(tDevFS_Driver *Device) { - Dev->Next = gDevFS_Drivers; - gDevFS_Drivers = Dev; - gDevFS_RootNode.Size ++; - return giDevFS_NextID++; + int ret = 0; + tDevFS_Driver *dev; + + SHORTLOCK( &glDevFS_ListLock ); + + // Check if the device is already registered or the name is taken + for( dev = gDevFS_Drivers; dev; dev = dev->Next ) + { + if(dev == Device) break; + if(strcmp(dev->Name, Device->Name) == 0) break; + } + + if(dev) { + if(dev == Device) + Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice", + dev, dev->Name); + else + Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p", + Device, dev->Name, dev); + ret = 0; // Error + } + else { + Device->Next = gDevFS_Drivers; + gDevFS_Drivers = Device; + gDevFS_RootNode.Size ++; + ret = giDevFS_NextID ++; + } + SHORTREL( &glDevFS_ListLock ); + + return ret; +} + +/** + * \brief Delete a device from the DevFS folder + */ +void DevFS_DelDevice(tDevFS_Driver *Device) +{ + tDevFS_Driver *prev = NULL, *dev; + + SHORTLOCK( &glDevFS_ListLock ); + // Search list for device + for(dev = gDevFS_Drivers; + dev && dev != Device; + prev = dev, dev = dev->Next + ); + + // Check if it was found + if(dev) + { + if(prev) + prev->Next = Device->Next; + else + gDevFS_Drivers = Device->Next; + } + else + Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered", + Device, Device->Name); + + SHORTREL( &glDevFS_ListLock ); } /** - * \fn tVFS_Node *DevFS_InitDevice(char *Device, char **Options) * \brief Initialise the DevFS and detect double-mounting, or just do nothing * \note STUB */ -tVFS_Node *DevFS_InitDevice(char *Device, char **Options) +tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options) { return &gDevFS_RootNode; } @@ -64,14 +122,17 @@ char *DevFS_ReadDir(tVFS_Node *Node, int Pos) dev = dev->Next ); - return strdup(dev->Name); + if(dev) + return strdup(dev->Name); + else + return NULL; } /** - * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) * \brief Get an entry from the devices directory */ -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) { tDevFS_Driver *dev; @@ -96,3 +157,4 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) // --- EXPORTS --- EXPORT(DevFS_AddDevice); +EXPORT(DevFS_DelDevice);