| @@ -1,1934 +1,1946 @@ | | | @@ -1,1934 +1,1946 @@ |
1 | /* $NetBSD: ffs_vfsops.c,v 1.260 2010/07/21 17:52:13 hannken Exp $ */ | | 1 | /* $NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Wasabi Systems, Inc, and by Andrew Doran. | | 8 | * by Wasabi Systems, Inc, and by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Copyright (c) 1989, 1991, 1993, 1994 | | 33 | * Copyright (c) 1989, 1991, 1993, 1994 |
34 | * The Regents of the University of California. All rights reserved. | | 34 | * The Regents of the University of California. All rights reserved. |
35 | * | | 35 | * |
36 | * Redistribution and use in source and binary forms, with or without | | 36 | * Redistribution and use in source and binary forms, with or without |
37 | * modification, are permitted provided that the following conditions | | 37 | * modification, are permitted provided that the following conditions |
38 | * are met: | | 38 | * are met: |
39 | * 1. Redistributions of source code must retain the above copyright | | 39 | * 1. Redistributions of source code must retain the above copyright |
40 | * notice, this list of conditions and the following disclaimer. | | 40 | * notice, this list of conditions and the following disclaimer. |
41 | * 2. Redistributions in binary form must reproduce the above copyright | | 41 | * 2. Redistributions in binary form must reproduce the above copyright |
42 | * notice, this list of conditions and the following disclaimer in the | | 42 | * notice, this list of conditions and the following disclaimer in the |
43 | * documentation and/or other materials provided with the distribution. | | 43 | * documentation and/or other materials provided with the distribution. |
44 | * 3. Neither the name of the University nor the names of its contributors | | 44 | * 3. Neither the name of the University nor the names of its contributors |
45 | * may be used to endorse or promote products derived from this software | | 45 | * may be used to endorse or promote products derived from this software |
46 | * without specific prior written permission. | | 46 | * without specific prior written permission. |
47 | * | | 47 | * |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95 | | 60 | * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.260 2010/07/21 17:52:13 hannken Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.261 2010/08/09 15:50:13 pooka Exp $"); |
65 | | | 65 | |
66 | #if defined(_KERNEL_OPT) | | 66 | #if defined(_KERNEL_OPT) |
67 | #include "opt_ffs.h" | | 67 | #include "opt_ffs.h" |
68 | #include "opt_quota.h" | | 68 | #include "opt_quota.h" |
69 | #include "opt_wapbl.h" | | 69 | #include "opt_wapbl.h" |
70 | #endif | | 70 | #endif |
71 | | | 71 | |
72 | #include <sys/param.h> | | 72 | #include <sys/param.h> |
73 | #include <sys/systm.h> | | 73 | #include <sys/systm.h> |
74 | #include <sys/namei.h> | | 74 | #include <sys/namei.h> |
75 | #include <sys/proc.h> | | 75 | #include <sys/proc.h> |
76 | #include <sys/kernel.h> | | 76 | #include <sys/kernel.h> |
77 | #include <sys/vnode.h> | | 77 | #include <sys/vnode.h> |
78 | #include <sys/socket.h> | | 78 | #include <sys/socket.h> |
79 | #include <sys/mount.h> | | 79 | #include <sys/mount.h> |
80 | #include <sys/buf.h> | | 80 | #include <sys/buf.h> |
81 | #include <sys/device.h> | | 81 | #include <sys/device.h> |
82 | #include <sys/mbuf.h> | | 82 | #include <sys/mbuf.h> |
83 | #include <sys/file.h> | | 83 | #include <sys/file.h> |
84 | #include <sys/disklabel.h> | | 84 | #include <sys/disklabel.h> |
85 | #include <sys/ioctl.h> | | 85 | #include <sys/ioctl.h> |
86 | #include <sys/errno.h> | | 86 | #include <sys/errno.h> |
87 | #include <sys/malloc.h> | | 87 | #include <sys/malloc.h> |
88 | #include <sys/pool.h> | | 88 | #include <sys/pool.h> |
89 | #include <sys/lock.h> | | 89 | #include <sys/lock.h> |
90 | #include <sys/sysctl.h> | | 90 | #include <sys/sysctl.h> |
91 | #include <sys/conf.h> | | 91 | #include <sys/conf.h> |
92 | #include <sys/kauth.h> | | 92 | #include <sys/kauth.h> |
93 | #include <sys/wapbl.h> | | 93 | #include <sys/wapbl.h> |
94 | #include <sys/fstrans.h> | | 94 | #include <sys/fstrans.h> |
95 | #include <sys/module.h> | | 95 | #include <sys/module.h> |
96 | | | 96 | |
97 | #include <miscfs/genfs/genfs.h> | | 97 | #include <miscfs/genfs/genfs.h> |
98 | #include <miscfs/specfs/specdev.h> | | 98 | #include <miscfs/specfs/specdev.h> |
99 | | | 99 | |
100 | #include <ufs/ufs/quota.h> | | 100 | #include <ufs/ufs/quota.h> |
101 | #include <ufs/ufs/ufsmount.h> | | 101 | #include <ufs/ufs/ufsmount.h> |
102 | #include <ufs/ufs/inode.h> | | 102 | #include <ufs/ufs/inode.h> |
103 | #include <ufs/ufs/dir.h> | | 103 | #include <ufs/ufs/dir.h> |
104 | #include <ufs/ufs/ufs_extern.h> | | 104 | #include <ufs/ufs/ufs_extern.h> |
105 | #include <ufs/ufs/ufs_bswap.h> | | 105 | #include <ufs/ufs/ufs_bswap.h> |
106 | #include <ufs/ufs/ufs_wapbl.h> | | 106 | #include <ufs/ufs/ufs_wapbl.h> |
107 | | | 107 | |
108 | #include <ufs/ffs/fs.h> | | 108 | #include <ufs/ffs/fs.h> |
109 | #include <ufs/ffs/ffs_extern.h> | | 109 | #include <ufs/ffs/ffs_extern.h> |
110 | | | 110 | |
111 | MODULE(MODULE_CLASS_VFS, ffs, NULL); | | 111 | MODULE(MODULE_CLASS_VFS, ffs, NULL); |
112 | | | 112 | |
113 | static int ffs_vfs_fsync(vnode_t *, int); | | 113 | static int ffs_vfs_fsync(vnode_t *, int); |
114 | | | 114 | |
115 | static struct sysctllog *ffs_sysctl_log; | | 115 | static struct sysctllog *ffs_sysctl_log; |
116 | | | 116 | |
117 | /* how many times ffs_init() was called */ | | 117 | /* how many times ffs_init() was called */ |
118 | int ffs_initcount = 0; | | 118 | int ffs_initcount = 0; |
119 | | | 119 | |
120 | extern const struct vnodeopv_desc ffs_vnodeop_opv_desc; | | 120 | extern const struct vnodeopv_desc ffs_vnodeop_opv_desc; |
121 | extern const struct vnodeopv_desc ffs_specop_opv_desc; | | 121 | extern const struct vnodeopv_desc ffs_specop_opv_desc; |
122 | extern const struct vnodeopv_desc ffs_fifoop_opv_desc; | | 122 | extern const struct vnodeopv_desc ffs_fifoop_opv_desc; |
123 | | | 123 | |
124 | const struct vnodeopv_desc * const ffs_vnodeopv_descs[] = { | | 124 | const struct vnodeopv_desc * const ffs_vnodeopv_descs[] = { |
125 | &ffs_vnodeop_opv_desc, | | 125 | &ffs_vnodeop_opv_desc, |
126 | &ffs_specop_opv_desc, | | 126 | &ffs_specop_opv_desc, |
127 | &ffs_fifoop_opv_desc, | | 127 | &ffs_fifoop_opv_desc, |
128 | NULL, | | 128 | NULL, |
129 | }; | | 129 | }; |
130 | | | 130 | |
131 | struct vfsops ffs_vfsops = { | | 131 | struct vfsops ffs_vfsops = { |
132 | MOUNT_FFS, | | 132 | MOUNT_FFS, |
133 | sizeof (struct ufs_args), | | 133 | sizeof (struct ufs_args), |
134 | ffs_mount, | | 134 | ffs_mount, |
135 | ufs_start, | | 135 | ufs_start, |
136 | ffs_unmount, | | 136 | ffs_unmount, |
137 | ufs_root, | | 137 | ufs_root, |
138 | ufs_quotactl, | | 138 | ufs_quotactl, |
139 | ffs_statvfs, | | 139 | ffs_statvfs, |
140 | ffs_sync, | | 140 | ffs_sync, |
141 | ffs_vget, | | 141 | ffs_vget, |
142 | ffs_fhtovp, | | 142 | ffs_fhtovp, |
143 | ffs_vptofh, | | 143 | ffs_vptofh, |
144 | ffs_init, | | 144 | ffs_init, |
145 | ffs_reinit, | | 145 | ffs_reinit, |
146 | ffs_done, | | 146 | ffs_done, |
147 | ffs_mountroot, | | 147 | ffs_mountroot, |
148 | ffs_snapshot, | | 148 | ffs_snapshot, |
149 | ffs_extattrctl, | | 149 | ffs_extattrctl, |
150 | ffs_suspendctl, | | 150 | ffs_suspendctl, |
151 | genfs_renamelock_enter, | | 151 | genfs_renamelock_enter, |
152 | genfs_renamelock_exit, | | 152 | genfs_renamelock_exit, |
153 | ffs_vfs_fsync, | | 153 | ffs_vfs_fsync, |
154 | ffs_vnodeopv_descs, | | 154 | ffs_vnodeopv_descs, |
155 | 0, | | 155 | 0, |
156 | { NULL, NULL }, | | 156 | { NULL, NULL }, |
157 | }; | | 157 | }; |
158 | | | 158 | |
159 | static const struct genfs_ops ffs_genfsops = { | | 159 | static const struct genfs_ops ffs_genfsops = { |
160 | .gop_size = ffs_gop_size, | | 160 | .gop_size = ffs_gop_size, |
161 | .gop_alloc = ufs_gop_alloc, | | 161 | .gop_alloc = ufs_gop_alloc, |
162 | .gop_write = genfs_gop_write, | | 162 | .gop_write = genfs_gop_write, |
163 | .gop_markupdate = ufs_gop_markupdate, | | 163 | .gop_markupdate = ufs_gop_markupdate, |
164 | }; | | 164 | }; |
165 | | | 165 | |
166 | static const struct ufs_ops ffs_ufsops = { | | 166 | static const struct ufs_ops ffs_ufsops = { |
167 | .uo_itimes = ffs_itimes, | | 167 | .uo_itimes = ffs_itimes, |
168 | .uo_update = ffs_update, | | 168 | .uo_update = ffs_update, |
169 | .uo_truncate = ffs_truncate, | | 169 | .uo_truncate = ffs_truncate, |
170 | .uo_valloc = ffs_valloc, | | 170 | .uo_valloc = ffs_valloc, |
171 | .uo_vfree = ffs_vfree, | | 171 | .uo_vfree = ffs_vfree, |
172 | .uo_balloc = ffs_balloc, | | 172 | .uo_balloc = ffs_balloc, |
173 | .uo_unmark_vnode = (void (*)(vnode_t *))nullop, | | 173 | .uo_unmark_vnode = (void (*)(vnode_t *))nullop, |
174 | }; | | 174 | }; |
175 | | | 175 | |
176 | static int | | 176 | static int |
177 | ffs_modcmd(modcmd_t cmd, void *arg) | | 177 | ffs_modcmd(modcmd_t cmd, void *arg) |
178 | { | | 178 | { |
179 | int error; | | 179 | int error; |
180 | | | 180 | |
181 | #if 0 | | 181 | #if 0 |
182 | extern int doasyncfree; | | 182 | extern int doasyncfree; |
183 | #endif | | 183 | #endif |
184 | extern int ffs_log_changeopt; | | 184 | extern int ffs_log_changeopt; |
185 | | | 185 | |
186 | switch (cmd) { | | 186 | switch (cmd) { |
187 | case MODULE_CMD_INIT: | | 187 | case MODULE_CMD_INIT: |
188 | error = vfs_attach(&ffs_vfsops); | | 188 | error = vfs_attach(&ffs_vfsops); |
189 | if (error != 0) | | 189 | if (error != 0) |
190 | break; | | 190 | break; |
191 | | | 191 | |
192 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 192 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
193 | CTLFLAG_PERMANENT, | | 193 | CTLFLAG_PERMANENT, |
194 | CTLTYPE_NODE, "vfs", NULL, | | 194 | CTLTYPE_NODE, "vfs", NULL, |
195 | NULL, 0, NULL, 0, | | 195 | NULL, 0, NULL, 0, |
196 | CTL_VFS, CTL_EOL); | | 196 | CTL_VFS, CTL_EOL); |
197 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 197 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
198 | CTLFLAG_PERMANENT, | | 198 | CTLFLAG_PERMANENT, |
199 | CTLTYPE_NODE, "ffs", | | 199 | CTLTYPE_NODE, "ffs", |
200 | SYSCTL_DESCR("Berkeley Fast File System"), | | 200 | SYSCTL_DESCR("Berkeley Fast File System"), |
201 | NULL, 0, NULL, 0, | | 201 | NULL, 0, NULL, 0, |
202 | CTL_VFS, 1, CTL_EOL); | | 202 | CTL_VFS, 1, CTL_EOL); |
203 | | | 203 | |
204 | /* | | 204 | /* |
205 | * @@@ should we even bother with these first three? | | 205 | * @@@ should we even bother with these first three? |
206 | */ | | 206 | */ |
207 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 207 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
208 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 208 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
209 | CTLTYPE_INT, "doclusterread", NULL, | | 209 | CTLTYPE_INT, "doclusterread", NULL, |
210 | sysctl_notavail, 0, NULL, 0, | | 210 | sysctl_notavail, 0, NULL, 0, |
211 | CTL_VFS, 1, FFS_CLUSTERREAD, CTL_EOL); | | 211 | CTL_VFS, 1, FFS_CLUSTERREAD, CTL_EOL); |
212 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 212 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
213 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 213 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
214 | CTLTYPE_INT, "doclusterwrite", NULL, | | 214 | CTLTYPE_INT, "doclusterwrite", NULL, |
215 | sysctl_notavail, 0, NULL, 0, | | 215 | sysctl_notavail, 0, NULL, 0, |
216 | CTL_VFS, 1, FFS_CLUSTERWRITE, CTL_EOL); | | 216 | CTL_VFS, 1, FFS_CLUSTERWRITE, CTL_EOL); |
217 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 217 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
218 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 218 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
219 | CTLTYPE_INT, "doreallocblks", NULL, | | 219 | CTLTYPE_INT, "doreallocblks", NULL, |
220 | sysctl_notavail, 0, NULL, 0, | | 220 | sysctl_notavail, 0, NULL, 0, |
221 | CTL_VFS, 1, FFS_REALLOCBLKS, CTL_EOL); | | 221 | CTL_VFS, 1, FFS_REALLOCBLKS, CTL_EOL); |
222 | #if 0 | | 222 | #if 0 |
223 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 223 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
224 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 224 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
225 | CTLTYPE_INT, "doasyncfree", | | 225 | CTLTYPE_INT, "doasyncfree", |
226 | SYSCTL_DESCR("Release dirty blocks asynchronously"), | | 226 | SYSCTL_DESCR("Release dirty blocks asynchronously"), |
227 | NULL, 0, &doasyncfree, 0, | | 227 | NULL, 0, &doasyncfree, 0, |
228 | CTL_VFS, 1, FFS_ASYNCFREE, CTL_EOL); | | 228 | CTL_VFS, 1, FFS_ASYNCFREE, CTL_EOL); |
229 | #endif | | 229 | #endif |
230 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, | | 230 | sysctl_createv(&ffs_sysctl_log, 0, NULL, NULL, |
231 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 231 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
232 | CTLTYPE_INT, "log_changeopt", | | 232 | CTLTYPE_INT, "log_changeopt", |
233 | SYSCTL_DESCR("Log changes in optimization strategy"), | | 233 | SYSCTL_DESCR("Log changes in optimization strategy"), |
234 | NULL, 0, &ffs_log_changeopt, 0, | | 234 | NULL, 0, &ffs_log_changeopt, 0, |
235 | CTL_VFS, 1, FFS_LOG_CHANGEOPT, CTL_EOL); | | 235 | CTL_VFS, 1, FFS_LOG_CHANGEOPT, CTL_EOL); |
236 | break; | | 236 | break; |
237 | case MODULE_CMD_FINI: | | 237 | case MODULE_CMD_FINI: |
238 | error = vfs_detach(&ffs_vfsops); | | 238 | error = vfs_detach(&ffs_vfsops); |
239 | if (error != 0) | | 239 | if (error != 0) |
240 | break; | | 240 | break; |
241 | sysctl_teardown(&ffs_sysctl_log); | | 241 | sysctl_teardown(&ffs_sysctl_log); |
242 | break; | | 242 | break; |
243 | default: | | 243 | default: |
244 | error = ENOTTY; | | 244 | error = ENOTTY; |
245 | break; | | 245 | break; |
246 | } | | 246 | } |
247 | | | 247 | |
248 | return (error); | | 248 | return (error); |
249 | } | | 249 | } |
250 | | | 250 | |
251 | pool_cache_t ffs_inode_cache; | | 251 | pool_cache_t ffs_inode_cache; |
252 | pool_cache_t ffs_dinode1_cache; | | 252 | pool_cache_t ffs_dinode1_cache; |
253 | pool_cache_t ffs_dinode2_cache; | | 253 | pool_cache_t ffs_dinode2_cache; |
254 | | | 254 | |
255 | static void ffs_oldfscompat_read(struct fs *, struct ufsmount *, daddr_t); | | 255 | static void ffs_oldfscompat_read(struct fs *, struct ufsmount *, daddr_t); |
256 | static void ffs_oldfscompat_write(struct fs *, struct ufsmount *); | | 256 | static void ffs_oldfscompat_write(struct fs *, struct ufsmount *); |
257 | | | 257 | |
258 | /* | | 258 | /* |
259 | * Called by main() when ffs is going to be mounted as root. | | 259 | * Called by main() when ffs is going to be mounted as root. |
260 | */ | | 260 | */ |
261 | | | 261 | |
262 | int | | 262 | int |
263 | ffs_mountroot(void) | | 263 | ffs_mountroot(void) |
264 | { | | 264 | { |
265 | struct fs *fs; | | 265 | struct fs *fs; |
266 | struct mount *mp; | | 266 | struct mount *mp; |
267 | struct lwp *l = curlwp; /* XXX */ | | 267 | struct lwp *l = curlwp; /* XXX */ |
268 | struct ufsmount *ump; | | 268 | struct ufsmount *ump; |
269 | int error; | | 269 | int error; |
270 | | | 270 | |
271 | if (device_class(root_device) != DV_DISK) | | 271 | if (device_class(root_device) != DV_DISK) |
272 | return (ENODEV); | | 272 | return (ENODEV); |
273 | | | 273 | |
274 | if ((error = vfs_rootmountalloc(MOUNT_FFS, "root_device", &mp))) { | | 274 | if ((error = vfs_rootmountalloc(MOUNT_FFS, "root_device", &mp))) { |
275 | vrele(rootvp); | | 275 | vrele(rootvp); |
276 | return (error); | | 276 | return (error); |
277 | } | | 277 | } |
278 | | | 278 | |
279 | /* | | 279 | /* |
280 | * We always need to be able to mount the root file system. | | 280 | * We always need to be able to mount the root file system. |
281 | */ | | 281 | */ |
282 | mp->mnt_flag |= MNT_FORCE; | | 282 | mp->mnt_flag |= MNT_FORCE; |
283 | if ((error = ffs_mountfs(rootvp, mp, l)) != 0) { | | 283 | if ((error = ffs_mountfs(rootvp, mp, l)) != 0) { |
284 | vfs_unbusy(mp, false, NULL); | | 284 | vfs_unbusy(mp, false, NULL); |
285 | vfs_destroy(mp); | | 285 | vfs_destroy(mp); |
286 | return (error); | | 286 | return (error); |
287 | } | | 287 | } |
288 | mp->mnt_flag &= ~MNT_FORCE; | | 288 | mp->mnt_flag &= ~MNT_FORCE; |
289 | mutex_enter(&mountlist_lock); | | 289 | mutex_enter(&mountlist_lock); |
290 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); | | 290 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); |
291 | mutex_exit(&mountlist_lock); | | 291 | mutex_exit(&mountlist_lock); |
292 | ump = VFSTOUFS(mp); | | 292 | ump = VFSTOUFS(mp); |
293 | fs = ump->um_fs; | | 293 | fs = ump->um_fs; |
294 | memset(fs->fs_fsmnt, 0, sizeof(fs->fs_fsmnt)); | | 294 | memset(fs->fs_fsmnt, 0, sizeof(fs->fs_fsmnt)); |
295 | (void)copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0); | | 295 | (void)copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0); |
296 | (void)ffs_statvfs(mp, &mp->mnt_stat); | | 296 | (void)ffs_statvfs(mp, &mp->mnt_stat); |
297 | vfs_unbusy(mp, false, NULL); | | 297 | vfs_unbusy(mp, false, NULL); |
298 | setrootfstime((time_t)fs->fs_time); | | 298 | setrootfstime((time_t)fs->fs_time); |
299 | return (0); | | 299 | return (0); |
300 | } | | 300 | } |
301 | | | 301 | |
302 | /* | | 302 | /* |
303 | * VFS Operations. | | 303 | * VFS Operations. |
304 | * | | 304 | * |
305 | * mount system call | | 305 | * mount system call |
306 | */ | | 306 | */ |
307 | int | | 307 | int |
308 | ffs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) | | 308 | ffs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) |
309 | { | | 309 | { |
310 | struct lwp *l = curlwp; | | 310 | struct lwp *l = curlwp; |
311 | struct vnode *devvp = NULL; | | 311 | struct vnode *devvp = NULL; |
312 | struct ufs_args *args = data; | | 312 | struct ufs_args *args = data; |
313 | struct ufsmount *ump = NULL; | | 313 | struct ufsmount *ump = NULL; |
314 | struct fs *fs; | | 314 | struct fs *fs; |
315 | int error = 0, flags, update; | | 315 | int error = 0, flags, update; |
316 | mode_t accessmode; | | 316 | mode_t accessmode; |
317 | | | 317 | |
318 | if (*data_len < sizeof *args) | | 318 | if (*data_len < sizeof *args) |
319 | return EINVAL; | | 319 | return EINVAL; |
320 | | | 320 | |
321 | if (mp->mnt_flag & MNT_GETARGS) { | | 321 | if (mp->mnt_flag & MNT_GETARGS) { |
322 | ump = VFSTOUFS(mp); | | 322 | ump = VFSTOUFS(mp); |
323 | if (ump == NULL) | | 323 | if (ump == NULL) |
324 | return EIO; | | 324 | return EIO; |
325 | args->fspec = NULL; | | 325 | args->fspec = NULL; |
326 | *data_len = sizeof *args; | | 326 | *data_len = sizeof *args; |
327 | return 0; | | 327 | return 0; |
328 | } | | 328 | } |
329 | | | 329 | |
330 | update = mp->mnt_flag & MNT_UPDATE; | | 330 | update = mp->mnt_flag & MNT_UPDATE; |
331 | | | 331 | |
332 | /* Check arguments */ | | 332 | /* Check arguments */ |
333 | if (args->fspec != NULL) { | | 333 | if (args->fspec != NULL) { |
334 | /* | | 334 | /* |
335 | * Look up the name and verify that it's sane. | | 335 | * Look up the name and verify that it's sane. |
336 | */ | | 336 | */ |
337 | error = namei_simple_user(args->fspec, | | 337 | error = namei_simple_user(args->fspec, |
338 | NSM_FOLLOW_NOEMULROOT, &devvp); | | 338 | NSM_FOLLOW_NOEMULROOT, &devvp); |
339 | if (error != 0) | | 339 | if (error != 0) |
340 | return (error); | | 340 | return (error); |
341 | | | 341 | |
342 | if (!update) { | | 342 | if (!update) { |
343 | /* | | 343 | /* |
344 | * Be sure this is a valid block device | | 344 | * Be sure this is a valid block device |
345 | */ | | 345 | */ |
346 | if (devvp->v_type != VBLK) | | 346 | if (devvp->v_type != VBLK) |
347 | error = ENOTBLK; | | 347 | error = ENOTBLK; |
348 | else if (bdevsw_lookup(devvp->v_rdev) == NULL) | | 348 | else if (bdevsw_lookup(devvp->v_rdev) == NULL) |
349 | error = ENXIO; | | 349 | error = ENXIO; |
350 | } else { | | 350 | } else { |
351 | /* | | 351 | /* |
352 | * Be sure we're still naming the same device | | 352 | * Be sure we're still naming the same device |
353 | * used for our initial mount | | 353 | * used for our initial mount |
354 | */ | | 354 | */ |
355 | ump = VFSTOUFS(mp); | | 355 | ump = VFSTOUFS(mp); |
356 | if (devvp != ump->um_devvp) { | | 356 | if (devvp != ump->um_devvp) { |
357 | if (devvp->v_rdev != ump->um_devvp->v_rdev) | | 357 | if (devvp->v_rdev != ump->um_devvp->v_rdev) |
358 | error = EINVAL; | | 358 | error = EINVAL; |
359 | else { | | 359 | else { |
360 | vrele(devvp); | | 360 | vrele(devvp); |
361 | devvp = ump->um_devvp; | | 361 | devvp = ump->um_devvp; |
362 | vref(devvp); | | 362 | vref(devvp); |
363 | } | | 363 | } |
364 | } | | 364 | } |
365 | } | | 365 | } |
366 | } else { | | 366 | } else { |
367 | if (!update) { | | 367 | if (!update) { |
368 | /* New mounts must have a filename for the device */ | | 368 | /* New mounts must have a filename for the device */ |
369 | return (EINVAL); | | 369 | return (EINVAL); |
370 | } else { | | 370 | } else { |
371 | /* Use the extant mount */ | | 371 | /* Use the extant mount */ |
372 | ump = VFSTOUFS(mp); | | 372 | ump = VFSTOUFS(mp); |
373 | devvp = ump->um_devvp; | | 373 | devvp = ump->um_devvp; |
374 | vref(devvp); | | 374 | vref(devvp); |
375 | } | | 375 | } |
376 | } | | 376 | } |
377 | | | 377 | |
378 | /* | | 378 | /* |
379 | * If mount by non-root, then verify that user has necessary | | 379 | * If mount by non-root, then verify that user has necessary |
380 | * permissions on the device. | | 380 | * permissions on the device. |
381 | * | | 381 | * |
382 | * Permission to update a mount is checked higher, so here we presume | | 382 | * Permission to update a mount is checked higher, so here we presume |
383 | * updating the mount is okay (for example, as far as securelevel goes) | | 383 | * updating the mount is okay (for example, as far as securelevel goes) |
384 | * which leaves us with the normal check. | | 384 | * which leaves us with the normal check. |
385 | */ | | 385 | */ |
386 | if (error == 0) { | | 386 | if (error == 0) { |
387 | accessmode = VREAD; | | 387 | accessmode = VREAD; |
388 | if (update ? | | 388 | if (update ? |
389 | (mp->mnt_iflag & IMNT_WANTRDWR) != 0 : | | 389 | (mp->mnt_iflag & IMNT_WANTRDWR) != 0 : |
390 | (mp->mnt_flag & MNT_RDONLY) == 0) | | 390 | (mp->mnt_flag & MNT_RDONLY) == 0) |
391 | accessmode |= VWRITE; | | 391 | accessmode |= VWRITE; |
392 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 392 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
393 | error = genfs_can_mount(devvp, accessmode, l->l_cred); | | 393 | error = genfs_can_mount(devvp, accessmode, l->l_cred); |
394 | VOP_UNLOCK(devvp); | | 394 | VOP_UNLOCK(devvp); |
395 | } | | 395 | } |
396 | | | 396 | |
397 | if (error) { | | 397 | if (error) { |
398 | vrele(devvp); | | 398 | vrele(devvp); |
399 | return (error); | | 399 | return (error); |
400 | } | | 400 | } |
401 | | | 401 | |
402 | #ifdef WAPBL | | 402 | #ifdef WAPBL |
403 | /* WAPBL can only be enabled on a r/w mount. */ | | 403 | /* WAPBL can only be enabled on a r/w mount. */ |
404 | if ((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) { | | 404 | if ((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) { |
405 | mp->mnt_flag &= ~MNT_LOG; | | 405 | mp->mnt_flag &= ~MNT_LOG; |
406 | } | | 406 | } |
407 | #else /* !WAPBL */ | | 407 | #else /* !WAPBL */ |
408 | mp->mnt_flag &= ~MNT_LOG; | | 408 | mp->mnt_flag &= ~MNT_LOG; |
409 | #endif /* !WAPBL */ | | 409 | #endif /* !WAPBL */ |
410 | | | 410 | |
411 | if (!update) { | | 411 | if (!update) { |
412 | int xflags; | | 412 | int xflags; |
413 | | | 413 | |
414 | if (mp->mnt_flag & MNT_RDONLY) | | 414 | if (mp->mnt_flag & MNT_RDONLY) |
415 | xflags = FREAD; | | 415 | xflags = FREAD; |
416 | else | | 416 | else |
417 | xflags = FREAD | FWRITE; | | 417 | xflags = FREAD | FWRITE; |
418 | error = VOP_OPEN(devvp, xflags, FSCRED); | | 418 | error = VOP_OPEN(devvp, xflags, FSCRED); |
419 | if (error) | | 419 | if (error) |
420 | goto fail; | | 420 | goto fail; |
421 | error = ffs_mountfs(devvp, mp, l); | | 421 | error = ffs_mountfs(devvp, mp, l); |
422 | if (error) { | | 422 | if (error) { |
423 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 423 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
424 | (void)VOP_CLOSE(devvp, xflags, NOCRED); | | 424 | (void)VOP_CLOSE(devvp, xflags, NOCRED); |
425 | VOP_UNLOCK(devvp); | | 425 | VOP_UNLOCK(devvp); |
426 | goto fail; | | 426 | goto fail; |
427 | } | | 427 | } |
428 | | | 428 | |
429 | ump = VFSTOUFS(mp); | | 429 | ump = VFSTOUFS(mp); |
430 | fs = ump->um_fs; | | 430 | fs = ump->um_fs; |
431 | } else { | | 431 | } else { |
432 | /* | | 432 | /* |
433 | * Update the mount. | | 433 | * Update the mount. |
434 | */ | | 434 | */ |
435 | | | 435 | |
436 | /* | | 436 | /* |
437 | * The initial mount got a reference on this | | 437 | * The initial mount got a reference on this |
438 | * device, so drop the one obtained via | | 438 | * device, so drop the one obtained via |
439 | * namei(), above. | | 439 | * namei(), above. |
440 | */ | | 440 | */ |
441 | vrele(devvp); | | 441 | vrele(devvp); |
442 | | | 442 | |
443 | ump = VFSTOUFS(mp); | | 443 | ump = VFSTOUFS(mp); |
444 | fs = ump->um_fs; | | 444 | fs = ump->um_fs; |
445 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { | | 445 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { |
446 | /* | | 446 | /* |
447 | * Changing from r/w to r/o | | 447 | * Changing from r/w to r/o |
448 | */ | | 448 | */ |
449 | flags = WRITECLOSE; | | 449 | flags = WRITECLOSE; |
450 | if (mp->mnt_flag & MNT_FORCE) | | 450 | if (mp->mnt_flag & MNT_FORCE) |
451 | flags |= FORCECLOSE; | | 451 | flags |= FORCECLOSE; |
452 | error = ffs_flushfiles(mp, flags, l); | | 452 | error = ffs_flushfiles(mp, flags, l); |
453 | if (error == 0) | | 453 | if (error == 0) |
454 | error = UFS_WAPBL_BEGIN(mp); | | 454 | error = UFS_WAPBL_BEGIN(mp); |
455 | if (error == 0 && | | 455 | if (error == 0 && |
456 | ffs_cgupdate(ump, MNT_WAIT) == 0 && | | 456 | ffs_cgupdate(ump, MNT_WAIT) == 0 && |
457 | fs->fs_clean & FS_WASCLEAN) { | | 457 | fs->fs_clean & FS_WASCLEAN) { |
458 | if (mp->mnt_flag & MNT_SOFTDEP) | | 458 | if (mp->mnt_flag & MNT_SOFTDEP) |
459 | fs->fs_flags &= ~FS_DOSOFTDEP; | | 459 | fs->fs_flags &= ~FS_DOSOFTDEP; |
460 | fs->fs_clean = FS_ISCLEAN; | | 460 | fs->fs_clean = FS_ISCLEAN; |
461 | (void) ffs_sbupdate(ump, MNT_WAIT); | | 461 | (void) ffs_sbupdate(ump, MNT_WAIT); |
462 | } | | 462 | } |
463 | if (error == 0) | | 463 | if (error == 0) |
464 | UFS_WAPBL_END(mp); | | 464 | UFS_WAPBL_END(mp); |
465 | if (error) | | 465 | if (error) |
466 | return (error); | | 466 | return (error); |
467 | } | | 467 | } |
468 | | | 468 | |
469 | #ifdef WAPBL | | 469 | #ifdef WAPBL |
470 | if ((mp->mnt_flag & MNT_LOG) == 0) { | | 470 | if ((mp->mnt_flag & MNT_LOG) == 0) { |
471 | error = ffs_wapbl_stop(mp, mp->mnt_flag & MNT_FORCE); | | 471 | error = ffs_wapbl_stop(mp, mp->mnt_flag & MNT_FORCE); |
472 | if (error) | | 472 | if (error) |
473 | return error; | | 473 | return error; |
474 | } | | 474 | } |
475 | #endif /* WAPBL */ | | 475 | #endif /* WAPBL */ |
476 | | | 476 | |
477 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { | | 477 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { |
478 | /* | | 478 | /* |
479 | * Finish change from r/w to r/o | | 479 | * Finish change from r/w to r/o |
480 | */ | | 480 | */ |
481 | fs->fs_ronly = 1; | | 481 | fs->fs_ronly = 1; |
482 | fs->fs_fmod = 0; | | 482 | fs->fs_fmod = 0; |
483 | } | | 483 | } |
484 | | | 484 | |
485 | if (mp->mnt_flag & MNT_RELOAD) { | | 485 | if (mp->mnt_flag & MNT_RELOAD) { |
486 | error = ffs_reload(mp, l->l_cred, l); | | 486 | error = ffs_reload(mp, l->l_cred, l); |
487 | if (error) | | 487 | if (error) |
488 | return (error); | | 488 | return (error); |
489 | } | | 489 | } |
490 | | | 490 | |
491 | if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) { | | 491 | if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) { |
492 | /* | | 492 | /* |
493 | * Changing from read-only to read/write | | 493 | * Changing from read-only to read/write |
494 | */ | | 494 | */ |
495 | fs->fs_ronly = 0; | | 495 | fs->fs_ronly = 0; |
496 | fs->fs_clean <<= 1; | | 496 | fs->fs_clean <<= 1; |
497 | fs->fs_fmod = 1; | | 497 | fs->fs_fmod = 1; |
498 | #ifdef WAPBL | | 498 | #ifdef WAPBL |
499 | if (fs->fs_flags & FS_DOWAPBL) { | | 499 | if (fs->fs_flags & FS_DOWAPBL) { |
500 | printf("%s: replaying log to disk\n", | | 500 | printf("%s: replaying log to disk\n", |
501 | fs->fs_fsmnt); | | 501 | fs->fs_fsmnt); |
502 | KDASSERT(mp->mnt_wapbl_replay); | | 502 | KDASSERT(mp->mnt_wapbl_replay); |
503 | error = wapbl_replay_write(mp->mnt_wapbl_replay, | | 503 | error = wapbl_replay_write(mp->mnt_wapbl_replay, |
504 | devvp); | | 504 | devvp); |
505 | if (error) { | | 505 | if (error) { |
506 | return error; | | 506 | return error; |
507 | } | | 507 | } |
508 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 508 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
509 | fs->fs_clean = FS_WASCLEAN; | | 509 | fs->fs_clean = FS_WASCLEAN; |
510 | } | | 510 | } |
511 | #endif /* WAPBL */ | | 511 | #endif /* WAPBL */ |
512 | if (fs->fs_snapinum[0] != 0) | | 512 | if (fs->fs_snapinum[0] != 0) |
513 | ffs_snapshot_mount(mp); | | 513 | ffs_snapshot_mount(mp); |
514 | } | | 514 | } |
515 | | | 515 | |
516 | #ifdef WAPBL | | 516 | #ifdef WAPBL |
517 | error = ffs_wapbl_start(mp); | | 517 | error = ffs_wapbl_start(mp); |
518 | if (error) | | 518 | if (error) |
519 | return error; | | 519 | return error; |
520 | #endif /* WAPBL */ | | 520 | #endif /* WAPBL */ |
521 | | | 521 | |
522 | if (args->fspec == NULL) | | 522 | if (args->fspec == NULL) |
523 | return 0; | | 523 | return 0; |
524 | } | | 524 | } |
525 | | | 525 | |
526 | error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, | | 526 | error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, |
527 | UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); | | 527 | UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); |
528 | if (error == 0) | | 528 | if (error == 0) |
529 | (void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, | | 529 | (void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, |
530 | sizeof(fs->fs_fsmnt)); | | 530 | sizeof(fs->fs_fsmnt)); |
531 | fs->fs_flags &= ~FS_DOSOFTDEP; | | 531 | fs->fs_flags &= ~FS_DOSOFTDEP; |
532 | if (fs->fs_fmod != 0) { /* XXX */ | | 532 | if (fs->fs_fmod != 0) { /* XXX */ |
533 | int err; | | 533 | int err; |
534 | | | 534 | |
535 | fs->fs_fmod = 0; | | 535 | fs->fs_fmod = 0; |
536 | if (fs->fs_clean & FS_WASCLEAN) | | 536 | if (fs->fs_clean & FS_WASCLEAN) |
537 | fs->fs_time = time_second; | | 537 | fs->fs_time = time_second; |
538 | else { | | 538 | else { |
539 | printf("%s: file system not clean (fs_clean=%#x); " | | 539 | printf("%s: file system not clean (fs_clean=%#x); " |
540 | "please fsck(8)\n", mp->mnt_stat.f_mntfromname, | | 540 | "please fsck(8)\n", mp->mnt_stat.f_mntfromname, |
541 | fs->fs_clean); | | 541 | fs->fs_clean); |
542 | printf("%s: lost blocks %" PRId64 " files %d\n", | | 542 | printf("%s: lost blocks %" PRId64 " files %d\n", |
543 | mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks, | | 543 | mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks, |
544 | fs->fs_pendinginodes); | | 544 | fs->fs_pendinginodes); |
545 | } | | 545 | } |
546 | err = UFS_WAPBL_BEGIN(mp); | | 546 | err = UFS_WAPBL_BEGIN(mp); |
547 | if (err == 0) { | | 547 | if (err == 0) { |
548 | (void) ffs_cgupdate(ump, MNT_WAIT); | | 548 | (void) ffs_cgupdate(ump, MNT_WAIT); |
549 | UFS_WAPBL_END(mp); | | 549 | UFS_WAPBL_END(mp); |
550 | } | | 550 | } |
551 | } | | 551 | } |
552 | if ((mp->mnt_flag & MNT_SOFTDEP) != 0) { | | 552 | if ((mp->mnt_flag & MNT_SOFTDEP) != 0) { |
553 | printf("%s: `-o softdep' is no longer supported, " | | 553 | printf("%s: `-o softdep' is no longer supported, " |
554 | "consider `-o log'\n", mp->mnt_stat.f_mntfromname); | | 554 | "consider `-o log'\n", mp->mnt_stat.f_mntfromname); |
555 | mp->mnt_flag &= ~MNT_SOFTDEP; | | 555 | mp->mnt_flag &= ~MNT_SOFTDEP; |
556 | } | | 556 | } |
557 | | | 557 | |
558 | return (error); | | 558 | return (error); |
559 | | | 559 | |
560 | fail: | | 560 | fail: |
561 | vrele(devvp); | | 561 | vrele(devvp); |
562 | return (error); | | 562 | return (error); |
563 | } | | 563 | } |
564 | | | 564 | |
565 | /* | | 565 | /* |
566 | * Reload all incore data for a filesystem (used after running fsck on | | 566 | * Reload all incore data for a filesystem (used after running fsck on |
567 | * the root filesystem and finding things to fix). The filesystem must | | 567 | * the root filesystem and finding things to fix). The filesystem must |
568 | * be mounted read-only. | | 568 | * be mounted read-only. |
569 | * | | 569 | * |
570 | * Things to do to update the mount: | | 570 | * Things to do to update the mount: |
571 | * 1) invalidate all cached meta-data. | | 571 | * 1) invalidate all cached meta-data. |
572 | * 2) re-read superblock from disk. | | 572 | * 2) re-read superblock from disk. |
573 | * 3) re-read summary information from disk. | | 573 | * 3) re-read summary information from disk. |
574 | * 4) invalidate all inactive vnodes. | | 574 | * 4) invalidate all inactive vnodes. |
575 | * 5) invalidate all cached file data. | | 575 | * 5) invalidate all cached file data. |
576 | * 6) re-read inode data for all active vnodes. | | 576 | * 6) re-read inode data for all active vnodes. |
577 | */ | | 577 | */ |
578 | int | | 578 | int |
579 | ffs_reload(struct mount *mp, kauth_cred_t cred, struct lwp *l) | | 579 | ffs_reload(struct mount *mp, kauth_cred_t cred, struct lwp *l) |
580 | { | | 580 | { |
581 | struct vnode *vp, *mvp, *devvp; | | 581 | struct vnode *vp, *mvp, *devvp; |
582 | struct inode *ip; | | 582 | struct inode *ip; |
583 | void *space; | | 583 | void *space; |
584 | struct buf *bp; | | 584 | struct buf *bp; |
585 | struct fs *fs, *newfs; | | 585 | struct fs *fs, *newfs; |
586 | struct partinfo dpart; | | 586 | struct partinfo dpart; |
587 | int i, bsize, blks, error; | | 587 | int i, bsize, blks, error; |
588 | int32_t *lp; | | 588 | int32_t *lp; |
589 | struct ufsmount *ump; | | 589 | struct ufsmount *ump; |
590 | daddr_t sblockloc; | | 590 | daddr_t sblockloc; |
591 | | | 591 | |
592 | if ((mp->mnt_flag & MNT_RDONLY) == 0) | | 592 | if ((mp->mnt_flag & MNT_RDONLY) == 0) |
593 | return (EINVAL); | | 593 | return (EINVAL); |
594 | | | 594 | |
595 | ump = VFSTOUFS(mp); | | 595 | ump = VFSTOUFS(mp); |
596 | /* | | 596 | /* |
597 | * Step 1: invalidate all cached meta-data. | | 597 | * Step 1: invalidate all cached meta-data. |
598 | */ | | 598 | */ |
599 | devvp = ump->um_devvp; | | 599 | devvp = ump->um_devvp; |
600 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 600 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
601 | error = vinvalbuf(devvp, 0, cred, l, 0, 0); | | 601 | error = vinvalbuf(devvp, 0, cred, l, 0, 0); |
602 | VOP_UNLOCK(devvp); | | 602 | VOP_UNLOCK(devvp); |
603 | if (error) | | 603 | if (error) |
604 | panic("ffs_reload: dirty1"); | | 604 | panic("ffs_reload: dirty1"); |
605 | /* | | 605 | /* |
606 | * Step 2: re-read superblock from disk. | | 606 | * Step 2: re-read superblock from disk. |
607 | */ | | 607 | */ |
608 | fs = ump->um_fs; | | 608 | fs = ump->um_fs; |
609 | | | 609 | |
610 | /* XXX we don't handle possibility that superblock moved. */ | | 610 | /* XXX we don't handle possibility that superblock moved. */ |
611 | error = bread(devvp, fs->fs_sblockloc / DEV_BSIZE, fs->fs_sbsize, | | 611 | error = bread(devvp, fs->fs_sblockloc / DEV_BSIZE, fs->fs_sbsize, |
612 | NOCRED, 0, &bp); | | 612 | NOCRED, 0, &bp); |
613 | if (error) { | | 613 | if (error) { |
614 | brelse(bp, 0); | | 614 | brelse(bp, 0); |
615 | return (error); | | 615 | return (error); |
616 | } | | 616 | } |
617 | newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK); | | 617 | newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK); |
618 | memcpy(newfs, bp->b_data, fs->fs_sbsize); | | 618 | memcpy(newfs, bp->b_data, fs->fs_sbsize); |
619 | #ifdef FFS_EI | | 619 | #ifdef FFS_EI |
620 | if (ump->um_flags & UFS_NEEDSWAP) { | | 620 | if (ump->um_flags & UFS_NEEDSWAP) { |
621 | ffs_sb_swap((struct fs*)bp->b_data, newfs); | | 621 | ffs_sb_swap((struct fs*)bp->b_data, newfs); |
622 | fs->fs_flags |= FS_SWAPPED; | | 622 | fs->fs_flags |= FS_SWAPPED; |
623 | } else | | 623 | } else |
624 | #endif | | 624 | #endif |
625 | fs->fs_flags &= ~FS_SWAPPED; | | 625 | fs->fs_flags &= ~FS_SWAPPED; |
626 | if ((newfs->fs_magic != FS_UFS1_MAGIC && | | 626 | if ((newfs->fs_magic != FS_UFS1_MAGIC && |
627 | newfs->fs_magic != FS_UFS2_MAGIC)|| | | 627 | newfs->fs_magic != FS_UFS2_MAGIC)|| |
628 | newfs->fs_bsize > MAXBSIZE || | | 628 | newfs->fs_bsize > MAXBSIZE || |
629 | newfs->fs_bsize < sizeof(struct fs)) { | | 629 | newfs->fs_bsize < sizeof(struct fs)) { |
630 | brelse(bp, 0); | | 630 | brelse(bp, 0); |
631 | free(newfs, M_UFSMNT); | | 631 | free(newfs, M_UFSMNT); |
632 | return (EIO); /* XXX needs translation */ | | 632 | return (EIO); /* XXX needs translation */ |
633 | } | | 633 | } |
634 | /* Store off old fs_sblockloc for fs_oldfscompat_read. */ | | 634 | /* Store off old fs_sblockloc for fs_oldfscompat_read. */ |
635 | sblockloc = fs->fs_sblockloc; | | 635 | sblockloc = fs->fs_sblockloc; |
636 | /* | | 636 | /* |
637 | * Copy pointer fields back into superblock before copying in XXX | | 637 | * Copy pointer fields back into superblock before copying in XXX |
638 | * new superblock. These should really be in the ufsmount. XXX | | 638 | * new superblock. These should really be in the ufsmount. XXX |
639 | * Note that important parameters (eg fs_ncg) are unchanged. | | 639 | * Note that important parameters (eg fs_ncg) are unchanged. |
640 | */ | | 640 | */ |
641 | newfs->fs_csp = fs->fs_csp; | | 641 | newfs->fs_csp = fs->fs_csp; |
642 | newfs->fs_maxcluster = fs->fs_maxcluster; | | 642 | newfs->fs_maxcluster = fs->fs_maxcluster; |
643 | newfs->fs_contigdirs = fs->fs_contigdirs; | | 643 | newfs->fs_contigdirs = fs->fs_contigdirs; |
644 | newfs->fs_ronly = fs->fs_ronly; | | 644 | newfs->fs_ronly = fs->fs_ronly; |
645 | newfs->fs_active = fs->fs_active; | | 645 | newfs->fs_active = fs->fs_active; |
646 | memcpy(fs, newfs, (u_int)fs->fs_sbsize); | | 646 | memcpy(fs, newfs, (u_int)fs->fs_sbsize); |
647 | brelse(bp, 0); | | 647 | brelse(bp, 0); |
648 | free(newfs, M_UFSMNT); | | 648 | free(newfs, M_UFSMNT); |
649 | | | 649 | |
650 | /* Recheck for apple UFS filesystem */ | | 650 | /* Recheck for apple UFS filesystem */ |
651 | ump->um_flags &= ~UFS_ISAPPLEUFS; | | 651 | ump->um_flags &= ~UFS_ISAPPLEUFS; |
652 | /* First check to see if this is tagged as an Apple UFS filesystem | | 652 | /* First check to see if this is tagged as an Apple UFS filesystem |
653 | * in the disklabel | | 653 | * in the disklabel |
654 | */ | | 654 | */ |
655 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && | | 655 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && |
656 | (dpart.part->p_fstype == FS_APPLEUFS)) { | | 656 | (dpart.part->p_fstype == FS_APPLEUFS)) { |
657 | ump->um_flags |= UFS_ISAPPLEUFS; | | 657 | ump->um_flags |= UFS_ISAPPLEUFS; |
658 | } | | 658 | } |
659 | #ifdef APPLE_UFS | | 659 | #ifdef APPLE_UFS |
660 | else { | | 660 | else { |
661 | /* Manually look for an apple ufs label, and if a valid one | | 661 | /* Manually look for an apple ufs label, and if a valid one |
662 | * is found, then treat it like an Apple UFS filesystem anyway | | 662 | * is found, then treat it like an Apple UFS filesystem anyway |
663 | */ | | 663 | */ |
664 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE), | | 664 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE), |
665 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); | | 665 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); |
666 | if (error) { | | 666 | if (error) { |
667 | brelse(bp, 0); | | 667 | brelse(bp, 0); |
668 | return (error); | | 668 | return (error); |
669 | } | | 669 | } |
670 | error = ffs_appleufs_validate(fs->fs_fsmnt, | | 670 | error = ffs_appleufs_validate(fs->fs_fsmnt, |
671 | (struct appleufslabel *)bp->b_data, NULL); | | 671 | (struct appleufslabel *)bp->b_data, NULL); |
672 | if (error == 0) | | 672 | if (error == 0) |
673 | ump->um_flags |= UFS_ISAPPLEUFS; | | 673 | ump->um_flags |= UFS_ISAPPLEUFS; |
674 | brelse(bp, 0); | | 674 | brelse(bp, 0); |
675 | bp = NULL; | | 675 | bp = NULL; |
676 | } | | 676 | } |
677 | #else | | 677 | #else |
678 | if (ump->um_flags & UFS_ISAPPLEUFS) | | 678 | if (ump->um_flags & UFS_ISAPPLEUFS) |
679 | return (EIO); | | 679 | return (EIO); |
680 | #endif | | 680 | #endif |
681 | | | 681 | |
682 | if (UFS_MPISAPPLEUFS(ump)) { | | 682 | if (UFS_MPISAPPLEUFS(ump)) { |
683 | /* see comment about NeXT below */ | | 683 | /* see comment about NeXT below */ |
684 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; | | 684 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; |
685 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; | | 685 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; |
686 | mp->mnt_iflag |= IMNT_DTYPE; | | 686 | mp->mnt_iflag |= IMNT_DTYPE; |
687 | } else { | | 687 | } else { |
688 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; | | 688 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; |
689 | ump->um_dirblksiz = DIRBLKSIZ; | | 689 | ump->um_dirblksiz = DIRBLKSIZ; |
690 | if (ump->um_maxsymlinklen > 0) | | 690 | if (ump->um_maxsymlinklen > 0) |
691 | mp->mnt_iflag |= IMNT_DTYPE; | | 691 | mp->mnt_iflag |= IMNT_DTYPE; |
692 | else | | 692 | else |
693 | mp->mnt_iflag &= ~IMNT_DTYPE; | | 693 | mp->mnt_iflag &= ~IMNT_DTYPE; |
694 | } | | 694 | } |
695 | ffs_oldfscompat_read(fs, ump, sblockloc); | | 695 | ffs_oldfscompat_read(fs, ump, sblockloc); |
696 | | | 696 | |
697 | mutex_enter(&ump->um_lock); | | 697 | mutex_enter(&ump->um_lock); |
698 | ump->um_maxfilesize = fs->fs_maxfilesize; | | 698 | ump->um_maxfilesize = fs->fs_maxfilesize; |
699 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { | | 699 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { |
700 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", | | 700 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", |
701 | mp->mnt_stat.f_mntonname, fs->fs_flags, | | 701 | mp->mnt_stat.f_mntonname, fs->fs_flags, |
702 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); | | 702 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); |
703 | if ((mp->mnt_flag & MNT_FORCE) == 0) { | | 703 | if ((mp->mnt_flag & MNT_FORCE) == 0) { |
704 | mutex_exit(&ump->um_lock); | | 704 | mutex_exit(&ump->um_lock); |
705 | return (EINVAL); | | 705 | return (EINVAL); |
706 | } | | 706 | } |
707 | } | | 707 | } |
708 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { | | 708 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { |
709 | fs->fs_pendingblocks = 0; | | 709 | fs->fs_pendingblocks = 0; |
710 | fs->fs_pendinginodes = 0; | | 710 | fs->fs_pendinginodes = 0; |
711 | } | | 711 | } |
712 | mutex_exit(&ump->um_lock); | | 712 | mutex_exit(&ump->um_lock); |
713 | | | 713 | |
714 | ffs_statvfs(mp, &mp->mnt_stat); | | 714 | ffs_statvfs(mp, &mp->mnt_stat); |
715 | /* | | 715 | /* |
716 | * Step 3: re-read summary information from disk. | | 716 | * Step 3: re-read summary information from disk. |
717 | */ | | 717 | */ |
718 | blks = howmany(fs->fs_cssize, fs->fs_fsize); | | 718 | blks = howmany(fs->fs_cssize, fs->fs_fsize); |
719 | space = fs->fs_csp; | | 719 | space = fs->fs_csp; |
720 | for (i = 0; i < blks; i += fs->fs_frag) { | | 720 | for (i = 0; i < blks; i += fs->fs_frag) { |
721 | bsize = fs->fs_bsize; | | 721 | bsize = fs->fs_bsize; |
722 | if (i + fs->fs_frag > blks) | | 722 | if (i + fs->fs_frag > blks) |
723 | bsize = (blks - i) * fs->fs_fsize; | | 723 | bsize = (blks - i) * fs->fs_fsize; |
724 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), bsize, | | 724 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), bsize, |
725 | NOCRED, 0, &bp); | | 725 | NOCRED, 0, &bp); |
726 | if (error) { | | 726 | if (error) { |
727 | brelse(bp, 0); | | 727 | brelse(bp, 0); |
728 | return (error); | | 728 | return (error); |
729 | } | | 729 | } |
730 | #ifdef FFS_EI | | 730 | #ifdef FFS_EI |
731 | if (UFS_FSNEEDSWAP(fs)) | | 731 | if (UFS_FSNEEDSWAP(fs)) |
732 | ffs_csum_swap((struct csum *)bp->b_data, | | 732 | ffs_csum_swap((struct csum *)bp->b_data, |
733 | (struct csum *)space, bsize); | | 733 | (struct csum *)space, bsize); |
734 | else | | 734 | else |
735 | #endif | | 735 | #endif |
736 | memcpy(space, bp->b_data, (size_t)bsize); | | 736 | memcpy(space, bp->b_data, (size_t)bsize); |
737 | space = (char *)space + bsize; | | 737 | space = (char *)space + bsize; |
738 | brelse(bp, 0); | | 738 | brelse(bp, 0); |
739 | } | | 739 | } |
740 | if (fs->fs_snapinum[0] != 0) | | 740 | if (fs->fs_snapinum[0] != 0) |
741 | ffs_snapshot_mount(mp); | | 741 | ffs_snapshot_mount(mp); |
742 | /* | | 742 | /* |
743 | * We no longer know anything about clusters per cylinder group. | | 743 | * We no longer know anything about clusters per cylinder group. |
744 | */ | | 744 | */ |
745 | if (fs->fs_contigsumsize > 0) { | | 745 | if (fs->fs_contigsumsize > 0) { |
746 | lp = fs->fs_maxcluster; | | 746 | lp = fs->fs_maxcluster; |
747 | for (i = 0; i < fs->fs_ncg; i++) | | 747 | for (i = 0; i < fs->fs_ncg; i++) |
748 | *lp++ = fs->fs_contigsumsize; | | 748 | *lp++ = fs->fs_contigsumsize; |
749 | } | | 749 | } |
750 | | | 750 | |
751 | /* Allocate a marker vnode. */ | | 751 | /* Allocate a marker vnode. */ |
752 | if ((mvp = vnalloc(mp)) == NULL) | | 752 | if ((mvp = vnalloc(mp)) == NULL) |
753 | return ENOMEM; | | 753 | return ENOMEM; |
754 | /* | | 754 | /* |
755 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() | | 755 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() |
756 | * and vclean() can be called indirectly | | 756 | * and vclean() can be called indirectly |
757 | */ | | 757 | */ |
758 | mutex_enter(&mntvnode_lock); | | 758 | mutex_enter(&mntvnode_lock); |
759 | loop: | | 759 | loop: |
760 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { | | 760 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { |
761 | vmark(mvp, vp); | | 761 | vmark(mvp, vp); |
762 | if (vp->v_mount != mp || vismarker(vp)) | | 762 | if (vp->v_mount != mp || vismarker(vp)) |
763 | continue; | | 763 | continue; |
764 | /* | | 764 | /* |
765 | * Step 4: invalidate all inactive vnodes. | | 765 | * Step 4: invalidate all inactive vnodes. |
766 | */ | | 766 | */ |
767 | if (vrecycle(vp, &mntvnode_lock, l)) { | | 767 | if (vrecycle(vp, &mntvnode_lock, l)) { |
768 | mutex_enter(&mntvnode_lock); | | 768 | mutex_enter(&mntvnode_lock); |
769 | (void)vunmark(mvp); | | 769 | (void)vunmark(mvp); |
770 | goto loop; | | 770 | goto loop; |
771 | } | | 771 | } |
772 | /* | | 772 | /* |
773 | * Step 5: invalidate all cached file data. | | 773 | * Step 5: invalidate all cached file data. |
774 | */ | | 774 | */ |
775 | mutex_enter(&vp->v_interlock); | | 775 | mutex_enter(&vp->v_interlock); |
776 | mutex_exit(&mntvnode_lock); | | 776 | mutex_exit(&mntvnode_lock); |
777 | if (vget(vp, LK_EXCLUSIVE)) { | | 777 | if (vget(vp, LK_EXCLUSIVE)) { |
778 | (void)vunmark(mvp); | | 778 | (void)vunmark(mvp); |
779 | goto loop; | | 779 | goto loop; |
780 | } | | 780 | } |
781 | if (vinvalbuf(vp, 0, cred, l, 0, 0)) | | 781 | if (vinvalbuf(vp, 0, cred, l, 0, 0)) |
782 | panic("ffs_reload: dirty2"); | | 782 | panic("ffs_reload: dirty2"); |
783 | /* | | 783 | /* |
784 | * Step 6: re-read inode data for all active vnodes. | | 784 | * Step 6: re-read inode data for all active vnodes. |
785 | */ | | 785 | */ |
786 | ip = VTOI(vp); | | 786 | ip = VTOI(vp); |
787 | error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), | | 787 | error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), |
788 | (int)fs->fs_bsize, NOCRED, 0, &bp); | | 788 | (int)fs->fs_bsize, NOCRED, 0, &bp); |
789 | if (error) { | | 789 | if (error) { |
790 | brelse(bp, 0); | | 790 | brelse(bp, 0); |
791 | vput(vp); | | 791 | vput(vp); |
792 | (void)vunmark(mvp); | | 792 | (void)vunmark(mvp); |
793 | break; | | 793 | break; |
794 | } | | 794 | } |
795 | ffs_load_inode(bp, ip, fs, ip->i_number); | | 795 | ffs_load_inode(bp, ip, fs, ip->i_number); |
796 | brelse(bp, 0); | | 796 | brelse(bp, 0); |
797 | vput(vp); | | 797 | vput(vp); |
798 | mutex_enter(&mntvnode_lock); | | 798 | mutex_enter(&mntvnode_lock); |
799 | } | | 799 | } |
800 | mutex_exit(&mntvnode_lock); | | 800 | mutex_exit(&mntvnode_lock); |
801 | vnfree(mvp); | | 801 | vnfree(mvp); |
802 | return (error); | | 802 | return (error); |
803 | } | | 803 | } |
804 | | | 804 | |
805 | /* | | 805 | /* |
806 | * Possible superblock locations ordered from most to least likely. | | 806 | * Possible superblock locations ordered from most to least likely. |
807 | */ | | 807 | */ |
808 | static const int sblock_try[] = SBLOCKSEARCH; | | 808 | static const int sblock_try[] = SBLOCKSEARCH; |
809 | | | 809 | |
810 | /* | | 810 | /* |
811 | * Common code for mount and mountroot | | 811 | * Common code for mount and mountroot |
812 | */ | | 812 | */ |
813 | int | | 813 | int |
814 | ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) | | 814 | ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) |
815 | { | | 815 | { |
816 | struct ufsmount *ump; | | 816 | struct ufsmount *ump; |
817 | struct buf *bp; | | 817 | struct buf *bp; |
818 | struct fs *fs; | | 818 | struct fs *fs; |
819 | dev_t dev; | | 819 | dev_t dev; |
820 | struct partinfo dpart; | | 820 | struct partinfo dpart; |
821 | void *space; | | 821 | void *space; |
822 | daddr_t sblockloc, fsblockloc; | | 822 | daddr_t sblockloc, fsblockloc; |
823 | int blks, fstype; | | 823 | int blks, fstype; |
824 | int error, i, bsize, ronly, bset = 0; | | 824 | int error, i, bsize, ronly, bset = 0; |
825 | #ifdef FFS_EI | | 825 | #ifdef FFS_EI |
826 | int needswap = 0; /* keep gcc happy */ | | 826 | int needswap = 0; /* keep gcc happy */ |
827 | #endif | | 827 | #endif |
828 | int32_t *lp; | | 828 | int32_t *lp; |
829 | kauth_cred_t cred; | | 829 | kauth_cred_t cred; |
830 | u_int32_t sbsize = 8192; /* keep gcc happy*/ | | 830 | u_int32_t sbsize = 8192; /* keep gcc happy*/ |
| | | 831 | int32_t fsbsize; |
831 | | | 832 | |
832 | dev = devvp->v_rdev; | | 833 | dev = devvp->v_rdev; |
833 | cred = l ? l->l_cred : NOCRED; | | 834 | cred = l ? l->l_cred : NOCRED; |
834 | | | 835 | |
835 | /* Flush out any old buffers remaining from a previous use. */ | | 836 | /* Flush out any old buffers remaining from a previous use. */ |
836 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 837 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
837 | error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0); | | 838 | error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0); |
838 | VOP_UNLOCK(devvp); | | 839 | VOP_UNLOCK(devvp); |
839 | if (error) | | 840 | if (error) |
840 | return (error); | | 841 | return (error); |
841 | | | 842 | |
842 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | | 843 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; |
843 | | | 844 | |
844 | bp = NULL; | | 845 | bp = NULL; |
845 | ump = NULL; | | 846 | ump = NULL; |
846 | fs = NULL; | | 847 | fs = NULL; |
847 | sblockloc = 0; | | 848 | sblockloc = 0; |
848 | fstype = 0; | | 849 | fstype = 0; |
849 | | | 850 | |
850 | error = fstrans_mount(mp); | | 851 | error = fstrans_mount(mp); |
851 | if (error) | | 852 | if (error) |
852 | return error; | | 853 | return error; |
853 | | | 854 | |
854 | ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK); | | 855 | ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK); |
855 | memset(ump, 0, sizeof *ump); | | 856 | memset(ump, 0, sizeof *ump); |
856 | mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE); | | 857 | mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE); |
857 | error = ffs_snapshot_init(ump); | | 858 | error = ffs_snapshot_init(ump); |
858 | if (error) | | 859 | if (error) |
859 | goto out; | | 860 | goto out; |
860 | ump->um_ops = &ffs_ufsops; | | 861 | ump->um_ops = &ffs_ufsops; |
861 | | | 862 | |
862 | #ifdef WAPBL | | 863 | #ifdef WAPBL |
863 | sbagain: | | 864 | sbagain: |
864 | #endif | | 865 | #endif |
865 | /* | | 866 | /* |
866 | * Try reading the superblock in each of its possible locations. | | 867 | * Try reading the superblock in each of its possible locations. |
867 | */ | | 868 | */ |
868 | for (i = 0; ; i++) { | | 869 | for (i = 0; ; i++) { |
869 | if (bp != NULL) { | | 870 | if (bp != NULL) { |
870 | brelse(bp, BC_NOCACHE); | | 871 | brelse(bp, BC_NOCACHE); |
871 | bp = NULL; | | 872 | bp = NULL; |
872 | } | | 873 | } |
873 | if (sblock_try[i] == -1) { | | 874 | if (sblock_try[i] == -1) { |
874 | error = EINVAL; | | 875 | error = EINVAL; |
875 | fs = NULL; | | 876 | fs = NULL; |
876 | goto out; | | 877 | goto out; |
877 | } | | 878 | } |
878 | error = bread(devvp, sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, cred, | | 879 | error = bread(devvp, sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, cred, |
879 | 0, &bp); | | 880 | 0, &bp); |
880 | if (error) { | | 881 | if (error) { |
881 | fs = NULL; | | 882 | fs = NULL; |
882 | goto out; | | 883 | goto out; |
883 | } | | 884 | } |
884 | fs = (struct fs*)bp->b_data; | | 885 | fs = (struct fs*)bp->b_data; |
885 | fsblockloc = sblockloc = sblock_try[i]; | | 886 | fsblockloc = sblockloc = sblock_try[i]; |
886 | if (fs->fs_magic == FS_UFS1_MAGIC) { | | 887 | if (fs->fs_magic == FS_UFS1_MAGIC) { |
887 | sbsize = fs->fs_sbsize; | | 888 | sbsize = fs->fs_sbsize; |
888 | fstype = UFS1; | | 889 | fstype = UFS1; |
| | | 890 | fsbsize = fs->fs_bsize; |
889 | #ifdef FFS_EI | | 891 | #ifdef FFS_EI |
890 | needswap = 0; | | 892 | needswap = 0; |
891 | } else if (fs->fs_magic == bswap32(FS_UFS1_MAGIC)) { | | 893 | } else if (fs->fs_magic == bswap32(FS_UFS1_MAGIC)) { |
892 | sbsize = bswap32(fs->fs_sbsize); | | 894 | sbsize = bswap32(fs->fs_sbsize); |
893 | fstype = UFS1; | | 895 | fstype = UFS1; |
| | | 896 | fsbsize = bswap32(fs->fs_bsize); |
894 | needswap = 1; | | 897 | needswap = 1; |
895 | #endif | | 898 | #endif |
896 | } else if (fs->fs_magic == FS_UFS2_MAGIC) { | | 899 | } else if (fs->fs_magic == FS_UFS2_MAGIC) { |
897 | sbsize = fs->fs_sbsize; | | 900 | sbsize = fs->fs_sbsize; |
898 | fstype = UFS2; | | 901 | fstype = UFS2; |
| | | 902 | fsbsize = fs->fs_bsize; |
899 | #ifdef FFS_EI | | 903 | #ifdef FFS_EI |
900 | needswap = 0; | | 904 | needswap = 0; |
901 | } else if (fs->fs_magic == bswap32(FS_UFS2_MAGIC)) { | | 905 | } else if (fs->fs_magic == bswap32(FS_UFS2_MAGIC)) { |
902 | sbsize = bswap32(fs->fs_sbsize); | | 906 | sbsize = bswap32(fs->fs_sbsize); |
903 | fstype = UFS2; | | 907 | fstype = UFS2; |
| | | 908 | fsbsize = bswap32(fs->fs_bsize); |
904 | needswap = 1; | | 909 | needswap = 1; |
905 | #endif | | 910 | #endif |
906 | } else | | 911 | } else |
907 | continue; | | 912 | continue; |
908 | | | 913 | |
909 | | | 914 | |
910 | /* fs->fs_sblockloc isn't defined for old filesystems */ | | 915 | /* fs->fs_sblockloc isn't defined for old filesystems */ |
911 | if (fstype == UFS1 && !(fs->fs_old_flags & FS_FLAGS_UPDATED)) { | | 916 | if (fstype == UFS1 && !(fs->fs_old_flags & FS_FLAGS_UPDATED)) { |
912 | if (sblockloc == SBLOCK_UFS2) | | 917 | if (sblockloc == SBLOCK_UFS2) |
913 | /* | | 918 | /* |
914 | * This is likely to be the first alternate | | 919 | * This is likely to be the first alternate |
915 | * in a filesystem with 64k blocks. | | 920 | * in a filesystem with 64k blocks. |
916 | * Don't use it. | | 921 | * Don't use it. |
917 | */ | | 922 | */ |
918 | continue; | | 923 | continue; |
919 | fsblockloc = sblockloc; | | 924 | fsblockloc = sblockloc; |
920 | } else { | | 925 | } else { |
921 | fsblockloc = fs->fs_sblockloc; | | 926 | fsblockloc = fs->fs_sblockloc; |
922 | #ifdef FFS_EI | | 927 | #ifdef FFS_EI |
923 | if (needswap) | | 928 | if (needswap) |
924 | fsblockloc = bswap64(fsblockloc); | | 929 | fsblockloc = bswap64(fsblockloc); |
925 | #endif | | 930 | #endif |
926 | } | | 931 | } |
927 | | | 932 | |
928 | /* Check we haven't found an alternate superblock */ | | 933 | /* Check we haven't found an alternate superblock */ |
929 | if (fsblockloc != sblockloc) | | 934 | if (fsblockloc != sblockloc) |
930 | continue; | | 935 | continue; |
931 | | | 936 | |
932 | /* Validate size of superblock */ | | 937 | /* Validate size of superblock */ |
933 | if (sbsize > MAXBSIZE || sbsize < sizeof(struct fs)) | | 938 | if (sbsize > MAXBSIZE || sbsize < sizeof(struct fs)) |
934 | continue; | | 939 | continue; |
935 | | | 940 | |
| | | 941 | /* Check that we can handle the file system blocksize */ |
| | | 942 | if (fsbsize > MAXBSIZE) { |
| | | 943 | printf("ffs_mountfs: block size (%d) > MAXBSIZE (%d)", |
| | | 944 | fsbsize, MAXBSIZE); |
| | | 945 | continue; |
| | | 946 | } |
| | | 947 | |
936 | /* Ok seems to be a good superblock */ | | 948 | /* Ok seems to be a good superblock */ |
937 | break; | | 949 | break; |
938 | } | | 950 | } |
939 | | | 951 | |
940 | fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK); | | 952 | fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK); |
941 | memcpy(fs, bp->b_data, sbsize); | | 953 | memcpy(fs, bp->b_data, sbsize); |
942 | ump->um_fs = fs; | | 954 | ump->um_fs = fs; |
943 | | | 955 | |
944 | #ifdef FFS_EI | | 956 | #ifdef FFS_EI |
945 | if (needswap) { | | 957 | if (needswap) { |
946 | ffs_sb_swap((struct fs*)bp->b_data, fs); | | 958 | ffs_sb_swap((struct fs*)bp->b_data, fs); |
947 | fs->fs_flags |= FS_SWAPPED; | | 959 | fs->fs_flags |= FS_SWAPPED; |
948 | } else | | 960 | } else |
949 | #endif | | 961 | #endif |
950 | fs->fs_flags &= ~FS_SWAPPED; | | 962 | fs->fs_flags &= ~FS_SWAPPED; |
951 | | | 963 | |
952 | #ifdef WAPBL | | 964 | #ifdef WAPBL |
953 | if ((mp->mnt_wapbl_replay == 0) && (fs->fs_flags & FS_DOWAPBL)) { | | 965 | if ((mp->mnt_wapbl_replay == 0) && (fs->fs_flags & FS_DOWAPBL)) { |
954 | error = ffs_wapbl_replay_start(mp, fs, devvp); | | 966 | error = ffs_wapbl_replay_start(mp, fs, devvp); |
955 | if (error && (mp->mnt_flag & MNT_FORCE) == 0) | | 967 | if (error && (mp->mnt_flag & MNT_FORCE) == 0) |
956 | goto out; | | 968 | goto out; |
957 | if (!error) { | | 969 | if (!error) { |
958 | if (!ronly) { | | 970 | if (!ronly) { |
959 | /* XXX fsmnt may be stale. */ | | 971 | /* XXX fsmnt may be stale. */ |
960 | printf("%s: replaying log to disk\n", | | 972 | printf("%s: replaying log to disk\n", |
961 | fs->fs_fsmnt); | | 973 | fs->fs_fsmnt); |
962 | error = wapbl_replay_write(mp->mnt_wapbl_replay, | | 974 | error = wapbl_replay_write(mp->mnt_wapbl_replay, |
963 | devvp); | | 975 | devvp); |
964 | if (error) | | 976 | if (error) |
965 | goto out; | | 977 | goto out; |
966 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 978 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
967 | fs->fs_clean = FS_WASCLEAN; | | 979 | fs->fs_clean = FS_WASCLEAN; |
968 | } else { | | 980 | } else { |
969 | /* XXX fsmnt may be stale */ | | 981 | /* XXX fsmnt may be stale */ |
970 | printf("%s: replaying log to memory\n", | | 982 | printf("%s: replaying log to memory\n", |
971 | fs->fs_fsmnt); | | 983 | fs->fs_fsmnt); |
972 | } | | 984 | } |
973 | | | 985 | |
974 | /* Force a re-read of the superblock */ | | 986 | /* Force a re-read of the superblock */ |
975 | brelse(bp, BC_INVAL); | | 987 | brelse(bp, BC_INVAL); |
976 | bp = NULL; | | 988 | bp = NULL; |
977 | free(fs, M_UFSMNT); | | 989 | free(fs, M_UFSMNT); |
978 | fs = NULL; | | 990 | fs = NULL; |
979 | goto sbagain; | | 991 | goto sbagain; |
980 | } | | 992 | } |
981 | } | | 993 | } |
982 | #else /* !WAPBL */ | | 994 | #else /* !WAPBL */ |
983 | if ((fs->fs_flags & FS_DOWAPBL) && (mp->mnt_flag & MNT_FORCE) == 0) { | | 995 | if ((fs->fs_flags & FS_DOWAPBL) && (mp->mnt_flag & MNT_FORCE) == 0) { |
984 | error = EPERM; | | 996 | error = EPERM; |
985 | goto out; | | 997 | goto out; |
986 | } | | 998 | } |
987 | #endif /* !WAPBL */ | | 999 | #endif /* !WAPBL */ |
988 | | | 1000 | |
989 | ffs_oldfscompat_read(fs, ump, sblockloc); | | 1001 | ffs_oldfscompat_read(fs, ump, sblockloc); |
990 | ump->um_maxfilesize = fs->fs_maxfilesize; | | 1002 | ump->um_maxfilesize = fs->fs_maxfilesize; |
991 | | | 1003 | |
992 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { | | 1004 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { |
993 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", | | 1005 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", |
994 | mp->mnt_stat.f_mntonname, fs->fs_flags, | | 1006 | mp->mnt_stat.f_mntonname, fs->fs_flags, |
995 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); | | 1007 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); |
996 | if ((mp->mnt_flag & MNT_FORCE) == 0) { | | 1008 | if ((mp->mnt_flag & MNT_FORCE) == 0) { |
997 | error = EINVAL; | | 1009 | error = EINVAL; |
998 | goto out; | | 1010 | goto out; |
999 | } | | 1011 | } |
1000 | } | | 1012 | } |
1001 | | | 1013 | |
1002 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { | | 1014 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { |
1003 | fs->fs_pendingblocks = 0; | | 1015 | fs->fs_pendingblocks = 0; |
1004 | fs->fs_pendinginodes = 0; | | 1016 | fs->fs_pendinginodes = 0; |
1005 | } | | 1017 | } |
1006 | | | 1018 | |
1007 | ump->um_fstype = fstype; | | 1019 | ump->um_fstype = fstype; |
1008 | if (fs->fs_sbsize < SBLOCKSIZE) | | 1020 | if (fs->fs_sbsize < SBLOCKSIZE) |
1009 | brelse(bp, BC_INVAL); | | 1021 | brelse(bp, BC_INVAL); |
1010 | else | | 1022 | else |
1011 | brelse(bp, 0); | | 1023 | brelse(bp, 0); |
1012 | bp = NULL; | | 1024 | bp = NULL; |
1013 | | | 1025 | |
1014 | /* First check to see if this is tagged as an Apple UFS filesystem | | 1026 | /* First check to see if this is tagged as an Apple UFS filesystem |
1015 | * in the disklabel | | 1027 | * in the disklabel |
1016 | */ | | 1028 | */ |
1017 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && | | 1029 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && |
1018 | (dpart.part->p_fstype == FS_APPLEUFS)) { | | 1030 | (dpart.part->p_fstype == FS_APPLEUFS)) { |
1019 | ump->um_flags |= UFS_ISAPPLEUFS; | | 1031 | ump->um_flags |= UFS_ISAPPLEUFS; |
1020 | } | | 1032 | } |
1021 | #ifdef APPLE_UFS | | 1033 | #ifdef APPLE_UFS |
1022 | else { | | 1034 | else { |
1023 | /* Manually look for an apple ufs label, and if a valid one | | 1035 | /* Manually look for an apple ufs label, and if a valid one |
1024 | * is found, then treat it like an Apple UFS filesystem anyway | | 1036 | * is found, then treat it like an Apple UFS filesystem anyway |
1025 | */ | | 1037 | */ |
1026 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE), | | 1038 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE), |
1027 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); | | 1039 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); |
1028 | if (error) | | 1040 | if (error) |
1029 | goto out; | | 1041 | goto out; |
1030 | error = ffs_appleufs_validate(fs->fs_fsmnt, | | 1042 | error = ffs_appleufs_validate(fs->fs_fsmnt, |
1031 | (struct appleufslabel *)bp->b_data, NULL); | | 1043 | (struct appleufslabel *)bp->b_data, NULL); |
1032 | if (error == 0) { | | 1044 | if (error == 0) { |
1033 | ump->um_flags |= UFS_ISAPPLEUFS; | | 1045 | ump->um_flags |= UFS_ISAPPLEUFS; |
1034 | } | | 1046 | } |
1035 | brelse(bp, 0); | | 1047 | brelse(bp, 0); |
1036 | bp = NULL; | | 1048 | bp = NULL; |
1037 | } | | 1049 | } |
1038 | #else | | 1050 | #else |
1039 | if (ump->um_flags & UFS_ISAPPLEUFS) { | | 1051 | if (ump->um_flags & UFS_ISAPPLEUFS) { |
1040 | error = EINVAL; | | 1052 | error = EINVAL; |
1041 | goto out; | | 1053 | goto out; |
1042 | } | | 1054 | } |
1043 | #endif | | 1055 | #endif |
1044 | | | 1056 | |
1045 | #if 0 | | 1057 | #if 0 |
1046 | /* | | 1058 | /* |
1047 | * XXX This code changes the behaviour of mounting dirty filesystems, to | | 1059 | * XXX This code changes the behaviour of mounting dirty filesystems, to |
1048 | * XXX require "mount -f ..." to mount them. This doesn't match what | | 1060 | * XXX require "mount -f ..." to mount them. This doesn't match what |
1049 | * XXX mount(8) describes and is disabled for now. | | 1061 | * XXX mount(8) describes and is disabled for now. |
1050 | */ | | 1062 | */ |
1051 | /* | | 1063 | /* |
1052 | * If the file system is not clean, don't allow it to be mounted | | 1064 | * If the file system is not clean, don't allow it to be mounted |
1053 | * unless MNT_FORCE is specified. (Note: MNT_FORCE is always set | | 1065 | * unless MNT_FORCE is specified. (Note: MNT_FORCE is always set |
1054 | * for the root file system.) | | 1066 | * for the root file system.) |
1055 | */ | | 1067 | */ |
1056 | if (fs->fs_flags & FS_DOWAPBL) { | | 1068 | if (fs->fs_flags & FS_DOWAPBL) { |
1057 | /* | | 1069 | /* |
1058 | * wapbl normally expects to be FS_WASCLEAN when the FS_DOWAPBL | | 1070 | * wapbl normally expects to be FS_WASCLEAN when the FS_DOWAPBL |
1059 | * bit is set, although there's a window in unmount where it | | 1071 | * bit is set, although there's a window in unmount where it |
1060 | * could be FS_ISCLEAN | | 1072 | * could be FS_ISCLEAN |
1061 | */ | | 1073 | */ |
1062 | if ((mp->mnt_flag & MNT_FORCE) == 0 && | | 1074 | if ((mp->mnt_flag & MNT_FORCE) == 0 && |
1063 | (fs->fs_clean & (FS_WASCLEAN | FS_ISCLEAN)) == 0) { | | 1075 | (fs->fs_clean & (FS_WASCLEAN | FS_ISCLEAN)) == 0) { |
1064 | error = EPERM; | | 1076 | error = EPERM; |
1065 | goto out; | | 1077 | goto out; |
1066 | } | | 1078 | } |
1067 | } else | | 1079 | } else |
1068 | if ((fs->fs_clean & FS_ISCLEAN) == 0 && | | 1080 | if ((fs->fs_clean & FS_ISCLEAN) == 0 && |
1069 | (mp->mnt_flag & MNT_FORCE) == 0) { | | 1081 | (mp->mnt_flag & MNT_FORCE) == 0) { |
1070 | error = EPERM; | | 1082 | error = EPERM; |
1071 | goto out; | | 1083 | goto out; |
1072 | } | | 1084 | } |
1073 | #endif | | 1085 | #endif |
1074 | | | 1086 | |
1075 | /* | | 1087 | /* |
1076 | * verify that we can access the last block in the fs | | 1088 | * verify that we can access the last block in the fs |
1077 | * if we're mounting read/write. | | 1089 | * if we're mounting read/write. |
1078 | */ | | 1090 | */ |
1079 | | | 1091 | |
1080 | if (!ronly) { | | 1092 | if (!ronly) { |
1081 | error = bread(devvp, fsbtodb(fs, fs->fs_size - 1), fs->fs_fsize, | | 1093 | error = bread(devvp, fsbtodb(fs, fs->fs_size - 1), fs->fs_fsize, |
1082 | cred, 0, &bp); | | 1094 | cred, 0, &bp); |
1083 | if (bp->b_bcount != fs->fs_fsize) | | 1095 | if (bp->b_bcount != fs->fs_fsize) |
1084 | error = EINVAL; | | 1096 | error = EINVAL; |
1085 | if (error) { | | 1097 | if (error) { |
1086 | bset = BC_INVAL; | | 1098 | bset = BC_INVAL; |
1087 | goto out; | | 1099 | goto out; |
1088 | } | | 1100 | } |
1089 | brelse(bp, BC_INVAL); | | 1101 | brelse(bp, BC_INVAL); |
1090 | bp = NULL; | | 1102 | bp = NULL; |
1091 | } | | 1103 | } |
1092 | | | 1104 | |
1093 | fs->fs_ronly = ronly; | | 1105 | fs->fs_ronly = ronly; |
1094 | /* Don't bump fs_clean if we're replaying journal */ | | 1106 | /* Don't bump fs_clean if we're replaying journal */ |
1095 | if (!((fs->fs_flags & FS_DOWAPBL) && (fs->fs_clean & FS_WASCLEAN))) | | 1107 | if (!((fs->fs_flags & FS_DOWAPBL) && (fs->fs_clean & FS_WASCLEAN))) |
1096 | if (ronly == 0) { | | 1108 | if (ronly == 0) { |
1097 | fs->fs_clean <<= 1; | | 1109 | fs->fs_clean <<= 1; |
1098 | fs->fs_fmod = 1; | | 1110 | fs->fs_fmod = 1; |
1099 | } | | 1111 | } |
1100 | bsize = fs->fs_cssize; | | 1112 | bsize = fs->fs_cssize; |
1101 | blks = howmany(bsize, fs->fs_fsize); | | 1113 | blks = howmany(bsize, fs->fs_fsize); |
1102 | if (fs->fs_contigsumsize > 0) | | 1114 | if (fs->fs_contigsumsize > 0) |
1103 | bsize += fs->fs_ncg * sizeof(int32_t); | | 1115 | bsize += fs->fs_ncg * sizeof(int32_t); |
1104 | bsize += fs->fs_ncg * sizeof(*fs->fs_contigdirs); | | 1116 | bsize += fs->fs_ncg * sizeof(*fs->fs_contigdirs); |
1105 | space = malloc((u_long)bsize, M_UFSMNT, M_WAITOK); | | 1117 | space = malloc((u_long)bsize, M_UFSMNT, M_WAITOK); |
1106 | fs->fs_csp = space; | | 1118 | fs->fs_csp = space; |
1107 | for (i = 0; i < blks; i += fs->fs_frag) { | | 1119 | for (i = 0; i < blks; i += fs->fs_frag) { |
1108 | bsize = fs->fs_bsize; | | 1120 | bsize = fs->fs_bsize; |
1109 | if (i + fs->fs_frag > blks) | | 1121 | if (i + fs->fs_frag > blks) |
1110 | bsize = (blks - i) * fs->fs_fsize; | | 1122 | bsize = (blks - i) * fs->fs_fsize; |
1111 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), bsize, | | 1123 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), bsize, |
1112 | cred, 0, &bp); | | 1124 | cred, 0, &bp); |
1113 | if (error) { | | 1125 | if (error) { |
1114 | free(fs->fs_csp, M_UFSMNT); | | 1126 | free(fs->fs_csp, M_UFSMNT); |
1115 | goto out; | | 1127 | goto out; |
1116 | } | | 1128 | } |
1117 | #ifdef FFS_EI | | 1129 | #ifdef FFS_EI |
1118 | if (needswap) | | 1130 | if (needswap) |
1119 | ffs_csum_swap((struct csum *)bp->b_data, | | 1131 | ffs_csum_swap((struct csum *)bp->b_data, |
1120 | (struct csum *)space, bsize); | | 1132 | (struct csum *)space, bsize); |
1121 | else | | 1133 | else |
1122 | #endif | | 1134 | #endif |
1123 | memcpy(space, bp->b_data, (u_int)bsize); | | 1135 | memcpy(space, bp->b_data, (u_int)bsize); |
1124 | | | 1136 | |
1125 | space = (char *)space + bsize; | | 1137 | space = (char *)space + bsize; |
1126 | brelse(bp, 0); | | 1138 | brelse(bp, 0); |
1127 | bp = NULL; | | 1139 | bp = NULL; |
1128 | } | | 1140 | } |
1129 | if (fs->fs_contigsumsize > 0) { | | 1141 | if (fs->fs_contigsumsize > 0) { |
1130 | fs->fs_maxcluster = lp = space; | | 1142 | fs->fs_maxcluster = lp = space; |
1131 | for (i = 0; i < fs->fs_ncg; i++) | | 1143 | for (i = 0; i < fs->fs_ncg; i++) |
1132 | *lp++ = fs->fs_contigsumsize; | | 1144 | *lp++ = fs->fs_contigsumsize; |
1133 | space = lp; | | 1145 | space = lp; |
1134 | } | | 1146 | } |
1135 | bsize = fs->fs_ncg * sizeof(*fs->fs_contigdirs); | | 1147 | bsize = fs->fs_ncg * sizeof(*fs->fs_contigdirs); |
1136 | fs->fs_contigdirs = space; | | 1148 | fs->fs_contigdirs = space; |
1137 | space = (char *)space + bsize; | | 1149 | space = (char *)space + bsize; |
1138 | memset(fs->fs_contigdirs, 0, bsize); | | 1150 | memset(fs->fs_contigdirs, 0, bsize); |
1139 | /* Compatibility for old filesystems - XXX */ | | 1151 | /* Compatibility for old filesystems - XXX */ |
1140 | if (fs->fs_avgfilesize <= 0) | | 1152 | if (fs->fs_avgfilesize <= 0) |
1141 | fs->fs_avgfilesize = AVFILESIZ; | | 1153 | fs->fs_avgfilesize = AVFILESIZ; |
1142 | if (fs->fs_avgfpdir <= 0) | | 1154 | if (fs->fs_avgfpdir <= 0) |
1143 | fs->fs_avgfpdir = AFPDIR; | | 1155 | fs->fs_avgfpdir = AFPDIR; |
1144 | fs->fs_active = NULL; | | 1156 | fs->fs_active = NULL; |
1145 | mp->mnt_data = ump; | | 1157 | mp->mnt_data = ump; |
1146 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; | | 1158 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; |
1147 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FFS); | | 1159 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FFS); |
1148 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; | | 1160 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; |
1149 | mp->mnt_stat.f_namemax = FFS_MAXNAMLEN; | | 1161 | mp->mnt_stat.f_namemax = FFS_MAXNAMLEN; |
1150 | if (UFS_MPISAPPLEUFS(ump)) { | | 1162 | if (UFS_MPISAPPLEUFS(ump)) { |
1151 | /* NeXT used to keep short symlinks in the inode even | | 1163 | /* NeXT used to keep short symlinks in the inode even |
1152 | * when using FS_42INODEFMT. In that case fs->fs_maxsymlinklen | | 1164 | * when using FS_42INODEFMT. In that case fs->fs_maxsymlinklen |
1153 | * is probably -1, but we still need to be able to identify | | 1165 | * is probably -1, but we still need to be able to identify |
1154 | * short symlinks. | | 1166 | * short symlinks. |
1155 | */ | | 1167 | */ |
1156 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; | | 1168 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; |
1157 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; | | 1169 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; |
1158 | mp->mnt_iflag |= IMNT_DTYPE; | | 1170 | mp->mnt_iflag |= IMNT_DTYPE; |
1159 | } else { | | 1171 | } else { |
1160 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; | | 1172 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; |
1161 | ump->um_dirblksiz = DIRBLKSIZ; | | 1173 | ump->um_dirblksiz = DIRBLKSIZ; |
1162 | if (ump->um_maxsymlinklen > 0) | | 1174 | if (ump->um_maxsymlinklen > 0) |
1163 | mp->mnt_iflag |= IMNT_DTYPE; | | 1175 | mp->mnt_iflag |= IMNT_DTYPE; |
1164 | else | | 1176 | else |
1165 | mp->mnt_iflag &= ~IMNT_DTYPE; | | 1177 | mp->mnt_iflag &= ~IMNT_DTYPE; |
1166 | } | | 1178 | } |
1167 | mp->mnt_fs_bshift = fs->fs_bshift; | | 1179 | mp->mnt_fs_bshift = fs->fs_bshift; |
1168 | mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */ | | 1180 | mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */ |
1169 | mp->mnt_flag |= MNT_LOCAL; | | 1181 | mp->mnt_flag |= MNT_LOCAL; |
1170 | mp->mnt_iflag |= IMNT_MPSAFE; | | 1182 | mp->mnt_iflag |= IMNT_MPSAFE; |
1171 | #ifdef FFS_EI | | 1183 | #ifdef FFS_EI |
1172 | if (needswap) | | 1184 | if (needswap) |
1173 | ump->um_flags |= UFS_NEEDSWAP; | | 1185 | ump->um_flags |= UFS_NEEDSWAP; |
1174 | #endif | | 1186 | #endif |
1175 | ump->um_mountp = mp; | | 1187 | ump->um_mountp = mp; |
1176 | ump->um_dev = dev; | | 1188 | ump->um_dev = dev; |
1177 | ump->um_devvp = devvp; | | 1189 | ump->um_devvp = devvp; |
1178 | ump->um_nindir = fs->fs_nindir; | | 1190 | ump->um_nindir = fs->fs_nindir; |
1179 | ump->um_lognindir = ffs(fs->fs_nindir) - 1; | | 1191 | ump->um_lognindir = ffs(fs->fs_nindir) - 1; |
1180 | ump->um_bptrtodb = fs->fs_fshift - DEV_BSHIFT; | | 1192 | ump->um_bptrtodb = fs->fs_fshift - DEV_BSHIFT; |
1181 | ump->um_seqinc = fs->fs_frag; | | 1193 | ump->um_seqinc = fs->fs_frag; |
1182 | for (i = 0; i < MAXQUOTAS; i++) | | 1194 | for (i = 0; i < MAXQUOTAS; i++) |
1183 | ump->um_quotas[i] = NULLVP; | | 1195 | ump->um_quotas[i] = NULLVP; |
1184 | devvp->v_specmountpoint = mp; | | 1196 | devvp->v_specmountpoint = mp; |
1185 | if (ronly == 0 && fs->fs_snapinum[0] != 0) | | 1197 | if (ronly == 0 && fs->fs_snapinum[0] != 0) |
1186 | ffs_snapshot_mount(mp); | | 1198 | ffs_snapshot_mount(mp); |
1187 | | | 1199 | |
1188 | #ifdef WAPBL | | 1200 | #ifdef WAPBL |
1189 | if (!ronly) { | | 1201 | if (!ronly) { |
1190 | KDASSERT(fs->fs_ronly == 0); | | 1202 | KDASSERT(fs->fs_ronly == 0); |
1191 | /* | | 1203 | /* |
1192 | * ffs_wapbl_start() needs mp->mnt_stat initialised if it | | 1204 | * ffs_wapbl_start() needs mp->mnt_stat initialised if it |
1193 | * needs to create a new log file in-filesystem. | | 1205 | * needs to create a new log file in-filesystem. |
1194 | */ | | 1206 | */ |
1195 | ffs_statvfs(mp, &mp->mnt_stat); | | 1207 | ffs_statvfs(mp, &mp->mnt_stat); |
1196 | | | 1208 | |
1197 | error = ffs_wapbl_start(mp); | | 1209 | error = ffs_wapbl_start(mp); |
1198 | if (error) { | | 1210 | if (error) { |
1199 | free(fs->fs_csp, M_UFSMNT); | | 1211 | free(fs->fs_csp, M_UFSMNT); |
1200 | goto out; | | 1212 | goto out; |
1201 | } | | 1213 | } |
1202 | } | | 1214 | } |
1203 | #endif /* WAPBL */ | | 1215 | #endif /* WAPBL */ |
1204 | #ifdef UFS_EXTATTR | | 1216 | #ifdef UFS_EXTATTR |
1205 | /* | | 1217 | /* |
1206 | * Initialize file-backed extended attributes on UFS1 file | | 1218 | * Initialize file-backed extended attributes on UFS1 file |
1207 | * systems. | | 1219 | * systems. |
1208 | */ | | 1220 | */ |
1209 | if (ump->um_fstype == UFS1) { | | 1221 | if (ump->um_fstype == UFS1) { |
1210 | ufs_extattr_uepm_init(&ump->um_extattr); | | 1222 | ufs_extattr_uepm_init(&ump->um_extattr); |
1211 | #ifdef UFS_EXTATTR_AUTOSTART | | 1223 | #ifdef UFS_EXTATTR_AUTOSTART |
1212 | /* | | 1224 | /* |
1213 | * XXX Just ignore errors. Not clear that we should | | 1225 | * XXX Just ignore errors. Not clear that we should |
1214 | * XXX fail the mount in this case. | | 1226 | * XXX fail the mount in this case. |
1215 | */ | | 1227 | */ |
1216 | (void) ufs_extattr_autostart(mp, l); | | 1228 | (void) ufs_extattr_autostart(mp, l); |
1217 | #endif | | 1229 | #endif |
1218 | } | | 1230 | } |
1219 | #endif /* UFS_EXTATTR */ | | 1231 | #endif /* UFS_EXTATTR */ |
1220 | return (0); | | 1232 | return (0); |
1221 | out: | | 1233 | out: |
1222 | #ifdef WAPBL | | 1234 | #ifdef WAPBL |
1223 | if (mp->mnt_wapbl_replay) { | | 1235 | if (mp->mnt_wapbl_replay) { |
1224 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 1236 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
1225 | wapbl_replay_free(mp->mnt_wapbl_replay); | | 1237 | wapbl_replay_free(mp->mnt_wapbl_replay); |
1226 | mp->mnt_wapbl_replay = 0; | | 1238 | mp->mnt_wapbl_replay = 0; |
1227 | } | | 1239 | } |
1228 | #endif | | 1240 | #endif |
1229 | | | 1241 | |
1230 | fstrans_unmount(mp); | | 1242 | fstrans_unmount(mp); |
1231 | if (fs) | | 1243 | if (fs) |
1232 | free(fs, M_UFSMNT); | | 1244 | free(fs, M_UFSMNT); |
1233 | devvp->v_specmountpoint = NULL; | | 1245 | devvp->v_specmountpoint = NULL; |
1234 | if (bp) | | 1246 | if (bp) |
1235 | brelse(bp, bset); | | 1247 | brelse(bp, bset); |
1236 | if (ump) { | | 1248 | if (ump) { |
1237 | if (ump->um_oldfscompat) | | 1249 | if (ump->um_oldfscompat) |
1238 | free(ump->um_oldfscompat, M_UFSMNT); | | 1250 | free(ump->um_oldfscompat, M_UFSMNT); |
1239 | mutex_destroy(&ump->um_lock); | | 1251 | mutex_destroy(&ump->um_lock); |
1240 | free(ump, M_UFSMNT); | | 1252 | free(ump, M_UFSMNT); |
1241 | mp->mnt_data = NULL; | | 1253 | mp->mnt_data = NULL; |
1242 | } | | 1254 | } |
1243 | return (error); | | 1255 | return (error); |
1244 | } | | 1256 | } |
1245 | | | 1257 | |
1246 | /* | | 1258 | /* |
1247 | * Sanity checks for loading old filesystem superblocks. | | 1259 | * Sanity checks for loading old filesystem superblocks. |
1248 | * See ffs_oldfscompat_write below for unwound actions. | | 1260 | * See ffs_oldfscompat_write below for unwound actions. |
1249 | * | | 1261 | * |
1250 | * XXX - Parts get retired eventually. | | 1262 | * XXX - Parts get retired eventually. |
1251 | * Unfortunately new bits get added. | | 1263 | * Unfortunately new bits get added. |
1252 | */ | | 1264 | */ |
1253 | static void | | 1265 | static void |
1254 | ffs_oldfscompat_read(struct fs *fs, struct ufsmount *ump, daddr_t sblockloc) | | 1266 | ffs_oldfscompat_read(struct fs *fs, struct ufsmount *ump, daddr_t sblockloc) |
1255 | { | | 1267 | { |
1256 | off_t maxfilesize; | | 1268 | off_t maxfilesize; |
1257 | int32_t *extrasave; | | 1269 | int32_t *extrasave; |
1258 | | | 1270 | |
1259 | if ((fs->fs_magic != FS_UFS1_MAGIC) || | | 1271 | if ((fs->fs_magic != FS_UFS1_MAGIC) || |
1260 | (fs->fs_old_flags & FS_FLAGS_UPDATED)) | | 1272 | (fs->fs_old_flags & FS_FLAGS_UPDATED)) |
1261 | return; | | 1273 | return; |
1262 | | | 1274 | |
1263 | if (!ump->um_oldfscompat) | | 1275 | if (!ump->um_oldfscompat) |
1264 | ump->um_oldfscompat = malloc(512 + 3*sizeof(int32_t), | | 1276 | ump->um_oldfscompat = malloc(512 + 3*sizeof(int32_t), |
1265 | M_UFSMNT, M_WAITOK); | | 1277 | M_UFSMNT, M_WAITOK); |
1266 | | | 1278 | |
1267 | memcpy(ump->um_oldfscompat, &fs->fs_old_postbl_start, 512); | | 1279 | memcpy(ump->um_oldfscompat, &fs->fs_old_postbl_start, 512); |
1268 | extrasave = ump->um_oldfscompat; | | 1280 | extrasave = ump->um_oldfscompat; |
1269 | extrasave += 512/sizeof(int32_t); | | 1281 | extrasave += 512/sizeof(int32_t); |
1270 | extrasave[0] = fs->fs_old_npsect; | | 1282 | extrasave[0] = fs->fs_old_npsect; |
1271 | extrasave[1] = fs->fs_old_interleave; | | 1283 | extrasave[1] = fs->fs_old_interleave; |
1272 | extrasave[2] = fs->fs_old_trackskew; | | 1284 | extrasave[2] = fs->fs_old_trackskew; |
1273 | | | 1285 | |
1274 | /* These fields will be overwritten by their | | 1286 | /* These fields will be overwritten by their |
1275 | * original values in fs_oldfscompat_write, so it is harmless | | 1287 | * original values in fs_oldfscompat_write, so it is harmless |
1276 | * to modify them here. | | 1288 | * to modify them here. |
1277 | */ | | 1289 | */ |
1278 | fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir; | | 1290 | fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir; |
1279 | fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree; | | 1291 | fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree; |
1280 | fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree; | | 1292 | fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree; |
1281 | fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree; | | 1293 | fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree; |
1282 | | | 1294 | |
1283 | fs->fs_maxbsize = fs->fs_bsize; | | 1295 | fs->fs_maxbsize = fs->fs_bsize; |
1284 | fs->fs_time = fs->fs_old_time; | | 1296 | fs->fs_time = fs->fs_old_time; |
1285 | fs->fs_size = fs->fs_old_size; | | 1297 | fs->fs_size = fs->fs_old_size; |
1286 | fs->fs_dsize = fs->fs_old_dsize; | | 1298 | fs->fs_dsize = fs->fs_old_dsize; |
1287 | fs->fs_csaddr = fs->fs_old_csaddr; | | 1299 | fs->fs_csaddr = fs->fs_old_csaddr; |
1288 | fs->fs_sblockloc = sblockloc; | | 1300 | fs->fs_sblockloc = sblockloc; |
1289 | | | 1301 | |
1290 | fs->fs_flags = fs->fs_old_flags | (fs->fs_flags & FS_INTERNAL); | | 1302 | fs->fs_flags = fs->fs_old_flags | (fs->fs_flags & FS_INTERNAL); |
1291 | | | 1303 | |
1292 | if (fs->fs_old_postblformat == FS_42POSTBLFMT) { | | 1304 | if (fs->fs_old_postblformat == FS_42POSTBLFMT) { |
1293 | fs->fs_old_nrpos = 8; | | 1305 | fs->fs_old_nrpos = 8; |
1294 | fs->fs_old_npsect = fs->fs_old_nsect; | | 1306 | fs->fs_old_npsect = fs->fs_old_nsect; |
1295 | fs->fs_old_interleave = 1; | | 1307 | fs->fs_old_interleave = 1; |
1296 | fs->fs_old_trackskew = 0; | | 1308 | fs->fs_old_trackskew = 0; |
1297 | } | | 1309 | } |
1298 | | | 1310 | |
1299 | if (fs->fs_old_inodefmt < FS_44INODEFMT) { | | 1311 | if (fs->fs_old_inodefmt < FS_44INODEFMT) { |
1300 | fs->fs_maxfilesize = (u_quad_t) 1LL << 39; | | 1312 | fs->fs_maxfilesize = (u_quad_t) 1LL << 39; |
1301 | fs->fs_qbmask = ~fs->fs_bmask; | | 1313 | fs->fs_qbmask = ~fs->fs_bmask; |
1302 | fs->fs_qfmask = ~fs->fs_fmask; | | 1314 | fs->fs_qfmask = ~fs->fs_fmask; |
1303 | } | | 1315 | } |
1304 | | | 1316 | |
1305 | maxfilesize = (u_int64_t)0x80000000 * fs->fs_bsize - 1; | | 1317 | maxfilesize = (u_int64_t)0x80000000 * fs->fs_bsize - 1; |
1306 | if (fs->fs_maxfilesize > maxfilesize) | | 1318 | if (fs->fs_maxfilesize > maxfilesize) |
1307 | fs->fs_maxfilesize = maxfilesize; | | 1319 | fs->fs_maxfilesize = maxfilesize; |
1308 | | | 1320 | |
1309 | /* Compatibility for old filesystems */ | | 1321 | /* Compatibility for old filesystems */ |
1310 | if (fs->fs_avgfilesize <= 0) | | 1322 | if (fs->fs_avgfilesize <= 0) |
1311 | fs->fs_avgfilesize = AVFILESIZ; | | 1323 | fs->fs_avgfilesize = AVFILESIZ; |
1312 | if (fs->fs_avgfpdir <= 0) | | 1324 | if (fs->fs_avgfpdir <= 0) |
1313 | fs->fs_avgfpdir = AFPDIR; | | 1325 | fs->fs_avgfpdir = AFPDIR; |
1314 | | | 1326 | |
1315 | #if 0 | | 1327 | #if 0 |
1316 | if (bigcgs) { | | 1328 | if (bigcgs) { |
1317 | fs->fs_save_cgsize = fs->fs_cgsize; | | 1329 | fs->fs_save_cgsize = fs->fs_cgsize; |
1318 | fs->fs_cgsize = fs->fs_bsize; | | 1330 | fs->fs_cgsize = fs->fs_bsize; |
1319 | } | | 1331 | } |
1320 | #endif | | 1332 | #endif |
1321 | } | | 1333 | } |
1322 | | | 1334 | |
1323 | /* | | 1335 | /* |
1324 | * Unwinding superblock updates for old filesystems. | | 1336 | * Unwinding superblock updates for old filesystems. |
1325 | * See ffs_oldfscompat_read above for details. | | 1337 | * See ffs_oldfscompat_read above for details. |
1326 | * | | 1338 | * |
1327 | * XXX - Parts get retired eventually. | | 1339 | * XXX - Parts get retired eventually. |
1328 | * Unfortunately new bits get added. | | 1340 | * Unfortunately new bits get added. |
1329 | */ | | 1341 | */ |
1330 | static void | | 1342 | static void |
1331 | ffs_oldfscompat_write(struct fs *fs, struct ufsmount *ump) | | 1343 | ffs_oldfscompat_write(struct fs *fs, struct ufsmount *ump) |
1332 | { | | 1344 | { |
1333 | int32_t *extrasave; | | 1345 | int32_t *extrasave; |
1334 | | | 1346 | |
1335 | if ((fs->fs_magic != FS_UFS1_MAGIC) || | | 1347 | if ((fs->fs_magic != FS_UFS1_MAGIC) || |
1336 | (fs->fs_old_flags & FS_FLAGS_UPDATED)) | | 1348 | (fs->fs_old_flags & FS_FLAGS_UPDATED)) |
1337 | return; | | 1349 | return; |
1338 | | | 1350 | |
1339 | fs->fs_old_time = fs->fs_time; | | 1351 | fs->fs_old_time = fs->fs_time; |
1340 | fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir; | | 1352 | fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir; |
1341 | fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree; | | 1353 | fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree; |
1342 | fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree; | | 1354 | fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree; |
1343 | fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree; | | 1355 | fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree; |
1344 | fs->fs_old_flags = fs->fs_flags; | | 1356 | fs->fs_old_flags = fs->fs_flags; |
1345 | | | 1357 | |
1346 | #if 0 | | 1358 | #if 0 |
1347 | if (bigcgs) { | | 1359 | if (bigcgs) { |
1348 | fs->fs_cgsize = fs->fs_save_cgsize; | | 1360 | fs->fs_cgsize = fs->fs_save_cgsize; |
1349 | } | | 1361 | } |
1350 | #endif | | 1362 | #endif |
1351 | | | 1363 | |
1352 | memcpy(&fs->fs_old_postbl_start, ump->um_oldfscompat, 512); | | 1364 | memcpy(&fs->fs_old_postbl_start, ump->um_oldfscompat, 512); |
1353 | extrasave = ump->um_oldfscompat; | | 1365 | extrasave = ump->um_oldfscompat; |
1354 | extrasave += 512/sizeof(int32_t); | | 1366 | extrasave += 512/sizeof(int32_t); |
1355 | fs->fs_old_npsect = extrasave[0]; | | 1367 | fs->fs_old_npsect = extrasave[0]; |
1356 | fs->fs_old_interleave = extrasave[1]; | | 1368 | fs->fs_old_interleave = extrasave[1]; |
1357 | fs->fs_old_trackskew = extrasave[2]; | | 1369 | fs->fs_old_trackskew = extrasave[2]; |
1358 | | | 1370 | |
1359 | } | | 1371 | } |
1360 | | | 1372 | |
1361 | /* | | 1373 | /* |
1362 | * unmount vfs operation | | 1374 | * unmount vfs operation |
1363 | */ | | 1375 | */ |
1364 | int | | 1376 | int |
1365 | ffs_unmount(struct mount *mp, int mntflags) | | 1377 | ffs_unmount(struct mount *mp, int mntflags) |
1366 | { | | 1378 | { |
1367 | struct lwp *l = curlwp; | | 1379 | struct lwp *l = curlwp; |
1368 | struct ufsmount *ump = VFSTOUFS(mp); | | 1380 | struct ufsmount *ump = VFSTOUFS(mp); |
1369 | struct fs *fs = ump->um_fs; | | 1381 | struct fs *fs = ump->um_fs; |
1370 | int error, flags; | | 1382 | int error, flags; |
1371 | #ifdef WAPBL | | 1383 | #ifdef WAPBL |
1372 | extern int doforce; | | 1384 | extern int doforce; |
1373 | #endif | | 1385 | #endif |
1374 | | | 1386 | |
1375 | flags = 0; | | 1387 | flags = 0; |
1376 | if (mntflags & MNT_FORCE) | | 1388 | if (mntflags & MNT_FORCE) |
1377 | flags |= FORCECLOSE; | | 1389 | flags |= FORCECLOSE; |
1378 | if ((error = ffs_flushfiles(mp, flags, l)) != 0) | | 1390 | if ((error = ffs_flushfiles(mp, flags, l)) != 0) |
1379 | return (error); | | 1391 | return (error); |
1380 | error = UFS_WAPBL_BEGIN(mp); | | 1392 | error = UFS_WAPBL_BEGIN(mp); |
1381 | if (error == 0) | | 1393 | if (error == 0) |
1382 | if (fs->fs_ronly == 0 && | | 1394 | if (fs->fs_ronly == 0 && |
1383 | ffs_cgupdate(ump, MNT_WAIT) == 0 && | | 1395 | ffs_cgupdate(ump, MNT_WAIT) == 0 && |
1384 | fs->fs_clean & FS_WASCLEAN) { | | 1396 | fs->fs_clean & FS_WASCLEAN) { |
1385 | fs->fs_clean = FS_ISCLEAN; | | 1397 | fs->fs_clean = FS_ISCLEAN; |
1386 | fs->fs_fmod = 0; | | 1398 | fs->fs_fmod = 0; |
1387 | (void) ffs_sbupdate(ump, MNT_WAIT); | | 1399 | (void) ffs_sbupdate(ump, MNT_WAIT); |
1388 | } | | 1400 | } |
1389 | if (error == 0) | | 1401 | if (error == 0) |
1390 | UFS_WAPBL_END(mp); | | 1402 | UFS_WAPBL_END(mp); |
1391 | #ifdef WAPBL | | 1403 | #ifdef WAPBL |
1392 | KASSERT(!(mp->mnt_wapbl_replay && mp->mnt_wapbl)); | | 1404 | KASSERT(!(mp->mnt_wapbl_replay && mp->mnt_wapbl)); |
1393 | if (mp->mnt_wapbl_replay) { | | 1405 | if (mp->mnt_wapbl_replay) { |
1394 | KDASSERT(fs->fs_ronly); | | 1406 | KDASSERT(fs->fs_ronly); |
1395 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 1407 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
1396 | wapbl_replay_free(mp->mnt_wapbl_replay); | | 1408 | wapbl_replay_free(mp->mnt_wapbl_replay); |
1397 | mp->mnt_wapbl_replay = 0; | | 1409 | mp->mnt_wapbl_replay = 0; |
1398 | } | | 1410 | } |
1399 | error = ffs_wapbl_stop(mp, doforce && (mntflags & MNT_FORCE)); | | 1411 | error = ffs_wapbl_stop(mp, doforce && (mntflags & MNT_FORCE)); |
1400 | if (error) { | | 1412 | if (error) { |
1401 | return error; | | 1413 | return error; |
1402 | } | | 1414 | } |
1403 | #endif /* WAPBL */ | | 1415 | #endif /* WAPBL */ |
1404 | #ifdef UFS_EXTATTR | | 1416 | #ifdef UFS_EXTATTR |
1405 | if (ump->um_fstype == UFS1) { | | 1417 | if (ump->um_fstype == UFS1) { |
1406 | ufs_extattr_stop(mp, l); | | 1418 | ufs_extattr_stop(mp, l); |
1407 | ufs_extattr_uepm_destroy(&ump->um_extattr); | | 1419 | ufs_extattr_uepm_destroy(&ump->um_extattr); |
1408 | } | | 1420 | } |
1409 | #endif /* UFS_EXTATTR */ | | 1421 | #endif /* UFS_EXTATTR */ |
1410 | | | 1422 | |
1411 | if (ump->um_devvp->v_type != VBAD) | | 1423 | if (ump->um_devvp->v_type != VBAD) |
1412 | ump->um_devvp->v_specmountpoint = NULL; | | 1424 | ump->um_devvp->v_specmountpoint = NULL; |
1413 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); | | 1425 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); |
1414 | (void)VOP_CLOSE(ump->um_devvp, fs->fs_ronly ? FREAD : FREAD | FWRITE, | | 1426 | (void)VOP_CLOSE(ump->um_devvp, fs->fs_ronly ? FREAD : FREAD | FWRITE, |
1415 | NOCRED); | | 1427 | NOCRED); |
1416 | vput(ump->um_devvp); | | 1428 | vput(ump->um_devvp); |
1417 | free(fs->fs_csp, M_UFSMNT); | | 1429 | free(fs->fs_csp, M_UFSMNT); |
1418 | free(fs, M_UFSMNT); | | 1430 | free(fs, M_UFSMNT); |
1419 | if (ump->um_oldfscompat != NULL) | | 1431 | if (ump->um_oldfscompat != NULL) |
1420 | free(ump->um_oldfscompat, M_UFSMNT); | | 1432 | free(ump->um_oldfscompat, M_UFSMNT); |
1421 | mutex_destroy(&ump->um_lock); | | 1433 | mutex_destroy(&ump->um_lock); |
1422 | ffs_snapshot_fini(ump); | | 1434 | ffs_snapshot_fini(ump); |
1423 | free(ump, M_UFSMNT); | | 1435 | free(ump, M_UFSMNT); |
1424 | mp->mnt_data = NULL; | | 1436 | mp->mnt_data = NULL; |
1425 | mp->mnt_flag &= ~MNT_LOCAL; | | 1437 | mp->mnt_flag &= ~MNT_LOCAL; |
1426 | fstrans_unmount(mp); | | 1438 | fstrans_unmount(mp); |
1427 | return (0); | | 1439 | return (0); |
1428 | } | | 1440 | } |
1429 | | | 1441 | |
1430 | /* | | 1442 | /* |
1431 | * Flush out all the files in a filesystem. | | 1443 | * Flush out all the files in a filesystem. |
1432 | */ | | 1444 | */ |
1433 | int | | 1445 | int |
1434 | ffs_flushfiles(struct mount *mp, int flags, struct lwp *l) | | 1446 | ffs_flushfiles(struct mount *mp, int flags, struct lwp *l) |
1435 | { | | 1447 | { |
1436 | extern int doforce; | | 1448 | extern int doforce; |
1437 | struct ufsmount *ump; | | 1449 | struct ufsmount *ump; |
1438 | int error; | | 1450 | int error; |
1439 | | | 1451 | |
1440 | if (!doforce) | | 1452 | if (!doforce) |
1441 | flags &= ~FORCECLOSE; | | 1453 | flags &= ~FORCECLOSE; |
1442 | ump = VFSTOUFS(mp); | | 1454 | ump = VFSTOUFS(mp); |
1443 | #ifdef QUOTA | | 1455 | #ifdef QUOTA |
1444 | if (mp->mnt_flag & MNT_QUOTA) { | | 1456 | if (mp->mnt_flag & MNT_QUOTA) { |
1445 | int i; | | 1457 | int i; |
1446 | if ((error = vflush(mp, NULLVP, SKIPSYSTEM | flags)) != 0) | | 1458 | if ((error = vflush(mp, NULLVP, SKIPSYSTEM | flags)) != 0) |
1447 | return (error); | | 1459 | return (error); |
1448 | for (i = 0; i < MAXQUOTAS; i++) { | | 1460 | for (i = 0; i < MAXQUOTAS; i++) { |
1449 | if (ump->um_quotas[i] == NULLVP) | | 1461 | if (ump->um_quotas[i] == NULLVP) |
1450 | continue; | | 1462 | continue; |
1451 | quotaoff(l, mp, i); | | 1463 | quotaoff(l, mp, i); |
1452 | } | | 1464 | } |
1453 | /* | | 1465 | /* |
1454 | * Here we fall through to vflush again to ensure | | 1466 | * Here we fall through to vflush again to ensure |
1455 | * that we have gotten rid of all the system vnodes. | | 1467 | * that we have gotten rid of all the system vnodes. |
1456 | */ | | 1468 | */ |
1457 | } | | 1469 | } |
1458 | #endif | | 1470 | #endif |
1459 | if ((error = vflush(mp, 0, SKIPSYSTEM | flags)) != 0) | | 1471 | if ((error = vflush(mp, 0, SKIPSYSTEM | flags)) != 0) |
1460 | return (error); | | 1472 | return (error); |
1461 | ffs_snapshot_unmount(mp); | | 1473 | ffs_snapshot_unmount(mp); |
1462 | /* | | 1474 | /* |
1463 | * Flush all the files. | | 1475 | * Flush all the files. |
1464 | */ | | 1476 | */ |
1465 | error = vflush(mp, NULLVP, flags); | | 1477 | error = vflush(mp, NULLVP, flags); |
1466 | if (error) | | 1478 | if (error) |
1467 | return (error); | | 1479 | return (error); |
1468 | /* | | 1480 | /* |
1469 | * Flush filesystem metadata. | | 1481 | * Flush filesystem metadata. |
1470 | */ | | 1482 | */ |
1471 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); | | 1483 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); |
1472 | error = VOP_FSYNC(ump->um_devvp, l->l_cred, FSYNC_WAIT, 0, 0); | | 1484 | error = VOP_FSYNC(ump->um_devvp, l->l_cred, FSYNC_WAIT, 0, 0); |
1473 | VOP_UNLOCK(ump->um_devvp); | | 1485 | VOP_UNLOCK(ump->um_devvp); |
1474 | if (flags & FORCECLOSE) /* XXXDBJ */ | | 1486 | if (flags & FORCECLOSE) /* XXXDBJ */ |
1475 | error = 0; | | 1487 | error = 0; |
1476 | | | 1488 | |
1477 | #ifdef WAPBL | | 1489 | #ifdef WAPBL |
1478 | if (error) | | 1490 | if (error) |
1479 | return error; | | 1491 | return error; |
1480 | if (mp->mnt_wapbl) { | | 1492 | if (mp->mnt_wapbl) { |
1481 | error = wapbl_flush(mp->mnt_wapbl, 1); | | 1493 | error = wapbl_flush(mp->mnt_wapbl, 1); |
1482 | if (flags & FORCECLOSE) | | 1494 | if (flags & FORCECLOSE) |
1483 | error = 0; | | 1495 | error = 0; |
1484 | } | | 1496 | } |
1485 | #endif | | 1497 | #endif |
1486 | | | 1498 | |
1487 | return (error); | | 1499 | return (error); |
1488 | } | | 1500 | } |
1489 | | | 1501 | |
1490 | /* | | 1502 | /* |
1491 | * Get file system statistics. | | 1503 | * Get file system statistics. |
1492 | */ | | 1504 | */ |
1493 | int | | 1505 | int |
1494 | ffs_statvfs(struct mount *mp, struct statvfs *sbp) | | 1506 | ffs_statvfs(struct mount *mp, struct statvfs *sbp) |
1495 | { | | 1507 | { |
1496 | struct ufsmount *ump; | | 1508 | struct ufsmount *ump; |
1497 | struct fs *fs; | | 1509 | struct fs *fs; |
1498 | | | 1510 | |
1499 | ump = VFSTOUFS(mp); | | 1511 | ump = VFSTOUFS(mp); |
1500 | fs = ump->um_fs; | | 1512 | fs = ump->um_fs; |
1501 | mutex_enter(&ump->um_lock); | | 1513 | mutex_enter(&ump->um_lock); |
1502 | sbp->f_bsize = fs->fs_bsize; | | 1514 | sbp->f_bsize = fs->fs_bsize; |
1503 | sbp->f_frsize = fs->fs_fsize; | | 1515 | sbp->f_frsize = fs->fs_fsize; |
1504 | sbp->f_iosize = fs->fs_bsize; | | 1516 | sbp->f_iosize = fs->fs_bsize; |
1505 | sbp->f_blocks = fs->fs_dsize; | | 1517 | sbp->f_blocks = fs->fs_dsize; |
1506 | sbp->f_bfree = blkstofrags(fs, fs->fs_cstotal.cs_nbfree) + | | 1518 | sbp->f_bfree = blkstofrags(fs, fs->fs_cstotal.cs_nbfree) + |
1507 | fs->fs_cstotal.cs_nffree + dbtofsb(fs, fs->fs_pendingblocks); | | 1519 | fs->fs_cstotal.cs_nffree + dbtofsb(fs, fs->fs_pendingblocks); |
1508 | sbp->f_bresvd = ((u_int64_t) fs->fs_dsize * (u_int64_t) | | 1520 | sbp->f_bresvd = ((u_int64_t) fs->fs_dsize * (u_int64_t) |
1509 | fs->fs_minfree) / (u_int64_t) 100; | | 1521 | fs->fs_minfree) / (u_int64_t) 100; |
1510 | if (sbp->f_bfree > sbp->f_bresvd) | | 1522 | if (sbp->f_bfree > sbp->f_bresvd) |
1511 | sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd; | | 1523 | sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd; |
1512 | else | | 1524 | else |
1513 | sbp->f_bavail = 0; | | 1525 | sbp->f_bavail = 0; |
1514 | sbp->f_files = fs->fs_ncg * fs->fs_ipg - ROOTINO; | | 1526 | sbp->f_files = fs->fs_ncg * fs->fs_ipg - ROOTINO; |
1515 | sbp->f_ffree = fs->fs_cstotal.cs_nifree + fs->fs_pendinginodes; | | 1527 | sbp->f_ffree = fs->fs_cstotal.cs_nifree + fs->fs_pendinginodes; |
1516 | sbp->f_favail = sbp->f_ffree; | | 1528 | sbp->f_favail = sbp->f_ffree; |
1517 | sbp->f_fresvd = 0; | | 1529 | sbp->f_fresvd = 0; |
1518 | mutex_exit(&ump->um_lock); | | 1530 | mutex_exit(&ump->um_lock); |
1519 | copy_statvfs_info(sbp, mp); | | 1531 | copy_statvfs_info(sbp, mp); |
1520 | | | 1532 | |
1521 | return (0); | | 1533 | return (0); |
1522 | } | | 1534 | } |
1523 | | | 1535 | |
1524 | /* | | 1536 | /* |
1525 | * Go through the disk queues to initiate sandbagged IO; | | 1537 | * Go through the disk queues to initiate sandbagged IO; |
1526 | * go through the inodes to write those that have been modified; | | 1538 | * go through the inodes to write those that have been modified; |
1527 | * initiate the writing of the super block if it has been modified. | | 1539 | * initiate the writing of the super block if it has been modified. |
1528 | * | | 1540 | * |
1529 | * Note: we are always called with the filesystem marked `MPBUSY'. | | 1541 | * Note: we are always called with the filesystem marked `MPBUSY'. |
1530 | */ | | 1542 | */ |
1531 | int | | 1543 | int |
1532 | ffs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) | | 1544 | ffs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) |
1533 | { | | 1545 | { |
1534 | struct vnode *vp, *mvp, *nvp; | | 1546 | struct vnode *vp, *mvp, *nvp; |
1535 | struct inode *ip; | | 1547 | struct inode *ip; |
1536 | struct ufsmount *ump = VFSTOUFS(mp); | | 1548 | struct ufsmount *ump = VFSTOUFS(mp); |
1537 | struct fs *fs; | | 1549 | struct fs *fs; |
1538 | int lk_flags, error, allerror = 0; | | 1550 | int lk_flags, error, allerror = 0; |
1539 | bool is_suspending; | | 1551 | bool is_suspending; |
1540 | | | 1552 | |
1541 | fs = ump->um_fs; | | 1553 | fs = ump->um_fs; |
1542 | if (fs->fs_fmod != 0 && fs->fs_ronly != 0) { /* XXX */ | | 1554 | if (fs->fs_fmod != 0 && fs->fs_ronly != 0) { /* XXX */ |
1543 | printf("fs = %s\n", fs->fs_fsmnt); | | 1555 | printf("fs = %s\n", fs->fs_fsmnt); |
1544 | panic("update: rofs mod"); | | 1556 | panic("update: rofs mod"); |
1545 | } | | 1557 | } |
1546 | | | 1558 | |
1547 | /* Allocate a marker vnode. */ | | 1559 | /* Allocate a marker vnode. */ |
1548 | if ((mvp = vnalloc(mp)) == NULL) | | 1560 | if ((mvp = vnalloc(mp)) == NULL) |
1549 | return (ENOMEM); | | 1561 | return (ENOMEM); |
1550 | | | 1562 | |
1551 | fstrans_start(mp, FSTRANS_SHARED); | | 1563 | fstrans_start(mp, FSTRANS_SHARED); |
1552 | is_suspending = (fstrans_getstate(mp) == FSTRANS_SUSPENDING); | | 1564 | is_suspending = (fstrans_getstate(mp) == FSTRANS_SUSPENDING); |
1553 | /* | | 1565 | /* |
1554 | * We can't lock vnodes while the file system is suspending because | | 1566 | * We can't lock vnodes while the file system is suspending because |
1555 | * threads waiting on fstrans may have locked vnodes. | | 1567 | * threads waiting on fstrans may have locked vnodes. |
1556 | */ | | 1568 | */ |
1557 | if (is_suspending) | | 1569 | if (is_suspending) |
1558 | lk_flags = 0; | | 1570 | lk_flags = 0; |
1559 | else | | 1571 | else |
1560 | lk_flags = LK_EXCLUSIVE | LK_NOWAIT; | | 1572 | lk_flags = LK_EXCLUSIVE | LK_NOWAIT; |
1561 | /* | | 1573 | /* |
1562 | * Write back each (modified) inode. | | 1574 | * Write back each (modified) inode. |
1563 | */ | | 1575 | */ |
1564 | mutex_enter(&mntvnode_lock); | | 1576 | mutex_enter(&mntvnode_lock); |
1565 | loop: | | 1577 | loop: |
1566 | /* | | 1578 | /* |
1567 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() | | 1579 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() |
1568 | * and vclean() can be called indirectly | | 1580 | * and vclean() can be called indirectly |
1569 | */ | | 1581 | */ |
1570 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) { | | 1582 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) { |
1571 | nvp = TAILQ_NEXT(vp, v_mntvnodes); | | 1583 | nvp = TAILQ_NEXT(vp, v_mntvnodes); |
1572 | /* | | 1584 | /* |
1573 | * If the vnode that we are about to sync is no longer | | 1585 | * If the vnode that we are about to sync is no longer |
1574 | * associated with this mount point, start over. | | 1586 | * associated with this mount point, start over. |
1575 | */ | | 1587 | */ |
1576 | if (vp->v_mount != mp) | | 1588 | if (vp->v_mount != mp) |
1577 | goto loop; | | 1589 | goto loop; |
1578 | /* | | 1590 | /* |
1579 | * Don't interfere with concurrent scans of this FS. | | 1591 | * Don't interfere with concurrent scans of this FS. |
1580 | */ | | 1592 | */ |
1581 | if (vismarker(vp)) | | 1593 | if (vismarker(vp)) |
1582 | continue; | | 1594 | continue; |
1583 | mutex_enter(&vp->v_interlock); | | 1595 | mutex_enter(&vp->v_interlock); |
1584 | ip = VTOI(vp); | | 1596 | ip = VTOI(vp); |
1585 | | | 1597 | |
1586 | /* | | 1598 | /* |
1587 | * Skip the vnode/inode if inaccessible. | | 1599 | * Skip the vnode/inode if inaccessible. |
1588 | */ | | 1600 | */ |
1589 | if (ip == NULL || (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0 || | | 1601 | if (ip == NULL || (vp->v_iflag & (VI_XLOCK | VI_CLEAN)) != 0 || |
1590 | vp->v_type == VNON) { | | 1602 | vp->v_type == VNON) { |
1591 | mutex_exit(&vp->v_interlock); | | 1603 | mutex_exit(&vp->v_interlock); |
1592 | continue; | | 1604 | continue; |
1593 | } | | 1605 | } |
1594 | | | 1606 | |
1595 | /* | | 1607 | /* |
1596 | * We deliberately update inode times here. This will | | 1608 | * We deliberately update inode times here. This will |
1597 | * prevent a massive queue of updates accumulating, only | | 1609 | * prevent a massive queue of updates accumulating, only |
1598 | * to be handled by a call to unmount. | | 1610 | * to be handled by a call to unmount. |
1599 | * | | 1611 | * |
1600 | * XXX It would be better to have the syncer trickle these | | 1612 | * XXX It would be better to have the syncer trickle these |
1601 | * out. Adjustment needed to allow registering vnodes for | | 1613 | * out. Adjustment needed to allow registering vnodes for |
1602 | * sync when the vnode is clean, but the inode dirty. Or | | 1614 | * sync when the vnode is clean, but the inode dirty. Or |
1603 | * have ufs itself trickle out inode updates. | | 1615 | * have ufs itself trickle out inode updates. |
1604 | * | | 1616 | * |
1605 | * If doing a lazy sync, we don't care about metadata or | | 1617 | * If doing a lazy sync, we don't care about metadata or |
1606 | * data updates, because they are handled by each vnode's | | 1618 | * data updates, because they are handled by each vnode's |
1607 | * synclist entry. In this case we are only interested in | | 1619 | * synclist entry. In this case we are only interested in |
1608 | * writing back modified inodes. | | 1620 | * writing back modified inodes. |
1609 | */ | | 1621 | */ |
1610 | if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | | | 1622 | if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | |
1611 | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) == 0 && | | 1623 | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) == 0 && |
1612 | (waitfor == MNT_LAZY || (LIST_EMPTY(&vp->v_dirtyblkhd) && | | 1624 | (waitfor == MNT_LAZY || (LIST_EMPTY(&vp->v_dirtyblkhd) && |
1613 | UVM_OBJ_IS_CLEAN(&vp->v_uobj)))) { | | 1625 | UVM_OBJ_IS_CLEAN(&vp->v_uobj)))) { |
1614 | mutex_exit(&vp->v_interlock); | | 1626 | mutex_exit(&vp->v_interlock); |
1615 | continue; | | 1627 | continue; |
1616 | } | | 1628 | } |
1617 | if (vp->v_type == VBLK && is_suspending) { | | 1629 | if (vp->v_type == VBLK && is_suspending) { |
1618 | mutex_exit(&vp->v_interlock); | | 1630 | mutex_exit(&vp->v_interlock); |
1619 | continue; | | 1631 | continue; |
1620 | } | | 1632 | } |
1621 | vmark(mvp, vp); | | 1633 | vmark(mvp, vp); |
1622 | mutex_exit(&mntvnode_lock); | | 1634 | mutex_exit(&mntvnode_lock); |
1623 | error = vget(vp, lk_flags); | | 1635 | error = vget(vp, lk_flags); |
1624 | if (error) { | | 1636 | if (error) { |
1625 | mutex_enter(&mntvnode_lock); | | 1637 | mutex_enter(&mntvnode_lock); |
1626 | nvp = vunmark(mvp); | | 1638 | nvp = vunmark(mvp); |
1627 | if (error == ENOENT) { | | 1639 | if (error == ENOENT) { |
1628 | goto loop; | | 1640 | goto loop; |
1629 | } | | 1641 | } |
1630 | continue; | | 1642 | continue; |
1631 | } | | 1643 | } |
1632 | if (waitfor == MNT_LAZY) { | | 1644 | if (waitfor == MNT_LAZY) { |
1633 | error = UFS_WAPBL_BEGIN(vp->v_mount); | | 1645 | error = UFS_WAPBL_BEGIN(vp->v_mount); |
1634 | if (!error) { | | 1646 | if (!error) { |
1635 | error = ffs_update(vp, NULL, NULL, | | 1647 | error = ffs_update(vp, NULL, NULL, |
1636 | UPDATE_CLOSE); | | 1648 | UPDATE_CLOSE); |
1637 | UFS_WAPBL_END(vp->v_mount); | | 1649 | UFS_WAPBL_END(vp->v_mount); |
1638 | } | | 1650 | } |
1639 | } else { | | 1651 | } else { |
1640 | error = VOP_FSYNC(vp, cred, FSYNC_NOLOG | | | 1652 | error = VOP_FSYNC(vp, cred, FSYNC_NOLOG | |
1641 | (waitfor == MNT_WAIT ? FSYNC_WAIT : 0), 0, 0); | | 1653 | (waitfor == MNT_WAIT ? FSYNC_WAIT : 0), 0, 0); |
1642 | } | | 1654 | } |
1643 | if (error) | | 1655 | if (error) |
1644 | allerror = error; | | 1656 | allerror = error; |
1645 | if (is_suspending) | | 1657 | if (is_suspending) |
1646 | vrele(vp); | | 1658 | vrele(vp); |
1647 | else | | 1659 | else |
1648 | vput(vp); | | 1660 | vput(vp); |
1649 | mutex_enter(&mntvnode_lock); | | 1661 | mutex_enter(&mntvnode_lock); |
1650 | nvp = vunmark(mvp); | | 1662 | nvp = vunmark(mvp); |
1651 | } | | 1663 | } |
1652 | mutex_exit(&mntvnode_lock); | | 1664 | mutex_exit(&mntvnode_lock); |
1653 | /* | | 1665 | /* |
1654 | * Force stale file system control information to be flushed. | | 1666 | * Force stale file system control information to be flushed. |
1655 | */ | | 1667 | */ |
1656 | if (waitfor != MNT_LAZY && (ump->um_devvp->v_numoutput > 0 || | | 1668 | if (waitfor != MNT_LAZY && (ump->um_devvp->v_numoutput > 0 || |
1657 | !LIST_EMPTY(&ump->um_devvp->v_dirtyblkhd))) { | | 1669 | !LIST_EMPTY(&ump->um_devvp->v_dirtyblkhd))) { |
1658 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); | | 1670 | vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); |
1659 | if ((error = VOP_FSYNC(ump->um_devvp, cred, | | 1671 | if ((error = VOP_FSYNC(ump->um_devvp, cred, |
1660 | (waitfor == MNT_WAIT ? FSYNC_WAIT : 0) | FSYNC_NOLOG, | | 1672 | (waitfor == MNT_WAIT ? FSYNC_WAIT : 0) | FSYNC_NOLOG, |
1661 | 0, 0)) != 0) | | 1673 | 0, 0)) != 0) |
1662 | allerror = error; | | 1674 | allerror = error; |
1663 | VOP_UNLOCK(ump->um_devvp); | | 1675 | VOP_UNLOCK(ump->um_devvp); |
1664 | if (allerror == 0 && waitfor == MNT_WAIT && !mp->mnt_wapbl) { | | 1676 | if (allerror == 0 && waitfor == MNT_WAIT && !mp->mnt_wapbl) { |
1665 | mutex_enter(&mntvnode_lock); | | 1677 | mutex_enter(&mntvnode_lock); |
1666 | goto loop; | | 1678 | goto loop; |
1667 | } | | 1679 | } |
1668 | } | | 1680 | } |
1669 | #ifdef QUOTA | | 1681 | #ifdef QUOTA |
1670 | qsync(mp); | | 1682 | qsync(mp); |
1671 | #endif | | 1683 | #endif |
1672 | /* | | 1684 | /* |
1673 | * Write back modified superblock. | | 1685 | * Write back modified superblock. |
1674 | */ | | 1686 | */ |
1675 | if (fs->fs_fmod != 0) { | | 1687 | if (fs->fs_fmod != 0) { |
1676 | fs->fs_fmod = 0; | | 1688 | fs->fs_fmod = 0; |
1677 | fs->fs_time = time_second; | | 1689 | fs->fs_time = time_second; |
1678 | error = UFS_WAPBL_BEGIN(mp); | | 1690 | error = UFS_WAPBL_BEGIN(mp); |
1679 | if (error) | | 1691 | if (error) |
1680 | allerror = error; | | 1692 | allerror = error; |
1681 | else { | | 1693 | else { |
1682 | if ((error = ffs_cgupdate(ump, waitfor))) | | 1694 | if ((error = ffs_cgupdate(ump, waitfor))) |
1683 | allerror = error; | | 1695 | allerror = error; |
1684 | UFS_WAPBL_END(mp); | | 1696 | UFS_WAPBL_END(mp); |
1685 | } | | 1697 | } |
1686 | } | | 1698 | } |
1687 | | | 1699 | |
1688 | #ifdef WAPBL | | 1700 | #ifdef WAPBL |
1689 | if (mp->mnt_wapbl) { | | 1701 | if (mp->mnt_wapbl) { |
1690 | error = wapbl_flush(mp->mnt_wapbl, 0); | | 1702 | error = wapbl_flush(mp->mnt_wapbl, 0); |
1691 | if (error) | | 1703 | if (error) |
1692 | allerror = error; | | 1704 | allerror = error; |
1693 | } | | 1705 | } |
1694 | #endif | | 1706 | #endif |
1695 | | | 1707 | |
1696 | fstrans_done(mp); | | 1708 | fstrans_done(mp); |
1697 | vnfree(mvp); | | 1709 | vnfree(mvp); |
1698 | return (allerror); | | 1710 | return (allerror); |
1699 | } | | 1711 | } |
1700 | | | 1712 | |
1701 | /* | | 1713 | /* |
1702 | * Look up a FFS dinode number to find its incore vnode, otherwise read it | | 1714 | * Look up a FFS dinode number to find its incore vnode, otherwise read it |
1703 | * in from disk. If it is in core, wait for the lock bit to clear, then | | 1715 | * in from disk. If it is in core, wait for the lock bit to clear, then |
1704 | * return the inode locked. Detection and handling of mount points must be | | 1716 | * return the inode locked. Detection and handling of mount points must be |
1705 | * done by the calling routine. | | 1717 | * done by the calling routine. |
1706 | */ | | 1718 | */ |
1707 | int | | 1719 | int |
1708 | ffs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) | | 1720 | ffs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) |
1709 | { | | 1721 | { |
1710 | struct fs *fs; | | 1722 | struct fs *fs; |
1711 | struct inode *ip; | | 1723 | struct inode *ip; |
1712 | struct ufsmount *ump; | | 1724 | struct ufsmount *ump; |
1713 | struct buf *bp; | | 1725 | struct buf *bp; |
1714 | struct vnode *vp; | | 1726 | struct vnode *vp; |
1715 | dev_t dev; | | 1727 | dev_t dev; |
1716 | int error; | | 1728 | int error; |
1717 | | | 1729 | |
1718 | ump = VFSTOUFS(mp); | | 1730 | ump = VFSTOUFS(mp); |
1719 | dev = ump->um_dev; | | 1731 | dev = ump->um_dev; |
1720 | | | 1732 | |
1721 | retry: | | 1733 | retry: |
1722 | if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) | | 1734 | if ((*vpp = ufs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) |
1723 | return (0); | | 1735 | return (0); |
1724 | | | 1736 | |
1725 | /* Allocate a new vnode/inode. */ | | 1737 | /* Allocate a new vnode/inode. */ |
1726 | if ((error = getnewvnode(VT_UFS, mp, ffs_vnodeop_p, &vp)) != 0) { | | 1738 | if ((error = getnewvnode(VT_UFS, mp, ffs_vnodeop_p, &vp)) != 0) { |
1727 | *vpp = NULL; | | 1739 | *vpp = NULL; |
1728 | return (error); | | 1740 | return (error); |
1729 | } | | 1741 | } |
1730 | ip = pool_cache_get(ffs_inode_cache, PR_WAITOK); | | 1742 | ip = pool_cache_get(ffs_inode_cache, PR_WAITOK); |
1731 | | | 1743 | |
1732 | /* | | 1744 | /* |
1733 | * If someone beat us to it, put back the freshly allocated | | 1745 | * If someone beat us to it, put back the freshly allocated |
1734 | * vnode/inode pair and retry. | | 1746 | * vnode/inode pair and retry. |
1735 | */ | | 1747 | */ |
1736 | mutex_enter(&ufs_hashlock); | | 1748 | mutex_enter(&ufs_hashlock); |
1737 | if (ufs_ihashget(dev, ino, 0) != NULL) { | | 1749 | if (ufs_ihashget(dev, ino, 0) != NULL) { |
1738 | mutex_exit(&ufs_hashlock); | | 1750 | mutex_exit(&ufs_hashlock); |
1739 | ungetnewvnode(vp); | | 1751 | ungetnewvnode(vp); |
1740 | pool_cache_put(ffs_inode_cache, ip); | | 1752 | pool_cache_put(ffs_inode_cache, ip); |
1741 | goto retry; | | 1753 | goto retry; |
1742 | } | | 1754 | } |
1743 | | | 1755 | |
1744 | vp->v_vflag |= VV_LOCKSWORK; | | 1756 | vp->v_vflag |= VV_LOCKSWORK; |
1745 | | | 1757 | |
1746 | /* | | 1758 | /* |
1747 | * XXX MFS ends up here, too, to allocate an inode. Should we | | 1759 | * XXX MFS ends up here, too, to allocate an inode. Should we |
1748 | * XXX create another pool for MFS inodes? | | 1760 | * XXX create another pool for MFS inodes? |
1749 | */ | | 1761 | */ |
1750 | | | 1762 | |
1751 | memset(ip, 0, sizeof(struct inode)); | | 1763 | memset(ip, 0, sizeof(struct inode)); |
1752 | vp->v_data = ip; | | 1764 | vp->v_data = ip; |
1753 | ip->i_vnode = vp; | | 1765 | ip->i_vnode = vp; |
1754 | ip->i_ump = ump; | | 1766 | ip->i_ump = ump; |
1755 | ip->i_fs = fs = ump->um_fs; | | 1767 | ip->i_fs = fs = ump->um_fs; |
1756 | ip->i_dev = dev; | | 1768 | ip->i_dev = dev; |
1757 | ip->i_number = ino; | | 1769 | ip->i_number = ino; |
1758 | #ifdef QUOTA | | 1770 | #ifdef QUOTA |
1759 | ufsquota_init(ip); | | 1771 | ufsquota_init(ip); |
1760 | #endif | | 1772 | #endif |
1761 | | | 1773 | |
1762 | /* | | 1774 | /* |
1763 | * Initialize genfs node, we might proceed to destroy it in | | 1775 | * Initialize genfs node, we might proceed to destroy it in |
1764 | * error branches. | | 1776 | * error branches. |
1765 | */ | | 1777 | */ |
1766 | genfs_node_init(vp, &ffs_genfsops); | | 1778 | genfs_node_init(vp, &ffs_genfsops); |
1767 | | | 1779 | |
1768 | /* | | 1780 | /* |
1769 | * Put it onto its hash chain and lock it so that other requests for | | 1781 | * Put it onto its hash chain and lock it so that other requests for |
1770 | * this inode will block if they arrive while we are sleeping waiting | | 1782 | * this inode will block if they arrive while we are sleeping waiting |
1771 | * for old data structures to be purged or for the contents of the | | 1783 | * for old data structures to be purged or for the contents of the |
1772 | * disk portion of this inode to be read. | | 1784 | * disk portion of this inode to be read. |
1773 | */ | | 1785 | */ |
1774 | | | 1786 | |
1775 | ufs_ihashins(ip); | | 1787 | ufs_ihashins(ip); |
1776 | mutex_exit(&ufs_hashlock); | | 1788 | mutex_exit(&ufs_hashlock); |
1777 | | | 1789 | |
1778 | /* Read in the disk contents for the inode, copy into the inode. */ | | 1790 | /* Read in the disk contents for the inode, copy into the inode. */ |
1779 | error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)), | | 1791 | error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)), |
1780 | (int)fs->fs_bsize, NOCRED, 0, &bp); | | 1792 | (int)fs->fs_bsize, NOCRED, 0, &bp); |
1781 | if (error) { | | 1793 | if (error) { |
1782 | | | 1794 | |
1783 | /* | | 1795 | /* |
1784 | * The inode does not contain anything useful, so it would | | 1796 | * The inode does not contain anything useful, so it would |
1785 | * be misleading to leave it on its hash chain. With mode | | 1797 | * be misleading to leave it on its hash chain. With mode |
1786 | * still zero, it will be unlinked and returned to the free | | 1798 | * still zero, it will be unlinked and returned to the free |
1787 | * list by vput(). | | 1799 | * list by vput(). |
1788 | */ | | 1800 | */ |
1789 | | | 1801 | |
1790 | vput(vp); | | 1802 | vput(vp); |
1791 | brelse(bp, 0); | | 1803 | brelse(bp, 0); |
1792 | *vpp = NULL; | | 1804 | *vpp = NULL; |
1793 | return (error); | | 1805 | return (error); |
1794 | } | | 1806 | } |
1795 | if (ip->i_ump->um_fstype == UFS1) | | 1807 | if (ip->i_ump->um_fstype == UFS1) |
1796 | ip->i_din.ffs1_din = pool_cache_get(ffs_dinode1_cache, | | 1808 | ip->i_din.ffs1_din = pool_cache_get(ffs_dinode1_cache, |
1797 | PR_WAITOK); | | 1809 | PR_WAITOK); |
1798 | else | | 1810 | else |
1799 | ip->i_din.ffs2_din = pool_cache_get(ffs_dinode2_cache, | | 1811 | ip->i_din.ffs2_din = pool_cache_get(ffs_dinode2_cache, |
1800 | PR_WAITOK); | | 1812 | PR_WAITOK); |
1801 | ffs_load_inode(bp, ip, fs, ino); | | 1813 | ffs_load_inode(bp, ip, fs, ino); |
1802 | brelse(bp, 0); | | 1814 | brelse(bp, 0); |
1803 | | | 1815 | |
1804 | /* | | 1816 | /* |
1805 | * Initialize the vnode from the inode, check for aliases. | | 1817 | * Initialize the vnode from the inode, check for aliases. |
1806 | * Note that the underlying vnode may have changed. | | 1818 | * Note that the underlying vnode may have changed. |
1807 | */ | | 1819 | */ |
1808 | | | 1820 | |
1809 | ufs_vinit(mp, ffs_specop_p, ffs_fifoop_p, &vp); | | 1821 | ufs_vinit(mp, ffs_specop_p, ffs_fifoop_p, &vp); |
1810 | | | 1822 | |
1811 | /* | | 1823 | /* |
1812 | * Finish inode initialization now that aliasing has been resolved. | | 1824 | * Finish inode initialization now that aliasing has been resolved. |
1813 | */ | | 1825 | */ |
1814 | | | 1826 | |
1815 | ip->i_devvp = ump->um_devvp; | | 1827 | ip->i_devvp = ump->um_devvp; |
1816 | vref(ip->i_devvp); | | 1828 | vref(ip->i_devvp); |
1817 | | | 1829 | |
1818 | /* | | 1830 | /* |
1819 | * Ensure that uid and gid are correct. This is a temporary | | 1831 | * Ensure that uid and gid are correct. This is a temporary |
1820 | * fix until fsck has been changed to do the update. | | 1832 | * fix until fsck has been changed to do the update. |
1821 | */ | | 1833 | */ |
1822 | | | 1834 | |
1823 | if (fs->fs_old_inodefmt < FS_44INODEFMT) { /* XXX */ | | 1835 | if (fs->fs_old_inodefmt < FS_44INODEFMT) { /* XXX */ |
1824 | ip->i_uid = ip->i_ffs1_ouid; /* XXX */ | | 1836 | ip->i_uid = ip->i_ffs1_ouid; /* XXX */ |
1825 | ip->i_gid = ip->i_ffs1_ogid; /* XXX */ | | 1837 | ip->i_gid = ip->i_ffs1_ogid; /* XXX */ |
1826 | } /* XXX */ | | 1838 | } /* XXX */ |
1827 | uvm_vnp_setsize(vp, ip->i_size); | | 1839 | uvm_vnp_setsize(vp, ip->i_size); |
1828 | *vpp = vp; | | 1840 | *vpp = vp; |
1829 | return (0); | | 1841 | return (0); |
1830 | } | | 1842 | } |
1831 | | | 1843 | |
1832 | /* | | 1844 | /* |
1833 | * File handle to vnode | | 1845 | * File handle to vnode |
1834 | * | | 1846 | * |
1835 | * Have to be really careful about stale file handles: | | 1847 | * Have to be really careful about stale file handles: |
1836 | * - check that the inode number is valid | | 1848 | * - check that the inode number is valid |
1837 | * - call ffs_vget() to get the locked inode | | 1849 | * - call ffs_vget() to get the locked inode |
1838 | * - check for an unallocated inode (i_mode == 0) | | 1850 | * - check for an unallocated inode (i_mode == 0) |
1839 | * - check that the given client host has export rights and return | | 1851 | * - check that the given client host has export rights and return |
1840 | * those rights via. exflagsp and credanonp | | 1852 | * those rights via. exflagsp and credanonp |
1841 | */ | | 1853 | */ |
1842 | int | | 1854 | int |
1843 | ffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) | | 1855 | ffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) |
1844 | { | | 1856 | { |
1845 | struct ufid ufh; | | 1857 | struct ufid ufh; |
1846 | struct fs *fs; | | 1858 | struct fs *fs; |
1847 | | | 1859 | |
1848 | if (fhp->fid_len != sizeof(struct ufid)) | | 1860 | if (fhp->fid_len != sizeof(struct ufid)) |
1849 | return EINVAL; | | 1861 | return EINVAL; |
1850 | | | 1862 | |
1851 | memcpy(&ufh, fhp, sizeof(ufh)); | | 1863 | memcpy(&ufh, fhp, sizeof(ufh)); |
1852 | fs = VFSTOUFS(mp)->um_fs; | | 1864 | fs = VFSTOUFS(mp)->um_fs; |
1853 | if (ufh.ufid_ino < ROOTINO || | | 1865 | if (ufh.ufid_ino < ROOTINO || |
1854 | ufh.ufid_ino >= fs->fs_ncg * fs->fs_ipg) | | 1866 | ufh.ufid_ino >= fs->fs_ncg * fs->fs_ipg) |
1855 | return (ESTALE); | | 1867 | return (ESTALE); |
1856 | return (ufs_fhtovp(mp, &ufh, vpp)); | | 1868 | return (ufs_fhtovp(mp, &ufh, vpp)); |
1857 | } | | 1869 | } |
1858 | | | 1870 | |
1859 | /* | | 1871 | /* |
1860 | * Vnode pointer to File handle | | 1872 | * Vnode pointer to File handle |
1861 | */ | | 1873 | */ |
1862 | /* ARGSUSED */ | | 1874 | /* ARGSUSED */ |
1863 | int | | 1875 | int |
1864 | ffs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) | | 1876 | ffs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) |
1865 | { | | 1877 | { |
1866 | struct inode *ip; | | 1878 | struct inode *ip; |
1867 | struct ufid ufh; | | 1879 | struct ufid ufh; |
1868 | | | 1880 | |
1869 | if (*fh_size < sizeof(struct ufid)) { | | 1881 | if (*fh_size < sizeof(struct ufid)) { |
1870 | *fh_size = sizeof(struct ufid); | | 1882 | *fh_size = sizeof(struct ufid); |
1871 | return E2BIG; | | 1883 | return E2BIG; |
1872 | } | | 1884 | } |
1873 | ip = VTOI(vp); | | 1885 | ip = VTOI(vp); |
1874 | *fh_size = sizeof(struct ufid); | | 1886 | *fh_size = sizeof(struct ufid); |
1875 | memset(&ufh, 0, sizeof(ufh)); | | 1887 | memset(&ufh, 0, sizeof(ufh)); |
1876 | ufh.ufid_len = sizeof(struct ufid); | | 1888 | ufh.ufid_len = sizeof(struct ufid); |
1877 | ufh.ufid_ino = ip->i_number; | | 1889 | ufh.ufid_ino = ip->i_number; |
1878 | ufh.ufid_gen = ip->i_gen; | | 1890 | ufh.ufid_gen = ip->i_gen; |
1879 | memcpy(fhp, &ufh, sizeof(ufh)); | | 1891 | memcpy(fhp, &ufh, sizeof(ufh)); |
1880 | return (0); | | 1892 | return (0); |
1881 | } | | 1893 | } |
1882 | | | 1894 | |
1883 | void | | 1895 | void |
1884 | ffs_init(void) | | 1896 | ffs_init(void) |
1885 | { | | 1897 | { |
1886 | if (ffs_initcount++ > 0) | | 1898 | if (ffs_initcount++ > 0) |
1887 | return; | | 1899 | return; |
1888 | | | 1900 | |
1889 | ffs_inode_cache = pool_cache_init(sizeof(struct inode), 0, 0, 0, | | 1901 | ffs_inode_cache = pool_cache_init(sizeof(struct inode), 0, 0, 0, |
1890 | "ffsino", NULL, IPL_NONE, NULL, NULL, NULL); | | 1902 | "ffsino", NULL, IPL_NONE, NULL, NULL, NULL); |
1891 | ffs_dinode1_cache = pool_cache_init(sizeof(struct ufs1_dinode), 0, 0, 0, | | 1903 | ffs_dinode1_cache = pool_cache_init(sizeof(struct ufs1_dinode), 0, 0, 0, |
1892 | "ffsdino1", NULL, IPL_NONE, NULL, NULL, NULL); | | 1904 | "ffsdino1", NULL, IPL_NONE, NULL, NULL, NULL); |
1893 | ffs_dinode2_cache = pool_cache_init(sizeof(struct ufs2_dinode), 0, 0, 0, | | 1905 | ffs_dinode2_cache = pool_cache_init(sizeof(struct ufs2_dinode), 0, 0, 0, |
1894 | "ffsdino2", NULL, IPL_NONE, NULL, NULL, NULL); | | 1906 | "ffsdino2", NULL, IPL_NONE, NULL, NULL, NULL); |
1895 | ufs_init(); | | 1907 | ufs_init(); |
1896 | } | | 1908 | } |
1897 | | | 1909 | |
1898 | void | | 1910 | void |
1899 | ffs_reinit(void) | | 1911 | ffs_reinit(void) |
1900 | { | | 1912 | { |
1901 | | | 1913 | |
1902 | ufs_reinit(); | | 1914 | ufs_reinit(); |
1903 | } | | 1915 | } |
1904 | | | 1916 | |
1905 | void | | 1917 | void |
1906 | ffs_done(void) | | 1918 | ffs_done(void) |
1907 | { | | 1919 | { |
1908 | if (--ffs_initcount > 0) | | 1920 | if (--ffs_initcount > 0) |
1909 | return; | | 1921 | return; |
1910 | | | 1922 | |
1911 | ufs_done(); | | 1923 | ufs_done(); |
1912 | pool_cache_destroy(ffs_dinode2_cache); | | 1924 | pool_cache_destroy(ffs_dinode2_cache); |
1913 | pool_cache_destroy(ffs_dinode1_cache); | | 1925 | pool_cache_destroy(ffs_dinode1_cache); |
1914 | pool_cache_destroy(ffs_inode_cache); | | 1926 | pool_cache_destroy(ffs_inode_cache); |
1915 | } | | 1927 | } |
1916 | | | 1928 | |
1917 | /* | | 1929 | /* |
1918 | * Write a superblock and associated information back to disk. | | 1930 | * Write a superblock and associated information back to disk. |
1919 | */ | | 1931 | */ |
1920 | int | | 1932 | int |
1921 | ffs_sbupdate(struct ufsmount *mp, int waitfor) | | 1933 | ffs_sbupdate(struct ufsmount *mp, int waitfor) |
1922 | { | | 1934 | { |
1923 | struct fs *fs = mp->um_fs; | | 1935 | struct fs *fs = mp->um_fs; |
1924 | struct buf *bp; | | 1936 | struct buf *bp; |
1925 | int error = 0; | | 1937 | int error = 0; |
1926 | u_int32_t saveflag; | | 1938 | u_int32_t saveflag; |
1927 | | | 1939 | |
1928 | error = ffs_getblk(mp->um_devvp, | | 1940 | error = ffs_getblk(mp->um_devvp, |
1929 | fs->fs_sblockloc / DEV_BSIZE, FFS_NOBLK, | | 1941 | fs->fs_sblockloc / DEV_BSIZE, FFS_NOBLK, |
1930 | fs->fs_sbsize, false, &bp); | | 1942 | fs->fs_sbsize, false, &bp); |
1931 | if (error) | | 1943 | if (error) |
1932 | return error; | | 1944 | return error; |
1933 | saveflag = fs->fs_flags & FS_INTERNAL; | | 1945 | saveflag = fs->fs_flags & FS_INTERNAL; |
1934 | fs->fs_flags &= ~FS_INTERNAL; | | 1946 | fs->fs_flags &= ~FS_INTERNAL; |