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