1 /* $NetBSD: mount_cd9660.c,v 1.26 2007/07/16 17:06:52 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@blitz.com). The Rock Ridge Extension 9 * Support code is derived from software contributed to Berkeley 10 * by Atsushi Murai (amurai@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\n\ 42 The Regents of the University of California. All rights reserved.\n"); 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.26 2007/07/16 17:06:52 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 static const struct mntopt mopts[] = { 68 MOPT_STDOPTS, 69 MOPT_UPDATE, 70 MOPT_GETARGS, 71 { "extatt", 0, ISOFSMNT_EXTATT, 1 }, 72 { "gens", 0, ISOFSMNT_GENS, 1 }, 73 { "maplcase", 1, ISOFSMNT_NOCASETRANS, 1 }, 74 { "nrr", 0, ISOFSMNT_NORRIP, 1 }, 75 { "rrip", 1, ISOFSMNT_NORRIP, 1 }, 76 { "joliet", 1, ISOFSMNT_NOJOLIET, 1 }, 77 { "rrcaseins", 0, ISOFSMNT_RRCASEINS, 1 }, 78 MOPT_NULL, 79 }; 80 81 int mount_cd9660(int argc, char **argv); 82 static void usage(void); 83 84 #ifndef MOUNT_NOMAIN 85 int 86 main(int argc, char **argv) 87 { 88 return mount_cd9660(argc, argv); 89 } 90 #endif 91 92 int 93 mount_cd9660(int argc, char **argv) 94 { 95 struct iso_args args; 96 int ch, mntflags, opts; 97 mntoptparse_t mp; 98 char *dev, *dir, canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN]; 99 100 mntflags = opts = 0; 101 while ((ch = getopt(argc, argv, "egijo:r")) != -1) 102 switch (ch) { 103 case 'e': 104 /* obsolete, retained for compatibility only, use 105 * -o extatt */ 106 opts |= ISOFSMNT_EXTATT; 107 break; 108 case 'g': 109 /* obsolete, retained for compatibility only, use 110 * -o gens */ 111 opts |= ISOFSMNT_GENS; 112 break; 113 case 'j': 114 /* obsolete, retained fo compatibility only, use 115 * -o nojoliet */ 116 opts |= ISOFSMNT_NOJOLIET; 117 break; 118 case 'o': 119 mp = getmntopts(optarg, mopts, &mntflags, &opts); 120 if (mp == NULL) 121 err(1, "getmntopts"); 122 freemntopts(mp); 123 break; 124 case 'r': 125 /* obsolete, retained for compatibility only, use 126 * -o norrip */ 127 opts |= ISOFSMNT_NORRIP; 128 break; 129 case '?': 130 default: 131 usage(); 132 } 133 argc -= optind; 134 argv += optind; 135 136 if (argc != 2) 137 usage(); 138 139 dev = argv[0]; 140 dir = argv[1]; 141 142 if (realpath(dev, canon_dev) == NULL) /* Check device path */ 143 err(1, "realpath %s", dev); 144 if (strncmp(dev, canon_dev, MAXPATHLEN)) { 145 warnx("\"%s\" is a relative path.", dev); 146 dev = canon_dev; 147 warnx("using \"%s\" instead.", dev); 148 } 149 150 if (realpath(dir, canon_dir) == NULL) /* Check mounton path */ 151 err(1, "realpath %s", dir); 152 if (strncmp(dir, canon_dir, MAXPATHLEN)) { 153 warnx("\"%s\" is a relative path.", dir); 154 dir = canon_dir; 155 warnx("using \"%s\" instead.", dir); 156 } 157 158 #define DEFAULT_ROOTUID -2 159 /* 160 * ISO 9660 filesystems are not writable. 161 */ 162 mntflags |= MNT_RDONLY; 163 args.fspec = dev; 164 args.flags = opts; 165 166 if (mount(MOUNT_CD9660, dir, mntflags, &args, sizeof args) == -1) 167 err(1, "%s on %s", dev, dir); 168 if (mntflags & MNT_GETARGS) { 169 char buf[2048]; 170 (void)snprintb(buf, sizeof(buf), ISOFSMNT_BITS, args.flags); 171 printf("%s\n", buf); 172 } 173 exit(0); 174 } 175 176 static void 177 usage(void) 178 { 179 (void)fprintf(stderr, 180 "usage: mount_cd9660 [-o options] special node\n"); 181 exit(1); 182 } 183