Home | History | Annotate | Line # | Download | only in mount_cd9660
mount_cd9660.c revision 1.28
      1 /*	$NetBSD: mount_cd9660.c,v 1.28 2008/08/05 20:57:45 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.28 2008/08/05 20:57:45 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 	{ "nrr", 0, ISOFSMNT_NORRIP, 1 },
     78 	{ "rrip", 1, ISOFSMNT_NORRIP, 1 },
     79 	{ "joliet", 1, ISOFSMNT_NOJOLIET, 1 },
     80 	{ "rrcaseins", 0, ISOFSMNT_RRCASEINS, 1 },
     81 	MOPT_NULL,
     82 };
     83 
     84 static void	usage(void);
     85 
     86 #ifndef MOUNT_NOMAIN
     87 int
     88 main(int argc, char **argv)
     89 {
     90 
     91 	setprogname(argv[0]);
     92 	return mount_cd9660(argc, argv);
     93 }
     94 #endif
     95 
     96 void
     97 mount_cd9660_parseargs(int argc, char **argv,
     98 	struct iso_args *args, int *mntflags,
     99 	char *canon_dev, char *canon_dir)
    100 {
    101 	int ch, opts;
    102 	mntoptparse_t mp;
    103 	char *dev, *dir;
    104 
    105 	*mntflags = opts = 0;
    106 	memset(args, 0, sizeof(*args));
    107 	while ((ch = getopt(argc, argv, "egijo:r")) != -1)
    108 		switch (ch) {
    109 		case 'e':
    110 			/* obsolete, retained for compatibility only, use
    111 			 * -o extatt */
    112 			opts |= ISOFSMNT_EXTATT;
    113 			break;
    114 		case 'g':
    115 			/* obsolete, retained for compatibility only, use
    116 			 * -o gens */
    117 			opts |= ISOFSMNT_GENS;
    118 			break;
    119 		case 'j':
    120 			/* obsolete, retained fo compatibility only, use
    121 			 * -o nojoliet */
    122 			opts |= ISOFSMNT_NOJOLIET;
    123 			break;
    124 		case 'o':
    125 			mp = getmntopts(optarg, mopts, mntflags, &opts);
    126 			if (mp == NULL)
    127 				err(1, "getmntopts");
    128 			freemntopts(mp);
    129 			break;
    130 		case 'r':
    131 			/* obsolete, retained for compatibility only, use
    132 			 * -o norrip */
    133 			opts |= ISOFSMNT_NORRIP;
    134 			break;
    135 		case '?':
    136 		default:
    137 			usage();
    138 		}
    139 	argc -= optind;
    140 	argv += optind;
    141 
    142 	if (argc != 2)
    143 		usage();
    144 
    145 	dev = argv[0];
    146 	dir = argv[1];
    147 
    148 	pathadj(dev, canon_dev);
    149 	pathadj(dir, canon_dir);
    150 
    151 #define DEFAULT_ROOTUID	-2
    152 	/*
    153 	 * ISO 9660 filesystems are not writable.
    154 	 */
    155 	*mntflags |= MNT_RDONLY;
    156 	args->fspec = dev;
    157 	args->flags = opts;
    158 }
    159 
    160 int
    161 mount_cd9660(int argc, char **argv)
    162 {
    163 	struct iso_args args;
    164 	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
    165 	int mntflags;
    166 
    167 	mount_cd9660_parseargs(argc, argv, &args, &mntflags,
    168 	    canon_dev, canon_dir);
    169 
    170 	if (mount(MOUNT_CD9660, canon_dir, mntflags, &args, sizeof args) == -1)
    171 		err(1, "%s on %s", canon_dev, canon_dir);
    172 	if (mntflags & MNT_GETARGS) {
    173 		char buf[2048];
    174 		(void)snprintb(buf, sizeof(buf), ISOFSMNT_BITS, args.flags);
    175 		printf("%s\n", buf);
    176 	}
    177 
    178 	exit(0);
    179 }
    180 
    181 static void
    182 usage(void)
    183 {
    184 	(void)fprintf(stderr,
    185 		"usage: %s [-o options] special node\n", getprogname());
    186 	exit(1);
    187 }
    188