1 /* $NetBSD: amfs_link.c,v 1.1.1.3 2015/01/17 16:34:15 christos Exp $ */
2
3 /*
4 * Copyright (c) 1997-2014 Erez Zadok
5 * Copyright (c) 1990 Jan-Simon Pendry
6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1990 The Regents of the University of California.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 *
38 * File: am-utils/amd/amfs_link.c
39 *
40 */
41
42 /*
43 * Symbol-link file system
44 */
45
46 #ifdef HAVE_CONFIG_H
47 # include <config.h>
48 #endif /* HAVE_CONFIG_H */
49 #include <am_defs.h>
50 #include <amd.h>
51
52 /* forward declarations */
53 static int amfs_link_mount(am_node *mp, mntfs *mf);
54 static int amfs_link_umount(am_node *mp, mntfs *mf);
55
56 /*
57 * Ops structures
58 */
59 am_ops amfs_link_ops =
60 {
61 "link",
62 amfs_link_match,
63 0, /* amfs_link_init */
64 amfs_link_mount,
65 amfs_link_umount,
66 amfs_error_lookup_child,
67 amfs_error_mount_child,
68 amfs_error_readdir,
69 0, /* amfs_link_readlink */
70 0, /* amfs_link_mounted */
71 0, /* amfs_link_umounted */
72 amfs_generic_find_srvr,
73 0, /* nfs_fs_flags */
74 0, /* amfs_link_get_wchan */
75 #ifdef HAVE_FS_AUTOFS
76 AUTOFS_LINK_FS_FLAGS,
77 #endif /* HAVE_FS_AUTOFS */
78 };
79
80
81 /*
82 * SFS needs a link.
83 */
84 char *
amfs_link_match(am_opts * fo)85 amfs_link_match(am_opts *fo)
86 {
87
88 if (!fo->opt_fs) {
89 plog(XLOG_USER, "link: no fs specified");
90 return 0;
91 }
92
93 /*
94 * If the link target points to another mount point, then we could
95 * end up with an unpleasant situation, where the link f/s simply
96 * "assumes" the mntfs of that mount point.
97 *
98 * For example, if the link points to /usr, and /usr is a real ufs
99 * filesystem, then the link f/s will use the inherited ufs mntfs,
100 * and the end result will be that it will become unmountable.
101 *
102 * To prevent this, we use a hack: we prepend a dot ('.') to opt_fs if
103 * its original value was an absolute path, so that it will never match
104 * any other mntfs.
105 *
106 * XXX: a less hacky solution should be used...
107 */
108 if (fo->opt_fs[0] == '/') {
109 char *link_hack = str3cat(NULL, ".", fo->opt_fs, "");
110 if (fo->opt_sublink == NULL || fo->opt_sublink[0] == '\0')
111 fo->opt_sublink = xstrdup(fo->opt_fs);
112 XFREE(fo->opt_fs);
113 fo->opt_fs = link_hack;
114 }
115
116 return xstrdup(fo->opt_fs);
117 }
118
119
120 static int
amfs_link_mount(am_node * mp,mntfs * mf)121 amfs_link_mount(am_node *mp, mntfs *mf)
122 {
123 return 0;
124 }
125
126
127 static int
amfs_link_umount(am_node * mp,mntfs * mf)128 amfs_link_umount(am_node *mp, mntfs *mf)
129 {
130 return 0;
131 }
132