Debian Codegraph @

dump/optr.c

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