44 * SPDX-License-Identifier: GPL-3.0-only
55 */
66
7- #include <fs/tarfs/tar.h>
87#include <machine/multiboot.h>
98#include <sys/device.h>
109#include <sys/stdkern.h>
2120 * do something useful).
2221 */
2322
24- // FIXME: These should not be declared here.
25- extern void null_install (void );
26- extern void vgatext_install (void );
27- extern void keyboard_install (void );
28- extern void pctimer_install (void );
29- extern void uart8250_install (void );
30-
3123static void ramdisk_init (void );
3224static void kernel_welcome (void );
3325
@@ -50,12 +42,20 @@ kernel_main(void)
5042static void
5143ramdisk_init (void )
5244{
45+ unsigned int i ;
5346 multiboot_module_t * multiboot_mods ;
54- unsigned char * tar_buffer ;
47+ unsigned char * tar ;
5548
5649 multiboot_mods = (multiboot_module_t * ) multiboot_info -> mods_addr ;
57- tar_buffer = (unsigned char * ) multiboot_mods [0 ].mod_start ;
58- vfs_mount ("tarfs" , "INITRD" , tar_buffer );
50+ for (i = 0 ; i < multiboot_info -> mods_count ; i ++ ) {
51+ /* We can afford to strcmp because "ramdisk" is static. */
52+ if (!strcmp ("ramdisk" , (char * ) multiboot_mods [0 ].string )) {
53+ /* We found the ramdisk. */
54+ tar = (unsigned char * ) multiboot_mods [i ].mod_start ;
55+ vfs_mount ("tarfs" , "INITRD" , tar );
56+ return ;
57+ }
58+ }
5959}
6060
6161static vfs_node_t *
@@ -76,160 +76,26 @@ fs_write_string(vfs_node_t *node, unsigned int offt, const char *str)
7676 return fs_write (node , offt , (unsigned char * ) str , strlen (str ));
7777}
7878
79- static void dump_path (vfs_node_t * stdout , char * path );
80- static void dump_dir (vfs_node_t * stdout , char * path , vfs_node_t * dir );
81-
82- static void
83- dump_dir (vfs_node_t * stdout , char * path , vfs_node_t * dir )
84- {
85- unsigned int i = 0 ;
86- vfs_node_t * node ;
87- size_t child_len ;
88- char * child_path ;
89-
90- while ((node = fs_readdir (dir , i ++ ))) {
91- child_len = strlen (path ) + strlen (node -> vn_name ) + 2 ;
92- child_path = (char * ) malloc (child_len );
93- if (child_path ) {
94- strcpy (child_path , path );
95- /* If the folder I'm in is not root. */
96- if (node -> vn_parent -> vn_parent ) {
97- strcat (child_path , "/" );
98- }
99- strcat (child_path , node -> vn_name );
100- dump_path (stdout , child_path );
101- free (child_path );
102- }
103- }
104- }
105-
106- static void
107- dump_file (vfs_node_t * stdout , vfs_node_t * node )
108- {
109- unsigned int read = 0 ;
110- char buf [128 ];
111- unsigned int offset = 0 ;
112-
113- fs_write_string (stdout , 0 , "\n" );
114- while ((read = fs_read (node , offset , buf , 128 )) > 0 ) {
115- fs_write (stdout , 0 , buf , read );
116- offset += read ;
117- }
118- fs_write_string (stdout , 0 , "\n" );
119- }
120-
121- static void
122- dump_path (vfs_node_t * stdout , char * path )
123- {
124- vfs_node_t * node = fs_resolve (path );
125-
126- if (node ) {
127- switch (node -> vn_flags ) {
128- case VN_FREGFILE :
129- fs_write_string (stdout , 0 , "[FIL]" );
130- break ;
131- case VN_FDIR :
132- fs_write_string (stdout , 0 , "[DIR]" );
133- break ;
134- case VN_FCHARDEV :
135- fs_write_string (stdout , 0 , "[CHD]" );
136- break ;
137- case VN_FBLOCKDEV :
138- fs_write_string (stdout , 0 , "[BLD]" );
139- break ;
140- }
141- fs_write_string (stdout , 0 , " " );
142- fs_write_string (stdout , 0 , path );
143- fs_write_string (stdout , 0 , " (" );
144- fs_write_string (stdout , 0 , node -> vn_name );
145- fs_write_string (stdout , 0 , ")\n" );
146- if (node -> vn_flags == VN_FDIR ) {
147- dump_dir (stdout , path , node );
148- } else if (node -> vn_flags == VN_FREGFILE ) {
149- dump_file (stdout , node );
150- }
151- }
152- }
153-
15479static void
155- dump_mountpoint (vfs_node_t * stdout , char * name )
156- {
157- char * path = malloc (strlen (name ) + 3 );
158- strcpy (path , name );
159- strcat (path , ":/" );
160- dump_path (stdout , path );
161- fs_write_string (stdout , 0 , "\n" );
162- }
163-
164- static void
165- dump_mountpoints (vfs_node_t * stdout )
80+ kernel_welcome (void )
16681{
167- vfs_node_t * rootfs , * mountpoint ;
168- unsigned int i = 0 ;
169-
170- rootfs = fs_resolve ("ROOT:/" );
171- if (rootfs ) {
172- while ((mountpoint = fs_readdir (rootfs , i ++ ))) {
173- /* Make sure ROOT is not dumped, infinite loop! */
174- if (strcmp (mountpoint -> vn_name , "ROOT" )) {
175- dump_mountpoint (stdout , mountpoint -> vn_name );
176- }
177- }
178- }
179- }
82+ vfs_node_t * vtcon , * motd ;
83+ int read , offt ;
84+ char buffer [64 ];
18085
181- static void
182- print_mountpoints (vfs_node_t * stdout )
183- {
184- vfs_node_t * rootfs , * mountpoint ;
185- unsigned int i = 0 ;
86+ vtcon = fs_resolve_and_open ("DEV:/vtcon" , VO_FWRITE );
18687
187- rootfs = fs_resolve ( "ROOT:/" );
188- if (rootfs ) {
189- fs_write_string ( stdout , 0 , "Mounted file systems:\n" ) ;
190- while ((mountpoint = fs_readdir ( rootfs , i ++ )) ) {
191- fs_write_string ( stdout , 0 , mountpoint -> vn_name );
192- fs_write_string ( stdout , 0 , "\n" ) ;
88+ motd = fs_resolve_and_open ( "INITRD:/SYSTEM/MOTD.TXT" , VO_FREAD );
89+ if (motd ) {
90+ offt = 0 ;
91+ while ((read = fs_read ( motd , offt , buffer , 64 )) > 0 ) {
92+ fs_write ( vtcon , 0 , buffer , read );
93+ offt += read ;
19394 }
194- fs_write_string (stdout , 0 , "\n" );
195- } else {
196- fs_write_string (stdout , 0 , "Error! No rootfs is present\n\n" );
95+ fs_write_string (vtcon , 0 , "\n" );
96+ fs_close (motd );
19797 }
198- }
199-
200- static unsigned int
201- octal2int (char * octstring )
202- {
203- unsigned int acc = 0 ;
204- while (* octstring ) {
205- acc = acc * 8 + (* octstring - '0' );
206- octstring ++ ;
207- }
208- return acc ;
209- }
210-
211- static void
212- kernel_welcome (void )
213- {
214- vfs_node_t * vtcon , * kbd , * uart ;
215- vtcon = fs_resolve_and_open ("DEV:/vtcon" , VO_FWRITE );
216- uart = fs_resolve_and_open ("DEV:/uart" , VO_FWRITE | VO_FREAD );
217-
218- print_mountpoints (vtcon );
219- dump_mountpoints (vtcon );
220-
221- fs_write_string (vtcon , 0 , "This is the NativeOS VTCON\n" );
222- fs_write_string (vtcon , 0 , "Press any key to test the keyboard :)\n\n" );
223-
224- fs_write_string (uart , 0 , "This is the NativeOS UART\n" );
225- fs_write_string (uart , 0 , "Type some characters to get echo:\n\n" );
226-
227- unsigned char buf [16 ];
228- unsigned int read ;
22998 for (;;) {
230- fs_read (vtcon , 0 , buf , 16 );
231-
232- read = fs_read (uart , 0 , buf , 16 );
233- fs_write (uart , 0 , buf , read );
99+ fs_read (vtcon , 0 , buffer , 64 );
234100 }
235101}
0 commit comments