tvbackup for mac tweaks (dave swasey) - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 9437f55b49afeca070264aec93f94b840e055c89
parent c99ef336aaa39a0c7aa2d0c62e93680764790605
Author: rsc 
Date:   Tue, 12 Jun 2007 18:35:17 +0000

vbackup for mac tweaks (dave swasey)

Diffstat:
  M src/cmd/vbackup/vbackup.c           |      28 ++++++++++++++++++++--------

1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/cmd/vbackup/vbackup.c b/src/cmd/vbackup/vbackup.c
t@@ -7,6 +7,7 @@
  *        -D        print debugging
  *        -f        'fast' writes - skip write if block exists on server
  *        -m        set mount name
+ *        -M        set mount place
  *        -n        nop -- don't actually write blocks
  *        -s        print status updates
  *        -v        print debugging trace
t@@ -83,19 +84,19 @@ void                fsysproc(void*);
 void                statusproc(void*);
 void                ventiproc(void*);
 int                timefmt(Fmt*);
-char*        mountplace(char *dev);
+char*        guessmountplace(char *dev);
 
 void
 usage(void)
 {
-        fprint(2, "usage: vbackup [-DVnv] [-m mtpt] [-s secs] [-w n] disk [score]\n");
+        fprint(2, "usage: vbackup [-DVnv] [-m mtpt] [-M mtpl] [-s secs] [-w n] disk [score]\n");
         threadexitsall("usage");
 }
 
 void
 threadmain(int argc, char **argv)
 {
-        char *pref, *mountname;
+        char *pref, *mountname, *mountplace;
         uchar score[VtScoreSize], prev[VtScoreSize];
         int i, fd, csize;
         vlong bsize;
t@@ -112,6 +113,7 @@ threadmain(int argc, char **argv)
         fmtinstall('V', vtscorefmt);
 
         mountname = sysname();
+        mountplace = nil;
         ARGBEGIN{
         default:
                 usage();
t@@ -128,6 +130,12 @@ threadmain(int argc, char **argv)
         case 'm':
                 mountname = EARGF(usage());
                 break;
+        case 'M':
+                mountplace = EARGF(usage());
+                i = strlen(mountplace);
+                if(i > 0 && mountplace[i-1] == '/')
+                        mountplace[i-1] = 0;
+                break;
         case 'n':
                 nop = 1;
                 break;
t@@ -289,8 +297,10 @@ threadmain(int argc, char **argv)
         qfree(qventi);
 
         if(statustime)
-                print("# %T procs exited: %d blocks changed, %d read, %d written, %d skipped, %d copied\n",
-                        nchange, vtcachenread, vtcachenwrite, nskip, vtcachencopy);
+                print("# %T procs exited: %d of %d %d-byte blocks changed, "
+                        "%d read, %d written, %d skipped, %d copied\n",
+                        nchange, fsys->nblock, fsys->blocksize,
+                        vtcachenread, vtcachenwrite, nskip, vtcachencopy);
 
         /*
          * prepare root block
t@@ -328,9 +338,11 @@ threadmain(int argc, char **argv)
         tm = *localtime(time(0));
         tm.year += 1900;
         tm.mon++;
+        if(mountplace == nil)
+                mountplace = guessmountplace(argv[0]);
         print("mount /%s/%d/%02d%02d%s %s:%V %d/%02d%02d/%02d%02d\n",
                 mountname, tm.year, tm.mon, tm.mday, 
-                mountplace(argv[0]),
+                mountplace,
                 root.type, b->score,
                 tm.year, tm.mon, tm.mday, tm.hour, tm.min);
         print("# %T %s %s:%V\n", argv[0], root.type, b->score);
t@@ -549,7 +561,7 @@ timefmt(Fmt *fmt)
 }
 
 char*
-mountplace(char *dev)
+guessmountplace(char *dev)
 {
         char *cmd, *q;
         int p[2], fd[3], n;
t@@ -561,7 +573,7 @@ mountplace(char *dev)
         fd[0] = -1;
         fd[1] = p[1];
         fd[2] = -1;
-        cmd = smprint("mount | awk '$1==\"%s\" && $2 == \"on\" {print $3}'", dev);
+        cmd = smprint("mount | awk 'BEGIN{v=\"%s\"; u=v; sub(/rdisk/, \"disk\", u);} ($1==v||$1==u) && $2 == \"on\" {print $3}'", dev);
         if(threadspawnl(fd, "sh", "sh", "-c", cmd, nil) < 0)
                 sysfatal("exec mount|awk (to find mtpt of %s): %r", dev);
         /* threadspawnl closed p[1] */