mount_hfs.c revision 1.8       1  1.8  pooka /*	$NetBSD: mount_hfs.c,v 1.8 2008/08/05 20:57:45 pooka 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.8  pooka __RCSID("$NetBSD: mount_hfs.c,v 1.8 2008/08/05 20:57:45 pooka 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.8  pooka #include <fs/hfs/hfs.h>
     74  1.8  pooka 
     75  1.1  dillo #include <err.h>
     76  1.1  dillo #include <unistd.h>
     77  1.1  dillo #include <stdio.h>
     78  1.1  dillo #include <stdlib.h>
     79  1.1  dillo #include <string.h>
     80  1.1  dillo 
     81  1.1  dillo #include <mntopts.h>
     82  1.1  dillo 
     83  1.8  pooka #include "mountprog.h"
     84  1.8  pooka #include "mount_hfs.h"
     85  1.1  dillo 
     86  1.1  dillo static const struct mntopt mopts[] = {
     87  1.1  dillo 	MOPT_STDOPTS,
     88  1.1  dillo 	MOPT_NULL,
     89  1.1  dillo };
     90  1.1  dillo 
     91  1.6  perry int	main(int, char *[]);
     92  1.6  perry static void	usage(void);
     93  1.1  dillo 
     94  1.1  dillo #ifndef MOUNT_NOMAIN
     95  1.1  dillo int
     96  1.6  perry main(int argc, char **argv)
     97  1.1  dillo {
     98  1.8  pooka 
     99  1.8  pooka 	setprogname(argv[0]);
    100  1.2  dillo 	return mount_hfs(argc, argv);
    101  1.1  dillo }
    102  1.1  dillo #endif
    103  1.1  dillo 
    104  1.8  pooka void
    105  1.8  pooka mount_hfs_parseargs(int argc, char *argv[],
    106  1.8  pooka 	struct hfs_args *args, int *mntflags,
    107  1.8  pooka 	char *canon_dev, char *canon_dir)
    108  1.1  dillo {
    109  1.1  dillo 	mntoptparse_t optparse;
    110  1.8  pooka 	int ch;
    111  1.1  dillo 
    112  1.8  pooka 	memset(args, 0, sizeof(*args));
    113  1.8  pooka 	*mntflags = 0;
    114  1.1  dillo 	optind = optreset = 1;		/* Reset for parse of new argv. */
    115  1.1  dillo 	while ((ch = getopt(argc, argv, "o:")) != -1)
    116  1.1  dillo 		switch (ch) {
    117  1.1  dillo 		case 'o':
    118  1.8  pooka 			optparse = getmntopts(optarg, mopts, mntflags, 0);
    119  1.3  dillo 			if (optparse == NULL)
    120  1.3  dillo 				err(1, "getmntopts");
    121  1.1  dillo 			freemntopts(optparse);
    122  1.1  dillo 			break;
    123  1.1  dillo 		case '?':
    124  1.1  dillo 		default:
    125  1.1  dillo 			usage();
    126  1.1  dillo 		}
    127  1.1  dillo 	argc -= optind;
    128  1.1  dillo 	argv += optind;
    129  1.1  dillo 
    130  1.1  dillo 	if (argc != 2)
    131  1.1  dillo 		usage();
    132  1.1  dillo 
    133  1.8  pooka 	pathadj(argv[0], canon_dev);
    134  1.8  pooka 	pathadj(argv[1], canon_dir);
    135  1.8  pooka 	args->fspec = canon_dev;	/* The name of the device file. */
    136  1.8  pooka }
    137  1.8  pooka 
    138  1.8  pooka int
    139  1.8  pooka mount_hfs(int argc, char *argv[])
    140  1.8  pooka {
    141  1.8  pooka 	struct hfs_args args;
    142  1.8  pooka 	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
    143  1.8  pooka 	int mntflags;
    144  1.8  pooka 
    145  1.8  pooka 	mount_hfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir);
    146  1.1  dillo 
    147  1.8  pooka 	if (mount(MOUNT_HFS, canon_dir, mntflags, &args, sizeof args) == -1)
    148  1.8  pooka 		err(1, "%s on %s", args.fspec, canon_dir);
    149  1.1  dillo 
    150  1.1  dillo 	exit(0);
    151  1.1  dillo }
    152  1.1  dillo 
    153  1.1  dillo static void
    154  1.6  perry usage(void)
    155  1.1  dillo {
    156  1.8  pooka 	fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
    157  1.1  dillo 	exit(1);
    158  1.1  dillo }
    159