3 * - Root Filesystem Driver
12 tVFS_Node *Root_InitDevice(char *Device, char *Options);
13 int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags);
14 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name);
15 char *Root_ReadDir(tVFS_Node *Node, int Pos);
16 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
17 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
18 tRamFS_File *Root_int_AllocFile();
21 tVFS_Driver gRootFS_Info = {
27 tRamFS_File RootFS_Files[MAX_FILES];
28 tVFS_ACL RootFS_ACLs[3] = {
29 {{0,0}, {0,VFS_PERM_ALL}}, // Owner (Root)
30 {{1,0}, {0,VFS_PERM_ALL}}, // Group (Root)
31 {{0,-1}, {0,VFS_PERM_ALL}} // World (Nobody)
36 * \fn tVFS_Node *Root_InitDevice(char *Device, char *Options)
37 * \brief Initialise the root filesystem
39 tVFS_Node *Root_InitDevice(char *Device, char *Options)
42 if(strcmp(Device, "root") != 0) {
47 root = &RootFS_Files[0];
49 root->Node.ImplPtr = root;
53 = root->Node.ATime = now();
54 root->Node.NumACLs = 3;
55 root->Node.ACLs = RootFS_ACLs;
57 //root->Node.Close = Root_CloseFile; // Not Needed (It's a RAM Disk!)
58 //root->Node.Relink = Root_RelinkRoot; // Not Needed (Why relink the root of the tree)
59 root->Node.FindDir = Root_FindDir;
60 root->Node.ReadDir = Root_ReadDir;
61 root->Node.MkNod = Root_MkNod;
67 * \fn int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
68 * \brief Create an entry in the root directory
70 int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
72 tRamFS_File *parent = Node->ImplPtr;
73 tRamFS_File *child = parent->Data.FirstChild;
74 tRamFS_File *prev = (tRamFS_File *) &parent->Data.FirstChild;
76 Log("Root_MkNod: (Node=%p, Name='%s', Flags=0x%x)", Node, Name, Flags);
78 // Find last child, while we're at it, check for duplication
79 for( ; child; prev = child, child = child->Next )
81 if(strcmp(child->Name, Name) == 0) return 0;
84 child = Root_int_AllocFile();
85 memset(child, 0, sizeof(tRamFS_File));
87 child->Name = malloc(strlen(Name)+1);
88 strcpy(child->Name, Name);
90 child->Parent = parent;
92 child->Data.FirstChild = NULL;
94 child->Node.ImplPtr = child;
95 child->Node.Flags = Flags;
96 child->Node.NumACLs = 0;
99 if(Flags & VFS_FFLAG_DIRECTORY)
101 child->Node.ReadDir = Root_ReadDir;
102 child->Node.FindDir = Root_FindDir;
103 child->Node.MkNod = Root_MkNod;
105 child->Node.Read = Root_Read;
106 child->Node.Write = Root_Write;
111 parent->Node.Size ++;
117 * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
118 * \brief Find an entry in the filesystem
120 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
122 tRamFS_File *parent = Node->ImplPtr;
123 tRamFS_File *child = parent->Data.FirstChild;
125 //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
127 for(;child;child = child->Next)
129 //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
130 if(strcmp(child->Name, Name) == 0) return &child->Node;
137 * \fn char *Root_ReadDir(tVFS_Node *Node, int Pos)
138 * \brief Get an entry from the filesystem
140 char *Root_ReadDir(tVFS_Node *Node, int Pos)
142 tRamFS_File *parent = Node->ImplPtr;
143 tRamFS_File *child = parent->Data.FirstChild;
145 for( ; child && Pos--; child = child->Next ) ;
147 if(Pos) return child->Name;
153 * \fn Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
154 * \brief Read from a file in the root directory
156 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
158 tRamFS_File *file = Node->ImplPtr;
160 if(Offset > Node->Size) return 0;
161 if(Length > Node->Size) return 0;
163 if(Offset+Length > Node->Size)
164 Length = Node->Size - Offset;
166 memcpy(Buffer, file->Data.Bytes+Offset, Length);
172 * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
173 * \brief Write to a file in the root directory
175 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
177 tRamFS_File *file = Node->ImplPtr;
179 // Check if buffer needs to be expanded
180 if(Offset + Length > Node->Size)
182 void *tmp = realloc( file->Data.Bytes, Offset + Length );
184 Warning("Root_Write - Increasing buffer size failed\n");
187 file->Data.Bytes = tmp;
188 Node->Size = Offset + Length;
189 Log(" Root_Write: Expanded buffer to %i bytes\n", Node->Size);
192 memcpy(file->Data.Bytes+Offset, Buffer, Length);
198 * \fn tRamFS_File *Root_int_AllocFile()
199 * \brief Allocates a file from the pool
201 tRamFS_File *Root_int_AllocFile()
204 for( i = 0; i < MAX_FILES; i ++ )
206 if( RootFS_Files[i].Name == NULL )
208 return &RootFS_Files[i];