diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1996-11-12 08:46:14 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1996-11-12 08:46:14 +0000 |
commit | c462b42923113c496b1e27971aae689df8b6c301 (patch) | |
tree | 093436115204bd3fe1d1a52e0159ddc4d20e3f21 /sbin/mount | |
parent | 306e66afd921d98e5734fd735a825fa24561aefc (diff) |
Prelimary label-groking code for mount; makes -t close to obsolete.
Diffstat (limited to 'sbin/mount')
-rw-r--r-- | sbin/mount/Makefile | 6 | ||||
-rw-r--r-- | sbin/mount/mount.c | 15 | ||||
-rw-r--r-- | sbin/mount/readlabel.c | 136 |
3 files changed, 152 insertions, 5 deletions
diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile index 9326efce97e..9e9ea8fdfec 100644 --- a/sbin/mount/Makefile +++ b/sbin/mount/Makefile @@ -1,8 +1,10 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/23 14:31:09 deraadt Exp $ +# $OpenBSD: Makefile,v 1.3 1996/11/12 08:46:12 downsj Exp $ # $NetBSD: Makefile,v 1.10 1995/07/12 03:45:09 cgd Exp $ PROG= mount -SRCS= mount.c getmntopts.c +SRCS= mount.c getmntopts.c readlabel.c +DPADD= ${LIBUTIL} +LDADD= -lutil MAN= mount.8 # We do NOT install the getmntopts.3 man page. diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index e83efd55d22..721870eeae1 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.c,v 1.4 1996/06/23 14:31:12 deraadt Exp $ */ +/* $OpenBSD: mount.c,v 1.5 1996/11/12 08:46:13 downsj Exp $ */ /* $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94"; #else -static char rcsid[] = "$OpenBSD: mount.c,v 1.4 1996/06/23 14:31:12 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mount.c,v 1.5 1996/11/12 08:46:13 downsj Exp $"; #endif #endif /* not lint */ @@ -78,6 +78,8 @@ int mountfs __P((const char *, const char *, const char *, void prmount __P((struct statfs *)); void usage __P((void)); +char *readlabelfs __P((char *)); + /* Map from mount otions to printable formats. */ static struct opt { int o_opt; @@ -225,10 +227,17 @@ main(argc, argv) /* * If -t flag has not been specified, and spec contains either * a ':' or a '@' then assume that an NFS filesystem is being - * specified ala Sun. + * specified ala Sun. If not, check the disklabel for a + * known filesystem type. */ if (typelist == NULL && strpbrk(argv[0], ":@") != NULL) vfstype = "nfs"; + else { + char *labelfs = readlabelfs(argv[0]); + if (labelfs != NULL) + vfstype = labelfs; + } + rval = mountfs(vfstype, argv[0], argv[1], init_flags, options, NULL, 0); break; diff --git a/sbin/mount/readlabel.c b/sbin/mount/readlabel.c new file mode 100644 index 00000000000..48df00c5021 --- /dev/null +++ b/sbin/mount/readlabel.c @@ -0,0 +1,136 @@ +/* $OpenBSD: readlabel.c,v 1.1 1996/11/12 08:46:13 downsj Exp $ */ + +/* + * Copyright (c) 1996, Jason Downs. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <paths.h> +#include <string.h> +#include <util.h> +#include <sys/dkio.h> +#include <sys/disklabel.h> +#include <sys/param.h> +#include <sys/stat.h> + +/* + * Try to get a disklabel for the specified device, and return mount_xxx + * style filesystem type name for the specified partition. + */ + +/* This needs to be kept in sync with disklabel.h */ +static char *vfstypes[] = { + NULL, /* 0 */ + NULL, /* 1 */ + NULL, /* 2 */ + NULL, /* 3 */ + NULL, /* 4 */ + NULL, /* 5 */ + NULL, /* 6 */ + "ffs", /* 7 */ + "msdos", /* 8 */ + "lfs", /* 9 */ + NULL, /* 10 */ + NULL, /* 11 */ + "cd9660", /* 12 */ + NULL, /* 13 */ + "ados", /* 14 */ + NULL, /* 15 */ + NULL, /* 16 */ + "ext2fs" /* 17 */ +}; +#define MAXVFSTYPE FS_EXT2FS + +char *readlabelfs(device) + char *device; +{ + char rpath[MAXPATHLEN]; + char part; + struct stat sbuf; + struct disklabel dk; + int fd; + + /* Assuming device is of the form /dev/??p, build a raw partition. */ + if (stat(device, &sbuf) < 0) { + warn("%s", device); + return(NULL); + } + switch(sbuf.st_mode & S_IFMT) { + case S_IFCHR: + /* Ok... already a raw device. Hmm. */ + strncpy(rpath, device, sizeof(rpath)); + rpath[sizeof(rpath) - 1] = '\0'; + + /* Change partition name. */ + part = rpath[strlen(rpath) - 1]; + rpath[strlen(rpath) - 1] = 'a' + getrawpartition(); + break; + case S_IFBLK: + if (strlen(device) > strlen(_PATH_DEV)) { + snprintf(rpath, sizeof(rpath), "%sr%s", _PATH_DEV, + &device[strlen(_PATH_DEV)]); + + /* Change partition name. */ + part = rpath[strlen(rpath) - 1]; + rpath[strlen(rpath) - 1] = 'a' + getrawpartition(); + break; + } + default: + warnx("%s: not a device node", device); + return(NULL); + } + + /* If rpath doesn't exist, change that partition back. */ + fd = open(rpath, O_RDONLY); + if (fd < 0) { + if (errno == ENOENT) { + rpath[strlen(rpath) - 1] = part; + + fd = open(rpath, O_RDONLY); + if (fd < 0) { + warn("%s", rpath); + return(NULL); + } + } else { + warn("%s", rpath); + return(NULL); + } + } + if (ioctl(fd, DIOCGDINFO, &dk) < 0) { + warn("%s: couldn't read disklabel", rpath); + return(NULL); + } + close(fd); + + if (dk.d_partitions[part - 'a'].p_fstype > MAXVFSTYPE) { + warnx("%s: bad filesystem type in label", rpath); + return(NULL); + } + + return(vfstypes[dk.d_partitions[part - 'a'].p_fstype]); +} |