3 * Device Filesystem (DevFS)
13 int DevFS_AddDevice(tDevFS_Driver *Device);
14 void DevFS_DelDevice(tDevFS_Driver *Device);
16 tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options);
17 void DevFS_Unmount(tVFS_Node *RootNode);
18 char *DevFS_ReadDir(tVFS_Node *Node, int Pos);
19 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name);
22 tVFS_Driver gDevFS_Info = {
23 "devfs", 0, DevFS_InitDevice, DevFS_Unmount, NULL
25 tVFS_NodeType gDevFS_DirType = {
26 .TypeName = "DevFS-Dir",
27 .ReadDir = DevFS_ReadDir,
28 .FindDir = DevFS_FindDir
30 tVFS_Node gDevFS_RootNode = {
32 .Flags = VFS_FFLAG_DIRECTORY,
34 .ACLs = &gVFS_ACL_EveryoneRX,
35 .Type = &gDevFS_DirType
37 tDevFS_Driver *gDevFS_Drivers = NULL;
38 int giDevFS_NextID = 1;
39 tShortSpinlock glDevFS_ListLock;
43 * \fn int DevFS_AddDevice(tDevFS_Driver *Device)
45 int DevFS_AddDevice(tDevFS_Driver *Device)
50 ENTER("pDevice", Device);
51 LOG("Device->Name = '%s'", Device->Name);
53 SHORTLOCK( &glDevFS_ListLock );
55 // Check if the device is already registered or the name is taken
56 for( dev = gDevFS_Drivers; dev; dev = dev->Next )
58 if(dev == Device) break;
59 if(strcmp(dev->Name, Device->Name) == 0) break;
64 Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice",
67 Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
68 Device, dev->Name, dev);
72 Device->Next = gDevFS_Drivers;
73 gDevFS_Drivers = Device;
74 gDevFS_RootNode.Size ++;
75 ret = giDevFS_NextID ++;
77 SHORTREL( &glDevFS_ListLock );
84 * \brief Delete a device from the DevFS folder
86 void DevFS_DelDevice(tDevFS_Driver *Device)
88 tDevFS_Driver *prev = NULL, *dev;
90 SHORTLOCK( &glDevFS_ListLock );
91 // Search list for device
92 for(dev = gDevFS_Drivers;
94 prev = dev, dev = dev->Next
97 // Check if it was found
101 prev->Next = Device->Next;
103 gDevFS_Drivers = Device->Next;
106 Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered",
107 Device, Device->Name);
109 SHORTREL( &glDevFS_ListLock );
113 * \brief Initialise the DevFS and detect double-mounting, or just do nothing
116 tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options)
118 return &gDevFS_RootNode;
121 void DevFS_Unmount(tVFS_Node *RootNode)
127 * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
129 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
133 if(Pos < 0) return NULL;
135 for(dev = gDevFS_Drivers;
141 return strdup(dev->Name);
147 * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
148 * \brief Get an entry from the devices directory
150 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
154 ENTER("pNode sName", Node, Name);
156 for(dev = gDevFS_Drivers;
161 //LOG("dev = %p", dev);
162 LOG("dev->Name = '%s'", dev->Name);
163 if(strcmp(dev->Name, Name) == 0) {
164 LEAVE('p', &dev->RootNode);
165 return &dev->RootNode;
174 EXPORT(DevFS_AddDevice);
175 EXPORT(DevFS_DelDevice);