X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Ffs%2Fdevfs.c;h=b3f4a57917bf7cedd06b9f10df00d13b71cd080d;hb=a2495c6ea4f4cab16b5d339ae511428e92e89e73;hp=90770a755d7cd6078a77679c69f74cb373cea95d;hpb=95a7eaaa4a1065334125b65130866f8d1048ddb7;p=tpg%2Facess2.git diff --git a/Kernel/vfs/fs/devfs.c b/Kernel/vfs/fs/devfs.c index 90770a75..b3f4a579 100644 --- a/Kernel/vfs/fs/devfs.c +++ b/Kernel/vfs/fs/devfs.c @@ -3,49 +3,111 @@ * 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 = { "devfs", 0, DevFS_InitDevice, NULL, NULL }; +tVFS_NodeType gDevFS_DirType = { + .TypeName = "DevFS-Dir", + .ReadDir = DevFS_ReadDir, + .FindDir = DevFS_FindDir + }; tVFS_Node gDevFS_RootNode = { .Size = 0, .Flags = VFS_FFLAG_DIRECTORY, .NumACLs = 1, - .ACLs = &gVFS_ACL_EveryoneRW, - .ReadDir = DevFS_ReadDir, - .FindDir = DevFS_FindDir + .ACLs = &gVFS_ACL_EveryoneRX, + .Type = &gDevFS_DirType }; 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 *Device) +{ + 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 */ -int DevFS_AddDevice(tDevFS_Driver *Dev) +void DevFS_DelDevice(tDevFS_Driver *Device) { - Dev->Next = gDevFS_Drivers; - gDevFS_Drivers = Dev; - gDevFS_RootNode.Size ++; - return giDevFS_NextID++; + 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 +126,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 +161,4 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) // --- EXPORTS --- EXPORT(DevFS_AddDevice); +EXPORT(DevFS_DelDevice);