MFC r1.27:
[dragonfly.git] / contrib / amd / amd / amfs_inherit.c
blob891afeae492e3177230247b2f5d1a16a429b4398
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.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
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.
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.
39 * %W% (Berkeley) %G%
41 * $Id: amfs_inherit.c,v 1.2 1999/01/10 21:53:41 ezk Exp $
46 * Inheritance file system.
49 #ifdef HAVE_CONFIG_H
50 # include <config.h>
51 #endif /* HAVE_CONFIG_H */
52 #include <am_defs.h>
53 #include <amd.h>
56 * This implements a filesystem restart.
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.
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);
71 * Ops structure
73 am_ops amfs_inherit_ops =
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
93 * This should never be called.
95 static char *
96 amfs_inherit_match(am_opts *fo)
98 plog(XLOG_FATAL, "amfs_inherit_match called!");
99 return 0;
103 static int
104 amfs_inherit_init(mntfs *mf)
106 mntfs *mf_link = (mntfs *) mf->mf_private;
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;
114 if (mf_link->mf_ops->fs_init)
115 return (*mf_link->mf_ops->fs_init) (mf_link);
116 return 0;
121 * Take the linked mount point and
122 * propagate.
124 static mntfs *
125 amfs_inherit_inherit(mntfs *mf)
127 mntfs *mf_link = (mntfs *) mf->mf_private;
129 if (mf_link == 0) {
130 plog(XLOG_FATAL, "Attempting to inherit not-a-filesystem");
131 return 0; /* XXX */
133 mf_link->mf_fo = mf->mf_fo;
136 * Discard the old map.
137 * Don't call am_unmounted since this
138 * node was never really mounted in the
139 * first place.
141 mf->mf_private = 0;
142 free_mntfs(mf);
145 * Free the dangling reference
146 * to the mount link.
148 free_mntfs(mf_link);
151 * Get a hold of the other entry
153 mf_link->mf_flags &= ~MFF_RESTART;
155 /* Say what happened */
156 plog(XLOG_INFO, "restarting %s on %s", mf_link->mf_info, mf_link->mf_mount);
158 return mf_link;
162 static int
163 amfs_inherit_mount(am_node *mp)
165 mntfs *newmf = amfs_inherit_inherit(mp->am_mnt);
167 if (newmf) {
168 mp->am_mnt = newmf;
170 * XXX - must do the am_mounted call here
172 if (newmf->mf_ops->fs_flags & FS_MBACKGROUND)
173 am_mounted(mp);
175 new_ttl(mp);
176 return 0;
178 return EINVAL;
182 static int
183 amfs_inherit_fmount(mntfs *mf)
185 am_node *mp = find_mf(mf);
187 if (mp)
188 return amfs_inherit_mount(mp);
189 return amfs_inherit_inherit(mf) ? 0 : EINVAL;
193 static int
194 amfs_inherit_fumount(mntfs *mf)
197 * Always succeed
199 return 0;