From 9c9ac2f1cfc6c28c66d0c882eb05d572b5c7b1cf Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 9 Aug 2009 17:20:34 -0700 Subject: [PATCH] DEVTAB - Add support in umount, fsck, and hammer, and add sample /etc/devtab. --- etc/Makefile | 2 +- etc/devtab | 22 ++++++++++++++++++++++ sbin/fsck/preen.c | 9 +++++++-- sbin/hammer/hammer.c | 15 ++++++++++++++- sbin/umount/umount.c | 5 +++++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 etc/devtab diff --git a/etc/Makefile b/etc/Makefile index ce2e7eb76c..53b83b3635 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -26,7 +26,7 @@ BINUPDATE+=${.CURDIR}/../usr.bin/mail/misc/mail.rc \ # BIN1= amd.map auth.conf \ crontab csh.cshrc csh.login csh.logout \ - devd.conf dhclient.conf dm.conf dntpd.conf \ + devd.conf devtab dhclient.conf dm.conf dntpd.conf \ ftpusers group \ hosts hosts.allow hosts.equiv hosts.lpd \ inetd.conf login.access login.conf \ diff --git a/etc/devtab b/etc/devtab new file mode 100644 index 0000000000..d64623b340 --- /dev/null +++ b/etc/devtab @@ -0,0 +1,22 @@ +# /etc/devtab +# +# This file contains label conversions for fstab, mount, fsck, hammer, +# and other command which expect device paths. It is typically used +# to translate longer serial numbers (which devs automatically installs +# as "/dev/serno/[.ext]" into short-form names to simplify +# fstab. +# +# For use cases a label is represented up to the last '.' (if any), +# looked up, and then any extension after and including the '.' is +# tacked onto the result. So in /etc/fstab the label "serno/fubar.s1a" +# would translate to "/dev/serno/L123456.s1a" in our example below. +# +# Currently the "serno" and "path" types are supported. Really any generic +# type is supported and will translate into a subdirectory lookup in /dev. +# The "path" type translates to an absolute path with no prepended /dev, +# suitable for files represented by block devices. +# +# label type basepath +# ----- ------ ------- +# fubar serno L123456 +# fubar path /full/path diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c index 8e2d1c8d87..466903f9df 100644 --- a/sbin/fsck/preen.c +++ b/sbin/fsck/preen.c @@ -287,13 +287,18 @@ blockcheck(char *origname) newname = origname; retry: if (stat(newname, &stblock) < 0) { - printf("Can't stat %s: %s\n", newname, strerror(errno)); - return (origname); + newname = getdevpath(newname, 0); + if (stat(newname, &stblock) < 0) { + printf("Can't stat %s: %s\n", newname, strerror(errno)); + return (origname); + } } switch(stblock.st_mode & S_IFMT) { case S_IFCHR: case S_IFBLK: return(newname); + case S_IFREG: + return(newname); case S_IFDIR: if (retried) break; diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index 17eb81a361..ea18a3c60b 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -37,6 +37,7 @@ #include "hammer.h" #include #include +#include static void hammer_parsedevs(const char *blkdevs); static void sigalrm(int signo); @@ -386,6 +387,14 @@ main(int ac, char **av) return(0); } +/* + * Parse the device specification. + * + * Multi-volume hammer devices are colon-separated. Each element + * may be further expanded via /etc/devtab. One may also specify + * a single element which is expanded into multiple elements via + * /etc/devtab. + */ static void hammer_parsedevs(const char *blkdevs) @@ -402,7 +411,11 @@ hammer_parsedevs(const char *blkdevs) while ((volname = copy) != NULL) { if ((copy = strchr(copy, ':')) != NULL) *copy++ = 0; - setup_volume(-1, volname, 0, O_RDONLY); + volname = getdevpath(volname, 0); + if (strchr(volname, ':')) + hammer_parsedevs(volname); + else + setup_volume(-1, volname, 0, O_RDONLY); } } diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index be0b7ac728..015dfe55a7 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -259,6 +259,11 @@ checkname(char *name, char **typelist) * 1. Check if the name exists in the mounttable. */ checkmntlist(name, &mntfromname, &mntonname, &type); + if (mntfromname == NULL && mntonname == NULL) { + checkmntlist(getdevpath(name, 0), &mntfromname, + &mntonname, &type); + } + /* * 2. Remove trailing slashes if there are any. After that * we look up the name in the mounttable again. -- 2.41.0