From: guenther Date: Sat, 23 May 2015 05:17:20 +0000 (+0000) Subject: Canonicalize all devices to DUIDs in order to make -w and -W output consistent. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7833183cb34e1003006dd5e2727edb5500709c39;p=openbsd Canonicalize all devices to DUIDs in order to make -w and -W output consistent. Based on diff from Manuel Giraud (manuel (at) ledu-giraud.fr) Thanks! --- diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index b7436ba4524..83023c68773 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.h,v 1.23 2015/05/03 01:44:34 guenther Exp $ */ +/* $OpenBSD: dump.h,v 1.24 2015/05/23 05:17:20 guenther Exp $ */ /* $NetBSD: dump.h,v 1.11 1997/06/05 11:13:20 lukem Exp $ */ /*- @@ -125,6 +125,7 @@ __dead void dumpabort(int signo); void getfstab(void); char *rawname(char *cp); +char *getduid(char *path); union dinode *getino(ino_t inum, int *mode); /* rdump routines */ diff --git a/sbin/dump/itime.c b/sbin/dump/itime.c index e3645dac026..af38cbc2414 100644 --- a/sbin/dump/itime.c +++ b/sbin/dump/itime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: itime.c,v 1.20 2015/05/03 01:44:34 guenther Exp $ */ +/* $OpenBSD: itime.c,v 1.21 2015/05/23 05:17:20 guenther Exp $ */ /* $NetBSD: itime.c,v 1.4 1997/04/15 01:09:50 lukem Exp $ */ /*- @@ -251,6 +251,11 @@ makedumpdate(struct dumpdates *ddp, char *tbuf) if (sscanf(tbuf, DUMPINFMT, ddp->dd_name, &ddp->dd_level, un_buf) != 3) return(-1); + str = getduid(ddp->dd_name); + if (str != NULL) { + strlcpy(ddp->dd_name, str, sizeof(ddp->dd_name)); + free(str); + } str = strptime(un_buf, "%a %b %e %H:%M:%S %Y", &then); then.tm_isdst = -1; if (str == NULL || (*str != '\n' && *str != '\0')) diff --git a/sbin/dump/main.c b/sbin/dump/main.c index ff7788de3a3..93bcfc3c4ad 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.55 2015/05/03 01:44:34 guenther Exp $ */ +/* $OpenBSD: main.c,v 1.56 2015/05/23 05:17:20 guenther Exp $ */ /* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */ /*- @@ -298,7 +298,7 @@ main(int argc, char *argv[]) * density tape size * 9-track 1600 bpi (160 bytes/.1") 2300 ft. * 9-track 6250 bpi (625 bytes/.1") 2300 ft. - * cartridge 8000 bpi (100 bytes/.1") 1700 ft. + * cartridge 8000 bpi (800 bytes/.1") 1700 ft. * (450*4 - slop) */ if (density == 0) @@ -363,7 +363,13 @@ main(int argc, char *argv[]) } } else if ((dt = fstabsearch(disk)) != NULL) { /* in fstab? */ - disk = rawname(dt->fs_spec); + if (strchr(dt->fs_spec, '/')) { + /* fs_spec is a /dev/something */ + disk = rawname(dt->fs_spec); + } else { + /* fs_spec is a DUID */ + disk = rawname(disk); + } mount_point = dt->fs_file; (void)strlcpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev)); if (dirlist != 0) { @@ -649,15 +655,50 @@ rawname(char *cp) { static char rawbuf[PATH_MAX]; char *dp = strrchr(cp, '/'); + char *prefix; if (dp == NULL) return (NULL); + prefix = dp[1] == 'r' ? "" : "r"; *dp = '\0'; - (void)snprintf(rawbuf, sizeof(rawbuf), "%s/r%s", cp, dp + 1); + (void)snprintf(rawbuf, sizeof(rawbuf), "%s/%s%s", cp, prefix, dp + 1); *dp = '/'; return (rawbuf); } +char * +getduid(char *path) +{ + int fd; + struct disklabel lab; + u_int64_t zero_uid = 0; + char *duid; + + if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, NULL)) >= 0) { + if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { + close(fd); + warn("ioctl(DIOCGDINFO)"); + return (NULL); + } + close(fd); + + if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) != 0) { + 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], + path[strlen(path)-1]) == -1) { + warn("Cannot malloc duid"); + return (NULL); + } + return (duid); + } + } + + return (NULL); +} + /* * obsolete -- * Change set of key letters and ordered arguments into something diff --git a/sbin/dump/optr.c b/sbin/dump/optr.c index 400f5ff941b..10aa0232325 100644 --- a/sbin/dump/optr.c +++ b/sbin/dump/optr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: optr.c,v 1.36 2015/03/15 00:41:27 millert Exp $ */ +/* $OpenBSD: optr.c,v 1.37 2015/05/23 05:17:20 guenther Exp $ */ /* $NetBSD: optr.c,v 1.11 1997/05/27 08:34:36 mrg Exp $ */ /*- @@ -337,7 +337,7 @@ fstabsearch(char *key) { struct pfstab *pf; struct fstab *fs; - char *rn; + char *rn, *uid; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; @@ -347,6 +347,12 @@ fstabsearch(char *key) rn = rawname(fs->fs_spec); if (rn != NULL && strcmp(rn, key) == 0) return (fs); + uid = getduid(rn != NULL ? rn : fs->fs_spec); + if (uid != NULL && strcmp(uid, key) == 0) { + free(uid); + return (fs); + } + free(uid); if (key[0] != '/') { if (*fs->fs_spec == '/' && strcmp(fs->fs_spec + 1, key) == 0)