138494Sobrien/*
2310490Scy * Copyright (c) 1997-2014 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.
19310490Scy * 3. Neither the name of the University nor the names of its contributors
2038494Sobrien *    may be used to endorse or promote products derived from this software
2138494Sobrien *    without specific prior written permission.
2238494Sobrien *
2338494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2438494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2538494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2638494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2738494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2838494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2938494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3038494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3138494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3238494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3338494Sobrien * SUCH DAMAGE.
3438494Sobrien *
3538494Sobrien *
36174294Sobrien * File: am-utils/amd/ops_ufs.c
3738494Sobrien *
3838494Sobrien */
3938494Sobrien
4038494Sobrien/*
4138494Sobrien * UN*X file system
4238494Sobrien */
4338494Sobrien
4438494Sobrien#ifdef HAVE_CONFIG_H
4538494Sobrien# include <config.h>
4638494Sobrien#endif /* HAVE_CONFIG_H */
4738494Sobrien#include <am_defs.h>
4838494Sobrien#include <amd.h>
4938494Sobrien
5038494Sobrien/* forward declarations */
5138494Sobrienstatic char *ufs_match(am_opts *fo);
52174294Sobrienstatic int ufs_mount(am_node *am, mntfs *mf);
53174294Sobrienstatic int ufs_umount(am_node *am, mntfs *mf);
5438494Sobrien
5538494Sobrien/*
5638494Sobrien * Ops structure
5738494Sobrien */
5838494Sobrienam_ops ufs_ops =
5938494Sobrien{
60310490Scy#ifndef __NetBSD__
6138494Sobrien  "ufs",
62310490Scy#else
63310490Scy  "ffs",
64310490Scy#endif
6538494Sobrien  ufs_match,
6638494Sobrien  0,				/* ufs_init */
67174294Sobrien  ufs_mount,
68174294Sobrien  ufs_umount,
69174294Sobrien  amfs_error_lookup_child,
70174294Sobrien  amfs_error_mount_child,
7138494Sobrien  amfs_error_readdir,
7238494Sobrien  0,				/* ufs_readlink */
7338494Sobrien  0,				/* ufs_mounted */
7438494Sobrien  0,				/* ufs_umounted */
75174294Sobrien  amfs_generic_find_srvr,
76174294Sobrien  0,				/* ufs_get_wchan */
77174294Sobrien  FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
78174294Sobrien#ifdef HAVE_FS_AUTOFS
79174294Sobrien  AUTOFS_UFS_FS_FLAGS,
80174294Sobrien#endif /* HAVE_FS_AUTOFS */
8138494Sobrien};
8238494Sobrien
8338494Sobrien
8438494Sobrien/*
8538494Sobrien * UFS needs local filesystem and device.
8638494Sobrien */
8738494Sobrienstatic char *
8838494Sobrienufs_match(am_opts *fo)
8938494Sobrien{
9038494Sobrien
9138494Sobrien  if (!fo->opt_dev) {
9238494Sobrien    plog(XLOG_USER, "ufs: no device specified");
9338494Sobrien    return 0;
9438494Sobrien  }
9538494Sobrien
9638494Sobrien  dlog("UFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs);
9738494Sobrien
9838494Sobrien  /*
9938494Sobrien   * Determine magic cookie to put in mtab
10038494Sobrien   */
101310490Scy  return xstrdup(fo->opt_dev);
10238494Sobrien}
10338494Sobrien
10438494Sobrien
10538494Sobrienstatic int
106174294Sobrienmount_ufs(char *mntdir, char *fs_name, char *opts, int on_autofs)
10738494Sobrien{
10838494Sobrien  ufs_args_t ufs_args;
10938494Sobrien  mntent_t mnt;
11038494Sobrien  int genflags;
11138494Sobrien
11238494Sobrien  /*
11338494Sobrien   * Figure out the name of the file system type.
11438494Sobrien   */
11538494Sobrien  MTYPE_TYPE type = MOUNT_TYPE_UFS;
11638494Sobrien
11738494Sobrien  memset((voidp) &ufs_args, 0, sizeof(ufs_args)); /* Paranoid */
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_UFS;
12638494Sobrien  mnt.mnt_opts = opts;
12738494Sobrien
12838494Sobrien  genflags = compute_mount_flags(&mnt);
129174294Sobrien#ifdef HAVE_FS_AUTOFS
130174294Sobrien  if (on_autofs)
131174294Sobrien    genflags |= autofs_compute_mount_flags(&mnt);
132174294Sobrien#endif /* HAVE_FS_AUTOFS */
13338494Sobrien
134119679Smbr#ifdef HAVE_UFS_ARGS_T_FLAGS
13538494Sobrien  ufs_args.flags = genflags;	/* XXX: is this correct? */
136119679Smbr#endif /* HAVE_UFS_ARGS_T_FLAGS */
13738494Sobrien
138119679Smbr#ifdef HAVE_UFS_ARGS_T_UFS_FLAGS
13951292Sobrien  ufs_args.ufs_flags = genflags;
140119679Smbr#endif /* HAVE_UFS_ARGS_T_UFS_FLAGS */
14138494Sobrien
142119679Smbr#ifdef HAVE_UFS_ARGS_T_FSPEC
14338494Sobrien  ufs_args.fspec = fs_name;
144119679Smbr#endif /* HAVE_UFS_ARGS_T_FSPEC */
14538494Sobrien
146119679Smbr#ifdef HAVE_UFS_ARGS_T_UFS_PGTHRESH
14738494Sobrien  ufs_args.ufs_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
148119679Smbr#endif /* HAVE_UFS_ARGS_T_UFS_PGTHRESH */
14938494Sobrien
15038494Sobrien  /*
15138494Sobrien   * Call generic mount routine
15238494Sobrien   */
153174294Sobrien  return mount_fs(&mnt, genflags, (caddr_t) &ufs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
15438494Sobrien}
15538494Sobrien
15638494Sobrien
15738494Sobrienstatic int
158174294Sobrienufs_mount(am_node *am, mntfs *mf)
15938494Sobrien{
160174294Sobrien  int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
16138494Sobrien  int error;
16238494Sobrien
163174294Sobrien  error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
16438494Sobrien  if (error) {
16538494Sobrien    errno = error;
16638494Sobrien    plog(XLOG_ERROR, "mount_ufs: %m");
16738494Sobrien    return error;
16838494Sobrien  }
16938494Sobrien
17038494Sobrien  return 0;
17138494Sobrien}
17238494Sobrien
17338494Sobrien
17438494Sobrienstatic int
175174294Sobrienufs_umount(am_node *am, mntfs *mf)
17638494Sobrien{
177174294Sobrien  int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
178174294Sobrien
179174294Sobrien  return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);
18038494Sobrien}
181