]> git.wh0rd.org - dump.git/blobdiff - restore/tape.c
Extract backuped sockets as dummy files.
[dump.git] / restore / tape.c
index 7378b208aad0b38bab9c38909627d6736c001564..5ee9973f5fdf4bb996652060f28f3dd089af6854 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.91 2007/02/22 20:12:50 stelian Exp $";
+       "$Id: tape.c,v 1.97 2010/06/11 09:51:59 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -474,7 +474,6 @@ getvol(long nextvol)
        if (nextvol == 1) {
                tapesread = 0;
                gettingfile = 0;
-               tpblksread = 0;
                blksread = 0;
        }
        if (pipein) {
@@ -844,9 +843,43 @@ extractfile(struct entry *ep, int doremove)
                return (FAIL);
 
        case IFSOCK:
-               Vprintf(stdout, "skipped socket %s\n", name);
+       {
+               uid_t luid = curfile.dip->di_uid;
+               gid_t lgid = curfile.dip->di_gid;
+
+               Vprintf(stdout, "extract socket as dummy file %s\n", name);
                skipfile();
+               if (Nflag)
+                       return (GOOD);
+               if (! (spcl.c_flags & DR_METAONLY)) {
+                       int fd;
+                       if (uflag)
+                               (void)unlink(name);
+                       if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
+                               warn("%s: cannot create dummy file", name);
+                               return (FAIL);
+                       }
+                       close(fd);
+               }
+               (void) chown(name, luid, lgid);
+               (void) chmod(name, mode);
+               extractattr(name);
+               utimes(name, timep);
+               if (flags)
+#ifdef __linux__
+                       (void) lsetflags(name, flags);
+#else
+#ifdef sunos
+                       {
+                       warn("%s: cannot call chflags", name);
+                       /* (void) chflags(name, flags); */
+                       }
+#else
+                       (void) chflags(name, flags);
+#endif
+#endif
                return (GOOD);
+       }
 
        case IFDIR:
        {
@@ -892,22 +925,26 @@ extractfile(struct entry *ep, int doremove)
        }
 
        case IFIFO:
+       {
+               uid_t luid = curfile.dip->di_uid;
+               gid_t lgid = curfile.dip->di_gid;
+
                Vprintf(stdout, "extract fifo %s\n", name);
-               if (Nflag) {
-                       skipfile();
+               skipfile();
+               if (Nflag)
                        return (GOOD);
-               }
                if (! (spcl.c_flags & DR_METAONLY)) {
                        if (uflag && !Nflag)
                                (void)unlink(name);
                        if (mkfifo(name, mode) < 0) {
                                warn("%s: cannot create fifo", name);
-                               skipfile();
                                return (FAIL);
                        }
                }
-               (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
+               (void) chown(name, luid, lgid);
                (void) chmod(name, mode);
+               extractattr(name);
+               utimes(name, timep);
                if (flags)
 #ifdef  __linux__
                        (void) lsetflags(name, flags);
@@ -921,29 +958,31 @@ extractfile(struct entry *ep, int doremove)
                        (void) chflags(name, flags);
 #endif
 #endif
-               skipfile();
-               extractattr(name);
-               utimes(name, timep);
                return (GOOD);
-
+       }
        case IFCHR:
        case IFBLK:
+       {
+               uid_t luid = curfile.dip->di_uid;
+               gid_t lgid = curfile.dip->di_gid;
+               int lrdev = (int)curfile.dip->di_rdev;
+
                Vprintf(stdout, "extract special file %s\n", name);
-               if (Nflag) {
-                       skipfile();
+               skipfile();
+               if (Nflag)
                        return (GOOD);
-               }
                if (! (spcl.c_flags & DR_METAONLY)) {
                        if (uflag)
                                (void)unlink(name);
-                       if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
+                       if (mknod(name, mode, lrdev) < 0) {
                                warn("%s: cannot create special file", name);
-                               skipfile();
                                return (FAIL);
                        }
                }
-               (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
+               (void) chown(name, luid, lgid);
                (void) chmod(name, mode);
+               extractattr(name);
+               utimes(name, timep);
                if (flags)
 #ifdef __linux__
                        {
@@ -963,11 +1002,8 @@ extractfile(struct entry *ep, int doremove)
                        }
 #endif
 #endif
-               skipfile();
-               extractattr(name);
-               utimes(name, timep);
                return (GOOD);
-
+       }
        case IFREG:
        {
                uid_t luid = curfile.dip->di_uid;
@@ -994,6 +1030,8 @@ extractfile(struct entry *ep, int doremove)
                        skipfile();
                (void) chown(name, luid, lgid);
                (void) chmod(name, mode);
+               extractattr(name);
+               utimes(name, timep);
                if (flags)
 #ifdef __linux__
                        (void) lsetflags(name, flags);
@@ -1007,8 +1045,6 @@ extractfile(struct entry *ep, int doremove)
                        (void) chflags(name, flags);
 #endif
 #endif
-               extractattr(name);
-               utimes(name, timep);
                return (GOOD);
        }
        }
@@ -1216,8 +1252,8 @@ extractresourceufs(char *name)
                (void) fchown(ofile, uid, gid);
                (void) fchmod(ofile, mode);
                (void) close(ofile);
-               (void) lsetflags(oFileRsrc, flags);
                utimes(oFileRsrc, timep);
+               (void) lsetflags(oFileRsrc, flags);
                return (GOOD);
        }
        /* NOTREACHED */
@@ -1236,12 +1272,20 @@ readxattr(char *buffer)
                skipfile();
                return (FAIL);
        }
-       
+
        memset(xattrbuf, 0, XATTR_MAXSIZE);
        xattrlen = 0;
 
+       /*
+        * ugly hack: cope with invalid spcl.c_addr[] records written by
+        * old versions of dump.
+        */
+       readmapflag = 1;
+
        getfile(xtrxattr, xtrnull);
 
+       readmapflag = 0;
+
        memcpy(buffer, xattrbuf, XATTR_MAXSIZE);
 
        return (GOOD);
@@ -1333,7 +1377,11 @@ loop:
                        break;
                }
        }
-       if (gethead(&spcl) == GOOD && size > 0) {
+       while (gethead(&spcl) != GOOD) {
+               fprintf(stderr, "Incorrect block for %s at %ld blocks\n",
+                       curfile.name, (long)blksread);
+       }
+       if (size > 0) {
                if (spcl.c_type == TS_ADDR)
                        goto loop;
                Dprintf(stdout,