Home | History | Annotate | Line # | Download | only in dump
optr.c revision 1.28
      1  1.28      yamt /*	$NetBSD: optr.c,v 1.28 2002/08/18 08:03:35 yamt Exp $	*/
      2   1.3       cgd 
      3   1.1       cgd /*-
      4   1.2   mycroft  * Copyright (c) 1980, 1988, 1993
      5   1.2   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.12     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38   1.3       cgd #if 0
     39   1.3       cgd static char sccsid[] = "@(#)optr.c	8.2 (Berkeley) 1/6/94";
     40   1.3       cgd #else
     41  1.28      yamt __RCSID("$NetBSD: optr.c,v 1.28 2002/08/18 08:03:35 yamt Exp $");
     42   1.3       cgd #endif
     43   1.1       cgd #endif /* not lint */
     44   1.1       cgd 
     45   1.1       cgd #include <sys/param.h>
     46  1.25     lukem #include <sys/queue.h>
     47   1.1       cgd #include <sys/wait.h>
     48   1.1       cgd #include <sys/time.h>
     49  1.17     lukem #include <sys/ucred.h>
     50  1.17     lukem #include <sys/mount.h>
     51   1.2   mycroft 
     52   1.2   mycroft #include <errno.h>
     53   1.1       cgd #include <fstab.h>
     54   1.1       cgd #include <grp.h>
     55   1.2   mycroft #include <signal.h>
     56   1.2   mycroft #include <stdio.h>
     57   1.1       cgd #include <stdlib.h>
     58   1.1       cgd #include <string.h>
     59   1.1       cgd #include <stdarg.h>
     60  1.13    kleink #include <time.h>
     61   1.2   mycroft #include <tzfile.h>
     62   1.2   mycroft #include <unistd.h>
     63   1.2   mycroft 
     64   1.1       cgd #include "dump.h"
     65   1.1       cgd #include "pathnames.h"
     66   1.1       cgd 
     67  1.26  christos #include "utmpentry.h"
     68  1.26  christos 
     69  1.15     lukem void	alarmcatch(int);
     70  1.15     lukem struct fstab *allocfsent(struct fstab *);
     71  1.15     lukem int	datesort(const void *, const void *);
     72  1.15     lukem static	void sendmes(char *, char *);
     73  1.18     david extern  gid_t egid;
     74  1.19     blymn extern  char *time_string;
     75  1.19     blymn extern  char default_time_string[];
     76  1.19     blymn 
     77  1.21     lukem static void do_timestamp(time_t, char *);
     78   1.1       cgd 
     79   1.1       cgd /*
     80   1.1       cgd  *	Query the operator; This previously-fascist piece of code
     81   1.1       cgd  *	no longer requires an exact response.
     82   1.1       cgd  *	It is intended to protect dump aborting by inquisitive
     83   1.1       cgd  *	people banging on the console terminal to see what is
     84   1.1       cgd  *	happening which might cause dump to croak, destroying
     85   1.1       cgd  *	a large number of hours of work.
     86   1.1       cgd  *
     87   1.1       cgd  *	Every 2 minutes we reprint the message, alerting others
     88   1.1       cgd  *	that dump needs attention.
     89   1.1       cgd  */
     90   1.2   mycroft static	int timeout;
     91   1.2   mycroft static	char *attnmessage;		/* attention message */
     92   1.1       cgd 
     93   1.1       cgd int
     94  1.15     lukem query(char *question)
     95   1.1       cgd {
     96   1.1       cgd 	char	replybuffer[64];
     97   1.1       cgd 	int	back, errcount;
     98   1.1       cgd 	FILE	*mytty;
     99   1.4       jtk 	time_t	firstprompt, when_answered;
    100   1.4       jtk 
    101   1.4       jtk 	firstprompt = time((time_t *)0);
    102   1.1       cgd 
    103   1.1       cgd 	if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
    104   1.1       cgd 		quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
    105   1.1       cgd 	attnmessage = question;
    106   1.1       cgd 	timeout = 0;
    107  1.12     lukem 	alarmcatch(0);
    108   1.1       cgd 	back = -1;
    109   1.1       cgd 	errcount = 0;
    110   1.1       cgd 	do {
    111   1.1       cgd 		if (fgets(replybuffer, 63, mytty) == NULL) {
    112   1.1       cgd 			clearerr(mytty);
    113   1.1       cgd 			if (++errcount > 30)	/* XXX	ugly */
    114   1.1       cgd 				quit("excessive operator query failures\n");
    115   1.1       cgd 		} else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') {
    116   1.1       cgd 			back = 1;
    117   1.1       cgd 		} else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') {
    118   1.1       cgd 			back = 0;
    119   1.1       cgd 		} else {
    120   1.1       cgd 			(void) fprintf(stderr,
    121   1.1       cgd 			    "  DUMP: \"Yes\" or \"No\"?\n");
    122   1.1       cgd 			(void) fprintf(stderr,
    123   1.1       cgd 			    "  DUMP: %s: (\"yes\" or \"no\") ", question);
    124   1.1       cgd 		}
    125   1.1       cgd 	} while (back < 0);
    126   1.1       cgd 
    127   1.1       cgd 	/*
    128   1.1       cgd 	 *	Turn off the alarm, and reset the signal to trap out..
    129   1.1       cgd 	 */
    130   1.1       cgd 	(void) alarm(0);
    131   1.1       cgd 	if (signal(SIGALRM, sig) == SIG_IGN)
    132   1.1       cgd 		signal(SIGALRM, SIG_IGN);
    133   1.1       cgd 	(void) fclose(mytty);
    134   1.4       jtk 	when_answered = time((time_t *)0);
    135   1.4       jtk 	/*
    136   1.4       jtk 	 * Adjust the base for time estimates to ignore time we spent waiting
    137   1.4       jtk 	 * for operator input.
    138   1.4       jtk 	 */
    139   1.4       jtk 	if (tstart_writing != 0)
    140   1.4       jtk 	    tstart_writing += (when_answered - firstprompt);
    141   1.1       cgd 	return(back);
    142   1.1       cgd }
    143   1.1       cgd 
    144  1.20     lukem char lastmsg[200];
    145   1.1       cgd 
    146   1.1       cgd /*
    147   1.1       cgd  *	Alert the console operator, and enable the alarm clock to
    148   1.1       cgd  *	sleep for 2 minutes in case nobody comes to satisfy dump
    149   1.1       cgd  */
    150   1.2   mycroft void
    151  1.15     lukem alarmcatch(int dummy)
    152   1.1       cgd {
    153  1.15     lukem 
    154   1.1       cgd 	if (notify == 0) {
    155   1.1       cgd 		if (timeout == 0)
    156   1.1       cgd 			(void) fprintf(stderr,
    157   1.1       cgd 			    "  DUMP: %s: (\"yes\" or \"no\") ",
    158   1.1       cgd 			    attnmessage);
    159   1.1       cgd 		else
    160  1.25     lukem 			msgtail("\a\a");
    161   1.1       cgd 	} else {
    162   1.1       cgd 		if (timeout) {
    163   1.1       cgd 			msgtail("\n");
    164   1.1       cgd 			broadcast("");		/* just print last msg */
    165   1.1       cgd 		}
    166   1.1       cgd 		(void) fprintf(stderr,"  DUMP: %s: (\"yes\" or \"no\") ",
    167   1.1       cgd 		    attnmessage);
    168   1.1       cgd 	}
    169   1.1       cgd 	signal(SIGALRM, alarmcatch);
    170   1.1       cgd 	(void) alarm(120);
    171   1.1       cgd 	timeout = 1;
    172   1.1       cgd }
    173   1.1       cgd 
    174   1.1       cgd /*
    175   1.1       cgd  *	Here if an inquisitive operator interrupts the dump program
    176   1.1       cgd  */
    177   1.1       cgd void
    178  1.15     lukem interrupt(int signo)
    179   1.1       cgd {
    180  1.28      yamt 	int errno_save;
    181  1.15     lukem 
    182  1.28      yamt 	errno_save = errno;
    183   1.1       cgd 	msg("Interrupt received.\n");
    184   1.1       cgd 	if (query("Do you want to abort dump?"))
    185   1.1       cgd 		dumpabort(0);
    186  1.28      yamt 	errno = errno_save;
    187   1.1       cgd }
    188   1.1       cgd 
    189   1.1       cgd /*
    190   1.1       cgd  *	The following variables and routines manage alerting
    191   1.1       cgd  *	operators to the status of dump.
    192   1.1       cgd  *	This works much like wall(1) does.
    193   1.1       cgd  */
    194   1.1       cgd struct	group *gp;
    195   1.1       cgd 
    196   1.1       cgd /*
    197   1.1       cgd  *	Get the names from the group entry "operator" to notify.
    198  1.23     lukem  */
    199   1.1       cgd void
    200  1.15     lukem set_operators(void)
    201   1.1       cgd {
    202  1.15     lukem 
    203   1.1       cgd 	if (!notify)		/*not going to notify*/
    204   1.1       cgd 		return;
    205   1.1       cgd 	gp = getgrnam(OPGRENT);
    206   1.1       cgd 	(void) endgrent();
    207   1.1       cgd 	if (gp == NULL) {
    208   1.1       cgd 		msg("No group entry for %s.\n", OPGRENT);
    209   1.1       cgd 		notify = 0;
    210   1.1       cgd 		return;
    211   1.1       cgd 	}
    212   1.1       cgd }
    213   1.1       cgd 
    214   1.1       cgd struct tm *localclock;
    215   1.1       cgd 
    216   1.1       cgd /*
    217   1.1       cgd  *	We fork a child to do the actual broadcasting, so
    218   1.1       cgd  *	that the process control groups are not messed up
    219   1.1       cgd  */
    220   1.1       cgd void
    221  1.15     lukem broadcast(char	*message)
    222   1.1       cgd {
    223  1.21     lukem 	time_t	now;
    224  1.21     lukem 	char  **np;
    225   1.1       cgd 	int	pid, s;
    226  1.26  christos 	struct utmpentry *ep;
    227   1.1       cgd 
    228   1.1       cgd 	if (!notify || gp == NULL)
    229   1.1       cgd 		return;
    230   1.1       cgd 
    231  1.23     lukem 	/* Restore 'tty' privs for the child's use only. */
    232  1.18     david 	setegid(egid);
    233   1.1       cgd 	switch (pid = fork()) {
    234   1.1       cgd 	case -1:
    235  1.18     david 		setegid(getgid());
    236   1.1       cgd 		return;
    237   1.1       cgd 	case 0:
    238   1.1       cgd 		break;
    239   1.1       cgd 	default:
    240  1.18     david 		setegid(getgid());
    241   1.1       cgd 		while (wait(&s) != pid)
    242   1.1       cgd 			continue;
    243   1.1       cgd 		return;
    244   1.1       cgd 	}
    245   1.1       cgd 
    246  1.21     lukem 	now = time((time_t *)0);
    247  1.21     lukem 	localclock = localtime(&now);
    248   1.1       cgd 
    249  1.26  christos 	(void)getutentries(NULL, &ep);
    250   1.1       cgd 
    251  1.26  christos 	for (; ep; ep = ep->next) {
    252   1.1       cgd 		for (np = gp->gr_mem; *np; np++) {
    253  1.26  christos 			if (strcmp(*np, ep->name) != 0)
    254   1.1       cgd 				continue;
    255   1.1       cgd 			/*
    256   1.1       cgd 			 *	Do not send messages to operators on dialups
    257   1.1       cgd 			 */
    258  1.26  christos 			if (strcmp(ep->line, DIALUP) == 0)
    259   1.1       cgd 				continue;
    260   1.1       cgd #ifdef DEBUG
    261  1.26  christos 			msg("Message to %s at %s\n", *np, ep->line);
    262   1.1       cgd #endif
    263  1.26  christos 			sendmes(ep->line, message);
    264   1.1       cgd 		}
    265   1.1       cgd 	}
    266   1.1       cgd 	Exit(0);	/* the wait in this same routine will catch this */
    267   1.1       cgd 	/* NOTREACHED */
    268   1.1       cgd }
    269   1.1       cgd 
    270   1.1       cgd static void
    271  1.15     lukem sendmes(char *tty, char *message)
    272   1.1       cgd {
    273   1.1       cgd 	char t[50], buf[BUFSIZ];
    274   1.7     lukem 	char *cp;
    275   1.1       cgd 	int lmsg = 1;
    276   1.1       cgd 	FILE *f_tty;
    277   1.1       cgd 
    278  1.27    itojun 	if (strcspn(tty, "./") != strlen(tty))
    279  1.27    itojun 		return;
    280  1.27    itojun 
    281   1.8       mrg 	(void)strncpy(t, _PATH_DEV, sizeof(t) - 1);
    282  1.11       mrg 	(void)strncat(t, tty, sizeof(t) - sizeof(_PATH_DEV) - 1);
    283   1.8       mrg 	t[sizeof(t) - 1] = '\0';
    284   1.1       cgd 
    285   1.1       cgd 	if ((f_tty = fopen(t, "w")) != NULL) {
    286  1.27    itojun 		if (!isatty(fileno(f_tty)))
    287  1.27    itojun 			return;
    288   1.1       cgd 		setbuf(f_tty, buf);
    289   1.1       cgd 		(void) fprintf(f_tty,
    290   1.1       cgd 		    "\n\
    291  1.25     lukem \a\a\aMessage from the dump program to all operators at %d:%02d ...\r\n\n\
    292   1.1       cgd DUMP: NEEDS ATTENTION: ",
    293   1.1       cgd 		    localclock->tm_hour, localclock->tm_min);
    294   1.1       cgd 		for (cp = lastmsg; ; cp++) {
    295   1.1       cgd 			if (*cp == '\0') {
    296   1.1       cgd 				if (lmsg) {
    297   1.1       cgd 					cp = message;
    298   1.1       cgd 					if (*cp == '\0')
    299   1.1       cgd 						break;
    300   1.1       cgd 					lmsg = 0;
    301   1.1       cgd 				} else
    302   1.1       cgd 					break;
    303   1.1       cgd 			}
    304   1.1       cgd 			if (*cp == '\n')
    305   1.1       cgd 				(void) putc('\r', f_tty);
    306   1.1       cgd 			(void) putc(*cp, f_tty);
    307   1.1       cgd 		}
    308   1.1       cgd 		(void) fclose(f_tty);
    309   1.1       cgd 	}
    310   1.1       cgd }
    311   1.1       cgd 
    312   1.1       cgd /*
    313  1.22     lukem  *	print out the timestamp string to stderr.
    314  1.19     blymn  */
    315  1.19     blymn #define STAMP_LENGTH 80
    316  1.19     blymn 
    317  1.19     blymn static void
    318  1.21     lukem do_timestamp(time_t thistime, char *message)
    319  1.19     blymn {
    320  1.19     blymn 	struct tm tm_time;
    321  1.19     blymn 	char then[STAMP_LENGTH + 1];
    322  1.23     lukem 
    323  1.21     lukem 	(void) localtime_r(&thistime, &tm_time);
    324  1.19     blymn 	if (strftime(then, STAMP_LENGTH, time_string, &tm_time) == 0) {
    325  1.19     blymn 		time_string = default_time_string;
    326  1.19     blymn 		strftime(then, STAMP_LENGTH, time_string, &tm_time);
    327  1.19     blymn 		fprintf(stderr,
    328  1.19     blymn 		   "DUMP: ERROR: TIMEFORMAT too long, reverting to default\n");
    329  1.19     blymn 	}
    330  1.23     lukem 
    331  1.21     lukem 	fprintf(stderr, message, then);
    332  1.19     blymn }
    333  1.19     blymn 
    334  1.23     lukem 
    335  1.19     blymn /*
    336   1.1       cgd  *	print out an estimate of the amount of time left to do the dump
    337   1.1       cgd  */
    338   1.1       cgd 
    339   1.1       cgd time_t	tschedule = 0;
    340   1.1       cgd 
    341   1.1       cgd void
    342  1.15     lukem timeest(void)
    343   1.1       cgd {
    344   1.1       cgd 	time_t	tnow, deltat;
    345   1.1       cgd 
    346   1.1       cgd 	(void) time((time_t *) &tnow);
    347   1.1       cgd 	if (tnow >= tschedule) {
    348   1.1       cgd 		tschedule = tnow + 300;
    349   1.1       cgd 		if (blockswritten < 500)
    350  1.23     lukem 			return;
    351   1.1       cgd 		deltat = tstart_writing - tnow +
    352   1.1       cgd 			(1.0 * (tnow - tstart_writing))
    353   1.1       cgd 			/ blockswritten * tapesize;
    354  1.19     blymn 
    355  1.19     blymn 		msg("%3.2f%% done, finished in %ld:%02ld",
    356  1.14        is 		    (blockswritten * 100.0) / tapesize,
    357  1.14        is 		    (long)(deltat / 3600), (long)((deltat % 3600) / 60));
    358  1.23     lukem 
    359  1.19     blymn 		if (timestamp == 1)
    360  1.19     blymn 			do_timestamp(tnow + deltat, " (at %s)");
    361  1.19     blymn 
    362  1.19     blymn 		fprintf(stderr, "\n");
    363   1.1       cgd 	}
    364   1.1       cgd }
    365   1.1       cgd 
    366   1.1       cgd void
    367   1.1       cgd msg(const char *fmt, ...)
    368   1.1       cgd {
    369  1.22     lukem 	time_t  tnow;
    370   1.1       cgd 	va_list ap;
    371   1.1       cgd 
    372  1.19     blymn 	fprintf(stderr, "  ");
    373  1.22     lukem 	if (timestamp == 1) {
    374  1.22     lukem 		(void) time((time_t *) &tnow);
    375  1.19     blymn 		do_timestamp(tnow, "[%s] ");
    376  1.22     lukem 	}
    377  1.19     blymn 
    378  1.19     blymn 	(void) fprintf(stderr,"DUMP: ");
    379   1.1       cgd #ifdef TDEBUG
    380   1.1       cgd 	(void) fprintf(stderr, "pid=%d ", getpid());
    381   1.1       cgd #endif
    382   1.1       cgd 	va_start(ap, fmt);
    383  1.20     lukem 	(void) vsnprintf(lastmsg, sizeof lastmsg, fmt, ap);
    384  1.20     lukem 	fputs(lastmsg, stderr);
    385   1.1       cgd 	(void) fflush(stdout);
    386   1.1       cgd 	(void) fflush(stderr);
    387   1.1       cgd 	va_end(ap);
    388   1.1       cgd }
    389   1.1       cgd 
    390   1.1       cgd void
    391   1.1       cgd msgtail(const char *fmt, ...)
    392   1.1       cgd {
    393   1.1       cgd 	va_list ap;
    394  1.15     lukem 
    395   1.1       cgd 	va_start(ap, fmt);
    396   1.1       cgd 	(void) vfprintf(stderr, fmt, ap);
    397   1.1       cgd 	va_end(ap);
    398   1.1       cgd }
    399   1.1       cgd 
    400   1.1       cgd void
    401   1.1       cgd quit(const char *fmt, ...)
    402   1.1       cgd {
    403   1.1       cgd 	va_list ap;
    404   1.1       cgd 
    405   1.1       cgd 	(void) fprintf(stderr,"  DUMP: ");
    406   1.1       cgd #ifdef TDEBUG
    407   1.1       cgd 	(void) fprintf(stderr, "pid=%d ", getpid());
    408   1.1       cgd #endif
    409   1.1       cgd 	va_start(ap, fmt);
    410   1.1       cgd 	(void) vfprintf(stderr, fmt, ap);
    411   1.1       cgd 	va_end(ap);
    412   1.1       cgd 	(void) fflush(stdout);
    413   1.1       cgd 	(void) fflush(stderr);
    414   1.1       cgd 	dumpabort(0);
    415   1.1       cgd }
    416   1.1       cgd 
    417   1.1       cgd /*
    418   1.1       cgd  *	Tell the operator what has to be done;
    419   1.1       cgd  *	we don't actually do it
    420   1.1       cgd  */
    421   1.1       cgd 
    422   1.1       cgd struct fstab *
    423  1.15     lukem allocfsent(struct fstab *fs)
    424   1.1       cgd {
    425   1.7     lukem 	struct fstab *new;
    426   1.1       cgd 
    427  1.17     lukem 	new = (struct fstab *)xmalloc(sizeof (*fs));
    428  1.17     lukem 	new->fs_file = xstrdup(fs->fs_file);
    429  1.17     lukem 	new->fs_type = xstrdup(fs->fs_type);
    430  1.17     lukem 	new->fs_spec = xstrdup(fs->fs_spec);
    431   1.1       cgd 	new->fs_passno = fs->fs_passno;
    432   1.1       cgd 	new->fs_freq = fs->fs_freq;
    433   1.1       cgd 	return (new);
    434   1.1       cgd }
    435   1.1       cgd 
    436   1.1       cgd struct	pfstab {
    437  1.25     lukem 	SLIST_ENTRY(pfstab) pf_list;
    438   1.1       cgd 	struct	fstab *pf_fstab;
    439   1.1       cgd };
    440   1.1       cgd 
    441  1.25     lukem static	SLIST_HEAD(, pfstab) table;
    442   1.1       cgd 
    443   1.1       cgd void
    444  1.15     lukem getfstab(void)
    445   1.1       cgd {
    446   1.7     lukem 	struct fstab *fs;
    447   1.7     lukem 	struct pfstab *pf;
    448   1.1       cgd 
    449   1.1       cgd 	if (setfsent() == 0) {
    450   1.1       cgd 		msg("Can't open %s for dump table information: %s\n",
    451   1.1       cgd 		    _PATH_FSTAB, strerror(errno));
    452   1.1       cgd 		return;
    453   1.1       cgd 	}
    454   1.2   mycroft 	while ((fs = getfsent()) != NULL) {
    455   1.1       cgd 		if (strcmp(fs->fs_type, FSTAB_RW) &&
    456   1.1       cgd 		    strcmp(fs->fs_type, FSTAB_RO) &&
    457   1.1       cgd 		    strcmp(fs->fs_type, FSTAB_RQ))
    458   1.5     perry 			continue;
    459  1.24     lukem #ifdef DUMP_LFS
    460  1.24     lukem 		if (strcmp(fs->fs_vfstype, "lfs"))
    461  1.24     lukem 			continue;
    462  1.24     lukem #else
    463   1.5     perry 		if (strcmp(fs->fs_vfstype, "ufs") &&
    464   1.5     perry 		    strcmp(fs->fs_vfstype, "ffs"))
    465   1.1       cgd 			continue;
    466  1.24     lukem #endif
    467   1.1       cgd 		fs = allocfsent(fs);
    468  1.17     lukem 		pf = (struct pfstab *)xmalloc(sizeof (*pf));
    469   1.1       cgd 		pf->pf_fstab = fs;
    470  1.25     lukem 		SLIST_INSERT_HEAD(&table, pf, pf_list);
    471   1.1       cgd 	}
    472   1.1       cgd 	(void) endfsent();
    473   1.1       cgd }
    474   1.1       cgd 
    475   1.1       cgd /*
    476   1.1       cgd  * Search in the fstab for a file name.
    477   1.1       cgd  * This file name can be either the special or the path file name.
    478   1.1       cgd  *
    479   1.1       cgd  * The entries in the fstab are the BLOCK special names, not the
    480   1.1       cgd  * character special names.
    481   1.1       cgd  * The caller of fstabsearch assures that the character device
    482   1.1       cgd  * is dumped (that is much faster)
    483   1.1       cgd  *
    484   1.1       cgd  * The file name can omit the leading '/'.
    485   1.1       cgd  */
    486   1.1       cgd struct fstab *
    487  1.17     lukem fstabsearch(const char *key)
    488   1.1       cgd {
    489   1.7     lukem 	struct pfstab *pf;
    490   1.7     lukem 	struct fstab *fs;
    491   1.2   mycroft 	char *rn;
    492   1.1       cgd 
    493  1.25     lukem 	SLIST_FOREACH(pf, &table, pf_list) {
    494   1.1       cgd 		fs = pf->pf_fstab;
    495   1.1       cgd 		if (strcmp(fs->fs_file, key) == 0 ||
    496   1.1       cgd 		    strcmp(fs->fs_spec, key) == 0)
    497   1.1       cgd 			return (fs);
    498   1.1       cgd 		rn = rawname(fs->fs_spec);
    499   1.1       cgd 		if (rn != NULL && strcmp(rn, key) == 0)
    500   1.1       cgd 			return (fs);
    501   1.1       cgd 		if (key[0] != '/') {
    502   1.1       cgd 			if (*fs->fs_spec == '/' &&
    503   1.1       cgd 			    strcmp(fs->fs_spec + 1, key) == 0)
    504   1.1       cgd 				return (fs);
    505   1.1       cgd 			if (*fs->fs_file == '/' &&
    506   1.1       cgd 			    strcmp(fs->fs_file + 1, key) == 0)
    507   1.1       cgd 				return (fs);
    508   1.1       cgd 		}
    509   1.1       cgd 	}
    510   1.1       cgd 	return (NULL);
    511   1.1       cgd }
    512  1.17     lukem 
    513  1.17     lukem /*
    514  1.17     lukem  * Search in the mounted file list for a file name.
    515  1.17     lukem  * This file name can be either the special or the path file name.
    516  1.17     lukem  *
    517  1.17     lukem  * The entries in the list are the BLOCK special names, not the
    518  1.17     lukem  * character special names.
    519  1.17     lukem  * The caller of mntinfosearch assures that the character device
    520  1.17     lukem  * is dumped (that is much faster)
    521  1.17     lukem  */
    522  1.17     lukem struct statfs *
    523  1.17     lukem mntinfosearch(const char *key)
    524  1.17     lukem {
    525  1.17     lukem 	int i, mntbufc;
    526  1.17     lukem 	struct statfs *mntbuf, *fs;
    527  1.17     lukem 	char *rn;
    528  1.17     lukem 
    529  1.17     lukem 	if ((mntbufc = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
    530  1.17     lukem 		quit("Can't get mount list: %s", strerror(errno));
    531  1.17     lukem 	for (fs = mntbuf, i = 0; i < mntbufc; i++, fs++) {
    532  1.17     lukem 		if (strcmp(fs->f_fstypename, "ufs") != 0 &&
    533  1.17     lukem 		    strcmp(fs->f_fstypename, "ffs") != 0)
    534  1.17     lukem 			continue;
    535  1.17     lukem 		if (strcmp(fs->f_mntonname, key) == 0 ||
    536  1.17     lukem 		    strcmp(fs->f_mntfromname, key) == 0)
    537  1.17     lukem 			return (fs);
    538  1.17     lukem 		rn = rawname(fs->f_mntfromname);
    539  1.17     lukem 		if (rn != NULL && strcmp(rn, key) == 0)
    540  1.17     lukem 			return (fs);
    541  1.17     lukem 	}
    542  1.17     lukem 	return (NULL);
    543  1.17     lukem }
    544  1.17     lukem 
    545   1.1       cgd 
    546   1.1       cgd /*
    547  1.15     lukem  *	Tell the operator what to do.
    548  1.15     lukem  *	arg:	w ==> just what to do; W ==> most recent dumps
    549   1.1       cgd  */
    550   1.1       cgd void
    551  1.15     lukem lastdump(char arg)
    552   1.1       cgd {
    553   1.7     lukem 	int i;
    554   1.7     lukem 	struct fstab *dt;
    555   1.7     lukem 	struct dumpdates *dtwalk;
    556   1.1       cgd 	char *lastname, *date;
    557   1.2   mycroft 	int dumpme;
    558   1.1       cgd 	time_t tnow;
    559   1.1       cgd 
    560   1.1       cgd 	(void) time(&tnow);
    561   1.1       cgd 	getfstab();		/* /etc/fstab input */
    562   1.1       cgd 	initdumptimes();	/* /etc/dumpdates input */
    563   1.1       cgd 	qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
    564   1.1       cgd 
    565   1.1       cgd 	if (arg == 'w')
    566   1.1       cgd 		(void) printf("Dump these file systems:\n");
    567   1.1       cgd 	else
    568   1.1       cgd 		(void) printf("Last dump(s) done (Dump '>' file systems):\n");
    569   1.1       cgd 	lastname = "??";
    570   1.1       cgd 	ITITERATE(i, dtwalk) {
    571   1.1       cgd 		if (strncmp(lastname, dtwalk->dd_name,
    572   1.1       cgd 		    sizeof(dtwalk->dd_name)) == 0)
    573   1.1       cgd 			continue;
    574   1.1       cgd 		date = (char *)ctime(&dtwalk->dd_ddate);
    575   1.6     lukem 		date[24] = '\0';
    576   1.6     lukem 		strcpy(date + 16, date + 19);	/* blast away seconds */
    577   1.1       cgd 		lastname = dtwalk->dd_name;
    578   1.1       cgd 		dt = fstabsearch(dtwalk->dd_name);
    579   1.1       cgd 		dumpme = (dt != NULL &&
    580   1.1       cgd 		    dt->fs_freq != 0 &&
    581   1.1       cgd 		    dtwalk->dd_ddate < tnow - (dt->fs_freq * SECSPERDAY));
    582   1.1       cgd 		if (arg != 'w' || dumpme)
    583   1.1       cgd 			(void) printf(
    584   1.1       cgd 			    "%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
    585   1.1       cgd 			    dumpme && (arg != 'w') ? '>' : ' ',
    586   1.1       cgd 			    dtwalk->dd_name,
    587   1.1       cgd 			    dt ? dt->fs_file : "",
    588   1.1       cgd 			    dtwalk->dd_level,
    589   1.1       cgd 			    date);
    590   1.1       cgd 	}
    591   1.1       cgd }
    592   1.1       cgd 
    593   1.1       cgd int
    594  1.15     lukem datesort(const void *a1, const void *a2)
    595   1.1       cgd {
    596   1.1       cgd 	struct dumpdates *d1 = *(struct dumpdates **)a1;
    597   1.1       cgd 	struct dumpdates *d2 = *(struct dumpdates **)a2;
    598   1.1       cgd 	int diff;
    599   1.1       cgd 
    600   1.1       cgd 	diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name));
    601   1.1       cgd 	if (diff == 0)
    602   1.1       cgd 		return (d2->dd_ddate - d1->dd_ddate);
    603   1.1       cgd 	return (diff);
    604   1.1       cgd }
    605