Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / am-utils / dist / amd / ops_cdfs.c
blobe66c5dfeb7af75fc955d9298e034488d9768b43e
1 /* $NetBSD: ops_cdfs.c,v 1.1.1.2 2009/03/20 20:26:49 christos Exp $ */
3 /*
4 * Copyright (c) 1997-2009 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.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
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. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
42 * File: am-utils/amd/ops_cdfs.c
47 * High Sierra (CD-ROM) file system
50 #ifdef HAVE_CONFIG_H
51 # include <config.h>
52 #endif /* HAVE_CONFIG_H */
53 #include <am_defs.h>
54 #include <amd.h>
56 /* forward declarations */
57 static char *cdfs_match(am_opts *fo);
58 static int cdfs_mount(am_node *am, mntfs *mf);
59 static int cdfs_umount(am_node *am, mntfs *mf);
62 * Ops structure
64 am_ops cdfs_ops =
66 "cdfs",
67 cdfs_match,
68 0, /* cdfs_init */
69 cdfs_mount,
70 cdfs_umount,
71 amfs_error_lookup_child,
72 amfs_error_mount_child,
73 amfs_error_readdir,
74 0, /* cdfs_readlink */
75 0, /* cdfs_mounted */
76 0, /* cdfs_umounted */
77 amfs_generic_find_srvr,
78 0, /* cdfs_get_wchan */
79 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
80 #ifdef HAVE_FS_AUTOFS
81 AUTOFS_CDFS_FS_FLAGS,
82 #endif /* HAVE_FS_AUTOFS */
87 * CDFS needs remote filesystem.
89 static char *
90 cdfs_match(am_opts *fo)
92 if (!fo->opt_dev) {
93 plog(XLOG_USER, "cdfs: no source device specified");
94 return 0;
96 dlog("CDFS: mounting device \"%s\" on \"%s\"",
97 fo->opt_dev, fo->opt_fs);
100 * Determine magic cookie to put in mtab
102 return strdup(fo->opt_dev);
106 static int
107 mount_cdfs(char *mntdir, char *fs_name, char *opts, int on_autofs)
109 cdfs_args_t cdfs_args;
110 mntent_t mnt;
111 int genflags, cdfs_flags, retval;
114 * Figure out the name of the file system type.
116 MTYPE_TYPE type = MOUNT_TYPE_CDFS;
118 memset((voidp) &cdfs_args, 0, sizeof(cdfs_args)); /* Paranoid */
119 cdfs_flags = 0;
122 * Fill in the mount structure
124 memset((voidp) &mnt, 0, sizeof(mnt));
125 mnt.mnt_dir = mntdir;
126 mnt.mnt_fsname = fs_name;
127 mnt.mnt_type = MNTTAB_TYPE_CDFS;
128 mnt.mnt_opts = opts;
130 #if defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM)
131 if (amu_hasmntopt(&mnt, MNTTAB_OPT_DEFPERM))
132 # ifdef MNT2_CDFS_OPT_DEFPERM
133 cdfs_flags |= MNT2_CDFS_OPT_DEFPERM;
134 # else /* not MNT2_CDFS_OPT_DEFPERM */
135 cdfs_flags &= ~MNT2_CDFS_OPT_NODEFPERM;
136 # endif /* not MNT2_CDFS_OPT_DEFPERM */
137 #endif /* defined(MNT2_CDFS_OPT_DEFPERM) && defined(MNTTAB_OPT_DEFPERM) */
139 #if defined(MNT2_CDFS_OPT_NODEFPERM) && defined(MNTTAB_OPT_NODEFPERM)
140 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NODEFPERM))
141 cdfs_flags |= MNT2_CDFS_OPT_NODEFPERM;
142 #endif /* MNTTAB_OPT_NODEFPERM */
144 #if defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION)
145 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOVERSION))
146 cdfs_flags |= MNT2_CDFS_OPT_NOVERSION;
147 #endif /* defined(MNT2_CDFS_OPT_NOVERSION) && defined(MNTTAB_OPT_NOVERSION) */
149 #if defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP)
150 if (amu_hasmntopt(&mnt, MNTTAB_OPT_RRIP))
151 cdfs_flags |= MNT2_CDFS_OPT_RRIP;
152 #endif /* defined(MNT2_CDFS_OPT_RRIP) && defined(MNTTAB_OPT_RRIP) */
154 #if defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP)
155 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NORRIP))
156 cdfs_flags |= MNT2_CDFS_OPT_NORRIP;
157 #endif /* defined(MNT2_CDFS_OPT_NORRIP) && defined(MNTTAB_OPT_NORRIP) */
159 #if defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS)
160 if (amu_hasmntopt(&mnt, MNTTAB_OPT_GENS))
161 cdfs_flags |= MNT2_CDFS_OPT_GENS;
162 #endif /* defined(MNT2_CDFS_OPT_GENS) && defined(MNTTAB_OPT_GENS) */
164 #if defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT)
165 if (amu_hasmntopt(&mnt, MNTTAB_OPT_EXTATT))
166 cdfs_flags |= MNT2_CDFS_OPT_EXTATT;
167 #endif /* defined(MNT2_CDFS_OPT_EXTATT) && defined(MNTTAB_OPT_EXTATT) */
169 #if defined(MNT2_CDFS_OPT_NOCASETRANS) && defined(MNTTAB_OPT_NOCASETRANS)
170 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOCASETRANS))
171 cdfs_flags |= MNT2_CDFS_OPT_NOCASETRANS;
172 #endif /* defined(MNT2_CDFS_OPT_NOCASETRANS) && defined(MNTTAB_OPT_NOCASETRANS) */
174 #if defined(MNT2_CDFS_OPT_NOJOLIET) && defined(MNTTAB_OPT_NOJOLIET)
175 if (amu_hasmntopt(&mnt, MNTTAB_OPT_NOJOLIET))
176 cdfs_flags |= MNT2_CDFS_OPT_NOJOLIET;
177 #endif /* defined(MNT2_CDFS_OPT_NOJOLIET) && defined(MNTTAB_OPT_NOJOLIET) */
179 #if defined(MNT2_CDFS_OPT_RRCASEINS) && defined(MNTTAB_OPT_RRCASEINS)
180 if (amu_hasmntopt(&mnt, MNTTAB_OPT_RRCASEINS))
181 cdfs_flags |= MNT2_CDFS_OPT_RRCASEINS;
182 #endif /* defined(MNT2_CDFS_OPT_RRCASEINS) && defined(MNTTAB_OPT_RRCASEINS) */
184 genflags = compute_mount_flags(&mnt);
185 #ifdef HAVE_FS_AUTOFS
186 if (on_autofs)
187 genflags |= autofs_compute_mount_flags(&mnt);
188 #endif /* HAVE_FS_AUTOFS */
190 #ifdef HAVE_CDFS_ARGS_T_FLAGS
191 cdfs_args.flags = cdfs_flags;
192 #endif /* HAVE_CDFS_ARGS_T_FLAGS */
194 #ifdef HAVE_CDFS_ARGS_T_ISO_FLAGS
195 cdfs_args.iso_flags = genflags | cdfs_flags;
196 #endif /* HAVE_CDFS_ARGS_T_ISO_FLAGS */
198 #ifdef HAVE_CDFS_ARGS_T_ISO_PGTHRESH
199 cdfs_args.iso_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
200 #endif /* HAVE_CDFS_ARGS_T_ISO_PGTHRESH */
202 #ifdef HAVE_CDFS_ARGS_T_NORRIP
203 /* XXX: need to provide norrip mount opt */
204 cdfs_args.norrip = 0; /* use Rock-Ridge Protocol extensions */
205 #endif /* HAVE_CDFS_ARGS_T_NORRIP */
207 #ifdef HAVE_CDFS_ARGS_T_SSECTOR
208 /* XXX: need to provide ssector mount option */
209 cdfs_args.ssector = 0; /* use 1st session on disk */
210 #endif /* HAVE_CDFS_ARGS_T_SSECTOR */
212 #ifdef HAVE_CDFS_ARGS_T_FSPEC
213 cdfs_args.fspec = fs_name;
214 #endif /* HAVE_CDFS_ARGS_T_FSPEC */
217 * Call generic mount routine
219 retval = mount_fs(&mnt, genflags, (caddr_t) &cdfs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
221 return retval;
225 static int
226 cdfs_mount(am_node *am, mntfs *mf)
228 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
229 int error;
231 error = mount_cdfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
232 if (error) {
233 errno = error;
234 plog(XLOG_ERROR, "mount_cdfs: %m");
235 return error;
237 return 0;
241 static int
242 cdfs_umount(am_node *am, mntfs *mf)
244 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
246 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);