On 07/11/14 14:33, Maximilian Fillinger wrote:
> On Fri, 2014-07-11 at 14:22 +0200, Alexander Hall wrote:
>> If there are no other objections, I'd like to commit this today.
> 
> Just don't forget to get rid of this
>> +       } else { fprintf(stderr, "duid: %s\n", duid); }
> before committing.
> 

Hmm... You've got a point there... :-P

Still looking for OK's.

/Alexander


Index: include/protocols/dumprestore.h
===================================================================
RCS file: /cvs/src/include/protocols/dumprestore.h,v
retrieving revision 1.9
diff -u -p -r1.9 dumprestore.h
--- include/protocols/dumprestore.h     15 Dec 2009 13:11:42 -0000      1.9
+++ include/protocols/dumprestore.h     11 Jul 2014 13:16:41 -0000
@@ -152,8 +152,8 @@ union u_spcl {
 #define DR_NEWHEADER   0x0001  /* new format tape header */
 #define DR_NEWINODEFMT 0x0002  /* new format inodes on tape */
 
-#define        DUMPOUTFMT      "%-16s %c %s"           /* for printf */
+#define        DUMPOUTFMT      "%-18s %c %s"           /* for printf */
                                                /* name, level, ctime(date) */
-#define        DUMPINFMT       "%16s %c %[^\n]\n"      /* inverse for scanf */
+#define        DUMPINFMT       "%18s %c %[^\n]\n"      /* inverse for scanf */
 
 #endif /* !_PROTOCOLS_DUMPRESTORE_H_ */
Index: sbin/dump/Makefile
===================================================================
RCS file: /cvs/src/sbin/dump/Makefile,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile
--- sbin/dump/Makefile  6 Jan 2013 21:59:28 -0000       1.11
+++ sbin/dump/Makefile  11 Jul 2014 13:16:41 -0000
@@ -14,6 +14,8 @@
 PROG=  dump
 LINKS= ${BINDIR}/dump ${BINDIR}/rdump
 CFLAGS+=-DRDUMP
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
 SRCS=  itime.c main.c optr.c dumprmt.c tape.c traverse.c
 MAN=   dump.8
 MLINKS+=dump.8 rdump.8
Index: sbin/dump/dump.8
===================================================================
RCS file: /cvs/src/sbin/dump/dump.8,v
retrieving revision 1.46
diff -u -p -r1.46 dump.8
--- sbin/dump/dump.8    30 May 2014 20:48:21 -0000      1.46
+++ sbin/dump/dump.8    11 Jul 2014 13:16:41 -0000
@@ -40,7 +40,7 @@
 .Sh SYNOPSIS
 .Nm dump
 .Bk -words
-.Op Fl 0123456789acnSuWw
+.Op Fl 0123456789acnSUuWw
 .Op Fl B Ar records
 .Op Fl b Ar blocksize
 .Op Fl d Ar density
@@ -229,6 +229,13 @@ The
 flag is mutually exclusive from the
 .Fl u
 flag.
+.It Fl U
+Use the
+.Xr disklabel 8
+UID instead of the device name when updating
+.Pa /etc/dumpdates
+and when searching for the date of the latest
+lower-level dump.
 .It Fl u
 Update the file
 .Pa /etc/dumpdates
Index: sbin/dump/dump.h
===================================================================
RCS file: /cvs/src/sbin/dump/dump.h,v
retrieving revision 1.20
diff -u -p -r1.20 dump.h
--- sbin/dump/dump.h    13 Jun 2014 20:43:06 -0000      1.20
+++ sbin/dump/dump.h    11 Jul 2014 13:16:41 -0000
@@ -56,9 +56,11 @@ char *disk;          /* name of the disk file */
 char   *tape;          /* name of the tape file */
 char   *dumpdates;     /* name of the file containing dump date information*/
 char   *temp;          /* name of the file for doing rewrite of dumpdates */
+char   *duid;          /* duid of the disk being dumped */
 char   lastlevel;      /* dump level of previous dump */
 char   level;          /* dump level of this dump */
 int    uflag;          /* update flag */
+int    Uflag;          /* use duids in dumpdates flag */
 int    diskfd;         /* disk file descriptor */
 int    tapefd;         /* tape file descriptor */
 int    pipeout;        /* true => output to standard output */
Index: sbin/dump/itime.c
===================================================================
RCS file: /cvs/src/sbin/dump/itime.c,v
retrieving revision 1.17
diff -u -p -r1.17 itime.c
--- sbin/dump/itime.c   27 Oct 2009 23:59:32 -0000      1.17
+++ sbin/dump/itime.c   11 Jul 2014 13:16:41 -0000
@@ -124,7 +124,7 @@ getdumptime(void)
        int i;
        char *fname;
 
-       fname = disk;
+       fname = Uflag ? duid : disk;
 #ifdef FDEBUG
        msg("Looking for name %s in dumpdates = %s for level = %c\n",
                fname, dumpdates, level);
@@ -164,7 +164,7 @@ putdumptime(void)
                quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno));
        fd = fileno(df);
        (void) flock(fd, LOCK_EX);
