Blob


1 #include <u.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <libc.h>
5 #include "mountnfs.h"
7 void
8 usage(void)
9 {
10 fprint(2, "usage: vmount [-v] [-h handle] address mountpoint\n");
11 exits("usage");
12 }
14 int handlelen = 20;
15 uchar handle[64] = {
16 /* SHA1("/") */
17 0x42, 0x09, 0x9B, 0x4A, 0xF0, 0x21, 0xE5, 0x3F, 0xD8, 0xFD,
18 0x4E, 0x05, 0x6C, 0x25, 0x68, 0xD7, 0xC2, 0xE3, 0xFF, 0xA8,
19 };
21 void
22 main(int argc, char **argv)
23 {
24 char *p, *net, *unx;
25 u32int host;
26 int n, port, proto, verbose;
27 struct sockaddr_in sa;
29 verbose = 0;
30 ARGBEGIN{
31 case 'h':
32 p = EARGF(usage());
33 n = strlen(p);
34 if(n%2)
35 sysfatal("bad handle '%s'", p);
36 if(n > 2*sizeof handle)
37 sysfatal("handle too long '%s'", p);
38 handlelen = n/2;
39 if(dec16(handle, n/2, p, n) != n/2)
40 sysfatal("bad hex in handle '%s'", p);
41 break;
43 case 'v':
44 verbose = 1;
45 break;
47 default:
48 usage();
49 }ARGEND
51 if(argc != 2)
52 usage();
54 p = p9netmkaddr(argv[0], "udp", "nfs");
55 if(p9dialparse(strdup(p), &net, &unx, &host, &port) < 0)
56 sysfatal("bad address '%s'", p);
58 if(verbose)
59 print("nfs server is net=%s addr=%d.%d.%d.%d port=%d\n",
60 net, host&0xFF, (host>>8)&0xFF, (host>>16)&0xFF, host>>24, port);
62 proto = 0;
63 if(strcmp(net, "tcp") == 0)
64 proto = SOCK_STREAM;
65 else if(strcmp(net, "udp") == 0)
66 proto = SOCK_DGRAM;
67 else
68 sysfatal("bad proto %s: can only handle tcp and udp", net);
70 memset(&sa, 0, sizeof sa);
71 memmove(&sa.sin_addr, &host, 4);
72 sa.sin_family = AF_INET;
73 sa.sin_port = htons(port);
75 mountnfs(proto, &sa, handle, handlelen, argv[1]);
76 exits(0);
77 }