Added Interval Time Scheduler (ITS) for calling kernel functions in time interval...
[ZeXOS.git] / kernel / core / commands.c
blob0ef1b76d9a2e09fd41ee333edddcd1653e563b30
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <build.h>
23 #include <system.h>
24 #include <arch/io.h>
25 #include <string.h>
26 #include <partition.h>
27 #include <env.h>
28 #include <dev.h>
29 #include <vfs.h>
30 #include <fs.h>
31 #include <tty.h>
32 #include <proc.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <net/socket.h>
36 #include <module.h>
37 #include <commands.h>
38 #include <signal.h>
39 #include <smp.h>
40 #include <build.h>
41 #include <config.h>
42 #include <net/if.h>
43 #include <net/net.h>
44 #include <net/ip.h>
45 #include <net/ndp.h>
46 #include <net/tun.h>
47 #include <net/icmp.h>
48 #include <net/hostname.h>
49 #include <mouse.h>
50 #include <pipe.h>
51 #include <cache.h>
52 #include <sound/audio.h>
54 command_t command_list;
55 extern partition_t partition_list;
57 unsigned char test[80];
59 typedef void (*void_fn_void_t)(void);
61 extern task_t task_list;
62 extern vfs_t vfs_list;
63 extern int cstrcmp (char *one, char *two);
64 extern unsigned long file_cache_id;
65 extern task_t *_curr_task;
66 extern module_t *module_load (char *modname);
67 extern unsigned long timer_ticks;
70 char *argparse (char *cmd)
72 unsigned cmd_len = strlen (cmd);
73 unsigned p = 1;
75 while (p < cmd_len) {
76 if (cmd[p] == ' ')
77 return cmd + p + 1;
79 p ++;
82 return "";
85 /*************************************************************\
86 | OMMANDs |
87 \*************************************************************/
90 unsigned command_help (char *command, unsigned len)
92 command_t *ctx;
94 tty_t *tty = currtty;
96 tty_cls (tty);
98 for (ctx = command_list.next; ctx != &command_list; ctx = ctx->next) {
99 printf ("%s : %s\n", ctx->name, ctx->desc);
101 if (tty->screen_y >= (tty_char.y-1)) {
102 if (!vgagui)
103 video_color (0, 15);
105 printf ("Press enter to continue");
107 video_color (15, 0);
108 printf (" ");
110 /* wait, until enter key is pressed */
111 while (1)
112 if (tty == currtty) {
113 if (getkey () != '\n')
114 schedule ();
115 else
116 break;
117 } else
118 schedule ();
120 tty_cls (tty);
124 return 1;
127 unsigned command_hdd (char *command, unsigned len)
129 #ifdef ARCH_i386
130 int t;
131 int m;
132 int c;
133 int c2;
134 int h;
135 int s;
137 outb (0x70, 0x12);
138 t = inb (0x71);
140 if (t >> 4 == 0)
141 printf ("/dev/hda not installed\n");
142 else {
143 outb (0x70, 0x1b);
144 c = inb (0x71);
145 outb (0x70, 0x1c);
146 c2 = inb (0x71);
147 outb (0x70, 0x1d);
148 h = inb (0x71);
149 outb (0x70, 0x23);
150 s = inb (0x71);
152 printf ("/dev/hda installed - CHS=%d-%d:%d:%d\n", c, c2, h, s);
155 if (t & 0xF == 0)
156 printf ("/dev/hdb not installed\n");
157 else {
158 outb (0x70, 0x24);
159 c = inb (0x71);
160 outb (0x70, 0x25);
161 c2 = inb (0x71);
162 outb (0x70, 0x26);
163 h = inb (0x71);
164 outb (0x70, 0x2c);
165 s = inb (0x71);
167 printf ("/dev/hdb installed - CHS=%d-%d:%d:%d\n", c, c2, h, s);
169 #endif
171 return 1;
174 unsigned command_reboot (char *command, unsigned len)
176 arch_cpu_reset ();
178 while (1);
180 return 1;
183 unsigned command_halt (char *command, unsigned len)
185 arch_cpu_shutdown ();
187 kprintf ("\nSystem halted\nPlease press power button ..");
189 int_disable ();
191 while(1);
193 return 1;
196 unsigned command_tasks (char *command, unsigned len)
198 printf ("id\tname\tpriority\n");
200 task_t *task;
201 for (task = task_list.next; task != &task_list; task = task->next)
202 printf ("%d\t%s\t%u\n", task->id, task->name, task->priority);
204 return 1;
207 unsigned command_ps (char *command, unsigned len)
209 proc_display ();
211 return 1;
214 unsigned command_uptime (char *command, unsigned len)
216 uptime ();
218 return 1;
221 unsigned command_version (char *command, unsigned len)
223 osinfo ();
225 return 1;
228 unsigned command_debug (char *command, unsigned len)
230 strcpy (test, argparse (command));
232 unsigned l = strlen (test);
234 if (l) {
235 debug = atoi (test);
237 printf ("Developer mode was enabled with mask 0x%x.\n", debug);
239 return 1;
242 printf ("Developer mode was disabled.\n");
243 debug = 0;
245 return 1;
248 unsigned command_mount (char *command, unsigned len)
250 strcpy (test, argparse (command));
251 char devname[20];
252 char mountpoint[32];
254 unsigned l = strlen (test);
255 unsigned x = 0;
256 while (x < l) {
257 if (test[x] == ' ')
258 break;
259 x ++;
262 memcpy (devname, test, x);
263 devname[x] = '\0';
264 strcpy (mountpoint, argparse (test));
265 unsigned y = strlen (mountpoint);
267 if (mountpoint[y-1] != '/') {
268 mountpoint[y] = '/';
269 mountpoint[y+1] = '\0';
272 if (x && y) {
273 partition_t *p = partition_find (devname);
275 if (p)
276 mount (p, "", mountpoint);
277 else
278 printf ("ERROR -> partition %s does not exists\n", devname);
279 } else
280 mount_display ();
282 return 1;
285 unsigned command_umount (char *command, unsigned len)
287 char mountpoint[32];
288 strcpy (mountpoint, argparse (command));
290 unsigned y = strlen (mountpoint);
291 unsigned x = 0;
293 if (mountpoint[y-1] != '/') {
294 mountpoint[y] = '/';
295 mountpoint[y+1] = '\0';
298 if (y) {
299 partition_t *partition;
300 for (partition = partition_list.next; partition != &partition_list; partition = partition->next) {
301 if (umount (partition, mountpoint))
302 x ++;
305 if (!x)
306 printf ("ERROR -> directory %s is not mounted\n", mountpoint);
308 if (x > 1)
309 printf ("WARNING -> multiple (%d) umount of %s\n", x, mountpoint);
310 } else
311 return 0;
313 return 1;
316 unsigned command_env (char *command, unsigned len)
318 env_display ();
320 return 1;
323 unsigned command_cd (char *command, unsigned len)
325 strcpy (test, argparse (command));
327 cd (test);
329 return 1;
332 unsigned command_ls (char *command, unsigned len)
334 strcpy (test, argparse (command));
336 ls (test);
338 return 1;
341 unsigned command_cat (char *command, unsigned len)
343 strcpy (test, argparse (command));
345 cat (test);
347 return 1;
350 unsigned command_cp (char *command, unsigned len)
352 strcpy (test, argparse (command));
354 unsigned l = strlen (test);
355 unsigned p = 0;
357 while (l) {
358 if (test[l] == ' ') {
359 test[l] = '\0';
360 p = l;
363 l --;
366 if (!p) {
367 printf ("Syntax:\ncp <source> <destination>\n");
368 return 0;
371 cp (test, test+p+1);
373 return 1;
377 unsigned command_rm (char *command, unsigned len)
379 strcpy (test, argparse (command));
381 rm (test);
383 return 1;
386 unsigned command_mkdir (char *command, unsigned len)
388 strcpy (test, argparse (command));
390 mkdir (test);
392 return 1;
395 unsigned command_touch (char *command, unsigned len)
397 strcpy (test, argparse (command));
399 touch (test);
401 return 1;
404 unsigned command_exec (char *command, unsigned len)
406 if (!strncmp ("./", command, 2))
407 strcpy (test, command+2);
408 else
409 strcpy (test, argparse (command));
411 unsigned arg_len = strlen (argparse (test));
412 char arg[arg_len+1];
413 strcpy (arg, argparse (test));
414 arg[arg_len] = '\0';
416 unsigned test_len = strlen (test);
418 tty_t *tty = currtty;
420 if (!tty)
421 return 0;
423 /* lock current tty keyboard */
424 tty_lock (tty);
426 /* if there is argument after name, rewrite space character to zero */
427 if (test [test_len-(arg_len+1)] == ' ')
428 test [test_len-(arg_len+1)] = '\0';
429 else
430 test [test_len-arg_len] = '\0';
432 vfs_content_t content;
433 /* read file data from filesystem */
434 int ret = vfs_read (test, strlen (test), &content);
436 if (ret < 0) {
437 printf ("%s: command not found\n", test);
438 DPRINT (DBG_CMDS, "ERROR -> vfs_read () - '%s'\n", test);
439 tty_unlock (tty);
440 return 0;
443 unsigned bin_len = content.len;
445 unsigned char *bin = (unsigned char *) swmalloc (bin_len);
447 if (!bin) {
448 printf ("ERROR -> out of memory\n");
449 return 0;
452 //paging_disable ();
454 /* copy image to page aligned memory */
455 memcpy (bin, content.ptr, bin_len);
457 //paging_enable ();
459 cache_closebyptr (content.ptr);
461 unsigned entry, code, data, data_off, bss;
462 int err = exec_elf (bin, &entry, &data, &data_off, &bss);
464 if (err) {
465 printf ("ERROR -> invalid ELF exec\n");
467 /* free program image */
468 swfree (bin, bin_len);
470 tty_unlock (tty);
471 return 0;
474 /* create process */
475 proc_t *proc = proc_create (tty, test, entry);
477 /* check for & character as app parameter */
478 unsigned d = 0;
479 while (d < arg_len) {
480 if (arg[d] == '&') {
481 if (proc_flag_set (proc, PROC_FLAG_DAEMON))
482 printf ("%s: started as daemon\n", test);
484 arg[d] = '\0';
486 if (arg_len > 2 && arg[d-1] == ' ') {
487 arg[d-1] = '\0';
488 arg_len --;
491 arg_len --;
493 break;
495 d ++;
498 if (!proc) {
499 printf ("ERROR -> Invalid process: %s\n", test);
501 /* free program image */
502 swfree (bin, bin_len);
504 tty_unlock (tty);
505 return 0;
508 /* save process information to structure for later use */
509 proc->start = (unsigned) bin;
510 proc->code = entry;
511 proc->data = data;
512 proc->data_off = data_off;
513 proc->bss = bss;
514 proc->end = (unsigned) (bin + bin_len);
516 /* well, set argument for out app */
517 proc_arg_set (proc, arg, arg_len);
519 proc_vmem_map (proc);
521 /* Is this process started as daemon ? */
522 /* wait here, until pid != 0*/
523 if (!(proc->flags & PROC_FLAG_DAEMON))
524 while (proc->pid)
525 schedule ();
527 /* enable interrupts */
528 int_enable ();
530 /* unlock tty console - user can write in */
531 tty_unlock (tty);
533 _curr_task = proc->tty->task; // this is pretty needed for correct return to our tty task
535 if (!(proc->flags & PROC_FLAG_DAEMON)) {
536 if (!proc_done (proc))
537 for (;;) // NOTE: heh, this is good stuff :P
538 schedule ();
540 /* free image of elf-bss section */
541 //flush_elf (bss);
543 /* free program image */
544 swfree (bin, bin_len);
547 /* switch to next task */
548 schedule ();
550 return 1;
553 unsigned command_lsdev (char *command, unsigned len)
555 dev_display ();
557 return 1;
560 unsigned command_login (char *command, unsigned len)
562 currtty->user = NULL;
563 currtty->logged = false;
565 video_color (7, 0);
566 printf ("login: ");
568 return 1;
571 unsigned command_serialw (char *command, unsigned len)
573 dev_t *dev = dev_find ("/dev/com0");
575 if (dev) {
576 unsigned len = strlen (argparse (command));
577 char data[len+1];
578 memcpy (data, argparse (command), len);
579 data[len] = '\0';
581 dev->handler (DEV_ACT_WRITE, data, len);
583 printf ("serialw: %s\n", data);
586 return 1;
589 unsigned command_serialr (char *command, unsigned len)
591 dev_t *dev = dev_find ("/dev/com0");
593 if (dev) {
594 char data[11];
596 dev->handler (DEV_ACT_READ, data, 1);
598 printf ("serialr: %s\n", data);
601 return 1;
604 unsigned command_fdisk (char *command, unsigned len)
606 char *parm = argparse (command);
608 fdisk (parm, strlen (parm));
610 return 1;
613 unsigned command_hdcat (char *command, unsigned len)
615 tty_lock (currtty);
617 dev_t *dev = (dev_t *) dev_find (argparse (command));
619 if (dev) {
620 partition_t p;
621 p.base_io = 0;
623 switch (dev->devname[7]) {
624 case 'a':
625 p.id = 0;
626 p.base_io = 0x1F0;
627 break;
628 case 'b':
629 p.id = 1;
630 p.base_io = 0x1F0;
631 break;
632 case 'c':
633 p.id = 0;
634 p.base_io = 0x170;
635 break;
636 case 'd':
637 p.id = 1;
638 p.base_io = 0x170;
639 break;
642 int c, d = 0;
643 unsigned char block[512];
645 printf ("dev: %s\n", dev->devname);
647 while (!key_pressed (1)) {
648 if (key_pressed (72) == 1) {
649 printf ("##block: %d\n", d);
650 dev->handler (DEV_ACT_READ, &p, block, "", d);
652 for (c = 0; c < 512; c ++)
653 printf ("%c", (unsigned) block[c]);
654 d ++;
657 usleep (5);
659 } else
660 printf ("Please specify block device, example: hdcat /dev/hda\n");
662 tty_unlock (currtty);
664 return 1;
667 unsigned command_free (char *command, unsigned len)
669 util_cmdfree ();
671 return 1;
674 unsigned command_top (char *command, unsigned len)
676 tty_lock (currtty);
678 proc_top ();
680 tty_unlock (currtty);
682 return 1;
685 unsigned command_date (char *command, unsigned len)
687 tm *t = rtc_getcurrtime ();
689 printf ("%02u:%02u:%02u, %u.%u.%u\n",
690 t->tm_hour, t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon, t->tm_year);
692 return 1;
696 Tone Frequency (Hz)
697 C 130.8
698 D 146.8
699 E 164.8
700 F 174.6
701 G 196.0
702 A 220.0
703 H 246.9
705 C 261.6
706 D 293.7
707 E 329.6
708 F 349.2
709 G 392.0
710 A 440.0
711 H 493.9
713 C 523.3
714 D 587.3
715 E 659.3
716 F 698.5
717 G 784.0
718 A 880.0
719 H 987.8
721 C 1046.5
722 D 1174.7
723 E 1318.5
724 F 1396.9
725 G 1568.0
726 A 1760.0
727 H 1975.5
730 void play_tone (dev_t *dev, char tone, char type, char time)
732 unsigned t = 2;
734 switch (type) {
735 case '1':
736 t = 1;
737 break;
738 case '2':
739 t = 2;
740 break;
741 case '3':
742 t = 3;
743 break;
744 case '4':
745 t = 4;
746 break;
750 unsigned tt = 1;
752 printf ("play_tone (.., %c, %d, %d);\n", tone, t, tt);
754 switch (tone) {
755 case 'c':
756 dev->handler (DEV_ACT_PLAY, 131*t);
757 break;
758 case 'd':
759 dev->handler (DEV_ACT_PLAY, 147*t);
760 break;
761 case 'e':
762 dev->handler (DEV_ACT_PLAY, 165*t);
763 break;
764 case 'f':
765 dev->handler (DEV_ACT_PLAY, 175*t);
766 break;
767 case 'g':
768 dev->handler (DEV_ACT_PLAY, 196*t);
769 break;
770 case 'a':
771 dev->handler (DEV_ACT_PLAY, 220*t);
772 break;
773 case 'h':
774 dev->handler (DEV_ACT_PLAY, 247*t);
775 break;
776 case 'C':
777 dev->handler (DEV_ACT_PLAY, 136*t);
778 break;
779 case 'F':
780 dev->handler (DEV_ACT_PLAY, 188*t);
781 break;
784 switch (time) {
785 case '0':
786 timer_wait (2500);
787 break;
788 case '1':
789 timer_wait (1250);
790 break;
791 case '2':
792 timer_wait (625);
793 break;
798 printf ("end: play_tone ();\n");
800 dev->handler (DEV_ACT_PLAY, 0);
803 void play_song (dev_t *dev, char *data)
805 printf ("play_song ();\n");
806 unsigned i = 0, l = strlen (data);
807 unsigned time = 1;
808 while (i != l) {
809 switch (data[i]) {
810 printf ("switch ()\n");
811 case 'p':
813 switch (data[i+1]) {
814 case '0':
815 timer_wait (2500);
816 break;
817 case '1':
818 timer_wait (1250);
819 break;
820 case '2':
821 timer_wait (625);
822 break;
826 i ++;
827 break;
828 case ' ':
829 break;
830 default:
831 play_tone (dev, data[i], data[i+1], data[i+2]);
832 i += 2;
833 break;
836 i ++;
841 unsigned command_spk (char *command, unsigned len)
843 unsigned int freq = 20;
845 dev_t *dev = dev_find ("/dev/pcspk");
847 if (dev) {
849 We wish you a merry christmas v1.0
851 D2(1/8) G2(1/8) G2(1/16) A2(1/16) G2(1/16) Fis2(1/16) E2(1/8) C2(1/8) E2(1/8) A2(1/8) A2(1/16) H2(1/16) A2(1/16) G2(1/16) Fis2(1/8) D2(1/4) H2(1/8) H2(1/16) C3(1/16) H2(1/16) A2(1/16) G2(1/8) E2(1/8) D2(1/16) D2(1/16) E2(1/8) A2(1/8) Fis2(1/8) G2(1/8)
854 play_song (dev, "d21 g21 g22 a22 g22 F22 e21 c21 e21 a21 a22 h22 a22 g22 F21 d20 h21 h22 c32 h22 a22 g21 e21 d22 d22 e21 a21 F21 g21");
856 timer_wait (2000);
859 We wish you a merry christmas v3.0
861 G2(1/8) C3(1/8) C3(1/16) D3(1/16) C3(1/16) H2(1/16) A2(1/4) D3(1/8) D3(1/16) E3(1/16) D3(1/16) C3(1/16) H2(1/4) G2(1/8) E3(1/8) E3(1/16) F3(1/16) E3(1/16) D3(1/16) C3(1/8) A2(1/8) G2(1/8) A2(1/8) D3(1/8) H2(1/8) C3(1/8)
864 play_song (dev, "g21 c31 c32 d32 c32 h22 a20 d31 d32 e32 d32 c32 h20 g21 e31 e32 f32 e32 d32 c31 a21 g21 a21 d31 h21 c31");
866 timer_wait (2000);
869 Dallas v2.0
870 G2(1/8) C3(1/8) P(1/16) G2(1/16) G3(1/8) C3(1/16) E3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) G3(1/16) P(1/16) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) E3(1/16) F3(1/16) D3(1/8) G3(1/8) G3(1/8)
872 /* play_song (dev, "g21 c31 p2 g22 g31 c32 e31 d32 e32 c31 g21 c31 a31 g31 e32 f32 g31 g32 p2 g21 c31 a31 g31 e32 f32 g31 d32 e32 c31 g21 c31 e32 f32 d31 g31 g31");*/
874 //timer_wait (2000);
877 return 1;
880 extern bool bus_pci_acthandler (unsigned act, char *block, unsigned block_len);
881 extern netif_t netif_list;
882 extern void ext2_dump ();
883 void thread_test ()
885 while (1) {
887 kprintf ("hu\n");
889 unsigned long timer_start = timer_ticks + ((unsigned) 1 * 1000);
891 while (timer_start > timer_ticks)
892 schedule ();
896 extern unsigned start;
897 extern unsigned end;
898 extern bool ide_acthandler (unsigned act, partition_t *p, char *block, char *more, int n);
899 unsigned command_test (char *command, unsigned len)
901 partition_t *p = partition_find ("/dev/hda0");
903 if (p)
904 mount (p, "", "/mnt/hdd/");
905 else
906 return 0;
908 cd ("/mnt/hdd");
910 return 1;
912 extern char *vgafb;
913 extern char *vgadb;
914 unsigned command_test2 (char *command, unsigned len)
916 partition_t *p = partition_find ("/dev/hdc0");
918 if (p)
919 mount (p, "", "/mnt/cdrom/");
920 else
921 return 0;
923 cd ("/mnt/cdrom");
925 /* tty_t *tty = tty_find ("tty0");
927 if (!tty)
928 return 0;
929 char str[513];
930 int r = tty_read (tty, str, 512);
932 if (r > 0) {
933 printf ("str: r: %d\n", r);
934 int i;
935 for (i = 0; i < r; i ++)
936 tty_putch (str[i]);
940 /* int ret = vfs_read ("wav", 3);
942 if (ret < 0) {
943 printf ("chyba\n");
944 return 0;
947 cache_t *cache = cache_read ();
949 unsigned char *p = (unsigned char *) &cache->data;
951 unsigned bin_len = cache->limit;
953 unsigned char *bin = (unsigned char *) 0x400000 - 44;
955 memcpy (bin, p, bin_len);
957 typedef struct {
958 unsigned chunkid;
959 unsigned chunksize;
960 unsigned format;
961 } riff_head_t;
963 typedef struct {
964 unsigned subchunk1id;
965 unsigned subchunk1size;
966 unsigned short audioformat;
967 unsigned short numchannels;
968 unsigned samplerate;
969 unsigned byterate;
970 unsigned short blockalign;
971 unsigned short bitspersample;
972 } fmt_head_t;
974 typedef struct {
975 unsigned subchunk2id;
976 unsigned subchunk2size;
977 } data_head_t;
979 riff_head_t *r = (riff_head_t *) bin;
980 fmt_head_t *fmt = (fmt_head_t *) ((char *) bin + sizeof (riff_head_t));
981 data_head_t *data = (data_head_t *) ((char *) bin + sizeof (riff_head_t) + sizeof (fmt_head_t));
983 printf ("riff_head_t 0x%x : %d : 0x%x\n", r->chunkid, r->chunksize, r->format);
984 printf ("fmt_head_t %d : %d : %d : %d : %d : %d\n", fmt->audioformat, fmt->subchunk1size, fmt->numchannels, fmt->samplerate, fmt->byterate, fmt->bitspersample);
985 printf ("data_head_t 0x%x : %d\n", data->subchunk2id, data->subchunk2size);
986 //memset (bin+44, 0, bin_len-44);
987 //dev->handler (DEV_ACT_WRITE, bin+44, bin_len-44);
989 snd_cfg_t cfg;
990 cfg.dev = "/dev/ac97";
991 cfg.rate = fmt->samplerate;
992 cfg.format = SOUND_FORMAT_S16;
993 cfg.channels = fmt->numchannels;
995 snd_audio_t *aud = audio_open (&cfg);
997 if (!aud)
998 return 0;
1000 audio_write (aud, bin+44, (bin_len-44));
1002 //swfree (bin, bin_len);*/
1006 return 1;
1009 unsigned command_test3 (char *command, unsigned len)
1012 return 1;
1015 unsigned command_test4 (char *command, unsigned len)
1019 return 1;
1022 unsigned command_mouse (char *command, unsigned len)
1024 printf ("PS/2 Mouse test\n");
1026 dev_t *dev = dev_find ("/dev/mouseps2");
1028 if (!dev)
1029 return 0;
1031 dev_mouse_t mouse;
1033 int ps2_fd = open ("/dev/mouseps2", O_RDONLY);
1035 if (!ps2_fd)
1036 return 0;
1038 printf ("dddd\n");
1040 while (!key_pressed (1)) {
1041 int r = read (ps2_fd, &mouse, sizeof (dev_mouse_t));
1043 if (!r) {
1044 kprintf ("oj oj\n");
1045 return 0;
1048 kprintf ("ps2mouse: x,y: %d, %d | 0x%x \n", mouse.pos_x, mouse.pos_y, mouse.flags);
1050 lseek (ps2_fd, 0, SEEK_SET);
1052 schedule ();
1055 return 1;
1058 unsigned command_vesa (char *command, unsigned len)
1060 if (!init_video_vesa ())
1061 printf ("vesa -> failed\n");
1063 return 1;
1066 unsigned command_kill (char *command, unsigned len)
1068 strcpy (test, argparse (currtty->shell));
1070 pid_t pid = (pid_t) atoi (test);
1072 proc_t *proc = proc_findbypid (pid);
1074 if (!proc) {
1075 printf ("kill: (%s) - No such process\n", test);
1076 return 0;
1079 /* send SIGTERM to selected process */
1080 if (!proc_signal (proc, SIGTERM))
1081 return 0;
1083 /* check for daemon */
1084 if (proc->flags & PROC_FLAG_DAEMON)
1085 if (!proc_done (proc))
1086 return 0;
1088 return 1;
1091 unsigned command_modprobe (char *command, unsigned len)
1093 unsigned arg_len = strlen (argparse (currtty->shell));
1094 char arg[arg_len+1];
1095 strcpy (arg, argparse (currtty->shell));
1096 arg[arg_len] = '\0';
1098 module_load (arg);
1100 return 1;
1103 unsigned command_lsmod (char *command, unsigned len)
1105 module_display ();
1107 return 1;
1110 #ifdef CONFIG_DRV_PCI
1111 unsigned command_lspci (char *command, unsigned len)
1113 #ifdef ARCH_i386
1114 pcidev_display ();
1115 #endif
1116 return 1;
1118 #endif
1120 unsigned command_iflist (char *command, unsigned len)
1122 iflist_display ();
1124 return 1;
1127 unsigned command_ifconfig (char *command, unsigned len)
1129 strcpy (test, argparse (command));
1130 char ifid[20];
1131 char ip[32];
1133 unsigned l = strlen (test);
1134 unsigned x = 0;
1135 while (x < l) {
1136 if (test[x] == ' ')
1137 break;
1138 x ++;
1141 memcpy (ifid, test, x);
1142 ifid[x] = '\0';
1144 strcpy (ip, argparse (test));
1145 unsigned y = strlen (ip);
1147 netif_t *netif = netif_findbyname (ifid);
1149 if (!netif) {
1150 printf ("ifconfig -> bad network interface name, example: eth0\n");
1151 return 0;
1154 net_ipv4 ipv4;
1155 net_ipv6 ipv6;
1156 if (ipv4 = net_proto_ip_convert (ip)) {
1157 netif_ip_addr (netif, ipv4, IF_CFG_TYPE_STATIC);
1159 printf ("%s: IPv4 ", ifid);
1160 net_proto_ip_print (ipv4);
1161 printf (" - OK\n");
1162 } else if (net_proto_ipv6_convert (ipv6, ip)) {
1163 netif_ipv6_addr (netif, ipv6, IF_CFG_TYPE_STATIC);
1165 printf ("%s: IPv6 ", ifid);
1166 net_proto_ipv6_print (ipv6);
1167 printf (" - OK\n");
1168 } else {
1169 printf ("ifconfig -> bad ip address format, example:\n\t\t192.168.1.1 for IPv4\n\t\tfc00:0:0:0:0:0:0:10 for IPv6\n");
1170 return 0;
1173 return 1;
1176 unsigned command_ifroute (char *command, unsigned len)
1178 strcpy (test, argparse (command));
1179 char ifid[20];
1180 char ip[32];
1182 unsigned l = strlen (test);
1183 unsigned x = 0;
1184 while (x < l) {
1185 if (test[x] == ' ')
1186 break;
1187 x ++;
1190 memcpy (ifid, test, x);
1191 ifid[x] = '\0';
1193 strcpy (ip, argparse (test));
1194 unsigned y = strlen (ip);
1196 netif_t *netif = netif_findbyname (ifid);
1198 if (!netif) {
1199 printf ("ifroute -> bad network interface name, example: eth0\n");
1200 return 0;
1203 unsigned char a;
1204 unsigned char b;
1205 unsigned char c;
1206 unsigned char d;
1208 unsigned g = 0;
1209 unsigned i = 0;
1211 unsigned h[4];
1213 while (i < y) {
1214 if (ip[i] == '.') {
1215 ip[i] = '\0';
1216 h[g] = i+1;
1217 g ++;
1220 i ++;
1223 if (g != 3) {
1224 printf ("ifroute -> bad ip address format, example: 192.168.1.254\n");
1225 return 0;
1228 a = atoi (ip);
1229 b = atoi (ip+h[0]);
1230 c = atoi (ip+h[1]);
1231 d = atoi (ip+h[2]);
1233 printf ("%s->gw: %d.%d.%d.%d - OK\n", ifid, a, b, c, d);
1235 return netif_gw_addr (netif, NET_IPV4_TO_ADDR (a, b, c, d));
1238 unsigned command_dnsconfig (char *command, unsigned len)
1240 strcpy (test, argparse (currtty->shell));
1242 if (!test)
1243 return 0;
1245 unsigned l = strlen (test);
1247 if (!l) {
1248 printf ("dnsconfig -> your domain name server is: ");
1249 net_proto_ip_print (dns_addr_get ());
1250 printf ("\n");
1252 return 0;
1255 printf ("dnsconfig: %s - OK\n", test);
1257 net_ipv4 dns = net_proto_ip_convert (test);
1259 if (!dns)
1260 return 0;
1262 dns_addr (dns);
1264 return 1;
1267 unsigned command_tunconfig (char *command, unsigned len)
1269 strcpy (test, argparse (currtty->shell));
1271 if (!test)
1272 return 0;
1274 unsigned l = strlen (test);
1276 if (!l) {
1277 printf ("tunconfig -> wrong syntax !\ntunconfig <ipv4tunnel> for enable or tunconfig 0 for disable\n");
1279 return 0;
1282 /* you can disable this service over character '0' as parameter */
1283 if (l == 1 && test[0] == '0') {
1284 tun6_addr (0);
1286 printf ("tunconfig: disabled - OK\n");
1288 return 1;
1291 /* classical ipv4 address from tunnel server */
1292 net_ipv4 tunnel = net_proto_ip_convert (test);
1294 if (!tunnel) {
1295 printf ("tunconfig -> wrong syntax !\nExample: tunconfig 216.66.80.30\n");
1297 return 0;
1300 tun6_addr (tunnel);
1302 printf ("tunconfig: ::%s - OK\n", test);
1304 return 1;
1308 unsigned command_hostname (char *command, unsigned len)
1310 strcpy (test, argparse (currtty->shell));
1312 if (!test)
1313 return 0;
1315 unsigned l = strlen (test);
1317 if (!l) {
1318 printf ("%s\n", hostname_get ());
1320 return 0;
1323 printf ("hostname: %s - OK\n", test);
1325 hostname_set (test);
1327 return 1;
1330 unsigned command_kbdmap (char *command, unsigned len)
1332 strcpy (test, argparse (currtty->shell));
1334 if (!test)
1335 return 0;
1337 unsigned ret = keyboard_setlayout (test);
1339 if (ret)
1340 printf ("Keyboard layout was changed to '%s'\n", test);
1342 return ret;
1345 unsigned command_mkzexfs (char *command, unsigned len)
1347 #ifdef ARCH_i386
1348 strcpy (test, argparse (currtty->shell));
1350 partition_t *p = partition_find (test);
1352 if (!p)
1353 return 0;
1355 mkzexfs (p);
1356 #endif
1357 return 1;
1360 unsigned command_mkext2 (char *command, unsigned len)
1362 #ifdef ARCH_i386
1363 strcpy (test, argparse (currtty->shell));
1365 if (!test)
1366 return 0;
1368 partition_t *p = partition_find ("/dev/hda0");
1370 mkext2 (p);
1371 #endif
1372 return 1;
1375 unsigned command_ping (char *command, unsigned len)
1377 strcpy (test, argparse (currtty->shell));
1379 if (!test)
1380 return 0;
1382 netif_t *netif = netif_findbyname ("eth0");
1384 if (!netif) {
1385 printf ("ping -> network interface does not exists\n");
1386 return 0;
1389 unsigned char a;
1390 unsigned char b;
1391 unsigned char c;
1392 unsigned char d;
1394 unsigned g = 0;
1395 unsigned i = 0;
1396 unsigned y = strlen (test);
1398 if (!y) {
1399 printf ("ping -> wrong syntax, please specify address\n");
1400 return 0;
1403 unsigned h[4];
1405 while (i < y) {
1406 if (test[i] == '.') {
1407 test[i] = '\0';
1408 h[g] = i+1;
1409 g ++;
1412 i ++;
1415 net_ipv4 target = 0;
1417 if (g != 3) {
1418 strcpy (test, argparse (currtty->shell));
1420 if (dns_cache_get (test, &target, 4) != 1)
1421 if (dns_send_request (test, &target, 4) != 1) {
1422 printf ("ping -> bad hostname or ip address format, example: 192.168.1.1\n");
1423 return 0;
1425 } else {
1426 a = atoi (test);
1427 b = atoi (test+h[0]);
1428 c = atoi (test+h[1]);
1429 d = atoi (test+h[2]);
1431 target = NET_IPV4_TO_ADDR (a, b, c, d);
1433 strcpy (test, argparse (currtty->shell));
1436 char address[20];
1437 net_proto_ip_convert2 (target, address);
1439 i = 0;
1441 while (i < 8) {
1442 unsigned long time_a = timer_ticks;
1443 unsigned ret = net_proto_icmp_ping (netif, target);
1444 if (ret) {
1445 printf ("ping -> %s (%s) - %ums\n", test, address, (timer_ticks - time_a));
1446 } else {
1447 printf ("ping -> Host %s is unreachable\n", test);
1448 break;
1451 i ++;
1454 return 1;
1457 unsigned command_ping6 (char *command, unsigned len)
1459 strcpy (test, argparse (currtty->shell));
1461 if (!test)
1462 return 0;
1464 netif_t *netif = netif_findbyname ("eth0");
1466 if (!netif) {
1467 printf ("ping6 -> network interface does not exists\n");
1468 return 0;
1471 unsigned short a;
1472 unsigned short b;
1473 unsigned short c;
1474 unsigned short d;
1475 unsigned short e;
1476 unsigned short f;
1477 unsigned short g;
1478 unsigned short h;
1480 unsigned j = 0;
1481 unsigned i = 0;
1482 unsigned y = strlen (test);
1484 if (!y) {
1485 printf ("ping6 -> wrong syntax, please specify ipv6 address\n");
1486 return 0;
1489 unsigned k[8];
1491 while (i < y) {
1492 if (test[i] == ':') {
1493 test[i] = '\0';
1494 k[j] = i+1;
1495 j ++;
1498 i ++;
1501 net_ipv6 target;
1503 if (j != 7) {
1504 strcpy (test, argparse (currtty->shell));
1506 if (dns_cache_get (test, &target, 16) != 1)
1507 if (dns_send_request (test, &target, 16) != 1) {
1508 printf ("ping6 -> bad hostname or ip address format, example: 2001:4d3:8fe:2:0:0:0:1\n");
1509 return 0;
1511 } else {
1512 char *endptr;
1514 a = strtol (test, &endptr, 16);
1515 b = strtol (test+k[0], &endptr, 16);
1516 c = strtol (test+k[1], &endptr, 16);
1517 d = strtol (test+k[2], &endptr, 16);
1518 e = strtol (test+k[3], &endptr, 16);
1519 f = strtol (test+k[4], &endptr, 16);
1520 g = strtol (test+k[5], &endptr, 16);
1521 h = strtol (test+k[6], &endptr, 16);
1523 NET_IPV6_TO_ADDR (target, a, b, c, d, e, f, g, h);
1525 //printf ("ipv6: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", a, b, c, d, e, f, g, h);
1527 strcpy (test, argparse (currtty->shell));
1530 char address[40];
1531 //net_proto_ipv6_convert2 (target, address);
1533 i = 0;
1535 while (i < 8) {
1536 unsigned long time_a = timer_ticks;
1537 unsigned ret = net_proto_icmp6_ping (netif, target);
1538 if (ret) {
1539 printf ("ping6 -> %s (%s) - %ums\n", test, test, (timer_ticks - time_a));
1540 } else {
1541 printf ("ping6 -> Host %s is unreachable\n", test);
1542 break;
1545 i ++;
1548 return 1;
1551 unsigned command_netexec (char *command, unsigned len)
1553 strcpy (test, argparse (command));
1555 if (!test)
1556 return 0;
1558 if (!strlen (test)) {
1559 printf ("Syntax:\nnetexec <ip_of_tftp> <filename> [parameters]\n");
1560 return 0;
1563 unsigned arg_len = strlen (argparse (test));
1564 char arg[arg_len+1];
1565 strcpy (arg, argparse (test));
1566 arg[arg_len] = '\0';
1568 unsigned test_len = strlen (test);
1569 test [test_len-arg_len] = '\0';
1571 if (test[test_len-arg_len-1] == ' ') {
1572 test[test_len-arg_len-1] = '\0';
1573 test_len --;
1576 char file[arg_len+1];
1577 unsigned file_len = 0;
1578 memcpy (file, arg, arg_len);
1579 while (file_len < arg_len) {
1580 if (file[file_len] == ' ') {
1581 file[file_len] = '\0';
1582 break;
1584 file_len ++;
1587 if (file[arg_len] != '\0')
1588 file[arg_len] = '\0';
1590 unsigned l = file_len;
1592 unsigned ret = tftp_client_connect (test, 69, file, &l);
1594 if (!ret) {
1595 printf ("tftp -> something go wrong !\n");
1596 return 0;
1599 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l);
1601 char *bin = (unsigned char *) swmalloc (sizeof (char) * (l+1));
1603 if (!bin)
1604 return 0;
1606 int ret2 = tftp_client_read (ret, bin, l);
1608 if (!ret2) {
1609 printf ("tftp -> tftp_client_read () error\n");
1610 swfree (bin, l);
1611 return 0;
1614 unsigned entry, code, data, data_off, bss;
1615 int err = exec_elf (bin, &entry, &data, &data_off, &bss);
1617 if (err != NULL) {
1618 printf ("ERROR -> invalid ELF exec\n");
1619 return 0;
1622 tty_lock (currtty);
1623 timer_wait (1);
1624 /* create process */
1625 proc_t *proc = proc_create (currtty, "netexec", entry);
1626 timer_wait (1);
1629 /* check for & character as app parameter */
1630 /* unsigned d = 0;
1631 while (d < arg_len) {
1632 if (arg[d] == '&') {
1633 if (proc_flag_set (proc, PROC_FLAG_DAEMON))
1634 printf ("%s: started as daemon\n", test);
1636 arg[d] = '\0';
1638 if (arg_len > 2 && arg[d-1] == ' ') {
1639 arg[d-1] = '\0';
1640 arg_len --;
1643 arg_len --;
1645 break;
1647 d ++;
1650 if (!proc) {
1651 printf ("ERROR -> Invalid process: %s\n", test);
1652 return 0;
1655 timer_wait (1);
1657 /* save process information to structure for later use */
1658 proc->start = (unsigned) bin;
1659 proc->code = entry;
1660 proc->data = data;
1661 proc->data_off = data_off;
1662 proc->bss = bss;
1663 proc->end = (unsigned) (bin + l);
1665 timer_wait (1);
1667 /* well, set argument for out app */
1668 proc_arg_set (proc, arg+file_len+1, arg_len-file_len-1);
1670 proc_vmem_map (proc);
1672 timer_wait (1);
1674 /* Is this process started as daemon ? */
1675 /* wait here, until pid != 0*/
1676 if (!(proc->flags & PROC_FLAG_DAEMON))
1677 while (proc->pid)
1678 schedule ();
1680 timer_wait (1);
1682 /* enable interrupts */
1683 int_enable ();
1685 /* unlock tty console - user can write in */
1686 tty_unlock (proc->tty);
1688 _curr_task = proc->tty->task; // this is pretty needed for correct return to our tty task
1690 if (!(proc->flags & PROC_FLAG_DAEMON)) {
1691 if (!proc_done (proc))
1692 while (1) // NOTE: heh, this is good stuff :P
1693 schedule ();
1695 /* free image of app */
1696 //flush_elf ();
1697 swfree (bin, l);
1700 /* switch to next task */
1701 schedule ();
1703 sclose (ret);
1705 return 1;
1708 unsigned command_netcp (char *command, unsigned len)
1710 strcpy (test, argparse (command));
1712 if (!test)
1713 return 0;
1715 if (!strlen (test)) {
1716 printf ("Syntax:\nnetcp <ip_of_tftp> <tftp_file> <output_file>\n");
1717 return 0;
1720 unsigned arg_len = strlen (argparse (test));
1721 char arg[arg_len+1];
1722 strcpy (arg, argparse (test));
1723 arg[arg_len] = '\0';
1725 unsigned test_len = strlen (test);
1726 test [test_len-arg_len] = '\0';
1728 if (test[test_len-arg_len-1] == ' ') {
1729 test[test_len-arg_len-1] = '\0';
1730 test_len --;
1733 char file[arg_len+1];
1734 unsigned file_len = 0;
1735 memcpy (file, arg, arg_len);
1736 while (file_len < arg_len) {
1737 if (file[file_len] == ' ') {
1738 file[file_len] = '\0';
1739 break;
1741 file_len ++;
1744 if (file[arg_len] != '\0')
1745 file[arg_len] = '\0';
1747 unsigned l = file_len;
1749 unsigned ret = tftp_client_connect (test, 69, file, &l);
1751 if (!ret) {
1752 printf ("tftp -> something go wrong !\n");
1753 return 0;
1756 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l);
1758 char *bin = (unsigned char *) swmalloc (sizeof (char) * (l+1));
1760 if (!bin)
1761 return 0;
1763 int ret2 = tftp_client_read (ret, bin, l);
1765 if (!ret2) {
1766 printf ("tftp -> tftp_client_read () error\n");
1767 swfree (bin, l);
1768 return 0;
1771 sclose (ret);
1773 char *output = argparse (arg);
1775 if (!output) {
1776 swfree (bin, l);
1777 printf ("ERROR -> output file name is empty\n");
1778 return 0;
1781 int fd = open (output, O_WRONLY | O_CREAT);
1783 if (!fd) {
1784 swfree (bin, l);
1785 printf ("ERROR -> something go wrong with %s\n", output);
1786 return 0;
1789 ret = write (fd, bin, l);
1791 if (!ret) {
1792 swfree (bin, l);
1793 printf ("ERROR -> File '%s' could'nt be writed\n", output);
1796 return 1;
1800 unsigned command_znfscl (char *command, unsigned len)
1802 #ifdef ARCH_i386
1803 strcpy (test, argparse (command));
1805 if (!strlen (test)) {
1806 printf ("Syntax:\nznfscl <ip_of_znfs>\n");
1807 return 0;
1810 dev_t *dev = dev_find ("/dev/vbd");
1812 if (dev) {
1813 printf ("znfscl: You are already connected to znfs server\n");
1814 return 0;
1817 dev = (dev_t *) dev_register ("vbd", "Virtual Block Device", DEV_ATTR_BLOCK, (dev_handler_t *) &ide_acthandler);
1819 if (!dev)
1820 return 0;
1822 partition_t *p = partition_add (dev, fs_supported ("znfs"), 0);
1824 if (!p)
1825 return 0;
1827 /* connect to specified address */
1828 if (znfs_init (p, test) != 1) {
1829 printf ("znfs: Wrong znfs server\n");
1830 return 0;
1833 char str[16];
1835 sprintf (str, "/mnt/%s", p->name+5);
1837 mkdir (str);
1839 mount (p, "", str);
1841 printf ("znfs: You are succefully connected to ZNFS server '%s'\nZNFS was mounted into '%s'\n", test, str);
1842 #else
1843 printf ("ERROR -> this architecture is not supported yet\n");
1844 #endif
1845 return 1;
1848 void task_savemode ()
1850 /* disable cpu for cycle */
1851 for (;; schedule ())
1852 arch_cpu_hlt ();
1855 unsigned command_savemode (char *command, unsigned len)
1857 task_t *task = (task_t *) task_create ("savemode", (unsigned) &task_savemode, 16);
1859 if (!task) {
1860 printf ("ERROR -> Save mode thread was'nt created\n");
1861 return 0;
1864 printf ("Save mode was succefully started\n");
1866 return 1;
1869 unsigned command_cpuinfo (char *command, unsigned len)
1871 printf ("Processor info:\n");
1873 cat ("/proc/cpuinfo");
1875 return 1;
1878 unsigned command_adm (char *command, unsigned len)
1880 printf ("Automatic Device Mounter - init ()\n");
1882 init_adm ();
1884 return 1;
1887 unsigned command_ttyctrl (char *command, unsigned len)
1889 char *parm = argparse (command);
1891 if (!strlen (parm)) {
1892 printf ("ttyctrl <operation> [parameter]\n\toperations: add; list; change <ttyid>\n");
1893 return 0;
1896 if (!strncmp (parm, "add", 3)) {
1897 tty_t *tty = tty_create ();
1899 if (!tty)
1900 return 0;
1902 video_color (7, 0);
1904 tty_write (tty, "\nlogin: ", 8);
1906 printf ("New tty '%s' was created\n", tty->name);
1907 } else
1908 if (!strncmp (parm, "list", 4)) {
1909 tty_listview ();
1910 } else
1911 if (!strncmp (parm, "change", 6)) {
1912 tty_t *tty = tty_find ((char *) argparse (parm));
1914 if (!tty)
1915 return 0;
1917 tty_change (tty);
1919 printf ("\n");
1922 return 1;
1925 unsigned command_cmd (char *command, unsigned len)
1927 unsigned s = 0;
1928 unsigned e = 0;
1930 if (!strlen (argparse (command))) {
1931 printf ("cmd <command1>;<command2>;...;\n");
1932 return 0;
1935 char *cmds = kmalloc (len - 3);
1937 if (!cmds)
1938 return 0;
1940 memcpy (cmds, command + 4, len - 4);
1941 cmds[len - 4] = '\0';
1943 unsigned i;
1944 for (i = 1; i < len - 4; i ++) {
1945 if (cmds[i] == ';') {
1946 cmds[i] = '\0';
1947 e = i-1;
1949 command_parser (cmds+s, e-s+1);
1951 s = i+1;
1955 kfree (cmds);
1957 return 1;
1960 /*************************************************************\
1961 | COMMAND's UTILS |
1962 \*************************************************************/
1964 unsigned command_parser (char *command, unsigned len)
1966 /* find first non-space in command */
1967 int i = 0;
1968 for (i = 0; i < len; i ++) {
1969 if (command[i] != ' ')
1970 break;
1972 command_t *ctx;
1974 /* try to find the command */
1975 for (ctx = command_list.next; ctx != &command_list; ctx = ctx->next) {
1976 if (!cstrcmp (ctx->name, command+i)) {
1977 ctx->handler (command+i, len-i); /* execute context function */
1978 return 1;
1982 printf ("%s: command not found\n", command);
1984 return 0;
1987 void commands (int i)
1989 // currtty->shell_len has been set to zero already
1990 command_parser (currtty->shell, strlen(currtty->shell));
1993 unsigned command_register (char *name, char *desc, command_handler_t *handler, unsigned flags)
1995 command_t *c;
1996 /* we dont want commands with same name */
1997 for (c = command_list.next; c != &command_list; c = c->next)
1998 if (!strcmp(c->name, name))
1999 return 0;
2001 command_t *ctx;
2003 // alloc and init context
2004 ctx = (command_t *) kmalloc (sizeof (command_t));
2006 if (!ctx)
2007 return 0;
2009 unsigned name_len = strlen (name);
2010 ctx->name = (char *) kmalloc (sizeof (char) * name_len +1);
2012 if (!ctx->name)
2013 return 0;
2015 memcpy (ctx->name, name, name_len);
2016 ctx->name[name_len] = '\0';
2018 unsigned desc_len = strlen (desc);
2019 ctx->desc = (char *) kmalloc (sizeof (char) * desc_len +1);
2021 if (!ctx->desc)
2022 return 0;
2024 memcpy (ctx->desc, desc, desc_len);
2025 ctx->desc[desc_len] = '\0';
2027 ctx->handler = handler;
2028 ctx->flags = flags;
2030 ctx->next = &command_list;
2031 ctx->prev = command_list.prev;
2032 ctx->prev->next = ctx;
2033 ctx->next->prev = ctx;
2035 return 1;
2038 unsigned command_unregister (char *name)
2040 command_t *ctx;
2042 for (ctx = command_list.next; ctx != &command_list; ctx = ctx->next) {
2043 if (!strcmp(ctx->name, name)) {
2044 ctx->next->prev = ctx->prev;
2045 ctx->prev->next = ctx->next;
2047 return 1;
2051 return 0;
2054 /*************************************************************\
2055 | INITIALIZATION OF COMMANDS |
2056 \*************************************************************/
2058 unsigned int init_commands ()
2060 command_list.next = &command_list;
2061 command_list.prev = &command_list;
2063 // reg commands
2064 command_register ("help", "Displays list of available commands", &command_help, 0);
2065 command_register ("hdd", "Detect HDD", &command_hdd, 0);
2066 command_register ("reboot", "Reboot computer", &command_reboot, 0);
2067 command_register ("halt", "Shutdown computer", &command_halt, 0);
2068 command_register ("tasks", "Print all tasks", &command_tasks, 0);
2069 command_register ("ps", "Print all process", &command_ps, 0);
2070 command_register ("uptime", "Print uptime in seconds", &command_uptime, 0);
2071 command_register ("version", "Displays a version of system", &command_version, 0);
2072 command_register ("debug", "Change to developer mode", &command_debug, 0);
2073 command_register ("mount", "Mount device to selected directory", &command_mount, 0);
2074 command_register ("umount", "Unmount mounted directory", &command_umount, 0);
2075 command_register ("env", "Displays all env variables", &command_env, 0);
2076 command_register ("cd", "Change directory", &command_cd, 0);
2077 command_register ("ls", " Displays files in current directory", &command_ls, 0);
2078 command_register ("cat", "Displays text in selected file", &command_cat, 0);
2079 command_register ("cp", "Copy a file", &command_cp, 0);
2080 command_register ("rm", "Remove a file", &command_rm, 0);
2081 command_register ("mkdir", "Create a directory", &command_mkdir, 0);
2082 command_register ("touch", "Create a file", &command_touch, 0);
2083 command_register ("exec", "Execute a selected program", &command_exec, 0);
2084 command_register ("lsdev", "Displays found devices", &command_lsdev, 0);
2085 command_register ("login", "Login as another user", &command_login, 0);
2086 command_register ("fdisk", "Partition table manipulator", &command_fdisk, 0);
2087 command_register ("hdcat", "Read selected block of data from drive", &command_hdcat, 0);
2088 command_register ("free", "Display amount of free and used memory", &command_free, 0);
2089 command_register ("top", "Stats of cpu usage", &command_top, 0);
2090 command_register ("date", "Show current date and time", &command_date, 0);
2091 //command_register ("xmastime", "play noel on pc-speaker", &command_spk, 0);
2092 command_register ("test", "Some test", &command_test, 0);
2093 command_register ("test2", "Some test", &command_test2, 0);
2094 //command_register ("testc", "Some test", &command_test3, 0);
2095 //command_register ("testd", "Some test", &command_test4, 0);
2096 //command_register ("vesa", "Some test", &command_vesa, 0);
2097 command_register ("kill", "Send a signal to process", &command_kill, 0);
2098 command_register ("modprobe", "program to add modules from the kernel", &command_modprobe, 0);
2099 command_register ("lsmod", "program to show the status of modules", &command_lsmod, 0);
2100 #ifdef CONFIG_DRV_PCI
2101 command_register ("lspci", "list all pci devices", &command_lspci, 0);
2102 #endif
2103 command_register ("mouse", "ps2 mouse test", &command_mouse, 0);
2104 command_register ("iflist", "Show network interface", &command_iflist, 0);
2105 command_register ("ifconfig", "Configure network interface", &command_ifconfig, 0);
2106 command_register ("ifroute", "Configure gateway address", &command_ifroute, 0);
2107 command_register ("dnsconfig", "Configure domain name server address", &command_dnsconfig, 0);
2108 #ifdef CONFIG_PROTO_TUN6
2109 command_register ("tunconfig", "Configure IPv6 tunnel server address", &command_tunconfig, 0);
2110 #endif
2111 command_register ("hostname", "Configure network hostname", &command_hostname, 0);
2112 command_register ("kbdmap", "Change keyboard layout", &command_kbdmap, 0);
2113 #ifdef CONFIG_DRV_ZEXFS
2114 command_register ("mkzexfs", "Create zexfs filesystem on hdd", &command_mkzexfs, 0);
2115 #endif
2116 #ifdef CONFIG_DRV_EXT2
2117 command_register ("mkext2", "Create ext2 filesystem on hdd", &command_mkext2, 0);
2118 #endif
2119 #ifdef CONFIG_PROTO_IPV4
2120 command_register ("ping", "Send ICMP echo request", &command_ping, 0);
2121 #endif
2122 #ifdef CONFIG_PROTO_IPV6
2123 command_register ("ping6", "Send ICMPv6 echo request", &command_ping6, 0);
2124 #endif
2125 command_register ("netexec", "Execute file from network", &command_netexec, 0);
2126 command_register ("netcp", "Copy file from network to filesystem", &command_netcp, 0);
2127 #ifdef CONFIG_DRV_ZNFS
2128 command_register ("znfscl", "Connect to znfs server - network filesystem", &command_znfscl, 0);
2129 #endif
2130 command_register ("savemode", "Make less cpu load", &command_savemode, 0);
2131 command_register ("cpuinfo", "Show CPU info", &command_cpuinfo, 0);
2133 command_register ("adm", "Automatic Device Mounter", &command_adm, 0);
2134 command_register ("ttyctrl", "TTY Console control", &command_ttyctrl, 0);
2135 command_register ("cmd", "Execute command sequence", &command_cmd, 0);
2137 return 1;