]> git.wh0rd.org - dump.git/blobdiff - restore/tape.c
Fix restore -P with compressed dumps.
[dump.git] / restore / tape.c
index 5ee9973f5fdf4bb996652060f28f3dd089af6854..bd411b945bf298467144dee8d1a297d160ee102c 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.97 2010/06/11 09:51:59 stelian Exp $";
+       "$Id: tape.c,v 1.101 2011/05/05 16:05:40 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -61,6 +61,8 @@ static const char rcsid[] =
 #include <sys/file.h>
 #include <sys/mtio.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #ifdef __linux__
 #include <sys/time.h>
@@ -520,7 +522,8 @@ again:
                do      {
                        fprintf(stderr, "Specify next volume # (none if no more volumes): ");
                        (void) fflush(stderr);
-                       (void) fgets(buf, TP_BSIZE, terminal);
+                       if (!fgets(buf, TP_BSIZE, terminal))
+                               break;
                } while (!feof(terminal) && buf[0] == '\n');
                if (feof(terminal))
                        exit(1);
@@ -583,7 +586,8 @@ again:
                fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
 #endif
                (void) fflush(stderr);
-               (void) fgets(buf, TP_BSIZE, terminal);
+               if (fgets(buf, TP_BSIZE, terminal))
+                       exit(1);
                if (feof(terminal))
                        exit(1);
                if (!strcmp(buf, "none\n")) {
@@ -847,22 +851,33 @@ extractfile(struct entry *ep, int doremove)
                uid_t luid = curfile.dip->di_uid;
                gid_t lgid = curfile.dip->di_gid;
 
-               Vprintf(stdout, "extract socket as dummy file %s\n", name);
+               Vprintf(stdout, "extract socket %s\n", name);
                skipfile();
                if (Nflag)
                        return (GOOD);
                if (! (spcl.c_flags & DR_METAONLY)) {
-                       int fd;
+                       int sk;
+                       struct sockaddr_un addr;
+
                        if (uflag)
                                (void)unlink(name);
-                       if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
-                               warn("%s: cannot create dummy file", name);
+
+                       if ((sk = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
+                               warn("%s: cannot create socket", name);
                                return (FAIL);
                        }
-                       close(fd);
+                       addr.sun_family = AF_UNIX;
+                       strcpy(addr.sun_path, name);
+                       if (bind(sk, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
+                               warn("%s: cannot create socket", name);
+                               return (FAIL);
+                       }
+                       close(sk);
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -918,7 +933,8 @@ extractfile(struct entry *ep, int doremove)
                        skipfile();
 
 #ifdef HAVE_LCHOWN
-               (void) lchown(name, luid, lgid);
+               if (lchown(name, luid, lgid) < 0)
+                       warn("%s: lchown", name);
 #endif
                extractattr(name);
                return (GOOD);
@@ -941,8 +957,10 @@ extractfile(struct entry *ep, int doremove)
                                return (FAIL);
                        }
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -979,8 +997,10 @@ extractfile(struct entry *ep, int doremove)
                                return (FAIL);
                        }
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -1028,8 +1048,10 @@ extractfile(struct entry *ep, int doremove)
                }
                else
                        skipfile();
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -1249,8 +1271,10 @@ extractresourceufs(char *name)
                /* and add the resource data from tape */
                getfile(xtrfile, xtrskip);
 
-               (void) fchown(ofile, uid, gid);
-               (void) fchmod(ofile, mode);
+               if (fchown(ofile, uid, gid) < 0)
+                       warn("%s: fchown", name);
+               if (fchmod(ofile, mode) < 0)
+                       warn("%s: fchmod", name);
                (void) close(ofile);
                utimes(oFileRsrc, timep);
                (void) lsetflags(oFileRsrc, flags);
@@ -1402,7 +1426,8 @@ loop:
                last_write_was_hole = 1;
        }
        if (last_write_was_hole) {
-               FTRUNCATE(ofile, origsize);
+               if (FTRUNCATE(ofile, origsize) < 0)
+                       warn("%s: ftruncate", curfile.name);
        }
        if (!readingmaps) 
                findinode(&spcl);
@@ -2118,6 +2143,10 @@ readtape_comprfile(char *buf)
                ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
        numtrec = ntrec;
        tpb = (struct tapebuf *) tapebuf;
+#ifdef USE_QFA
+       if (createtapeposflag)
+               (void)GetTapePos(&curtapepos);
+#endif
 
        /* read the block prefix */
        ret = read_a_block(mt, tapebuf, PREFIXSIZE, &rl);
@@ -2207,6 +2236,10 @@ readtape_comprtape(char *buf)
                ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
        numtrec = ntrec;
        tpb = (struct tapebuf *) tapebuf;
+#ifdef USE_QFA
+       if (createtapeposflag)
+               (void)GetTapePos(&curtapepos);
+#endif
 
        /* read the block */
        size = bufsize + PREFIXSIZE;
@@ -2396,8 +2429,8 @@ decompress_tapebuf(struct tapebuf *tpbin, int readsize)
        }
        if (reason) {
                if (lengtherr)
-                       fprintf(stderr, "%s compressed block: %d expected: %u\n",
-                               lengtherr, readsize, tpbin->length + PREFIXSIZE);
+                       fprintf(stderr, "%s compressed block: %d expected: %lu\n",
+                               lengtherr, readsize, (unsigned long)tpbin->length + PREFIXSIZE);
                fprintf(stderr, "decompression error, block %ld: %s\n",
                        tpblksread+1, reason);
                if (!cresult)
@@ -3311,11 +3344,14 @@ ReReadInodeFromTape(dump_ino_t theino)
                cntloop++;
                gethead(&spcl);
        } while (!(spcl.c_inumber == theino && spcl.c_type == TS_INODE && spcl.c_date == dumpdate));
+
+       tpblksread = spcl.c_tapea + spcl.c_volume;
 #ifdef DEBUG_QFA
        fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
        fprintf(stderr, "DEBUG: bufsize %ld\n", bufsize);
        fprintf(stderr, "DEBUG: ntrec %ld\n", ntrec);
-       fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
+       fprintf(stderr, "DEBUG: tapea %d\n", spcl.c_tapea);
+       fprintf(stderr, "DEBUG: tpblksread %ld\n", tpblksread);
 #endif
        findinode(&spcl);
        noresyncmesg = 0;