112119Sdyson/*-
212119Sdyson * Copyright (c) 1993, 1994
312119Sdyson *	The Regents of the University of California.  All rights reserved.
412119Sdyson *
512119Sdyson * Redistribution and use in source and binary forms, with or without
612119Sdyson * modification, are permitted provided that the following conditions
712119Sdyson * are met:
812119Sdyson * 1. Redistributions of source code must retain the above copyright
912119Sdyson *    notice, this list of conditions and the following disclaimer.
1012119Sdyson * 2. Redistributions in binary form must reproduce the above copyright
1112119Sdyson *    notice, this list of conditions and the following disclaimer in the
1212119Sdyson *    documentation and/or other materials provided with the distribution.
1312119Sdyson * 4. Neither the name of the University nor the names of its contributors
1412119Sdyson *    may be used to endorse or promote products derived from this software
1512119Sdyson *    without specific prior written permission.
1612119Sdyson *
1712119Sdyson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1812119Sdyson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1912119Sdyson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2012119Sdyson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2112119Sdyson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2212119Sdyson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2312119Sdyson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2412119Sdyson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2512119Sdyson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2612119Sdyson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2712119Sdyson * SUCH DAMAGE.
2812119Sdyson */
2912119Sdyson
3012119Sdyson#ifndef lint
31122622Sjohanstatic const char copyright[] =
3212119Sdyson"@(#) Copyright (c) 1993, 1994\n\
3312119Sdyson	The Regents of the University of California.  All rights reserved.\n";
3412119Sdyson#endif /* not lint */
3512119Sdyson
3612119Sdyson#ifndef lint
3715770Swollman/*
3812119Sdysonstatic char sccsid[] = "@(#)mount_lfs.c	8.3 (Berkeley) 3/27/94";
3915770Swollman*/
4015770Swollmanstatic const char rcsid[] =
4150476Speter  "$FreeBSD$";
4212119Sdyson#endif /* not lint */
4312119Sdyson
4412119Sdyson#include <sys/param.h>
4512119Sdyson#include <sys/mount.h>
46101829Smux#include <sys/uio.h>
4712119Sdyson
4812119Sdyson#include <err.h>
4912119Sdyson#include <stdio.h>
5012119Sdyson#include <stdlib.h>
5112119Sdyson#include <string.h>
5215770Swollman#include <sysexits.h>
5312119Sdyson#include <unistd.h>
5412119Sdyson
5512119Sdyson#include "mntopts.h"
5612119Sdyson
57166290Srodrigcstatic void	usage(void);
5812119Sdyson
5912119Sdysonint
60166290Srodrigcmain(int argc, char *argv[])
6112119Sdyson{
62166290Srodrigc	struct iovec *iov;
63166290Srodrigc	int ch, iovlen;
64148719Sstefanf	char *fs_name, *fspec, mntpath[MAXPATHLEN];
65166290Srodrigc	char *fstype;
6612119Sdyson
67166290Srodrigc	fstype = strrchr(argv[0], '_');
68166290Srodrigc	if (fstype == NULL)
69166290Srodrigc		errx(EX_USAGE, "argv[0] must end in _fstype");
70166290Srodrigc	else
71166290Srodrigc		++fstype;
72166290Srodrigc
73166290Srodrigc	iov = NULL;
74166290Srodrigc	iovlen = 0;
7524359Simp	while ((ch = getopt(argc, argv, "o:")) != -1)
7612119Sdyson		switch (ch) {
77166290Srodrigc		case 'o': {
78166290Srodrigc			char *p = NULL;
79166290Srodrigc			char *val = strdup("");
80166290Srodrigc			p = strchr(optarg, '=');
81166290Srodrigc			if (p != NULL) {
82166290Srodrigc				free(val);
83166290Srodrigc				*p = '\0';
84166290Srodrigc				val = p + 1;
85166290Srodrigc			}
86166290Srodrigc			build_iovec(&iov, &iovlen, optarg, val, strlen(val)+1);
87166290Srodrigc			}
8812119Sdyson			break;
8912119Sdyson		case '?':
9012119Sdyson		default:
9112119Sdyson			usage();
9212119Sdyson		}
9312119Sdyson	argc -= optind;
9412119Sdyson	argv += optind;
9512119Sdyson
9612119Sdyson	if (argc != 2)
9712119Sdyson		usage();
9812119Sdyson
9997256Smux	fspec = argv[0];	/* the name of the device file */
10012119Sdyson	fs_name = argv[1];	/* the mount point */
10112119Sdyson
10252055Sphk	/*
10352055Sphk	 * Resolve the mountpoint with realpath(3) and remove unnecessary
10452055Sphk	 * slashes from the devicename if there are any.
10552055Sphk	 */
10652055Sphk	(void)checkpath(fs_name, mntpath);
10797256Smux	(void)rmslashes(fspec, fspec);
10852055Sphk
109166290Srodrigc	build_iovec(&iov, &iovlen, "fstype", fstype, strlen(fstype) + 1);
110166290Srodrigc	build_iovec(&iov, &iovlen, "fspath", mntpath, strlen(mntpath) + 1);
111166290Srodrigc	build_iovec(&iov, &iovlen, "from", fspec, strlen(fspec) + 1);
112166290Srodrigc
113166290Srodrigc	if (nmount(iov, iovlen, 0) < 0)
11497256Smux		err(EX_OSERR, "%s", fspec);
115166290Srodrigc	return (0);
11612119Sdyson}
11712119Sdyson
118166290Srodrigcstatic void
11912119Sdysonusage()
12012119Sdyson{
12112119Sdyson	(void)fprintf(stderr,
12212119Sdyson		"usage: mount_ext2fs [-o options] special node\n");
12315770Swollman	exit(EX_USAGE);
12412119Sdyson}
125