]> git.wh0rd.org - dump.git/commitdiff
Make dump/restore use O_CREAT|O_TRUNC both locally and remotely.
authorStelian Pop <stelian@popies.net>
Tue, 21 May 2002 15:48:44 +0000 (15:48 +0000)
committerStelian Pop <stelian@popies.net>
Tue, 21 May 2002 15:48:44 +0000 (15:48 +0000)
Use GNU's symbolic syntax over rmt for open modes.

CHANGES
common/dumprmt.c
dump/dump.h
dump/tape.c
restore/extern.h
restore/tape.c
rmt/rmt.c

diff --git a/CHANGES b/CHANGES
index 0f1cedb5c59bf1d47d750d40c6b393099cc8fa2e..1fbab6fa6a1f0660400fe2de1046ef462b43acdc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,4 @@
-$Id: CHANGES,v 1.176 2002/05/17 08:10:43 stelian Exp $
+$Id: CHANGES,v 1.177 2002/05/21 15:48:44 stelian Exp $
 
 Changes between versions 0.4b28 and 0.4b29 (released ??????????????)
 ====================================================================
@@ -27,7 +27,11 @@ Changes between versions 0.4b28 and 0.4b29 (released ??????????????)
 4.     Added some example scripts from Gerd Bavendiek <bav@epost.de>
        which makes one able to pipe the output of dump, by the net, to
        a remote CD-burner server.
-       
+
+5.     Make dump use O_CREAT|O_TRUNC both locally and remotely (over rmt), and 
+       use GNU's symbolic syntax over rmt instead of numerical values to assure 
+       multiple platform compatibility.
+
 Changes between versions 0.4b27 and 0.4b28 (released April 12, 2002)
 ====================================================================
 
index 4d570fdd87eabdfd5f73fa991cc360e098a104cb..129ce208c4c26d8ce9e82b5ec5a89f2caa1d9d60 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: dumprmt.c,v 1.20 2002/01/25 15:08:59 stelian Exp $";
+       "$Id: dumprmt.c,v 1.21 2002/05/21 15:48:46 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -273,11 +273,11 @@ okname(const char *cp0)
 }
 
 int
-rmtopen(const char *tape, int mode)
+rmtopen(const char *tape, const char *mode)
 {
        char buf[MAXPATHLEN];
 
-       (void)snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode);
+       (void)snprintf(buf, sizeof (buf), "O%s\n%s\n", tape, mode);
        rmtstate = TS_OPEN;
        return (rmtcall(tape, buf));
 }
index 177329bbc5917b3bddf08637cfbc901d8f6b9deb..a392aacd205dd3fdc0c262681c1b8930a20b76ed 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <stelian@popies.net>, 1999-2000
  *     Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
  *
- *     $Id: dump.h,v 1.37 2002/04/04 08:20:23 stelian Exp $
+ *     $Id: dump.h,v 1.38 2002/05/21 15:48:46 stelian Exp $
  */
 
 /*-
@@ -185,7 +185,7 @@ struct      dinode *getino __P((dump_ino_t inum));
 /* rdump routines */
 #ifdef RDUMP
 int    rmthost __P((const char *host));
-int    rmtopen __P((const char *tape, int mode));
+int    rmtopen __P((const char *tape, const char *mode));
 void   rmtclose __P((void));
 int    rmtread __P((char *buf, size_t count));
 int    rmtwrite __P((const char *buf, size_t count));
index 0dffa3a7cba384772f087967cf0356e4236412a8..54b387eac62559d092a687ab18eca75d7a36a479 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.67 2002/04/11 14:51:09 stelian Exp $";
+       "$Id: tape.c,v 1.68 2002/05/21 15:48:46 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -542,7 +542,7 @@ trewind(void)
 #ifdef RDUMP
                if (host) {
                        rmtclose();
-                       while (rmtopen(tape, 0) < 0)
+                       while (rmtopen(tape, "O_RDONLY") < 0)
                                sleep(10);
                        rmtclose();
                }
