1*8bae5d40Schristos /* $NetBSD: ops_ufs.c,v 1.1.1.3 2015/01/17 16:34:15 christos Exp $ */
2a53f50b9Schristos
3a53f50b9Schristos /*
4*8bae5d40Schristos * 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*8bae5d40Schristos * 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_ufs.c
39a53f50b9Schristos *
40a53f50b9Schristos */
41a53f50b9Schristos
42a53f50b9Schristos /*
43a53f50b9Schristos * UN*X 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 *ufs_match(am_opts *fo);
54a53f50b9Schristos static int ufs_mount(am_node *am, mntfs *mf);
55a53f50b9Schristos static int ufs_umount(am_node *am, mntfs *mf);
56a53f50b9Schristos
57a53f50b9Schristos /*
58a53f50b9Schristos * Ops structure
59a53f50b9Schristos */
60a53f50b9Schristos am_ops ufs_ops =
61a53f50b9Schristos {
62a53f50b9Schristos #ifndef __NetBSD__
63a53f50b9Schristos "ufs",
64a53f50b9Schristos #else
65a53f50b9Schristos "ffs",
66a53f50b9Schristos #endif
67a53f50b9Schristos ufs_match,
68a53f50b9Schristos 0, /* ufs_init */
69a53f50b9Schristos ufs_mount,
70a53f50b9Schristos ufs_umount,
71a53f50b9Schristos amfs_error_lookup_child,
72a53f50b9Schristos amfs_error_mount_child,
73a53f50b9Schristos amfs_error_readdir,
74a53f50b9Schristos 0, /* ufs_readlink */
75a53f50b9Schristos 0, /* ufs_mounted */
76a53f50b9Schristos 0, /* ufs_umounted */
77a53f50b9Schristos amfs_generic_find_srvr,
78a53f50b9Schristos 0, /* ufs_get_wchan */
79a53f50b9Schristos FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
80a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
81a53f50b9Schristos AUTOFS_UFS_FS_FLAGS,
82a53f50b9Schristos #endif /* HAVE_FS_AUTOFS */
83a53f50b9Schristos };
84a53f50b9Schristos
85a53f50b9Schristos
86a53f50b9Schristos /*
87a53f50b9Schristos * UFS needs local filesystem and device.
88a53f50b9Schristos */
89a53f50b9Schristos static char *
ufs_match(am_opts * fo)90a53f50b9Schristos ufs_match(am_opts *fo)
91a53f50b9Schristos {
92a53f50b9Schristos
93a53f50b9Schristos if (!fo->opt_dev) {
94a53f50b9Schristos plog(XLOG_USER, "ufs: no device specified");
95a53f50b9Schristos return 0;
96a53f50b9Schristos }
97a53f50b9Schristos
98a53f50b9Schristos dlog("UFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs);
99a53f50b9Schristos
100a53f50b9Schristos /*
101a53f50b9Schristos * Determine magic cookie to put in mtab
102a53f50b9Schristos */
103*8bae5d40Schristos return xstrdup(fo->opt_dev);
104a53f50b9Schristos }
105a53f50b9Schristos
106a53f50b9Schristos
107a53f50b9Schristos static int
mount_ufs(char * mntdir,char * fs_name,char * opts,int on_autofs)108a53f50b9Schristos mount_ufs(char *mntdir, char *fs_name, char *opts, int on_autofs)
109a53f50b9Schristos {
110a53f50b9Schristos ufs_args_t ufs_args;
111a53f50b9Schristos mntent_t mnt;
112a53f50b9Schristos int genflags;
113a53f50b9Schristos
114a53f50b9Schristos /*
115a53f50b9Schristos * Figure out the name of the file system type.
116a53f50b9Schristos */
117a53f50b9Schristos MTYPE_TYPE type = MOUNT_TYPE_UFS;
118a53f50b9Schristos
119a53f50b9Schristos memset((voidp) &ufs_args, 0, sizeof(ufs_args)); /* Paranoid */
120a53f50b9Schristos
121a53f50b9Schristos /*
122a53f50b9Schristos * Fill in the mount structure
123a53f50b9Schristos */
124a53f50b9Schristos memset((voidp) &mnt, 0, sizeof(mnt));
125a53f50b9Schristos mnt.mnt_dir = mntdir;
126a53f50b9Schristos mnt.mnt_fsname = fs_name;
127a53f50b9Schristos mnt.mnt_type = MNTTAB_TYPE_UFS;
128a53f50b9Schristos mnt.mnt_opts = opts;
129a53f50b9Schristos
130a53f50b9Schristos genflags = compute_mount_flags(&mnt);
131a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
132a53f50b9Schristos if (on_autofs)
133a53f50b9Schristos genflags |= autofs_compute_mount_flags(&mnt);
134a53f50b9Schristos #endif /* HAVE_FS_AUTOFS */
135a53f50b9Schristos
136a53f50b9Schristos #ifdef HAVE_UFS_ARGS_T_FLAGS
137a53f50b9Schristos ufs_args.flags = genflags; /* XXX: is this correct? */
138a53f50b9Schristos #endif /* HAVE_UFS_ARGS_T_FLAGS */
139a53f50b9Schristos
140a53f50b9Schristos #ifdef HAVE_UFS_ARGS_T_UFS_FLAGS
141a53f50b9Schristos ufs_args.ufs_flags = genflags;
142a53f50b9Schristos #endif /* HAVE_UFS_ARGS_T_UFS_FLAGS */
143a53f50b9Schristos
144a53f50b9Schristos #ifdef HAVE_UFS_ARGS_T_FSPEC
145a53f50b9Schristos ufs_args.fspec = fs_name;
146a53f50b9Schristos #endif /* HAVE_UFS_ARGS_T_FSPEC */
147a53f50b9Schristos
148a53f50b9Schristos #ifdef HAVE_UFS_ARGS_T_UFS_PGTHRESH
149a53f50b9Schristos ufs_args.ufs_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
150a53f50b9Schristos #endif /* HAVE_UFS_ARGS_T_UFS_PGTHRESH */
151a53f50b9Schristos
152a53f50b9Schristos /*
153a53f50b9Schristos * Call generic mount routine
154a53f50b9Schristos */
155a53f50b9Schristos return mount_fs(&mnt, genflags, (caddr_t) &ufs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
156a53f50b9Schristos }
157a53f50b9Schristos
158a53f50b9Schristos
159a53f50b9Schristos static int
ufs_mount(am_node * am,mntfs * mf)160a53f50b9Schristos ufs_mount(am_node *am, mntfs *mf)
161a53f50b9Schristos {
162a53f50b9Schristos int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
163a53f50b9Schristos int error;
164a53f50b9Schristos
165a53f50b9Schristos error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
166a53f50b9Schristos if (error) {
167a53f50b9Schristos errno = error;
168a53f50b9Schristos plog(XLOG_ERROR, "mount_ufs: %m");
169a53f50b9Schristos return error;
170a53f50b9Schristos }
171a53f50b9Schristos
172a53f50b9Schristos return 0;
173a53f50b9Schristos }
174a53f50b9Schristos
175a53f50b9Schristos
176a53f50b9Schristos static int
ufs_umount(am_node * am,mntfs * mf)177a53f50b9Schristos ufs_umount(am_node *am, mntfs *mf)
178a53f50b9Schristos {
179a53f50b9Schristos int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
180a53f50b9Schristos
181a53f50b9Schristos return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);
182a53f50b9Schristos }
183