+Changes between versions 0.4b5 and 0.4b6
+========================================
+
+1. Integrated multiple patches from RedHat, Debian and SuSE:
+
+ - tweak dump/itime.c to not try to read dumpdates if the 'u' option
+ isn't specified.
+ - several fixes in the man pages.
+ - update the default tape device to /dev/st0.
+ - many updates for Linux Alpha (byte ordering, size_t etc).
+ - buffer overruns.
+ - use environment variable for TMPDIR (instead of /tmp).
+ - use sigjmp_buf instead of jmp_buf (RedHat bug #3260).
+ - workaround egcs bug (RedHat bugs #4281 and #2989).
+ - wire $(OPT) throughout Makefile's.
+
+2. Fix some compile warnings, prototype all functions.
+
+3. Use glibc err/glob instead of internal compatibility
+ routines (only if available).
+
Changes between versions 0.4b4 and 0.4b5
========================================
#
# Global include directories
#
-GINC= -I/usr/include/bsd -I$(top_builddir) -I$(top_srcdir)/compat/include
+GINC= -I$(top_builddir) -I$(top_srcdir)/compat/include
# indicate where the ext2fs library can be found (this is not needed if you
# have run `make install-libs' in the e2fsprogs source directory).
#GINC+= -I/usr/src/e2fsprogs-0.5c/lib
# indicate where the ext2fs library can be found (this is not needed if you
# have run `make install-libs' in the e2fsprogs source directory).
#GLIBDIR= -L/usr/src/e2fsprogs-0.5c/lib
-GLIBS= -lbsd $(GLIBDIR) -L../compat/lib -lcompat -lext2fs -lcom_err
+GLIBS= $(GLIBDIR) -L../compat/lib -lcompat -lext2fs -lcom_err
#
# Definitions (don't change them unless you know what you are doing)
suggested various improvements.
Here is a partial list of them (if I have forgotten someone, please complain):
+Bdale Garbee ndale@gag.com
Henry Katz hkatz@hkatz.dialup.access.net
Klaus Kudielka kkudielk@cacofonix.nt.tuwien.ac.at
Florian La Roche florian@jurix.jura.uni-sb.de
@MCONFIG@
INC= -I$(top_srcdir)/dump
-CFLAGS= @CCOPTS@ -pipe $(GINC) $(INC) $(DEFS)
+CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS)
SRCS= dumprmt.c
OBJS= dumprmt.o
static char sccsid[] = "@(#)dumprmt.c 8.3 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: dumprmt.c,v 1.2 1999/10/11 12:53:20 stelian Exp $";
+ "$Id: dumprmt.c,v 1.3 1999/10/11 12:59:16 stelian Exp $";
#endif /* not lint */
#ifdef __linux__
#include <protocols/dumprestore.h>
#include <ctype.h>
+#include <errno.h>
+#include <compaterr.h>
#include <netdb.h>
#include <pwd.h>
#include <stdio.h>
#define TS_OPEN 1
static int rmtstate = TS_CLOSED;
-static int rmtape;
-static char *rmtpeer;
+static int rmtape = -1;
+static const char *rmtpeer = 0;
-static int okname __P((char *));
-static int rmtcall __P((char *, char *));
-static void rmtconnaborted __P((/* int, int */));
+static int okname __P((const char *));
+static int rmtcall __P((const char *, const char *));
+static void rmtconnaborted __P((int));
static int rmtgetb __P((void));
static void rmtgetconn __P((void));
-static void rmtgets __P((char *, int));
-static int rmtreply __P((char *));
+static void rmtgets __P((char *, size_t));
+static int rmtreply __P((const char *));
#ifdef KERBEROS
int krcmd __P((char **, int /*u_short*/, char *, char *, int *, char *));
#endif
static int errfd = -1;
extern int dokerberos;
extern int ntrec; /* blocking factor on tape */
+#ifndef errno
+extern int errno;
+#endif
int
-rmthost(host)
- char *host;
+rmthost(const char *host)
{
-
- rmtpeer = malloc(strlen(host) + 1);
if (rmtpeer)
- strcpy(rmtpeer, host);
- else
+ free((void *)rmtpeer);
+ if ((rmtpeer = strdup(host)) == NULL)
rmtpeer = host;
signal(SIGPIPE, rmtconnaborted);
rmtgetconn();
}
static void
-rmtconnaborted()
+rmtconnaborted(int signo)
{
msg("Lost connection to remote host.\n");
if (errfd != -1) {
exit(X_ABORT);
}
-void
-rmtgetconn()
+static void
+rmtgetconn(void)
{
register char *cp;
register const char *rmt;
static struct servent *sp = NULL;
static struct passwd *pwd = NULL;
- char *tuser;
+ const char *tuser;
int size;
int throughput;
int on;
if (sp == NULL) {
sp = getservbyname(dokerberos ? "kshell" : "shell", "tcp");
- if (sp == NULL) {
- msg("%s/tcp: unknown service\n",
+ if (sp == NULL)
+ errx(1, "%s/tcp: unknown service",
dokerberos ? "kshell" : "shell");
- exit(X_STARTUP);
- }
pwd = getpwuid(getuid());
- if (pwd == NULL) {
- msg("who are you?\n");
- exit(X_STARTUP);
- }
+ if (pwd == NULL)
+ errx(1, "who are you?");
}
if ((cp = strchr(rmtpeer, '@')) != NULL) {
tuser = rmtpeer;
msg("");
#ifdef KERBEROS
if (dokerberos)
- rmtape = krcmd(&rmtpeer, sp->s_port, tuser, rmt, &errfd,
+ rmtape = krcmd((char **)&rmtpeer, sp->s_port, tuser, rmt, &errfd,
(char *)0);
else
#endif
- rmtape = rcmd(&rmtpeer, (u_short)sp->s_port, pwd->pw_name,
+ rmtape = rcmd((char **)&rmtpeer, (u_short)sp->s_port, pwd->pw_name,
tuser, rmt, &errfd);
if (rmtape < 0) {
msg("login to %s as %s failed.\n", rmtpeer, tuser);
}
static int
-okname(cp0)
- char *cp0;
+okname(const char *cp0)
{
- register char *cp;
+ register const char *cp;
register int c;
for (cp = cp0; *cp; cp++) {
c = *cp;
if (!isascii(c) || !(isalnum(c) || c == '_' || c == '-')) {
- msg("invalid user name %s\n", cp0);
+ warnx("invalid user name %s\n", cp0);
return (0);
}
}
}
int
-rmtopen(tape, mode)
- char *tape;
- int mode;
+rmtopen(const char *tape, int mode)
{
- char buf[256];
+ char buf[MAXPATHLEN];
- (void)snprintf(buf, sizeof (buf), "O%.226s\n%d\n", tape, mode);
+ (void)snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode);
rmtstate = TS_OPEN;
return (rmtcall(tape, buf));
}
void
-rmtclose()
+rmtclose(void)
{
if (rmtstate != TS_OPEN)
}
int
-rmtread(buf, count)
- char *buf;
- int count;
+rmtread(char *buf, size_t count)
{
char line[30];
- int n, i, cc;
+ int n, i;
+ ssize_t cc;
- (void)snprintf(line, sizeof (line), "R%d\n", count);
+ (void)snprintf(line, sizeof (line), "R%u\n", (unsigned)count);
n = rmtcall("read", line);
if (n < 0)
/* rmtcall() properly sets errno for us on errors. */
for (i = 0; i < n; i += cc) {
cc = read(rmtape, buf+i, n - i);
if (cc <= 0)
- rmtconnaborted();
+ rmtconnaborted(0);
}
return (n);
}
int
-rmtwrite(buf, count)
- char *buf;
- int count;
+rmtwrite(const char *buf, size_t count)
{
char line[30];
return (rmtreply("write"));
}
-void
-rmtwrite0(count)
- int count;
-{
- char line[30];
-
- (void)snprintf(line, sizeof (line), "W%d\n", count);
- write(rmtape, line, strlen(line));
-}
-
-void
-rmtwrite1(buf, count)
- char *buf;
- int count;
-{
-
- write(rmtape, buf, count);
-}
-
int
-rmtwrite2()
-{
-
- return (rmtreply("write"));
-}
-
-int
-rmtseek(offset, pos)
- int offset, pos;
+rmtseek(int offset, int pos)
{
char line[80];
struct mtget mts;
struct mtget *
-rmtstatus()
+rmtstatus(void)
{
register int i;
register char *cp;
}
int
-rmtioctl(cmd, count)
- int cmd, count;
+rmtioctl(int cmd, int count)
{
char buf[256];
}
static int
-rmtcall(cmd, buf)
- char *cmd, *buf;
+rmtcall(const char *cmd, const char *buf)
{
if (write(rmtape, buf, strlen(buf)) != strlen(buf))
- rmtconnaborted();
+ rmtconnaborted(0);
return (rmtreply(cmd));
}
static int
-rmtreply(cmd)
- char *cmd;
+rmtreply(const char *cmd)
{
register char *cp;
char code[30], emsg[BUFSIZ];
- extern int errno;
rmtgets(code, sizeof (code));
if (*code == 'E' || *code == 'F') {
msg("Protocol to remote tape server botched (code \"%s\").\n",
code);
- rmtconnaborted();
+ rmtconnaborted(0);
}
return (atoi(code + 1));
}
-int
-rmtgetb()
+static int
+rmtgetb(void)
{
char c;
if (read(rmtape, &c, 1) != 1)
- rmtconnaborted();
+ rmtconnaborted(0);
return (c);
}
/* Get a line (guaranteed to have a trailing newline). */
-void
-rmtgets(line, len)
- char *line;
- int len;
+static void
+rmtgets(char *line, size_t len)
{
register char *cp = line;
*cp = '\0';
msg("Protocol to remote tape server botched.\n");
msg("(rmtgets got \"%s\").\n", line);
- rmtconnaborted();
+ rmtconnaborted(0);
}
__u32 di_spare[4];
};
+struct bsdtimeval { /* XXX alpha-*-linux is deviant */
+ __u32 tv_sec;
+ __u32 tv_usec;
+};
+
/*
* This is the new (4.4) BSD inode structure
* copied from the FreeBSD 2.0 <ufs/ufs/dinode.h> include file
__u32 inumber;
} di_u;
u_quad_t di_size;
- struct timeval di_atime;
- struct timeval di_mtime;
- struct timeval di_ctime;
+ struct bsdtimeval di_atime;
+ struct bsdtimeval di_mtime;
+ struct bsdtimeval di_ctime;
daddr_t di_db[NDADDR];
daddr_t di_ib[NIADDR];
__u32 di_flags;
--- /dev/null
+/*
+ * 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
+ *
+ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * @(#)err.h 8.1 (Berkeley) 6/2/93
+ * $Id: compaterr.h,v 1.1 1999/10/11 12:59:17 stelian Exp $
+ */
+
+#ifndef _ERR_H_
+#define _ERR_H_
+
+#include <config.h>
+
+#if defined(HAVE_ERR) || defined(HAVE_ERRX) || defined(HAVE_VERR) || defined(HAVE_VERRX) || defined(HAVE_VWARN) || defined(HAVE_VWARNX) || defined(HAVE_WARN) || defined(HAVE_WARNX)
+#include <err.h>
+#endif
+
+#include <sys/cdefs.h>
+
+#include <stdarg.h>
+
+#ifndef _BSD_VA_LIST_
+#define _BSD_VA_LIST_ va_list
+#endif
+
+#ifndef __dead
+#define __dead volatile
+#endif
+
+__BEGIN_DECLS
+#ifndef HAVE_ERR
+__dead void err __P((int, const char *, ...));
+#endif
+#ifndef HAVE_VERR
+__dead void verr __P((int, const char *, _BSD_VA_LIST_));
+#endif
+#ifndef HAVE_ERRX
+__dead void errx __P((int, const char *, ...));
+#endif
+#ifndef HAVE_VERRX
+__dead void verrx __P((int, const char *, _BSD_VA_LIST_));
+#endif
+#ifndef HAVE_WARN
+void warn __P((const char *, ...));
+#endif
+#ifndef HAVE_VWARN
+void vwarn __P((const char *, _BSD_VA_LIST_));
+#endif
+#ifndef HAVE_WARNX
+void warnx __P((const char *, ...));
+#endif
+#ifndef HAVE_VWARNX
+void vwarnx __P((const char *, _BSD_VA_LIST_));
+#endif
+__END_DECLS
+
+#endif /* !_ERR_H_ */
--- /dev/null
+/*
+ * 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
+ *
+ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guido van Rossum.
+ *
+ * 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.
+ *
+ * @(#)glob.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _GLOB_H_
+#define _GLOB_H_
+
+#include <config.h>
+
+#ifdef HAVE_GLOB
+#include <glob.h>
+#else
+
+#include <sys/cdefs.h>
+
+struct stat;
+typedef struct {
+ int gl_pathc; /* Count of total paths so far. */
+ int gl_matchc; /* Count of paths matching pattern. */
+ int gl_offs; /* Reserved at beginning of gl_pathv. */
+ int gl_flags; /* Copy of flags parameter to glob. */
+ char **gl_pathv; /* List of paths matching pattern. */
+ /* Copy of errfunc parameter to glob. */
+ int (*gl_errfunc) __P((const char *, int));
+
+ /*
+ * Alternate filesystem access methods for glob; replacement
+ * versions of closedir(3), readdir(3), opendir(3), stat(2)
+ * and lstat(2).
+ */
+ void (*gl_closedir) __P((void *));
+ struct dirent *(*gl_readdir) __P((void *));
+ void *(*gl_opendir) __P((const char *));
+ int (*gl_lstat) __P((const char *, struct stat *));
+ int (*gl_stat) __P((const char *, struct stat *));
+} glob_t;
+
+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
+#define GLOB_ERR 0x0004 /* Return on error. */
+#define GLOB_MARK 0x0008 /* Append / to matching directories. */
+#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
+#define GLOB_NOSORT 0x0020 /* Don't sort. */
+
+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
+#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
+#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
+#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
+#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
+
+#define GLOB_NOSPACE (-1) /* Malloc call failed. */
+#define GLOB_ABEND (-2) /* Unignored error. */
+
+__BEGIN_DECLS
+int glob __P((const char *, int, int (*)(const char *, int), glob_t *));
+void globfree __P((glob_t *));
+__END_DECLS
+
+#endif /* !_GLOB_H_ */
+
+#endif /* HAVE_GLOB */
+++ /dev/null
-/*
- * 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
- *
- */
-
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- *
- * @(#)err.h 8.1 (Berkeley) 6/2/93
- * $Id: err.h,v 1.2 1999/10/11 12:53:20 stelian Exp $
- */
-
-#ifndef _ERR_H_
-#define _ERR_H_
-
-#include <sys/cdefs.h>
-
-#include <stdarg.h>
-
-#ifndef _BSD_VA_LIST_
-#define _BSD_VA_LIST_ va_list
-#endif
-
-#ifndef __dead
-#define __dead volatile
-#endif
-
-__BEGIN_DECLS
-__dead void err __P((int, const char *, ...));
-__dead void verr __P((int, const char *, _BSD_VA_LIST_));
-__dead void errc __P((int, int, const char *, ...));
-__dead void verrc __P((int, int, const char *, _BSD_VA_LIST_));
-__dead void errx __P((int, const char *, ...));
-__dead void verrx __P((int, const char *, _BSD_VA_LIST_));
-void warn __P((const char *, ...));
-void vwarn __P((const char *, _BSD_VA_LIST_));
-void warnc __P((int, const char *, ...));
-void vwarnc __P((int, const char *, _BSD_VA_LIST_));
-void warnx __P((const char *, ...));
-void vwarnx __P((const char *, _BSD_VA_LIST_));
-void err_set_file __P((void *));
-void err_set_exit __P((void (*)(int)));
-__END_DECLS
-
-#endif /* !_ERR_H_ */
+++ /dev/null
-/*
- * 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
- *
- */
-
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Guido van Rossum.
- *
- * 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.
- *
- * @(#)glob.h 8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _GLOB_H_
-#define _GLOB_H_
-
-#include <sys/cdefs.h>
-
-struct stat;
-typedef struct {
- int gl_pathc; /* Count of total paths so far. */
- int gl_matchc; /* Count of paths matching pattern. */
- int gl_offs; /* Reserved at beginning of gl_pathv. */
- int gl_flags; /* Copy of flags parameter to glob. */
- char **gl_pathv; /* List of paths matching pattern. */
- /* Copy of errfunc parameter to glob. */
- int (*gl_errfunc) __P((const char *, int));
-
- /*
- * Alternate filesystem access methods for glob; replacement
- * versions of closedir(3), readdir(3), opendir(3), stat(2)
- * and lstat(2).
- */
- void (*gl_closedir) __P((void *));
- struct dirent *(*gl_readdir) __P((void *));
- void *(*gl_opendir) __P((const char *));
- int (*gl_lstat) __P((const char *, struct stat *));
- int (*gl_stat) __P((const char *, struct stat *));
-} glob_t;
-
-#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
-#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
-#define GLOB_ERR 0x0004 /* Return on error. */
-#define GLOB_MARK 0x0008 /* Append / to matching directories. */
-#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
-#define GLOB_NOSORT 0x0020 /* Don't sort. */
-
-#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
-#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
-#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
-#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
-#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
-#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
-
-#define GLOB_NOSPACE (-1) /* Malloc call failed. */
-#define GLOB_ABEND (-2) /* Unignored error. */
-
-__BEGIN_DECLS
-int glob __P((const char *, int, int (*)(const char *, int), glob_t *));
-void globfree __P((glob_t *));
-__END_DECLS
-
-#endif /* !_GLOB_H_ */
#include <paths.h>
-#define _PATH_DEFTAPE "/dev/rmt8"
+#define _PATH_DEFTAPE "/dev/st0"
#define _PATH_DTMP "/etc/dtmp"
#define _PATH_DUMPDATES "/etc/dumpdates"
#define _PATH_LOCK "/tmp/dumplockXXXXXX"
@MCONFIG@
INC= -I$(top_srcdir)/compat/include
-CFLAGS= @CCOPTS@ -pipe $(GINC) $(INC) $(DEFS)
-SRCS= err.c fstab.c glob.c
-OBJS= err.o fstab.o glob.o
+CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS)
+SRCS= compaterr.c fstab.c compatglob.c
+OBJS= compaterr.o fstab.o compatglob.o
LIB= libcompat.a
all:: $(LIB)
--- /dev/null
+/*
+ * 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
+ *
+ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * From: @(#)err.c 8.1 (Berkeley) 6/4/93
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] =
+ "$Id: compaterr.c,v 1.1 1999/10/11 12:59:17 stelian Exp $";
+#endif /* LIBC_RCS and not lint */
+
+#include <compaterr.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <stdarg.h>
+
+#include <config.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+#if !defined(HAVE_ERR) || !defined(HAVE_ERRX) || !defined(HAVE_VERR) || !defined(HAVE_VERRX) || !defined(HAVE_VWARN) || !defined(HAVE_VWARNX) || !defined(HAVE_WARN) || !defined(HAVE_WARNX)
+
+__BEGIN_DECLS
+__dead void errc __P((int, int, const char *, ...));
+__dead void verrc __P((int, int, const char *, _BSD_VA_LIST_));
+void warnc __P((int, const char *, ...));
+void vwarnc __P((int, const char *, _BSD_VA_LIST_));
+void err_set_file __P((void *));
+void err_set_exit __P((void (*)(int)));
+__END_DECLS
+
+static void (*err_exit)(int);
+
+static FILE *err_file; /* file to use for error output */
+/*
+ * This is declared to take a `void *' so that the caller is not required
+ * to include <stdio.h> first. However, it is really a `FILE *', and the
+ * manual page documents it as such.
+ */
+void
+err_set_file(void *fp)
+{
+ if (fp)
+ err_file = fp;
+ else
+ err_file = stderr;
+}
+
+void
+err_set_exit(void (*ef)(int))
+{
+ err_exit = ef;
+}
+
+__dead void
+errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrc(eval, code, fmt, ap);
+ va_end(ap);
+}
+
+__dead void
+verrc(int eval, int code, const char *fmt, va_list ap)
+{
+ if (err_file == 0)
+ err_set_file((FILE *)0);
+ fprintf(err_file, "%s: ", __progname);
+ if (fmt != NULL) {
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, ": ");
+ }
+ fprintf(err_file, "%s\n", strerror(code));
+ if (err_exit)
+ err_exit(eval);
+ exit(eval);
+}
+
+void
+warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+
+void
+vwarnc(int code, const char *fmt, va_list ap)
+{
+ if (err_file == 0)
+ err_set_file((FILE *)0);
+ fprintf(err_file, "%s: ", __progname);
+ if (fmt != NULL) {
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, ": ");
+ }
+ fprintf(err_file, "%s\n", strerror(code));
+}
+#endif
+
+#ifndef HAVE_ERR
+__dead void
+err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrc(eval, errno, fmt, ap);
+ va_end(ap);
+}
+#endif
+
+#ifndef HAVE_VERR
+__dead void
+verr(int eval, const char *fmt, va_list ap)
+{
+ verrc(eval, errno, fmt, ap);
+}
+#endif
+
+#ifndef HAVE_ERRX
+__dead void
+errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrx(eval, fmt, ap);
+ va_end(ap);
+}
+#endif
+
+#ifndef HAVE_VERRX
+__dead void
+verrx(int eval, const char *fmt, va_list ap)
+{
+ if (err_file == 0)
+ err_set_file((FILE *)0);
+ fprintf(err_file, "%s: ", __progname);
+ if (fmt != NULL)
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, "\n");
+ if (err_exit)
+ err_exit(eval);
+ exit(eval);
+}
+#endif
+
+#ifndef HAVE_WARN
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnc(errno, fmt, ap);
+ va_end(ap);
+}
+#endif
+
+#ifndef HAVE_VWARN
+void
+vwarn(const char *fmt, va_list ap)
+{
+ vwarnc(errno, fmt, ap);
+}
+#endif
+
+#ifndef HAVE_WARNX
+void
+warnx(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+}
+#endif
+
+#ifndef HAVE_VWARNX
+void
+vwarnx(const char *fmt, va_list ap)
+{
+ if (err_file == 0)
+ err_set_file((FILE *)0);
+ fprintf(err_file, "%s: ", __progname);
+ if (fmt != NULL)
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, "\n");
+}
+#endif
--- /dev/null
+/*
+ * 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
+ *
+ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guido van Rossum.
+ *
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * glob(3) -- a superset of the one defined in POSIX 1003.2.
+ *
+ * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
+ *
+ * Optional extra services, controlled by flags not defined by POSIX:
+ *
+ * GLOB_QUOTE:
+ * Escaping convention: \ inhibits any special meaning the following
+ * character might have (except \ at end of string is retained).
+ * GLOB_MAGCHAR:
+ * Set in gl_flags if pattern contained a globbing character.
+ * GLOB_NOMAGIC:
+ * Same as GLOB_NOCHECK, but it will only append pattern if it did
+ * not contain any magic characters. [Used in csh style globbing]
+ * GLOB_ALTDIRFUNC:
+ * Use alternately specified directory access functions.
+ * GLOB_TILDE:
+ * expand ~user/foo to the /home/dir/of/user/foo
+ * GLOB_BRACE:
+ * expand {1,2}{a,b} to 1a 1b 2a 2b
+ * gl_matchc:
+ * Number of matches in the current invocation of glob.
+ */
+
+#include <config.h>
+
+#ifndef HAVE_GLOB
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <compatglob.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DOLLAR '$'
+#define DOT '.'
+#define EOS '\0'
+#define LBRACKET '['
+#define NOT '!'
+#define QUESTION '?'
+#define QUOTE '\\'
+#define RANGE '-'
+#define RBRACKET ']'
+#define SEP '/'
+#define STAR '*'
+#define TILDE '~'
+#define UNDERSCORE '_'
+#define LBRACE '{'
+#define RBRACE '}'
+#define SLASH '/'
+#define COMMA ','
+
+#ifndef DEBUG
+
+#define M_QUOTE 0x8000
+#define M_PROTECT 0x4000
+#define M_MASK 0xffff
+#define M_ASCII 0x00ff
+
+typedef u_short Char;
+
+#else
+
+#define M_QUOTE 0x80
+#define M_PROTECT 0x40
+#define M_MASK 0xff
+#define M_ASCII 0x7f
+
+typedef char Char;
+
+#endif
+
+
+#define CHAR(c) ((Char)((c)&M_ASCII))
+#define META(c) ((Char)((c)|M_QUOTE))
+#define M_ALL META('*')
+#define M_END META(']')
+#define M_NOT META('!')
+#define M_ONE META('?')
+#define M_RNG META('-')
+#define M_SET META('[')
+#define ismeta(c) (((c)&M_QUOTE) != 0)
+
+
+static int compare __P((const void *, const void *));
+static void g_Ctoc __P((const Char *, char *));
+static int g_lstat __P((Char *, struct stat *, glob_t *));
+static DIR *g_opendir __P((Char *, glob_t *));
+static Char *g_strchr __P((Char *, int));
+#ifdef notdef
+static Char *g_strcat __P((Char *, const Char *));
+#endif
+static int g_stat __P((Char *, struct stat *, glob_t *));
+static int glob0 __P((const Char *, glob_t *));
+static int glob1 __P((Char *, glob_t *));
+static int glob2 __P((Char *, Char *, Char *, glob_t *));
+static int glob3 __P((Char *, Char *, Char *, Char *, glob_t *));
+static int globextend __P((const Char *, glob_t *));
+static const Char * globtilde __P((const Char *, Char *, size_t, glob_t *));
+static int globexp1 __P((const Char *, glob_t *));
+static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
+static int match __P((Char *, Char *, Char *));
+#ifdef DEBUG
+static void qprintf __P((const char *, Char *));
+#endif
+
+int
+glob(const char *pattern, int flags, int (*errfunc) __P((const char *, int)), glob_t *pglob)
+{
+ const u_char *patnext;
+ int c;
+ Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
+
+ patnext = (u_char *) pattern;
+ if (!(flags & GLOB_APPEND)) {
+ pglob->gl_pathc = 0;
+ pglob->gl_pathv = NULL;
+ if (!(flags & GLOB_DOOFFS))
+ pglob->gl_offs = 0;
+ }
+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
+ pglob->gl_errfunc = errfunc;
+ pglob->gl_matchc = 0;
+
+ bufnext = patbuf;
+ bufend = bufnext + MAXPATHLEN;
+ if (flags & GLOB_QUOTE) {
+ /* Protect the quoted characters. */
+ while (bufnext < bufend && (c = *patnext++) != EOS)
+ if (c == QUOTE) {
+ if ((c = *patnext++) == EOS) {
+ c = QUOTE;
+ --patnext;
+ }
+ *bufnext++ = c | M_PROTECT;
+ }
+ else
+ *bufnext++ = c;
+ }
+ else
+ while (bufnext < bufend && (c = *patnext++) != EOS)
+ *bufnext++ = c;
+ *bufnext = EOS;
+
+ if (flags & GLOB_BRACE)
+ return globexp1(patbuf, pglob);
+ else
+ return glob0(patbuf, pglob);
+}
+
+/*
+ * Expand recursively a glob {} pattern. When there is no more expansion
+ * invoke the standard globbing routine to glob the rest of the magic
+ * characters
+ */
+static int globexp1(const Char *pattern, glob_t *pglob)
+{
+ const Char* ptr = pattern;
+ int rv;
+
+ /* Protect a single {}, for find(1), like csh */
+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
+ return glob0(pattern, pglob);
+
+ while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
+ if (!globexp2(ptr, pattern, pglob, &rv))
+ return rv;
+
+ return glob0(pattern, pglob);
+}
+
+
+/*
+ * Recursive brace globbing helper. Tries to expand a single brace.
+ * If it succeeds then it invokes globexp1 with the new pattern.
+ * If it fails then it tries to glob the rest of the pattern and returns.
+ */
+static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
+{
+ int i;
+ Char *lm, *ls;
+ const Char *pe, *pm, *pl;
+ Char patbuf[MAXPATHLEN + 1];
+
+ /* copy part up to the brace */
+ for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
+ continue;
+ ls = lm;
+
+ /* Find the balanced brace */
+ for (i = 0, pe = ++ptr; *pe; pe++)
+ if (*pe == LBRACKET) {
+ /* Ignore everything between [] */
+ for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
+ continue;
+ if (*pe == EOS) {
+ /*
+ * We could not find a matching RBRACKET.
+ * Ignore and just look for RBRACE
+ */
+ pe = pm;
+ }
+ }
+ else if (*pe == LBRACE)
+ i++;
+ else if (*pe == RBRACE) {
+ if (i == 0)
+ break;
+ i--;
+ }
+
+ /* Non matching braces; just glob the pattern */
+ if (i != 0 || *pe == EOS) {
+ *rv = glob0(patbuf, pglob);
+ return 0;
+ }
+
+ for (i = 0, pl = pm = ptr; pm <= pe; pm++)
+ switch (*pm) {
+ case LBRACKET:
+ /* Ignore everything between [] */
+ for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
+ continue;
+ if (*pm == EOS) {
+ /*
+ * We could not find a matching RBRACKET.
+ * Ignore and just look for RBRACE
+ */
+ pm = pl;
+ }
+ break;
+
+ case LBRACE:
+ i++;
+ break;
+
+ case RBRACE:
+ if (i) {
+ i--;
+ break;
+ }
+ /* FALLTHROUGH */
+ case COMMA:
+ if (i && *pm == COMMA)
+ break;
+ else {
+ /* Append the current string */
+ for (lm = ls; (pl < pm); *lm++ = *pl++)
+ continue;
+ /*
+ * Append the rest of the pattern after the
+ * closing brace
+ */
+ for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
+ continue;
+
+ /* Expand the current pattern */
+#ifdef DEBUG
+ qprintf("globexp2:", patbuf);
+#endif
+ *rv = globexp1(patbuf, pglob);
+
+ /* move after the comma, to the next string */
+ pl = pm + 1;
+ }
+ break;
+
+ default:
+ break;
+ }
+ *rv = 0;
+ return 0;
+}
+
+
+
+/*
+ * expand tilde from the passwd file.
+ */
+static const Char *
+globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
+{
+ struct passwd *pwd;
+ char *h;
+ const Char *p;
+ Char *b, *eb;
+
+ if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
+ return pattern;
+
+ /*
+ * Copy up to the end of the string or /
+ */
+ eb = &patbuf[patbuf_len - 1];
+ for (p = pattern + 1, h = (char *) patbuf;
+ h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
+ continue;
+
+ *h = EOS;
+
+ if (((char *) patbuf)[0] == EOS) {
+ /*
+ * handle a plain ~ or ~/ by expanding $HOME first if
+ * we're not running setuid or setgid) and then trying
+ * the password file
+ */
+ if (
+#ifndef __linux__
+#ifndef __NETBSD_SYSCALLS
+ issetugid() != 0 ||
+#endif
+#endif
+ (h = getenv("HOME")) == NULL) {
+ if (((h = getlogin()) != NULL &&
+ (pwd = getpwnam(h)) != NULL) ||
+ (pwd = getpwuid(getuid())) != NULL)
+ h = pwd->pw_dir;
+ else
+ return pattern;
+ }
+ }
+ else {
+ /*
+ * Expand a ~user
+ */
+ if ((pwd = getpwnam((char*) patbuf)) == NULL)
+ return pattern;
+ else
+ h = pwd->pw_dir;
+ }
+
+ /* Copy the home directory */
+ for (b = patbuf; b < eb && *h; *b++ = *h++)
+ continue;
+
+ /* Append the rest of the pattern */
+ while (b < eb && (*b++ = *p++) != EOS)
+ continue;
+ *b = EOS;
+
+ return patbuf;
+}
+
+
+/*
+ * The main glob() routine: compiles the pattern (optionally processing
+ * quotes), calls glob1() to do the real pattern matching, and finally
+ * sorts the list (unless unsorted operation is requested). Returns 0
+ * if things went well, nonzero if errors occurred. It is not an error
+ * to find no matches.
+ */
+static int
+glob0(const Char *pattern, glob_t *pglob)
+{
+ const Char *qpatnext;
+ int c, err, oldpathc;
+ Char *bufnext, patbuf[MAXPATHLEN+1];
+
+ qpatnext = globtilde(pattern, patbuf, sizeof(patbuf) / sizeof(Char),
+ pglob);
+ oldpathc = pglob->gl_pathc;
+ bufnext = patbuf;
+
+ /* We don't need to check for buffer overflow any more. */
+ while ((c = *qpatnext++) != EOS) {
+ switch (c) {
+ case LBRACKET:
+ c = *qpatnext;
+ if (c == NOT)
+ ++qpatnext;
+ if (*qpatnext == EOS ||
+ g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
+ *bufnext++ = LBRACKET;
+ if (c == NOT)
+ --qpatnext;
+ break;
+ }
+ *bufnext++ = M_SET;
+ if (c == NOT)
+ *bufnext++ = M_NOT;
+ c = *qpatnext++;
+ do {
+ *bufnext++ = CHAR(c);
+ if (*qpatnext == RANGE &&
+ (c = qpatnext[1]) != RBRACKET) {
+ *bufnext++ = M_RNG;
+ *bufnext++ = CHAR(c);
+ qpatnext += 2;
+ }
+ } while ((c = *qpatnext++) != RBRACKET);
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_END;
+ break;
+ case QUESTION:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_ONE;
+ break;
+ case STAR:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ /* collapse adjacent stars to one,
+ * to avoid exponential behavior
+ */
+ if (bufnext == patbuf || bufnext[-1] != M_ALL)
+ *bufnext++ = M_ALL;
+ break;
+ default:
+ *bufnext++ = CHAR(c);
+ break;
+ }
+ }
+ *bufnext = EOS;
+#ifdef DEBUG
+ qprintf("glob0:", patbuf);
+#endif
+
+ if ((err = glob1(patbuf, pglob)) != 0)
+ return(err);
+
+ /*
+ * If there was no match we are going to append the pattern
+ * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
+ * and the pattern did not contain any magic characters
+ * GLOB_NOMAGIC is there just for compatibility with csh.
+ */
+ if (pglob->gl_pathc == oldpathc &&
+ ((pglob->gl_flags & GLOB_NOCHECK) ||
+ ((pglob->gl_flags & GLOB_NOMAGIC) &&
+ !(pglob->gl_flags & GLOB_MAGCHAR))))
+ return(globextend(pattern, pglob));
+ else if (!(pglob->gl_flags & GLOB_NOSORT))
+ qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
+ pglob->gl_pathc - oldpathc, sizeof(char *), compare);
+ return(0);
+}
+
+static int
+compare(const void *p, const void *q)
+{
+ return(strcmp(*(char **)p, *(char **)q));
+}
+
+static int
+glob1(Char *pattern, glob_t *pglob)
+{
+ Char pathbuf[MAXPATHLEN+1];
+
+ /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
+ if (*pattern == EOS)
+ return(0);
+ return(glob2(pathbuf, pathbuf, pattern, pglob));
+}
+
+/*
+ * The functions glob2 and glob3 are mutually recursive; there is one level
+ * of recursion for each segment in the pattern that contains one or more
+ * meta characters.
+ */
+static int
+glob2(Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob)
+{
+ struct stat sb;
+ Char *p, *q;
+ int anymeta;
+
+ /*
+ * Loop over pattern segments until end of pattern or until
+ * segment with meta character found.
+ */
+ for (anymeta = 0;;) {
+ if (*pattern == EOS) { /* End of pattern? */
+ *pathend = EOS;
+ if (g_lstat(pathbuf, &sb, pglob))
+ return(0);
+
+ if (((pglob->gl_flags & GLOB_MARK) &&
+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
+ || (S_ISLNK(sb.st_mode) &&
+ (g_stat(pathbuf, &sb, pglob) == 0) &&
+ S_ISDIR(sb.st_mode)))) {
+ *pathend++ = SEP;
+ *pathend = EOS;
+ }
+ ++pglob->gl_matchc;
+ return(globextend(pathbuf, pglob));
+ }
+
+ /* Find end of next segment, copy tentatively to pathend. */
+ q = pathend;
+ p = pattern;
+ while (*p != EOS && *p != SEP) {
+ if (ismeta(*p))
+ anymeta = 1;
+ *q++ = *p++;
+ }
+
+ if (!anymeta) { /* No expansion, do next segment. */
+ pathend = q;
+ pattern = p;
+ while (*pattern == SEP)
+ *pathend++ = *pattern++;
+ } else /* Need expansion, recurse. */
+ return(glob3(pathbuf, pathend, pattern, p, pglob));
+ }
+ /* NOTREACHED */
+}
+
+static int
+glob3(Char *pathbuf, Char *pathend, Char *pattern, Char *restpattern, glob_t *pglob)
+{
+ register struct dirent *dp;
+ DIR *dirp;
+ int err;
+ char buf[MAXPATHLEN];
+
+ /*
+ * The readdirfunc declaration can't be prototyped, because it is
+ * assigned, below, to two functions which are prototyped in glob.h
+ * and dirent.h as taking pointers to differently typed opaque
+ * structures.
+ */
+ struct dirent *(*readdirfunc)();
+
+ *pathend = EOS;
+ errno = 0;
+
+ if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
+ /* TODO: don't call for ENOENT or ENOTDIR? */
+ if (pglob->gl_errfunc) {
+ g_Ctoc(pathbuf, buf);
+ if (pglob->gl_errfunc(buf, errno) ||
+ pglob->gl_flags & GLOB_ERR)
+ return (GLOB_ABEND);
+ }
+ return(0);
+ }
+
+ err = 0;
+
+ /* Search directory for matching names. */
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ readdirfunc = pglob->gl_readdir;
+ else
+ readdirfunc = readdir;
+ while ((dp = (*readdirfunc)(dirp))) {
+ register u_char *sc;
+ register Char *dc;
+
+ /* Initial DOT must be matched literally. */
+ if (dp->d_name[0] == DOT && *pattern != DOT)
+ continue;
+ for (sc = (u_char *) dp->d_name, dc = pathend;
+ (*dc++ = *sc++) != EOS;)
+ continue;
+ if (!match(pathend, pattern, restpattern)) {
+ *pathend = EOS;
+ continue;
+ }
+ err = glob2(pathbuf, --dc, restpattern, pglob);
+ if (err)
+ break;
+ }
+
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ (*pglob->gl_closedir)(dirp);
+ else
+ closedir(dirp);
+ return(err);
+}
+
+
+/*
+ * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
+ * add the new item, and update gl_pathc.
+ *
+ * This assumes the BSD realloc, which only copies the block when its size
+ * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
+ * behavior.
+ *
+ * Return 0 if new item added, error code if memory couldn't be allocated.
+ *
+ * Invariant of the glob_t structure:
+ * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
+ * gl_pathv points to (gl_offs + gl_pathc + 1) items.
+ */
+static int
+globextend(const Char *path, glob_t *pglob)
+{
+ register char **pathv;
+ register int i;
+ u_int newsize;
+ char *copy;
+ const Char *p;
+
+ newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
+ pathv = pglob->gl_pathv ?
+ realloc((char *)pglob->gl_pathv, newsize) :
+ malloc(newsize);
+ if (pathv == NULL)
+ return(GLOB_NOSPACE);
+
+ if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
+ /* first time around -- clear initial gl_offs items */
+ pathv += pglob->gl_offs;
+ for (i = pglob->gl_offs; --i >= 0; )
+ *--pathv = NULL;
+ }
+ pglob->gl_pathv = pathv;
+
+ for (p = path; *p++;)
+ continue;
+ if ((copy = malloc(p - path)) != NULL) {
+ g_Ctoc(path, copy);
+ pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
+ }
+ pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
+ return(copy == NULL ? GLOB_NOSPACE : 0);
+}
+
+/*
+ * pattern matching function for filenames. Each occurrence of the *
+ * pattern causes a recursion level.
+ */
+static int
+match(Char *name, Char *pat, Char *patend)
+{
+ int ok, negate_range;
+ Char c, k;
+
+ while (pat < patend) {
+ c = *pat++;
+ switch (c & M_MASK) {
+ case M_ALL:
+ if (pat == patend)
+ return(1);
+ do
+ if (match(name, pat, patend))
+ return(1);
+ while (*name++ != EOS);
+ return(0);
+ case M_ONE:
+ if (*name++ == EOS)
+ return(0);
+ break;
+ case M_SET:
+ ok = 0;
+ if ((k = *name++) == EOS)
+ return(0);
+ if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
+ ++pat;
+ while (((c = *pat++) & M_MASK) != M_END)
+ if ((*pat & M_MASK) == M_RNG) {
+ if (c <= k && k <= pat[1])
+ ok = 1;
+ pat += 2;
+ } else if (c == k)
+ ok = 1;
+ if (ok == negate_range)
+ return(0);
+ break;
+ default:
+ if (*name++ != c)
+ return(0);
+ break;
+ }
+ }
+ return(*name == EOS);
+}
+
+/* Free allocated data belonging to a glob_t structure. */
+void
+globfree(glob_t *pglob)
+{
+ register int i;
+ register char **pp;
+
+ if (pglob->gl_pathv != NULL) {
+ pp = pglob->gl_pathv + pglob->gl_offs;
+ for (i = pglob->gl_pathc; i--; ++pp)
+ if (*pp)
+ free(*pp);
+ free(pglob->gl_pathv);
+ }
+}
+
+static DIR *
+g_opendir(Char *str, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ if (!*str)
+ strcpy(buf, ".");
+ else
+ g_Ctoc(str, buf);
+
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return((*pglob->gl_opendir)(buf));
+
+ return(opendir(buf));
+}
+
+static int
+g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ g_Ctoc(fn, buf);
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return((*pglob->gl_lstat)(buf, sb));
+ return(lstat(buf, sb));
+}
+
+static int
+g_stat(Char *fn, struct stat *sb, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ g_Ctoc(fn, buf);
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return((*pglob->gl_stat)(buf, sb));
+ return(stat(buf, sb));
+}
+
+static Char *
+g_strchr(Char *str, int ch)
+{
+ do {
+ if (*str == ch)
+ return (str);
+ } while (*str++);
+ return (NULL);
+}
+
+#ifdef notdef
+static Char *
+g_strcat(Char *dst, const Char *src)
+{
+ Char *sdst = dst;
+
+ while (*dst++)
+ continue;
+ --dst;
+ while((*dst++ = *src++) != EOS)
+ continue;
+
+ return (sdst);
+}
+#endif
+
+static void
+g_Ctoc(const Char *str, char *buf)
+{
+ register char *dc;
+
+ for (dc = buf; (*dc++ = *str++) != EOS;)
+ continue;
+}
+
+#ifdef DEBUG
+static void
+qprintf(const char *str, Char *s)
+{
+ register Char *p;
+
+ (void)printf("%s:\n", str);
+ for (p = s; *p; p++)
+ (void)printf("%c", CHAR(*p));
+ (void)printf("\n");
+ for (p = s; *p; p++)
+ (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
+ (void)printf("\n");
+ for (p = s; *p; p++)
+ (void)printf("%c", ismeta(*p) ? '_' : ' ');
+ (void)printf("\n");
+}
+#endif
+
+#endif /* ! HAVE_GLOB */
+++ /dev/null
-/*
- * 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
- *
- */
-
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- * From: @(#)err.c 8.1 (Berkeley) 6/4/93
- */
-
-#if defined(LIBC_RCS) && !defined(lint)
-static const char rcsid[] =
- "$Id: err.c,v 1.2 1999/10/11 12:53:21 stelian Exp $";
-#endif /* LIBC_RCS and not lint */
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <stdarg.h>
-
-#include <config.h>
-
-extern char *__progname; /* Program name, from crt0. */
-
-static FILE *err_file; /* file to use for error output */
-static void (*err_exit)(int);
-
-/*
- * This is declared to take a `void *' so that the caller is not required
- * to include <stdio.h> first. However, it is really a `FILE *', and the
- * manual page documents it as such.
- */
-void
-err_set_file(void *fp)
-{
- if (fp)
- err_file = fp;
- else
- err_file = stderr;
-}
-
-void
-err_set_exit(void (*ef)(int))
-{
- err_exit = ef;
-}
-
-
-#ifndef HAVE_ERR
-__dead void
-err(int eval, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- verrc(eval, errno, fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VERR
-__dead void
-verr(eval, fmt, ap)
- int eval;
- const char *fmt;
- va_list ap;
-{
- verrc(eval, errno, fmt, ap);
-}
-#endif
-
-#ifndef HAVE_ERRC
-__dead void
-errc(int eval, int code, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- verrc(eval, code, fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VERRC
-__dead void
-verrc(eval, code, fmt, ap)
- int eval;
- int code;
- const char *fmt;
- va_list ap;
-{
- if (err_file == 0)
- err_set_file((FILE *)0);
- fprintf(err_file, "%s: ", __progname);
- if (fmt != NULL) {
- vfprintf(err_file, fmt, ap);
- fprintf(err_file, ": ");
- }
- fprintf(err_file, "%s\n", strerror(code));
- if (err_exit)
- err_exit(eval);
- exit(eval);
-}
-#endif
-
-#ifndef HAVE_ERRX
-__dead void
-errx(int eval, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- verrx(eval, fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VERRX
-__dead void
-verrx(eval, fmt, ap)
- int eval;
- const char *fmt;
- va_list ap;
-{
- if (err_file == 0)
- err_set_file((FILE *)0);
- fprintf(err_file, "%s: ", __progname);
- if (fmt != NULL)
- vfprintf(err_file, fmt, ap);
- fprintf(err_file, "\n");
- if (err_exit)
- err_exit(eval);
- exit(eval);
-}
-#endif
-
-#ifndef HAVE_WARN
-void
-warn(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vwarnc(errno, fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VWARN
-void
-vwarn(fmt, ap)
- const char *fmt;
- va_list ap;
-{
- vwarnc(errno, fmt, ap);
-}
-#endif
-
-#ifndef HAVE_WARNC
-void
-warnc(int code, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vwarnc(code, fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VWARNC
-void
-vwarnc(code, fmt, ap)
- int code;
- const char *fmt;
- va_list ap;
-{
- if (err_file == 0)
- err_set_file((FILE *)0);
- fprintf(err_file, "%s: ", __progname);
- if (fmt != NULL) {
- vfprintf(err_file, fmt, ap);
- fprintf(err_file, ": ");
- }
- fprintf(err_file, "%s\n", strerror(code));
-}
-#endif
-
-#ifndef HAVE_WARNX
-void
-warnx(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vwarnx(fmt, ap);
- va_end(ap);
-}
-#endif
-
-#ifndef HAVE_VWARNX
-void
-vwarnx(fmt, ap)
- const char *fmt;
- va_list ap;
-{
- if (err_file == 0)
- err_set_file((FILE *)0);
- fprintf(err_file, "%s: ", __progname);
- if (fmt != NULL)
- vfprintf(err_file, fmt, ap);
- fprintf(err_file, "\n");
-}
-#endif
static int fstabscan __P((void));
static
-int fstabscan()
+int fstabscan(void)
{
struct mntent *mnt;
register char *cp;
}
struct fstab *
-getfsent()
+getfsent(void)
{
if ((!_fs_fp && !setfsent()) || !fstabscan())
return((struct fstab *)NULL);
}
struct fstab *
-getfsspec(name)
- register const char *name;
+getfsspec(const char *name)
{
if (setfsent())
while (fstabscan())
}
struct fstab *
-getfsfile(name)
- register const char *name;
+getfsfile(const char *name)
{
if (setfsent())
while (fstabscan())
return((struct fstab *)NULL);
}
-int setfsent()
+int
+setfsent(void)
{
if (_fs_fp) {
rewind(_fs_fp);
}
void
-endfsent()
+endfsent(void)
{
if (_fs_fp) {
(void)endmntent(_fs_fp);
}
static
-void error(err)
- int err;
+void error(int err)
{
char *p;
+++ /dev/null
-/*
- * 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
- *
- */
-
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Guido van Rossum.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * glob(3) -- a superset of the one defined in POSIX 1003.2.
- *
- * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
- *
- * Optional extra services, controlled by flags not defined by POSIX:
- *
- * GLOB_QUOTE:
- * Escaping convention: \ inhibits any special meaning the following
- * character might have (except \ at end of string is retained).
- * GLOB_MAGCHAR:
- * Set in gl_flags if pattern contained a globbing character.
- * GLOB_NOMAGIC:
- * Same as GLOB_NOCHECK, but it will only append pattern if it did
- * not contain any magic characters. [Used in csh style globbing]
- * GLOB_ALTDIRFUNC:
- * Use alternately specified directory access functions.
- * GLOB_TILDE:
- * expand ~user/foo to the /home/dir/of/user/foo
- * GLOB_BRACE:
- * expand {1,2}{a,b} to 1a 1b 2a 2b
- * gl_matchc:
- * Number of matches in the current invocation of glob.
- */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <ctype.h>
-#include <dirent.h>
-#include <errno.h>
-#include <glob.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define DOLLAR '$'
-#define DOT '.'
-#define EOS '\0'
-#define LBRACKET '['
-#define NOT '!'
-#define QUESTION '?'
-#define QUOTE '\\'
-#define RANGE '-'
-#define RBRACKET ']'
-#define SEP '/'
-#define STAR '*'
-#define TILDE '~'
-#define UNDERSCORE '_'
-#define LBRACE '{'
-#define RBRACE '}'
-#define SLASH '/'
-#define COMMA ','
-
-#ifndef DEBUG
-
-#define M_QUOTE 0x8000
-#define M_PROTECT 0x4000
-#define M_MASK 0xffff
-#define M_ASCII 0x00ff
-
-typedef u_short Char;
-
-#else
-
-#define M_QUOTE 0x80
-#define M_PROTECT 0x40
-#define M_MASK 0xff
-#define M_ASCII 0x7f
-
-typedef char Char;
-
-#endif
-
-
-#define CHAR(c) ((Char)((c)&M_ASCII))
-#define META(c) ((Char)((c)|M_QUOTE))
-#define M_ALL META('*')
-#define M_END META(']')
-#define M_NOT META('!')
-#define M_ONE META('?')
-#define M_RNG META('-')
-#define M_SET META('[')
-#define ismeta(c) (((c)&M_QUOTE) != 0)
-
-
-static int compare __P((const void *, const void *));
-static void g_Ctoc __P((const Char *, char *));
-static int g_lstat __P((Char *, struct stat *, glob_t *));
-static DIR *g_opendir __P((Char *, glob_t *));
-static Char *g_strchr __P((Char *, int));
-#ifdef notdef
-static Char *g_strcat __P((Char *, const Char *));
-#endif
-static int g_stat __P((Char *, struct stat *, glob_t *));
-static int glob0 __P((const Char *, glob_t *));
-static int glob1 __P((Char *, glob_t *));
-static int glob2 __P((Char *, Char *, Char *, glob_t *));
-static int glob3 __P((Char *, Char *, Char *, Char *, glob_t *));
-static int globextend __P((const Char *, glob_t *));
-static const Char * globtilde __P((const Char *, Char *, size_t, glob_t *));
-static int globexp1 __P((const Char *, glob_t *));
-static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
-static int match __P((Char *, Char *, Char *));
-#ifdef DEBUG
-static void qprintf __P((const char *, Char *));
-#endif
-
-int
-glob(pattern, flags, errfunc, pglob)
- const char *pattern;
- int flags, (*errfunc) __P((const char *, int));
- glob_t *pglob;
-{
- const u_char *patnext;
- int c;
- Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
-
- patnext = (u_char *) pattern;
- if (!(flags & GLOB_APPEND)) {
- pglob->gl_pathc = 0;
- pglob->gl_pathv = NULL;
- if (!(flags & GLOB_DOOFFS))
- pglob->gl_offs = 0;
- }
- pglob->gl_flags = flags & ~GLOB_MAGCHAR;
- pglob->gl_errfunc = errfunc;
- pglob->gl_matchc = 0;
-
- bufnext = patbuf;
- bufend = bufnext + MAXPATHLEN;
- if (flags & GLOB_QUOTE) {
- /* Protect the quoted characters. */
- while (bufnext < bufend && (c = *patnext++) != EOS)
- if (c == QUOTE) {
- if ((c = *patnext++) == EOS) {
- c = QUOTE;
- --patnext;
- }
- *bufnext++ = c | M_PROTECT;
- }
- else
- *bufnext++ = c;
- }
- else
- while (bufnext < bufend && (c = *patnext++) != EOS)
- *bufnext++ = c;
- *bufnext = EOS;
-
- if (flags & GLOB_BRACE)
- return globexp1(patbuf, pglob);
- else
- return glob0(patbuf, pglob);
-}
-
-/*
- * Expand recursively a glob {} pattern. When there is no more expansion
- * invoke the standard globbing routine to glob the rest of the magic
- * characters
- */
-static int globexp1(pattern, pglob)
- const Char *pattern;
- glob_t *pglob;
-{
- const Char* ptr = pattern;
- int rv;
-
- /* Protect a single {}, for find(1), like csh */
- if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
- return glob0(pattern, pglob);
-
- while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
- if (!globexp2(ptr, pattern, pglob, &rv))
- return rv;
-
- return glob0(pattern, pglob);
-}
-
-
-/*
- * Recursive brace globbing helper. Tries to expand a single brace.
- * If it succeeds then it invokes globexp1 with the new pattern.
- * If it fails then it tries to glob the rest of the pattern and returns.
- */
-static int globexp2(ptr, pattern, pglob, rv)
- const Char *ptr, *pattern;
- glob_t *pglob;
- int *rv;
-{
- int i;
- Char *lm, *ls;
- const Char *pe, *pm, *pl;
- Char patbuf[MAXPATHLEN + 1];
-
- /* copy part up to the brace */
- for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
- continue;
- ls = lm;
-
- /* Find the balanced brace */
- for (i = 0, pe = ++ptr; *pe; pe++)
- if (*pe == LBRACKET) {
- /* Ignore everything between [] */
- for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
- continue;
- if (*pe == EOS) {
- /*
- * We could not find a matching RBRACKET.
- * Ignore and just look for RBRACE
- */
- pe = pm;
- }
- }
- else if (*pe == LBRACE)
- i++;
- else if (*pe == RBRACE) {
- if (i == 0)
- break;
- i--;
- }
-
- /* Non matching braces; just glob the pattern */
- if (i != 0 || *pe == EOS) {
- *rv = glob0(patbuf, pglob);
- return 0;
- }
-
- for (i = 0, pl = pm = ptr; pm <= pe; pm++)
- switch (*pm) {
- case LBRACKET:
- /* Ignore everything between [] */
- for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
- continue;
- if (*pm == EOS) {
- /*
- * We could not find a matching RBRACKET.
- * Ignore and just look for RBRACE
- */
- pm = pl;
- }
- break;
-
- case LBRACE:
- i++;
- break;
-
- case RBRACE:
- if (i) {
- i--;
- break;
- }
- /* FALLTHROUGH */
- case COMMA:
- if (i && *pm == COMMA)
- break;
- else {
- /* Append the current string */
- for (lm = ls; (pl < pm); *lm++ = *pl++)
- continue;
- /*
- * Append the rest of the pattern after the
- * closing brace
- */
- for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
- continue;
-
- /* Expand the current pattern */
-#ifdef DEBUG
- qprintf("globexp2:", patbuf);
-#endif
- *rv = globexp1(patbuf, pglob);
-
- /* move after the comma, to the next string */
- pl = pm + 1;
- }
- break;
-
- default:
- break;
- }
- *rv = 0;
- return 0;
-}
-
-
-
-/*
- * expand tilde from the passwd file.
- */
-static const Char *
-globtilde(pattern, patbuf, patbuf_len, pglob)
- const Char *pattern;
- Char *patbuf;
- size_t patbuf_len;
- glob_t *pglob;
-{
- struct passwd *pwd;
- char *h;
- const Char *p;
- Char *b, *eb;
-
- if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
- return pattern;
-
- /*
- * Copy up to the end of the string or /
- */
- eb = &patbuf[patbuf_len - 1];
- for (p = pattern + 1, h = (char *) patbuf;
- h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
- continue;
-
- *h = EOS;
-
- if (((char *) patbuf)[0] == EOS) {
- /*
- * handle a plain ~ or ~/ by expanding $HOME first if
- * we're not running setuid or setgid) and then trying
- * the password file
- */
- if (
-#ifndef __linux__
-#ifndef __NETBSD_SYSCALLS
- issetugid() != 0 ||
-#endif
-#endif
- (h = getenv("HOME")) == NULL) {
- if (((h = getlogin()) != NULL &&
- (pwd = getpwnam(h)) != NULL) ||
- (pwd = getpwuid(getuid())) != NULL)
- h = pwd->pw_dir;
- else
- return pattern;
- }
- }
- else {
- /*
- * Expand a ~user
- */
- if ((pwd = getpwnam((char*) patbuf)) == NULL)
- return pattern;
- else
- h = pwd->pw_dir;
- }
-
- /* Copy the home directory */
- for (b = patbuf; b < eb && *h; *b++ = *h++)
- continue;
-
- /* Append the rest of the pattern */
- while (b < eb && (*b++ = *p++) != EOS)
- continue;
- *b = EOS;
-
- return patbuf;
-}
-
-
-/*
- * The main glob() routine: compiles the pattern (optionally processing
- * quotes), calls glob1() to do the real pattern matching, and finally
- * sorts the list (unless unsorted operation is requested). Returns 0
- * if things went well, nonzero if errors occurred. It is not an error
- * to find no matches.
- */
-static int
-glob0(pattern, pglob)
- const Char *pattern;
- glob_t *pglob;
-{
- const Char *qpatnext;
- int c, err, oldpathc;
- Char *bufnext, patbuf[MAXPATHLEN+1];
-
- qpatnext = globtilde(pattern, patbuf, sizeof(patbuf) / sizeof(Char),
- pglob);
- oldpathc = pglob->gl_pathc;
- bufnext = patbuf;
-
- /* We don't need to check for buffer overflow any more. */
- while ((c = *qpatnext++) != EOS) {
- switch (c) {
- case LBRACKET:
- c = *qpatnext;
- if (c == NOT)
- ++qpatnext;
- if (*qpatnext == EOS ||
- g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
- *bufnext++ = LBRACKET;
- if (c == NOT)
- --qpatnext;
- break;
- }
- *bufnext++ = M_SET;
- if (c == NOT)
- *bufnext++ = M_NOT;
- c = *qpatnext++;
- do {
- *bufnext++ = CHAR(c);
- if (*qpatnext == RANGE &&
- (c = qpatnext[1]) != RBRACKET) {
- *bufnext++ = M_RNG;
- *bufnext++ = CHAR(c);
- qpatnext += 2;
- }
- } while ((c = *qpatnext++) != RBRACKET);
- pglob->gl_flags |= GLOB_MAGCHAR;
- *bufnext++ = M_END;
- break;
- case QUESTION:
- pglob->gl_flags |= GLOB_MAGCHAR;
- *bufnext++ = M_ONE;
- break;
- case STAR:
- pglob->gl_flags |= GLOB_MAGCHAR;
- /* collapse adjacent stars to one,
- * to avoid exponential behavior
- */
- if (bufnext == patbuf || bufnext[-1] != M_ALL)
- *bufnext++ = M_ALL;
- break;
- default:
- *bufnext++ = CHAR(c);
- break;
- }
- }
- *bufnext = EOS;
-#ifdef DEBUG
- qprintf("glob0:", patbuf);
-#endif
-
- if ((err = glob1(patbuf, pglob)) != 0)
- return(err);
-
- /*
- * If there was no match we are going to append the pattern
- * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
- * and the pattern did not contain any magic characters
- * GLOB_NOMAGIC is there just for compatibility with csh.
- */
- if (pglob->gl_pathc == oldpathc &&
- ((pglob->gl_flags & GLOB_NOCHECK) ||
- ((pglob->gl_flags & GLOB_NOMAGIC) &&
- !(pglob->gl_flags & GLOB_MAGCHAR))))
- return(globextend(pattern, pglob));
- else if (!(pglob->gl_flags & GLOB_NOSORT))
- qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
- pglob->gl_pathc - oldpathc, sizeof(char *), compare);
- return(0);
-}
-
-static int
-compare(p, q)
- const void *p, *q;
-{
- return(strcmp(*(char **)p, *(char **)q));
-}
-
-static int
-glob1(pattern, pglob)
- Char *pattern;
- glob_t *pglob;
-{
- Char pathbuf[MAXPATHLEN+1];
-
- /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
- if (*pattern == EOS)
- return(0);
- return(glob2(pathbuf, pathbuf, pattern, pglob));
-}
-
-/*
- * The functions glob2 and glob3 are mutually recursive; there is one level
- * of recursion for each segment in the pattern that contains one or more
- * meta characters.
- */
-static int
-glob2(pathbuf, pathend, pattern, pglob)
- Char *pathbuf, *pathend, *pattern;
- glob_t *pglob;
-{
- struct stat sb;
- Char *p, *q;
- int anymeta;
-
- /*
- * Loop over pattern segments until end of pattern or until
- * segment with meta character found.
- */
- for (anymeta = 0;;) {
- if (*pattern == EOS) { /* End of pattern? */
- *pathend = EOS;
- if (g_lstat(pathbuf, &sb, pglob))
- return(0);
-
- if (((pglob->gl_flags & GLOB_MARK) &&
- pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
- || (S_ISLNK(sb.st_mode) &&
- (g_stat(pathbuf, &sb, pglob) == 0) &&
- S_ISDIR(sb.st_mode)))) {
- *pathend++ = SEP;
- *pathend = EOS;
- }
- ++pglob->gl_matchc;
- return(globextend(pathbuf, pglob));
- }
-
- /* Find end of next segment, copy tentatively to pathend. */
- q = pathend;
- p = pattern;
- while (*p != EOS && *p != SEP) {
- if (ismeta(*p))
- anymeta = 1;
- *q++ = *p++;
- }
-
- if (!anymeta) { /* No expansion, do next segment. */
- pathend = q;
- pattern = p;
- while (*pattern == SEP)
- *pathend++ = *pattern++;
- } else /* Need expansion, recurse. */
- return(glob3(pathbuf, pathend, pattern, p, pglob));
- }
- /* NOTREACHED */
-}
-
-static int
-glob3(pathbuf, pathend, pattern, restpattern, pglob)
- Char *pathbuf, *pathend, *pattern, *restpattern;
- glob_t *pglob;
-{
- register struct dirent *dp;
- DIR *dirp;
- int err;
- char buf[MAXPATHLEN];
-
- /*
- * The readdirfunc declaration can't be prototyped, because it is
- * assigned, below, to two functions which are prototyped in glob.h
- * and dirent.h as taking pointers to differently typed opaque
- * structures.
- */
- struct dirent *(*readdirfunc)();
-
- *pathend = EOS;
- errno = 0;
-
- if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
- /* TODO: don't call for ENOENT or ENOTDIR? */
- if (pglob->gl_errfunc) {
- g_Ctoc(pathbuf, buf);
- if (pglob->gl_errfunc(buf, errno) ||
- pglob->gl_flags & GLOB_ERR)
- return (GLOB_ABEND);
- }
- return(0);
- }
-
- err = 0;
-
- /* Search directory for matching names. */
- if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- readdirfunc = pglob->gl_readdir;
- else
- readdirfunc = readdir;
- while ((dp = (*readdirfunc)(dirp))) {
- register u_char *sc;
- register Char *dc;
-
- /* Initial DOT must be matched literally. */
- if (dp->d_name[0] == DOT && *pattern != DOT)
- continue;
- for (sc = (u_char *) dp->d_name, dc = pathend;
- (*dc++ = *sc++) != EOS;)
- continue;
- if (!match(pathend, pattern, restpattern)) {
- *pathend = EOS;
- continue;
- }
- err = glob2(pathbuf, --dc, restpattern, pglob);
- if (err)
- break;
- }
-
- if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- (*pglob->gl_closedir)(dirp);
- else
- closedir(dirp);
- return(err);
-}
-
-
-/*
- * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
- * add the new item, and update gl_pathc.
- *
- * This assumes the BSD realloc, which only copies the block when its size
- * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
- * behavior.
- *
- * Return 0 if new item added, error code if memory couldn't be allocated.
- *
- * Invariant of the glob_t structure:
- * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
- * gl_pathv points to (gl_offs + gl_pathc + 1) items.
- */
-static int
-globextend(path, pglob)
- const Char *path;
- glob_t *pglob;
-{
- register char **pathv;
- register int i;
- u_int newsize;
- char *copy;
- const Char *p;
-
- newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
- pathv = pglob->gl_pathv ?
- realloc((char *)pglob->gl_pathv, newsize) :
- malloc(newsize);
- if (pathv == NULL)
- return(GLOB_NOSPACE);
-
- if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
- /* first time around -- clear initial gl_offs items */
- pathv += pglob->gl_offs;
- for (i = pglob->gl_offs; --i >= 0; )
- *--pathv = NULL;
- }
- pglob->gl_pathv = pathv;
-
- for (p = path; *p++;)
- continue;
- if ((copy = malloc(p - path)) != NULL) {
- g_Ctoc(path, copy);
- pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
- }
- pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
- return(copy == NULL ? GLOB_NOSPACE : 0);
-}
-
-/*
- * pattern matching function for filenames. Each occurrence of the *
- * pattern causes a recursion level.
- */
-static int
-match(name, pat, patend)
- register Char *name, *pat, *patend;
-{
- int ok, negate_range;
- Char c, k;
-
- while (pat < patend) {
- c = *pat++;
- switch (c & M_MASK) {
- case M_ALL:
- if (pat == patend)
- return(1);
- do
- if (match(name, pat, patend))
- return(1);
- while (*name++ != EOS);
- return(0);
- case M_ONE:
- if (*name++ == EOS)
- return(0);
- break;
- case M_SET:
- ok = 0;
- if ((k = *name++) == EOS)
- return(0);
- if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
- ++pat;
- while (((c = *pat++) & M_MASK) != M_END)
- if ((*pat & M_MASK) == M_RNG) {
- if (c <= k && k <= pat[1])
- ok = 1;
- pat += 2;
- } else if (c == k)
- ok = 1;
- if (ok == negate_range)
- return(0);
- break;
- default:
- if (*name++ != c)
- return(0);
- break;
- }
- }
- return(*name == EOS);
-}
-
-/* Free allocated data belonging to a glob_t structure. */
-void
-globfree(pglob)
- glob_t *pglob;
-{
- register int i;
- register char **pp;
-
- if (pglob->gl_pathv != NULL) {
- pp = pglob->gl_pathv + pglob->gl_offs;
- for (i = pglob->gl_pathc; i--; ++pp)
- if (*pp)
- free(*pp);
- free(pglob->gl_pathv);
- }
-}
-
-static DIR *
-g_opendir(str, pglob)
- register Char *str;
- glob_t *pglob;
-{
- char buf[MAXPATHLEN];
-
- if (!*str)
- strcpy(buf, ".");
- else
- g_Ctoc(str, buf);
-
- if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- return((*pglob->gl_opendir)(buf));
-
- return(opendir(buf));
-}
-
-static int
-g_lstat(fn, sb, pglob)
- register Char *fn;
- struct stat *sb;
- glob_t *pglob;
-{
- char buf[MAXPATHLEN];
-
- g_Ctoc(fn, buf);
- if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- return((*pglob->gl_lstat)(buf, sb));
- return(lstat(buf, sb));
-}
-
-static int
-g_stat(fn, sb, pglob)
- register Char *fn;
- struct stat *sb;
- glob_t *pglob;
-{
- char buf[MAXPATHLEN];
-
- g_Ctoc(fn, buf);
- if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- return((*pglob->gl_stat)(buf, sb));
- return(stat(buf, sb));
-}
-
-static Char *
-g_strchr(str, ch)
- Char *str;
- int ch;
-{
- do {
- if (*str == ch)
- return (str);
- } while (*str++);
- return (NULL);
-}
-
-#ifdef notdef
-static Char *
-g_strcat(dst, src)
- Char *dst;
- const Char* src;
-{
- Char *sdst = dst;
-
- while (*dst++)
- continue;
- --dst;
- while((*dst++ = *src++) != EOS)
- continue;
-
- return (sdst);
-}
-#endif
-
-static void
-g_Ctoc(str, buf)
- register const Char *str;
- char *buf;
-{
- register char *dc;
-
- for (dc = buf; (*dc++ = *str++) != EOS;)
- continue;
-}
-
-#ifdef DEBUG
-static void
-qprintf(str, s)
- const char *str;
- register Char *s;
-{
- register Char *p;
-
- (void)printf("%s:\n", str);
- for (p = s; *p; p++)
- (void)printf("%c", CHAR(*p));
- (void)printf("\n");
- for (p = s; *p; p++)
- (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
- (void)printf("\n");
- for (p = s; *p; p++)
- (void)printf("%c", ismeta(*p) ? '_' : ' ');
- (void)printf("\n");
-}
-#endif
/* Define if you have the err function. */
#undef HAVE_ERR
-/* Define if you have the errc function. */
-#undef HAVE_ERRC
-
/* Define if you have the errx function. */
#undef HAVE_ERRX
/* Define if you have the verr function. */
#undef HAVE_VERR
-/* Define if you have the verrc function. */
-#undef HAVE_VERRC
-
/* Define if you have the verrx function. */
#undef HAVE_VERRX
/* Define if you have the vwarn function. */
#undef HAVE_VWARN
-/* Define if you have the vwarnc function. */
-#undef HAVE_VWARNC
-
/* Define if you have the vwarnx function. */
#undef HAVE_VWARNX
/* Define if you have the warn function. */
#undef HAVE_WARN
-/* Define if you have the warnc function. */
-#undef HAVE_WARNC
-
/* Define if you have the warnx function. */
#undef HAVE_WARNX
+
+/* Define if you have the glob function. */
+#undef HAVE_GLOB
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated automatically using autoconf version 2.12
+# Generated automatically using autoconf version 2.13
# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
#
# This configure script is free software; the Free Software Foundation
# Initialize some other variables.
subdirs=
MFLAGS= MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
# Maximum number of lines to put in a shell here document.
ac_max_here_lines=12
verbose=yes ;;
-version | --version | --versio | --versi | --vers)
- echo "configure generated by autoconf version 2.12"
+ echo "configure generated by autoconf version 2.13"
exit 0 ;;
-with-* | --with-*)
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
ac_cpp='$CPP $CPPFLAGS'
ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
cross_compiling=$ac_cv_prog_cc_cross
+ac_exeext=
+ac_objext=o
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
# Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:557: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:560: checking whether ${MAKE-make} sets \${MAKE}" >&5
set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
fi
echo $ac_n "checking whether ln -s works""... $ac_c" 1>&6
-echo "configure:584: checking whether ln -s works" >&5
+echo "configure:587: checking whether ln -s works" >&5
if eval "test \"`echo '$''{'ac_cv_prog_LN_S'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "cp", so it can be a program name with args.
set dummy cp; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:607: checking for $ac_word" >&5
+echo "configure:610: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_CP'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
/*)
ac_cv_path_CP="$CP" # Let the user override the test with a path.
;;
+ ?:/*)
+ ac_cv_path_CP="$CP" # Let the user override the test with a dos path.
+ ;;
*)
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_path_CP="$ac_dir/$ac_word"
# Extract the first word of "mv", so it can be a program name with args.
set dummy mv; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:639: checking for $ac_word" >&5
+echo "configure:646: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_MV'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
/*)
ac_cv_path_MV="$MV" # Let the user override the test with a path.
;;
+ ?:/*)
+ ac_cv_path_MV="$MV" # Let the user override the test with a dos path.
+ ;;
*)
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_path_MV="$ac_dir/$ac_word"
# Extract the first word of "rm", so it can be a program name with args.
set dummy rm; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:671: checking for $ac_word" >&5
+echo "configure:682: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_RM'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
/*)
ac_cv_path_RM="$RM" # Let the user override the test with a path.
;;
+ ?:/*)
+ ac_cv_path_RM="$RM" # Let the user override the test with a dos path.
+ ;;
*)
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_path_RM="$ac_dir/$ac_word"
# Make sure we can run config.sub.
-if $ac_config_sub sun4 >/dev/null 2>&1; then :
+if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then :
else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; }
fi
echo $ac_n "checking host system type""... $ac_c" 1>&6
-echo "configure:726: checking host system type" >&5
+echo "configure:741: checking host system type" >&5
host_alias=$host
case "$host_alias" in
NONE)
case $nonopt in
NONE)
- if host_alias=`$ac_config_guess`; then :
+ if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then :
else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; }
fi ;;
*) host_alias=$nonopt ;;
esac ;;
esac
-host=`$ac_config_sub $host_alias`
+host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias`
host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$ac_t""$host" 1>&6
echo $ac_n "checking build system type""... $ac_c" 1>&6
-echo "configure:747: checking build system type" >&5
+echo "configure:762: checking build system type" >&5
build_alias=$build
case "$build_alias" in
esac ;;
esac
-build=`$ac_config_sub $build_alias`
+build=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $build_alias`
build_cpu=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
build_vendor=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
build_os=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
# Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
set dummy ${ac_tool_prefix}ar; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:773: checking for $ac_word" >&5
+echo "configure:788: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_AR'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$AR"; then
ac_cv_prog_AR="$AR" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_AR="${ac_tool_prefix}ar"
# Extract the first word of "ar", so it can be a program name with args.
set dummy ar; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:804: checking for $ac_word" >&5
+echo "configure:820: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_AR'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$AR"; then
ac_cv_prog_AR="$AR" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_AR="ar"
# Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:838: checking for $ac_word" >&5
+echo "configure:855: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$RANLIB"; then
ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
# Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:869: checking for $ac_word" >&5
+echo "configure:887: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$RANLIB"; then
ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_RANLIB="ranlib"
# Extract the first word of "${ac_tool_prefix}patch", so it can be a program name with args.
set dummy ${ac_tool_prefix}patch; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:903: checking for $ac_word" >&5
+echo "configure:922: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_PATCH'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$PATCH"; then
ac_cv_prog_PATCH="$PATCH" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_PATCH="${ac_tool_prefix}patch"
# Extract the first word of "patch", so it can be a program name with args.
set dummy patch; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:934: checking for $ac_word" >&5
+echo "configure:954: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_PATCH'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$PATCH"; then
ac_cv_prog_PATCH="$PATCH" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_PATCH="patch"
# Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:968: checking for $ac_word" >&5
+echo "configure:989: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
- for ac_dir in $PATH; do
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_CC="gcc"
# Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:997: checking for $ac_word" >&5
+echo "configure:1019: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
ac_prog_rejected=no
- for ac_dir in $PATH; do
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
echo "$ac_t""no" 1>&6
fi
+ if test -z "$CC"; then
+ case "`uname -s`" in
+ *win32* | *WIN32*)
+ # Extract the first word of "cl", so it can be a program name with args.
+set dummy cl; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:1070: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_CC="cl"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+ ;;
+ esac
+ fi
test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1045: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:1102: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
ac_cpp='$CPP $CPPFLAGS'
ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
cross_compiling=$ac_cv_prog_cc_cross
-cat > conftest.$ac_ext <<EOF
-#line 1055 "configure"
+cat > conftest.$ac_ext << EOF
+
+#line 1113 "configure"
#include "confdefs.h"
+
main(){return(0);}
EOF
-if { (eval echo configure:1059: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1118: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
ac_cv_prog_cc_works=yes
# If we can't run a trivial program, we are probably using a cross compiler.
if (./conftest; exit) 2>/dev/null; then
ac_cv_prog_cc_works=no
fi
rm -fr conftest*
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
if test $ac_cv_prog_cc_works = no; then
{ echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1079: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1144: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
cross_compiling=$ac_cv_prog_cc_cross
echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:1084: checking whether we are using GNU C" >&5
+echo "configure:1149: checking whether we are using GNU C" >&5
if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
yes;
#endif
EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1093: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1158: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
ac_cv_prog_gcc=yes
else
ac_cv_prog_gcc=no
if test $ac_cv_prog_gcc = yes; then
GCC=yes
- ac_test_CFLAGS="${CFLAGS+set}"
- ac_save_CFLAGS="$CFLAGS"
- CFLAGS=
- echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:1108: checking whether ${CC-cc} accepts -g" >&5
+else
+ GCC=
+fi
+
+ac_test_CFLAGS="${CFLAGS+set}"
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS=
+echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
+echo "configure:1177: checking whether ${CC-cc} accepts -g" >&5
if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
- if test "$ac_test_CFLAGS" = set; then
- CFLAGS="$ac_save_CFLAGS"
- elif test $ac_cv_prog_cc_g = yes; then
+if test "$ac_test_CFLAGS" = set; then
+ CFLAGS="$ac_save_CFLAGS"
+elif test $ac_cv_prog_cc_g = yes; then
+ if test "$GCC" = yes; then
CFLAGS="-g -O2"
else
- CFLAGS="-O2"
+ CFLAGS="-g"
fi
else
- GCC=
- test "${CFLAGS+set}" = set || CFLAGS="-g"
+ if test "$GCC" = yes; then
+ CFLAGS="-O2"
+ else
+ CFLAGS=
+ fi
fi
# Find a good install program. We prefer a C program (faster),
# SunOS /usr/etc/install
# IRIX /sbin/install
# AIX /bin/install
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
# AFS /usr/afsws/bin/install, which mishandles nonexistent args
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./install, which can be erroneously created by make from ./install.sh.
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:1146: checking for a BSD compatible install" >&5
+echo "configure:1220: checking for a BSD compatible install" >&5
if test -z "$INSTALL"; then
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
- IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:"
+ IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":"
for ac_dir in $PATH; do
# Account for people who put trailing slashes in PATH elements.
case "$ac_dir/" in
/|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
*)
# OSF1 and SCO ODT 3.0 have their own names for install.
- for ac_prog in ginstall installbsd scoinst install; do
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
if test -f $ac_dir/$ac_prog; then
if test $ac_prog = install &&
grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
# AIX install. It has an incompatible calling convention.
- # OSF/1 installbsd also uses dspmsg, but is usable.
:
else
ac_cv_path_install="$ac_dir/$ac_prog -c"
# It thinks the first close brace ends the variable substitution.
test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
+
test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1387: checking how to run the C preprocessor" >&5
+echo "configure:1464: checking how to run the C preprocessor" >&5
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
CPP=
# On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp.
cat > conftest.$ac_ext <<EOF
-#line 1402 "configure"
+#line 1479 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1408: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:1485: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
else
rm -rf conftest*
CPP="${CC-cc} -E -traditional-cpp"
cat > conftest.$ac_ext <<EOF
-#line 1419 "configure"
+#line 1496 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1425: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:1502: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+ :
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ CPP="${CC-cc} -nologo -E"
+ cat > conftest.$ac_ext <<EOF
+#line 1513 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1519: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
else
fi
rm -f conftest*
fi
+rm -f conftest*
+fi
rm -f conftest*
ac_cv_prog_CPP="$CPP"
fi
ac_safe=`echo "ext2fs/ext2fs.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for ext2fs/ext2fs.h""... $ac_c" 1>&6
-echo "configure:1449: checking for ext2fs/ext2fs.h" >&5
+echo "configure:1545: checking for ext2fs/ext2fs.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1454 "configure"
+#line 1550 "configure"
#include "confdefs.h"
#include <ext2fs/ext2fs.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1459: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:1555: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
eval "ac_cv_header_$ac_safe=yes"
fi
echo $ac_n "checking for ext2fs_open in -lext2fs""... $ac_c" 1>&6
-echo "configure:1482: checking for ext2fs_open in -lext2fs" >&5
+echo "configure:1578: checking for ext2fs_open in -lext2fs" >&5
ac_lib_var=`echo ext2fs'_'ext2fs_open | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lext2fs -lcom_err $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 1490 "configure"
+#line 1586 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
ext2fs_open()
; return 0; }
EOF
-if { (eval echo configure:1501: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1597: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
{ echo "configure: error: You need to install the Ext2fs libraries from the E2fsprogs distribution first" 1>&2; exit 1; }
fi
-for ac_func in err errc errx verr verrc verrx vwarn vwarnc vwarnx warn warnc warnx realpath
+for ac_func in err errx verr verrx vwarn vwarnx warn warnx realpath glob
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1529: checking for $ac_func" >&5
+echo "configure:1625: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1534 "configure"
+#line 1630 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:1557: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1653: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1583: checking for ANSI C header files" >&5
+echo "configure:1679: checking for ANSI C header files" >&5
if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1588 "configure"
+#line 1684 "configure"
#include "confdefs.h"
#include <stdlib.h>
#include <stdarg.h>
#include <float.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1596: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:1692: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
ac_cv_header_stdc=yes
if test $ac_cv_header_stdc = yes; then
# SunOS 4.x string.h does not declare mem*, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 1613 "configure"
+#line 1709 "configure"
#include "confdefs.h"
#include <string.h>
EOF
if test $ac_cv_header_stdc = yes; then
# ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 1631 "configure"
+#line 1727 "configure"
#include "confdefs.h"
#include <stdlib.h>
EOF
:
else
cat > conftest.$ac_ext <<EOF
-#line 1652 "configure"
+#line 1748 "configure"
#include "confdefs.h"
#include <ctype.h>
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
exit (0); }
EOF
-if { (eval echo configure:1663: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1759: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
fi
echo $ac_n "checking for quad_t""... $ac_c" 1>&6
-echo "configure:1687: checking for quad_t" >&5
+echo "configure:1783: checking for quad_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_quad_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1692 "configure"
+#line 1788 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
#endif
EOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "quad_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+ egrep "(^|[^a-zA-Z_0-9])quad_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
rm -rf conftest*
ac_cv_type_quad_t=yes
else
fi
echo $ac_n "checking for u_quad_t""... $ac_c" 1>&6
-echo "configure:1720: checking for u_quad_t" >&5
+echo "configure:1816: checking for u_quad_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_u_quad_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1725 "configure"
+#line 1821 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
#endif
EOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- egrep "u_quad_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+ egrep "(^|[^a-zA-Z_0-9])u_quad_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
rm -rf conftest*
ac_cv_type_u_quad_t=yes
else
# Ultrix sh set writes to stderr and can't be redirected directly,
# and sets the high bit in the cache file unless we assign to the vars.
(set) 2>&1 |
- case `(ac_space=' '; set) 2>&1` in
+ case `(ac_space=' '; set | grep ac_space) 2>&1` in
*ac_space=\ *)
# `set' does not quote correctly, so add quotes (double-quote substitution
# turns \\\\ into \\, and sed turns \\ into \).
echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
-version | --version | --versio | --versi | --vers | --ver | --ve | --v)
- echo "$CONFIG_STATUS generated by autoconf version 2.12"
+ echo "$CONFIG_STATUS generated by autoconf version 2.13"
exit 0 ;;
-help | --help | --hel | --he | --h)
echo "\$ac_cs_usage"; exit 0 ;;
s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
$ac_vpsub
$extrasub
+s%@SHELL@%$SHELL%g
s%@CFLAGS@%$CFLAGS%g
s%@CPPFLAGS@%$CPPFLAGS%g
s%@CXXFLAGS@%$CXXFLAGS%g
+s%@FFLAGS@%$FFLAGS%g
s%@DEFS@%$DEFS%g
s%@LDFLAGS@%$LDFLAGS%g
s%@LIBS@%$LIBS%g
s%@PATCH@%$PATCH%g
s%@CC@%$CC%g
s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
+s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g
s%@INSTALL_DATA@%$INSTALL_DATA%g
s%@DUMPDEBUG@%$DUMPDEBUG%g
s%@RESTOREDEBUG@%$RESTOREDEBUG%g
dnl
dnl Check for library functions
dnl
-AC_CHECK_FUNCS(err errc errx verr verrc verrx vwarn vwarnc vwarnx warn warnc warnx realpath)
+AC_CHECK_FUNCS(err errx verr verrx vwarn vwarnx warn warnx realpath glob)
dnl
dnl Check for types
Begin3
Title: dump and restore for Ext2fs
-Version: 0.4b5
-Entered-date: 22SEP99
+Version: 0.4b6
+Entered-date: 03OCT99
Description: Port of the 4.4BSD dump and restore backup suite
Keywords: backup, filesystem, Ext2fs
Author: University of California, Berkeley
-Maintained-by: pop@captimark.fr (Stelian Pop)
+Maintained-by: pop@cybercable.fr (Stelian Pop)
Primary-site: tsx-11.mit.edu /pub/linux/ALPHA/ext2fs
- 132kB dump-0.4b5.tar.gz
+ 132kB dump-0.4b6.tar.gz
627 dump.lsm
Alternate-site:
Original-site: ftp.freebsd.org /pub/bsd-sources/4.4BSD-Lite2/sbin
@MCONFIG@
-CFLAGS= @CCOPTS@ -pipe $(GINC) $(INC) $(DEFS) @DUMPDEBUG@
+CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS) @DUMPDEBUG@
LDFLAGS:= $(LDFLAGS) @STATIC@
LIBS= $(GLIBS)
DEPLIBS= ../compat/lib/libcompat.a
OBJS= itime.o main.o optr.o tape.o traverse.o unctime.o \
../common/dumprmt.o
MAN8= dump.8
-MLINKS= $(MANDIR)/dump.8 $(MANDIR)/rdump.8
+MLINKS= dump.8 $(MANDIR)/rdump.8
all:: $(PROG)
.\" 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 acknowledgment:
+.\" 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
.\" SUCH DAMAGE.
.\"
.\" @(#)dump.8 8.3 (Berkeley) 5/1/95
-.\" $Id: dump.8,v 1.2 1999/10/11 12:53:21 stelian Exp $
+.\" $Id: dump.8,v 1.3 1999/10/11 12:59:18 stelian Exp $
.\"
-.Dd May 1, 1995
+.Dd June 4, 1997
.Dt DUMP 8
.Os BSD 4
.Sh NAME
.Nm dump
-.Nd filesystem backup
+.Nd ext2 filesystem backup
.Sh SYNOPSIS
.Nm dump
.Op Fl 0123456789acknu
.in -\\n(iSu
(The
.Bx 4.3
-option syntax is implemented for backward compatibility, but
+option syntax is implemented for backward compatibility but
is not documented here.)
.Sh DESCRIPTION
.Nm Dump
examines files
-on a filesystem
+on an ext2 filesystem
and determines which files
need to be backed up. These files
are copied to the given disk, tape or other
A dump that is larger than the output medium is broken into
multiple volumes.
On most media the size is determined by writing until an
-end-of-media indication is returned. This can be enforced
+end-of-media indication is returned. This can be enforced
by using the
.Fl a
option.
.Pp
On media that cannot reliably return an end-of-media indication
-(such as some cartridge tape drives)
+(such as some cartridge tape drives),
each volume is of a fixed size;
-the actual size is determined by the tape size and density and/or
+the actual size is determined by the tape size, density and/or
block count options below.
By default, the same output file name is used for each volume
after prompting the operator to change media.
option below).
A level number above 0,
incremental backup,
-tells dump to
+tells
+.Nm dump
+to
copy all files new or modified since the
-last dump of any lower level.
-The default level is 0.
+last dump of the same or lower level.
+The default level is 9.
.It Fl B Ar records
The number of 1 KB blocks per volume.
This option overrides the calculation of tape size
the compression ratio).
.It Fl b Ar blocksize
The number of kilobytes per dump record.
+Since the IO system slices all requests into chunks of MAXBSIZE
+(typically 64KB), it is not possible to use a larger blocksize
+without having problems later with
+.Xr restore 8 .
+Therefore
+.Nm dump
+will constrain writes to MAXBSIZE.
.It Fl c
Change the defaults for use with a cartridge tape drive, with a density
of 8000 bpi, and a length of 1700 feet.
.Ar file
may be a special device file
like
-.Pa /dev/rmt12
+.Pa /dev/st0
(a tape drive),
.Pa /dev/rsd1c
(a floppy disk drive),
the last file name will used for all remaining volumes after prompting
for media changes.
If the name of the file is of the form
-.Dq host:file ,
+.Dq host:file
or
-.Dq user@host:file ,
+.Dq user@host:file
.Nm
writes to the named file on the remote host using
.Xr rmt 8 .
Use the specified date as the starting time for the dump
instead of the time determined from looking in
.Pa /etc/dumpdates .
-The format of date is the same as that of
+The format of
+.Ar date
+is the same as that of
.Xr ctime 3 .
This option is useful for automated dump scripts that wish to
dump over a specific period of time.
option causes
.Nm
to print out, for each file system in
-.Pa /etc/dumpdates
+.Pa /etc/dumpdates ,
the most recent dump date and level,
and highlights those file systems that should be dumped.
If the
.Nm
exits immediately.
.It Fl w
-Is like W, but prints only those filesystems which need to be dumped.
+Is like
+.Fl W ,
+but prints only those filesystems which need to be dumped.
.El
.Pp
.Nm Dump
end of dump,
tape write error,
tape open error or
-disk read error (if there are more than a threshold of 32).
+disk read error (if there is more than a threshold of 32).
In addition to alerting all operators implied by the
.Fl n
key,
program.
.Sh FILES
.Bl -tag -width /etc/dumpdates -compact
-.It Pa /dev/rmt8
+.It Pa /dev/st0
default tape unit to dump to
.It Pa /etc/dumpdates
dump date records
.Sh DIAGNOSTICS
Many, and verbose.
.Pp
-Dump exits with zero status on success.
+.Nm Dump
+exits with zero status on success.
Startup errors are indicated with an exit code of 1;
abnormal termination is indicated with an exit code of 3.
.Sh BUGS
-Fewer than 32 read errors on the filesystem are ignored.
+It might be considered a bug that this version of dump can only handle ext2
+filesystems. Specifically, it does not work with FAT filesystems.
+.Pp
+Fewer than 32 read errors on the filesystem are ignored. If noticing
+read errors is important, the output from dump can be parsed to look for lines
+that contain the text 'read error'.
.Pp
Each reel requires a new process, so parent processes for
reels already written just hang around until the entire tape
.Fl W
or
.Fl w
-options does not report filesystems that have never been recorded
+option does not report filesystems that have never been recorded
in
.Pa /etc/dumpdates ,
even if listed in
struct fs *sblock; /* the file system super block */
char sblock_buf[MAXBSIZE];
#endif
+long xferrate; /* averaged transfer rate of all volumes */
long dev_bsize; /* block size of underlying disk device */
int dev_bshift; /* log2(dev_bsize) */
int tp_bshift; /* log2(TP_BSIZE) */
#endif
/* operator interface functions */
-void broadcast __P((char *message));
-void lastdump __P((int arg)); /* int should be char */
+void broadcast __P((const char *message));
+time_t do_stats __P((void));
+void lastdump __P((char arg));
void msg __P((const char *fmt, ...));
void msgtail __P((const char *fmt, ...));
-int query __P((char *question));
+int query __P((const char *question));
void quit __P((const char *fmt, ...));
void set_operators __P((void));
+#if defined(SIGINFO)
+void statussig __P((int signo));
+#endif
void timeest __P((void));
-time_t unctime __P((char *str));
+time_t unctime __P((const char *str));
/* mapping rouintes */
struct dinode;
void dumpblock __P((daddr_t blkno, int size));
void startnewtape __P((int top));
void trewind __P((void));
-void writerec __P((char *dp, int isspcl));
+void writerec __P((const void *dp, int isspcl));
-__dead void Exit __P((int status));
+void Exit __P((int status));
void dumpabort __P((int signo));
void getfstab __P((void));
/* rdump routines */
#ifdef RDUMP
+int rmthost __P((const char *host));
+int rmtopen __P((const char *tape, int mode));
void rmtclose __P((void));
-int rmthost __P((char *host));
-int rmtopen __P((char *tape, int mode));
-int rmtwrite __P((char *buf, int count));
+int rmtread __P((char *buf, size_t count));
+int rmtwrite __P((const char *buf, size_t count));
+int rmtseek __P((int offset, int pos));
+struct mtget * rmtstatus __P((void));
+int rmtioctl __P((int cmd, int count));
#endif /* RDUMP */
void interrupt __P((int signo)); /* in case operator bangs on console */
* Exit status codes
*/
#define X_FINOK 0 /* normal exit */
-#define X_STARTUP 1 /* startup error */
+#define X_STARTUP 1 /* startup error */
#define X_REWRITE 2 /* restart writing from the check point */
#define X_ABORT 3 /* abort dump; don't attempt checkpointing */
#define DIALUP "ttyd" /* prefix for dialups */
#endif
-struct fstab *fstabsearch __P((char *key)); /* search fs_file and fs_spec */
+struct fstab *fstabsearch __P((const char *key)); /* search fs_file and fs_spec */
#ifdef __linux__
-struct fstab *fstabsearchdir __P((char *key, char *dir)); /* search fs_file and fs_spec */
+struct fstab *fstabsearchdir __P((const char *key, char *dir)); /* search fs_file and fs_spec */
#endif
#ifndef NAME_MAX
static char sccsid[] = "@(#)itime.c 8.1 (Berkeley) 6/5/93";
#endif
static const char rcsid[] =
- "$Id: itime.c,v 1.2 1999/10/11 12:53:22 stelian Exp $";
+ "$Id: itime.c,v 1.3 1999/10/11 12:59:18 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
static void readdumptimes __P((FILE *));
void
-initdumptimes()
+initdumptimes(void)
{
FILE *df;
}
static void
-readdumptimes(df)
- FILE *df;
+readdumptimes(FILE *df)
{
register int i;
register struct dumptime *dtwalk;
}
void
-getdumptime()
+getdumptime(void)
{
register struct dumpdates *ddp;
register int i;
spcl.c_ddate = 0;
lastlevel = '0';
+ /* if we're not going to update dumpdates, there's no point in reading
+ it, particularly since /var might not be mounted... wait until here
+ to benefit from the initialization of variables needed by parent */
+ if (uflag == 0)
+ return;
+
initdumptimes();
/*
* Go find the entry with the same name for a lower increment
}
void
-putdumptime()
+putdumptime(void)
{
FILE *df;
register struct dumpdates *dtwalk;
}
static void
-dumprecout(file, what)
- FILE *file;
- struct dumpdates *what;
+dumprecout(FILE *file, struct dumpdates *what)
{
if (fprintf(file, DUMPOUTFMT,
int recno;
static int
-getrecord(df, ddatep)
- FILE *df;
- struct dumpdates *ddatep;
+getrecord(FILE *df, struct dumpdates *ddatep)
{
char tbuf[BUFSIZ];
recno = 0;
- if ( (fgets(tbuf, sizeof (tbuf), df)) != tbuf)
+ if (fgets(tbuf, sizeof (tbuf), df) == NULL)
return(-1);
recno++;
if (makedumpdate(ddatep, tbuf) < 0)
}
static int
-makedumpdate(ddp, tbuf)
- struct dumpdates *ddp;
- char *tbuf;
+makedumpdate(struct dumpdates *ddp, char *tbuf)
{
- char un_buf[128];
+ char un_buf[BUFSIZ];
(void) sscanf(tbuf, DUMPINFMT, ddp->dd_name, &ddp->dd_level, un_buf);
ddp->dd_ddate = unctime(un_buf);
* 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@cybercable.fr>, 1999
*
*/
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95";
#endif
static const char rcsid[] =
- "$Id: main.c,v 1.2 1999/10/11 12:53:22 stelian Exp $";
+ "$Id: main.c,v 1.3 1999/10/11 12:59:18 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <protocols/dumprestore.h>
#include <ctype.h>
-#include <err.h>
+#include <compaterr.h>
#include <fcntl.h>
#include <fstab.h>
#include <signal.h>
char *__progname;
#endif
-static long numarg __P((char *, long, long));
+int maxbsize = 64*1024; /* XXX MAXBSIZE from sys/param.h */
+static long numarg __P((const char *, long, long));
static void obsolete __P((int *, char **[]));
static void usage __P((void));
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
register ino_t ino;
register int dirty;
char directory[NAME_MAX];
char pathname[NAME_MAX];
#endif
+ time_t tnow;
char labelstr[LBLSIZE];
spcl.c_date = 0;
case 'b': /* blocks per tape write */
ntrec = numarg("number of blocks per write",
1L, 1000L);
+ if (ntrec > maxbsize/1024) {
+ msg("Please choose a blocksize <= %dKB\n",
+ maxbsize/1024);
+ exit(X_STARTUP);
+ }
+ bflag = 1;
break;
case 'c': /* Tape is cart. not 9-track */
}
Tflag = 1;
lastlevel = '?';
- argc--;
- argv++;
break;
- case 'u': /* update /etc/dumpdates */
+ case 'u': /* update dumpdates */
uflag = 1;
break;
* the special name missing the leading '/',
* the file system name with or without the leading '/'.
*/
- dt = fstabsearch(disk);
- if (dt != NULL) {
+ if ((dt = fstabsearch(disk)) != NULL) {
disk = rawname(dt->fs_spec);
(void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
(void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
spcl.c_level = level - '0';
spcl.c_type = TS_TAPE;
if (!Tflag)
- getdumptime(); /* /etc/dumpdates snarfed */
+ getdumptime(); /* dumpdates snarfed */
msg("Date of this level %c dump: %s", level,
#ifdef __linux
nonodump = spcl.c_level < honorlevel;
+#if defined(SIGINFO)
+ (void)signal(SIGINFO, statussig);
+#endif
+
msg("mapping (Pass I) [regular files]\n");
#ifdef __linux__
if (directory[0] == 0)
tend_writing - tstart_writing,
spcl.c_tapea / (tend_writing - tstart_writing));
+ tnow = do_stats();
putdumptime();
+#ifdef __linux__
+ msg("DUMP: Date of this level %c dump: %s", level,
+ spcl.c_date == 0 ? "the epoch\n" : ctime4(&spcl.c_date));
+#else
+ msg("DUMP: Date of this level %c dump: %s", level,
+ spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
+#endif
+ msg("DUMP: Date this dump completed: %s", ctime(&tnow));
+
+ msg("DUMP: Average transfer rate: %ld KB/s\n", xferrate / tapeno);
+
trewind();
broadcast("DUMP IS DONE!\7\7\n");
msg("DUMP IS DONE\n");
Exit(X_FINOK);
/* NOTREACHED */
- exit(1); /* gcc - shut up */
+ return 0; /* gcc - shut up */
}
static void
-usage()
+usage(void)
{
fprintf(stderr,
- "usage: dump [-0123456789ac"
+ "usage: %s [-0123456789ac"
#ifdef KERBEROS
"k"
#endif
"nu] [-B records] [-b blocksize] [-d density] [-f file]\n"
" [-h level] [-s feet] [-T date] filesystem\n"
- " dump [-W | -w]\n");
+ " %s [-W | -w]\n", __progname, __progname);
exit(X_STARTUP);
}
* range (except that a vmax of 0 means unlimited).
*/
static long
-numarg(meaning, vmin, vmax)
- char *meaning;
- long vmin, vmax;
+numarg(const char *meaning, long vmin, long vmax)
{
char *p;
long val;
val = strtol(optarg, &p, 10);
if (*p)
- errx(1, "illegal %s -- %s", meaning, optarg);
+ errx(X_STARTUP, "illegal %s -- %s", meaning, optarg);
if (val < vmin || (vmax && val > vmax))
- errx(1, "%s must be between %ld and %ld", meaning, vmin, vmax);
+ errx(X_STARTUP, "%s must be between %ld and %ld", meaning, vmin, vmax);
return (val);
}
void
-sig(signo)
- int signo;
+sig(int signo)
{
switch(signo) {
case SIGALRM:
}
char *
-rawname(cp)
- char *cp;
+rawname(char *cp)
{
#ifdef __linux__
return cp;
* getopt(3) will like.
*/
static void
-obsolete(argcp, argvp)
- int *argcp;
- char **argvp[];
+obsolete(int *argcp, char **argvp[])
{
int argc, flags;
char *ap, **argv, *flagsp=NULL, **nargv, *p=NULL;
/* Allocate space for new arguments. */
if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
(p = flagsp = malloc(strlen(ap) + 2)) == NULL)
- err(1, NULL);
+ err(X_STARTUP, "malloc new args");
*nargv++ = *argv;
argv += 2;
usage();
}
if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
- err(1, NULL);
+ err(X_STARTUP, "malloc arg");
nargv[0][0] = '-';
nargv[0][1] = *ap;
(void)strcpy(&nargv[0][2], *argv);
static char sccsid[] = "@(#)optr.c 8.2 (Berkeley) 1/6/94";
#endif
static const char rcsid[] =
- "$Id: optr.c,v 1.2 1999/10/11 12:53:22 stelian Exp $";
+ "$Id: optr.c,v 1.3 1999/10/11 12:59:19 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#include "dump.h"
#include "pathnames.h"
-void alarmcatch __P((/* int, int */));
+static void alarmcatch __P((int));
int datesort __P((const void *, const void *));
-static void sendmes __P((char *, char *));
+static void sendmes __P((const char *, const char *));
/*
* Query the operator; This previously-fascist piece of code
* that dump needs attention.
*/
static int timeout;
-static char *attnmessage; /* attention message */
+static const char *attnmessage; /* attention message */
int
-query(question)
- char *question;
+query(const char *question)
{
char replybuffer[64];
int back, errcount;
FILE *mytty;
+ time_t firstprompt, when_answered;
+
+ firstprompt = time(NULL);
if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
attnmessage = question;
timeout = 0;
- alarmcatch();
+ alarmcatch(0);
back = -1;
errcount = 0;
do {
if (signal(SIGALRM, sig) == SIG_IGN)
signal(SIGALRM, SIG_IGN);
(void) fclose(mytty);
+ when_answered = time(NULL);
+ /*
+ * Adjust the base for time estimates to ignore time we spent waiting
+ * for operator input.
+ */
+ if (tstart_writing != 0)
+ tstart_writing += (when_answered - firstprompt);
return(back);
}
-char lastmsg[100];
+char lastmsg[BUFSIZ];
/*
* Alert the console operator, and enable the alarm clock to
* sleep for 2 minutes in case nobody comes to satisfy dump
*/
-void
-alarmcatch()
+static void
+alarmcatch(int signo)
{
+ int save_errno = errno;
if (notify == 0) {
if (timeout == 0)
(void) fprintf(stderr,
signal(SIGALRM, alarmcatch);
(void) alarm(120);
timeout = 1;
+ errno = save_errno;
}
/*
* Here if an inquisitive operator interrupts the dump program
*/
void
-interrupt(signo)
- int signo;
+interrupt(int signo)
{
msg("Interrupt received.\n");
if (query("Do you want to abort dump?"))
* Get the names from the group entry "operator" to notify.
*/
void
-set_operators()
+set_operators(void)
{
if (!notify) /*not going to notify*/
return;
* that the process control groups are not messed up
*/
void
-broadcast(message)
- char *message;
+broadcast(const char *message)
{
time_t clock;
FILE *f_utmp;
}
static void
-sendmes(tty, message)
- char *tty, *message;
+sendmes(const char *tty, const char *message)
{
char t[MAXPATHLEN], buf[BUFSIZ];
- register char *cp;
+ register const char *cp;
int lmsg = 1;
FILE *f_tty;
if (*cp == '\0') {
if (lmsg) {
cp = message;
- if (*cp == '\0')
+ if (!(cp && *cp != '\0'))
break;
lmsg = 0;
} else
time_t tschedule = 0;
void
-timeest()
+timeest(void)
{
time_t tnow, deltat;
}
void
-#if __STDC__
+#ifdef __STDC__
msg(const char *fmt, ...)
#else
msg(fmt, va_alist)
#ifdef TDEBUG
(void) fprintf(stderr, "pid=%d ", getpid());
#endif
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
(void) vfprintf(stderr, fmt, ap);
(void) fflush(stdout);
(void) fflush(stderr);
- (void) vsprintf(lastmsg, fmt, ap);
+ (void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
va_end(ap);
}
void
-#if __STDC__
+#ifdef __STDC__
msgtail(const char *fmt, ...)
#else
msgtail(fmt, va_alist)
#endif
{
va_list ap;
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
}
void
-#if __STDC__
+#ifdef __STDC__
quit(const char *fmt, ...)
#else
quit(fmt, va_alist)
#ifdef TDEBUG
(void) fprintf(stderr, "pid=%d ", getpid());
#endif
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
* we don't actually do it
*/
-struct fstab *
-allocfsent(fs)
- register struct fstab *fs;
+static struct fstab *
+allocfsent(struct fstab *fs)
{
register struct fstab *new;
static struct pfstab *table;
void
-getfstab()
+getfstab(void)
{
register struct fstab *fs;
register struct pfstab *pf;
* The file name can omit the leading '/'.
*/
struct fstab *
-fstabsearch(key)
- char *key;
+fstabsearch(const char *key)
{
register struct pfstab *pf;
register struct fstab *fs;
#ifdef __linux__
struct fstab *
-fstabsearchdir(key, directory)
- char *key;
- char *directory;
+fstabsearchdir(const char *key, char *directory)
{
register struct pfstab *pf;
register struct fstab *fs;
* Tell the operator what to do
*/
void
-lastdump(arg)
- char arg; /* w ==> just what to do; W ==> most recent dumps */
+lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
{
register int i;
register struct fstab *dt;
}
int
-datesort(a1, a2)
- const void *a1, *a2;
+datesort(const void *a1, const void *a2)
{
struct dumpdates *d1 = *(struct dumpdates **)a1;
struct dumpdates *d2 = *(struct dumpdates **)a2;
static char sccsid[] = "@(#)tape.c 8.4 (Berkeley) 5/1/95";
#endif
static const char rcsid[] =
- "$Id: tape.c,v 1.2 1999/10/11 12:53:22 stelian Exp $";
+ "$Id: tape.c,v 1.3 1999/10/11 12:59:19 stelian Exp $";
#endif /* not lint */
#ifdef __linux__
extern char *host;
char *nexttape;
-static int atomic __P((ssize_t (*)(), int, char *, int));
+static ssize_t atomic_read __P((int, void *, size_t));
+static ssize_t atomic_write __P((int, const void *, size_t));
static void doslave __P((int, int));
static void enslave __P((void));
static void flushtape __P((void));
char (*nextblock)[TP_BSIZE];
+static time_t tstart_volume; /* time of volume start */
+static int tapea_volume; /* value of spcl.c_tapea at volume start */
+
int master; /* pid of master, for sending error signals */
int tenths; /* length of tape used per block written */
static int caught; /* have we caught the signal to proceed? */
static int ready; /* have we reached the lock point without having */
/* received the SIGUSR2 signal from the prev slave? */
-static jmp_buf jmpbuf; /* where to jump to if we are ready when the */
+static sigjmp_buf jmpbuf; /* where to jump to if we are ready when the */
/* SIGUSR2 arrives from the previous slave */
int
-alloctape()
+alloctape(void)
{
int pgoff = getpagesize() - 1;
char *buf;
}
void
-writerec(dp, isspcl)
- char *dp;
- int isspcl;
+writerec(const void *dp, int isspcl)
{
slp->req[trecno].dblk = (daddr_t)0;
slp->req[trecno].count = 1;
- *(union u_spcl *)(*(nextblock)++) = *(union u_spcl *)dp;
+ /* XXX post increment triggers an egcs-1.1.2-12 bug on alpha/sparc */
+ *(union u_spcl *)(*(nextblock)) = *(union u_spcl *)dp;
+ nextblock++;
if (isspcl)
lastspclrec = spcl.c_tapea;
trecno++;
}
void
-dumpblock(blkno, size)
- daddr_t blkno;
- int size;
+dumpblock(daddr_t blkno, int size)
{
int avail, tpblks, dblkno;
int nogripe = 0;
-void
-tperror(signo)
- int signo;
+static void
+tperror(int signo)
{
if (pipeout) {
Exit(X_REWRITE);
}
-void
-sigpipe(signo)
- int signo;
+static void
+sigpipe(int signo)
{
quit("Broken pipe\n");
}
+/*
+ * do_stats --
+ * Update xferrate stats
+ */
+time_t
+do_stats(void)
+{
+ time_t tnow, ttaken;
+ int blocks;
+
+ (void)time(&tnow);
+ ttaken = tnow - tstart_volume;
+ blocks = spcl.c_tapea - tapea_volume;
+ msg("Volume %d completed at: %s", tapeno, ctime(&tnow));
+ if (ttaken > 0) {
+ msg("Volume %d took %d:%02d:%02d\n", tapeno,
+ ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60);
+ msg("Volume %d transfer rate: %ld KB/s\n", tapeno,
+ blocks / ttaken);
+ xferrate += blocks / ttaken;
+ }
+ return(tnow);
+}
+
+#if defined(SIGINFO)
+/*
+ * statussig --
+ * information message upon receipt of SIGINFO
+ * (derived from optr.c::timeest())
+ */
+void
+statussig(int notused)
+{
+ time_t tnow, deltat;
+ char msgbuf[128];
+ int save_errno = errno;
+
+ if (blockswritten < 500)
+ return;
+ (void) time((time_t *) &tnow);
+ deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
+ / blockswritten * tapesize;
+ (void)snprintf(msgbuf, sizeof(msgbuf),
+ "%3.2f%% done at %ld KB/s, finished in %d:%02d\n",
+ (blockswritten * 100.0) / tapesize,
+ (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume),
+ (int)(deltat / 3600), (int)((deltat % 3600) / 60));
+ write(STDERR_FILENO, msgbuf, strlen(msgbuf));
+ errno = save_errno;
+}
+#endif
+
static void
-flushtape()
+flushtape(void)
{
int i, blks, got;
long lastfirstrec;
slp->req[trecno].count = 0; /* Sentinel */
- if (atomic(write, slp->fd, (char *)slp->req, siz) != siz)
+ if (atomic_write( slp->fd, (char *)slp->req, siz) != siz)
quit("error writing command pipe: %s\n", strerror(errno));
slp->sent = 1; /* we sent a request, read the response later */
/* Read results back from next slave */
if (slp->sent) {
- if (atomic(read, slp->fd, (char *)&got, sizeof got)
+ if (atomic_read( slp->fd, (char *)&got, sizeof got)
!= sizeof got) {
perror(" DUMP: error reading command pipe in master");
dumpabort(0);
*/
for (i = 0; i < SLAVES; i++) {
if (slaves[i].sent) {
- if (atomic(read, slaves[i].fd,
+ if (atomic_read( slaves[i].fd,
(char *)&got, sizeof got)
!= sizeof got) {
perror(" DUMP: error reading command pipe in master");
}
void
-trewind()
+trewind(void)
{
int f;
int got;
* fixme: punt for now.
*/
if (slaves[f].sent) {
- if (atomic(read, slaves[f].fd, (char *)&got, sizeof got)
+ if (atomic_read( slaves[f].fd, (char *)&got, sizeof got)
!= sizeof got) {
perror(" DUMP: error reading command pipe in master");
dumpabort(0);
}
void
-close_rewind()
+close_rewind(void)
{
time_t tstart_changevol, tend_changevol;
trewind();
+ (void)do_stats();
if (nexttape)
return;
#ifdef __linux__
}
void
-rollforward()
+rollforward(void)
{
register struct req *p, *q, *prev;
register struct slave *tslp;
lastspclrec = savedtapea - 1;
}
size = (char *)ntb - (char *)q;
- if (atomic(write, slp->fd, (char *)q, size) != size) {
+ if (atomic_write( slp->fd, (char *)q, size) != size) {
perror(" DUMP: error writing command pipe");
dumpabort(0);
}
* worked ok, otherwise the tape is much too short!
*/
if (slp->sent) {
- if (atomic(read, slp->fd, (char *)&got, sizeof got)
+ if (atomic_read( slp->fd, (char *)&got, sizeof got)
!= sizeof got) {
perror(" DUMP: error reading command pipe in master");
dumpabort(0);
* everything continues as if nothing had happened.
*/
void
-startnewtape(top)
- int top;
+startnewtape(int top)
{
int parentpid;
int childpid;
int waitpid;
char *p;
#ifdef __linux__
- void (*interrupt_save)();
+ void (*interrupt_save) __P((int signo));
#else /* __linux__ */
#ifdef sunos
void (*interrupt_save)();
interrupt_save = signal(SIGINT, SIG_IGN);
parentpid = getpid();
+ tapea_volume = spcl.c_tapea;
+ (void)time(&tstart_volume);
restore_check_point:
(void)signal(SIGINT, interrupt_save);
spcl.c_flags |= DR_NEWHEADER;
writeheader((ino_t)slp->inode);
spcl.c_flags &=~ DR_NEWHEADER;
+ msg("Volume %d started at: %s", tapeno, ctime(&tstart_volume));
if (tapeno > 1)
msg("Volume %d begins with blocks from inode %d\n",
tapeno, slp->inode);
}
void
-dumpabort(signo)
- int signo;
+dumpabort(int signo)
{
if (master != 0 && master != getpid())
}
void
-Exit(status)
- int status;
+Exit(int status)
{
#ifdef TDEBUG
/*
* proceed - handler for SIGUSR2, used to synchronize IO between the slaves.
*/
-void
-proceed(signo)
- int signo;
+static void
+proceed(int signo)
{
if (ready)
- longjmp(jmpbuf, 1);
+ siglongjmp(jmpbuf, 1);
caught++;
}
void
-enslave()
+enslave(void)
{
int cmd[2];
#ifdef LINUX_FORK_BUG
for (j = 0; j <= i; j++)
(void) close(slaves[j].fd);
signal(SIGINT, SIG_IGN); /* Master handles this */
+#if defined(SIGINFO)
+ signal(SIGINFO, SIG_IGN);
+#endif
+
#ifdef LINUX_FORK_BUG
- if (atomic(write, cmd[0], (char *) &i, sizeof i)
+ if (atomic_write( cmd[0], (char *) &i, sizeof i)
!= sizeof i)
quit("master/slave protocol botched 3\n");
#endif
* returned from fork() causes a SEGV in the child process
*/
for (i = 0; i < SLAVES; i++)
- if (atomic(read, slaves[i].fd, (char *) &j, sizeof j) != sizeof j)
+ if (atomic_read( slaves[i].fd, (char *) &j, sizeof j) != sizeof j)
quit("master/slave protocol botched 4\n");
#endif
for (i = 0; i < SLAVES; i++)
- (void) atomic(write, slaves[i].fd,
+ (void) atomic_write( slaves[i].fd,
(char *) &slaves[(i + 1) % SLAVES].pid,
sizeof slaves[0].pid);
}
void
-killall()
+killall(void)
{
register int i;
* get the lock back for the next cycle by swapping descriptors.
*/
static void
-doslave(cmd, slave_number)
- register int cmd;
- int slave_number;
+doslave(int cmd, int slave_number)
{
register int nread;
- int nextslave, size, wrote, eot_count;
+ int nextslave, size, eot_count;
+ volatile int wrote = 0;
+ sigset_t sigset;
#ifdef __linux__
errcode_t retval;
#endif
/*
* Need the pid of the next slave in the loop...
*/
- if ((nread = atomic(read, cmd, (char *)&nextslave, sizeof nextslave))
+ if ((nread = atomic_read( cmd, (char *)&nextslave, sizeof nextslave))
!= sizeof nextslave) {
quit("master/slave protocol botched - didn't get pid of next slave.\n");
}
/*
* Get list of blocks to dump, read the blocks into tape buffer
*/
- while ((nread = atomic(read, cmd, (char *)slp->req, reqsiz)) == reqsiz) {
+ while ((nread = atomic_read( cmd, (char *)slp->req, reqsiz)) == reqsiz) {
register struct req *p = slp->req;
for (trecno = 0; trecno < ntrec;
bread(p->dblk, slp->tblock[trecno],
p->count * TP_BSIZE);
} else {
- if (p->count != 1 || atomic(read, cmd,
+ if (p->count != 1 || atomic_read( cmd,
(char *)slp->tblock[trecno],
TP_BSIZE) != TP_BSIZE)
quit("master/slave protocol botched.\n");
if (wrote < 0) {
(void) kill(master, SIGUSR1);
+ sigemptyset(&sigset);
for (;;)
- (void) sigpause(0);
+ sigsuspend(&sigset);
} else {
/*
* pass size of write back to master
* (for EOT handling)
*/
- (void) atomic(write, cmd, (char *)&size, sizeof size);
+ (void) atomic_write( cmd, (char *)&size, sizeof size);
}
/*
* or a write may not write all we ask if we get a signal,
* loop until the count is satisfied (or error).
*/
-static int
-atomic(func, fd, buf, count)
- ssize_t (*func)();
- int fd;
- char *buf;
- int count;
+static ssize_t
+atomic_read(int fd, void *buf, size_t count)
+{
+ int got, need = count;
+
+ while ((got = read(fd, buf, need)) > 0 && (need -= got) > 0)
+ (char *)buf += got;
+ return (got < 0 ? got : count - need);
+}
+
+/*
+ * Since a read from a pipe may not return all we asked for,
+ * or a write may not write all we ask if we get a signal,
+ * loop until the count is satisfied (or error).
+ */
+static ssize_t
+atomic_write(int fd, const void *buf, size_t count)
{
int got, need = count;
- while ((got = (*func)(fd, buf, need)) > 0 && (need -= got) > 0)
- buf += got;
+ while ((got = write(fd, buf, need)) > 0 && (need -= got) > 0)
+ (char *)buf += got;
return (got < 0 ? got : count - need);
}
static char sccsid[] = "@(#)traverse.c 8.7 (Berkeley) 6/15/95";
#endif
static const char rcsid[] =
- "$Id: traverse.c,v 1.2 1999/10/11 12:53:22 stelian Exp $";
+ "$Id: traverse.c,v 1.3 1999/10/11 12:59:19 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#ifdef __linux__
#include <linux/ext2_fs.h>
#include <bsdcompat.h>
-#include <err.h>
+#include <compaterr.h>
#include <stdlib.h>
#define swab32(x) ext2fs_swab32(x)
#else /* __linux__ */
+#define swab32(x) x
#ifdef sunos
#include <sys/vnode.h>
#ifdef __linux__
static int searchdir __P((struct ext2_dir_entry *dp, int offset,
int blocksize, char *buf, void *private));
-long long llseek(int fildes, long long offset, int whence);
+loff_t llseek (int fd, loff_t offset, int origin);
#else
static int dirindir __P((ino_t ino, daddr_t blkno, int level, long *size));
static void dmpindir __P((ino_t ino, daddr_t blk, int level, fsizeT *size));
* hence the estimate may be high.
*/
long
-blockest(dp)
- register struct dinode *dp;
+blockest(struct dinode *dp)
{
long blkest, sizeest;
* the directories in the filesystem.
*/
int
-mapfiles(maxino, tapesize)
- ino_t maxino;
- long *tapesize;
+mapfiles(ino_t maxino, long *tapesize)
{
register int mode;
register ino_t ino;
};
static int
-mapfilesindir(dirent, offset, blocksize, buf, private)
- struct ext2_dir_entry *dirent;
- int offset;
- int blocksize;
- char *buf;
- void *private;
+mapfilesindir(struct ext2_dir_entry *dirent, int offset, int blocksize, char *buf, void *private)
{
register struct dinode *dp;
register int mode;
* the directories in the filesystem.
*/
int
-mapfilesfromdir(maxino, tapesize, directory)
- ino_t maxino;
- long *tapesize;
- char *directory;
+mapfilesfromdir(ino_t maxino, long *tapesize, char *directory)
{
errcode_t retval;
struct mapfile_context mfc;
* pass using this algorithm.
*/
int
-mapdirs(maxino, tapesize)
- ino_t maxino;
- long *tapesize;
+mapdirs(ino_t maxino, long *tapesize)
{
register struct dinode *dp;
register int isdir;
* require the directory to be dumped.
*/
static int
-dirindir(ino, blkno, ind_level, filesize)
- ino_t ino;
- daddr_t blkno;
- int ind_level;
- long *filesize;
+dirindir(ino_t ino, daddr_t blkno, int ind_level, long *filesize)
{
int ret = 0;
register int i;
*/
#ifdef __linux__
static int
-searchdir(dp, offset, blocksize, buf, private)
- struct ext2_dir_entry *dp;
- int offset;
- int blocksize;
- char *buf;
- void *private;
+searchdir(struct ext2_dir_entry *dp, int offset, int blocksize, char *buf, void *private)
{
int *ret = (int *) private;
#else /* __linux__ */
static int
-searchdir(ino, blkno, size, filesize)
- ino_t ino;
- daddr_t blkno;
- register long size;
- long filesize;
+searchdir(ino_t ino, daddr_t blkno, long size, long filesize)
{
register struct direct *dp;
register long loc, ret = 0;
* Dump the contents of an inode to tape.
*/
void
-dumpino(dp, ino)
- register struct dinode *dp;
- ino_t ino;
+dumpino(struct dinode *dp, ino_t ino)
{
int cnt;
fsizeT size;
obi.di_gen = dp->di_gen;
memmove(&obi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t));
if (dp->di_file_acl || dp->di_dir_acl)
- warn("ACLs in inode #%d won't be dumped", ino);
+ warn("ACLs in inode #%ld won't be dumped", ino);
memmove(&spcl.c_dinode, &obi, sizeof(obi));
#else /* __linux__ */
spcl.c_dinode = *dp;
* size of the entry, and creates it in a temporary buffer
*/
static int
-convert_dir(dirent, offset, blocksize, buf, private)
- struct ext2_dir_entry *dirent;
- int offset;
- int blocksize;
- char *buf;
- void *private;
+convert_dir(struct ext2_dir_entry *dirent, int offset, int blocksize, char *buf, void *private)
{
struct convert_dir_context *p;
struct direct *dp;
* Dumps a directory to tape after converting it to the BSD format
*/
void
-dumpdirino(dp, ino)
- register struct dinode *dp;
- ino_t ino;
+dumpdirino(struct dinode *dp, ino_t ino)
{
fsizeT size;
char buf[TP_BSIZE];
ext2fs directory to avoid problems ;-) */
cdc.buf = (char *)malloc(dp->di_size * 2 * sizeof(char));
if (cdc.buf == NULL)
- err(1, "Cannot allocate buffer to convert directory #%ld\n",
- ino);
+ err(1, "Cannot allocate buffer to convert directory #%lu\n",
+ (unsigned long)ino);
cdc.offset = 0;
cdc.prev_offset = 0;
cdc.bs = MIN(DIRBLKSIZ, TP_BSIZE);
obi.di_gen = dp->di_gen;
memmove(&obi.di_db, &dp->di_db, (NDADDR + NIADDR) * sizeof(daddr_t));
if (dp->di_file_acl || dp->di_dir_acl)
- warn("ACLs in inode #%d won't be dumped", ino);
+ warn("ACLs in inode #%ld won't be dumped", ino);
memmove(&spcl.c_dinode, &obi, sizeof(obi));
#else /* __linux__ */
spcl.c_dinode = *dp;
* Read indirect blocks, and pass the data blocks to be dumped.
*/
static void
-dmpindir(ino, blk, ind_level, size)
- ino_t ino;
- daddr_t blk;
- int ind_level;
- fsizeT *size;
+dmpindir(ino_t ino, daddr_t blk, int ind_level, fsizeT *size)
{
int i, cnt;
#ifdef __linux__
* Collect up the data into tape record sized buffers and output them.
*/
void
-blksout(blkp, frags, ino)
- daddr_t *blkp;
- int frags;
- ino_t ino;
+blksout(daddr_t *blkp, int frags, ino_t ino)
{
register daddr_t *bp;
int i, j, count, blks, tbperdb;
spcl.c_count = count - i;
writeheader(ino);
bp = &blkp[i / tbperdb];
- for (j = i; j < count; j += tbperdb, bp++)
- if (*bp != 0)
+ for (j = i; j < count; j += tbperdb, bp++) {
+ if (*bp != 0) {
if (j + tbperdb <= count)
dumpblock(*bp, (int)sblock->fs_bsize);
else
dumpblock(*bp, (count - j) * TP_BSIZE);
+ }
+ }
spcl.c_type = TS_ADDR;
}
}
* Dump a map to the tape.
*/
void
-dumpmap(map, type, ino)
- char *map;
- int type;
- ino_t ino;
+dumpmap(char *map, int type, ino_t ino)
{
register int i;
char *cp;
* Write a header record to the dump tape.
*/
void
-writeheader(ino)
- ino_t ino;
+writeheader(ino_t ino)
{
#ifdef __linux__
register __s32 sum, cnt, *lp;
#ifdef __linux__
struct dinode *
-getino(inum)
- ino_t inum;
+getino(ino_t inum)
{
static struct dinode dinode;
}
#else /* __linux__ */
struct dinode *
-getino(inum)
- ino_t inum;
+getino(ino_t inum)
{
static daddr_t minino, maxino;
static struct dinode inoblock[MAXINOPB];
#define BREADEMAX 32
void
-bread(blkno, buf, size)
- daddr_t blkno;
- char *buf;
- int size;
+bread(daddr_t blkno, char *buf, int size)
{
int cnt, i;
extern int errno;
static char sccsid[] = "@(#)unctime.c 8.2 (Berkeley) 6/14/94";
#endif
static const char rcsid[] =
- "$Id: unctime.c,v 1.2 1999/10/11 12:53:23 stelian Exp $";
+ "$Id: unctime.c,v 1.3 1999/10/11 12:59:19 stelian Exp $";
#endif /* not lint */
#include <time.h>
#include <string.h>
#endif
+#include <sys/param.h>
+#include <stdio.h>
+
+#ifdef __linux__
+#include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
+#include <bsdcompat.h>
+#endif
+
+#include "dump.h"
+
/*
* Convert a ctime(3) format string into a system format date.
* Return the date thus calculated.
#define E_SECOND 17
#define E_YEAR 20
-static int lookup __P((char *));
+static int lookup __P((const char *));
time_t
-unctime(str)
- char *str;
+unctime(const char *str)
{
struct tm then;
char dbuf[26];
"JanFebMarAprMayJunJulAugSepOctNovDec";
static int
-lookup(str)
- char *str;
+lookup(const char *str)
{
- register char *cp, *cp2;
+ register const char *cp, *cp2;
for (cp = months, cp2 = str; *cp != '\0'; cp += 3)
if (strncmp(cp, cp2, 3) == 0)
@MCONFIG@
-CFLAGS= @CCOPTS@ -pipe $(DEFS) $(GINC) $(INC) @RESTOREDEBUG@
+CFLAGS= @CCOPTS@ -pipe $(OPT) $(DEFS) $(GINC) $(INC) @RESTOREDEBUG@
LDFLAGS:= $(LDFLAGS) @STATIC@
LIBS= $(GLIBS) -le2p
DEPLIBS= ../compat/lib/libcompat.a
OBJS= dirs.o interactive.o main.o restore.o symtab.o tape.o \
utilities.o ../common/dumprmt.o
MAN8= restore.8
-MLINKS= $(MANDIR)/restore.8 $(MANDIR)/rrestore.8
+MLINKS= restore.8 $(MANDIR)/rrestore.8
all:: $(PROG)
static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
#endif
static const char rcsid[] =
- "$Id: dirs.c,v 1.2 1999/10/11 12:53:23 stelian Exp $";
+ "$Id: dirs.c,v 1.3 1999/10/11 12:59:19 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#endif /* __linux__ */
#include <protocols/dumprestore.h>
-#include <err.h>
+#include <compaterr.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
mode_t mode;
uid_t uid;
gid_t gid;
- int flags;
+ unsigned int flags;
};
/*
static void flushent __P((void));
static struct inotab *inotablookup __P((ino_t));
static RST_DIR *opendirfile __P((const char *));
-static void putdir __P((char *, long));
+static void putdir __P((char *, size_t));
static void putent __P((struct direct *));
static void rst_seekdir __P((RST_DIR *, long, long));
static long rst_telldir __P((RST_DIR *));
* directories on the tape.
*/
void
-extractdirs(genmode)
- int genmode;
+extractdirs(int genmode)
{
register int i;
#ifdef __linux__
struct direct nulldir;
int fd;
- vprintf(stdout, "Extract directories from tape\n");
- (void) sprintf(dirfile, "%s/rstdir%ld", tmpdir, dumpdate);
+ Vprintf(stdout, "Extract directories from tape\n");
+ (void) snprintf(dirfile, sizeof(dirfile), "%s/rstdir%ld", tmpdir,
+ (long)dumpdate);
if (command != 'r' && command != 'R') {
- (void *) strcat(dirfile, "-XXXXXX");
+ (void) strncat(dirfile, "-XXXXXX",
+ sizeof(dirfile) - strlen(dirfile));
fd = mkstemp(dirfile);
} else
fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
if (fd != -1)
close(fd);
- warn("%s - cannot create directory temporary\nfopen", dirfile);
- done(1);
+ err(1, "cannot create directory temporary %s", dirfile);
}
if (genmode != 0) {
- (void) sprintf(modefile, "%s/rstmode%ld", tmpdir, dumpdate);
+ (void) snprintf(modefile, sizeof(modefile), "%s/rstmode%ld", tmpdir, (long)dumpdate);
if (command != 'r' && command != 'R') {
- (void *) strcat(modefile, "-XXXXXX");
+ (void) strncat(modefile, "-XXXXXX",
+ sizeof(modefile) - strlen(modefile));
fd = mkstemp(modefile);
} else
fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
if (fd != -1)
close(fd);
- warn("%s - cannot create modefile\nfopen", modefile);
- done(1);
+ err(1, "cannot create modefile %s", modefile);
}
}
nulldir.d_ino = 0;
nulldir.d_type = DT_DIR;
nulldir.d_namlen = 1;
- (void) strcpy(nulldir.d_name, "/");
+ nulldir.d_name[0] = '/';
+ nulldir.d_name[1] = '\0';
nulldir.d_reclen = DIRSIZ(0, &nulldir);
for (;;) {
curfile.name = "<directory file - name unknown>";
(void) fclose(df);
dirp = opendirfile(dirfile);
if (dirp == NULL)
- fprintf(stderr, "opendirfile: %s\n",
- strerror(errno));
+ warn("opendirfile");
if (mf != NULL)
(void) fclose(mf);
i = dirlookup(dot);
* skip over all the directories on the tape
*/
void
-skipdirs()
+skipdirs(void)
{
while (curfile.dip && (curfile.dip->di_mode & IFMT) == IFDIR) {
* pname and pass them off to be processed.
*/
void
-treescan(pname, ino, todo)
- char *pname;
- ino_t ino;
- long (*todo) __P((char *, ino_t, int));
+treescan(char *pname, ino_t ino, long (*todo) __P((char *, ino_t, int)))
{
register struct inotab *itp;
register struct direct *dp;
* begin search through the directory
* skipping over "." and ".."
*/
- (void) strncpy(locname, pname, sizeof(locname) - 1);
- locname[sizeof(locname) - 1] = '\0';
- (void) strncat(locname, "/", sizeof(locname) - strlen(locname));
- namelen = strlen(locname);
+ namelen = snprintf(locname, sizeof(locname), "%s/", pname);
+ if (namelen >= sizeof(locname))
+ namelen = sizeof(locname) - 1;
rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
dp = rst_readdir(dirp); /* "." */
if (dp != NULL && strcmp(dp->d_name, ".") == 0)
while (dp != NULL) {
locname[namelen] = '\0';
if (namelen + dp->d_namlen >= sizeof(locname)) {
- fprintf(stderr, "%s%s: name exceeds %d char\n",
- locname, dp->d_name, sizeof(locname) - 1);
+ fprintf(stderr, "%s%s: name exceeds %ld char\n",
+ locname, dp->d_name, (long)sizeof(locname) - 1);
} else {
(void) strncat(locname, dp->d_name, (int)dp->d_namlen);
treescan(locname, dp->d_ino, todo);
* Lookup a pathname which is always assumed to start from the ROOTINO.
*/
struct direct *
-pathsearch(pathname)
- const char *pathname;
+pathsearch(const char *pathname)
{
ino_t ino;
struct direct *dp;
while (*path == '/')
path++;
dp = NULL;
- while ((name = strsep(&path, "/")) != NULL && *name != '\0') {
+ while ((name = strsep(&path, "/")) != NULL && *name /* != NULL */) {
if ((dp = searchdir(ino, name)) == NULL)
return (NULL);
ino = dp->d_ino;
* Return its inode number if found, zero if it does not exist.
*/
static struct direct *
-searchdir(inum, name)
- ino_t inum;
- char *name;
+searchdir(ino_t inum, char *name)
{
register struct direct *dp;
register struct inotab *itp;
* Put the directory entries in the directory file
*/
static void
-putdir(buf, size)
- char *buf;
- long size;
+putdir(char *buf, size_t size)
{
struct direct cvtbuf;
register struct odirect *odp;
dp->d_reclen, dp->d_namlen, dp->d_type);
#endif
if (Bcvt)
- swabst((u_char *)"ls", (u_char *) dp);
+ swabst((u_char *)"is", (u_char *) dp);
if (oldinofmt && dp->d_ino != 0) {
#ifdef __linux__
if (Bcvt)
dp->d_reclen > i ||
dp->d_reclen < DIRSIZ(0, dp) ||
dp->d_namlen > NAME_MAX) {
- vprintf(stdout, "Mangled directory: ");
+ Vprintf(stdout, "Mangled directory: ");
if ((dp->d_reclen & 0x3) != 0)
- vprintf(stdout,
+ Vprintf(stdout,
"reclen not multiple of 4 ");
if (dp->d_reclen < DIRSIZ(0, dp))
- vprintf(stdout,
+ Vprintf(stdout,
"reclen less than DIRSIZ (%d < %d) ",
dp->d_reclen, DIRSIZ(0, dp));
if (dp->d_namlen > NAME_MAX)
- vprintf(stdout,
+ Vprintf(stdout,
"reclen name too big (%d > %d) ",
dp->d_namlen, NAME_MAX);
- vprintf(stdout, "\n");
+ Vprintf(stdout, "\n");
loc += i;
continue;
}
* add a new directory entry to a file.
*/
static void
-putent(dp)
- struct direct *dp;
+putent(struct direct *dp)
{
dp->d_reclen = DIRSIZ(0, dp);
if (dirloc + dp->d_reclen > DIRBLKSIZ) {
(void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
dirloc = 0;
}
- memmove(dirbuf + dirloc, dp, (long)dp->d_reclen);
+ memmove(dirbuf + dirloc, dp, (size_t)dp->d_reclen);
prev = dirloc;
dirloc += dp->d_reclen;
}
* flush out a directory that is finished.
*/
static void
-flushent()
+flushent(void)
{
((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev;
(void) fwrite(dirbuf, (int)dirloc, 1, df);
}
static void
-dcvt(odp, ndp)
- register struct odirect *odp;
- register struct direct *ndp;
+dcvt(struct odirect *odp, struct direct *ndp)
{
- memset(ndp, 0, (long)(sizeof *ndp));
+ memset(ndp, 0, (size_t)(sizeof *ndp));
ndp->d_ino = odp->d_ino;
ndp->d_type = DT_UNKNOWN;
(void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
* the desired seek offset into it.
*/
static void
-rst_seekdir(dirp, loc, base)
- register RST_DIR *dirp;
- long loc, base;
+rst_seekdir(RST_DIR *dirp, long loc, long base)
{
if (loc == rst_telldir(dirp))
* get next entry in a directory.
*/
struct direct *
-rst_readdir(dirp)
- register RST_DIR *dirp;
+rst_readdir(RST_DIR *dirp)
{
register struct direct *dp;
dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
DIRBLKSIZ);
if (dirp->dd_size <= 0) {
- dprintf(stderr, "error reading directory\n");
+ Dprintf(stderr, "error reading directory\n");
return (NULL);
}
}
dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
if (dp->d_reclen == 0 ||
dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) {
- dprintf(stderr, "corrupted directory: bad reclen %d\n",
+ Dprintf(stderr, "corrupted directory: bad reclen %d\n",
dp->d_reclen);
return (NULL);
}
if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0)
return (NULL);
if (dp->d_ino >= maxino) {
- dprintf(stderr, "corrupted directory: bad inum %d\n",
+ Dprintf(stderr, "corrupted directory: bad inum %d\n",
dp->d_ino);
continue;
}
* Simulate the opening of a directory
*/
RST_DIR *
-rst_opendir(name)
- const char *name;
+rst_opendir(const char *name)
{
struct inotab *itp;
RST_DIR *dirp;
* In our case, there is nothing to do when closing a directory.
*/
void
-rst_closedir(dirp)
- RST_DIR *dirp;
+rst_closedir(RST_DIR *dirp)
{
(void)close(dirp->dd_fd);
* Simulate finding the current offset in the directory.
*/
static long
-rst_telldir(dirp)
- RST_DIR *dirp;
+rst_telldir(RST_DIR *dirp)
{
return ((long)lseek(dirp->dd_fd,
(off_t)0, SEEK_CUR) - dirp->dd_size + dirp->dd_loc);
* Open a directory file.
*/
static RST_DIR *
-opendirfile(name)
- const char *name;
+opendirfile(const char *name)
{
register RST_DIR *dirp;
register int fd;
* Set the mode, owner, and times for all new or changed directories
*/
void
-setdirmodes(flags)
- int flags;
+setdirmodes(int flags)
{
FILE *mf;
struct modeinfo node;
struct entry *ep;
char *cp;
- vprintf(stdout, "Set directory mode, owner, and times.\n");
+ Vprintf(stdout, "Set directory mode, owner, and times.\n");
if (command == 'r' || command == 'R')
- (void) sprintf(modefile, "%s/rstmode%ld", tmpdir, dumpdate);
+ (void) snprintf(modefile, sizeof(modefile), "%s/rstmode%lu", tmpdir, (long)dumpdate);
if (modefile[0] == '#') {
panic("modefile not defined\n");
fprintf(stderr, "directory mode, owner, and times not set\n");
}
mf = fopen(modefile, "r");
if (mf == NULL) {
- fprintf(stderr, "fopen: %s\n", strerror(errno));
+ warn("fopen");
fprintf(stderr, "cannot open mode file %s\n", modefile);
fprintf(stderr, "directory mode, owner, and times not set\n");
return;
* Generate a literal copy of a directory.
*/
int
-genliteraldir(name, ino)
- char *name;
- ino_t ino;
+genliteraldir(char *name, ino_t ino)
{
register struct inotab *itp;
int ofile, dp, i, size;
if (itp == NULL)
panic("Cannot find directory inode %d named %s\n", ino, name);
if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
- fprintf(stderr, "%s: ", name);
- (void) fflush(stderr);
- fprintf(stderr, "cannot create file: %s\n", strerror(errno));
+ warn("%s: cannot create file\n", name);
return (FAIL);
}
rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
for (i = itp->t_size; i > 0; i -= BUFSIZ) {
size = i < BUFSIZ ? i : BUFSIZ;
if (read(dp, buf, (int) size) == -1) {
- fprintf(stderr,
- "write error extracting inode %ld, name %s\n",
- curfile.ino, curfile.name);
- fprintf(stderr, "read: %s\n", strerror(errno));
- done(1);
+ warnx("write error extracting inode %lu, name %s\n",
+ (unsigned long)curfile.ino, curfile.name);
+ err(1, "read");
}
if (!Nflag && write(ofile, buf, (int) size) == -1) {
- fprintf(stderr,
- "write error extracting inode %ld, name %s\n",
- curfile.ino, curfile.name);
- fprintf(stderr, "write: %s\n", strerror(errno));
- done(1);
+ warnx("write error extracting inode %lu, name %s\n",
+ (unsigned long)curfile.ino, curfile.name);
+ err(1, "write");
}
}
(void) close(dp);
* Determine the type of an inode
*/
int
-inodetype(ino)
- ino_t ino;
+inodetype(ino_t ino)
{
struct inotab *itp;
* If requested, save its pertinent mode, owner, and time info.
*/
static struct inotab *
-allocinotab(ino, dip, seekpt)
- ino_t ino;
#ifdef __linux__
- struct new_bsd_inode *dip;
+allocinotab(ino_t ino, struct new_bsd_inode *dip, long seekpt)
#else
- struct dinode *dip;
+allocinotab(ino_t ino, struct dinode *dip, long seekpt)
#endif
- long seekpt;
{
register struct inotab *itp;
struct modeinfo node;
* Look up an inode in the table of directories
*/
static struct inotab *
-inotablookup(ino)
- ino_t ino;
+inotablookup(ino_t ino)
{
register struct inotab *itp;
* Clean up and exit
*/
void
-done(exitcode)
- int exitcode;
+cleanup(void)
{
-
closemt();
if (modefile[0] != '#')
(void) unlink(modefile);
if (dirfile[0] != '#')
(void) unlink(dirfile);
- exit(exitcode);
}
* SUCH DAMAGE.
*
* @(#)extern.h 8.2 (Berkeley) 1/7/94
- * $Id: extern.h,v 1.2 1999/10/11 12:53:23 stelian Exp $
+ * $Id: extern.h,v 1.3 1999/10/11 12:59:20 stelian Exp $
*/
struct entry *addentry __P((char *, ino_t, int));
long addfile __P((char *, ino_t, int));
int addwhiteout __P((char *));
-void badentry __P((struct entry *, char *));
+void badentry __P((struct entry *, const char *));
void canon __P((char *, char *, int));
void checkrestore __P((void));
void closemt __P((void));
+void cleanup __P((void));
void comparefile __P((char *));
void compareleaves __P((void));
void createfiles __P((void));
void deleteino __P((ino_t));
void delwhiteout __P((struct entry *));
ino_t dirlookup __P((const char *));
-__dead void done __P((int));
void dumpsymtable __P((char *, long));
void extractdirs __P((int));
int extractfile __P((char *));
void freename __P((char *));
int genliteraldir __P((char *, ino_t));
char *gentempname __P((struct entry *));
-void getfile __P((void (*)(char *, long), void (*)(char *, long)));
+void getfile __P((void (*)(char *, size_t), void (*)(char *, size_t)));
void getvol __P((long));
void initsymtable __P((char *));
int inodetype __P((ino_t));
void removeoldleaves __P((void));
void removeoldnodes __P((void));
void renameit __P((char *, char *));
-int reply __P((char *));
+int reply __P((const char *));
RST_DIR *rst_opendir __P((const char *));
struct direct *rst_readdir __P((RST_DIR *));
void rst_closedir __P((RST_DIR *dirp));
void treescan __P((char *, ino_t, long (*)(char *, ino_t, int)));
ino_t upperbnd __P((ino_t));
long verifyfile __P((char *, ino_t, int));
-void xtrnull __P((char *, long));
+void xtrnull __P((char *, size_t));
/* From ../dump/dumprmt.c */
void rmtclose __P((void));
-int rmthost __P((char *));
+int rmthost __P((const char *));
int rmtioctl __P((int, int));
-int rmtopen __P((char *, int));
-int rmtread __P((char *, int));
+int rmtopen __P((const char *, int));
+int rmtread __P((const char *, int));
int rmtseek __P((int, int));
static char sccsid[] = "@(#)interactive.c 8.5 (Berkeley) 5/1/95";
#endif
static const char rcsid[] =
- "$Id: interactive.c,v 1.2 1999/10/11 12:53:23 stelian Exp $";
+ "$Id: interactive.c,v 1.3 1999/10/11 12:59:20 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <protocols/dumprestore.h>
#include <setjmp.h>
-#include <glob.h>
+#include <compaterr.h>
+#include <errno.h>
+#include <compatglob.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __linux__
#include <ext2fs/ext2fs.h>
+extern char * __progname;
#endif
#include "restore.h"
* Read and execute commands from the terminal.
*/
void
-runcmdshell()
+runcmdshell(void)
{
register struct entry *np;
ino_t ino;
fprintf(stderr, "%s: not a directory\n", name);
break;
}
- (void) strcpy(curdir, name);
+ (void) strncpy(curdir, name, sizeof(curdir));
+ curdir[sizeof(curdir) - 1] = '\0';
break;
/*
* Delete elements from the extraction list.
* eliminate any embedded ".." components.
*/
static void
-getcmd(curdir, cmd, name, size, ap)
- char *curdir, *cmd, *name;
- struct arglist *ap;
- int size;
+getcmd(char *curdir, char *cmd, char *name, int size, struct arglist *ap)
{
register char *cp;
static char input[BUFSIZ];
* Read a command line and trim off trailing white space.
*/
do {
- fprintf(stderr, "restore > ");
+ fprintf(stderr, "%s > ", __progname);
(void) fflush(stderr);
(void) fgets(input, BUFSIZ, terminal);
} while (!feof(terminal) && input[0] == '\n');
* Strip off the next token of the input.
*/
static char *
-copynext(input, output)
- char *input, *output;
+copynext(char *input, char *output)
{
register char *cp, *bp;
char quote;
* remove any embedded "." and ".." components.
*/
void
-canon(rawname, canonname, len)
- char *rawname, *canonname;
- int len;
+canon(char *rawname, char *canonname, int len)
{
register char *cp, *np;
(void) strcpy(canonname, ".");
else
(void) strcpy(canonname, "./");
- if (strlen(canonname) + strlen(rawname) >= len) {
- fprintf(stderr, "canonname: not enough buffer space\n");
- done(1);
- }
+ if (strlen(canonname) + strlen(rawname) >= len)
+ errx(1, "canonname: not enough buffer space");
(void) strcat(canonname, rawname);
/*
* Do an "ls" style listing of a directory
*/
static void
-printlist(name, basename)
- char *name;
- char *basename;
+printlist(char *name, char *basename)
{
- register struct afile *fp, *list, *listp=NULL;
+ register struct afile *fp, *list, *listp = NULL;
register struct direct *dp;
struct afile single;
RST_DIR *dirp;
fprintf(stderr, "%s:\n", name);
entries = 0;
listp = list;
- (void) strncpy(locname, name, MAXPATHLEN);
- (void) strncat(locname, "/", MAXPATHLEN);
- namelen = strlen(locname);
+ namelen = snprintf(locname, sizeof(locname), "%s/", name);
+ if (namelen >= sizeof(locname))
+ namelen = sizeof(locname) - 1;
while ((dp = rst_readdir(dirp))) {
if (dp == NULL)
break;
* Read the contents of a directory.
*/
static void
-mkentry(name, dp, fp)
- char *name;
- struct direct *dp;
- register struct afile *fp;
+mkentry(char *name, struct direct *dp, struct afile *fp)
{
char *cp;
struct entry *np;
* Print out a pretty listing of a directory
*/
static void
-formatf(list, nentry)
- register struct afile *list;
- int nentry;
+formatf(struct afile *list, int nentry)
{
register struct afile *fp, *endlist;
int width, bigino, haveprefix, havepostfix;
- int i, j, w, precision=0, columns, lines;
+ int i, j, w, precision = 0, columns, lines;
width = 0;
haveprefix = 0;
#endif /* __linux__ */
struct dirent *
-glob_readdir(dirp)
- RST_DIR *dirp;
+glob_readdir(RST_DIR *dirp)
{
struct direct *dp;
static struct dirent adirent;
* Return st_mode information in response to stat or lstat calls
*/
static int
-glob_stat(name, stp)
- const char *name;
- struct stat *stp;
+glob_stat(const char *name, struct stat *stp)
{
register struct direct *dp;
* Comparison routine for qsort.
*/
static int
-fcmp(f1, f2)
- register const void *f1, *f2;
+fcmp(const void *f1, const void *f2)
{
return (strcmp(((struct afile *)f1)->fname,
((struct afile *)f2)->fname));
* respond to interrupts
*/
void
-onintr(signo)
- int signo;
+onintr(int signo)
{
+ int save_errno = errno;
+
if (command == 'i' && runshell)
longjmp(reset, 1);
if (reply("restore interrupted, continue") == FAIL)
- done(1);
+ exit(1);
+ errno = save_errno;
}
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
- "$Id: main.c,v 1.2 1999/10/11 12:53:23 stelian Exp $";
+ "$Id: main.c,v 1.3 1999/10/11 12:59:20 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#endif /* __linux__ */
#include <protocols/dumprestore.h>
-#include <err.h>
+#include <compaterr.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
time_t dumptime;
time_t dumpdate;
FILE *terminal;
+char *tmpdir;
int compare_ignore_not_found;
char *filesys = NULL;
-char *tmpdir = _PATH_TMP;
#ifdef __linux__
char *__progname;
static void usage __P((void));
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int ch;
ino_t ino;
- char *inputdev;
+ char *inputdev = _PATH_DEFTAPE;
char *symtbl = "./restoresymtable";
char *p, name[MAXPATHLEN];
if ((inputdev = getenv("TAPE")) == NULL)
inputdev = _PATH_DEFTAPE;
+ if ((tmpdir = getenv("TMPDIR")) == NULL)
+ tmpdir = _PATH_TMP;
+ if ((tmpdir = strdup(tmpdir)) == NULL)
+ err(1, "malloc tmpdir");
+ for (p = tmpdir + strlen(tmpdir) - 1; p >= tmpdir && *p == '/'; p--)
+ ;
obsolete(&argc, &argv);
#ifdef KERBEROS
-#define optlist "b:CcdDf:hikmNRrs:tTuvxy"
+#define optlist "b:CcdD:f:hikmNRrs:tT:uvxy"
#else
-#define optlist "b:CcdDf:himNRrs:tTuvxy"
+#define optlist "b:CcdD:f:himNRrs:tT:uvxy"
#endif
while ((ch = getopt(argc, argv, optlist)) != -1)
switch(ch) {
(void) signal(SIGTERM, SIG_IGN);
setlinebuf(stderr);
+ atexit(cleanup);
+
setinput(inputdev);
if (argc == 0) {
case 'C': {
struct stat stbuf;
- vprintf(stdout, "Begin compare restore\n");
+ Vprintf(stdout, "Begin compare restore\n");
compare_ignore_not_found = 0;
setup();
printf("filesys = %s\n", filesys);
- if (stat(filesys, &stbuf) < 0) {
- fprintf(stderr, "cannot stat directory %s: %s\n",
- filesys, strerror(errno));
- exit(1);
- } else {
- if (chdir(filesys) < 0) {
- fprintf(stderr, "cannot cd to %s: %s\n",
- filesys, strerror(errno));
- exit(1);
- }
- }
+ if (stat(filesys, &stbuf) < 0)
+ err(1, "cannot stat directory %s", filesys);
+ if (chdir(filesys) < 0)
+ err(1, "cannot cd to %s", filesys);
compare_ignore_not_found = dumptime > 0;
initsymtable((char *)0);
extractdirs(0);
/*
* This is an incremental dump tape.
*/
- vprintf(stdout, "Begin incremental restore\n");
+ Vprintf(stdout, "Begin incremental restore\n");
initsymtable(symtbl);
extractdirs(1);
removeoldleaves();
- vprintf(stdout, "Calculate node updates.\n");
+ Vprintf(stdout, "Calculate node updates.\n");
treescan(".", ROOTINO, nodeupdates);
findunreflinks();
removeoldnodes();
/*
* This is a level zero dump tape.
*/
- vprintf(stdout, "Begin level 0 restore\n");
+ Vprintf(stdout, "Begin level 0 restore\n");
initsymtable((char *)0);
extractdirs(1);
- vprintf(stdout, "Calculate extraction list.\n");
+ Vprintf(stdout, "Calculate extraction list.\n");
treescan(".", ROOTINO, nodeupdates);
}
createleaves(symtbl);
setdirmodes(FORCE);
checkrestore();
if (dflag) {
- vprintf(stdout, "Verify the directory structure\n");
+ Vprintf(stdout, "Verify the directory structure\n");
treescan(".", ROOTINO, verifyfile);
}
dumpsymtable(symtbl, (long)1);
checkrestore();
break;
}
- done(0);
+ exit(0);
/* NOTREACHED */
- exit(1); /* gcc shut up */
+ return 0; /* gcc shut up */
}
static void
-usage()
+usage(void)
{
(void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
"restore -i [-chkmuvy] [-b blocksize] [-f file] [-s fileno]",
"restore -R [-ckuvy] [-b blocksize] [-f file] [-s fileno]",
"restore -x [-chkmuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
"restore -t [-chkuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
- done(1);
+ exit(1);
}
/*
* getopt(3) will like.
*/
static void
-obsolete(argcp, argvp)
- int *argcp;
- char **argvp[];
+obsolete(int *argcp, char **argvp[])
{
int argc, flags;
- char *ap, **argv, *flagsp=NULL, **nargv, *p=NULL;
+ char *ap, **argv, *flagsp = NULL, **nargv, *p = NULL;
/* Setup. */
argv = *argvp;
/* Allocate space for new arguments. */
if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
(p = flagsp = malloc(strlen(ap) + 2)) == NULL)
- err(1, NULL);
+ err(1, "malloc args");
*nargv++ = *argv;
argv += 2, argc -= 2;
usage();
}
if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
- err(1, NULL);
+ err(1, "malloc arg");
nargv[0][0] = '-';
nargv[0][1] = *ap;
(void)strcpy(&nargv[0][2], *argv);
.\" SUCH DAMAGE.
.\"
.\" @(#)restore.8 8.4 (Berkeley) 5/1/95
-.\" $Id: restore.8,v 1.2 1999/10/11 12:53:24 stelian Exp $
+.\" $Id: restore.8,v 1.3 1999/10/11 12:59:20 stelian Exp $
.\"
.Dd May 1, 1995
.Dt RESTORE 8
.in -\\n(iSu
(The
.Bx 4.3
-option syntax is implemented for backward compatibility, but
+option syntax is implemented for backward compatibility but
is not documented here.)
.Sh DESCRIPTION
The
(unless the
.Fl h
flag is specified on the command line).
-Files that are on the extraction list are prepended with a ``*''
+Files that are on the extraction list are prepended with a
+.Dq \&*
when they are listed by
.Ic ls .
.It Ic \&cd Ar arg
is to add the directory to the extraction list and then delete
those files that are not needed.
.It Ic extract
-All the files that are on the extraction list are extracted
+All files on the extraction list are extracted
from the dump.
.Nm Restore
will ask which volume the user wishes to mount.
The fastest way to extract a few files is to
-start with the last volume, and work towards the first volume.
+start with the last volume and work towards the first volume.
.It Ic help
List a summary of the available commands.
.It Ic \&ls Op Ar arg
List the current or specified directory.
-Entries that are directories are appended with a ``/''.
+Entries that are directories are appended with a
+.Dq \&* .
Entries that have been marked for extraction are prepended with a ``*''.
If the verbose
-flag is set the inode number of each entry is also listed.
+flag is set, the inode number of each entry is also listed.
.It Ic pwd
Print the full pathname of the current working directory.
.It Ic quit
Restore immediately exits,
even if the extraction list is not empty.
.It Ic setmodes
-All the directories that have been added to the extraction list
+All directories that have been added to the extraction list
have their owner, modes, and times set;
nothing is extracted from the dump.
This is useful for cleaning up after a restore has been prematurely aborted.
.El
.It Fl R
.Nm Restore
-requests a particular tape of a multi volume set on which to restart
+requests a particular tape of a multi-volume set on which to restart
a full restore
(see the
.Fl r
flag below).
This is useful if the restore has been interrupted.
.It Fl r
-Restore (rebuild a file system).
+Restore (rebuild) a file system.
The target file system should be made pristine with
.Xr newfs 8 ,
-mounted and the user
+mounted, and the user
.Xr cd Ns 'd
into the pristine file system
before starting the restoration of the initial level 0 backup. If the
The
.Fl r
flag precludes an interactive file extraction and can be
-detrimental to one's health if not used carefully (not to mention
-the disk). An example:
+detrimental to one's health (not to mention the disk) if not used carefully.
+An example:
.Bd -literal -offset indent
newfs /dev/rrp0g eagle
mount /dev/rp0g /mnt
The names of the specified files are listed if they occur
on the backup.
If no file argument is given,
-then the root directory is listed,
+the root directory is listed,
which results in the entire content of the
backup being listed,
unless the
The owner, modification time,
and mode are restored (if possible).
If no file argument is given,
-then the root directory is extracted,
+the root directory is extracted,
which results in the entire content of the
backup being extracted,
unless the
.Ar file
may be a special device file
like
-.Pa /dev/rmt12
+.Pa /dev/st0
(a tape drive),
.Pa /dev/rsd1c
(a disk drive),
.Ql Fl
(the standard input).
If the name of the file is of the form
-.Dq host:file ,
+.Dq host:file
or
.Dq user@host:file ,
.Nm restore
Always try to skip over the bad block(s) and continue.
.El
.Sh DIAGNOSTICS
-Complaints if it gets a read error.
+Complains if it gets a read error.
If
.Fl y
has been specified, or the user responds
.Pp
There are numerous consistency checks that can be listed by
.Nm restore .
-Most checks are self-explanatory or can ``never happen''.
+Most checks are self-explanatory or can
+.Dq never happen .
Common errors are given below.
.Pp
.Bl -tag -width Ds -compact
-.It Converting to new file system format.
+.It Converting to new file system format
A dump tape created from the old file system has been loaded.
It is automatically converted to the new file system format.
.Pp
This can occur when using a dump created on an active file system.
.Pp
.It Incremental dump too low
-When doing incremental restore,
+When doing an incremental restore,
a dump that was written before the previous incremental dump,
or that has too low an incremental level has been loaded.
.Pp
.It Incremental dump too high
-When doing incremental restore,
+When doing an incremental restore,
a dump that does not begin its coverage where the previous incremental
dump left off,
or that has too high an incremental level has been loaded.
.It Tape read error while trying to resynchronize
A tape (or other media) read error has occurred.
If a file name is specified,
-then its contents are probably partially wrong.
+its contents are probably partially wrong.
If an inode is being skipped or the tape is trying to resynchronize,
-then no extracted files have been corrupted,
+no extracted files have been corrupted,
though files may not be found on the tape.
.Pp
.It resync restore, skipped <num> blocks
This message lists the number of blocks that were skipped over.
.El
.Sh ENVIRONMENT
-.Bl -tag -width Fl
+If the following environment variable exists it will be utilized by
+.Nm restore :
+.Pp
+.Bl -tag -width "TMPDIR" -compact
.It Ev TAPE
If no -f option was specified,
.Nm
.Ev TAPE
may be of the form
.Qq tapename ,
-.Qq host:tapename ,
+.Qq host:tapename
or
.Qq user@host:tapename .
+.It Ev TMPDIR
+The directory given in
+.Ev TMPDIR
+will be used
+instead of
+.Pa /tmp
+to store temporary files.
.It Ev RMT
The environment variable
.Ev RMT
program.
.Sh FILES
.Bl -tag -width "./restoresymtable" -compact
-.It Pa /dev/rmt?
+.It Pa /dev/st0
the default tape drive
.It Pa /tmp/rstdir*
-file containing directories on the tape.
+file containing directories on the tape
.It Pa /tmp/rstmode*
-owner, mode, and time stamps for directories.
+owner, mode, and time stamps for directories
.It Pa \&./restoresymtable
-information passed between incremental restores.
+information passed between incremental restores
.El
.Sh SEE ALSO
.Xr dump 8 ,
can get confused when doing incremental restores from
dumps that were made on active file systems.
.Pp
-A level zero dump must be done after a full restore.
-Because restore runs in user code,
+A level 0 dump must be done after a full restore.
+Because
+.Nm restore
+runs in user code,
it has no control over inode allocation;
thus a full dump must be done to get a new set of directories
reflecting the new inode numbering,
-even though the contents of the files is unchanged.
+even though the content of the files is unchanged.
+.Pp
+The temporary files
+.Pa /tmp/rstdir*
+and
+.Pa /tmp/rstmode*
+are generated with a unique name based on the date of the dump
+and the process ID (see
+.Xr mktemp 3 ),
+except when
+.Fl r
+or
+.Fl R
+is used.
+Because
+.Fl R
+allows you to restart a
+.Fl r
+operation that may have been interrupted, the temporary files should
+be the same across different processes.
+In all other cases, the files are unique because it is possible to
+have two different dumps started at the same time, and separate
+operations shouldn't conflict with each other.
.Pp
To do a network restore, you have to run restore as root. This is due
to the previous security history of dump and restore. (restore is
static char sccsid[] = "@(#)restore.c 8.3 (Berkeley) 9/13/94";
#endif
static const char rcsid[] =
- "$Id: restore.c,v 1.2 1999/10/11 12:53:24 stelian Exp $";
+ "$Id: restore.c,v 1.3 1999/10/11 12:59:20 stelian Exp $";
#endif /* not lint */
#include <sys/types.h>
#ifdef __linux__
+#include <sys/param.h>
#include <sys/time.h>
#include <linux/ext2_fs.h>
#include <bsdcompat.h>
* List entries on the tape.
*/
long
-listfile(name, ino, type)
- char *name;
- ino_t ino;
- int type;
+listfile(char *name, ino_t ino, int type)
{
long descend = hflag ? GOOD : FAIL;
if (TSTINO(ino, dumpmap) == 0)
return (descend);
- vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
- fprintf(stdout, "%10ld\t%s\n", ino, name);
+ Vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
+ fprintf(stdout, "%10lu\t%s\n", (unsigned long)ino, name);
return (descend);
}
* Request that new entries be extracted.
*/
long
-addfile(name, ino, type)
- char *name;
- ino_t ino;
- int type;
+addfile(char *name, ino_t ino, int type)
{
register struct entry *ep;
long descend = hflag ? GOOD : FAIL;
char buf[100];
if (TSTINO(ino, dumpmap) == 0) {
- dprintf(stdout, "%s: not on the tape\n", name);
+ Dprintf(stdout, "%s: not on the tape\n", name);
return (descend);
}
if (ino == WINO && command == 'i' && !vflag)
return (descend);
if (!mflag) {
- (void) sprintf(buf, "./%lu", ino);
+ (void) snprintf(buf, sizeof(buf), "./%lu", (unsigned long)ino);
name = buf;
if (type == NODE) {
(void) genliteraldir(name, ino);
*/
/* ARGSUSED */
long
-deletefile(name, ino, type)
- char *name;
- ino_t ino;
- int type;
+deletefile(char *name, ino_t ino, int type)
{
long descend = hflag ? GOOD : FAIL;
struct entry *ep;
* Remove directories from the lookup chains.
*/
void
-removeoldleaves()
+removeoldleaves(void)
{
register struct entry *ep, *nextep;
register ino_t i, mydirino;
- vprintf(stdout, "Mark entries to be removed.\n");
+ Vprintf(stdout, "Mark entries to be removed.\n");
if ((ep = lookupino(WINO))) {
- vprintf(stdout, "Delete whiteouts\n");
+ Vprintf(stdout, "Delete whiteouts\n");
for ( ; ep != NULL; ep = nextep) {
nextep = ep->e_links;
mydirino = ep->e_parent->e_ino;
if (TSTINO(i, usedinomap))
continue;
for ( ; ep != NULL; ep = ep->e_links) {
- dprintf(stdout, "%s: REMOVE\n", myname(ep));
+ Dprintf(stdout, "%s: REMOVE\n", myname(ep));
if (ep->e_type == LEAF) {
removeleaf(ep);
freeentry(ep);
* Renames are done at the same time.
*/
long
-nodeupdates(name, ino, type)
- char *name;
- ino_t ino;
- int type;
+nodeupdates(char *name, ino_t ino, int type)
{
register struct entry *ep, *np, *ip;
long descend = GOOD;
removeleaf(np);
freeentry(np);
} else {
- dprintf(stdout, "name/inode conflict, mktempname %s\n",
+ Dprintf(stdout, "name/inode conflict, mktempname %s\n",
myname(np));
mktempname(np);
}
*/
case INOFND|NAMEFND:
ip->e_flags |= KEEP;
- dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
flagvalues(ip));
break;
if (type == NODE)
newnode(ep);
ep->e_flags |= NEW|KEEP;
- dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
flagvalues(ep));
break;
renameit(myname(ip), name);
moveentry(ip, name);
ip->e_flags |= KEEP;
- dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
flagvalues(ip));
break;
}
}
ep = addentry(name, ino, type|LINK);
ep->e_flags |= NEW;
- dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
flagvalues(ep));
break;
if (type == NODE)
newnode(ep);
ep->e_flags |= NEW|KEEP;
- dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
flagvalues(ep));
break;
}
if (type == LEAF && lookuptype != LINK)
np->e_flags |= EXTRACT;
np->e_flags |= KEEP;
- dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
flagvalues(np));
break;
}
if (ip->e_type == LEAF) {
/* changing from leaf to node */
- for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) {
+ for ( ; ip != NULL; ip = ip->e_links) {
if (ip->e_type != LEAF)
badentry(ip, "NODE and LEAF links to same inode");
removeleaf(ip);
ip = addentry(name, ino, type);
}
ip->e_flags |= NEW|KEEP;
- dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
+ Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
flagvalues(ip));
break;
* Ignore it.
*/
case NAMEFND:
- dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
+ Dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
name);
descend = FAIL;
break;
*/
case NULL:
if (compare_ignore_not_found) break;
- fprintf(stderr, "%s: (inode %ld) not found on tape\n",
- name, ino);
+ fprintf(stderr, "%s: (inode %lu) not found on tape\n",
+ name, (unsigned long)ino);
break;
/*
* Calculate the active flags in a key.
*/
static char *
-keyval(key)
- int key;
+keyval(int key)
{
static char keybuf[32];
* Find unreferenced link names.
*/
void
-findunreflinks()
+findunreflinks(void)
{
register struct entry *ep, *np;
register ino_t i;
- vprintf(stdout, "Find unreferenced names.\n");
+ Vprintf(stdout, "Find unreferenced names.\n");
for (i = ROOTINO; i < maxino; i++) {
ep = lookupino(i);
if (ep == NULL || ep->e_type == LEAF || TSTINO(i, dumpmap) == 0)
continue;
for (np = ep->e_entries; np != NULL; np = np->e_sibling) {
if (np->e_flags == 0) {
- dprintf(stdout,
+ Dprintf(stdout,
"%s: remove unreferenced name\n",
myname(np));
removeleaf(np);
if (np->e_type == LEAF) {
if (np->e_flags != 0)
badentry(np, "unreferenced with flags");
- dprintf(stdout,
+ Dprintf(stdout,
"%s: remove unreferenced name\n",
myname(np));
removeleaf(np);
* time O(N).
*/
void
-removeoldnodes()
+removeoldnodes(void)
{
register struct entry *ep, **prev;
long change;
- vprintf(stdout, "Remove old nodes (directories).\n");
+ Vprintf(stdout, "Remove old nodes (directories).\n");
do {
change = 0;
prev = &removelist;
/* current copy of this file on disk. If do_compare is 0, then just */
/* make our caller think we did it--this is used to handle hard links */
/* to files and devices. */
-void
+static void
compare_entry(struct entry *ep, int do_compare)
{
if ((ep->e_flags & (NEW|EXTRACT)) == 0)
* This is the routine used to compare files for the 'C' command.
*/
void
-compareleaves()
+compareleaves(void)
{
register struct entry *ep;
ino_t first;
* on the next incremental tape.
*/
if (first != curfile.ino) {
- fprintf(stderr, "expected next file %ld, got %ld\n",
- first, curfile.ino);
+ fprintf(stderr, "expected next file %ld, got %lu\n",
+ (long)first, (unsigned long)curfile.ino);
skipfile();
goto next;
}
* Extract new leaves.
*/
void
-createleaves(symtabfile)
- char *symtabfile;
+createleaves(char *symtabfile)
{
register struct entry *ep;
ino_t first;
long curvol;
if (command == 'R') {
- vprintf(stdout, "Continue extraction of new leaves\n");
+ Vprintf(stdout, "Continue extraction of new leaves\n");
} else {
- vprintf(stdout, "Extract new leaves.\n");
+ Vprintf(stdout, "Extract new leaves.\n");
dumpsymtable(symtabfile, volno);
}
first = lowerbnd(ROOTINO);
* on the next incremental tape.
*/
if (first != curfile.ino) {
- fprintf(stderr, "expected next file %ld, got %ld\n",
- first, curfile.ino);
+ fprintf(stderr, "expected next file %ld, got %lu\n",
+ (long)first, (unsigned long)curfile.ino);
skipfile();
goto next;
}
* Efficiently extract a subset of the files on a tape.
*/
void
-createfiles()
+createfiles(void)
{
register ino_t first, next, last;
register struct entry *ep;
long curvol;
- vprintf(stdout, "Extract requested files\n");
+ Vprintf(stdout, "Extract requested files\n");
curfile.action = SKIP;
getvol((long)1);
skipmaps();
* Add links.
*/
void
-createlinks()
+createlinks(void)
{
register struct entry *np, *ep;
register ino_t i;
char name[BUFSIZ];
if ((ep = lookupino(WINO))) {
- vprintf(stdout, "Add whiteouts\n");
+ Vprintf(stdout, "Add whiteouts\n");
for ( ; ep != NULL; ep = ep->e_links) {
if ((ep->e_flags & NEW) == 0)
continue;
ep->e_flags &= ~NEW;
}
}
- vprintf(stdout, "Add links\n");
+ Vprintf(stdout, "Add links\n");
for (i = ROOTINO; i < maxino; i++) {
ep = lookupino(i);
if (ep == NULL)
* that no temporary names remain.
*/
void
-checkrestore()
+checkrestore(void)
{
register struct entry *ep;
register ino_t i;
- vprintf(stdout, "Check the symbol table.\n");
+ Vprintf(stdout, "Check the symbol table.\n");
for (i = WINO; i < maxino; i++) {
for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
ep->e_flags &= ~KEEP;
if (ep->e_type == NODE)
ep->e_flags &= ~(NEW|EXISTED);
- if (ep->e_flags != 0)
+ if (ep->e_flags /* != NULL */)
badentry(ep, "incomplete operations");
}
}
* A paranoid check that things are as they should be.
*/
long
-verifyfile(name, ino, type)
- char *name;
- ino_t ino;
- int type;
+verifyfile(char *name, ino_t ino, int type)
{
struct entry *np, *ep;
long descend = GOOD;
extern time_t dumpdate; /* time that this dump was made */
extern char command; /* opration being performed */
extern FILE *terminal; /* file descriptor for the terminal input */
+extern char *tmpdir; /* name of temp directory */
extern int oldinofmt; /* reading tape with old format inodes */
extern int Bcvt; /* need byte swapping on inodes and dirs */
extern int compare_ignore_not_found;
/* so messages about "not found" files */
/* isn't seen. */
extern char *filesys; /* name of dumped filesystem */
-extern char *tmpdir; /* name of temp directory */
/*
* Each file in the file system is described by one of these entries
#define SETINO(ino, map) \
map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
-#define dprintf if (dflag) fprintf
-#define vprintf if (vflag) fprintf
+#define Dprintf if (dflag) fprintf
+#define Vprintf if (vflag) fprintf
#define GOOD 1
#define FAIL 0
static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: symtab.c,v 1.2 1999/10/11 12:53:24 stelian Exp $";
+ "$Id: symtab.c,v 1.3 1999/10/11 12:59:20 stelian Exp $";
#endif /* not lint */
/*
#endif /* __linux__ */
#include <errno.h>
+#include <compaterr.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
* Look up an entry by inode number
*/
struct entry *
-lookupino(inum)
- ino_t inum;
+lookupino(ino_t inum)
{
register struct entry *ep;
* Add an entry into the entry table
*/
static void
-addino(inum, np)
- ino_t inum;
- struct entry *np;
+addino(ino_t inum, struct entry *np)
{
struct entry **epp;
* Delete an entry from the entry table
*/
void
-deleteino(inum)
- ino_t inum;
+deleteino(ino_t inum)
{
register struct entry *next;
struct entry **prev;
* Look up an entry by name
*/
struct entry *
-lookupname(name)
- char *name;
+lookupname(char *name)
{
register struct entry *ep;
register char *np, *cp;
* Look up the parent of a pathname
*/
static struct entry *
-lookupparent(name)
- char *name;
+lookupparent(char *name)
{
struct entry *ep;
char *tailindex;
* Determine the current pathname of a node or leaf
*/
char *
-myname(ep)
- register struct entry *ep;
+myname(struct entry *ep)
{
register char *cp;
static char namebuf[MAXPATHLEN];
for (cp = &namebuf[MAXPATHLEN - 2]; cp > &namebuf[ep->e_namlen]; ) {
cp -= ep->e_namlen;
- memmove(cp, ep->e_name, (long)ep->e_namlen);
+ memmove(cp, ep->e_name, (size_t)ep->e_namlen);
if (ep == lookupino(ROOTINO))
return (cp);
*(--cp) = '/';
* add an entry to the symbol table
*/
struct entry *
-addentry(name, inum, type)
- char *name;
- ino_t inum;
- int type;
+addentry(char *name, ino_t inum, int type)
{
register struct entry *np, *ep;
if (freelist != NULL) {
np = freelist;
freelist = np->e_next;
- memset(np, 0, (long)sizeof(struct entry));
+ memset(np, 0, sizeof(struct entry));
} else {
np = (struct entry *)calloc(1, sizeof(struct entry));
if (np == NULL)
* delete an entry from the symbol table
*/
void
-freeentry(ep)
- register struct entry *ep;
+freeentry(struct entry *ep)
{
register struct entry *np;
ino_t inum;
* Relocate an entry in the tree structure
*/
void
-moveentry(ep, newname)
- register struct entry *ep;
- char *newname;
+moveentry(struct entry *ep, char *newname)
{
struct entry *np;
char *cp;
* Remove an entry in the tree structure
*/
static void
-removeentry(ep)
- register struct entry *ep;
+removeentry(struct entry *ep)
{
register struct entry *np;
* has an appropriate sized entry, and if not allocates a new one.
*/
char *
-savename(name)
- char *name;
+savename(char *name)
{
struct strhdr *np;
long len;
* appropriate free list.
*/
void
-freename(name)
- char *name;
+freename(char *name)
{
struct strhdr *tp, *np;
* dump a snapshot of the symbol table
*/
void
-dumpsymtable(filename, checkpt)
- char *filename;
- long checkpt;
+dumpsymtable(char *filename, long checkpt)
{
register struct entry *ep, *tep;
register ino_t i;
FILE *fd;
struct symtableheader hdr;
- vprintf(stdout, "Check pointing the restore\n");
+ Vprintf(stdout, "Check pointing the restore\n");
if (Nflag)
return;
if ((fd = fopen(filename, "w")) == NULL) {
- fprintf(stderr, "fopen: %s\n", strerror(errno));
+ warn("fopen");
panic("cannot create save file %s for symbol table\n",
filename);
}
stroff = 0;
for (i = WINO; i <= maxino; i++) {
for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
- memmove(tep, ep, (long)sizeof(struct entry));
+ memmove(tep, ep, sizeof(struct entry));
tep->e_name = (char *)stroff;
stroff += allocsize(ep->e_namlen);
tep->e_parent = (struct entry *)ep->e_parent->e_index;
hdr.ntrec = ntrec;
(void) fwrite((char *)&hdr, sizeof(struct symtableheader), 1, fd);
if (ferror(fd)) {
- fprintf(stderr, "fwrite: %s\n", strerror(errno));
+ warn("fwrite");
panic("output error to file %s writing symbol table\n",
filename);
}
* Initialize a symbol table from a file
*/
void
-initsymtable(filename)
- char *filename;
+initsymtable(char *filename)
{
char *base;
long tblsize;
register long i;
int fd;
- vprintf(stdout, "Initialize symbol table.\n");
+ Vprintf(stdout, "Initialize symbol table.\n");
if (filename == NULL) {
entrytblsize = maxino / HASHFACTOR;
entry = (struct entry **)
return;
}
if ((fd = open(filename, O_RDONLY, 0)) < 0) {
- fprintf(stderr, "open: %s\n", strerror(errno));
+ warn("open");
panic("cannot open symbol table file %s\n", filename);
}
if (fstat(fd, &stbuf) < 0) {
- fprintf(stderr, "stat: %s\n", strerror(errno));
+ warn("stat");
panic("cannot stat symbol table file %s\n", filename);
}
tblsize = stbuf.st_size - sizeof(struct symtableheader);
panic("cannot allocate space for symbol table\n");
if (read(fd, base, (int)tblsize) < 0 ||
read(fd, (char *)&hdr, sizeof(struct symtableheader)) < 0) {
- fprintf(stderr, "read: %s\n", strerror(errno));
+ warn("read");
panic("cannot read symbol table file %s\n", filename);
}
switch (command) {
* For normal continuation, insure that we are using
* the next incremental tape
*/
- if (hdr.dumpdate != dumptime) {
- if (hdr.dumpdate < dumptime)
- fprintf(stderr, "Incremental tape too low\n");
- else
- fprintf(stderr, "Incremental tape too high\n");
- done(1);
- }
+ if (hdr.dumpdate != dumptime)
+ errx(1, "Incremental tape too %s",
+ (hdr.dumpdate < dumptime) ? "low" : "high");
break;
case 'R':
/*
static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
#endif
static const char rcsid[] =
- "$Id: tape.c,v 1.2 1999/10/11 12:53:24 stelian Exp $";
+ "$Id: tape.c,v 1.3 1999/10/11 12:59:21 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <protocols/dumprestore.h>
#include <errno.h>
+#include <compaterr.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
static long blksread; /* blocks read since last header */
static long tpblksread = 0; /* TP_BSIZE blocks read */
static long tapesread;
-static jmp_buf restart;
+static sigjmp_buf restart;
static int gettingfile = 0; /* restart has a valid frame */
static char *host = NULL;
static int gethead __P((struct s_spcl *));
static void readtape __P((char *));
static void setdumpnum __P((void));
+static u_int swabi __P((u_int));
static u_long swabl __P((u_long));
-static u_char *swablong __P((u_char *, int));
-static u_char *swabshort __P((u_char *, int));
+static u_char *swab64 __P((u_char *, int));
+static u_char *swab32 __P((u_char *, int));
+static u_char *swab16 __P((u_char *, int));
static void terminateinput __P((void));
-static void xtrfile __P((char *, long));
-static void xtrlnkfile __P((char *, long));
-static void xtrlnkskip __P((char *, long));
-static void xtrmap __P((char *, long));
-static void xtrmapskip __P((char *, long));
-static void xtrskip __P((char *, long));
+static void xtrfile __P((char *, size_t));
+static void xtrlnkfile __P((char *, size_t));
+static void xtrlnkskip __P((char *, size_t));
+static void xtrmap __P((char *, size_t));
+static void xtrmapskip __P((char *, size_t));
+static void xtrskip __P((char *, size_t));
static int readmapflag;
* Set up an input source
*/
void
-setinput(source)
- char *source;
+setinput(char *source)
{
FLUSHTAPEBUF();
if (bflag)
source = strchr(host, ':');
*source++ = '\0';
if (rmthost(host) == 0)
- done(1);
+ exit(1);
} else
#endif
if (strcmp(source, "-") == 0) {
*/
terminal = fopen(_PATH_TTY, "r");
if (terminal == NULL) {
- (void)fprintf(stderr, "cannot open %s: %s\n",
- _PATH_TTY, strerror(errno));
+ warn("cannot open %s", _PATH_TTY);
terminal = fopen(_PATH_DEVNULL, "r");
- if (terminal == NULL) {
- (void)fprintf(stderr, "cannot open %s: %s\n",
- _PATH_DEVNULL, strerror(errno));
- done(1);
- }
+ if (terminal == NULL)
+ err(1, "cannot open %s", _PATH_DEVNULL);
}
pipein++;
}
setuid(getuid()); /* no longer need or want root privileges */
magtape = strdup(source);
- if (magtape == NULL) {
- fprintf(stderr, "Cannot allocate space for magtape buffer\n");
- done(1);
- }
+ if (magtape == NULL)
+ errx(1, "Cannot allocate space for magtape buffer");
}
void
-newtapebuf(size)
- long size;
+newtapebuf(long size)
{
- static tapebufsize = -1;
+ static int tapebufsize = -1;
ntrec = size;
if (size <= tapebufsize)
if (tapebuf != NULL)
free(tapebuf);
tapebuf = malloc(size * TP_BSIZE);
- if (tapebuf == NULL) {
- fprintf(stderr, "Cannot allocate space for tape buffer\n");
- done(1);
- }
+ if (tapebuf == NULL)
+ errx(1, "Cannot allocate space for tape buffer");
tapebufsize = size;
}
* that it actually is a dump tape.
*/
void
-setup()
+setup(void)
{
int i, j, *ip;
struct stat stbuf;
- vprintf(stdout, "Verify tape and initialize maps\n");
+ Vprintf(stdout, "Verify tape and initialize maps\n");
#ifdef RRESTORE
if (host)
mt = rmtopen(magtape, 0);
mt = 0;
else
mt = open(magtape, O_RDONLY, 0);
- if (mt < 0) {
- fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
- done(1);
- }
+ if (mt < 0)
+ err(1, "%s", magtape);
volno = 1;
setdumpnum();
FLUSHTAPEBUF();
blksread--;
tpblksread--;
cvtflag++;
- if (gethead(&spcl) == FAIL) {
- fprintf(stderr, "Tape is not a dump tape\n");
- done(1);
- }
+ if (gethead(&spcl) == FAIL)
+ errx(1, "Tape is not a dump tape");
fprintf(stderr, "Converting to new file system format.\n");
}
if (pipein) {
}
dumptime = spcl.c_ddate;
dumpdate = spcl.c_date;
- if (stat(".", &stbuf) < 0) {
- fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
- done(1);
- }
+ if (stat(".", &stbuf) < 0)
+ err(1, "cannot stat .");
if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
fssize = TP_BSIZE;
if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
fssize = stbuf.st_blksize;
- if (((fssize - 1) & fssize) != 0) {
- fprintf(stderr, "bad block size %ld\n", fssize);
- done(1);
- }
- if (spcl.c_volume != 1) {
- fprintf(stderr, "Tape is not volume 1 of the dump\n");
- done(1);
- }
+ if (((fssize - 1) & fssize) != 0)
+ errx(1, "bad block size %ld", fssize);
+ if (spcl.c_volume != 1)
+ errx(1, "Tape is not volume 1 of the dump");
if (gethead(&spcl) == FAIL) {
- dprintf(stdout, "header read failed at %ld blocks\n", blksread);
+ Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
panic("no header after volume mark!\n");
}
findinode(&spcl);
- if (spcl.c_type != TS_CLRI) {
- fprintf(stderr, "Cannot find file removal list\n");
- done(1);
- }
+ if (spcl.c_type != TS_CLRI)
+ errx(1, "Cannot find file removal list");
maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
- dprintf(stdout, "maxino = %ld\n", maxino);
+ Dprintf(stdout, "maxino = %ld\n", maxino);
map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
if (map == NULL)
panic("no memory for active inode map\n");
usedinomap = map;
curfile.action = USING;
getfile(xtrmap, xtrmapskip);
- if (spcl.c_type != TS_BITS) {
- fprintf(stderr, "Cannot find file dump list\n");
- done(1);
- }
+ if (spcl.c_type != TS_BITS)
+ errx(1, "Cannot find file dump list");
map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
if (map == (char *)NULL)
panic("no memory for file dump list\n");
* the user when only extracting a subset of the files.
*/
void
-getvol(nextvol)
- long nextvol;
+getvol(long nextvol)
{
- long newvol=0, savecnt=0, wantnext=0, i;
+ long newvol = 0, savecnt = 0, wantnext = 0, i;
union u_spcl tmpspcl;
# define tmpbuf tmpspcl.s_spcl
char buf[TP_BSIZE];
savecnt = blksread;
again:
if (pipein)
- done(1); /* pipes do not get a second chance */
+ exit(1); /* pipes do not get a second chance */
if (command == 'R' || command == 'r' || curfile.action != SKIP) {
newvol = nextvol;
wantnext = 1;
strcpy(buf, ": ");
for (i = 1; i < 32; i++)
if (tapesread & (1 << i)) {
- fprintf(stderr, "%s%ld", buf, i);
+ fprintf(stderr, "%s%ld", buf, (long)i);
strcpy(buf, ", ");
}
fprintf(stderr, "\n");
(void) fgets(buf, BUFSIZ, terminal);
} while (!feof(terminal) && buf[0] == '\n');
if (feof(terminal))
- done(1);
+ exit(1);
newvol = atoi(buf);
if (newvol <= 0) {
fprintf(stderr,
return;
}
closemt();
- fprintf(stderr, "Mount tape volume %ld\n", newvol);
+ fprintf(stderr, "Mount tape volume %ld\n", (long)newvol);
fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
(void) fflush(stderr);
(void) fgets(buf, BUFSIZ, terminal);
if (feof(terminal))
- done(1);
+ exit(1);
if (!strcmp(buf, "none\n")) {
terminateinput();
return;
setdumpnum();
FLUSHTAPEBUF();
if (gethead(&tmpbuf) == FAIL) {
- dprintf(stdout, "header read failed at %ld blocks\n", blksread);
+ Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
fprintf(stderr, "tape is not dump tape\n");
volno = 0;
goto again;
* If coming to this volume at random, skip to the beginning
* of the next record.
*/
- dprintf(stdout, "read %ld recs, tape starts with %d\n",
- tpblksread, tmpbuf.c_firstrec);
+ Dprintf(stdout, "read %ld recs, tape starts with %ld\n",
+ tpblksread, (long)tmpbuf.c_firstrec);
if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
if (!wantnext) {
tpblksread = tmpbuf.c_firstrec;
* -1 since we've read the volume header
*/
i = tpblksread - tmpbuf.c_firstrec - 1;
- dprintf(stderr, "Skipping %ld duplicate record%s.\n",
- i, i > 1 ? "s" : "");
+ Dprintf(stderr, "Skipping %ld duplicate record%s.\n",
+ (long)i, i > 1 ? "s" : "");
while (--i >= 0)
readtape(buf);
}
findinode(&spcl);
if (gettingfile) {
gettingfile = 0;
- longjmp(restart, 1);
+ siglongjmp(restart, 1);
}
}
* Handle unexpected EOF.
*/
static void
-terminateinput()
+terminateinput(void)
{
if (gettingfile && curfile.action == USING) {
curfile.ino = maxino;
if (gettingfile) {
gettingfile = 0;
- longjmp(restart, 1);
+ siglongjmp(restart, 1);
}
}
* appropriate one.
*/
static void
-setdumpnum()
+setdumpnum(void)
{
struct mtop tcom;
if (dumpnum == 1 || volno != 1)
return;
- if (pipein) {
- fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
- done(1);
- }
+ if (pipein)
+ errx(1, "Cannot have multiple dumps on pipe input");
tcom.mt_op = MTFSF;
tcom.mt_count = dumpnum - 1;
#ifdef RRESTORE
else
#endif
if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0)
- fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
+ warn("ioctl MTFSF");
}
void
-printdumpinfo()
+printdumpinfo(void)
{
#ifdef __linux__
fprintf(stdout, "Dump date: %s", ctime4(&spcl.c_date));
}
int
-extractfile(name)
- char *name;
+extractfile(char *name)
{
- int flags;
+ unsigned int flags;
mode_t mode;
struct timeval timep[2];
struct entry *ep;
-#ifdef __linux__
- int err;
- uid_t uid;
- gid_t gid;
-#endif
curfile.name = name;
curfile.action = USING;
return (FAIL);
case IFSOCK:
- vprintf(stdout, "skipped socket %s\n", name);
+ Vprintf(stdout, "skipped socket %s\n", name);
skipfile();
return (GOOD);
skipfile();
return (GOOD);
}
- vprintf(stdout, "extract file %s\n", name);
+ Vprintf(stdout, "extract file %s\n", name);
return (genliteraldir(name, curfile.ino));
case IFLNK:
+ { uid_t luid = curfile.dip->di_uid;
+ gid_t lgid = curfile.dip->di_gid;
+
lnkbuf[0] = '\0';
pathlen = 0;
-#ifdef __linux__
- uid = curfile.dip->di_uid;
- gid = curfile.dip->di_gid;
-#endif
getfile(xtrlnkfile, xtrlnkskip);
if (pathlen == 0) {
- vprintf(stdout,
+ Vprintf(stdout,
"%s: zero length symbolic link (ignored)\n", name);
return (GOOD);
}
-#ifdef __linux__
- err = linkit(lnkbuf, name, SYMLINK);
- if (err == GOOD)
- (void) chown(name, uid, gid);
- return (err);
-#else
- return (linkit(lnkbuf, name, SYMLINK));
-#endif
+ if (linkit(lnkbuf, name, SYMLINK) == FAIL)
+ return (FAIL);
+ (void) chown(name, luid, lgid);
+ return (GOOD);
+ }
case IFIFO:
- vprintf(stdout, "extract fifo %s\n", name);
+ Vprintf(stdout, "extract fifo %s\n", name);
if (Nflag) {
skipfile();
return (GOOD);
if (uflag && !Nflag)
(void)unlink(name);
if (mkfifo(name, mode) < 0) {
- fprintf(stderr, "%s: cannot create fifo: %s\n",
- name, strerror(errno));
+ warn("%s: cannot create fifo", name);
skipfile();
return (FAIL);
}
case IFCHR:
case IFBLK:
- vprintf(stdout, "extract special file %s\n", name);
+ Vprintf(stdout, "extract special file %s\n", name);
if (Nflag) {
skipfile();
return (GOOD);
if (uflag)
(void)unlink(name);
if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
- fprintf(stderr, "%s: cannot create special file: %s\n",
- name, strerror(errno));
+ warn("%s: cannot create special file", name);
skipfile();
return (FAIL);
}
return (GOOD);
case IFREG:
- vprintf(stdout, "extract file %s\n", name);
+ Vprintf(stdout, "extract file %s\n", name);
if (Nflag) {
skipfile();
return (GOOD);
(void)unlink(name);
if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
0666)) < 0) {
- fprintf(stderr, "%s: cannot create file: %s\n",
- name, strerror(errno));
+ warn("%s: cannot create file", name);
skipfile();
return (FAIL);
}
* skip over bit maps on the tape
*/
void
-skipmaps()
+skipmaps(void)
{
while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
* skip over a file on the tape
*/
void
-skipfile()
+skipfile(void)
{
curfile.action = SKIP;
* to the skip function.
*/
void
-getfile(fill, skip)
- void (*fill) __P((char *, long));
- void (*skip) __P((char *, long));
+getfile(void (*fill) __P((char *, size_t)), void (*skip) __P((char *, size_t)))
{
register int i;
- int curblk = 0;
- quad_t size = spcl.c_dinode.di_size;
- int last_write_was_hole = 0;
- long origsize = size;
+ volatile int curblk = 0;
+ volatile quad_t size = spcl.c_dinode.di_size;
+ volatile int last_write_was_hole = 0;
+ quad_t origsize = size;
static char clearedbuf[MAXBSIZE];
char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
char junk[TP_BSIZE];
if (readmapflag || spcl.c_addr[i]) {
readtape(&buf[curblk++][0]);
if (curblk == fssize / TP_BSIZE) {
- (*fill)((char *)buf, (long)(size > TP_BSIZE ?
+ (*fill)((char *)buf, (size_t)(size > TP_BSIZE ?
fssize : (curblk - 1) * TP_BSIZE + size));
curblk = 0;
last_write_was_hole = 0;
}
} else {
if (curblk > 0) {
- (*fill)((char *)buf, (long)(size > TP_BSIZE ?
+ (*fill)((char *)buf, (size_t)(size > TP_BSIZE ?
curblk * TP_BSIZE :
(curblk - 1) * TP_BSIZE + size));
curblk = 0;
if (gethead(&spcl) == GOOD && size > 0) {
if (spcl.c_type == TS_ADDR)
goto loop;
- dprintf(stdout,
+ Dprintf(stdout,
"Missing address (header) block for %s at %ld blocks\n",
- curfile.name, blksread);
+ curfile.name, (long)blksread);
}
if (curblk > 0) {
- (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
+ (*fill)((char *)buf, (size_t)(curblk * TP_BSIZE) + size);
last_write_was_hole = 0;
}
if (last_write_was_hole) {
* Write out the next block of a file.
*/
static void
-xtrfile(buf, size)
- char *buf;
- long size;
+xtrfile(char *buf, size_t size)
{
if (Nflag)
return;
- if (write(ofile, buf, (int) size) == -1) {
- fprintf(stderr,
- "write error extracting inode %ld, name %s\nwrite: %s\n",
- curfile.ino, curfile.name, strerror(errno));
- done(1);
- }
+ if (write(ofile, buf, (int) size) == -1)
+ err(1, "write error extracting inode %lu, name %s\nwrite",
+ (unsigned long)curfile.ino, curfile.name);
}
/*
*/
/* ARGSUSED */
static void
-xtrskip(buf, size)
- char *buf;
- long size;
+xtrskip(char *buf, size_t size)
{
- if (lseek(ofile, size, SEEK_CUR) == -1) {
- fprintf(stderr,
- "seek error extracting inode %ld, name %s\nlseek: %s\n",
- curfile.ino, curfile.name, strerror(errno));
- done(1);
- }
+ if (lseek(ofile, (off_t)size, SEEK_CUR) == -1)
+ err(1, "seek error extracting inode %lu, name %s\nlseek",
+ (unsigned long)curfile.ino, curfile.name);
}
/*
* Collect the next block of a symbolic link.
*/
static void
-xtrlnkfile(buf, size)
- char *buf;
- long size;
+xtrlnkfile(char *buf, size_t size)
{
pathlen += size;
- if (pathlen > MAXPATHLEN) {
- fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
+ if (pathlen > MAXPATHLEN)
+ errx(1, "symbolic link name: %s->%s%s; too long %d",
curfile.name, lnkbuf, buf, pathlen);
- done(1);
- }
(void) strcat(lnkbuf, buf);
}
*/
/* ARGSUSED */
static void
-xtrlnkskip(buf, size)
- char *buf;
- long size;
+xtrlnkskip(char *buf, size_t size)
{
- fprintf(stderr, "unallocated block in symbolic link %s\n",
- curfile.name);
- done(1);
+ errx(1, "unallocated block in symbolic link %s", curfile.name);
}
/*
* Collect the next block of a bit map.
*/
static void
-xtrmap(buf, size)
- char *buf;
- long size;
+xtrmap(char *buf, size_t size)
{
memmove(map, buf, size);
*/
/* ARGSUSED */
static void
-xtrmapskip(buf, size)
- char *buf;
- long size;
+xtrmapskip(char *buf, size_t size)
{
panic("hole in map\n");
*/
/* ARGSUSED */
void
-xtrnull(buf, size)
- char *buf;
- long size;
+xtrnull(char *buf, size_t size)
{
return;
}
-int
+static int
do_cmpfiles(int fd_tape, int fd_disk, long size)
{
-#ifndef BUFSIZE
-#define BUFSIZE 1024
-#endif
static char buf_tape[BUFSIZ];
static char buf_disk[BUFSIZ];
- int n_tape;
- int n_disk;
+ ssize_t n_tape;
+ ssize_t n_disk;
while (size > 0) {
- if ((n_tape = read(fd_tape, buf_tape, BUFSIZE)) < 1) {
+ if ((n_tape = read(fd_tape, buf_tape, sizeof(buf_tape))) < 1) {
close(fd_tape), close(fd_disk);
panic("do_cmpfiles: unexpected EOF[1]");
}
- if ((n_disk = read(fd_disk, buf_disk, BUFSIZE)) < 1) {
+ if ((n_disk = read(fd_disk, buf_disk, sizeof(buf_tape))) < 1) {
close(fd_tape), close(fd_disk);
panic("do_cmpfiles: unexpected EOF[2]");
}
close(fd_tape), close(fd_disk);
panic("do_cmpfiles: sizes different!");
}
- if (memcmp(buf_tape, buf_disk, n_tape) != 0) return (1);
+ if (memcmp(buf_tape, buf_disk, (size_t)n_tape) != 0) return (1);
size -= n_tape;
}
return (0);
/* for debugging compare problems */
#undef COMPARE_FAIL_KEEP_FILE
+static
#ifdef COMPARE_FAIL_KEEP_FILE
/* return true if tapefile should be unlinked after compare */
int
if (sbuf_disk->st_size != sbuf_tape.st_size) {
fprintf(stderr,
"%s: size changed from %ld to %ld.\n",
- diskfile, sbuf_tape.st_size, sbuf_disk->st_size);
+ diskfile, (long)sbuf_tape.st_size, (long)sbuf_disk->st_size);
#ifdef COMPARE_FAIL_KEEP_FILE
return (0);
#else
if (!p) {
panic("can't find / in %s\n", diskfile);
}
- sprintf(newname, "%s/debug/%s", tmpdir, p + 1);
+ snprintf(newname, sizeof(newname), "%s/debug/%s", tmpdir, p + 1);
if (rename(tapefile, newname)) {
panic("rename from %s to %s failed: %s\n",
tapefile, newname,
#endif
}
-static char tmpfilename[128];
+static char tmpfilename[MAXPATHLEN];
void
-comparefile(name)
- char *name;
+comparefile(char *name)
{
static char *tmpfile = NULL;
int mode;
int r;
if ((r = lstat(name, &sb)) != 0) {
- fprintf(stderr, "%s: does not exist (%d, %d).\n", name, r, errno);
+ warn("%s: does not exist (%d)", name, r);
skipfile();
return;
}
curfile.action = USING;
mode = curfile.dip->di_mode;
- vprintf(stdout, "comparing %s (size: %ld, mode: 0%o)\n", name,
- sb.st_size, mode);
+ Vprintf(stdout, "comparing %s (size: %ld, mode: 0%o)\n", name,
+ (long)sb.st_size, mode);
if (sb.st_mode != mode) {
fprintf(stderr, "%s: mode changed from 0%o to 0%o.\n",
fprintf(stderr,
"%s: device changed from %d,%d to %d,%d.\n",
name,
- ((int)curfile.dip->di_rdev >> 8) & 0xf,
- (int)curfile.dip->di_rdev & 0xf,
- ((int)sb.st_rdev >> 8) & 0xf,
- (int)sb.st_rdev & 0xf);
+ ((int)curfile.dip->di_rdev >> 8) & 0xff,
+ (int)curfile.dip->di_rdev & 0xff,
+ ((int)sb.st_rdev >> 8) & 0xff,
+ (int)sb.st_rdev & 0xff);
}
skipfile();
return;
case IFREG:
if (tmpfile == NULL) {
/* argument to mktemp() must not be in RO space: */
- sprintf(tmpfilename, "%s/restoreCXXXXXX", tmpdir);
+ snprintf(tmpfilename, sizeof(tmpfilename), "%s/restoreCXXXXXX", tmpdir);
tmpfile = mktemp(&tmpfilename[0]);
}
if ((stat(tmpfile, &stemp) == 0) && (unlink(tmpfile) != 0)) {
* Handle read errors, and end of media.
*/
static void
-readtape(buf)
- char *buf;
+readtape(char *buf)
{
- long rd, newvol, i;
+ ssize_t rd, newvol, i;
int cnt, seek_failed;
if (blkcnt < numtrec) {
- memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
+ memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
blksread++;
tpblksread++;
return;
* If found, skip rest of buffer and start with the next.
*/
if (!pipein && numtrec < ntrec && i > 0) {
- dprintf(stdout, "mid-media short read error.\n");
+ Dprintf(stdout, "mid-media short read error.\n");
numtrec = ntrec;
}
/*
* Short read. Process the blocks read.
*/
if (i % TP_BSIZE != 0)
- vprintf(stdout,
+ Vprintf(stdout,
"partial block read: %ld should be %ld\n",
- i, ntrec * TP_BSIZE);
+ (long)i, ntrec * TP_BSIZE);
numtrec = i / TP_BSIZE;
}
}
fprintf(stderr, "restoring %s\n", curfile.name);
break;
case SKIP:
- fprintf(stderr, "skipping over inode %ld\n",
- curfile.ino);
+ fprintf(stderr, "skipping over inode %lu\n",
+ (unsigned long)curfile.ino);
break;
}
if (!yflag && !reply("continue"))
- done(1);
+ exit(1);
i = ntrec * TP_BSIZE;
- memset(tapebuf, 0, i);
+ memset(tapebuf, 0, (size_t)i);
#ifdef RRESTORE
if (host)
seek_failed = (rmtseek(i, 1) < 0);
#endif
seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
- if (seek_failed) {
- fprintf(stderr,
- "continuation failed: %s\n", strerror(errno));
- done(1);
- }
+ if (seek_failed)
+ err(1, "continuation failed");
}
/*
* Handle end of tape.
*/
if (i == 0) {
- vprintf(stdout, "End-of-tape encountered\n");
+ Vprintf(stdout, "End-of-tape encountered\n");
if (!pipein) {
newvol = volno + 1;
volno = 0;
panic("partial block read: %d should be %d\n",
rd, ntrec * TP_BSIZE);
terminateinput();
- memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
+ memmove(&tapebuf[rd], &endoftapemark, TP_BSIZE);
}
blkcnt = 0;
- memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
+ memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
blksread++;
tpblksread++;
}
static void
-findtapeblksize()
+findtapeblksize(void)
{
register long i;
blkcnt = 0;
#ifdef RRESTORE
if (host)
- i = rmtread(tapebuf, ntrec * TP_BSIZE);
+ i = rmtread(tapebuf, (size_t)(ntrec * TP_BSIZE));
else
#endif
- i = read(mt, tapebuf, ntrec * TP_BSIZE);
+ i = read(mt, tapebuf, (size_t)(ntrec * TP_BSIZE));
- if (i <= 0) {
- fprintf(stderr, "tape read error: %s\n", strerror(errno));
- done(1);
- }
- if (i % TP_BSIZE != 0) {
- fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
- i, "is not a multiple of dump block size", TP_BSIZE);
- done(1);
- }
+ if (i <= 0)
+ err(1, "tape read error");
+ if (i % TP_BSIZE != 0)
+ errx(1, "Tape block size (%ld) is not a multiple of dump block size (%d)",
+ (long)i, TP_BSIZE);
ntrec = i / TP_BSIZE;
numtrec = ntrec;
- vprintf(stdout, "Tape block size is %ld\n", ntrec);
+ Vprintf(stdout, "Tape block size is %ld\n", ntrec);
}
void
-closemt()
+closemt(void)
{
if (mt < 0)
* If it is not any valid header, return an error.
*/
static int
-gethead(buf)
- struct s_spcl *buf;
+gethead(struct s_spcl *buf)
{
- long i;
+ int32_t i;
union {
quad_t qval;
int32_t val[2];
int32_t c_ddate;
int32_t c_volume;
int32_t c_tapea;
- u_short c_inumber;
+ u_int16_t c_inumber;
int32_t c_magic;
int32_t c_checksum;
struct odinode {
- unsigned short odi_mode;
- u_short odi_nlink;
- u_short odi_uid;
- u_short odi_gid;
+ u_int16_t odi_mode;
+ u_int16_t odi_nlink;
+ u_int16_t odi_uid;
+ u_int16_t odi_gid;
int32_t odi_size;
int32_t odi_rdev;
char odi_addr[36];
if (!cvtflag) {
readtape((char *)buf);
if (buf->c_magic != NFS_MAGIC) {
- if (swabl(buf->c_magic) != NFS_MAGIC)
+ if (swabi(buf->c_magic) != NFS_MAGIC)
return (FAIL);
if (!Bcvt) {
- vprintf(stdout, "Note: Doing Byte swapping\n");
+ Vprintf(stdout, "Note: Doing Byte swapping\n");
Bcvt = 1;
}
}
if (checksum((int *)buf) == FAIL)
return (FAIL);
- if (Bcvt) {
- swabst((u_char *)"8l4s31l", (u_char *)buf);
- swabst((u_char *)"l",(u_char *) &buf->c_level);
- swabst((u_char *)"2l",(u_char *) &buf->c_flags);
- }
+ if (Bcvt)
+ swabst((u_char *)"8i4s31i528bi192b2i", (u_char *)buf);
goto good;
}
readtape((char *)(&u_ospcl.s_ospcl));
- memset(buf, 0, (long)TP_BSIZE);
+ memset((char *)buf, 0, (long)TP_BSIZE);
buf->c_type = u_ospcl.s_ospcl.c_type;
buf->c_date = u_ospcl.s_ospcl.c_date;
buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
* Check that a header is where it belongs and predict the next header
*/
static void
-accthdr(header)
- struct s_spcl *header;
+accthdr(struct s_spcl *header)
{
static ino_t previno = 0x7fffffff;
static int prevtype;
fprintf(stderr, "Used inodes map header");
break;
case TS_INODE:
- fprintf(stderr, "File header, ino %ld", previno);
+ fprintf(stderr, "File header, ino %lu", (unsigned long)previno);
break;
case TS_ADDR:
fprintf(stderr, "File continuation header, ino %ld", previno);
* Complain if had to skip, and complain is set.
*/
static void
-findinode(header)
- struct s_spcl *header;
+findinode(struct s_spcl *header)
{
static long skipcnt = 0;
long i;
}
static int
-checksum(buf)
- register int *buf;
+checksum(int *buf)
{
register int i, j;
/* What happens if we want to read restore tapes
for a 16bit int machine??? */
do
- i += swabl(*buf++);
+ i += swabi(*buf++);
while (--j);
}
if (i != CHECKSUM) {
- fprintf(stderr, "Checksum error %o, inode %ld file %s\n", i,
- curfile.ino, curfile.name);
+ fprintf(stderr, "Checksum error %o, inode %lu file %s\n", i,
+ (unsigned long)curfile.ino, curfile.name);
return(FAIL);
}
return(GOOD);
}
#ifdef RRESTORE
-#if __STDC__
+#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
-#if __STDC__
+#ifdef __STDC__
msg(const char *fmt, ...)
#else
msg(fmt, va_alist)
#endif
{
va_list ap;
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif /* RRESTORE */
static u_char *
-swabshort(sp, n)
- register u_char *sp;
- register int n;
+swab16(u_char *sp, int n)
{
char c;
}
static u_char *
-swablong(sp, n)
- register u_char *sp;
- register int n;
+swab32(u_char *sp, int n)
{
char c;
while (--n >= 0) {
c = sp[0]; sp[0] = sp[3]; sp[3] = c;
- c = sp[2]; sp[2] = sp[1]; sp[1] = c;
+ c = sp[1]; sp[1] = sp[2]; sp[2] = c;
sp += 4;
}
return (sp);
}
+static u_char *
+swab64(u_char *sp, int n)
+{
+ char c;
+
+ while (--n >= 0) {
+ c = sp[0]; sp[0] = sp[7]; sp[7] = c;
+ c = sp[1]; sp[1] = sp[6]; sp[6] = c;
+ c = sp[2]; sp[2] = sp[5]; sp[5] = c;
+ c = sp[3]; sp[3] = sp[4]; sp[4] = c;
+ sp += 8;
+ }
+ return (sp);
+}
+
void
-swabst(cp, sp)
- register u_char *cp, *sp;
+swabst(u_char *cp, u_char *sp)
{
int n = 0;
case 's': case 'w': case 'h':
if (n == 0)
n = 1;
- sp = swabshort(sp, n);
+ sp = swab16(sp, n);
+ break;
+
+ case 'i':
+ if (n == 0)
+ n = 1;
+ sp = swab32(sp, n);
break;
case 'l':
if (n == 0)
n = 1;
- sp = swablong(sp, n);
+ sp = swab64(sp, n);
break;
default: /* Any other character, like 'b' counts as byte. */
}
}
+static u_int
+swabi(u_int x)
+{
+ swabst((u_char *)"i", (u_char *)&x);
+ return (x);
+}
+
static u_long
-swabl(x)
- u_long x;
+swabl(u_long x)
{
swabst((u_char *)"l", (u_char *)&x);
return (x);
static char sccsid[] = "@(#)utilities.c 8.5 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: utilities.c,v 1.2 1999/10/11 12:53:25 stelian Exp $";
+ "$Id: utilities.c,v 1.3 1999/10/11 12:59:21 stelian Exp $";
#endif /* not lint */
#include <sys/param.h>
#endif /* __linux__ */
#include <errno.h>
+#include <compaterr.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
* Insure that all the components of a pathname exist.
*/
void
-pathcheck(name)
- char *name;
+pathcheck(char *name)
{
register char *cp;
struct entry *ep;
* Change a name to a unique temporary name.
*/
void
-mktempname(ep)
- register struct entry *ep;
+mktempname(struct entry *ep)
{
char oldname[MAXPATHLEN];
* Generate a temporary name for an entry.
*/
char *
-gentempname(ep)
- struct entry *ep;
+gentempname(struct entry *ep)
{
static char name[MAXPATHLEN];
struct entry *np;
i++;
if (np == NULL)
badentry(ep, "not on ino list");
- (void) sprintf(name, "%s%ld%lu", TMPHDR, i, (u_long)ep->e_ino);
+ (void) snprintf(name, sizeof(name), "%s%ld%lu", TMPHDR, i, (unsigned long)ep->e_ino);
return (name);
}
* Rename a file or directory.
*/
void
-renameit(from, to)
- char *from, *to;
+renameit(char *from, char *to)
{
if (!Nflag && rename(from, to) < 0) {
- fprintf(stderr, "warning: cannot rename %s to %s: %s\n",
- from, to, strerror(errno));
+ warn("cannot rename %s to %s", from, to);
return;
}
- vprintf(stdout, "rename %s to %s\n", from, to);
+ Vprintf(stdout, "rename %s to %s\n", from, to);
}
/*
* Create a new node (directory).
*/
void
-newnode(np)
- struct entry *np;
+newnode(struct entry *np)
{
char *cp;
if (!Nflag && mkdir(cp, 0777) < 0 && !uflag) {
np->e_flags |= EXISTED;
- fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno));
+ warn("%s", cp);
return;
}
- vprintf(stdout, "Make node %s\n", cp);
+ Vprintf(stdout, "Make node %s\n", cp);
}
/*
* Remove an old node (directory).
*/
void
-removenode(ep)
- register struct entry *ep;
+removenode(struct entry *ep)
{
char *cp;
ep->e_flags &= ~TMPNAME;
cp = myname(ep);
if (!Nflag && rmdir(cp) < 0) {
- fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno));
+ warn("%s", cp);
return;
}
- vprintf(stdout, "Remove node %s\n", cp);
+ Vprintf(stdout, "Remove node %s\n", cp);
}
/*
* Remove a leaf.
*/
void
-removeleaf(ep)
- register struct entry *ep;
+removeleaf(struct entry *ep)
{
char *cp;
ep->e_flags &= ~TMPNAME;
cp = myname(ep);
if (!Nflag && unlink(cp) < 0) {
- fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno));
+ warn("%s", cp);
return;
}
- vprintf(stdout, "Remove leaf %s\n", cp);
+ Vprintf(stdout, "Remove leaf %s\n", cp);
}
/*
* Create a link.
*/
int
-linkit(existing, new, type)
- char *existing, *new;
- int type;
+linkit(char *existing, char *new, int type)
{
/* if we want to unlink first, do it now so *link() won't fail */
if (type == SYMLINK) {
if (!Nflag && symlink(existing, new) < 0) {
- fprintf(stderr,
- "warning: cannot create symbolic link %s->%s: %s\n",
- new, existing, strerror(errno));
+ warn("cannot create symbolic link %s->%s",
+ new, existing);
return (FAIL);
}
} else if (type == HARDLINK) {
}
#endif
if (ret < 0) {
- fprintf(stderr, "warning: cannot create "
- "hard link %s->%s: %s\n",
- new, existing, strerror(errno));
+ warn("warning: cannot create hard link %s->%s",
+ new, existing);
return (FAIL);
}
}
panic("linkit: unknown type %d\n", type);
return (FAIL);
}
- vprintf(stdout, "Create %s link %s->%s\n",
+ Vprintf(stdout, "Create %s link %s->%s\n",
type == SYMLINK ? "symbolic" : "hard", new, existing);
return (GOOD);
}
* Create a whiteout.
*/
int
-addwhiteout(name)
- char *name;
+addwhiteout(char *name)
{
if (!Nflag && mknod(name, S_IFWHT, 0) < 0) {
- fprintf(stderr, "warning: cannot create whiteout %s: %s\n",
- name, strerror(errno));
+ warn("cannot create whiteout %s", name);
return (FAIL);
}
- vprintf(stdout, "Create whiteout %s\n", name);
+ Vprintf(stdout, "Create whiteout %s\n", name);
return (GOOD);
}
* Delete a whiteout.
*/
void
-delwhiteout(ep)
- register struct entry *ep;
+delwhiteout(struct entry *ep)
{
char *name;
ep->e_flags &= ~TMPNAME;
name = myname(ep);
if (!Nflag && undelete(name) < 0) {
- fprintf(stderr, "warning: cannot delete whiteout %s: %s\n",
- name, strerror(errno));
+ warn("cannot delete whiteout %s", name);
return;
}
- vprintf(stdout, "Delete whiteout %s\n", name);
+ Vprintf(stdout, "Delete whiteout %s\n", name);
}
#endif
* find lowest number file (above "start") that needs to be extracted
*/
ino_t
-lowerbnd(start)
- ino_t start;
+lowerbnd(ino_t start)
{
register struct entry *ep;
* find highest number file (below "start") that needs to be extracted
*/
ino_t
-upperbnd(start)
- ino_t start;
+upperbnd(ino_t start)
{
register struct entry *ep;
* report on a badly formed entry
*/
void
-badentry(ep, msg)
- register struct entry *ep;
- char *msg;
+badentry(struct entry *ep, const char *msg)
{
fprintf(stderr, "bad entry: %s\n", msg);
"next hashchain name: %s\n", myname(ep->e_next));
fprintf(stderr, "entry type: %s\n",
ep->e_type == NODE ? "NODE" : "LEAF");
- fprintf(stderr, "inode number: %lu\n", (u_long)ep->e_ino);
+ fprintf(stderr, "inode number: %lu\n", (unsigned long)ep->e_ino);
panic("flags: %s\n", flagvalues(ep));
}
* Construct a string indicating the active flag bits of an entry.
*/
char *
-flagvalues(ep)
- register struct entry *ep;
+flagvalues(struct entry *ep)
{
static char flagbuf[BUFSIZ];
* Check to see if a name is on a dump tape.
*/
ino_t
-dirlookup(name)
- const char *name;
+dirlookup(const char *name)
{
struct direct *dp;
ino_t ino;
* Elicit a reply.
*/
int
-reply(question)
- char *question;
+reply(const char *question)
{
char c;
/*
* handle unexpected inconsistencies
*/
-#if __STDC__
+#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
-#if __STDC__
+#ifdef __STDC__
panic(const char *fmt, ...)
#else
panic(fmt, va_alist)
#endif
{
va_list ap;
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
if (reply("abort") == GOOD) {
if (reply("dump core") == GOOD)
abort();
- done(1);
+ exit(1);
}
}
@MCONFIG@
-CFLAGS= @CCOPTS@ -pipe $(GINC) $(INC) $(DEFS)
+CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS)
LDFLAGS:= $(LDFLAGS) @STATIC@
LIBS= $(GLIBS)
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 $";
+ "$Id: rmt.c,v 1.3 1999/10/11 12:59:21 stelian Exp $";
#endif /* not lint */
/*
#include <string.h>
#include <unistd.h>
+#ifdef __linux__
+#include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
+#include <bsdcompat.h>
+#endif
+
int tape = -1;
char *record;
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;
goto top;
}
-void
-getstring(bp)
- char *bp;
+void getstring(char *bp)
{
int i;
char *cp = bp;
}
char *
-checkbuf(record, size)
- char *record;
- int size;
+checkbuf(char *record, int size)
{
if (size <= maxrecsize)
}
void
-error(num)
- int num;
+error(int num)
{
DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));