-       fname = disk;
+       fname = Uflag ? duid : disk;
        free((char *)ddatev);
        ddatev = 0;
        nddates = 0;
Index: sbin/dump/main.c
===================================================================
RCS file: /cvs/src/sbin/dump/main.c,v
retrieving revision 1.51
diff -u -p -r1.51 main.c
--- sbin/dump/main.c    13 Jun 2014 20:43:06 -0000      1.51
+++ sbin/dump/main.c    11 Jul 2014 13:16:41 -0000
@@ -54,6 +54,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <util.h>
 
 #include "dump.h"
 #include "pathnames.h"
@@ -94,8 +95,9 @@ main(int argc, char *argv[])
        ino_t maxino;
        time_t t;
        int dirlist;
-       char *toplevel, *str, *mount_point = NULL;
+       char *toplevel, *str, *mount_point = NULL, *realpath;
        int just_estimate = 0;
+       u_int64_t zero_uid = 0;
 
        spcl.c_date = (int64_t)time(NULL);
 
@@ -112,7 +114,7 @@ main(int argc, char *argv[])
                usage();
 
        obsolete(&argc, &argv);
-       while ((ch = getopt(argc, argv, "0123456789aB:b:cd:f:h:ns:ST:uWw")) != 
-1)
+       while ((ch = getopt(argc, argv, "0123456789aB:b:cd:f:h:ns:ST:UuWw")) != 
-1)
                switch (ch) {
                /* dump level */
                case '0': case '1': case '2': case '3': case '4':
@@ -180,6 +182,10 @@ main(int argc, char *argv[])
                        lastlevel = '?';
                        break;
 
+               case 'U':
+                       Uflag = 1;      /* use duids */
+                       break;
+
                case 'u':               /* update /etc/dumpdates */
                        uflag = 1;
                        break;
@@ -213,6 +219,16 @@ main(int argc, char *argv[])
        for (i = 0; i < argc; i++) {
                struct stat sb;
 
+               /* Convert potential duid into a device name */
+               if ((diskfd = opendev(argv[i], O_RDONLY | O_NOFOLLOW, 0,
+                   &realpath)) >= 0) {
+                       argv[i] = strdup(realpath);
+                       if (argv[i] == NULL) {
+                               msg("Cannot malloc realpath\n");
+                               exit(X_STARTUP);
+                       }
+                       (void)close(diskfd);
+               }
                if (lstat(argv[i], &sb) == -1) {
                        msg("Cannot lstat %s: %s\n", argv[i], strerror(errno));
                        exit(X_STARTUP);
@@ -370,6 +386,26 @@ main(int argc, char *argv[])
        (void)gethostname(spcl.c_host, sizeof(spcl.c_host));
        spcl.c_level = level - '0';
        spcl.c_type = TS_TAPE;
+
+       if ((diskfd = open(disk, O_RDONLY)) < 0) {
+               msg("Cannot open %s\n", disk);
+               exit(X_STARTUP);
+       }
+       if (ioctl(diskfd, DIOCGDINFO, (char *)&lab) < 0)
+               err(1, "ioctl (DIOCGDINFO)");
+       if (!Uflag)
+               ;
+       else if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) == 0) {
+               msg("Cannot find DUID of disk %s\n", disk);
+               exit(X_STARTUP);
+       } else if (asprintf(&duid,
+           "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+           lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3],
+           lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7],
+           disk[strlen(disk)-1]) == -1) {
+               msg("Cannot malloc duid\n");
+               exit(X_STARTUP);
+       }
        if (!Tflag)
                getdumptime();          /* /etc/dumpdates snarfed */
 
@@ -387,10 +423,6 @@ main(int argc, char *argv[])
        else
                msgtail("to %s\n", tape);
 
-       if ((diskfd = open(disk, O_RDONLY)) < 0) {
-               msg("Cannot open %s\n", disk);
-               exit(X_STARTUP);
-       }
        if (ioctl(diskfd, DIOCGPDINFO, (char *)&lab) < 0)
                err(1, "ioctl (DIOCGPDINFO)");
        sync();

Reply via email to