Initial commit of kernel only
[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
19         };
20 tVFS_Node       gDevFS_RootNode = {
21         .NumACLs = 1,
22         .ACLs = &gVFS_ACL_EveryoneRW,
23         .ReadDir = DevFS_ReadDir,
24         .FindDir = DevFS_FindDir
25         };
26 tDevFS_Driver   *gDevFS_Drivers = NULL;
27  int    giDevFS_NextID = 1;
28
29 // === CODE ===
30 /**
31  * \fn int DevFS_AddDevice(tDevFS_Driver *Dev)
32  */
33 int DevFS_AddDevice(tDevFS_Driver *Dev)
34 {
35         Dev->Next = gDevFS_Drivers;
36         gDevFS_Drivers = Dev;
37         
38         return giDevFS_NextID++;
39 }
40
41 /**
42  * \fn tVFS_Node *DevFS_InitDevice(char *Device, char *Options)
43  * \brief Initialise the DevFS and detect double-mounting, or just do nothing
44  * \stub
45  */
46 tVFS_Node *DevFS_InitDevice(char *Device, char *Options)
47 {
48         return &gDevFS_RootNode;
49 }
50
51 /**
52  * \fn char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
53  */
54 char *DevFS_ReadDir(tVFS_Node *Node, int Pos)
55 {
56         tDevFS_Driver   *dev;
57         
58         if(Pos < 0)     return NULL;
59         
60         for(dev = gDevFS_Drivers;
61                 dev && Pos--;
62                 dev = dev->Next
63                 );
64         
65         return dev->Name;
66 }
67
68 /**
69  * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
70  * \brief Get an entry from the devices directory
71  */
72 tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name)
73 {
74         tDevFS_Driver   *dev;
75         
76         //ENTER("pNode sName", Node, Name);
77         
78         for(dev = gDevFS_Drivers;
79                 dev;
80                 dev = dev->Next
81                 )
82         {
83                 //LOG("dev = %p", dev);
84                 //LOG("dev->Name = '%s'", dev->Name);
85                 if(strcmp(dev->Name, Name) == 0) {
86                         //LEAVE('p', &dev->RootNode);
87                         return &dev->RootNode;
88                 }
89         }
90         
91         //LEAVE('n');
92         return NULL;
93 }
94
95 // --- EXPORTS ---
96 EXPORT(DevFS_AddDevice);

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