Home | History | Annotate | Line # | Download | only in mount_cd9660
mount_cd9660.c revision 1.31
      1 /*	$NetBSD: mount_cd9660.c,v 1.31 2009/10/07 20:42:09 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993, 1994
      5  *      The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley
      8  * by Pace Willisson (pace (at) blitz.com).  The Rock Ridge Extension
      9  * Support code is derived from software contributed to Berkeley
     10  * by Atsushi Murai (amurai (at) spec.co.jp).
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *      @(#)mount_cd9660.c	8.7 (Berkeley) 5/1/95
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 #ifndef lint
     41 __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
     42  The Regents of the University of California.  All rights reserved.");
     43 #endif /* not lint */
     44 
     45 #ifndef lint
     46 #if 0
     47 static char sccsid[] = "@(#)mount_cd9660.c	8.7 (Berkeley) 5/1/95";
     48 #else
     49 __RCSID("$NetBSD: mount_cd9660.c,v 1.31 2009/10/07 20:42:09 pooka Exp $");
     50 #endif
     51 #endif /* not lint */
     52 
     53 #include <sys/param.h>
     54 #include <sys/mount.h>
     55 
     56 #include <err.h>
     57 #include <stdlib.h>
     58 #include <stdio.h>
     59 #include <string.h>
     60 #include <unistd.h>
     61 #include <util.h>
     62 
     63 #include <isofs/cd9660/cd9660_mount.h>
     64 
     65 #include <mntopts.h>
     66 
     67 #include "mountprog.h"
     68 #include "mount_cd9660.h"
     69 
     70 static const struct mntopt mopts[] = {
     71 	MOPT_STDOPTS,
     72 	MOPT_UPDATE,
     73 	MOPT_GETARGS,
     74 	{ "extatt", 0, ISOFSMNT_EXTATT, 1 },
     75 	{ "gens", 0, ISOFSMNT_GENS, 1 },
     76 	{ "maplcase", 1, ISOFSMNT_NOCASETRANS, 1 },
     77 	{ "casetrans", 1, ISOFSMNT_NOCASETRANS, 1 },
     78 	{ "nrr", 0, ISOFSMNT_NORRIP, 1 },
     79 	{ "rrip", 1, ISOFSMNT_NORRIP, 1 },
     80 	{ "joliet", 1, ISOFSMNT_NOJOLIET, 1 },
     81 	{ "rrcaseins", 0, ISOFSMNT_RRCASEINS, 1 },
     82 	MOPT_NULL,
     83 };
     84 
     85 static void	usage(void);
     86 
     87 #ifndef MOUNT_NOMAIN
     88 int
     89 main(int argc, char **argv)
     90 {
     91 
     92 	setprogname(argv[0]);
     93 	return mount_cd9660(argc, argv);
     94 }
     95 #endif
     96 
     97 void
     98 mount_cd9660_parseargs(int argc, char **argv,
     99 	struct iso_args *args, int *mntflags,
    100 	char *canon_dev, char *canon_dir)
    101 {
    102 	int ch, opts;
    103 	mntoptparse_t mp;
    104 	char *dev, *dir;
    105 
    106 	memset(args, 0, sizeof(*args));
    107 	*mntflags = opts = 0;
    108 	optind = optreset = 1;
    109 	while ((ch = getopt(argc, argv, "egijo:r")) != -1)
    110 		switch (ch) {
    111 		case 'e':
    112 			/* obsolete, retained for compatibility only, use
    113 			 * -o extatt */
    114 			opts |= ISOFSMNT_EXTATT;
    115 			break;
    116 		case 'g':
    117 			/* obsolete, retained for compatibility only, use
    118 			 * -o gens */
    119 			opts |= ISOFSMNT_GENS;
    120 			break;
    121 		case 'j':
    122 			/* obsolete, retained fo compatibility only, use
    123 			 * -o nojoliet */
    124 			opts |= ISOFSMNT_NOJOLIET;
    125 			break;
    126 		case 'o':
    127 			mp = getmntopts(optarg, mopts, mntflags, &opts);
    128 			if (mp == NULL)
    129 				err(1, "getmntopts");
    130 			freemntopts(mp);
    131 			break;
    132 		case 'r':
    133 			/* obsolete, retained for compatibility only, use
    134 			 * -o norrip */
    135 			opts |= ISOFSMNT_NORRIP;
    136 			break;
    137 		case '?':
    138 		default:
    139 			usage();
    140 		}
    141 
    142 	argc -= optind;
    143 	argv += optind;
    144 
    145 	if (argc != 2)
    146 		usage();
    147 
    148 	dev = argv[0];
    149 	dir = argv[1];
    150 
    151 	pathadj(dev, canon_dev);
    152 	pathadj(dir, canon_dir);
    153 
    154 #define DEFAULT_ROOTUID	-2
    155 	/*
    156 	 * ISO 9660 filesystems are not writable.
    157 	 */
    158 	if ((*mntflags & MNT_GETARGS) == 0)
    159 		*mntflags |= MNT_RDONLY;
    160 	args->fspec = canon_dev;
    161 	args->flags = opts;
    162 }
    163 
    164 int
    165 mount_cd9660(int argc, char **argv)
    166 {
    167 	struct iso_args args;
    168 	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
    169 	int mntflags;
    170 
    171 	mount_cd9660_parseargs(argc, argv, &args, &mntflags,
    172 	    canon_dev, canon_dir);
    173 
    174 	if (mount(MOUNT_CD9660, canon_dir, mntflags, &args, sizeof args) == -1)
    175 		err(1, "%s on %s", canon_dev, canon_dir);
    176 	if (mntflags & MNT_GETARGS) {
    177 		char buf[2048];
    178 		(void)snprintb(buf, sizeof(buf), ISOFSMNT_BITS, args.flags);
    179 		printf("%s\n", buf);
    180 	}
    181 
    182 	exit(0);
    183 }
    184 
    185 static void
    186 usage(void)
    187 {
    188 	(void)fprintf(stderr,
    189 		"usage: %s [-o options] special node\n", getprogname());
    190 	exit(1);
    191 }
    192