1 /* Copyright © 2003 Russ Cox, MIT; see /sys/src/libsunrpc/COPYING */
14 fprint(2, "usage: nfsmount address [cmd]\n"
21 "\texport (default)\n");
22 threadexitsall("usage");
26 portCall(SunCall *c, PortCallType type)
28 c->rpc.prog = PortProgram;
29 c->rpc.vers = PortVersion;
30 c->rpc.proc = type>>1;
31 c->rpc.iscall = !(type&1);
36 getport(SunClient *client, uint prog, uint vers, uint prot, uint *port)
41 memset(&tx, 0, sizeof tx);
42 portCall(&tx.call, PortCallTGetport);
47 memset(&rx, 0, sizeof rx);
48 portCall(&rx.call, PortCallRGetport);
50 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
57 0x12, 0x23, 0x34, 0x45, /* stamp */
58 0x00, 0x00, 0x00, 0x04, /* gnot */
59 0x67, 0x6e, 0x6f, 0x74,
60 0x00, 0x00, 0x03, 0xE9, /* 1001 */
61 0x00, 0x00, 0x03, 0xE9, /* 1001 */
62 0x00, 0x00, 0x00, 0x00, /* gid list */
65 mountCall(SunCall *c, NfsMount3CallType type)
67 c->rpc.prog = NfsMount3Program;
68 c->rpc.vers = NfsMount3Version;
69 c->rpc.proc = type>>1;
70 c->rpc.iscall = !(type&1);
72 c->rpc.cred.flavor = SunAuthSys;
73 c->rpc.cred.data = unixauth;
74 c->rpc.cred.ndata = sizeof unixauth;
87 memset(&tx, 0, sizeof tx);
88 mountCall(&tx.call, NfsMount3CallTNull);
90 memset(&rx, 0, sizeof rx);
91 mountCall(&rx.call, NfsMount3CallRNull);
93 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
104 memset(&tx, 0, sizeof tx);
105 mountCall(&tx.call, NfsMount3CallTMnt);
108 memset(&rx, 0, sizeof rx);
109 mountCall(&rx.call, NfsMount3CallRMnt);
111 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
115 nfs3Errstr(rx.status);
119 print("handle %.*H\n", rx.len, rx.handle);
121 for(i=0; i<rx.nauth; i++)
122 print(" %ud", (uint)rx.auth[i]);
134 memset(&tx, 0, sizeof tx);
135 mountCall(&tx.call, NfsMount3CallTDump);
138 memset(&rx, 0, sizeof rx);
139 mountCall(&rx.call, NfsMount3CallRDump);
141 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
147 if(nfsMount3EntryUnpack(p, ep, &p, &e) < 0)
148 sysfatal("unpack entry structure failed");
149 print("%s %s\n", e.host, e.path);
159 memset(&tx, 0, sizeof tx);
160 mountCall(&tx.call, NfsMount3CallTUmnt);
163 memset(&rx, 0, sizeof rx);
164 mountCall(&rx.call, NfsMount3CallRUmnt);
166 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
173 tumntall(char **argv)
175 NfsMount3TUmntall tx;
176 NfsMount3RUmntall rx;
178 memset(&tx, 0, sizeof tx);
179 mountCall(&tx.call, NfsMount3CallTUmntall);
182 memset(&rx, 0, sizeof rx);
183 mountCall(&rx.call, NfsMount3CallRUmntall);
185 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
194 uchar *p, *ep, *tofree;
201 memset(&tx, 0, sizeof tx);
202 mountCall(&tx.call, NfsMount3CallTExport);
205 memset(&rx, 0, sizeof rx);
206 mountCall(&rx.call, NfsMount3CallRExport);
208 if(sunClientRpc(client, 0, &tx.call, &rx.call, &tofree) < 0)
216 n = nfsMount3ExportGroupSize(p);
219 g = erealloc(g, sizeof(g[0])*ng);
221 if(nfsMount3ExportUnpack(p, ep, &p, g, &gg, &e) < 0)
222 sysfatal("unpack export structure failed");
224 for(i=0; i<e.ng; i++)
225 print(" %s", e.g[i]);
240 "umntall", 1, tumntall,
241 "export", 0, texport,
245 netchangeport(char *addr, char *port)
247 static char buf[256];
250 strecpy(buf, buf+sizeof buf, addr);
251 r = strrchr(buf, '!');
255 strecpy(r, buf+sizeof buf, port);
260 threadmain(int argc, char **argv)
262 char *dflt[] = { "export", };
282 fmtinstall('B', sunRpcFmt);
283 fmtinstall('C', sunCallFmt);
284 fmtinstall('H', encodefmt);
285 sunFmtInstall(&portProg);
286 sunFmtInstall(&nfsMount3Prog);
288 addr = netmkaddr(argv[0], "udp", "portmap");
290 /* translate with port mapper */
291 fprint(2, "connecting to %s\n", addr);
292 if((client = sunDial(addr)) == nil)
293 sysfatal("dial %s: %r", addr);
294 client->chatty = chatty;
295 sunClientProg(client, &portProg);
296 if(strstr(addr, "udp!"))
297 proto = PortProtoUdp;
299 proto = PortProtoTcp;
300 if(getport(client, NfsMount3Program, NfsMount3Version, proto, &port) < 0)
301 sysfatal("getport: %r");
302 snprint(buf, sizeof buf, "%ud!r", port);
303 addr = netchangeport(addr, buf);
304 sunClientClose(client);
307 fprint(2, "connecting to %s\n", addr);
308 if((client = sunDial(addr)) == nil)
309 sysfatal("dial %s: %r", addr);
311 client->chatty = chatty;
312 sunClientProg(client, &nfsMount3Prog);
325 for(i=0; i<nelem(tab); i++){
326 if(strcmp(tab[i].cmd, cmd) == 0){
327 if(tab[i].narg != argc)