2 * Copyright (c) 1997-2003 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.
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
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
41 * $Id: restart.c,v 1.3.2.3 2002/12/27 22:44:43 ezk Exp $
47 #endif /* HAVE_CONFIG_H */
53 * Handle an amd restart.
55 * Scan through the mount list finding all "interesting" mount points.
56 * Next hack up partial data structures and add the mounted file
57 * system to the list of known filesystems. This will leave a
58 * dangling reference to that filesystems, so when the filesystem is
59 * finally inherited, an extra "free" must be done on it.
61 * This module relies on internal details of other components. If
62 * you change something else make *sure* restart() still works.
68 * Read the existing mount table
73 * For each entry, find nfs, ufs or auto mounts
74 * and create a partial am_node to represent it.
76 for (mlp = ml = read_mtab("restart", mnttab_file_name);
79 mntent_t *me = mlp->mnt;
81 if (STREQ(me->mnt_type, MNTTAB_TYPE_UFS)) {
86 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_NFS)) {
88 * NFS entry, or possibly an Amd entry...
89 * The mnt_fsname for daemon mount points is
91 * or (seen on Solaris)
94 char *colon = strchr(me->mnt_fsname, ':');
96 if (colon && strstr(colon, "(pid")) {
97 plog(XLOG_WARNING, "%s is an existing automount point", me->mnt_dir);
98 fs_ops = &amfs_link_ops;
102 #ifdef MNTTAB_TYPE_NFS3
103 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_NFS3)) {
105 #endif /* MNTTAB_TYPE_NFS3 */
106 #ifdef MNTTAB_TYPE_LOFS
107 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_LOFS)) {
109 #endif /* MNTTAB_TYPE_LOFS */
110 #ifdef MNTTAB_TYPE_CDFS
111 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_CDFS)) {
113 #endif /* MNTTAB_TYPE_CDFS */
114 #ifdef MNTTAB_TYPE_PCFS
115 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_PCFS)) {
117 #endif /* MNTTAB_TYPE_PCFS */
118 #ifdef MNTTAB_TYPE_MFS
119 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_MFS)) {
121 * MFS entry. Fake with a symlink.
123 fs_ops = &amfs_link_ops;
124 #endif /* MNTTAB_TYPE_MFS */
127 * Catch everything else with symlinks to
128 * avoid recursive mounts. This is debatable...
130 fs_ops = &amfs_link_ops;
134 * If we found something to do
140 cp = strchr(me->mnt_fsname, ':');
143 * Partially fake up an opts structure
149 mo.opt_rhost = strdup(me->mnt_fsname);
150 mo.opt_rfs = strdup(cp + 1);
152 } else if (fs_ops->ffserver == find_nfs_srvr) {
154 * Prototype 4.4 BSD used to end up here -
155 * might as well keep the workaround for now
157 plog(XLOG_WARNING, "NFS server entry assumed to be %s:/", me->mnt_fsname);
158 mo.opt_rhost = strdup(me->mnt_fsname);
159 mo.opt_rfs = strdup("/");
160 me->mnt_fsname = str3cat(me->mnt_fsname, mo.opt_rhost, ":", "/");
162 mo.opt_fs = me->mnt_dir;
163 mo.opt_opts = me->mnt_opts;
166 * Make a new mounted filesystem
168 mf = find_mntfs(fs_ops, &mo, me->mnt_dir,
169 me->mnt_fsname, "", me->mnt_opts, "");
170 if (mf->mf_refc == 1) {
171 mf->mf_flags |= MFF_RESTART | MFF_MOUNTED;
172 mf->mf_error = 0; /* Already mounted correctly */
175 * If the restarted type is a link then
178 if (fs_ops == &amfs_link_ops || fs_ops == &ufs_ops)
179 mf->mf_flags |= MFF_RSTKEEP;
180 if (fs_ops->fs_init) {
182 * Don't care whether this worked since
183 * it is checked again when the fs is
186 (void) (*fs_ops->fs_init) (mf);
188 plog(XLOG_INFO, "%s restarted fstype %s on %s",
189 me->mnt_fsname, fs_ops->fs_type, me->mnt_dir);
191 /* Something strange happened - two mounts at the same place! */
205 * Free the mount list