sys.c (2080B)
1 #include <os9/os9.h> 2 3 #include <libk.h> 4 5 #include <ctype.h> 6 #include <string.h> 7 8 #include "version.h" 9 10 Chan *console; 11 12 static void 13 icons(void) 14 { 15 if ((console = namec("#c/raw", O_RDWR)) == NULL) 16 panic("icons:#c/raw open"); 17 } 18 19 static void 20 writeline(char *line) 21 { 22 Chan *c; 23 char *p, *file, *data; 24 25 file = p = line; 26 while (*p && !isspace(*p)) 27 ++p; 28 while (isspace(*p)) 29 *p++ = '\0'; 30 data = p; 31 32 if ((c = namec(file, O_WRITE)) < 0) 33 panic("writeline:open"); 34 if (chanwrite(c, data, strlen(data)) < 0) 35 panic("writeline:write"); 36 chanclose(c); 37 } 38 39 static void 40 bindline(char *line) 41 { 42 int n; 43 char *tokens[10]; 44 45 n = tokenize(line, strlen(line), tokens, NELEM(tokens)); 46 if (n != 2) 47 panic("bindline:params"); 48 if (bind(tokens[0], tokens[1]) < 0) 49 panic("bindline:bind"); 50 } 51 52 static void 53 mountline(char *line) 54 { 55 int n; 56 char *tokens[10]; 57 58 n = tokenize(line, strlen(line), tokens, NELEM(tokens)); 59 if (n != 3) 60 panic("mountline:params"); 61 if (mount(tokens[0], tokens[1], tokens[2]) < 0) 62 panic("mountline:mount"); 63 } 64 65 static void 66 iconf(void) 67 { 68 int n; 69 Chan *c; 70 char line[80], *s, *p; 71 static struct { 72 char *verb; 73 void (*fn)(char *); 74 } words[] = { 75 "write", writeline, 76 "bind", bindline, 77 "mount", mountline, 78 NULL 79 }, *bp; 80 81 if ((c = namec("/blobs/conf", O_READ)) == NULL) { 82 kprint("missed kernel namespace configuration\n"); 83 return; 84 } 85 86 while ((n = getline(c, line, sizeof(line))) > 0) { 87 if (line[n-1] != '\n') { 88 kprint("iconf: truncated configuration line\n"); 89 continue; 90 } 91 for (p = line; isspace(*p); ++p) 92 ; 93 s = p; 94 while (*p && !isspace(*p)) 95 ++p; 96 while (isspace(*p)) 97 *p++ = '\0'; 98 99 for (bp = words; bp->verb; ++bp) { 100 if (strcmp(s, bp->verb) == 0) { 101 (*bp->fn)(p); 102 break; 103 } 104 } 105 106 if (!bp->verb) 107 kprint("iconf: incorrect verb '%s'\n", s); 108 } 109 110 if (n < 0) 111 kprint("iconf: error reading configuration:%r\n"); 112 113 chanclose(c); 114 } 115 116 static void 117 info(void) 118 { 119 kprint("Booting os9\n"); 120 kprint("os9: version %s\n", OS9VERSION); 121 } 122 123 void 124 isys(void) 125 { 126 info(); 127 ialloc(); 128 iproc(); 129 idev(); 130 iconf(); 131 icons(); 132 sched(); 133 }