Merge branch 'vendor/OPENSSH'
[dragonfly.git] / contrib / amd / amd / amfs_inherit.c
1 /*
2  * Copyright (c) 1997-1999 Erez Zadok
3  * Copyright (c) 1989 Jan-Simon Pendry
4  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5  * Copyright (c) 1989 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. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgment:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      %W% (Berkeley) %G%
40  *
41  * $Id: amfs_inherit.c,v 1.2 1999/01/10 21:53:41 ezk Exp $
42  *
43  */
44
45 /*
46  * Inheritance file system.
47  */
48
49 #ifdef HAVE_CONFIG_H
50 # include <config.h>
51 #endif /* HAVE_CONFIG_H */
52 #include <am_defs.h>
53 #include <amd.h>
54
55 /*
56  * This implements a filesystem restart.
57  *
58  * This is a *gross* hack - it knows far too
59  * much about the way other parts of the
60  * system work.  See restart.c too.
61  */
62
63 static char *amfs_inherit_match(am_opts *fo);
64 static int amfs_inherit_fmount(mntfs *mf);
65 static int amfs_inherit_fumount(mntfs *mf);
66 static int amfs_inherit_init(mntfs *mf);
67 static int amfs_inherit_mount(am_node *mp);
68
69
70 /*
71  * Ops structure
72  */
73 am_ops amfs_inherit_ops =
74 {
75   "inherit",
76   amfs_inherit_match,
77   amfs_inherit_init,
78   amfs_inherit_mount,
79   amfs_inherit_fmount,
80   amfs_auto_fumount,
81   amfs_inherit_fumount,
82   amfs_error_lookuppn,
83   amfs_error_readdir,
84   0,                            /* amfs_inherit_readlink */
85   0,                            /* amfs_inherit_mounted */
86   0,                            /* amfs_inherit_umounted */
87   find_amfs_auto_srvr,
88   FS_DISCARD
89 };
90
91
92 /*
93  * This should never be called.
94  */
95 static char *
96 amfs_inherit_match(am_opts *fo)
97 {
98   plog(XLOG_FATAL, "amfs_inherit_match called!");
99   return 0;
100 }
101
102
103 static int
104 amfs_inherit_init(mntfs *mf)
105 {
106   mntfs *mf_link = (mntfs *) mf->mf_private;
107
108   if (mf_link == 0) {
109     plog(XLOG_ERROR, "Remount collision on %s?", mf->mf_mount);
110     plog(XLOG_FATAL, "Attempting to init not-a-filesystem");
111     return EINVAL;
112   }
113
114   if (mf_link->mf_ops->fs_init)
115     return (*mf_link->mf_ops->fs_init) (mf_link);
116   return 0;
117 }
118
119
120 /*
121  * Take the linked mount point and
122  * propagate.
123  */
124 static mntfs *
125 amfs_inherit_inherit(mntfs *mf)
126 {
127   mntfs *mf_link = (mntfs *) mf->mf_private;
128
129   if (mf_link == 0) {
130     plog(XLOG_FATAL, "Attempting to inherit not-a-filesystem");
131     return 0;                   /* XXX */
132   }
133   mf_link->mf_fo = mf->mf_fo;
134
135   /*
136    * Discard the old map.
137    * Don't call am_unmounted since this
138    * node was never really mounted in the
139    * first place.
140    */
141   mf->mf_private = 0;
142   free_mntfs(mf);
143
144   /*
145    * Free the dangling reference
146    * to the mount link.
147    */
148   free_mntfs(mf_link);
149
150   /*
151    * Get a hold of the other entry
152    */
153   mf_link->mf_flags &= ~MFF_RESTART;
154
155   /* Say what happened */
156   plog(XLOG_INFO, "restarting %s on %s", mf_link->mf_info, mf_link->mf_mount);
157
158   return mf_link;
159 }
160
161
162 static int
163 amfs_inherit_mount(am_node *mp)
164 {
165   mntfs *newmf = amfs_inherit_inherit(mp->am_mnt);
166
167   if (newmf) {
168     mp->am_mnt = newmf;
169     /*
170      * XXX - must do the am_mounted call here
171      */
172     if (newmf->mf_ops->fs_flags & FS_MBACKGROUND)
173       am_mounted(mp);
174
175     new_ttl(mp);
176     return 0;
177   }
178   return EINVAL;
179 }
180
181
182 static int
183 amfs_inherit_fmount(mntfs *mf)
184 {
185   am_node *mp = find_mf(mf);
186
187   if (mp)
188     return amfs_inherit_mount(mp);
189   return amfs_inherit_inherit(mf) ? 0 : EINVAL;
190 }
191
192
193 static int
194 amfs_inherit_fumount(mntfs *mf)
195 {
196   /*
197    * Always succeed
198    */
199   return 0;
200 }