aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vbackup/vmount0.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-07-13 03:49:41 +0000
committerrsc <devnull@localhost>2005-07-13 03:49:41 +0000
commit004aa293f360ea0f63ec50f5042f8c0fb2831e4f (patch)
treed44b801b47c82861d68d4045acf0bf7129ce6009 /src/cmd/vbackup/vmount0.c
parent0c98da8bf8ea51d0288222f6c6ba3c125cf20f46 (diff)
downloadplan9port-004aa293f360ea0f63ec50f5042f8c0fb2831e4f.tar.gz
plan9port-004aa293f360ea0f63ec50f5042f8c0fb2831e4f.tar.bz2
plan9port-004aa293f360ea0f63ec50f5042f8c0fb2831e4f.zip
Dump-like file system backup for Unix, built on Venti.
Diffstat (limited to 'src/cmd/vbackup/vmount0.c')
-rw-r--r--src/cmd/vbackup/vmount0.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/cmd/vbackup/vmount0.c b/src/cmd/vbackup/vmount0.c
new file mode 100644
index 00000000..8d650586
--- /dev/null
+++ b/src/cmd/vbackup/vmount0.c
@@ -0,0 +1,77 @@
+#include <u.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <libc.h>
+#include "mountnfs.h"
+
+void
+usage(void)
+{
+ fprint(2, "usage: vmount [-v] [-h handle] address mountpoint\n");
+ exits("usage");
+}
+
+int handlelen = 20;
+uchar handle[64] = {
+ /* SHA1("/") */
+ 0x42, 0x09, 0x9B, 0x4A, 0xF0, 0x21, 0xE5, 0x3F, 0xD8, 0xFD,
+ 0x4E, 0x05, 0x6C, 0x25, 0x68, 0xD7, 0xC2, 0xE3, 0xFF, 0xA8,
+};
+
+void
+main(int argc, char **argv)
+{
+ char *p, *net, *unx;
+ u32int host;
+ int n, port, proto, verbose;
+ struct sockaddr_in sa;
+
+ verbose = 0;
+ ARGBEGIN{
+ case 'h':
+ p = EARGF(usage());
+ n = strlen(p);
+ if(n%2)
+ sysfatal("bad handle '%s'", p);
+ if(n > 2*sizeof handle)
+ sysfatal("handle too long '%s'", p);
+ handlelen = n/2;
+ if(dec16(handle, n/2, p, n) != n/2)
+ sysfatal("bad hex in handle '%s'", p);
+ break;
+
+ case 'v':
+ verbose = 1;
+ break;
+
+ default:
+ usage();
+ }ARGEND
+
+ if(argc != 2)
+ usage();
+
+ p = p9netmkaddr(argv[0], "udp", "nfs");
+ if(p9dialparse(strdup(p), &net, &unx, &host, &port) < 0)
+ sysfatal("bad address '%s'", p);
+
+ if(verbose)
+ print("nfs server is net=%s addr=%d.%d.%d.%d port=%d\n",
+ net, host&0xFF, (host>>8)&0xFF, (host>>16)&0xFF, host>>24, port);
+
+ proto = 0;
+ if(strcmp(net, "tcp") == 0)
+ proto = SOCK_STREAM;
+ else if(strcmp(net, "udp") == 0)
+ proto = SOCK_DGRAM;
+ else
+ sysfatal("bad proto %s: can only handle tcp and udp", net);
+
+ memset(&sa, 0, sizeof sa);
+ memmove(&sa.sin_addr, &host, 4);
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(port);
+
+ mountnfs(proto, &sa, handle, handlelen, argv[1]);
+ exits(0);
+}