Fix dump -w/-W output, again...
[dump.git] / dump / optr.c
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 */
8
9 /*-
10 * Copyright (c) 1980, 1988, 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #ifndef lint
39 static const char rcsid[] =
40 "$Id: optr.c,v 1.40 2006/03/14 11:09:51 stelian Exp $";
41 #endif /* not lint */
42
43 #include <config.h>
44 #include <sys/param.h>
45 #include <sys/wait.h>
46 #include <sys/time.h>
47 #include <time.h>
48
49 #include <errno.h>
50 #include <mntent.h>
51 #include <paths.h>
52 #include <grp.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <stdarg.h>
57 #include <unistd.h>
58 #include <utmp.h>
59 #include <sys/stat.h>
60
61 #ifdef __linux__
62 #ifdef HAVE_EXT2FS_EXT2_FS_H
63 #include <ext2fs/ext2_fs.h>
64 #else
65 #include <linux/ext2_fs.h>
66 #endif
67 #include <ext2fs/ext2fs.h>
68 #include <bsdcompat.h>
69 #include <signal.h>
70 #endif
71
72 #include "dump.h"
73 #include "pathnames.h"
74 #include "bylabel.h"
75
76 static void alarmcatch __P((int));
77 int datesort __P((const void *, const void *));
78 static void sendmes __P((const char *, const char *));
79
80 /* List of filesystem types that we can dump (same ext2 on-disk format) */
81 static char *fstypes[] = { "ext2", "ext3", "InterMezzo", NULL };
82
83 /*
84 * Query the operator; This previously-fascist piece of code
85 * no longer requires an exact response.
86 * It is intended to protect dump aborting by inquisitive
87 * people banging on the console terminal to see what is
88 * happening which might cause dump to croak, destroying
89 * a large number of hours of work.
90 *
91 * Every 2 minutes we reprint the message, alerting others
92 * that dump needs attention.
93 */
94 static int timeout;
95 static const char *attnmessage; /* attention message */
96
97 int
98 query(const char *question)
99 {
100 char replybuffer[64];
101 int back, errcount;
102 FILE *mytty;
103 time_t firstprompt, when_answered;
104
105 if (qflag) {
106 msg("%s - forced abort\n", question);
107 dumpabort(0);
108 /* NOTREACHED */
109 }
110
111 firstprompt = time(NULL);
112
113 if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
114 quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
115 attnmessage = question;
116 timeout = 0;
117 alarmcatch(0);
118 back = -1;
119 errcount = 0;
120 do {
121 if (fgets(replybuffer, 63, mytty) == NULL) {
122 clearerr(mytty);
123 if (++errcount > 30) /* XXX ugly */
124 quit("excessive operator query failures\n");
125 } else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') {
126 back = 1;
127 } else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') {
128 back = 0;
129 } else {
130 (void) fprintf(stderr,
131 " DUMP: \"Yes\" or \"No\"?\n");
132 (void) fprintf(stderr,
133 " DUMP: %s: (\"yes\" or \"no\") ", question);
134 }
135 } while (back < 0);
136
137 /*
138 * Turn off the alarm, and reset the signal to trap out..
139 */
140 (void) alarm(0);
141 if (signal(SIGALRM, sig) == SIG_IGN)
142 signal(SIGALRM, SIG_IGN);
143 (void) fclose(mytty);
144 when_answered = time(NULL);
145 /*
146 * Adjust the base for time estimates to ignore time we spent waiting
147 * for operator input.
148 */
149 if (tstart_writing != 0)
150 tstart_writing += (when_answered - firstprompt);
151 return(back);
152 }
153
154 char lastmsg[BUFSIZ];
155
156 /*
157 * Alert the console operator, and enable the alarm clock to
158 * sleep for 2 minutes in case nobody comes to satisfy dump
159 */
160 static void
161 alarmcatch(UNUSED(int signo))
162 {
163 int save_errno = errno;
164 if (notify == 0) {
165 if (timeout == 0)
166 (void) fprintf(stderr,
167 " DUMP: %s: (\"yes\" or \"no\") ",
168 attnmessage);
169 else
170 msgtail("\7\7");
171 } else {
172 if (timeout) {
173 msgtail("\n");
174 broadcast(""); /* just print last msg */
175 }
176 (void) fprintf(stderr," DUMP: %s: (\"yes\" or \"no\") ",
177 attnmessage);
178 }
179 signal(SIGALRM, alarmcatch);
180 (void) alarm(120);
181 timeout = 1;
182 errno = save_errno;
183 }
184
185 /*
186 * Here if an inquisitive operator interrupts the dump program
187 */
188 void
189 interrupt(UNUSED(int signo))
190 {
191 msg("Interrupt received.\n");
192 if (query("Do you want to abort dump?"))
193 dumpabort(0);
194 }
195
196 /*
197 * The following variables and routines manage alerting
198 * operators to the status of dump.
199 * This works much like wall(1) does.
200 */
201 struct group *gp;
202
203 /*
204 * Get the names from the group entry "operator" to notify.
205 */
206 void
207 set_operators(void)
208 {
209 if (!notify) /*not going to notify*/
210 return;
211 gp = getgrnam(OPGRENT);
212 (void) endgrent();
213 if (gp == NULL) {
214 msg("No group entry for %s.\n", OPGRENT);
215 notify = 0;
216 return;
217 }
218 }
219
220 struct tm *localclock;
221
222 /*
223 * We fork a child to do the actual broadcasting, so
224 * that the process control groups are not messed up
225 */
226 void
227 broadcast(const char *message)
228 {
229 time_t clock;
230 FILE *f_utmp;
231 struct utmp utmp;
232 char **np;
233 int pid, s;
234
235 if (!notify || gp == NULL)
236 return;
237
238 switch (pid = fork()) {
239 case -1:
240 return;
241 case 0:
242 break;
243 default:
244 while (wait(&s) != pid)
245 continue;
246 return;
247 }
248
249 clock = time(NULL);
250 localclock = localtime(&clock);
251
252 if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
253 msg("Cannot open %s: %s\n", _PATH_UTMP, strerror(errno));
254 return;
255 }
256
257 while (!feof(f_utmp)) {
258 if (fread((char *) &utmp, sizeof (struct utmp), 1, f_utmp) != 1)
259 break;
260 if (utmp.ut_name[0] == 0)
261 continue;
262 for (np = gp->gr_mem; *np; np++) {
263 if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0)
264 continue;
265 /*
266 * Do not send messages to operators on dialups
267 */
268 if (strncmp(utmp.ut_line, DIALUP, strlen(DIALUP)) == 0)
269 continue;
270 #ifdef DEBUG
271 msg("Message to %s at %s\n", *np, utmp.ut_line);
272 #endif
273 sendmes(utmp.ut_line, message);
274 }
275 }
276 (void) fclose(f_utmp);
277 Exit(0); /* the wait in this same routine will catch this */
278 /* NOTREACHED */
279 }
280
281 static void
282 sendmes(const char *tty, const char *message)
283 {
284 char t[MAXPATHLEN], buf[BUFSIZ];
285 const char *cp;
286 int lmsg = 1;
287 FILE *f_tty;
288
289 (void) strcpy(t, _PATH_DEV);
290 (void) strncat(t, tty, sizeof t - strlen(_PATH_DEV) - 1);
291
292 if ((f_tty = fopen(t, "w")) != NULL) {
293 setbuf(f_tty, buf);
294 (void) fprintf(f_tty,
295 "\n\
296 \7\7\7Message from the dump program to all operators at %d:%02d ...\r\n\n\
297 DUMP: NEEDS ATTENTION: ",
298 localclock->tm_hour, localclock->tm_min);
299 for (cp = lastmsg; ; cp++) {
300 if (*cp == '\0') {
301 if (lmsg) {
302 cp = message;
303 if (!(cp && *cp != '\0'))
304 break;
305 lmsg = 0;
306 } else
307 break;
308 }
309 if (*cp == '\n')
310 (void) putc('\r', f_tty);
311 (void) putc(*cp, f_tty);
312 }
313 (void) fclose(f_tty);
314 }
315 }
316
317 /*
318 * print out an estimate of the amount of time left to do the dump
319 */
320
321 time_t tschedule = 0;
322
323 void
324 timeest(void)
325 {
326 time_t tnow = time(NULL);
327
328 if (tnow >= tschedule) {
329 char *buf = mktimeest(tnow);
330 tschedule = tnow + 300;
331 if (buf) {
332 fprintf(stderr, " DUMP: ");
333 fwrite(buf, strlen(buf), 1, stderr);
334 fflush(stderr);
335 }
336 }
337 }
338
339 void
340 #ifdef __STDC__
341 msg(const char *fmt, ...)
342 #else
343 msg(fmt, va_alist)
344 char *fmt;
345 va_dcl
346 #endif
347 {
348 va_list ap;
349
350 (void) fprintf(stderr," DUMP: ");
351 #ifdef TDEBUG
352 (void) fprintf(stderr, "pid=%d ", getpid());
353 #endif
354 #ifdef __STDC__
355 va_start(ap, fmt);
356 #else
357 va_start(ap);
358 #endif
359 (void) vfprintf(stderr, fmt, ap);
360 va_end(ap);
361 (void) fflush(stdout);
362 (void) fflush(stderr);
363 #ifdef __STDC__
364 va_start(ap, fmt);
365 #else
366 va_start(ap);
367 #endif
368 (void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
369 va_end(ap);
370 }
371
372 void
373 #ifdef __STDC__
374 msgtail(const char *fmt, ...)
375 #else
376 msgtail(fmt, va_alist)
377 char *fmt;
378 va_dcl
379 #endif
380 {
381 va_list ap;
382 #ifdef __STDC__
383 va_start(ap, fmt);
384 #else
385 va_start(ap);
386 #endif
387 (void) vfprintf(stderr, fmt, ap);
388 va_end(ap);
389 }
390
391 void
392 #ifdef __STDC__
393 quit(const char *fmt, ...)
394 #else
395 quit(fmt, va_alist)
396 char *fmt;
397 va_dcl
398 #endif
399 {
400 va_list ap;
401
402 (void) fprintf(stderr," DUMP: ");
403 #ifdef TDEBUG
404 (void) fprintf(stderr, "pid=%d ", getpid());
405 #endif
406 #ifdef __STDC__
407 va_start(ap, fmt);
408 #else
409 va_start(ap);
410 #endif
411 (void) vfprintf(stderr, fmt, ap);
412 va_end(ap);
413 (void) fflush(stdout);
414 (void) fflush(stderr);
415 dumpabort(0);
416 }
417
418 /*
419 * Tell the operator what has to be done;
420 * we don't actually do it
421 */
422
423 struct pfstab {
424 struct pfstab *pf_next;
425 struct dumpdates *pf_dd;
426 struct mntent *pf_mntent;
427 };
428
429 static struct pfstab *table;
430
431 static struct mntent *
432 allocfsent(struct mntent *fs)
433 {
434 struct mntent *new;
435 const char *disk;
436 struct stat buf, tabbuf;
437 struct pfstab *tabpf;
438 struct mntent *tabfs;
439
440 new = (struct mntent *)malloc(sizeof (*fs));
441 if (new == NULL)
442 quit("%s\n", strerror(errno));
443
444 /* Translade UUID=, LABEL= ... */
445 disk = get_device_name(fs->mnt_fsname);
446 if (disk == NULL)
447 disk = strdup(fs->mnt_fsname);
448
449 /* Discard non block devices */
450 if (stat(disk, &buf) != 0 || !S_ISBLK(buf.st_mode)) {
451 free(new);
452 return NULL;
453 }
454
455 /* Discard same major/minor devices */
456 for (tabpf = table; tabpf != NULL; tabpf = tabpf->pf_next) {
457 tabfs = tabpf->pf_mntent;
458 if (stat(tabfs->mnt_fsname, &tabbuf) != 0)
459 /* should not happen */
460 quit("Cannot access %s\n", tabfs->mnt_fsname);
461 if (tabbuf.st_rdev == buf.st_rdev) {
462 free(new);
463 /* Copy passno and freq from /etc/fstab because
464 * /etc/mtab does always have them as 0 0 */
465 if (!tabfs->mnt_passno)
466 tabfs->mnt_passno = fs->mnt_passno;
467 if (!tabfs->mnt_freq)
468 tabfs->mnt_freq = fs->mnt_freq;
469 if (tabfs->mnt_freq > 3659)
470 quit("Dump frequency in fstab/mtab for %s is too big: %d > 3659\n",
471 tabfs->mnt_fsname, tabfs->mnt_freq);
472 return NULL;
473 }
474 }
475
476 if (strlen(fs->mnt_dir) > 1 && fs->mnt_dir[strlen(fs->mnt_dir) - 1] == '/')
477 fs->mnt_dir[strlen(fs->mnt_dir) - 1] = '\0';
478 if ((new->mnt_dir = strdup(fs->mnt_dir)) == NULL ||
479 (new->mnt_type = strdup(fs->mnt_type)) == NULL ||
480 (new->mnt_opts = strdup(fs->mnt_opts)) == NULL ||
481 (new->mnt_fsname = strdup(disk)) == NULL)
482 quit("%s\n", strerror(errno));
483 new->mnt_passno = fs->mnt_passno;
484 new->mnt_freq = fs->mnt_freq;
485 if (new->mnt_freq > 3659)
486 quit("Dump frequency in fstab/mtab for %s %s is too big: %d > 3659\n",
487 new->mnt_dir, new->mnt_fsname, new->mnt_freq);
488 return (new);
489 }
490
491 void
492 getfstab(void)
493 {
494 struct mntent *fs;
495 struct pfstab *pf;
496 struct pfstab *pfold = NULL;
497 FILE *mntfp;
498 char *mnttables[] = { _PATH_MOUNTED, _PATH_MNTTAB, 0 };
499 int i;
500
501 for (i = 0; mnttables[i]; i++) {
502 mntfp = setmntent(mnttables[i], "r");
503 if (mntfp == NULL) {
504 msg("Can't open %s for dump table information: %s\n",
505 mnttables[i], strerror(errno));
506 continue;
507 }
508 while ((fs = getmntent(mntfp)) != NULL) {
509 fs = allocfsent(fs);
510 if (!fs)
511 continue;
512 fs->mnt_passno = 0;
513 if ((pf = (struct pfstab *)malloc(sizeof (*pf))) == NULL)
514 quit("%s\n", strerror(errno));
515 pf->pf_mntent = fs;
516 pf->pf_next = NULL;
517
518 /* keep table in /etc/fstab order for use with -w and -W */
519 if (pfold) {
520 pfold->pf_next = pf;
521 pfold = pf;
522 } else
523 pfold = table = pf;
524 }
525 (void) endmntent(mntfp);
526 }
527 }
528
529 /*
530 * Search in the fstab for a file name.
531 * This file name can be either the special or the path file name.
532 *
533 * The entries in the fstab are the BLOCK special names, not the
534 * character special names.
535 * The caller of fstabsearch assures that the character device
536 * is dumped (that is much faster)
537 *
538 * The file name can omit the leading '/'.
539 */
540 struct mntent *
541 fstabsearch(const char *key)
542 {
543 struct pfstab *pf;
544 struct mntent *fs;
545 const char *rn;
546
547 for (pf = table; pf != NULL; pf = pf->pf_next) {
548 fs = pf->pf_mntent;
549 if (strcmp(fs->mnt_dir, key) == 0 ||
550 strcmp(fs->mnt_fsname, key) == 0)
551 return (fs);
552 rn = rawname(fs->mnt_fsname);
553 if (rn != NULL && strcmp(rn, key) == 0)
554 return (fs);
555 if (key[0] != '/') {
556 if (*fs->mnt_fsname == '/' &&
557 strcmp(fs->mnt_fsname + 1, key) == 0)
558 return (fs);
559 if (*fs->mnt_dir == '/' &&
560 strcmp(fs->mnt_dir + 1, key) == 0)
561 return (fs);
562 }
563 }
564 return (NULL);
565 }
566
567 #ifdef __linux__
568 struct mntent *
569 fstabsearchdir(const char *key, char *directory)
570 {
571 struct pfstab *pf;
572 struct mntent *fs;
573 struct mntent *found_fs = NULL;
574 unsigned int size = 0;
575 struct stat buf;
576
577 if (stat(key, &buf) == 0 && S_ISBLK(buf.st_mode))
578 return NULL;
579
580 for (pf = table; pf != NULL; pf = pf->pf_next) {
581 fs = pf->pf_mntent;
582 if (strlen(fs->mnt_dir) > size &&
583 strlen(key) > strlen(fs->mnt_dir) &&
584 strncmp(fs->mnt_dir, key, strlen(fs->mnt_dir)) == 0 &&
585 (key[strlen(fs->mnt_dir)] == '/' ||
586 fs->mnt_dir[strlen(fs->mnt_dir) - 1] == '/')) {
587 found_fs = fs;
588 size = strlen(fs->mnt_dir);
589 }
590 }
591 if (found_fs != NULL) {
592 /*
593 * Ok, we have found a fstab entry which matches the argument
594 * We have to split the argument name into:
595 * - a device name (from the fstab entry)
596 * - a directory name on this device
597 */
598 strcpy(directory, key + size);
599 }
600 return(found_fs);
601 }
602 #endif
603
604 static void
605 print_wmsg(char arg, int dumpme, const char *dev, int level,
606 const char *mtpt, time_t ddate)
607 {
608 #ifdef FDEBUG
609 printf("checking dev %s: lvl %d, mtpt %s\n", dev, level, mtpt);
610 #endif
611 if (!dumpme && arg == 'w')
612 return;
613
614 (void) printf("%c %8s\t(%6s) Last dump: ",
615 dumpme && (arg != 'w') ? '>' : ' ',
616 dev,
617 mtpt ? mtpt : "");
618
619 /*
620 * Check ddate > 365 to avoid issues with fs in stab but not dumpdates.
621 * Not a problem, because ddate is in seconds since the epoch anyways.
622 */
623 if (level >= 0 && ddate > 365) {
624 char *date, *d;
625
626 date = (char *)ctime(&ddate);
627 d = strchr(date, '\n');
628 if (d) *d = '\0';
629 printf("Level %d, Date %s\n", level, date);
630 } else
631 printf("never\n");
632 }
633
634 /*
635 * Tell the operator what to do
636 */
637 void
638 lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
639 {
640 struct pfstab *pf;
641 time_t tnow;
642
643 tnow = time(NULL);
644 getfstab(); /* /etc/fstab input */
645 initdumptimes(0); /* dumpdates input */
646 if (ddatev == NULL && table == NULL) {
647 (void) printf("No %s or %s file found\n",
648 _PATH_MNTTAB, dumpdates);
649 return;
650 }
651
652 if (arg == 'w')
653 (void) printf("Dump these file systems:\n");
654 else
655 (void) printf("Last dump(s) done (Dump '>' file systems):\n");
656
657 /* For files in dumpdates, get the last dump level and date */
658 if (ddatev != NULL) {
659 struct dumpdates *dtwalk = NULL;
660 int i;
661 char *lastname;
662
663 qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
664
665 lastname = "??";
666 ITITERATE(i, dtwalk) {
667 struct mntent *dt;
668 if (strncmp(lastname, dtwalk->dd_name,
669 sizeof(dtwalk->dd_name)) == 0)
670 continue;
671 lastname = dtwalk->dd_name;
672 if ((dt = dtwalk->dd_fstab) != NULL) {
673 /* Overload fs_freq as dump level and
674 * fs_passno as date, because we can't
675 * change struct fstab format.
676 * A positive fs_freq means this
677 * filesystem needs to be dumped.
678 *
679 * UGLY HACK: values in 0-3659 range indicate
680 * original value from /etc/fstab (maximum
681 * 10 years...)
682 *
683 * Values bigger than 3659 indicate that
684 * the fs is to be dumped, and the latest
685 * dump level was x-3660
686 *
687 * Negative values indicate that the fs is
688 * not to be dumped, and the latest dump
689 * level was -x-1
690 */
691 dt->mnt_passno = dtwalk->dd_ddate;
692 if (dt->mnt_freq > 0 && (dtwalk->dd_ddate <
693 tnow - (dt->mnt_freq * 86400)))
694 dt->mnt_freq = 3660 + dtwalk->dd_level;
695 else
696 dt->mnt_freq = -dtwalk->dd_level - 1;
697 #ifdef FDEBUG
698 printf("%s fs_freq set to %d\n", lastname,
699 dt->mnt_freq);
700 #endif
701 }
702 }
703 }
704
705 /* print in /etc/fstab order only those filesystem types we can dump */
706 for (pf = table; pf != NULL; pf = pf->pf_next) {
707 struct mntent *dt = pf->pf_mntent;
708 char **type;
709
710 for (type = fstypes; *type != NULL; type++) {
711 if (strncmp(dt->mnt_type, *type,
712 sizeof(dt->mnt_type)) == 0) {
713 const char *disk = get_device_name(dt->mnt_fsname);
714 print_wmsg(arg, dt->mnt_freq > 0,
715 disk ? disk : dt->mnt_fsname,
716 (dt->mnt_freq < 0 ? -dt->mnt_freq - 1 :
717 dt->mnt_freq < 3660 ? -1 :
718 dt->mnt_freq - 3660),
719 dt->mnt_dir,
720 dt->mnt_passno);
721 }
722 }
723 }
724
725 /* print in /etc/dumpdates order if not in /etc/fstab */
726 if (ddatev != NULL) {
727 struct dumpdates *dtwalk = NULL;
728 char *lastname;
729 int i;
730
731 lastname = "??";
732 ITITERATE(i, dtwalk) {
733 if (strncmp(lastname, dtwalk->dd_name,
734 sizeof(dtwalk->dd_name)) == 0 ||
735 dtwalk->dd_fstab != NULL)
736 continue;
737 lastname = dtwalk->dd_name;
738 print_wmsg(arg, 0, dtwalk->dd_name,
739 dtwalk->dd_level, NULL, dtwalk->dd_ddate);
740 }
741 }
742 }
743
744 int
745 datesort(const void *a1, const void *a2)
746 {
747 struct dumpdates *d1 = *(struct dumpdates **)a1;
748 struct dumpdates *d2 = *(struct dumpdates **)a2;
749 int diff;
750
751 diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name));
752 if (diff == 0)
753 return (d2->dd_ddate - d1->dd_ddate);
754 return (diff);
755 }