Fixing up doxygen comments
[tpg/acess2.git] / Kernel / vfs / fs / devfs.c
1 /*
2  * Acess 2
3  * Device Filesystem (DevFS)
4  * - vfs/fs/devfs.c
5  */
6 #include <acess.h>
7 #include <vfs.h>
8 #include <fs_devfs.h>
9
10 // === PROTOTYPES ===
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, const char *Name);
16
17 // === GLOBALS ===
18 tVFS_Driver     gDevFS_Info = {
19         "devfs", 0, DevFS_InitDevice, NULL, NULL
20         };
21 tVFS_Node       gDevFS_RootNode = {
22         .Size = 0,
23         .Flags = VFS_FFLAG_DIRECTORY,
24         .NumACLs = 1,
25         .ACLs = &gVFS_ACL_EveryoneRX,
26         .ReadDir = DevFS_ReadDir,
27         .FindDir = DevFS_FindDir
28         };
29 tDevFS_Driver   *gDevFS_Drivers = NULL;
30  int    giDevFS_NextID = 1;
31 tShortSpinlock  glDevFS_ListLock;
32
33 // === CODE ===
34 /**
35  * \fn int DevFS_AddDevice(tDevFS_Driver *Device)
36  */
37 int DevFS_AddDevice(tDevFS_Driver *Device)
38 {
39          int    ret = 0;
40         tDevFS_Driver   *dev;
41         
42         SHORTLOCK( &glDevFS_ListLock );
43         
44         // Check if the device is already registered or the name is taken
45         for( dev = gDevFS_Drivers; dev; dev = dev->Next )
46         {
47                 if(dev == Device)       break;
48                 if(strcmp(dev->Name, Device->Name) == 0)        break;
49         }
50         
51         if(dev) {
52                 if(dev == Device)
53                         Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice",
54                                 dev, dev->Name);
55                 else
56                         Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p",
57                                 Device, dev->Name, dev);
58                 ret = 0;        // Error
59         }
60         else {
61                 Device->Next = gDevFS_Drivers;
62                 gDevFS_Drivers = Device;
63                 gDevFS_RootNode.Size ++;
64                 ret = giDevFS_NextID ++;
65         }
66         SHORTREL( &glDevFS_ListLock );
67         
68         return ret;
69 }
70
71 /**
72  * \brief Delete a device from the DevFS folder
73  */
74 void DevFS_DelDevice(tDevFS_Driver *Device)
75 {
76         tDevFS_Driver   *prev = NULL, *dev;
77         
78         SHORTLOCK( &glDevFS_ListLock );
79         // Search list for device
80         for(dev = gDevFS_Drivers;
81                 dev && dev != Device;
82                 prev = dev, dev = dev->Next
83                 );
84         
85         // Check if it was found
86         if(dev)
87         {
88                 if(prev)
89                         prev->Next = Device->Next;
90                 else
91                         gDevFS_Drivers = Device->Next;
92         }
93         else
94                 Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered",
95                         Device, Device->Name);
96         
97         SHORTREL( &glDevFS_ListLock );
98 }
99
100 /**
101  * \fn tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
102  * \brief Initialise the DevFS and detect double-mounting, or just do nothing
103  * \note STUB
104  */
105 tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
106 {
107         return &gDevFS_RootNode;
108 }
109
110 /**
111  * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
112  */
113 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
114 {
115         tDevFS_Driver   *dev;
116         
117         if(Pos < 0)     return NULL;
118         
119         for(dev = gDevFS_Drivers;
120                 dev && Pos--;
121                 dev = dev->Next
122                 );
123         
124         if(dev)
125                 return strdup(dev->Name);
126         else
127                 return NULL;
128 }
129
130 /**
131  * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
132  * \brief Get an entry from the devices directory
133  */
134 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name)
135 {
136         tDevFS_Driver   *dev;
137         
138         //ENTER("pNode sName", Node, Name);
139         
140         for(dev = gDevFS_Drivers;
141                 dev;
142                 dev = dev->Next
143                 )
144         {
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;
150                 }
151         }
152         
153         //LEAVE('n');
154         return NULL;
155 }
156
157 // --- EXPORTS ---
158 EXPORT(DevFS_AddDevice);
159 EXPORT(DevFS_DelDevice);

UCC git Repository :: git.ucc.asn.au