Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / am-utils / dist / amd / ops_ufs.c
blob2b77500a60870a0d57683ca31ab34eb4f4a787bb
1 /* $NetBSD$ */
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_ufs.c
47 * UN*X 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 *ufs_match(am_opts *fo);
58 static int ufs_mount(am_node *am, mntfs *mf);
59 static int ufs_umount(am_node *am, mntfs *mf);
62 * Ops structure
64 am_ops ufs_ops =
66 #ifndef __NetBSD__
67 "ufs",
68 #else
69 "ffs",
70 #endif
71 ufs_match,
72 0, /* ufs_init */
73 ufs_mount,
74 ufs_umount,
75 amfs_error_lookup_child,
76 amfs_error_mount_child,
77 amfs_error_readdir,
78 0, /* ufs_readlink */
79 0, /* ufs_mounted */
80 0, /* ufs_umounted */
81 amfs_generic_find_srvr,
82 0, /* ufs_get_wchan */
83 FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
84 #ifdef HAVE_FS_AUTOFS
85 AUTOFS_UFS_FS_FLAGS,
86 #endif /* HAVE_FS_AUTOFS */
91 * UFS needs local filesystem and device.
93 static char *
94 ufs_match(am_opts *fo)
97 if (!fo->opt_dev) {
98 plog(XLOG_USER, "ufs: no device specified");
99 return 0;
102 dlog("UFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs);
105 * Determine magic cookie to put in mtab
107 return strdup(fo->opt_dev);
111 static int
112 mount_ufs(char *mntdir, char *fs_name, char *opts, int on_autofs)
114 ufs_args_t ufs_args;
115 mntent_t mnt;
116 int genflags;
119 * Figure out the name of the file system type.
121 MTYPE_TYPE type = MOUNT_TYPE_UFS;
123 memset((voidp) &ufs_args, 0, sizeof(ufs_args)); /* Paranoid */
126 * Fill in the mount structure
128 memset((voidp) &mnt, 0, sizeof(mnt));
129 mnt.mnt_dir = mntdir;
130 mnt.mnt_fsname = fs_name;
131 mnt.mnt_type = MNTTAB_TYPE_UFS;
132 mnt.mnt_opts = opts;
134 genflags = compute_mount_flags(&mnt);
135 #ifdef HAVE_FS_AUTOFS
136 if (on_autofs)
137 genflags |= autofs_compute_mount_flags(&mnt);
138 #endif /* HAVE_FS_AUTOFS */
140 #ifdef HAVE_UFS_ARGS_T_FLAGS
141 ufs_args.flags = genflags; /* XXX: is this correct? */
142 #endif /* HAVE_UFS_ARGS_T_FLAGS */
144 #ifdef HAVE_UFS_ARGS_T_UFS_FLAGS
145 ufs_args.ufs_flags = genflags;
146 #endif /* HAVE_UFS_ARGS_T_UFS_FLAGS */
148 #ifdef HAVE_UFS_ARGS_T_FSPEC
149 ufs_args.fspec = fs_name;
150 #endif /* HAVE_UFS_ARGS_T_FSPEC */
152 #ifdef HAVE_UFS_ARGS_T_UFS_PGTHRESH
153 ufs_args.ufs_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
154 #endif /* HAVE_UFS_ARGS_T_UFS_PGTHRESH */
157 * Call generic mount routine
159 return mount_fs(&mnt, genflags, (caddr_t) &ufs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
163 static int
164 ufs_mount(am_node *am, mntfs *mf)
166 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
167 int error;
169 error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
170 if (error) {
171 errno = error;
172 plog(XLOG_ERROR, "mount_ufs: %m");
173 return error;
176 return 0;
180 static int
181 ufs_umount(am_node *am, mntfs *mf)
183 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
185 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);