Index: mount/Makefile =================================================================== RCS file: /cvsroot/src/sbin/mount/Makefile,v retrieving revision 1.29 diff -u -r1.29 Makefile --- mount/Makefile 19 Aug 2004 23:02:27 -0000 1.29 +++ mount/Makefile 27 Mar 2011 22:59:06 -0000 @@ -6,5 +6,6 @@ PROG= mount MAN= mount.8 SRCS= mount.c vfslist.c +LDADD+= -lutil .include Index: mount/mount.c =================================================================== RCS file: /cvsroot/src/sbin/mount/mount.c,v retrieving revision 1.92 diff -u -r1.92 mount.c --- mount/mount.c 13 Jan 2011 11:57:02 -0000 1.92 +++ mount/mount.c 27 Mar 2011 22:59:06 -0000 @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include @@ -58,6 +60,7 @@ #include #include #include +#include #define MOUNTNAMES #include @@ -76,6 +79,8 @@ static struct statvfs * getmntpt(const char *); static int getmntargs(struct statvfs *, char *, size_t); +static const char * + getspec(const char *); static int hasopt(const char *, const char *); static void mangle(char *, int *, const char ** volatile *, int *); static int mountfs(const char *, const char *, const char *, @@ -183,7 +188,8 @@ mntfromname = mntbuf->f_mntfromname; } else mntfromname = fs->fs_spec; - if (mountfs(fs->fs_vfstype, mntfromname, + if (mountfs(fs->fs_vfstype, + getspec(mntfromname), fs->fs_file, init_flags, options, fs->fs_mntops, !forceall, NULL, 0)) rval = 1; @@ -274,7 +280,7 @@ fstypename = fs->fs_vfstype; mountopts = fs->fs_mntops; } - rval = mountfs(fstypename, mntfromname, + rval = mountfs(fstypename, getspec(mntfromname), mntonname, init_flags, options, mountopts, 0, NULL, 0); break; case 2: @@ -283,6 +289,7 @@ * a ':' or a '@' then assume that an NFS filesystem is being * specified ala Sun. */ + mntfromname = getspec(argv[0]); if (vfslist == NULL) { if (strpbrk(argv[0], ":@") != NULL) { fprintf(stderr, "WARNING: autoselecting nfs " @@ -292,13 +299,13 @@ "in a future release\n"); vfstype = "nfs"; } else { - vfstype = getfslab(argv[0]); + vfstype = getfslab(mntfromname); if (vfstype == NULL) vfstype = ffs_fstype; } } - rval = mountfs(vfstype, - argv[0], argv[1], init_flags, options, NULL, 0, NULL, 0); + rval = mountfs(vfstype, mntfromname, + argv[1], init_flags, options, NULL, 0, NULL, 0); break; default: usage(); @@ -767,6 +774,58 @@ return (vfstype); } +/* Query device path from disk name */ +static const char * +getspec(const char *name) +{ + struct dkwedge_info dkw; + char *drives, *dk; + int mib[2]; + size_t len; + int fd; + static char devpath[MAXPATHLEN]; + const char *match = name; + char *bn; + + if (strncasecmp(name, "NAME=", 5) != 0) + return name; + name += 5; + + mib[0] = CTL_HW; + mib[1] = HW_DISKNAMES; + if (sysctl(mib, 2, NULL, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + drives = (char *)malloc(len); + if (drives == NULL) + err(1, "out of memory"); + if (sysctl(mib, 2, drives, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + + for (dk = drives; (dk = strtok(dk, " ")) != NULL; dk = NULL) { + if (strncmp(dk, "dk", 2) != 0) + continue; + /* must use raw device, the block device can be busy */ + fd = opendisk(dk, O_RDONLY, devpath, sizeof(devpath), 0); + if (fd < 0) + continue; + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1) + err(1, "%s: getwedgeinfo", dk); + close(fd); + if (strcmp(name, (char *)dkw.dkw_wname) == 0) { + /* fix up raw path */ + bn = strrchr(devpath,'/'); + if (bn != NULL && bn[1] == 'r') + memmove(&bn[1],&bn[2],strlen(&bn[2])+1); + match = devpath; + break; + } + } + + free(drives); + + return match; +} + static void usage(void) { Index: umount/Makefile =================================================================== RCS file: /cvsroot/src/sbin/umount/Makefile,v retrieving revision 1.16 diff -u -r1.16 Makefile --- umount/Makefile 21 Jan 2006 11:59:53 -0000 1.16 +++ umount/Makefile 27 Mar 2011 22:59:06 -0000 @@ -15,5 +15,6 @@ .PATH: ${MOUNT} SRCS+= vfslist.c .endif +LDADD+= -lutil .include Index: umount/umount.c =================================================================== RCS file: /cvsroot/src/sbin/umount/umount.c,v retrieving revision 1.43 diff -u -r1.43 umount.c --- umount/umount.c 5 Aug 2008 20:57:45 -0000 1.43 +++ umount/umount.c 27 Mar 2011 22:59:06 -0000 @@ -47,6 +47,8 @@ #include #include #include +#include +#include #ifndef SMALL #include @@ -63,6 +65,8 @@ #include #include #include +#include +#include typedef enum { MNTANY, MNTON, MNTFROM } mntwhat; @@ -80,6 +84,8 @@ static int fflag; static char *getmntname(const char *, mntwhat, char **); +static const char * + getspec(const char *); static int umountfs(const char *, const char **, int); static void usage(void) __dead; @@ -93,6 +99,7 @@ struct addrinfo hints; #endif /* SMALL */ const char **typelist = NULL; + const char *spec; /* Start disks transferring immediately. */ sync(); @@ -166,9 +173,11 @@ } } else #endif /* !SMALL */ - for (errs = 0; *argv != NULL; ++argv) - if (umountfs(*argv, typelist, raw) != 0) + for (errs = 0; *argv != NULL; ++argv) { + spec = getspec(*argv); + if (umountfs(spec, typelist, raw) != 0) errs = 1; + } return errs; } @@ -321,6 +330,58 @@ return (NULL); } +/* Query device path from disk name */ +static const char * +getspec(const char *name) +{ + struct dkwedge_info dkw; + char *drives, *dk; + int mib[2]; + size_t len; + int fd; + static char devpath[MAXPATHLEN]; + const char *match = name; + char *bn; + + if (strncasecmp(name, "NAME=", 5) != 0) + return name; + name += 5; + + mib[0] = CTL_HW; + mib[1] = HW_DISKNAMES; + if (sysctl(mib, 2, NULL, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + drives = (char *)malloc(len); + if (drives == NULL) + err(1, "out of memory"); + if (sysctl(mib, 2, drives, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + + for (dk = drives; (dk = strtok(dk, " ")) != NULL; dk = NULL) { + if (strncmp(dk, "dk", 2) != 0) + continue; + /* must use raw device, the block device can be busy */ + fd = opendisk(dk, O_RDONLY, devpath, sizeof(devpath), 0); + if (fd < 0) + continue; + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1) + err(1, "%s: getwedgeinfo", dk); + close(fd); + if (strcmp(name, (char *)dkw.dkw_wname) == 0) { + /* fix up raw path */ + bn = strrchr(devpath,'/'); + if (bn != NULL && bn[1] == 'r') + memmove(&bn[1],&bn[2],strlen(&bn[2])+1); + match = devpath; + break; + } + } + + free(drives); + + return match; +} + #ifndef SMALL static int sacmp(const struct sockaddr *sa1, const struct sockaddr *sa2) Index: fsck/fsck.c =================================================================== RCS file: /cvsroot/src/sbin/fsck/fsck.c,v retrieving revision 1.49 diff -u -r1.49 fsck.c --- fsck/fsck.c 24 Feb 2010 13:56:07 -0000 1.49 +++ fsck/fsck.c 27 Mar 2011 22:59:06 -0000 @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -91,6 +92,7 @@ static const char *getfslab(const char *); static void usage(void); static void *isok(struct fstab *); +static const char *getspec(const char *); int main(int argc, char *argv[]) @@ -199,6 +201,9 @@ char device[MAXPATHLEN]; spec = *argv; + + spec = getspec(spec); + cp = strrchr(spec, '/'); if (cp == 0) { (void)snprintf(device, sizeof(device), "%s%s", @@ -218,6 +223,7 @@ errx(FSCK_EXIT_CHECK_FAILED, "%s has unknown file system type.", spec); + spec = getspec(spec); } rval = checkfs(type, blockcheck(spec), *argv, NULL, NULL); @@ -576,6 +582,57 @@ return vfstype; } +/* Query device path from disk name */ +static const char * +getspec(const char *name) +{ + struct dkwedge_info dkw; + char *drives, *dk; + int mib[2]; + size_t len; + int fd; + static char devpath[MAXPATHLEN]; + const char *match = name; + char *bn; + + if (strncasecmp(name, "NAME=", 5) != 0) + return name; + name += 5; + + mib[0] = CTL_HW; + mib[1] = HW_DISKNAMES; + if (sysctl(mib, 2, NULL, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + drives = (char *)malloc(len); + if (drives == NULL) + err(1, "out of memory"); + if (sysctl(mib, 2, drives, &len, NULL, 0) < 0) + err(1, "sysctl hw.disknames failed"); + + for (dk = drives; (dk = strtok(dk, " ")) != NULL; dk = NULL) { + if (strncmp(dk, "dk", 2) != 0) + continue; + /* must use raw device, the block device can be busy */ + fd = opendisk(dk, O_RDONLY, devpath, sizeof(devpath), 0); + if (fd < 0) + continue; + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1) + err(1, "%s: getwedgeinfo", dk); + close(fd); + if (strcmp(name, (char *)dkw.dkw_wname) == 0) { + /* fix up raw path */ + bn = strrchr(devpath,'/'); + if (bn != NULL && bn[1] == 'r') + memmove(&bn[1],&bn[2],strlen(&bn[2])+1); + match = devpath; + break; + } + } + + free(drives); + + return match; +} static void usage(void)