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/amfs_link.c
3738494Sobrien *
3838494Sobrien */
3938494Sobrien
4038494Sobrien/*
4138494Sobrien * Symbol-link 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
50174294Sobrien/* forward declarations */
51174294Sobrienstatic int amfs_link_mount(am_node *mp, mntfs *mf);
52174294Sobrienstatic int amfs_link_umount(am_node *mp, mntfs *mf);
5338494Sobrien
5438494Sobrien/*
5538494Sobrien * Ops structures
5638494Sobrien */
5738494Sobrienam_ops amfs_link_ops =
5838494Sobrien{
5938494Sobrien  "link",
6038494Sobrien  amfs_link_match,
6138494Sobrien  0,				/* amfs_link_init */
62174294Sobrien  amfs_link_mount,
63174294Sobrien  amfs_link_umount,
64174294Sobrien  amfs_error_lookup_child,
65174294Sobrien  amfs_error_mount_child,
6638494Sobrien  amfs_error_readdir,
6738494Sobrien  0,				/* amfs_link_readlink */
6838494Sobrien  0,				/* amfs_link_mounted */
6938494Sobrien  0,				/* amfs_link_umounted */
70174294Sobrien  amfs_generic_find_srvr,
71174294Sobrien  0,				/* nfs_fs_flags */
72174294Sobrien  0,				/* amfs_link_get_wchan */
73174294Sobrien#ifdef HAVE_FS_AUTOFS
74174294Sobrien  AUTOFS_LINK_FS_FLAGS,
75174294Sobrien#endif /* HAVE_FS_AUTOFS */
7638494Sobrien};
7738494Sobrien
7838494Sobrien
7938494Sobrien/*
8038494Sobrien * SFS needs a link.
8138494Sobrien */
8238494Sobrienchar *
8338494Sobrienamfs_link_match(am_opts *fo)
8438494Sobrien{
8538494Sobrien
8638494Sobrien  if (!fo->opt_fs) {
8738494Sobrien    plog(XLOG_USER, "link: no fs specified");
8838494Sobrien    return 0;
8938494Sobrien  }
9038494Sobrien
9138494Sobrien  /*
92174294Sobrien   * If the link target points to another mount point, then we could
93174294Sobrien   * end up with an unpleasant situation, where the link f/s simply
94174294Sobrien   * "assumes" the mntfs of that mount point.
9538494Sobrien   *
96174294Sobrien   * For example, if the link points to /usr, and /usr is a real ufs
97174294Sobrien   * filesystem, then the link f/s will use the inherited ufs mntfs,
98174294Sobrien   * and the end result will be that it will become unmountable.
9938494Sobrien   *
100174294Sobrien   * To prevent this, we use a hack: we prepend a dot ('.') to opt_fs if
101174294Sobrien   * its original value was an absolute path, so that it will never match
102174294Sobrien   * any other mntfs.
10338494Sobrien   *
104174294Sobrien   * XXX: a less hacky solution should be used...
10538494Sobrien   */
106174294Sobrien  if (fo->opt_fs[0] == '/') {
107174294Sobrien    char *link_hack = str3cat(NULL, ".", fo->opt_fs, "");
108310490Scy    if (fo->opt_sublink == NULL || fo->opt_sublink[0] == '\0')
109310490Scy      fo->opt_sublink = xstrdup(fo->opt_fs);
110174294Sobrien    XFREE(fo->opt_fs);
111174294Sobrien    fo->opt_fs = link_hack;
11238494Sobrien  }
11338494Sobrien
114310490Scy  return xstrdup(fo->opt_fs);
11538494Sobrien}
11638494Sobrien
11738494Sobrien
118174294Sobrienstatic int
119174294Sobrienamfs_link_mount(am_node *mp, mntfs *mf)
12038494Sobrien{
12138494Sobrien  return 0;
12238494Sobrien}
12338494Sobrien
12438494Sobrien
125174294Sobrienstatic int
126174294Sobrienamfs_link_umount(am_node *mp, mntfs *mf)
12738494Sobrien{
12838494Sobrien  return 0;
12938494Sobrien}
130