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;
109 parent->Node.Size ++;
115 * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
116 * \brief Find an entry in the filesystem
118 tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name)
120 tRamFS_File *parent = Node->ImplPtr;
121 tRamFS_File *child = parent->Data.FirstChild;
123 //Log("Root_FindDir: (Node=%p, Name='%s')", Node, Name);
125 for(;child;child = child->Next)
127 //Log(" Root_FindDir: strcmp('%s', '%s')", child->Node.Name, Name);
128 if(strcmp(child->Name, Name) == 0) return &child->Node;
135 * \fn char *Root_ReadDir(tVFS_Node *Node, int Pos)
136 * \brief Get an entry from the filesystem
138 char *Root_ReadDir(tVFS_Node *Node, int Pos)
140 tRamFS_File *parent = Node->ImplPtr;
141 tRamFS_File *child = parent->Data.FirstChild;
143 for( ; child && Pos--; child = child->Next ) ;
145 if(Pos) return child->Name;
151 * \fn Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
152 * \brief Read from a file in the root directory
154 Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
156 tRamFS_File *file = Node->ImplPtr;
158 if(Offset > Node->Size) return 0;
159 if(Length > Node->Size) return 0;
161 if(Offset+Length > Node->Size)
162 Length = Node->Size - Offset;
164 memcpy(Buffer, file->Data.Bytes+Offset, Length);
170 * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
171 * \brief Write to a file in the root directory
173 Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
175 tRamFS_File *file = Node->ImplPtr;
177 // Check if buffer needs to be expanded
178 if(Offset + Length > Node->Size)
180 void *tmp = realloc( file->Data.Bytes, Offset + Length );
182 Warning("Root_Write - Increasing buffer size failed\n");
185 file->Data.Bytes = tmp;
186 Node->Size = Offset + Length;
187 Log(" Root_Write: Expanded buffer to %i bytes\n", Node->Size);
190 memcpy(file->Data.Bytes+Offset, Buffer, Length);
196 * \fn tRamFS_File *Root_int_AllocFile()
197 * \brief Allocates a file from the pool
199 tRamFS_File *Root_int_AllocFile()
202 for( i = 0; i < MAX_FILES; i ++ )
204 if( RootFS_Files[i].Name == NULL )
206 return &RootFS_Files[i];