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 = {
22 "rootfs", 0, Root_InitDevice,
25 tRamFS_File RootFS_Files[MAX_FILES];
26 tVFS_ACL RootFS_ACLs[3] = {
27 {{0,0}, {0,VFS_PERM_ALL}}, // Owner (Root)
28 {{1,0}, {0,VFS_PERM_ALL}}, // Group (Root)
29 {{0,-1}, {0,VFS_PERM_ALL}} // World (Nobody)
34 * \fn tVFS_Node *Root_InitDevice(char *Device, char *Options)
35 * \brief Initialise the root filesystem
37 tVFS_Node *Root_InitDevice(char *Device, char *Options)
40 if(strcmp(Device, "root") != 0) {
45 root = &RootFS_Files[0];
47 root->Node.ImplPtr = root;
51 = root->Node.ATime = now();
52 root->Node.NumACLs = 3;
53 root->Node.ACLs = RootFS_ACLs;
55 //root->Node.Close = Root_CloseFile; // Not Needed (It's a RAM Disk!)
56 //root->Node.Relink = Root_RelinkRoot; // Not Needed (Why relink the root of the tree)
57 root->Node.FindDir = Root_FindDir;
58 root->Node.ReadDir = Root_ReadDir;
59 root->Node.MkNod = Root_MkNod;
65 * \fn int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
66 * \brief Create an entry in the root directory
68 int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags)
70 tRamFS_File *parent = Node->ImplPtr;
71 tRamFS_File *child = parent->Data.FirstChild;
72 tRamFS_File *prev = (tRamFS_File *) &parent->Data.FirstChild;
74 Log("Root_MkNod: (Node=%p, Name='%s', Flags=0x%x)", Node, Name, Flags);
76 // Find last child, while we're at it, check for duplication
77 for( ; child; prev = child, child = child->Next )
79 if(strcmp(child->Name, Name) == 0) return 0;
82 child = Root_int_AllocFile();
83 memset(child, 0, sizeof(tRamFS_File));
85 child->Name = malloc(strlen(Name)+1);
86 strcpy(child->Name, Name);
88 child->Parent = parent;
90 child->Data.FirstChild = NULL;
92 child->Node.ImplPtr = child;
93 child->Node.Flags = Flags;
94 child->Node.NumACLs = 0;
97 if(Flags & VFS_FFLAG_DIRECTORY)
99 child->Node.ReadDir = Root_ReadDir;
100 child->Node.FindDir = Root_FindDir;
101 child->Node.MkNod = Root_MkNod;
103 child->Node.Read = Root_Read;
104 child->Node.Write = Root_Write;
113 * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
114 * \brief Find an entry in the filesystem
116 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
118 tRamFS_File *parent = Node->ImplPtr;
119 tRamFS_File *child = parent->Data.FirstChild;
121 //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
123 for(;child;child = child->Next)
125 //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
126 if(strcmp(child->Name, Name) == 0) return &child->Node;
133 * \fn char *Root_ReadDir(tVFS_Node *Node, int Pos)
134 * \brief Get an entry from the filesystem
136 char *Root_ReadDir(tVFS_Node *Node, int Pos)
138 tRamFS_File *parent = Node->ImplPtr;
139 tRamFS_File *child = parent->Data.FirstChild;
141 for( ; child && Pos--; child = child->Next ) ;
143 if(Pos) return child->Name;
149 * \fn Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
150 * \brief Read from a file in the root directory
152 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
154 tRamFS_File *file = Node->ImplPtr;
156 if(Offset > Node->Size) return 0;
157 if(Length > Node->Size) return 0;
159 if(Offset+Length > Node->Size)
160 Length = Node->Size - Offset;
162 memcpy(Buffer, file->Data.Bytes+Offset, Length);
168 * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
169 * \brief Write to a file in the root directory
171 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
173 tRamFS_File *file = Node->ImplPtr;
175 // Check if buffer needs to be expanded
176 if(Offset + Length > Node->Size)
178 void *tmp = realloc( file->Data.Bytes, Offset + Length );
180 Warning("Root_Write - Increasing buffer size failed\n");
183 file->Data.Bytes = tmp;
184 Node->Size = Offset + Length;
185 Log(" Root_Write: Expanded buffer to %i bytes\n", Node->Size);
188 memcpy(file->Data.Bytes+Offset, Buffer, Length);
194 * \fn tRamFS_File *Root_int_AllocFile()
195 * \brief Allocates a file from the pool
197 tRamFS_File *Root_int_AllocFile()
200 for( i = 0; i < MAX_FILES; i ++ )
202 if( RootFS_Files[i].Name == NULL )
204 return &RootFS_Files[i];