ops_lofs.c revision 174295
11553Srgrimes/*
21553Srgrimes * Copyright (c) 1997-2006 Erez Zadok
31553Srgrimes * Copyright (c) 1990 Jan-Simon Pendry
41553Srgrimes * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
51553Srgrimes * Copyright (c) 1990 The Regents of the University of California.
61553Srgrimes * All rights reserved.
71553Srgrimes *
81553Srgrimes * This code is derived from software contributed to Berkeley by
91553Srgrimes * Jan-Simon Pendry at Imperial College, London.
101553Srgrimes *
111553Srgrimes * Redistribution and use in source and binary forms, with or without
121553Srgrimes * modification, are permitted provided that the following conditions
131553Srgrimes * are met:
141553Srgrimes * 1. Redistributions of source code must retain the above copyright
151553Srgrimes *    notice, this list of conditions and the following disclaimer.
161553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
171553Srgrimes *    notice, this list of conditions and the following disclaimer in the
181553Srgrimes *    documentation and/or other materials provided with the distribution.
191553Srgrimes * 3. All advertising materials mentioning features or use of this software
201553Srgrimes *    must display the following acknowledgment:
211553Srgrimes *      This product includes software developed by the University of
221553Srgrimes *      California, Berkeley and its contributors.
231553Srgrimes * 4. Neither the name of the University nor the names of its contributors
241553Srgrimes *    may be used to endorse or promote products derived from this software
251553Srgrimes *    without specific prior written permission.
261553Srgrimes *
271553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
281553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
291553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
301553Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3130380Scharnier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
351553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36117278Scharnier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
371553Srgrimes * SUCH DAMAGE.
381553Srgrimes *
39117278Scharnier *
4030380Scharnier * File: am-utils/amd/ops_lofs.c
411553Srgrimes *
42117278Scharnier */
43117278Scharnier
44117278Scharnier/*
451553Srgrimes * Loopback file system
461553Srgrimes */
471553Srgrimes
481553Srgrimes#ifdef HAVE_CONFIG_H
491553Srgrimes# include <config.h>
501553Srgrimes#endif /* HAVE_CONFIG_H */
511553Srgrimes#include <am_defs.h>
521553Srgrimes#include <amd.h>
531553Srgrimes
541553Srgrimes/* forward definitions */
551553Srgrimesstatic char *lofs_match(am_opts *fo);
5670284Siedowsestatic int lofs_mount(am_node *am, mntfs *mf);
571553Srgrimesstatic int lofs_umount(am_node *am, mntfs *mf);
581553Srgrimes
591553Srgrimes/*
6030380Scharnier * Ops structure
611553Srgrimes */
621553Srgrimesam_ops lofs_ops =
631553Srgrimes{
641553Srgrimes  "lofs",
651553Srgrimes  lofs_match,
661553Srgrimes  0,				/* lofs_init */
671553Srgrimes  lofs_mount,
681553Srgrimes  lofs_umount,
6999825Salfred  amfs_error_lookup_child,
701553Srgrimes  amfs_error_mount_child,
71202206Sed  amfs_error_readdir,
7217829Spst  0,				/* lofs_readlink */
7318092Speter  0,				/* lofs_mounted */
741553Srgrimes  0,				/* lofs_umounted */
751553Srgrimes  amfs_generic_find_srvr,
7610087Sjkh  0,				/* lofs_get_wchan */
7710087Sjkh  FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
7810087Sjkh#ifdef HAVE_FS_AUTOFS
7910087Sjkh  AUTOFS_LOFS_FS_FLAGS,
8010087Sjkh#endif /* HAVE_FS_AUTOFS */
8110087Sjkh};
8210087Sjkh
8310087Sjkh
8410087Sjkh/*
8510087Sjkh * LOFS needs remote filesystem.
8610087Sjkh */
8710087Sjkhstatic char *
8810087Sjkhlofs_match(am_opts *fo)
8910087Sjkh{
9010087Sjkh  if (!fo->opt_rfs) {
9110087Sjkh    plog(XLOG_USER, "lofs: no source filesystem specified");
9210087Sjkh    return 0;
9310087Sjkh  }
9410087Sjkh  dlog("LOFS: mounting fs \"%s\" on \"%s\"",
9510087Sjkh       fo->opt_rfs, fo->opt_fs);
9610087Sjkh
9710087Sjkh  /*
9810087Sjkh   * Determine magic cookie to put in mtab
9910087Sjkh   */
10010087Sjkh  return strdup(fo->opt_rfs);
10110087Sjkh}
10210087Sjkh
10310087Sjkh
10410087Sjkhint
10517832Spstmount_lofs(char *mntdir, char *fs_name, char *opts, int on_autofs)
10617829Spst{
10717829Spst  mntent_t mnt;
10810087Sjkh  int flags;
10910087Sjkh
11010087Sjkh  /*
11110087Sjkh   * Figure out the name of the file system type.
11210087Sjkh   */
11310087Sjkh  MTYPE_TYPE type = MOUNT_TYPE_LOFS;
11410087Sjkh
11510087Sjkh  /*
11610087Sjkh   * Fill in the mount structure
11741895Sdes   */
11842508Ssteve  memset((voidp) &mnt, 0, sizeof(mnt));
11947963Sbrian  mnt.mnt_dir = mntdir;
12010087Sjkh  mnt.mnt_fsname = fs_name;
12110087Sjkh  mnt.mnt_type = MNTTAB_TYPE_LOFS;
12299825Salfred  mnt.mnt_opts = opts;
12399825Salfred
12410087Sjkh  flags = compute_mount_flags(&mnt);
12510087Sjkh#ifdef HAVE_FS_AUTOFS
1261553Srgrimes  if (on_autofs)
1271553Srgrimes    flags |= autofs_compute_mount_flags(&mnt);
1281553Srgrimes#endif /* HAVE_FS_AUTOFS */
1291553Srgrimes
1301553Srgrimes  /*
1311553Srgrimes   * Call generic mount routine
1321553Srgrimes   */
1331553Srgrimes  return mount_fs(&mnt, flags, NULL, 0, type, 0, NULL, mnttab_file_name, on_autofs);
1341553Srgrimes}
1351553Srgrimes
1361553Srgrimes
1371553Srgrimesstatic int
1381553Srgrimeslofs_mount(am_node *am, mntfs *mf)
1391553Srgrimes{
1401553Srgrimes  int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
1411553Srgrimes  int error;
1421553Srgrimes
1431553Srgrimes  error = mount_lofs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
1441553Srgrimes  if (error) {
1451553Srgrimes    errno = error;
1461553Srgrimes    plog(XLOG_ERROR, "mount_lofs: %m");
1471553Srgrimes    return error;
1481553Srgrimes  }
149201060Sed  return 0;
1501553Srgrimes}
15199825Salfred
1521553Srgrimes
15399825Salfredstatic int
15499825Salfredlofs_umount(am_node *am, mntfs *mf)
15599825Salfred{
15699825Salfred  int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
15799825Salfred
15899825Salfred  return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);
15999825Salfred}
16099825Salfred