#include #include #include #include #include #include #include #include uchar *buf; uint bufsize; Nfs3Handle cwd, root; Biobuf bin, bout; char pwd[1000]; Fsys *fsys; SunAuthUnix *auth; VtConn *z; VtCache *c; Disk *disk; char *cmdhelp(int, char**); char *cmdcd(int, char**); char *cmdpwd(int, char**); char *cmdls(int, char**); char *cmdcp(int, char**); char *cmdblock(int, char**); char *cmddisk(int, char**); typedef struct Cmd Cmd; struct Cmd { char *s; char *(*fn)(int, char**); char *help; }; Cmd cmdtab[] = { "cd", cmdcd, "cd dir - change directory", "ls", cmdls, "ls [-d] path... - list file", "pwd", cmdpwd, "pwd - print working directory", "help", cmdhelp, "help - print usage summaries", "block", cmdblock, "block path offset - print disk offset of path's byte offset", "disk", cmddisk, "disk offset count - dump disk contents", }; char* ebuf(void) { static char buf[ERRMAX]; rerrstr(buf, sizeof buf); return buf; } char* walk(char *path, Nfs3Handle *ph) { char *p, *q; Nfs3Handle h; Nfs3Status ok; if(path[0] == '/') h = root; else h = cwd; for(p=path; *p; p=q){ q = strchr(p, '/'); if(q == nil) q = p+strlen(p); else *q++ = 0; if(*p == 0) continue; if((ok = fsyslookup(fsys, auth, &h, p, &h)) != Nfs3Ok){ nfs3errstr(ok); return ebuf(); } } *ph = h; return nil; } char* cmdhelp(int argc, char **argv) { int i; for(i=0; itype */ Bprint(&bout, "%s%s%s", dir ? dir : "", dir && elem ? "/" : "", elem ? elem : ""); Bprint(&bout, " %c%luo %1d %4d %4d", c, attr->mode, attr->nlink, attr->uid, attr->gid); Bprint(&bout, " %11,lld %11,lld %4d.%4d %#11,llux %#11,llux", attr->size, attr->used, attr->major, attr->minor, attr->fsid, attr->fileid); Bprint(&bout, "\n"); } void lsdir(char *dir, Nfs3Handle *h) { uchar *data, *p, *ep; Nfs3Attr attr; Nfs3Entry e; Nfs3Handle eh; u32int count; u1int eof; Nfs3Status ok; u64int cookie; cookie = 0; for(;;){ ok = fsysreaddir(fsys, auth, h, 8192, cookie, &data, &count, &eof); fprint(2, "got %d\n", count); if(ok != Nfs3Ok){ nfs3errstr(ok); fprint(2, "ls %s: %r\n", dir); return; } p = data; ep = data+count; while(pfileblock(fsys, &h, strtoll(argv[1], 0, 0))) == 0){ fprint(2, "%s: %r\n", argv[0]); return nil; } print("%#llux\n", bno); return nil; } char* cmddisk(int argc, char **argv) { Block *b; int delta, count, i; u64int offset; uchar *p; ARGBEGIN{ default: return "usage: disk offset count"; }ARGEND if(argc != 2) return "usage: disk offset count"; offset = strtoull(argv[0], 0, 0); count = atoi(argv[1]); delta = offset%fsys->blocksize; b = diskread(disk, fsys->blocksize, offset-delta); if(b == nil){ fprint(2, "diskread: %r\n"); return nil; } p = b->data + delta; for(i=0; iblocksize); buf = emalloc(fsys->blocksize); if((ok = fsysroot(fsys, &root)) != Nfs3Ok){ nfs3errstr(ok); sysfatal("accessing root: %r"); } cwd = root; Binit(&bin, 0, OREAD); Binit(&bout, 1, OWRITE); while(fprint(2, "vftp> "), (p = Brdstr(&bin, '\n', 1)) != nil){ if(p[0] == '#') continue; nf = tokenize(p, f, nelem(f)); if(nf == 0) continue; for(i=0; i