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