3 * Device Filesystem (DevFS)
12 int DevFS_AddDevice(tDevFS_Driver *Device);
13 void DevFS_DelDevice(tDevFS_Driver *Device);
15 tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options);
16 char *DevFS_ReadDir(tVFS_Node *Node, int Pos);
17 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name);
20 tVFS_Driver gDevFS_Info = {
21 "devfs", 0, DevFS_InitDevice, NULL, NULL
23 tVFS_NodeType gDevFS_DirType = {
24 .TypeName = "DevFS-Dir",
25 .ReadDir = DevFS_ReadDir,
26 .FindDir = DevFS_FindDir
28 tVFS_Node gDevFS_RootNode = {
30 .Flags = VFS_FFLAG_DIRECTORY,
32 .ACLs = &gVFS_ACL_EveryoneRX,
33 .Type = &gDevFS_DirType
35 tDevFS_Driver *gDevFS_Drivers = NULL;
36 int giDevFS_NextID = 1;
37 tShortSpinlock glDevFS_ListLock;
41 * \fn int DevFS_AddDevice(tDevFS_Driver *Device)
43 int DevFS_AddDevice(tDevFS_Driver *Device)
48 SHORTLOCK( &glDevFS_ListLock );
50 // Check if the device is already registered or the name is taken
51 for( dev = gDevFS_Drivers; dev; dev = dev->Next )
53 if(dev == Device) break;
54 if(strcmp(dev->Name, Device->Name) == 0) break;
59 Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice",
62 Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
63 Device, dev->Name, dev);
67 Device->Next = gDevFS_Drivers;
68 gDevFS_Drivers = Device;
69 gDevFS_RootNode.Size ++;
70 ret = giDevFS_NextID ++;
72 SHORTREL( &glDevFS_ListLock );
78 * \brief Delete a device from the DevFS folder
80 void DevFS_DelDevice(tDevFS_Driver *Device)
82 tDevFS_Driver *prev = NULL, *dev;
84 SHORTLOCK( &glDevFS_ListLock );
85 // Search list for device
86 for(dev = gDevFS_Drivers;
88 prev = dev, dev = dev->Next
91 // Check if it was found
95 prev->Next = Device->Next;
97 gDevFS_Drivers = Device->Next;
100 Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered",
101 Device, Device->Name);
103 SHORTREL( &glDevFS_ListLock );
107 * \brief Initialise the DevFS and detect double-mounting, or just do nothing
110 tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options)
112 return &gDevFS_RootNode;
116 * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
118 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
122 if(Pos < 0) return NULL;
124 for(dev = gDevFS_Drivers;
130 return strdup(dev->Name);
136 * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
137 * \brief Get an entry from the devices directory
139 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
143 //ENTER("pNode sName", Node, Name);
145 for(dev = gDevFS_Drivers;
150 //LOG("dev = %p", dev);
151 //LOG("dev->Name = '%s'", dev->Name);
152 if(strcmp(dev->Name, Name) == 0) {
153 //LEAVE('p', &dev->RootNode);
154 return &dev->RootNode;
163 EXPORT(DevFS_AddDevice);
164 EXPORT(DevFS_DelDevice);