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 ENTER("pNode sName xFlags", 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) {
87 child = Root_int_AllocFile();
88 memset(child, 0, sizeof(tRamFS_File));
90 child->Name = malloc(strlen(Name)+1);
91 strcpy(child->Name, Name);
93 child->Parent = parent;
95 child->Data.FirstChild = NULL;
97 child->Node.ImplPtr = child;
98 child->Node.Flags = Flags;
99 child->Node.NumACLs = 0;
100 child->Node.Size = 0;
102 if(Flags & VFS_FFLAG_DIRECTORY)
104 child->Node.ReadDir = Root_ReadDir;
105 child->Node.FindDir = Root_FindDir;
106 child->Node.MkNod = Root_MkNod;
108 child->Node.Read = Root_Read;
109 child->Node.Write = Root_Write;
114 parent->Node.Size ++;
121 * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
122 * \brief Find an entry in the filesystem
124 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
126 tRamFS_File *parent = Node->ImplPtr;
127 tRamFS_File *child = parent->Data.FirstChild;
129 //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
131 for(;child;child = child->Next)
133 //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
134 if(strcmp(child->Name, Name) == 0) return &child->Node;
141 * \fn char *Root_ReadDir(tVFS_Node *Node, int Pos)
142 * \brief Get an entry from the filesystem
144 char *Root_ReadDir(tVFS_Node *Node, int Pos)
146 tRamFS_File *parent = Node->ImplPtr;
147 tRamFS_File *child = parent->Data.FirstChild;
149 for( ; child && Pos--; child = child->Next ) ;
151 if(Pos) return strdup(child->Name);
157 * \fn Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
158 * \brief Read from a file in the root directory
160 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
162 tRamFS_File *file = Node->ImplPtr;
164 if(Offset > Node->Size) return 0;
165 if(Length > Node->Size) return 0;
167 if(Offset+Length > Node->Size)
168 Length = Node->Size - Offset;
170 memcpy(Buffer, file->Data.Bytes+Offset, Length);
176 * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
177 * \brief Write to a file in the root directory
179 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
181 tRamFS_File *file = Node->ImplPtr;
183 // Check if buffer needs to be expanded
184 if(Offset + Length > Node->Size)
186 void *tmp = realloc( file->Data.Bytes, Offset + Length );
188 Warning("Root_Write - Increasing buffer size failed");
191 file->Data.Bytes = tmp;
192 Node->Size = Offset + Length;
193 //LOG("Expanded buffer to %i bytes", Node->Size);
196 memcpy(file->Data.Bytes+Offset, Buffer, Length);
202 * \fn tRamFS_File *Root_int_AllocFile()
203 * \brief Allocates a file from the pool
205 tRamFS_File *Root_int_AllocFile()
208 for( i = 0; i < MAX_FILES; i ++ )
210 if( RootFS_Files[i].Name == NULL )
212 return &RootFS_Files[i];