3 * Device Filesystem (DevFS)
11 int DevFS_AddDevice(tDevFS_Driver *Device);
12 void DevFS_DelDevice(tDevFS_Driver *Device);
13 tVFS_Node *DevFS_InitDevice(char *Device, char **Options);
14 char *DevFS_ReadDir(tVFS_Node *Node, int Pos);
15 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name);
18 tVFS_Driver gDevFS_Info = {
19 "devfs", 0, DevFS_InitDevice, NULL, NULL
21 tVFS_Node gDevFS_RootNode = {
23 .Flags = VFS_FFLAG_DIRECTORY,
25 .ACLs = &gVFS_ACL_EveryoneRX,
26 .ReadDir = DevFS_ReadDir,
27 .FindDir = DevFS_FindDir
29 tDevFS_Driver *gDevFS_Drivers = NULL;
30 int giDevFS_NextID = 1;
31 tSpinlock glDevFS_ListLock;
35 * \fn int DevFS_AddDevice(tDevFS_Driver *Device)
37 int DevFS_AddDevice(tDevFS_Driver *Device)
42 LOCK( &glDevFS_ListLock );
44 // Check if the device is already registered or the name is taken
45 for( dev = gDevFS_Drivers; dev; dev = dev->Next )
47 if(dev == Device) break;
48 if(strcmp(dev->Name, Device->Name) == 0) break;
53 Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice",
56 Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
57 Device, dev->Name, dev);
61 Device->Next = gDevFS_Drivers;
62 gDevFS_Drivers = Device;
63 gDevFS_RootNode.Size ++;
64 ret = giDevFS_NextID ++;
66 RELEASE( &glDevFS_ListLock );
72 * \brief Delete a device from the DevFS folder
74 void DevFS_DelDevice(tDevFS_Driver *Device)
76 tDevFS_Driver *prev = NULL, *dev;
78 LOCK( &glDevFS_ListLock );
79 // Search list for device
80 for(dev = gDevFS_Drivers;
82 prev = dev, dev = dev->Next
85 // Check if it was found
89 prev->Next = Device->Next;
91 gDevFS_Drivers = Device->Next;
94 Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered",
95 Device, Device->Name);
97 RELEASE( &glDevFS_ListLock );
101 * \fn tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
102 * \brief Initialise the DevFS and detect double-mounting, or just do nothing
105 tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
107 return &gDevFS_RootNode;
111 * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
113 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
117 if(Pos < 0) return NULL;
119 for(dev = gDevFS_Drivers;
125 return strdup(dev->Name);
131 * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
132 * \brief Get an entry from the devices directory
134 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
138 //ENTER("pNode sName", Node, Name);
140 for(dev = gDevFS_Drivers;
145 //LOG("dev = %p", dev);
146 //LOG("dev->Name = '%s'", dev->Name);
147 if(strcmp(dev->Name, Name) == 0) {
148 //LEAVE('p', &dev->RootNode);
149 return &dev->RootNode;
158 EXPORT(DevFS_AddDevice);
159 EXPORT(DevFS_DelDevice);