1*8bae5d40Schristos /* $NetBSD: amfs_link.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/amfs_link.c
39a53f50b9Schristos *
40a53f50b9Schristos */
41a53f50b9Schristos
42a53f50b9Schristos /*
43a53f50b9Schristos * Symbol-link 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 int amfs_link_mount(am_node *mp, mntfs *mf);
54a53f50b9Schristos static int amfs_link_umount(am_node *mp, mntfs *mf);
55a53f50b9Schristos
56a53f50b9Schristos /*
57a53f50b9Schristos * Ops structures
58a53f50b9Schristos */
59a53f50b9Schristos am_ops amfs_link_ops =
60a53f50b9Schristos {
61a53f50b9Schristos "link",
62a53f50b9Schristos amfs_link_match,
63a53f50b9Schristos 0, /* amfs_link_init */
64a53f50b9Schristos amfs_link_mount,
65a53f50b9Schristos amfs_link_umount,
66a53f50b9Schristos amfs_error_lookup_child,
67a53f50b9Schristos amfs_error_mount_child,
68a53f50b9Schristos amfs_error_readdir,
69a53f50b9Schristos 0, /* amfs_link_readlink */
70a53f50b9Schristos 0, /* amfs_link_mounted */
71a53f50b9Schristos 0, /* amfs_link_umounted */
72a53f50b9Schristos amfs_generic_find_srvr,
73a53f50b9Schristos 0, /* nfs_fs_flags */
74a53f50b9Schristos 0, /* amfs_link_get_wchan */
75a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
76a53f50b9Schristos AUTOFS_LINK_FS_FLAGS,
77a53f50b9Schristos #endif /* HAVE_FS_AUTOFS */
78a53f50b9Schristos };
79a53f50b9Schristos
80a53f50b9Schristos
81a53f50b9Schristos /*
82a53f50b9Schristos * SFS needs a link.
83a53f50b9Schristos */
84a53f50b9Schristos char *
amfs_link_match(am_opts * fo)85a53f50b9Schristos amfs_link_match(am_opts *fo)
86a53f50b9Schristos {
87a53f50b9Schristos
88a53f50b9Schristos if (!fo->opt_fs) {
89a53f50b9Schristos plog(XLOG_USER, "link: no fs specified");
90a53f50b9Schristos return 0;
91a53f50b9Schristos }
92a53f50b9Schristos
93a53f50b9Schristos /*
94a53f50b9Schristos * If the link target points to another mount point, then we could
95a53f50b9Schristos * end up with an unpleasant situation, where the link f/s simply
96a53f50b9Schristos * "assumes" the mntfs of that mount point.
97a53f50b9Schristos *
98a53f50b9Schristos * For example, if the link points to /usr, and /usr is a real ufs
99a53f50b9Schristos * filesystem, then the link f/s will use the inherited ufs mntfs,
100a53f50b9Schristos * and the end result will be that it will become unmountable.
101a53f50b9Schristos *
102a53f50b9Schristos * To prevent this, we use a hack: we prepend a dot ('.') to opt_fs if
103a53f50b9Schristos * its original value was an absolute path, so that it will never match
104a53f50b9Schristos * any other mntfs.
105a53f50b9Schristos *
106a53f50b9Schristos * XXX: a less hacky solution should be used...
107a53f50b9Schristos */
108a53f50b9Schristos if (fo->opt_fs[0] == '/') {
109a53f50b9Schristos char *link_hack = str3cat(NULL, ".", fo->opt_fs, "");
1104bcd344eSchristos if (fo->opt_sublink == NULL || fo->opt_sublink[0] == '\0')
111*8bae5d40Schristos fo->opt_sublink = xstrdup(fo->opt_fs);
112a53f50b9Schristos XFREE(fo->opt_fs);
113a53f50b9Schristos fo->opt_fs = link_hack;
114a53f50b9Schristos }
115a53f50b9Schristos
116*8bae5d40Schristos return xstrdup(fo->opt_fs);
117a53f50b9Schristos }
118a53f50b9Schristos
119a53f50b9Schristos
120a53f50b9Schristos static int
amfs_link_mount(am_node * mp,mntfs * mf)121a53f50b9Schristos amfs_link_mount(am_node *mp, mntfs *mf)
122a53f50b9Schristos {
123a53f50b9Schristos return 0;
124a53f50b9Schristos }
125a53f50b9Schristos
126a53f50b9Schristos
127a53f50b9Schristos static int
amfs_link_umount(am_node * mp,mntfs * mf)128a53f50b9Schristos amfs_link_umount(am_node *mp, mntfs *mf)
129a53f50b9Schristos {
130a53f50b9Schristos return 0;
131a53f50b9Schristos }
132