1 /* $NetBSD: ops_cdfs.c,v 1.4 2015/01/17 17:46:31 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1997-2014 Erez Zadok 5 * Copyright (c) 1990 Jan-Simon Pendry 6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 7 * Copyright (c) 1990 The Regents of the University of California. 8 * All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Jan-Simon Pendry at Imperial College, London. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * 38 * File: am-utils/amd/ops_cdfs.c 39 * 40 */ 41 42 /* 43 * High Sierra (CD-ROM) file system 44 */ 45 46 #ifdef HAVE_CONFIG_H 47 # include <config.h> 48 #endif /* HAVE_CONFIG_H */ 49 #include <am_defs.h> 50 #include <amd.h> 51 52 /* forward declarations */ 53 static char *cdfs_match(am_opts *fo); 54 static int cdfs_mount(am_node *am, mntfs *mf); 55 static int cdfs_umount(am_node *am, mntfs *mf); 56 57 /* 58 * Ops structure 59 */ 60 am_ops cdfs_ops = 61 { 62 "cdfs", 63 cdfs_match, 64 0, /* cdfs_init */ 65 cdfs_mount, 66 cdfs_umount, 67 amfs_error_lookup_child, 68 amfs_error_mount_child, 69 amfs_error_readdir, 70 0, /* cdfs_readlink */ 71 0, /* cdfs_mounted */ 72 0, /* cdfs_umounted */ 73 amfs_generic_find_srvr, 74 0, /* cdfs_get_wchan */ 75 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */ 76 #ifdef HAVE_FS_AUTOFS 77 AUTOFS_CDFS_FS_FLAGS, 78 #endif /* HAVE_FS_AUTOFS */ 79 }; 80 81 82 /* 83 * CDFS needs remote filesystem. 84 */ 85 static char * 86 cdfs_match(am_opts *fo) 87 { 88 if (!fo->opt_dev) { 89 plog(XLOG_USER, "cdfs: no source device specified"); 90 return 0; 91 } 92 dlog("CDFS: mounting device \"%s\" on \"%s\"", 93 fo->opt_dev, fo->opt_fs); 94 95 /* 96 * Determine magic cookie to put in mtab 97 */ 98 return xstrdup(fo->opt_dev); 99 } 100 101 102 static int 103 mount_cdfs(char *mntdir, char *fs_name, char *opts, int on_autofs) 104 { 105 cdfs_args_t cdfs_args; 106 mntent_t mnt; 107 int genflags, cdfs_flags, retval; 108 109 /* 110 * Figure out the name of the file system type. 111 */ 112 MTYPE_TYPE type = MOUNT_TYPE_CDFS; 113 114 memset((voidp) &cdfs_args, 0, sizeof(cdfs_args)); /* Paranoid */ 115 cdfs_flags = 0; 116 117 /* 118 * Fill in the mount structure 119 */ 120 memset((voidp) &mnt, 0, sizeof(mnt)); 121 mnt.mnt_dir = mntdir; 122 mnt.mnt_fsname = fs_name; 123 mnt.mnt_type = MNTTAB_TYPE_CDFS; 124 mnt.mnt_opts = opts; 125 126 #if defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM) 127 if (amu_hasmntopt(&mnt, MNTTAB_OPT_DEFPERM)) 128 # ifdef MNT2_CDFS_OPT_DEFPERM 129 cdfs_flags |= MNT2_CDFS_OPT_DEFPERM; 130 # else /* not MNT2_CDFS_OPT_DEFPERM */ 131 cdfs_flags &= ~MNT2_CDFS_OPT_NODEFPERM; 132 # endif /* not MNT2_CDFS_OPT_DEFPERM */ 133 #endif /* defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM) */ 134 135 #if defined(MNT2_CDFS_OPT_NODEFPERM) && defined(MNTTAB_OPT_NODEFPERM) 136 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NODEFPERM)) 137 cdfs_flags |= MNT2_CDFS_OPT_NODEFPERM; 138 #endif /* MNTTAB_OPT_NODEFPERM */ 139 140 #if defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION) 141 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOVERSION)) 142 cdfs_flags |= MNT2_CDFS_OPT_NOVERSION; 143 #endif /* defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION) */ 144 145 #if defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP) 146 if (amu_hasmntopt(&mnt, MNTTAB_OPT_RRIP)) 147 cdfs_flags |= MNT2_CDFS_OPT_RRIP; 148 #endif /* defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP) */ 149 150 #if defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP) 151 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NORRIP)) 152 cdfs_flags |= MNT2_CDFS_OPT_NORRIP; 153 #endif /* defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP) */ 154 155 #if defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS) 156 if (amu_hasmntopt(&mnt, MNTTAB_OPT_GENS)) 157 cdfs_flags |= MNT2_CDFS_OPT_GENS; 158 #endif /* defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS) */ 159 160 #if defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT) 161 if (amu_hasmntopt(&mnt, MNTTAB_OPT_EXTATT)) 162 cdfs_flags |= MNT2_CDFS_OPT_EXTATT; 163 #endif /* defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT) */ 164 165 #if defined(MNT2_CDFS_OPT_NOCASETRANS) && defined(MNTTAB_OPT_NOCASETRANS) 166 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOCASETRANS)) 167 cdfs_flags |= MNT2_CDFS_OPT_NOCASETRANS; 168 #endif /* defined(MNT2_CDFS_OPT_NOCASETRANS) && defined(MNTTAB_OPT_NOCASETRANS) */ 169 170 #if defined(MNT2_CDFS_OPT_NOJOLIET) && defined(MNTTAB_OPT_NOJOLIET) 171 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOJOLIET)) 172 cdfs_flags |= MNT2_CDFS_OPT_NOJOLIET; 173 #endif /* defined(MNT2_CDFS_OPT_NOJOLIET) && defined(MNTTAB_OPT_NOJOLIET) */ 174 175 #if defined(MNT2_CDFS_OPT_RRCASEINS) && defined(MNTTAB_OPT_RRCASEINS) 176 if (amu_hasmntopt(&mnt, MNTTAB_OPT_RRCASEINS)) 177 cdfs_flags |= MNT2_CDFS_OPT_RRCASEINS; 178 #endif /* defined(MNT2_CDFS_OPT_RRCASEINS) && defined(MNTTAB_OPT_RRCASEINS) */ 179 180 genflags = compute_mount_flags(&mnt); 181 #ifdef HAVE_FS_AUTOFS 182 if (on_autofs) 183 genflags |= autofs_compute_mount_flags(&mnt); 184 #endif /* HAVE_FS_AUTOFS */ 185 186 #ifdef HAVE_CDFS_ARGS_T_FLAGS 187 cdfs_args.flags = cdfs_flags; 188 #endif /* HAVE_CDFS_ARGS_T_FLAGS */ 189 190 #ifdef HAVE_CDFS_ARGS_T_ISO_FLAGS 191 cdfs_args.iso_flags = genflags | cdfs_flags; 192 #endif /* HAVE_CDFS_ARGS_T_ISO_FLAGS */ 193 194 #ifdef HAVE_CDFS_ARGS_T_ISO_PGTHRESH 195 cdfs_args.iso_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH); 196 #endif /* HAVE_CDFS_ARGS_T_ISO_PGTHRESH */ 197 198 #ifdef HAVE_CDFS_ARGS_T_NORRIP 199 /* XXX: need to provide norrip mount opt */ 200 cdfs_args.norrip = 0; /* use Rock-Ridge Protocol extensions */ 201 #endif /* HAVE_CDFS_ARGS_T_NORRIP */ 202 203 #ifdef HAVE_CDFS_ARGS_T_SSECTOR 204 /* XXX: need to provide ssector mount option */ 205 cdfs_args.ssector = 0; /* use 1st session on disk */ 206 #endif /* HAVE_CDFS_ARGS_T_SSECTOR */ 207 208 #ifdef HAVE_CDFS_ARGS_T_FSPEC 209 cdfs_args.fspec = fs_name; 210 #endif /* HAVE_CDFS_ARGS_T_FSPEC */ 211 212 /* 213 * Call generic mount routine 214 */ 215 retval = mount_fs(&mnt, genflags, (caddr_t) &cdfs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs); 216 217 return retval; 218 } 219 220 221 static int 222 cdfs_mount(am_node *am, mntfs *mf) 223 { 224 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS; 225 int error; 226 227 error = mount_cdfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs); 228 if (error) { 229 errno = error; 230 plog(XLOG_ERROR, "mount_cdfs: %m"); 231 return error; 232 } 233 return 0; 234 } 235 236 237 static int 238 cdfs_umount(am_node *am, mntfs *mf) 239 { 240 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0; 241 242 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags); 243 } 244