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_Node gDevFS_RootNode = {
25 .Flags = VFS_FFLAG_DIRECTORY,
27 .ACLs = &gVFS_ACL_EveryoneRX,
28 .ReadDir = DevFS_ReadDir,
29 .FindDir = DevFS_FindDir
31 tDevFS_Driver *gDevFS_Drivers = NULL;
32 int giDevFS_NextID = 1;
33 tShortSpinlock glDevFS_ListLock;
37 * \fn int DevFS_AddDevice(tDevFS_Driver *Device)
39 int DevFS_AddDevice(tDevFS_Driver *Device)
44 SHORTLOCK( &glDevFS_ListLock );
46 // Check if the device is already registered or the name is taken
47 for( dev = gDevFS_Drivers; dev; dev = dev->Next )
49 if(dev == Device) break;
50 if(strcmp(dev->Name, Device->Name) == 0) break;
55 Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice",
58 Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
59 Device, dev->Name, dev);
63 Device->Next = gDevFS_Drivers;
64 gDevFS_Drivers = Device;
65 gDevFS_RootNode.Size ++;
66 ret = giDevFS_NextID ++;
68 SHORTREL( &glDevFS_ListLock );
74 * \brief Delete a device from the DevFS folder
76 void DevFS_DelDevice(tDevFS_Driver *Device)
78 tDevFS_Driver *prev = NULL, *dev;
80 SHORTLOCK( &glDevFS_ListLock );
81 // Search list for device
82 for(dev = gDevFS_Drivers;
84 prev = dev, dev = dev->Next
87 // Check if it was found
91 prev->Next = Device->Next;
93 gDevFS_Drivers = Device->Next;
96 Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered",
97 Device, Device->Name);
99 SHORTREL( &glDevFS_ListLock );
103 * \brief Initialise the DevFS and detect double-mounting, or just do nothing
106 tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options)
108 return &gDevFS_RootNode;
112 * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
114 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
118 if(Pos < 0) return NULL;
120 for(dev = gDevFS_Drivers;
126 return strdup(dev->Name);
132 * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
133 * \brief Get an entry from the devices directory
135 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
139 //ENTER("pNode sName", Node, Name);
141 for(dev = gDevFS_Drivers;
146 //LOG("dev = %p", dev);
147 //LOG("dev->Name = '%s'", dev->Name);
148 if(strcmp(dev->Name, Name) == 0) {
149 //LEAVE('p', &dev->RootNode);
150 return &dev->RootNode;
159 EXPORT(DevFS_AddDevice);
160 EXPORT(DevFS_DelDevice);