3 * - Root Filesystem Driver
13 tVFS_Node *Root_InitDevice(char *Device, char **Options);
14 int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags);
15 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name);
16 char *Root_ReadDir(tVFS_Node *Node, int Pos);
17 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
18 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
19 tRamFS_File *Root_int_AllocFile();
22 tVFS_Driver gRootFS_Info = {
28 tRamFS_File RootFS_Files[MAX_FILES];
29 tVFS_ACL RootFS_ACLs[3] = {
30 {{0,0}, {0,VFS_PERM_ALL}}, // Owner (Root)
31 {{1,0}, {0,VFS_PERM_ALL}}, // Group (Root)
32 {{0,-1}, {0,VFS_PERM_ALL}} // World (Nobody)
37 * \fn tVFS_Node *Root_InitDevice(char *Device, char **Options)
38 * \brief Initialise the root filesystem
40 tVFS_Node *Root_InitDevice(char *Device, char **Options)
43 if(strcmp(Device, "root") != 0) {
48 root = &RootFS_Files[0];
50 root->Node.ImplPtr = root;
54 = root->Node.ATime = now();
55 root->Node.NumACLs = 3;
56 root->Node.ACLs = RootFS_ACLs;
58 //root->Node.Close = Root_CloseFile; // Not Needed (It's a RAM Disk!)
59 //root->Node.Relink = Root_RelinkRoot; // Not Needed (Why relink the root of the tree)
60 root->Node.FindDir = Root_FindDir;
61 root->Node.ReadDir = Root_ReadDir;
62 root->Node.MkNod = Root_MkNod;
68 * \fn int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
69 * \brief Create an entry in the root directory
71 int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
73 tRamFS_File *parent = Node->ImplPtr;
74 tRamFS_File *child = parent->Data.FirstChild;
75 tRamFS_File *prev = (tRamFS_File *) &parent->Data.FirstChild;
77 ENTER("pNode sName xFlags", Node, Name, Flags);
79 // Find last child, while we're at it, check for duplication
80 for( ; child; prev = child, child = child->Next )
82 if(strcmp(child->Name, Name) == 0) {
88 child = Root_int_AllocFile();
89 memset(child, 0, sizeof(tRamFS_File));
91 child->Name = malloc(strlen(Name)+1);
92 strcpy(child->Name, Name);
94 child->Parent = parent;
96 child->Data.FirstChild = NULL;
98 child->Node.ImplPtr = child;
99 child->Node.Flags = Flags;
100 child->Node.NumACLs = 0;
101 child->Node.Size = 0;
103 if(Flags & VFS_FFLAG_DIRECTORY)
105 child->Node.ReadDir = Root_ReadDir;
106 child->Node.FindDir = Root_FindDir;
107 child->Node.MkNod = Root_MkNod;
109 child->Node.Read = Root_Read;
110 child->Node.Write = Root_Write;
115 parent->Node.Size ++;
122 * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
123 * \brief Find an entry in the filesystem
125 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
127 tRamFS_File *parent = Node->ImplPtr;
128 tRamFS_File *child = parent->Data.FirstChild;
130 //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
132 for(;child;child = child->Next)
134 //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
135 if(strcmp(child->Name, Name) == 0) return &child->Node;
142 * \fn char *Root_ReadDir(tVFS_Node *Node, int Pos)
143 * \brief Get an entry from the filesystem
145 char *Root_ReadDir(tVFS_Node *Node, int Pos)
147 tRamFS_File *parent = Node->ImplPtr;
148 tRamFS_File *child = parent->Data.FirstChild;
150 for( ; child && Pos--; child = child->Next ) ;
152 if(Pos) return strdup(child->Name);
158 * \fn Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
159 * \brief Read from a file in the root directory
161 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
163 tRamFS_File *file = Node->ImplPtr;
165 if(Offset > Node->Size) return 0;
166 if(Length > Node->Size) return 0;
168 if(Offset+Length > Node->Size)
169 Length = Node->Size - Offset;
171 memcpy(Buffer, file->Data.Bytes+Offset, Length);
177 * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
178 * \brief Write to a file in the root directory
180 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
182 tRamFS_File *file = Node->ImplPtr;
184 // Check if buffer needs to be expanded
185 if(Offset + Length > Node->Size)
187 void *tmp = realloc( file->Data.Bytes, Offset + Length );
189 Warning("Root_Write - Increasing buffer size failed");
192 file->Data.Bytes = tmp;
193 Node->Size = Offset + Length;
194 //LOG("Expanded buffer to %i bytes", Node->Size);
197 memcpy(file->Data.Bytes+Offset, Buffer, Length);
203 * \fn tRamFS_File *Root_int_AllocFile()
204 * \brief Allocates a file from the pool
206 tRamFS_File *Root_int_AllocFile()
209 for( i = 0; i < MAX_FILES; i ++ )
211 if( RootFS_Files[i].Name == NULL )
213 return &RootFS_Files[i];