mount_chfs.c revision 1.4
11.4Sdholland/*	$NetBSD: mount_chfs.c,v 1.4 2021/06/07 21:44:35 dholland Exp $	*/
21.1Sahoka
31.1Sahoka/*-
41.1Sahoka * Copyright (c) 2010 Department of Software Engineering,
51.1Sahoka *		      University of Szeged, Hungary
61.1Sahoka * All rights reserved.
71.1Sahoka *
81.1Sahoka * This code is derived from software contributed to The NetBSD Foundation
91.1Sahoka * by the Department of Software Engineering, University of Szeged, Hungary
101.1Sahoka *
111.1Sahoka * Redistribution and use in source and binary forms, with or without
121.1Sahoka * modification, are permitted provided that the following conditions
131.1Sahoka * are met:
141.1Sahoka * 1. Redistributions of source code must retain the above copyright
151.1Sahoka *    notice, this list of conditions and the following disclaimer.
161.1Sahoka * 2. Redistributions in binary form must reproduce the above copyright
171.1Sahoka *    notice, this list of conditions and the following disclaimer in the
181.1Sahoka *    documentation and/or other materials provided with the distribution.
191.1Sahoka *
201.1Sahoka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
211.1Sahoka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221.1Sahoka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
231.1Sahoka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
241.1Sahoka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
251.1Sahoka * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
261.1Sahoka * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
271.1Sahoka * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
281.1Sahoka * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291.1Sahoka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301.1Sahoka * SUCH DAMAGE.
311.1Sahoka */
321.1Sahoka
331.1Sahoka#include <sys/cdefs.h>
341.1Sahoka#ifndef lint
351.1Sahoka#endif /* not lint */
361.1Sahoka
371.1Sahoka#include <sys/param.h>
381.1Sahoka#include <sys/mount.h>
391.1Sahoka#include <sys/stat.h>
401.1Sahoka#include <ufs/ufs/ufsmount.h>
411.1Sahoka
421.1Sahoka#include <ctype.h>
431.1Sahoka#include <err.h>
441.1Sahoka#include <errno.h>
451.1Sahoka#include <grp.h>
461.1Sahoka#include <mntopts.h>
471.1Sahoka#include <pwd.h>
481.1Sahoka#include <stdio.h>
491.1Sahoka#include <stdlib.h>
501.1Sahoka#include <string.h>
511.1Sahoka#include <unistd.h>
521.1Sahoka
531.1Sahoka#include "mountprog.h"
541.1Sahoka#include "mount_chfs.h"
551.1Sahoka
561.4Sdhollandstatic const struct mntopt mopts[] = {
571.4Sdholland	MOPT_STDOPTS,
581.4Sdholland	MOPT_GETARGS,
591.4Sdholland	MOPT_NULL,
601.4Sdholland};
611.4Sdholland
621.1Sahoka/* --------------------------------------------------------------------- */
631.1Sahoka
641.1Sahokastatic void	usage(void) __dead;
651.1Sahoka
661.1Sahoka/* --------------------------------------------------------------------- */
671.1Sahoka
681.1Sahokavoid
691.1Sahokamount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args,
701.1Sahoka    int *mntflags, char *canon_dev, char *canon_dir)
711.1Sahoka{
721.1Sahoka	int ch;
731.4Sdholland	mntoptparse_t mp;
741.1Sahoka	struct stat sb;
751.1Sahoka
761.1Sahoka	/* Set default values for mount point arguments. */
771.1Sahoka	memset(args, 0, sizeof(*args));
781.1Sahoka	*mntflags = 0;
791.1Sahoka
801.1Sahoka	optind = optreset = 1;
811.1Sahoka
821.4Sdholland	while ((ch = getopt(argc, argv, "o:")) != -1) {
831.1Sahoka		switch (ch) {
841.4Sdholland		case 'o':
851.4Sdholland			mp = getmntopts(optarg, mopts, mntflags, 0);
861.4Sdholland			if (mp == NULL)
871.4Sdholland				err(1, "getmntopts");
881.4Sdholland			freemntopts(mp);
891.4Sdholland			break;
901.1Sahoka		case '?':
911.1Sahoka		default:
921.1Sahoka			usage();
931.1Sahoka		}
941.1Sahoka	}
951.1Sahoka	argc -= optind;
961.1Sahoka	argv += optind;
971.1Sahoka
981.1Sahoka	if (argc != 2)
991.1Sahoka		usage();
1001.1Sahoka
1011.1Sahoka	//strlcpy(canon_dev, argv[0], MAXPATHLEN);
1021.1Sahoka	pathadj(argv[0], canon_dev);
1031.1Sahoka	pathadj(argv[1], canon_dir);
1041.1Sahoka
1051.1Sahoka	args->fspec = canon_dev;
1061.1Sahoka
1071.1Sahoka	if (stat(canon_dir, &sb) == -1) {
1081.1Sahoka		err(EXIT_FAILURE, "cannot stat `%s'", canon_dir);
1091.1Sahoka	}
1101.1Sahoka
1111.1Sahoka}
1121.1Sahoka
1131.1Sahoka/* --------------------------------------------------------------------- */
1141.1Sahoka
1151.1Sahokastatic void
1161.1Sahokausage(void)
1171.1Sahoka{
1181.1Sahoka	(void)fprintf(stderr,
1191.1Sahoka	    "usage: %s special mountpath\n",
1201.1Sahoka	    getprogname());
1211.1Sahoka	exit(1);
1221.1Sahoka}
1231.1Sahoka
1241.1Sahoka/* --------------------------------------------------------------------- */
1251.1Sahoka
1261.1Sahokaint
1271.1Sahokamount_chfs(int argc, char *argv[])
1281.1Sahoka{
1291.1Sahoka	struct ufs_args args;
1301.1Sahoka	char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN];
1311.1Sahoka	int mntflags;
1321.1Sahoka
1331.1Sahoka	mount_chfs_parseargs(argc, argv, &args, &mntflags,
1341.1Sahoka	    canon_dev, fs_name);
1351.1Sahoka
1361.3Sriastrad	if (mount(MOUNT_CHFS, fs_name, mntflags, &args, sizeof args) == -1) {
1371.1Sahoka		err(EXIT_FAILURE, "chfs on %s", fs_name);
1381.1Sahoka	}
1391.1Sahoka
1401.1Sahoka	if (mntflags & MNT_GETARGS) {
1411.1Sahoka
1421.1Sahoka		//(void)printf("flash index=%d\n",  args.fl_index);
1431.1Sahoka	}
1441.1Sahoka
1451.1Sahoka	return EXIT_SUCCESS;
1461.1Sahoka}
1471.1Sahoka
1481.1Sahoka#ifndef MOUNT_NOMAIN
1491.1Sahokaint
1501.1Sahokamain(int argc, char *argv[])
1511.1Sahoka{
1521.1Sahoka	setprogname(argv[0]);
1531.1Sahoka	return mount_chfs(argc, argv);
1541.1Sahoka}
1551.1Sahoka#endif
156