3 static Command command[100];
5 static char statsdef[20]; /* default stats list */
8 static void consserve1(void *);
15 strncpy(cons.chan->whochan, "console", sizeof(cons.chan->whochan));
17 for(i = 0; command[i].arg0; i++)
18 if(strcmp("cwcmd", command[i].arg0) == 0){
19 cmd_exec("cwcmd touchsb");
23 newproc(consserve1, 0, "con");
26 /* console commands process */
34 if ((conline = Brdline(&bin, '\n')) != nil) {
35 conline[Blinelen(&bin)-1] = '\0';
36 print("%s: %s\n", service, conline);
39 } while (conline != nil);
44 cmdcmp(void *va, void *vb)
50 return strcmp(a->arg0, b->arg0);
54 cmd_install(char *arg0, char *help, void (*func)(int, char*[]))
59 for(i=0; command[i].arg0; i++)
61 if(i >= nelem(command)-2) {
63 print("cmd_install: too many commands\n");
66 command[i+1].arg0 = 0;
67 command[i].help = help;
68 command[i].func = func;
69 command[i].arg0 = arg0;
70 qsort(command, i+1, sizeof(Command), cmdcmp);
77 char line[2*Maxword], *s;
81 if(strlen(arg) >= nelem(line)-2) {
82 print("cmd_exec: line too long\n");
91 while(isascii(c) && isspace(c))
95 if(argc >= nelem(argv)-2) {
96 print("cmd_exec: too many args\n");
100 while((!isascii(c) || !isspace(c)) && c != '\0')
106 for(i=0; s=command[i].arg0; i++)
107 if(strcmp(argv[0], s) == 0) {
108 (*command[i].func)(argc, argv);
112 print("cmd_exec: unknown command: %s\n", argv[0]);
116 cmd_halt(int, char *[])
118 wlock(&mainlock); /* halt */
124 cmd_duallow(int argc, char *argv[])
133 uid = strtouid(argv[1]);
135 uid = number(argv[1], -2, 10);
137 print("bad uid %s\n", argv[1]);
144 cmd_stats(int argc, char *argv[])
147 char buf[30], *s, *p, *q;
151 strcpy(statsdef, "a");
152 sprint(buf, "stats s%s", statsdef);
162 for(i = 1; i < argc; i++)
163 for(s = argv[i]; c = *s; s++) {
180 cmd_stata(int, char *[])
184 print("cons stats\n");
185 // print("\twork =%7W%7W%7W rps\n", cons.work+0, cons.work+1, cons.work+2);
186 // print("\trate =%7W%7W%7W tBps\n", cons.rate+0, cons.rate+1, cons.rate+2);
187 // print("\thits =%7W%7W%7W iops\n", cons.bhit+0, cons.bhit+1, cons.bhit+2);
188 // print("\tread =%7W%7W%7W iops\n", cons.bread+0, cons.bread+1, cons.bread+2);
189 // print("\trah =%7W%7W%7W iops\n", cons.brahead+0, cons.brahead+1, cons.brahead+2);
190 // print("\tinit =%7W%7W%7W iops\n", cons.binit+0, cons.binit+1, cons.binit+2);
191 print("\tbufs = %3ld sm %3ld lg %ld res\n",
192 cons.nsmall, cons.nlarge, cons.nreseq);
194 for(i=0; i<nelem(mballocs); i++)
196 print("\t[%d]=%d\n", i, mballocs[i]);
198 print("\tioerr= %3ld wr %3ld ww %3ld dr %3ld dw\n",
199 cons.nwormre, cons.nwormwe, cons.nwrenre, cons.nwrenwe);
200 print("\tcache= %9ld hit %9ld miss\n",
201 cons.nwormhit, cons.nwormmiss);
205 flagcmp(void *va, void *vb)
211 return strcmp(a->arg0, b->arg0);
215 flag_install(char *arg, char *help)
220 for(i=0; flag[i].arg0; i++)
224 print("flag_install: too many flags\n");
231 qsort(flag, i+1, sizeof(Flag), flagcmp);
237 cmd_flag(int argc, char *argv[])
244 for(i=0; flag[i].arg0; i++)
245 print("%.4lux %s %s\n",
246 flag[i].flag, flag[i].arg0, flag[i].help);
248 print("flag[*] = %.4lux\n", cons.flags);
249 for(cp = chans; cp; cp = cp->next)
251 print("flag[%3d] = %.4lux\n", cp->chan, cp->flags);
257 for(i=1; i<argc; i++) {
258 for(j=0; s=flag[j].arg0; j++)
259 if(strcmp(s, argv[i]) == 0)
261 j = number(argv[i], -1, 10);
263 print("bad flag argument: %s\n", argv[i]);
276 print("flag = %.8lux\n", cons.flags);
279 for(cp = chans; cp; cp = cp->next)
284 print("flag[%3d] = %.8lux\n", cp->chan, cp->flags);
287 print("no such channel\n");
291 cmd_who(int argc, char *argv[])
297 for(cp = chans; cp; cp = cp->next) {
298 if(cp->whotime == 0 && !(cons.flags & whoflag)) {
303 for(i=1; i<argc; i++)
304 if(strcmp(argv[i], cp->whoname) == 0)
311 print("%3d: %10s %24s", cp->chan,
312 cp->whoname? cp->whoname: "<nowhoname>", cp->whochan);
319 print("%d chans not listed\n", c);
323 cmd_hangup(int argc, char *argv[])
329 print("usage: hangup chan-number\n");
332 n = number(argv[1], -1, 10);
333 for(cp = chans; cp; cp = cp->next) {
334 if(cp->whotime == 0) {
336 print("that chan is hung up\n");
340 /* need more than just fileinit with tcp */
341 chanhangup(cp, "console command", 1);
348 cmd_sync(int, char *[])
350 wlock(&mainlock); /* sync */
357 cmd_help(int argc, char *argv[])
362 for(i=0; arg=command[i].arg0; i++) {
364 for(j=1; j<argc; j++)
365 if(strcmp(argv[j], arg) == 0)
370 print("\t%s %s\n", arg, command[i].help);
376 cmd_fstat(int argc, char *argv[])
380 for(i=1; i<argc; i++) {
381 if(walkto(argv[i])) {
382 print("cant stat %s\n", argv[i]);
390 cmd_create(int argc, char *argv[])
394 char elem[NAMELEN], *p;
397 print("usage: create path uid gid mode [lad]\n");
401 p = utfrrune(argv[1], '/');
404 if(walkto(argv[1])) {
405 print("create failed in walkto: %s\n", p);
413 if(strlen(p) >= NAMELEN) {
414 print("name too long %s\n", p);
418 memset(elem, 0, sizeof(elem));
421 uid = strtouid(argv[2]);
423 uid = number(argv[2], -2, 10);
425 print("bad uid %s\n", argv[2]);
429 gid = strtouid(argv[3]);
431 gid = number(argv[3], -2, 10);
433 print("bad gid %s\n", argv[3]);
437 perm = number(argv[4], 0777, 8) & 0777;
440 if(strchr(argv[5], 'l'))
442 if(strchr(argv[5], 'a'))
444 if(strchr(argv[5], 'd'))
448 if(con_create(FID2, elem, uid, gid, perm, 0))
449 print("create failed: %s/%s\n", argv[1], p);
453 cmd_clri(int argc, char *argv[])
457 for(i=1; i<argc; i++) {
458 if(walkto(argv[i])) {
459 print("cant remove %s\n", argv[i]);
467 cmd_allow(int, char**)
469 wstatallow = writeallow = 1;
473 cmd_disallow(int, char**)
475 wstatallow = writeallow = 0;
479 ckblock(Device *d, Off a, int typ, Off qpath)
484 p = getbuf(d, a, Brd);
486 checktag(p, typ, qpath);
493 doclean(Iobuf *p, Dentry *d, int n, Off a)
503 for(i=0; i<NDBLOCK; i++) {
504 print("dblock[%d] = %lld\n", i, (Wideoff)d->dblock[i]);
505 ckblock(p->dev, d->dblock[i], typ, qpath);
509 print("dblock[%d] modified %lld\n", i, (Wideoff)a);
513 /* add NDBLOCK so user can cite block address by index */
514 for (i = 0; i < NIBLOCK; i++) {
515 print("iblocks[%d] = %lld\n", NDBLOCK+i, (Wideoff)d->iblocks[i]);
516 ckblock(p->dev, d->iblocks[i], Tind1+i, qpath);
520 print("iblocks[%d] modified %lld\n", NDBLOCK+i, (Wideoff)a);
525 p->flags |= Bmod|Bimm;
529 cmd_clean(int argc, char *argv[])
542 n = number(argv[2], -1, 10);
545 a = number(argv[3], 0, 10);
546 if(walkto(argv[1])) {
547 print("cant remove %s\n", argv[1]);
550 f = filep(cons.chan, FID2, 0);
553 if(n >= 0 && f->fs->dev->type == Devro) {
554 print("readonly %s\n", argv[1]);
557 p = getbuf(f->fs->dev, f->addr, Brd);
558 d = getdir(p, f->slot);
559 if(!d || !(d->mode & DALLOC)) {
560 print("not alloc %s\n", argv[1]);
573 cmd_remove(int argc, char *argv[])
577 for(i=1; i<argc; i++) {
578 if(walkto(argv[i])) {
579 print("cant remove %s\n", argv[i]);
587 cmd_version(int, char *[])
589 print("%d-bit %s as of %T\n", sizeof(Off)*8 - 1, service, fs_mktime);
590 print("\tlast boot %T\n", boottime);
594 cmd_cfs(int argc, char *argv[])
604 print("%s: unknown file system\n", name);
609 if(con_attach(FID1, "adm", fs->name))
610 panic("FID1 attach to root");
612 print("current fs is \"%s\"\n", cons.curfs->name);
616 cmd_prof(int argc, char *argv[])
622 if(cons.profbuf == 0) {
623 print("no buffer\n");
628 n = number(argv[1], n, 10);
629 if(n && !cons.profile) {
630 print("clr and start\n");
631 memset(cons.profbuf, 0, cons.nprofbuf*sizeof(cons.profbuf[0]));
635 if(!n && cons.profile) {
637 print("stop and write\n");
638 if(walkto("/adm/kprofdata"))
640 if(con_open(FID2, OWRITE|OTRUNC)) {
642 print("cant open /adm/kprofdata\n");
645 p = (char*)cons.profbuf;
646 for(m=0; m<cons.nprofbuf; m++) {
655 m = cons.nprofbuf*sizeof(cons.profbuf[0]);
661 con_write(FID2, (char*)cons.profbuf+o, o, n);
670 cmd_time(int argc, char *argv[])
678 for(i=1; i<argc; i++)
679 len += 1 + strlen(argv[i]);
680 cmd = malloc(len + 1);
682 for(i=1; i<argc; i++) {
684 strcat(cmd, argv[i]);
689 print("time = %ld ms\n", TK2MS(t2-t1));
693 cmd_noauth(int, char *[])
697 print("authentication is DISABLED\n");
701 cmd_noattach(int, char *[])
703 noattach = !noattach;
705 print("attaches are DISABLED\n");
709 cmd_files(int, char *[])
714 for(cp = chans; cp; cp = cp->next)
719 for(i=0; i<conf.nfile; i++)
722 files[i].cp->nfile++;
724 print("%ld out of %ld files used\n", n, conf.nfile);
728 for(cp = chans; cp; cp = cp->next)
730 print("%3d: %5d\n", cp->chan, cp->nfile);
734 print("%ld out of %ld files used\n", n, conf.nfile);
738 cmd_chatty(int argc, char *argv[])
741 print("cmd_chatty: usage: chatty n\n");
744 chatty = atoi(argv[1]);
750 cmd_install("allow", "-- disable permission checking", cmd_allow);
751 cmd_install("cfs", "[file] -- set current filesystem", cmd_cfs);
752 cmd_install("chatty", "n -- set chattiness", cmd_chatty);
753 cmd_install("clean", "file [bno [addr]] -- block print/fix", cmd_clean);
754 cmd_install("check", "[options]", cmd_check);
755 cmd_install("clri", "[file ...] -- purge files/dirs", cmd_clri);
756 cmd_install("create", "path uid gid perm [lad] -- make a file/dir", cmd_create);
757 cmd_install("disallow", "-- enable permission checking", cmd_disallow);
758 cmd_install("duallow", "uid -- duallow", cmd_duallow);
759 cmd_install("flag", "-- print set flags", cmd_flag);
760 cmd_install("fstat", "path -- print info on a file/dir", cmd_fstat);
761 cmd_install("halt", "-- return to boot rom", cmd_halt);
762 cmd_install("help", "", cmd_help);
763 cmd_install("newuser", "username -- add user to /adm/users", cmd_newuser);
764 cmd_install("profile", "[01] -- fs profile", cmd_prof);
765 cmd_install("remove", "[file ...] -- remove files/dirs", cmd_remove);
766 cmd_install("stata", "-- overall stats", cmd_stata);
767 cmd_install("stats", "[[-]flags ...] -- various stats", cmd_stats);
768 cmd_install("sync", "", cmd_sync);
769 cmd_install("time", "command -- time another command", cmd_time);
770 cmd_install("users", "[file] -- read /adm/users", cmd_users);
771 cmd_install("version", "-- print time of mk and boot", cmd_version);
772 cmd_install("who", "[user ...] -- print attaches", cmd_who);
773 cmd_install("hangup", "chan -- clunk files", cmd_hangup);
774 cmd_install("printconf", "-- print configuration", cmd_printconf);
775 cmd_install("noauth", "toggle noauth flag", cmd_noauth);
776 cmd_install("noattach", "toggle noattach flag", cmd_noattach);
777 cmd_install("files", "report on files structure", cmd_files);
779 chatflag = flag_install("chat", "-- verbose");
780 errorflag = flag_install("error", "-- on errors");
781 whoflag = flag_install("allchans", "-- on who");
782 authdebugflag = flag_install("authdebug", "-- report authentications");
788 char elem[NAMELEN], *p;
791 if(con_clone(FID1, FID2))
795 p = utfrune(name, '/');
797 p = strchr(name, '\0');
807 memset(elem, 0, sizeof(elem));
808 memmove(elem, name, n);
809 if(con_walk(FID2, elem))
815 /* needs to parse and return vlongs to cope with new larger block numbers */
817 number(char *arg, int def, int base)
829 for (c = *arg; isascii(c) && isspace(c) && c != '\n'; c = *arg)
836 while (isascii(c) && (isdigit(c) || base == 16 && isxdigit(c))) {
838 if(c >= 'a' && c <= 'f')
840 else if(c >= 'A' && c <= 'F')