Added `strdup` library function and removed VFS_FREEPLZ, also added valid tVFS_Node...
[tpg/acess2.git] / Kernel / vfs / fs / devfs.c
1 /*
2  * Acess 2
3  * Device Filesystem (DevFS)
4  * - vfs/fs/devfs.c
5  */
6 #include <common.h>
7 #include <vfs.h>
8 #include <fs_devfs.h>
9
10 // === PROTOTYPES ===
11  int    DevFS_AddDevice(tDevFS_Driver *Dev);
12 tVFS_Node       *DevFS_InitDevice(char *Device, char *Options);
13 char    *DevFS_ReadDir(tVFS_Node *Node, int Pos);
14 tVFS_Node       *DevFS_FindDir(tVFS_Node *Node, char *Name);
15
16 // === GLOBALS ===
17 tVFS_Driver     gDevFS_Info = {
18         "devfs", 0, DevFS_InitDevice, NULL, NULL
19         };
20 tVFS_Node       gDevFS_RootNode = {
21         .Size = 0,
22         .Flags = VFS_FFLAG_DIRECTORY,
23         .NumACLs = 1,
24         .ACLs = &gVFS_ACL_EveryoneRW,
25         .ReadDir = DevFS_ReadDir,
26         .FindDir = DevFS_FindDir
27         };
28 tDevFS_Driver   *gDevFS_Drivers = NULL;
29  int    giDevFS_NextID = 1;
30
31 // === CODE ===
32 /**
33  * \fn int DevFS_AddDevice(tDevFS_Driver *Dev)
34  */
35 int DevFS_AddDevice(tDevFS_Driver *Dev)
36 {
37         Dev->Next = gDevFS_Drivers;
38         gDevFS_Drivers = Dev;
39         gDevFS_RootNode.Size ++;
40         return giDevFS_NextID++;
41 }
42
43 /**
44  * \fn tVFS_Node *DevFS_InitDevice(char *Device, char *Options)
45  * \brief Initialise the DevFS and detect double-mounting, or just do nothing
46  * \stub
47  */
48 tVFS_Node *DevFS_InitDevice(char *Device, char *Options)
49 {
50         return &gDevFS_RootNode;
51 }
52
53 /**
54  * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
55  */
56 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
57 {
58         tDevFS_Driver   *dev;
59         
60         if(Pos < 0)     return NULL;
61         
62         for(dev = gDevFS_Drivers;
63                 dev && Pos--;
64                 dev = dev->Next
65                 );
66         
67         return strdup(dev->Name);
68 }
69
70 /**
71  * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
72  * \brief Get an entry from the devices directory
73  */
74 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
75 {
76         tDevFS_Driver   *dev;
77         
78         //ENTER("pNode sName", Node, Name);
79         
80         for(dev = gDevFS_Drivers;
81                 dev;
82                 dev = dev->Next
83                 )
84         {
85                 //LOG("dev = %p", dev);
86                 //LOG("dev->Name = '%s'", dev->Name);
87                 if(strcmp(dev->Name, Name) == 0) {
88                         //LEAVE('p', &dev->RootNode);
89                         return &dev->RootNode;
90                 }
91         }
92         
93         //LEAVE('n');
94         return NULL;
95 }
96
97 // --- EXPORTS ---
98 EXPORT(DevFS_AddDevice);

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