]> git.wh0rd.org - dump.git/blobdiff - rmt/rmt.c
LFS fixes (explicit use of open64/etc)
[dump.git] / rmt / rmt.c
index b8cd3f6b0ca802246ae4a29cf8727f73a0eb1ac6..e23d0a3f350c860a6c15efe68230d2058f2c933e 100644 (file)
--- a/rmt/rmt.c
+++ b/rmt/rmt.c
@@ -2,8 +2,8 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *      Stelian Pop <pop@cybercable.fr>, 1999 
- *
+ *     Stelian Pop <pop@noos.fr>, 1999-2000
+ *     Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
  */
 
 /*
  */
 
 #ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1983, 1993\n\
-       The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)rmt.c      8.1 (Berkeley) 6/6/93";
-#endif
 static const char rcsid[] =
-       "$Id: rmt.c,v 1.2 1999/10/11 12:53:25 stelian Exp $";
-#endif /* not lint */
+       "$Id: rmt.c,v 1.14 2001/04/27 15:22:47 stelian Exp $";
+#endif /* not linux */
 
 /*
  * rmt
  */
+#include <config.h>
+#include <compatlfs.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/mtio.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifndef __linux__
 #include <sgtty.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -74,7 +69,7 @@ int   maxrecsize = -1;
 
 #define        SSIZE   64
 char   device[SSIZE];
-char   count[SSIZE], mode[SSIZE], pos[SSIZE], op[SSIZE];
+char   count[SSIZE], filemode[SSIZE], pos[SSIZE], op[SSIZE];
 
 char   resp[BUFSIZ];
 
@@ -88,13 +83,12 @@ void         error __P((int));
 void    getstring __P((char *));
 
 int
-main(argc, argv)
-       int argc;
-       char **argv;
+main(int argc, char *argv[])
 {
-       int rval;
+       int rval = 0;
        char c;
        int n, i, cc;
+       unsigned long block = 0;
 
        argc--, argv++;
        if (argc > 0) {
@@ -114,31 +108,33 @@ top:
                if (tape >= 0)
                        (void) close(tape);
                getstring(device);
-               getstring(mode);
-               DEBUG2("rmtd: O %s %s\n", device, mode);
+               getstring(filemode);
+               DEBUG2("rmtd: O %s %s\n", device, filemode);
                /*
                 * 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(mode), 0666);
+               tape = OPEN(device, atoi(filemode), 0666);
                if (tape < 0)
                        goto ioerror;
+               block = 0;
                goto respond;
 
        case 'C':
-               DEBUG("rmtd: C\n");
+               DEBUG1("rmtd: C  (%lu blocks)\n", block);
                getstring(device);              /* discard */
                if (close(tape) < 0)
                        goto ioerror;
                tape = -1;
+               block = 0;
                goto respond;
 
        case 'L':
                getstring(count);
                getstring(pos);
                DEBUG2("rmtd: L %s %s\n", count, pos);
-               rval = lseek(tape, (off_t)atol(count), atoi(pos));
+               rval = LSEEK(tape, (off_t)atol(count), atoi(pos));
                if (rval < 0)
                        goto ioerror;
                goto respond;
@@ -146,7 +142,7 @@ top:
        case 'W':
                getstring(count);
                n = atoi(count);
-               DEBUG1("rmtd: W %s\n", count);
+               DEBUG2("rmtd: W %s (block = %lu)\n", count, block);
                record = checkbuf(record, n);
                for (i = 0; i < n; i += cc) {
                        cc = read(0, &record[i], n - i);
@@ -158,11 +154,12 @@ top:
                rval = write(tape, record, n);
                if (rval < 0)
                        goto ioerror;
+               block += n >> 10;
                goto respond;
 
        case 'R':
                getstring(count);
-               DEBUG1("rmtd: R %s\n", count);
+               DEBUG2("rmtd: R %s (block %lu)\n", count, block);
                n = atoi(count);
                record = checkbuf(record, n);
                rval = read(tape, record, n);
@@ -171,6 +168,7 @@ top:
                (void)sprintf(resp, "A%d\n", rval);
                (void)write(1, resp, strlen(resp));
                (void)write(1, record, rval);
+               block += n >> 10;
                goto top;
 
        case 'I':
@@ -218,9 +216,7 @@ ioerror:
        goto top;
 }
 
-void
-getstring(bp)
-       char *bp;
+void getstring(char *bp)
 {
        int i;
        char *cp = bp;
@@ -235,9 +231,7 @@ getstring(bp)
 }
 
 char *
-checkbuf(record, size)
-       char *record;
-       int size;
+checkbuf(char *record, int size)
 {
 
        if (size <= maxrecsize)
@@ -257,8 +251,7 @@ checkbuf(record, size)
 }
 
 void
-error(num)
-       int num;
+error(int num)
 {
 
        DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));