/* Copyright © 2003 Russ Cox, MIT; see /sys/src/libsunrpc/COPYING */ #include #include #include #include #include int chatty; SunClient *client; void usage(void) { fprint(2, "usage: nfsmount address [cmd]\n" "cmd is one of:\n" "\tnull\n" "\tmnt path\n" "\tdump\n" "\tumnt path\n" "\tumntall\n" "\texport (default)\n"); threadexitsall("usage"); } void portCall(SunCall *c, PortCallType type) { c->rpc.prog = PortProgram; c->rpc.vers = PortVersion; c->rpc.proc = type>>1; c->rpc.iscall = !(type&1); c->type = type; } int getport(SunClient *client, uint prog, uint vers, uint prot, uint *port) { PortTGetport tx; PortRGetport rx; memset(&tx, 0, sizeof tx); portCall(&tx.call, PortCallTGetport); tx.map.prog = prog; tx.map.vers = vers; tx.map.prot = prot; memset(&rx, 0, sizeof rx); portCall(&rx.call, PortCallRGetport); if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0) return -1; *port = rx.port; return 0; } uchar unixauth[] = { 0x12, 0x23, 0x34, 0x45, /* stamp */ 0x00, 0x00, 0x00, 0x04, /* gnot */ 0x67, 0x6e, 0x6f, 0x74, 0x00, 0x00, 0x03, 0xE9, /* 1001 */ 0x00, 0x00, 0x03, 0xE9, /* 1001 */ 0x00, 0x00, 0x00, 0x00, /* gid list */ }; void mountCall(SunCall *c, NfsMount3CallType type) { c->rpc.prog = NfsMount3Program; c->rpc.vers = NfsMount3Version; c->rpc.proc = type>>1; c->rpc.iscall = !(type&1); if(c->rpc.iscall){ c->rpc.cred.flavor = SunAuthSys; c->rpc.cred.data = unixauth; c->rpc.cred.ndata = sizeof unixauth; } c->type = type; } void tnull(char **argv) { NfsMount3TNull tx; NfsMount3RNull rx; USED(argv); memset(&tx, 0, sizeof tx); mountCall(&tx.call, NfsMount3CallTNull); memset(&rx, 0, sizeof rx); mountCall(&rx.call, NfsMount3CallRNull); if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0) sysfatal("rpc: %r"); } void tmnt(char **argv) { int i; NfsMount3TMnt tx; NfsMount3RMnt rx; memset(&tx, 0, sizeof tx); mountCall(&tx.call, NfsMount3CallTMnt); tx.path = argv[0]; memset(&rx, 0, sizeof rx); mountCall(&rx.call, NfsMount3CallRMnt); if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0) sysfatal("rpc: %r"); if(rx.status != 0){ nfs3Errstr(rx.status); sysfatal("mnt: %r"); } print("handle %.*H\n", rx.len, rx.handle); print("auth:"); for(i=0; i ng){ ng = n; g = erealloc(g, sizeof(g[0])*ng); } if(nfsMount3ExportUnpack(p, ep, &p, g, &gg, &e) < 0) sysfatal("unpack export structure failed"); print("%s", e.path); for(i=0; ichatty = chatty; sunClientProg(client, &portProg); if(strstr(addr, "udp!")) proto = PortProtoUdp; else proto = PortProtoTcp; if(getport(client, NfsMount3Program, NfsMount3Version, proto, &port) < 0) sysfatal("getport: %r"); snprint(buf, sizeof buf, "%ud!r", port); addr = netchangeport(addr, buf); sunClientClose(client); } fprint(2, "connecting to %s\n", addr); if((client = sunDial(addr)) == nil) sysfatal("dial %s: %r", addr); client->chatty = chatty; sunClientProg(client, &nfsMount3Prog); argv++; argc--; if(argc == 0){ argc = 1; argv = dflt; } cmd = argv[0]; argv++; argc--; for(i=0; i