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