mount_chfs.c revision 1.3
11.3Sriastrad/*	$NetBSD: mount_chfs.c,v 1.3 2021/06/04 22:41:36 riastradh 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.1Sahoka/* --------------------------------------------------------------------- */
571.1Sahoka
581.1Sahokastatic void	usage(void) __dead;
591.1Sahoka
601.1Sahoka/* --------------------------------------------------------------------- */
611.1Sahoka
621.1Sahokavoid
631.1Sahokamount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args,
641.1Sahoka    int *mntflags, char *canon_dev, char *canon_dir)
651.1Sahoka{
661.1Sahoka	int ch;
671.1Sahoka	struct stat sb;
681.1Sahoka
691.1Sahoka	/* Set default values for mount point arguments. */
701.1Sahoka	memset(args, 0, sizeof(*args));
711.1Sahoka	*mntflags = 0;
721.1Sahoka
731.1Sahoka	optind = optreset = 1;
741.1Sahoka
751.1Sahoka	while ((ch = getopt(argc, argv, "i:")) != -1) {
761.1Sahoka		switch (ch) {
771.1Sahoka		case '?':
781.1Sahoka		default:
791.1Sahoka			usage();
801.1Sahoka		}
811.1Sahoka	}
821.1Sahoka	argc -= optind;
831.1Sahoka	argv += optind;
841.1Sahoka
851.1Sahoka	if (argc != 2)
861.1Sahoka		usage();
871.1Sahoka
881.1Sahoka	//strlcpy(canon_dev, argv[0], MAXPATHLEN);
891.1Sahoka	pathadj(argv[0], canon_dev);
901.1Sahoka	pathadj(argv[1], canon_dir);
911.1Sahoka
921.1Sahoka	args->fspec = canon_dev;
931.1Sahoka
941.1Sahoka	if (stat(canon_dir, &sb) == -1) {
951.1Sahoka		err(EXIT_FAILURE, "cannot stat `%s'", canon_dir);
961.1Sahoka	}
971.1Sahoka
981.1Sahoka}
991.1Sahoka
1001.1Sahoka/* --------------------------------------------------------------------- */
1011.1Sahoka
1021.1Sahokastatic void
1031.1Sahokausage(void)
1041.1Sahoka{
1051.1Sahoka	(void)fprintf(stderr,
1061.1Sahoka	    "usage: %s special mountpath\n",
1071.1Sahoka	    getprogname());
1081.1Sahoka	exit(1);
1091.1Sahoka}
1101.1Sahoka
1111.1Sahoka/* --------------------------------------------------------------------- */
1121.1Sahoka
1131.1Sahokaint
1141.1Sahokamount_chfs(int argc, char *argv[])
1151.1Sahoka{
1161.1Sahoka	struct ufs_args args;
1171.1Sahoka	char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN];
1181.1Sahoka	int mntflags;
1191.1Sahoka
1201.1Sahoka	mount_chfs_parseargs(argc, argv, &args, &mntflags,
1211.1Sahoka	    canon_dev, fs_name);
1221.1Sahoka
1231.3Sriastrad	if (mount(MOUNT_CHFS, fs_name, mntflags, &args, sizeof args) == -1) {
1241.1Sahoka		err(EXIT_FAILURE, "chfs on %s", fs_name);
1251.1Sahoka	}
1261.1Sahoka
1271.1Sahoka	if (mntflags & MNT_GETARGS) {
1281.1Sahoka
1291.1Sahoka		//(void)printf("flash index=%d\n",  args.fl_index);
1301.1Sahoka	}
1311.1Sahoka
1321.1Sahoka	return EXIT_SUCCESS;
1331.1Sahoka}
1341.1Sahoka
1351.1Sahoka#ifndef MOUNT_NOMAIN
1361.1Sahokaint
1371.1Sahokamain(int argc, char *argv[])
1381.1Sahoka{
1391.1Sahoka	setprogname(argv[0]);
1401.1Sahoka	return mount_chfs(argc, argv);
1411.1Sahoka}
1421.1Sahoka#endif
143