From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/cmd/syscall/syscall.c | 190 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100755 sys/src/cmd/syscall/syscall.c (limited to 'sys/src/cmd/syscall/syscall.c') diff --git a/sys/src/cmd/syscall/syscall.c b/sys/src/cmd/syscall/syscall.c new file mode 100755 index 000000000..74e3afe2b --- /dev/null +++ b/sys/src/cmd/syscall/syscall.c @@ -0,0 +1,190 @@ +#include +#include +#include +#include + +char buf[1048576]; +#define NARG 5 +uintptr arg[NARG]; + +/* system calls not defined in libc.h */ +int sysr1(void); +int _stat(char*, char*); +int _fstat(int, char*); +int _errstr(char*); +int _wstat(char*, char*); +int _fwstat(int, char*); +int _read(int, void*, int); +int _write(int, void*, int); +int _read9p(int, void*, int); +int _write9p(int, void*, int); +int brk_(void*); +int _nfstat(int, void*, int); +int _nstat(char*, void*, int); +int _nfwstat(int, void*, int); +int _nwstat(char*, void*, int); +int _fsession(char*, void*, int); +int _mount(int, char*, int, char*); +int _wait(void*); + +struct{ + char *name; + int (*func)(...); +}tab[]={ +#include "tab.h" + 0, 0 +}; + +uintptr parse(char *); +void catch(void*, char*); + +char* +xctime(ulong t) +{ + char *buf, *s; + + s = ctime(t); + s[strlen(s)-1] = '\0'; /* remove newline */ + buf = malloc(512); + if(buf == nil) + sysfatal("can't malloc: %r"); + snprint(buf, 512, "%s (%lud)", s, t); + return buf; +} + + +char* +lstime(long l) +{ + static char buf[32]; + char *t; + long clk; + + clk = time(0); + t = ctime(l); + /* 6 months in the past or a day in the future */ + if(l1+NARG){ + Usage: + fprint(2, "usage: syscall [-ox] entry [args; buf==1MB buffer]\n"); + fprint(2, "\tsyscall write 1 hello 5\n"); + fprint(2, "\tsyscall -o errstr buf 1024\n"); + fprint(2, "\tsyscall -[xs] stat file buf 1024\n"); + exits("usage"); + } + for(i=1; i 0){ + r = convM2D((uchar*)buf, r, &d, strs); + if(r <= BIT16SZ) + print("short stat message\n"); + else{ + print("[%s] ", d.muid); + print("(%.16llux %lud %.2ux) ", d.qid.path, d.qid.vers, d.qid.type); + print("%M (%luo) ", d.mode, d.mode); + print("%c %d ", d.type, d.dev); + print("%s %s ", d.uid, d.gid); + print("%lld ", d.length); + print("%s ", lstime(d.mtime)); + print("%s\n", d.name); + print("\tmtime: %s\n\tatime: %s\n", xctime(d.mtime), xctime(d.atime)); + } + } + exits(ebuf); + } + fprint(2, "syscall: %s not known\n", argv[0]); + exits("unknown"); +} + +uintptr +parse(char *s) +{ + char *t; + uintptr l; + + if(strcmp(s, "buf") == 0) + return (uintptr)buf; + + l = strtoull(s, &t, 0); + if(t>s && *t==0) + return l; + return (uintptr)s; +} + +void +catch(void *, char *msg) +{ + fprint(2, "syscall: received note='%s'\n", msg); + noted(NDFLT); +} -- cgit v1.2.3