138494Sobrien/*
2174294Sobrien * Copyright (c) 1997-2006 Erez Zadok
338494Sobrien * Copyright (c) 1990 Jan-Simon Pendry
438494Sobrien * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
538494Sobrien * Copyright (c) 1990 The Regents of the University of California.
638494Sobrien * All rights reserved.
738494Sobrien *
838494Sobrien * This code is derived from software contributed to Berkeley by
938494Sobrien * Jan-Simon Pendry at Imperial College, London.
1038494Sobrien *
1138494Sobrien * Redistribution and use in source and binary forms, with or without
1238494Sobrien * modification, are permitted provided that the following conditions
1338494Sobrien * are met:
1438494Sobrien * 1. Redistributions of source code must retain the above copyright
1538494Sobrien *    notice, this list of conditions and the following disclaimer.
1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1738494Sobrien *    notice, this list of conditions and the following disclaimer in the
1838494Sobrien *    documentation and/or other materials provided with the distribution.
1938494Sobrien * 3. All advertising materials mentioning features or use of this software
2042629Sobrien *    must display the following acknowledgment:
2138494Sobrien *      This product includes software developed by the University of
2238494Sobrien *      California, Berkeley and its contributors.
2338494Sobrien * 4. Neither the name of the University nor the names of its contributors
2438494Sobrien *    may be used to endorse or promote products derived from this software
2538494Sobrien *    without specific prior written permission.
2638494Sobrien *
2738494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2838494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2938494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3038494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3138494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3238494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3338494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3438494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3538494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3638494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3738494Sobrien * SUCH DAMAGE.
3838494Sobrien *
3938494Sobrien *
40174294Sobrien * File: am-utils/amd/ops_cdfs.c
4138494Sobrien *
4238494Sobrien */
4338494Sobrien
4438494Sobrien/*
4538494Sobrien * High Sierra (CD-ROM) file system
4638494Sobrien */
4738494Sobrien
4838494Sobrien#ifdef HAVE_CONFIG_H
4938494Sobrien# include <config.h>
5038494Sobrien#endif /* HAVE_CONFIG_H */
5138494Sobrien#include <am_defs.h>
5238494Sobrien#include <amd.h>
5338494Sobrien
5438494Sobrien/* forward declarations */
5538494Sobrienstatic char *cdfs_match(am_opts *fo);
56174294Sobrienstatic int cdfs_mount(am_node *am, mntfs *mf);
57174294Sobrienstatic int cdfs_umount(am_node *am, mntfs *mf);
5838494Sobrien
5938494Sobrien/*
6038494Sobrien * Ops structure
6138494Sobrien */
6238494Sobrienam_ops cdfs_ops =
6338494Sobrien{
6438494Sobrien  "cdfs",
6538494Sobrien  cdfs_match,
6638494Sobrien  0,				/* cdfs_init */
67174294Sobrien  cdfs_mount,
68174294Sobrien  cdfs_umount,
69174294Sobrien  amfs_error_lookup_child,
70174294Sobrien  amfs_error_mount_child,
7138494Sobrien  amfs_error_readdir,
7238494Sobrien  0,				/* cdfs_readlink */
7338494Sobrien  0,				/* cdfs_mounted */
7438494Sobrien  0,				/* cdfs_umounted */
75174294Sobrien  amfs_generic_find_srvr,
76174294Sobrien  0,				/* cdfs_get_wchan */
77174294Sobrien  FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO,	/* nfs_fs_flags */
78174294Sobrien#ifdef HAVE_FS_AUTOFS
79174294Sobrien  AUTOFS_CDFS_FS_FLAGS,
80174294Sobrien#endif /* HAVE_FS_AUTOFS */
8138494Sobrien};
8238494Sobrien
8338494Sobrien
8438494Sobrien/*
8538494Sobrien * CDFS needs remote filesystem.
8638494Sobrien */
8738494Sobrienstatic char *
8838494Sobriencdfs_match(am_opts *fo)
8938494Sobrien{
9038494Sobrien  if (!fo->opt_dev) {
9138494Sobrien    plog(XLOG_USER, "cdfs: no source device specified");
9238494Sobrien    return 0;
9338494Sobrien  }
9438494Sobrien  dlog("CDFS: mounting device \"%s\" on \"%s\"",
9538494Sobrien       fo->opt_dev, fo->opt_fs);
9638494Sobrien
9738494Sobrien  /*
9838494Sobrien   * Determine magic cookie to put in mtab
9938494Sobrien   */
10038494Sobrien  return strdup(fo->opt_dev);
10138494Sobrien}
10238494Sobrien
10338494Sobrien
10438494Sobrienstatic int
105174294Sobrienmount_cdfs(char *mntdir, char *fs_name, char *opts, int on_autofs)
10638494Sobrien{
10738494Sobrien  cdfs_args_t cdfs_args;
10838494Sobrien  mntent_t mnt;
109174294Sobrien  int genflags, cdfs_flags, retval;
11038494Sobrien
11138494Sobrien  /*
11238494Sobrien   * Figure out the name of the file system type.
11338494Sobrien   */
11438494Sobrien  MTYPE_TYPE type = MOUNT_TYPE_CDFS;
11538494Sobrien
11638494Sobrien  memset((voidp) &cdfs_args, 0, sizeof(cdfs_args)); /* Paranoid */
11738494Sobrien  cdfs_flags = 0;
11838494Sobrien
11938494Sobrien  /*
12038494Sobrien   * Fill in the mount structure
12138494Sobrien   */
12238494Sobrien  memset((voidp) &mnt, 0, sizeof(mnt));
123174294Sobrien  mnt.mnt_dir = mntdir;
12438494Sobrien  mnt.mnt_fsname = fs_name;
12538494Sobrien  mnt.mnt_type = MNTTAB_TYPE_CDFS;
12638494Sobrien  mnt.mnt_opts = opts;
12738494Sobrien
12838494Sobrien#if defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM)
129174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_DEFPERM))
13038494Sobrien# ifdef MNT2_CDFS_OPT_DEFPERM
13138494Sobrien    cdfs_flags |= MNT2_CDFS_OPT_DEFPERM;
13238494Sobrien# else /* not MNT2_CDFS_OPT_DEFPERM */
13338494Sobrien    cdfs_flags &= ~MNT2_CDFS_OPT_NODEFPERM;
13438494Sobrien# endif /* not MNT2_CDFS_OPT_DEFPERM */
13538494Sobrien#endif /* defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM) */
13638494Sobrien
13738494Sobrien#if defined(MNT2_CDFS_OPT_NODEFPERM) && defined(MNTTAB_OPT_NODEFPERM)
138174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_NODEFPERM))
13938494Sobrien    cdfs_flags |= MNT2_CDFS_OPT_NODEFPERM;
14038494Sobrien#endif /* MNTTAB_OPT_NODEFPERM */
14138494Sobrien
14238494Sobrien#if defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION)
143174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOVERSION))
14438494Sobrien    cdfs_flags |= MNT2_CDFS_OPT_NOVERSION;
14538494Sobrien#endif /* defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION) */
14638494Sobrien
14738494Sobrien#if defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP)
148174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_RRIP))
14938494Sobrien    cdfs_flags |= MNT2_CDFS_OPT_RRIP;
15038494Sobrien#endif /* defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP) */
15151292Sobrien#if defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP)
152174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_NORRIP))
15351292Sobrien    cdfs_flags |= MNT2_CDFS_OPT_NORRIP;
15451292Sobrien#endif /* defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP) */
15538494Sobrien
15651292Sobrien#if defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS)
157174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_GENS))
15851292Sobrien    cdfs_flags |= MNT2_CDFS_OPT_GENS;
15951292Sobrien#endif /* defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS) */
16051292Sobrien#if defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT)
161174294Sobrien  if (amu_hasmntopt(&mnt, MNTTAB_OPT_EXTATT))
16251292Sobrien    cdfs_flags |= MNT2_CDFS_OPT_EXTATT;
16351292Sobrien#endif /* defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT) */
16451292Sobrien
16538494Sobrien  genflags = compute_mount_flags(&mnt);
166174294Sobrien#ifdef HAVE_FS_AUTOFS
167174294Sobrien  if (on_autofs)
168174294Sobrien    genflags |= autofs_compute_mount_flags(&mnt);
169174294Sobrien#endif /* HAVE_FS_AUTOFS */
17038494Sobrien
171119679Smbr#ifdef HAVE_CDFS_ARGS_T_FLAGS
17238494Sobrien  cdfs_args.flags = cdfs_flags;
173119679Smbr#endif /* HAVE_CDFS_ARGS_T_FLAGS */
17438494Sobrien
175119679Smbr#ifdef HAVE_CDFS_ARGS_T_ISO_FLAGS
17638494Sobrien  cdfs_args.iso_flags = genflags | cdfs_flags;
177119679Smbr#endif /* HAVE_CDFS_ARGS_T_ISO_FLAGS */
17838494Sobrien
179119679Smbr#ifdef HAVE_CDFS_ARGS_T_ISO_PGTHRESH
18038494Sobrien  cdfs_args.iso_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
181119679Smbr#endif /* HAVE_CDFS_ARGS_T_ISO_PGTHRESH */
18238494Sobrien
183119679Smbr#ifdef HAVE_CDFS_ARGS_T_NORRIP
18438494Sobrien  /* XXX: need to provide norrip mount opt */
18538494Sobrien  cdfs_args.norrip = 0;		/* use Rock-Ridge Protocol extensions */
186119679Smbr#endif /* HAVE_CDFS_ARGS_T_NORRIP */
18738494Sobrien
188119679Smbr#ifdef HAVE_CDFS_ARGS_T_SSECTOR
18938494Sobrien  /* XXX: need to provide ssector mount option */
19038494Sobrien  cdfs_args.ssector = 0;	/* use 1st session on disk */
191119679Smbr#endif /* HAVE_CDFS_ARGS_T_SSECTOR */
19238494Sobrien
193174294Sobrien#ifdef HAVE_CDFS_ARGS_T_FSPEC
194174294Sobrien  cdfs_args.fspec = fs_name;
195174294Sobrien#endif /* HAVE_CDFS_ARGS_T_FSPEC */
196174294Sobrien
19738494Sobrien  /*
19838494Sobrien   * Call generic mount routine
19938494Sobrien   */
200174294Sobrien  retval = mount_fs(&mnt, genflags, (caddr_t) &cdfs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
201174294Sobrien
202174294Sobrien  return retval;
20338494Sobrien}
20438494Sobrien
20538494Sobrien
20638494Sobrienstatic int
207174294Sobriencdfs_mount(am_node *am, mntfs *mf)
20838494Sobrien{
209174294Sobrien  int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
21038494Sobrien  int error;
21138494Sobrien
212174294Sobrien  error = mount_cdfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
21338494Sobrien  if (error) {
21438494Sobrien    errno = error;
21538494Sobrien    plog(XLOG_ERROR, "mount_cdfs: %m");
21638494Sobrien    return error;
21738494Sobrien  }
21838494Sobrien  return 0;
21938494Sobrien}
22038494Sobrien
22138494Sobrien
22238494Sobrienstatic int
223174294Sobriencdfs_umount(am_node *am, mntfs *mf)
22438494Sobrien{
225174294Sobrien  int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
226174294Sobrien
227174294Sobrien  return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);
22838494Sobrien}
229