mount_hfs.c revision 1.7       1  1.7  lukem /*	$NetBSD: mount_hfs.c,v 1.7 2008/07/20 01:20:22 lukem Exp $	*/
      2  1.1  dillo 
      3  1.1  dillo /*-
      4  1.1  dillo  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
      5  1.1  dillo  * All rights reserved.
      6  1.1  dillo  *
      7  1.1  dillo  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  dillo  * by Yevgeny Binder and Dieter Baron.
      9  1.1  dillo  *
     10  1.1  dillo  * Redistribution and use in source and binary forms, with or without
     11  1.1  dillo  * modification, are permitted provided that the following conditions
     12  1.1  dillo  * are met:
     13  1.1  dillo  * 1. Redistributions of source code must retain the above copyright
     14  1.1  dillo  *    notice, this list of conditions and the following disclaimer.
     15  1.1  dillo  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  dillo  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  dillo  *    documentation and/or other materials provided with the distribution.
     18  1.1  dillo  *
     19  1.1  dillo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  dillo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  dillo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  dillo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  dillo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  dillo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  dillo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  dillo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  dillo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  dillo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  dillo  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  dillo  */
     31  1.1  dillo 
     32  1.1  dillo /*
     33  1.1  dillo  * Copyright (c) 1993, 1994
     34  1.1  dillo  *	The Regents of the University of California.  All rights reserved.
     35  1.1  dillo  *
     36  1.1  dillo  * Redistribution and use in source and binary forms, with or without
     37  1.1  dillo  * modification, are permitted provided that the following conditions
     38  1.1  dillo  * are met:
     39  1.1  dillo  * 1. Redistributions of source code must retain the above copyright
     40  1.1  dillo  *    notice, this list of conditions and the following disclaimer.
     41  1.1  dillo  * 2. Redistributions in binary form must reproduce the above copyright
     42  1.1  dillo  *    notice, this list of conditions and the following disclaimer in the
     43  1.1  dillo  *    documentation and/or other materials provided with the distribution.
     44  1.1  dillo  * 3. Neither the name of the University nor the names of its contributors
     45  1.1  dillo  *    may be used to endorse or promote products derived from this software
     46  1.1  dillo  *    without specific prior written permission.
     47  1.1  dillo  *
     48  1.1  dillo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49  1.1  dillo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50  1.1  dillo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51  1.1  dillo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52  1.1  dillo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53  1.1  dillo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54  1.1  dillo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55  1.1  dillo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56  1.1  dillo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57  1.1  dillo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58  1.1  dillo  * SUCH DAMAGE.
     59  1.1  dillo  */
     60  1.1  dillo 
     61  1.1  dillo #include <sys/cdefs.h>
     62  1.1  dillo #ifndef lint
     63  1.7  lukem __COPYRIGHT("@(#) Copyright (c) 2005 Yevgeny Binder.  All rights reserved.");
     64  1.1  dillo #endif /* not lint */
     65  1.1  dillo 
     66  1.1  dillo #ifndef lint
     67  1.7  lukem __RCSID("$NetBSD: mount_hfs.c,v 1.7 2008/07/20 01:20:22 lukem Exp $");
     68  1.1  dillo #endif /* not lint */
     69  1.1  dillo 
     70  1.1  dillo #include <sys/param.h>
     71  1.1  dillo #include <sys/mount.h>
     72  1.1  dillo 
     73  1.1  dillo #include <err.h>
     74  1.1  dillo #include <unistd.h>
     75  1.1  dillo #include <stdio.h>
     76  1.1  dillo #include <stdlib.h>
     77  1.1  dillo #include <string.h>
     78  1.1  dillo 
     79  1.1  dillo #include <mntopts.h>
     80  1.1  dillo 
     81  1.2  dillo #include <fs/hfs/hfs.h>
     82  1.1  dillo 
     83  1.1  dillo static const struct mntopt mopts[] = {
     84  1.1  dillo 	MOPT_STDOPTS,
     85  1.1  dillo 	MOPT_GETARGS,
     86  1.1  dillo 	MOPT_NULL,
     87  1.1  dillo };
     88  1.1  dillo 
     89  1.6  perry int	main(int, char *[]);
     90  1.6  perry int	mount_hfs(int argc, char **argv);
     91  1.6  perry static void	usage(void);
     92  1.1  dillo 
     93  1.1  dillo #ifndef MOUNT_NOMAIN
     94  1.1  dillo int
     95  1.6  perry main(int argc, char **argv)
     96  1.1  dillo {
     97  1.2  dillo 	return mount_hfs(argc, argv);
     98  1.1  dillo }
     99  1.1  dillo #endif
    100  1.1  dillo 
    101  1.1  dillo int
    102  1.6  perry mount_hfs(int argc, char *argv[])
    103  1.1  dillo {
    104  1.2  dillo 	struct hfs_args args;
    105  1.1  dillo 	mntoptparse_t optparse;
    106  1.1  dillo 	int ch, mntflags;
    107  1.1  dillo 	char *fs_name;
    108  1.1  dillo 
    109  1.1  dillo 	args.fspec = NULL;
    110  1.1  dillo 
    111  1.1  dillo 	mntflags = 0;
    112  1.1  dillo 	optind = optreset = 1;		/* Reset for parse of new argv. */
    113  1.1  dillo 	while ((ch = getopt(argc, argv, "o:")) != -1)
    114  1.1  dillo 		switch (ch) {
    115  1.1  dillo 		case 'o':
    116  1.1  dillo 			optparse = getmntopts(optarg, mopts, &mntflags, 0);
    117  1.3  dillo 			if (optparse == NULL)
    118  1.3  dillo 				err(1, "getmntopts");
    119  1.1  dillo 			freemntopts(optparse);
    120  1.1  dillo 			break;
    121  1.1  dillo 		case '?':
    122  1.1  dillo 		default:
    123  1.1  dillo 			usage();
    124  1.1  dillo 		}
    125  1.1  dillo 	argc -= optind;
    126  1.1  dillo 	argv += optind;
    127  1.1  dillo 
    128  1.1  dillo 	if (argc != 2)
    129  1.1  dillo 		usage();
    130  1.1  dillo 
    131  1.1  dillo 	args.fspec = argv[0];	/* The name of the device file. */
    132  1.1  dillo 	fs_name = argv[1];		/* The mount point. */
    133  1.1  dillo 
    134  1.1  dillo 
    135  1.5  pooka 	if (mount(MOUNT_HFS, fs_name, mntflags, &args, sizeof args) == -1)
    136  1.1  dillo 		err(1, "%s on %s", args.fspec, fs_name);
    137  1.1  dillo 
    138  1.1  dillo 	exit(0);
    139  1.1  dillo }
    140  1.1  dillo 
    141  1.1  dillo static void
    142  1.6  perry usage(void)
    143  1.1  dillo {
    144  1.2  dillo 	(void)fprintf(stderr, "usage: mount_hfs [-o options] special node\n");
    145  1.1  dillo 	exit(1);
    146  1.1  dillo }
    147