3 * InitRD Driver Version 1
8 #define DUMP_ON_MOUNT 0
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 size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t 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
30 tVFS_NodeType gInitRD_DirType = {
31 .ReadDir = InitRD_ReadDir,
32 .FindDir = InitRD_FindDir
34 tVFS_NodeType gInitRD_FileType = {
35 .Read = InitRD_ReadFile
39 * \brief Register initrd with the kernel
41 int InitRD_Install(char **Arguments)
43 Log_Notice("InitRD", "Installed");
44 VFS_AddDriver( &gInitRD_FSInfo );
50 * \brief Mount the InitRD
52 tVFS_Node *InitRD_InitDevice(const char *Device, const char **Arguments)
55 InitRD_DumpDir( &gInitRD_RootNode, 0 );
57 Log_Notice("InitRD", "Mounted (%i files)", giInitRD_NumFiles);
58 return &gInitRD_RootNode;
62 * \brief Unmount the InitRD
64 void InitRD_Unmount(tVFS_Node *Node)
70 tVFS_Node *InitRD_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode)
72 if( Inode >= giInitRD_NumFiles ) return NULL;
73 return gInitRD_FileList[Inode];
77 * \brief Read from a file
79 size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
81 if(Offset > Node->Size)
83 if(Offset + Length > Node->Size)
84 Length = Node->Size - Offset;
86 memcpy(Buffer, Node->ImplPtr+Offset, Length);
92 * \brief Read from a directory
94 char *InitRD_ReadDir(tVFS_Node *Node, int ID)
96 tInitRD_File *dir = Node->ImplPtr;
101 return strdup(dir[ID].Name);
105 * \brief Find an element in a directory
107 tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name)
110 tInitRD_File *dir = Node->ImplPtr;
112 LOG("Name = '%s'", Name);
114 for( i = 0; i < Node->Size; i++ )
116 if(strcmp(Name, dir[i].Name) == 0)
123 void InitRD_DumpDir(tVFS_Node *Node, int Indent)
126 char indent[Indent+1];
127 tInitRD_File *dir = Node->ImplPtr;
129 for( i = 0; i < Indent; i++ ) indent[i] = ' ';
132 for( i = 0; i < Node->Size; i++ )
134 Log_Debug("InitRD", "%s- %p %s", indent, dir[i].Node, dir[i].Name);
135 if(dir[i].Node->Flags & VFS_FFLAG_DIRECTORY)
136 InitRD_DumpDir(dir[i].Node, Indent+1);