3 * InitRD Driver Version 1
8 #define DUMP_ON_MOUNT 1
11 extern tVFS_Node gInitRD_RootNode;
12 extern const int giInitRD_NumFiles;
13 extern tVFS_Node * const gInitRD_FileList[];
16 int InitRD_Install(char **Arguments);
17 tVFS_Node *InitRD_InitDevice(const char *Device, const char **Arguments);
18 void InitRD_Unmount(tVFS_Node *Node);
19 tVFS_Node *InitRD_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);
20 Uint64 InitRD_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Size, void *Buffer);
21 char *InitRD_ReadDir(tVFS_Node *Node, int ID);
22 tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name);
23 void InitRD_DumpDir(tVFS_Node *Node, int Indent);
26 MODULE_DEFINE(0, 0x0A, FS_InitRD, InitRD_Install, NULL);
27 tVFS_Driver gInitRD_FSInfo = {
28 "initrd", 0, InitRD_InitDevice, InitRD_Unmount, InitRD_GetNodeFromINode
32 * \brief Register initrd with the kernel
34 int InitRD_Install(char **Arguments)
36 Log_Notice("InitRD", "Installed");
37 VFS_AddDriver( &gInitRD_FSInfo );
43 * \brief Mount the InitRD
45 tVFS_Node *InitRD_InitDevice(const char *Device, const char **Arguments)
48 InitRD_DumpDir( &gInitRD_RootNode, 0 );
50 Log_Notice("InitRD", "Mounted");
51 return &gInitRD_RootNode;
55 * \brief Unmount the InitRD
57 void InitRD_Unmount(tVFS_Node *Node)
63 tVFS_Node *InitRD_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode)
65 if( Inode >= giInitRD_NumFiles ) return NULL;
66 return gInitRD_FileList[Inode];
70 * \brief Read from a file
72 Uint64 InitRD_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
74 if(Offset > Node->Size)
76 if(Offset + Length > Node->Size)
77 Length = Node->Size - Offset;
79 memcpy(Buffer, Node->ImplPtr+Offset, Length);
85 * \brief Read from a directory
87 char *InitRD_ReadDir(tVFS_Node *Node, int ID)
89 tInitRD_File *dir = Node->ImplPtr;
94 return strdup(dir[ID].Name);
98 * \brief Find an element in a directory
100 tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name)
103 tInitRD_File *dir = Node->ImplPtr;
105 LOG("Name = '%s'", Name);
107 for( i = 0; i < Node->Size; i++ )
109 if(strcmp(Name, dir[i].Name) == 0)
116 void InitRD_DumpDir(tVFS_Node *Node, int Indent)
119 char indent[Indent+1];
120 tInitRD_File *dir = Node->ImplPtr;
122 for( i = 0; i < Indent; i++ ) indent[i] = ' ';
125 for( i = 0; i < Node->Size; i++ )
127 Log_Debug("InitRD", "%s- %p %s", indent, dir[i].Node, dir[i].Name);
128 if(dir[i].Node->Flags & VFS_FFLAG_DIRECTORY)
129 InitRD_DumpDir(dir[i].Node, Indent+1);