11.1Such/*	$NetBSD: mount_v7fs.c,v 1.1 2011/06/27 11:52:58 uch Exp $ */
21.1Such
31.1Such/*-
41.1Such * Copyright (c) 2011 The NetBSD Foundation, Inc.
51.1Such * All rights reserved.
61.1Such *
71.1Such * This code is derived from software contributed to The NetBSD Foundation
81.1Such * by UCHIYAMA Yasushi.
91.1Such *
101.1Such * Redistribution and use in source and binary forms, with or without
111.1Such * modification, are permitted provided that the following conditions
121.1Such * are met:
131.1Such * 1. Redistributions of source code must retain the above copyright
141.1Such *    notice, this list of conditions and the following disclaimer.
151.1Such * 2. Redistributions in binary form must reproduce the above copyright
161.1Such *    notice, this list of conditions and the following disclaimer in the
171.1Such *    documentation and/or other materials provided with the distribution.
181.1Such *
191.1Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Such * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Such * POSSIBILITY OF SUCH DAMAGE.
301.1Such */
311.1Such/*-
321.1Such * Copyright (c) 1993, 1994
331.1Such *	The Regents of the University of California.  All rights reserved.
341.1Such *
351.1Such * Redistribution and use in source and binary forms, with or without
361.1Such * modification, are permitted provided that the following conditions
371.1Such * are met:
381.1Such * 1. Redistributions of source code must retain the above copyright
391.1Such *    notice, this list of conditions and the following disclaimer.
401.1Such * 2. Redistributions in binary form must reproduce the above copyright
411.1Such *    notice, this list of conditions and the following disclaimer in the
421.1Such *    documentation and/or other materials provided with the distribution.
431.1Such * 3. Neither the name of the University nor the names of its contributors
441.1Such *    may be used to endorse or promote products derived from this software
451.1Such *    without specific prior written permission.
461.1Such *
471.1Such * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
481.1Such * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
491.1Such * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
501.1Such * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
511.1Such * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
521.1Such * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
531.1Such * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
541.1Such * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
551.1Such * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
561.1Such * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
571.1Such * SUCH DAMAGE.
581.1Such */
591.1Such
601.1Such#include <sys/cdefs.h>
611.1Such#ifndef lint
621.1Such__RCSID("$NetBSD: mount_v7fs.c,v 1.1 2011/06/27 11:52:58 uch Exp $");
631.1Such#endif /* not lint */
641.1Such
651.1Such#include <sys/param.h>
661.1Such#include <sys/mount.h>
671.1Such
681.1Such#include <err.h>
691.1Such#include <errno.h>
701.1Such#include <stdio.h>
711.1Such#include <stdlib.h>
721.1Such
731.1Such#include <string.h>
741.1Such#include <unistd.h>
751.1Such
761.1Such#include <mntopts.h>
771.1Such
781.1Such#include "mountprog.h"
791.1Such#include "mount_v7fs.h"
801.1Such
811.1Suchstatic const struct mntopt mopts[] = {
821.1Such	MOPT_STDOPTS,
831.1Such	MOPT_UPDATE,
841.1Such	MOPT_GETARGS,
851.1Such	MOPT_NULL,
861.1Such};
871.1Such
881.1Suchstatic void v7fs_usage(void) __dead;
891.1Such
901.1Such#ifndef MOUNT_NOMAIN
911.1Suchint
921.1Suchmain(int argc, char **argv)
931.1Such{
941.1Such
951.1Such	return mount_v7fs(argc, argv);
961.1Such}
971.1Such#endif
981.1Such
991.1Suchint
1001.1Suchmount_v7fs(int argc, char *argv[])
1011.1Such{
1021.1Such	struct v7fs_args args;
1031.1Such	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
1041.1Such	const char *errcause;
1051.1Such	int mntflags;
1061.1Such
1071.1Such	mount_v7fs_parseargs(argc, argv, &args, &mntflags,
1081.1Such	    canon_dev, canon_dir);
1091.1Such
1101.1Such	if (mount(MOUNT_V7FS, canon_dir, mntflags, &args, sizeof args) == -1) {
1111.1Such		switch (errno) {
1121.1Such		case EMFILE:
1131.1Such			errcause = "mount table full";
1141.1Such			break;
1151.1Such		case EINVAL:
1161.1Such			if (mntflags & MNT_UPDATE)
1171.1Such				errcause =
1181.1Such			    "specified device does not match mounted device";
1191.1Such			else
1201.1Such				errcause = "incorrect super block";
1211.1Such			break;
1221.1Such		default:
1231.1Such			errcause = strerror(errno);
1241.1Such			break;
1251.1Such		}
1261.1Such		errx(EXIT_FAILURE, "%s on %s: %s", canon_dev, canon_dir,
1271.1Such		    errcause);
1281.1Such	}
1291.1Such
1301.1Such	if (mntflags & MNT_GETARGS) {
1311.1Such		printf("endian=%d\n", args.endian);
1321.1Such	}
1331.1Such
1341.1Such	return EXIT_SUCCESS;
1351.1Such}
1361.1Such
1371.1Suchvoid
1381.1Suchmount_v7fs_parseargs(int argc, char **argv, struct v7fs_args *args,
1391.1Such    int *mntflags, char *canon_dev, char *canon_dir)
1401.1Such{
1411.1Such	int ch;
1421.1Such	mntoptparse_t mp;
1431.1Such	int endian = _BYTE_ORDER;
1441.1Such	*mntflags = 0;
1451.1Such	optind = optreset = 1;		/* Reset for parse of new argv. */
1461.1Such	while ((ch = getopt(argc, argv, "o:B:")) != -1)
1471.1Such		switch (ch) {
1481.1Such		case 'o':
1491.1Such			mp = getmntopts(optarg, mopts, mntflags, 0);
1501.1Such			if (mp == NULL)
1511.1Such				err(1, "getmntopts");
1521.1Such			freemntopts(mp);
1531.1Such			break;
1541.1Such		case 'B':
1551.1Such		  switch (optarg[0]) {
1561.1Such		    case 'l':
1571.1Such		      endian = _LITTLE_ENDIAN;
1581.1Such		      break;
1591.1Such		    case 'b':
1601.1Such		      endian = _BIG_ENDIAN;
1611.1Such		      break;
1621.1Such		    case 'p':
1631.1Such		      endian = _PDP_ENDIAN;
1641.1Such		      break;
1651.1Such		    }
1661.1Such		  break;
1671.1Such		case '?':
1681.1Such
1691.1Such		default:
1701.1Such			v7fs_usage();
1711.1Such		}
1721.1Such	argc -= optind;
1731.1Such	argv += optind;
1741.1Such
1751.1Such	if (argc != 2)
1761.1Such		v7fs_usage();
1771.1Such
1781.1Such	pathadj(argv[0], canon_dev);
1791.1Such	args->endian = endian;
1801.1Such	args->fspec = canon_dev;
1811.1Such	pathadj(argv[1], canon_dir);
1821.1Such}
1831.1Such
1841.1Suchstatic void
1851.1Suchv7fs_usage(void)
1861.1Such{
1871.1Such
1881.1Such	fprintf(stderr, "usage: \n %s [-o options] [-B endian] special node\n",
1891.1Such	    getprogname());
1901.1Such	exit(EXIT_FAILURE);
1911.1Such}
192