2006-06-24 09:28:54 +04:00
|
|
|
/* $NetBSD: optr.c,v 1.35 2006/06/24 05:28:54 perseant Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
/*-
|
1994-06-08 22:57:30 +04:00
|
|
|
* Copyright (c) 1980, 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-12-22 13:19:31 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-12-22 13:19:31 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 11:58:01 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-12-22 13:19:31 +03:00
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)optr.c 8.2 (Berkeley) 1/6/94";
|
|
|
|
#else
|
2006-06-24 09:28:54 +04:00
|
|
|
__RCSID("$NetBSD: optr.c,v 1.35 2006/06/24 05:28:54 perseant Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1993-12-22 13:19:31 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2001-12-25 15:06:26 +03:00
|
|
|
#include <sys/queue.h>
|
1993-12-22 13:19:31 +03:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/time.h>
|
2001-05-28 05:09:54 +04:00
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
#include <errno.h>
|
1993-12-22 13:19:31 +03:00
|
|
|
#include <fstab.h>
|
|
|
|
#include <grp.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
1993-12-22 13:19:31 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
1998-04-01 20:15:40 +04:00
|
|
|
#include <time.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <tzfile.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
#include "dump.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2001-05-27 18:17:56 +04:00
|
|
|
void alarmcatch(int);
|
|
|
|
struct fstab *allocfsent(struct fstab *);
|
|
|
|
int datesort(const void *, const void *);
|
2001-10-15 17:25:33 +04:00
|
|
|
extern char *time_string;
|
|
|
|
extern char default_time_string[];
|
|
|
|
|
2005-06-27 05:37:32 +04:00
|
|
|
static void do_timestamp(time_t, const char *);
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Query the operator; This previously-fascist piece of code
|
|
|
|
* no longer requires an exact response.
|
|
|
|
* It is intended to protect dump aborting by inquisitive
|
|
|
|
* people banging on the console terminal to see what is
|
|
|
|
* happening which might cause dump to croak, destroying
|
|
|
|
* a large number of hours of work.
|
|
|
|
*
|
|
|
|
* Every 2 minutes we reprint the message, alerting others
|
|
|
|
* that dump needs attention.
|
|
|
|
*/
|
1994-06-08 22:57:30 +04:00
|
|
|
static int timeout;
|
2005-06-27 05:37:32 +04:00
|
|
|
static const char *attnmessage; /* attention message */
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
int
|
2005-06-27 05:37:32 +04:00
|
|
|
query(const char *question)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
|
|
|
char replybuffer[64];
|
|
|
|
int back, errcount;
|
|
|
|
FILE *mytty;
|
1996-05-18 20:16:17 +04:00
|
|
|
time_t firstprompt, when_answered;
|
|
|
|
|
|
|
|
firstprompt = time((time_t *)0);
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
|
|
|
|
quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
|
|
|
|
attnmessage = question;
|
|
|
|
timeout = 0;
|
1997-09-15 11:58:01 +04:00
|
|
|
alarmcatch(0);
|
1993-12-22 13:19:31 +03:00
|
|
|
back = -1;
|
|
|
|
errcount = 0;
|
|
|
|
do {
|
|
|
|
if (fgets(replybuffer, 63, mytty) == NULL) {
|
|
|
|
clearerr(mytty);
|
|
|
|
if (++errcount > 30) /* XXX ugly */
|
|
|
|
quit("excessive operator query failures\n");
|
|
|
|
} else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') {
|
|
|
|
back = 1;
|
|
|
|
} else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') {
|
|
|
|
back = 0;
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
" DUMP: \"Yes\" or \"No\"?\n");
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
" DUMP: %s: (\"yes\" or \"no\") ", question);
|
|
|
|
}
|
|
|
|
} while (back < 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off the alarm, and reset the signal to trap out..
|
|
|
|
*/
|
|
|
|
(void) alarm(0);
|
|
|
|
if (signal(SIGALRM, sig) == SIG_IGN)
|
|
|
|
signal(SIGALRM, SIG_IGN);
|
|
|
|
(void) fclose(mytty);
|
1996-05-18 20:16:17 +04:00
|
|
|
when_answered = time((time_t *)0);
|
|
|
|
/*
|
|
|
|
* Adjust the base for time estimates to ignore time we spent waiting
|
|
|
|
* for operator input.
|
|
|
|
*/
|
|
|
|
if (tstart_writing != 0)
|
2004-03-15 04:06:06 +03:00
|
|
|
tstart_writing += (when_answered - firstprompt);
|
|
|
|
if (tstart_volume != 0)
|
|
|
|
tstart_volume += (when_answered - firstprompt);
|
1993-12-22 13:19:31 +03:00
|
|
|
return(back);
|
|
|
|
}
|
|
|
|
|
2001-10-25 12:04:27 +04:00
|
|
|
char lastmsg[200];
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Alert the console operator, and enable the alarm clock to
|
|
|
|
* sleep for 2 minutes in case nobody comes to satisfy dump
|
|
|
|
*/
|
1994-06-08 22:57:30 +04:00
|
|
|
void
|
2001-05-27 18:17:56 +04:00
|
|
|
alarmcatch(int dummy)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
2001-05-27 18:17:56 +04:00
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
if (notify == 0) {
|
|
|
|
if (timeout == 0)
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
" DUMP: %s: (\"yes\" or \"no\") ",
|
|
|
|
attnmessage);
|
|
|
|
else
|
2001-12-25 15:06:26 +03:00
|
|
|
msgtail("\a\a");
|
1993-12-22 13:19:31 +03:00
|
|
|
} else {
|
|
|
|
if (timeout) {
|
|
|
|
msgtail("\n");
|
|
|
|
broadcast(""); /* just print last msg */
|
|
|
|
}
|
|
|
|
(void) fprintf(stderr," DUMP: %s: (\"yes\" or \"no\") ",
|
|
|
|
attnmessage);
|
|
|
|
}
|
|
|
|
signal(SIGALRM, alarmcatch);
|
|
|
|
(void) alarm(120);
|
|
|
|
timeout = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here if an inquisitive operator interrupts the dump program
|
|
|
|
*/
|
|
|
|
void
|
2001-05-27 18:17:56 +04:00
|
|
|
interrupt(int signo)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
2002-08-18 12:03:35 +04:00
|
|
|
int errno_save;
|
2001-05-27 18:17:56 +04:00
|
|
|
|
2002-08-18 12:03:35 +04:00
|
|
|
errno_save = errno;
|
1993-12-22 13:19:31 +03:00
|
|
|
msg("Interrupt received.\n");
|
|
|
|
if (query("Do you want to abort dump?"))
|
|
|
|
dumpabort(0);
|
2002-08-18 12:03:35 +04:00
|
|
|
errno = errno_save;
|
1993-12-22 13:19:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-03-27 16:56:46 +03:00
|
|
|
* Use wall(1) "-g operator" to do the actual broadcasting.
|
1993-12-22 13:19:31 +03:00
|
|
|
*/
|
|
|
|
void
|
2005-06-27 05:37:32 +04:00
|
|
|
broadcast(const char *message)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
2003-03-27 16:56:46 +03:00
|
|
|
FILE *fp;
|
|
|
|
char buf[sizeof(_PATH_WALL) + sizeof(OPGRENT) + 3];
|
1993-12-22 13:19:31 +03:00
|
|
|
|
2003-03-27 16:56:46 +03:00
|
|
|
if (!notify)
|
1993-12-22 13:19:31 +03:00
|
|
|
return;
|
|
|
|
|
2003-03-27 16:56:46 +03:00
|
|
|
(void)snprintf(buf, sizeof(buf), "%s -g %s", _PATH_WALL, OPGRENT);
|
|
|
|
if ((fp = popen(buf, "w")) == NULL)
|
1993-12-22 13:19:31 +03:00
|
|
|
return;
|
|
|
|
|
2003-03-27 16:56:46 +03:00
|
|
|
(void) fputs("\a\a\aMessage from the dump program to all operators\n\nDUMP: NEEDS ATTENTION: ", fp);
|
|
|
|
if (lastmsg[0])
|
|
|
|
(void) fputs(lastmsg, fp);
|
|
|
|
if (message[0])
|
|
|
|
(void) fputs(message, fp);
|
1993-12-22 13:19:31 +03:00
|
|
|
|
2003-03-27 16:56:46 +03:00
|
|
|
(void) pclose(fp);
|
1993-12-22 13:19:31 +03:00
|
|
|
}
|
|
|
|
|
2001-10-15 17:25:33 +04:00
|
|
|
/*
|
2001-12-22 11:05:24 +03:00
|
|
|
* print out the timestamp string to stderr.
|
2001-10-15 17:25:33 +04:00
|
|
|
*/
|
|
|
|
#define STAMP_LENGTH 80
|
|
|
|
|
|
|
|
static void
|
2005-06-27 05:37:32 +04:00
|
|
|
do_timestamp(time_t thistime, const char *message)
|
2001-10-15 17:25:33 +04:00
|
|
|
{
|
|
|
|
struct tm tm_time;
|
|
|
|
char then[STAMP_LENGTH + 1];
|
2001-12-23 15:29:55 +03:00
|
|
|
|
2001-11-01 11:03:03 +03:00
|
|
|
(void) localtime_r(&thistime, &tm_time);
|
2001-10-15 17:25:33 +04:00
|
|
|
if (strftime(then, STAMP_LENGTH, time_string, &tm_time) == 0) {
|
|
|
|
time_string = default_time_string;
|
|
|
|
strftime(then, STAMP_LENGTH, time_string, &tm_time);
|
|
|
|
fprintf(stderr,
|
|
|
|
"DUMP: ERROR: TIMEFORMAT too long, reverting to default\n");
|
|
|
|
}
|
2001-12-23 15:29:55 +03:00
|
|
|
|
2001-11-01 11:03:03 +03:00
|
|
|
fprintf(stderr, message, then);
|
2001-10-15 17:25:33 +04:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:29:55 +03:00
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
/*
|
|
|
|
* print out an estimate of the amount of time left to do the dump
|
|
|
|
*/
|
|
|
|
|
|
|
|
time_t tschedule = 0;
|
|
|
|
|
|
|
|
void
|
2001-05-27 18:17:56 +04:00
|
|
|
timeest(void)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
|
|
|
time_t tnow, deltat;
|
|
|
|
|
|
|
|
(void) time((time_t *) &tnow);
|
|
|
|
if (tnow >= tschedule) {
|
|
|
|
tschedule = tnow + 300;
|
|
|
|
if (blockswritten < 500)
|
2001-12-23 15:29:55 +03:00
|
|
|
return;
|
1993-12-22 13:19:31 +03:00
|
|
|
deltat = tstart_writing - tnow +
|
|
|
|
(1.0 * (tnow - tstart_writing))
|
|
|
|
/ blockswritten * tapesize;
|
2001-10-15 17:25:33 +04:00
|
|
|
|
|
|
|
msg("%3.2f%% done, finished in %ld:%02ld",
|
2000-10-11 00:24:49 +04:00
|
|
|
(blockswritten * 100.0) / tapesize,
|
|
|
|
(long)(deltat / 3600), (long)((deltat % 3600) / 60));
|
2001-12-23 15:29:55 +03:00
|
|
|
|
2001-10-15 17:25:33 +04:00
|
|
|
if (timestamp == 1)
|
|
|
|
do_timestamp(tnow + deltat, " (at %s)");
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
1993-12-22 13:19:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
msg(const char *fmt, ...)
|
|
|
|
{
|
2001-12-22 11:05:24 +03:00
|
|
|
time_t tnow;
|
1993-12-22 13:19:31 +03:00
|
|
|
va_list ap;
|
|
|
|
|
2001-10-15 17:25:33 +04:00
|
|
|
fprintf(stderr, " ");
|
2001-12-22 11:05:24 +03:00
|
|
|
if (timestamp == 1) {
|
|
|
|
(void) time((time_t *) &tnow);
|
2001-10-15 17:25:33 +04:00
|
|
|
do_timestamp(tnow, "[%s] ");
|
2001-12-22 11:05:24 +03:00
|
|
|
}
|
2001-10-15 17:25:33 +04:00
|
|
|
|
|
|
|
(void) fprintf(stderr,"DUMP: ");
|
1993-12-22 13:19:31 +03:00
|
|
|
#ifdef TDEBUG
|
|
|
|
(void) fprintf(stderr, "pid=%d ", getpid());
|
|
|
|
#endif
|
|
|
|
va_start(ap, fmt);
|
2001-10-25 12:04:27 +04:00
|
|
|
(void) vsnprintf(lastmsg, sizeof lastmsg, fmt, ap);
|
|
|
|
fputs(lastmsg, stderr);
|
1993-12-22 13:19:31 +03:00
|
|
|
(void) fflush(stdout);
|
|
|
|
(void) fflush(stderr);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
msgtail(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2001-05-27 18:17:56 +04:00
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void) vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
quit(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
(void) fprintf(stderr," DUMP: ");
|
|
|
|
#ifdef TDEBUG
|
|
|
|
(void) fprintf(stderr, "pid=%d ", getpid());
|
|
|
|
#endif
|
|
|
|
va_start(ap, fmt);
|
|
|
|
(void) vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
(void) fflush(stdout);
|
|
|
|
(void) fflush(stderr);
|
|
|
|
dumpabort(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the operator what has to be done;
|
|
|
|
* we don't actually do it
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct fstab *
|
2001-05-27 18:17:56 +04:00
|
|
|
allocfsent(struct fstab *fs)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
1997-04-15 05:09:49 +04:00
|
|
|
struct fstab *new;
|
1993-12-22 13:19:31 +03:00
|
|
|
|
2001-05-28 05:09:54 +04:00
|
|
|
new = (struct fstab *)xmalloc(sizeof (*fs));
|
|
|
|
new->fs_file = xstrdup(fs->fs_file);
|
|
|
|
new->fs_type = xstrdup(fs->fs_type);
|
|
|
|
new->fs_spec = xstrdup(fs->fs_spec);
|
1993-12-22 13:19:31 +03:00
|
|
|
new->fs_passno = fs->fs_passno;
|
|
|
|
new->fs_freq = fs->fs_freq;
|
|
|
|
return (new);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pfstab {
|
2001-12-25 15:06:26 +03:00
|
|
|
SLIST_ENTRY(pfstab) pf_list;
|
1993-12-22 13:19:31 +03:00
|
|
|
struct fstab *pf_fstab;
|
|
|
|
};
|
|
|
|
|
2001-12-25 15:06:26 +03:00
|
|
|
static SLIST_HEAD(, pfstab) table;
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
void
|
2001-05-27 18:17:56 +04:00
|
|
|
getfstab(void)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
1997-04-15 05:09:49 +04:00
|
|
|
struct fstab *fs;
|
|
|
|
struct pfstab *pf;
|
1993-12-22 13:19:31 +03:00
|
|
|
|
|
|
|
if (setfsent() == 0) {
|
|
|
|
msg("Can't open %s for dump table information: %s\n",
|
|
|
|
_PATH_FSTAB, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
while ((fs = getfsent()) != NULL) {
|
1993-12-22 13:19:31 +03:00
|
|
|
if (strcmp(fs->fs_type, FSTAB_RW) &&
|
|
|
|
strcmp(fs->fs_type, FSTAB_RO) &&
|
|
|
|
strcmp(fs->fs_type, FSTAB_RQ))
|
|
|
|
continue;
|
2001-12-24 06:02:34 +03:00
|
|
|
#ifdef DUMP_LFS
|
|
|
|
if (strcmp(fs->fs_vfstype, "lfs"))
|
|
|
|
continue;
|
|
|
|
#else
|
1997-01-17 01:00:30 +03:00
|
|
|
if (strcmp(fs->fs_vfstype, "ufs") &&
|
|
|
|
strcmp(fs->fs_vfstype, "ffs"))
|
|
|
|
continue;
|
2001-12-24 06:02:34 +03:00
|
|
|
#endif
|
1993-12-22 13:19:31 +03:00
|
|
|
fs = allocfsent(fs);
|
2001-05-28 05:09:54 +04:00
|
|
|
pf = (struct pfstab *)xmalloc(sizeof (*pf));
|
1993-12-22 13:19:31 +03:00
|
|
|
pf->pf_fstab = fs;
|
2001-12-25 15:06:26 +03:00
|
|
|
SLIST_INSERT_HEAD(&table, pf, pf_list);
|
1993-12-22 13:19:31 +03:00
|
|
|
}
|
|
|
|
(void) endfsent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search in the fstab for a file name.
|
|
|
|
* This file name can be either the special or the path file name.
|
|
|
|
*
|
|
|
|
* The entries in the fstab are the BLOCK special names, not the
|
|
|
|
* character special names.
|
|
|
|
* The caller of fstabsearch assures that the character device
|
|
|
|
* is dumped (that is much faster)
|
|
|
|
*
|
|
|
|
* The file name can omit the leading '/'.
|
|
|
|
*/
|
|
|
|
struct fstab *
|
2001-05-28 05:09:54 +04:00
|
|
|
fstabsearch(const char *key)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
1997-04-15 05:09:49 +04:00
|
|
|
struct pfstab *pf;
|
|
|
|
struct fstab *fs;
|
1994-06-08 22:57:30 +04:00
|
|
|
char *rn;
|
1993-12-22 13:19:31 +03:00
|
|
|
|
2001-12-25 15:06:26 +03:00
|
|
|
SLIST_FOREACH(pf, &table, pf_list) {
|
1993-12-22 13:19:31 +03:00
|
|
|
fs = pf->pf_fstab;
|
|
|
|
if (strcmp(fs->fs_file, key) == 0 ||
|
|
|
|
strcmp(fs->fs_spec, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
rn = rawname(fs->fs_spec);
|
|
|
|
if (rn != NULL && strcmp(rn, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
if (key[0] != '/') {
|
|
|
|
if (*fs->fs_spec == '/' &&
|
|
|
|
strcmp(fs->fs_spec + 1, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
if (*fs->fs_file == '/' &&
|
|
|
|
strcmp(fs->fs_file + 1, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2001-05-28 05:09:54 +04:00
|
|
|
/*
|
|
|
|
* Search in the mounted file list for a file name.
|
|
|
|
* This file name can be either the special or the path file name.
|
|
|
|
*
|
|
|
|
* The entries in the list are the BLOCK special names, not the
|
|
|
|
* character special names.
|
|
|
|
* The caller of mntinfosearch assures that the character device
|
|
|
|
* is dumped (that is much faster)
|
|
|
|
*/
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *
|
2001-05-28 05:09:54 +04:00
|
|
|
mntinfosearch(const char *key)
|
|
|
|
{
|
|
|
|
int i, mntbufc;
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *mntbuf, *fs;
|
2001-05-28 05:09:54 +04:00
|
|
|
char *rn;
|
|
|
|
|
|
|
|
if ((mntbufc = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
|
|
|
quit("Can't get mount list: %s", strerror(errno));
|
|
|
|
for (fs = mntbuf, i = 0; i < mntbufc; i++, fs++) {
|
2006-06-24 09:28:54 +04:00
|
|
|
#ifdef DUMP_LFS
|
|
|
|
if (strcmp(fs->f_fstypename, "lfs") != 0)
|
|
|
|
continue;
|
|
|
|
#else /* ! DUMP_LFS */
|
2001-05-28 05:09:54 +04:00
|
|
|
if (strcmp(fs->f_fstypename, "ufs") != 0 &&
|
|
|
|
strcmp(fs->f_fstypename, "ffs") != 0)
|
|
|
|
continue;
|
2006-06-24 09:28:54 +04:00
|
|
|
#endif /* ! DUMP_LFS */
|
2001-05-28 05:09:54 +04:00
|
|
|
if (strcmp(fs->f_mntonname, key) == 0 ||
|
|
|
|
strcmp(fs->f_mntfromname, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
rn = rawname(fs->f_mntfromname);
|
|
|
|
if (rn != NULL && strcmp(rn, key) == 0)
|
|
|
|
return (fs);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-12-22 13:19:31 +03:00
|
|
|
/*
|
2001-05-27 18:17:56 +04:00
|
|
|
* Tell the operator what to do.
|
|
|
|
* arg: w ==> just what to do; W ==> most recent dumps
|
1993-12-22 13:19:31 +03:00
|
|
|
*/
|
|
|
|
void
|
2001-05-27 18:17:56 +04:00
|
|
|
lastdump(char arg)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
1997-04-15 05:09:49 +04:00
|
|
|
int i;
|
|
|
|
struct fstab *dt;
|
|
|
|
struct dumpdates *dtwalk;
|
2005-06-27 05:37:32 +04:00
|
|
|
char *date;
|
|
|
|
const char *lastname;
|
1994-06-08 22:57:30 +04:00
|
|
|
int dumpme;
|
1993-12-22 13:19:31 +03:00
|
|
|
time_t tnow;
|
|
|
|
|
|
|
|
(void) time(&tnow);
|
|
|
|
getfstab(); /* /etc/fstab input */
|
|
|
|
initdumptimes(); /* /etc/dumpdates input */
|
|
|
|
qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
|
|
|
|
|
|
|
|
if (arg == 'w')
|
|
|
|
(void) printf("Dump these file systems:\n");
|
|
|
|
else
|
|
|
|
(void) printf("Last dump(s) done (Dump '>' file systems):\n");
|
|
|
|
lastname = "??";
|
|
|
|
ITITERATE(i, dtwalk) {
|
|
|
|
if (strncmp(lastname, dtwalk->dd_name,
|
|
|
|
sizeof(dtwalk->dd_name)) == 0)
|
|
|
|
continue;
|
|
|
|
date = (char *)ctime(&dtwalk->dd_ddate);
|
1997-04-10 09:36:23 +04:00
|
|
|
date[24] = '\0';
|
|
|
|
strcpy(date + 16, date + 19); /* blast away seconds */
|
1993-12-22 13:19:31 +03:00
|
|
|
lastname = dtwalk->dd_name;
|
|
|
|
dt = fstabsearch(dtwalk->dd_name);
|
|
|
|
dumpme = (dt != NULL &&
|
|
|
|
dt->fs_freq != 0 &&
|
|
|
|
dtwalk->dd_ddate < tnow - (dt->fs_freq * SECSPERDAY));
|
|
|
|
if (arg != 'w' || dumpme)
|
|
|
|
(void) printf(
|
|
|
|
"%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
|
|
|
|
dumpme && (arg != 'w') ? '>' : ' ',
|
|
|
|
dtwalk->dd_name,
|
|
|
|
dt ? dt->fs_file : "",
|
|
|
|
dtwalk->dd_level,
|
|
|
|
date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-05-27 18:17:56 +04:00
|
|
|
datesort(const void *a1, const void *a2)
|
1993-12-22 13:19:31 +03:00
|
|
|
{
|
2005-06-27 05:37:32 +04:00
|
|
|
const struct dumpdates *d1 = *(const struct dumpdates *const *)a1;
|
|
|
|
const struct dumpdates *d2 = *(const struct dumpdates *const *)a2;
|
1993-12-22 13:19:31 +03:00
|
|
|
int diff;
|
|
|
|
|
|
|
|
diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name));
|
|
|
|
if (diff == 0)
|
|
|
|
return (d2->dd_ddate - d1->dd_ddate);
|
|
|
|
return (diff);
|
|
|
|
}
|