@@ -551,7 +551,7 @@ trewind(void)
                {
                        (void) close(tapefd);
                        if (!fifoout) {
-                               while ((f = OPEN(tape, 0)) < 0)
+                               while ((f = OPEN(tape, O_RDONLY)) < 0)
                                        sleep (10);
                                (void) close(f);
                        }
@@ -864,12 +864,12 @@ restore_check_point:
                        msg("Dumping volume %d on %s\n", tapeno, tape);
                }
 #ifdef RDUMP
-               while ((tapefd = (host ? rmtopen(tape, 2) : pipeout ? 
+               while ((tapefd = (host ? rmtopen(tape, "O_WRONLY|O_CREAT|O_TRUNC") : pipeout ? 
                        fileno(stdout) : 
-                       OPEN(tape, O_WRONLY|O_CREAT, 0666))) < 0)
+                       OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0)
 #else
                while ((tapefd = (pipeout ? fileno(stdout) :
-                                 OPEN(tape, O_RDWR|O_CREAT, 0666))) < 0)
+                                 OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0)
 #endif
                    {
                        msg("Cannot open output \"%s\": %s\n", tape, 
index 0a4cbb1c94232135299eea0e138033ff6432284b..6046e57afc018f8f917e50664cdc835408b9e345 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <stelian@popies.net>, 1999-2000
  *     Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
  *
- *     $Id: extern.h,v 1.17 2002/04/04 08:20:23 stelian Exp $
+ *     $Id: extern.h,v 1.18 2002/05/21 15:48:46 stelian Exp $
  */
 
 /*-
@@ -118,7 +118,7 @@ void                 xtrnull __P((char *, size_t));
 void           rmtclose __P((void));
 int            rmthost __P((const char *));
 int            rmtioctl __P((int, int));
-int            rmtopen __P((const char *, int));
+int            rmtopen __P((const char *, const char *));
 int            rmtread __P((const char *, int));
 int            rmtseek __P((int, int));
 
index 1b6b1d9d52578436d8fd6c1cfa6baf712359fe11..558e8f3680a9ecbacdf0cf2e196cb197d25da2d4 100644 (file)
@@ -46,7 +46,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.61 2002/05/06 08:45:41 stelian Exp $";
+       "$Id: tape.c,v 1.62 2002/05/21 15:48:46 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -285,7 +285,7 @@ setup(void)
 
 #ifdef RRESTORE
        if (host)
-               mt = rmtopen(temptape, 0);
+               mt = rmtopen(temptape, "O_RDONLY");
        else
 #endif
        if (pipein)
@@ -541,7 +541,7 @@ again:
        }
 #ifdef RRESTORE
        if (host)
-               mt = rmtopen(magtape, 0);
+               mt = rmtopen(magtape, "O_RDONLY");
        else
 #endif
                mt = OPEN(magtape, O_RDONLY, 0);
index 3c8f5fd3dd3ab17f90af0d6ea5738b6d5106fa27..fc8ebce49eec2c95bb89cb7f978ae0f87ac4a077 100644 (file)
--- a/rmt/rmt.c
+++ b/rmt/rmt.c
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: rmt.c,v 1.19 2002/04/16 21:00:59 stelian Exp $";
+       "$Id: rmt.c,v 1.20 2002/05/21 15:48:46 stelian Exp $";
 #endif /* not linux */
 
 /*
@@ -117,13 +117,14 @@ static int        rmt_version = 0;
 char   *checkbuf __P((char *, int));
 void    error __P((int));
 void    getstring __P((char *));
+int     getopenflags __P((char *));
 
 int
 main(int argc, char *argv[])
 {
        int rval = 0;
        char c;
-       int n, i, cc;
+       int n, i, cc, oflags;
        unsigned long block = 0;
 
        argc--, argv++;
@@ -146,12 +147,24 @@ top:
                getstring(device);
                getstring(filemode);
                DEBUG2("rmtd: O %s %s\n", device, filemode);
+               /*
+                * Translate extended GNU syntax into its numeric platform equivalent
+                */
+               oflags = getopenflags(filemode);
+#ifdef  O_TEXT
+               /*
+                * Default to O_BINARY the client may not know that we need it.
+                */
+               if ((oflags & O_TEXT) == 0)
+                       oflags |= O_BINARY;
+#endif
+               DEBUG2("rmtd: O %s %d\n", device, oflags);
                /*
                 * XXX the rmt protocol does not provide a means to
                 * specify the permission bits; allow rw for everyone,
                 * as modified by the users umask
                 */
-               tape = OPEN(device, atoi(filemode), 0666);
+               tape = OPEN(device, oflags, 0666);
                if (tape < 0)
                        goto ioerror;
                block = 0;
@@ -445,3 +458,96 @@ error(int num)
        (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num));
        (void)write(1, resp, strlen(resp));
 }
+
+struct openflags {
+       char    *name;
+       int     value;
+} openflags[] = {
+       { "O_RDONLY",   O_RDONLY },
+       { "O_WRONLY",   O_WRONLY },
+       { "O_RDWR",     O_RDWR },
+#ifdef O_CREAT
+       { "O_CREAT",    O_CREAT },
+#endif
+#ifdef O_EXCL
+       { "O_EXCL",     O_EXCL },
+#endif
+#ifdef O_NOCTTY
+       { "O_NOCTTY",   O_NOCTTY },
+#endif
+#ifdef O_TRUNC
+       { "O_TRUNC",    O_TRUNC },
+#endif
+#ifdef O_APPEND
+       { "O_APPEND",   O_APPEND },
+#endif
+#ifdef O_NONBLOCK
+       { "O_NONBLOCK", O_NONBLOCK },
+#endif
+#ifdef O_NDELAY
+       { "O_NDELAY",   O_NDELAY },
+#endif
+#ifdef O_SYNC
+       { "O_SYNC",     O_SYNC },
+#endif
+#ifdef O_FSYNC
+       { "O_FSYNC",    O_FSYNC },
+#endif
+#ifdef O_ASYNC
+       { "O_ASYNC",    O_ASYNC },
+#endif
+#ifdef O_TEXT
+       { "O_TEXT",     O_TEXT },
+#endif
+#ifdef O_DSYNC
+       { "O_DSYNC",    O_DSYNC },
+#endif
+#ifdef O_RSYNC
+       { "O_RSYNC",    O_RSYNC },
+#endif
+#ifdef O_PRIV
+       { "O_PRIV",     O_PRIV },
+#endif
+#ifdef O_LARGEFILE
+       { "O_LARGEFILE",O_LARGEFILE },
+#endif
+       { NULL,         0 }
+};
+
+/* Parts of this stolen again from Jörg Schilling's star package... */
+int
+getopenflags(char *filemode)
+{
+       char    *p = filemode;
+       struct openflags *op;
+       int     result = 0;
+
+       do {
+               /* skip space */
+               while (*p != '\0' && *p == ' ')
+                       p++;
+               /* get O_XXXX constant */
+               if (p[0] != 'O' || p[1] != '_') {
+                       /* numeric syntax detected */
+                       result = atoi(filemode);
+                       result &= O_RDONLY | O_WRONLY | O_RDWR;
+                       return result;
+               }
+
+               /* translate O_XXXX constant */
+               for (op = openflags; op->name; op++) {
+                       int slen = strlen(op->name);
+                       if ((strncmp(op->name, p, slen) == 0) &&
+                           (p[slen] == '|' || p[slen] == ' ' ||
+                            p[slen] == '\0')) {
+                               result |= op->value;
+                               break;
+                       }
+               }
+
+               /* goto next constant */
+               p = strchr(p, '|');
+       } while (p && *p++ == '|');
+
+       return result;
+}