BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / restore / utilities.c
index a9145c3..29ac8bd 100644 (file)
@@ -1,18 +1,45 @@
 /*
 /*
- * Copyright (c) 1983 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)utilities.c        8.5 (Berkeley) 4/28/95";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #include <ufs/ufs/dinode.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #include <ufs/ufs/dinode.h>
+#include <ufs/ufs/dir.h>
 
 #include <errno.h>
 #include <stdio.h>
 
 #include <errno.h>
 #include <stdio.h>
@@ -34,7 +61,7 @@ pathcheck(name)
        struct entry *ep;
        char *start;
 
        struct entry *ep;
        char *start;
 
-       start = index(name, '/');
+       start = strchr(name, '/');
        if (start == 0)
                return;
        for (cp = start; *cp != '\0'; cp++) {
        if (start == 0)
                return;
        for (cp = start; *cp != '\0'; cp++) {
@@ -43,7 +70,8 @@ pathcheck(name)
                *cp = '\0';
                ep = lookupname(name);
                if (ep == NULL) {
                *cp = '\0';
                ep = lookupname(name);
                if (ep == NULL) {
-                       ep = addentry(name, pathsearch(name), NODE);
+                       /* Safe; we know the pathname exists in the dump. */
+                       ep = addentry(name, pathsearch(name)->d_ino, NODE);
                        newnode(ep);
                }
                ep->e_flags |= NEW|KEEP;
                        newnode(ep);
                }
                ep->e_flags |= NEW|KEEP;
@@ -201,6 +229,45 @@ linkit(existing, new, type)
        return (GOOD);
 }
 
        return (GOOD);
 }
 
+/*
+ * Create a whiteout.
+ */
+int
+addwhiteout(name)
+       char *name;
+{
+
+       if (!Nflag && mknod(name, S_IFWHT, 0) < 0) {
+               fprintf(stderr, "warning: cannot create whiteout %s: %s\n",
+                   name, strerror(errno));
+               return (FAIL);
+       }
+       vprintf(stdout, "Create whiteout %s\n", name);
+       return (GOOD);
+}
+
+/*
+ * Delete a whiteout.
+ */
+void
+delwhiteout(ep)
+       register struct entry *ep;
+{
+       char *name;
+
+       if (ep->e_type != LEAF)
+               badentry(ep, "delwhiteout: not a leaf");
+       ep->e_flags |= REMOVED;
+       ep->e_flags &= ~TMPNAME;
+       name = myname(ep);
+       if (!Nflag && undelete(name) < 0) {
+               fprintf(stderr, "warning: cannot delete whiteout %s: %s\n",
+                   name, strerror(errno));
+               return;
+       }
+       vprintf(stdout, "Delete whiteout %s\n", name);
+}
+
 /*
  * find lowest number file (above "start") that needs to be extracted
  */
 /*
  * find lowest number file (above "start") that needs to be extracted
  */
@@ -297,13 +364,15 @@ flagvalues(ep)
  */
 ino_t
 dirlookup(name)
  */
 ino_t
 dirlookup(name)
-       char *name;
+       const char *name;
 {
 {
+       struct direct *dp;
        ino_t ino;
        ino_t ino;
+       ino = ((dp = pathsearch(name)) == NULL) ? 0 : dp->d_ino;
 
 
-       ino = pathsearch(name);
        if (ino == 0 || TSTINO(ino, dumpmap) == 0)
        if (ino == 0 || TSTINO(ino, dumpmap) == 0)
-               fprintf(stderr, "%s is not on tape\n", name);
+               fprintf(stderr, "%s is not on the tape\n", name);
        return (ino);
 }
 
        return (ino);
 }