| @@ -1,1322 +1,1317 @@ | | | @@ -1,1322 +1,1317 @@ |
1 | /* $NetBSD: ffs_vfsops.c,v 1.236 2008/09/21 23:22:00 freza Exp $ */ | | 1 | /* $NetBSD: ffs_vfsops.c,v 1.237 2008/09/23 15:27:59 pooka Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 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. | | 8 | * by Wasabi Systems, Inc. |
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.236 2008/09/21 23:22:00 freza Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.237 2008/09/23 15:27:59 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_softdep.h" | | 69 | #include "opt_softdep.h" |
70 | #include "opt_wapbl.h" | | 70 | #include "opt_wapbl.h" |
71 | #endif | | 71 | #endif |
72 | | | 72 | |
73 | #include <sys/param.h> | | 73 | #include <sys/param.h> |
74 | #include <sys/systm.h> | | 74 | #include <sys/systm.h> |
75 | #include <sys/namei.h> | | 75 | #include <sys/namei.h> |
76 | #include <sys/proc.h> | | 76 | #include <sys/proc.h> |
77 | #include <sys/kernel.h> | | 77 | #include <sys/kernel.h> |
78 | #include <sys/vnode.h> | | 78 | #include <sys/vnode.h> |
79 | #include <sys/socket.h> | | 79 | #include <sys/socket.h> |
80 | #include <sys/mount.h> | | 80 | #include <sys/mount.h> |
81 | #include <sys/buf.h> | | 81 | #include <sys/buf.h> |
82 | #include <sys/device.h> | | 82 | #include <sys/device.h> |
83 | #include <sys/mbuf.h> | | 83 | #include <sys/mbuf.h> |
84 | #include <sys/file.h> | | 84 | #include <sys/file.h> |
85 | #include <sys/disklabel.h> | | 85 | #include <sys/disklabel.h> |
86 | #include <sys/ioctl.h> | | 86 | #include <sys/ioctl.h> |
87 | #include <sys/errno.h> | | 87 | #include <sys/errno.h> |
88 | #include <sys/malloc.h> | | 88 | #include <sys/malloc.h> |
89 | #include <sys/pool.h> | | 89 | #include <sys/pool.h> |
90 | #include <sys/lock.h> | | 90 | #include <sys/lock.h> |
91 | #include <sys/sysctl.h> | | 91 | #include <sys/sysctl.h> |
92 | #include <sys/conf.h> | | 92 | #include <sys/conf.h> |
93 | #include <sys/kauth.h> | | 93 | #include <sys/kauth.h> |
94 | #include <sys/wapbl.h> | | 94 | #include <sys/wapbl.h> |
95 | #include <sys/fstrans.h> | | 95 | #include <sys/fstrans.h> |
96 | #include <sys/module.h> | | 96 | #include <sys/module.h> |
97 | | | 97 | |
98 | #include <miscfs/genfs/genfs.h> | | 98 | #include <miscfs/genfs/genfs.h> |
99 | #include <miscfs/specfs/specdev.h> | | 99 | #include <miscfs/specfs/specdev.h> |
100 | | | 100 | |
101 | #include <ufs/ufs/quota.h> | | 101 | #include <ufs/ufs/quota.h> |
102 | #include <ufs/ufs/ufsmount.h> | | 102 | #include <ufs/ufs/ufsmount.h> |
103 | #include <ufs/ufs/inode.h> | | 103 | #include <ufs/ufs/inode.h> |
104 | #include <ufs/ufs/dir.h> | | 104 | #include <ufs/ufs/dir.h> |
105 | #include <ufs/ufs/ufs_extern.h> | | 105 | #include <ufs/ufs/ufs_extern.h> |
106 | #include <ufs/ufs/ufs_bswap.h> | | 106 | #include <ufs/ufs/ufs_bswap.h> |
107 | #include <ufs/ufs/ufs_wapbl.h> | | 107 | #include <ufs/ufs/ufs_wapbl.h> |
108 | | | 108 | |
109 | #include <ufs/ffs/fs.h> | | 109 | #include <ufs/ffs/fs.h> |
110 | #include <ufs/ffs/ffs_extern.h> | | 110 | #include <ufs/ffs/ffs_extern.h> |
111 | | | 111 | |
112 | MODULE(MODULE_CLASS_VFS, ffs, NULL); | | 112 | MODULE(MODULE_CLASS_VFS, ffs, NULL); |
113 | | | 113 | |
114 | static struct sysctllog *ffs_sysctl_log; | | 114 | static struct sysctllog *ffs_sysctl_log; |
115 | | | 115 | |
116 | /* how many times ffs_init() was called */ | | 116 | /* how many times ffs_init() was called */ |
117 | int ffs_initcount = 0; | | 117 | int ffs_initcount = 0; |
118 | | | 118 | |
119 | extern kmutex_t ufs_hashlock; | | 119 | extern kmutex_t ufs_hashlock; |
120 | | | 120 | |
121 | extern const struct vnodeopv_desc ffs_vnodeop_opv_desc; | | 121 | extern const struct vnodeopv_desc ffs_vnodeop_opv_desc; |
122 | extern const struct vnodeopv_desc ffs_specop_opv_desc; | | 122 | extern const struct vnodeopv_desc ffs_specop_opv_desc; |
123 | extern const struct vnodeopv_desc ffs_fifoop_opv_desc; | | 123 | extern const struct vnodeopv_desc ffs_fifoop_opv_desc; |
124 | | | 124 | |
125 | const struct vnodeopv_desc * const ffs_vnodeopv_descs[] = { | | 125 | const struct vnodeopv_desc * const ffs_vnodeopv_descs[] = { |
126 | &ffs_vnodeop_opv_desc, | | 126 | &ffs_vnodeop_opv_desc, |
127 | &ffs_specop_opv_desc, | | 127 | &ffs_specop_opv_desc, |
128 | &ffs_fifoop_opv_desc, | | 128 | &ffs_fifoop_opv_desc, |
129 | NULL, | | 129 | NULL, |
130 | }; | | 130 | }; |
131 | | | 131 | |
132 | struct vfsops ffs_vfsops = { | | 132 | struct vfsops ffs_vfsops = { |
133 | MOUNT_FFS, | | 133 | MOUNT_FFS, |
134 | sizeof (struct ufs_args), | | 134 | sizeof (struct ufs_args), |
135 | ffs_mount, | | 135 | ffs_mount, |
136 | ufs_start, | | 136 | ufs_start, |
137 | ffs_unmount, | | 137 | ffs_unmount, |
138 | ufs_root, | | 138 | ufs_root, |
139 | ufs_quotactl, | | 139 | ufs_quotactl, |
140 | ffs_statvfs, | | 140 | ffs_statvfs, |
141 | ffs_sync, | | 141 | ffs_sync, |
142 | ffs_vget, | | 142 | ffs_vget, |
143 | ffs_fhtovp, | | 143 | ffs_fhtovp, |
144 | ffs_vptofh, | | 144 | ffs_vptofh, |
145 | ffs_init, | | 145 | ffs_init, |
146 | ffs_reinit, | | 146 | ffs_reinit, |
147 | ffs_done, | | 147 | ffs_done, |
148 | ffs_mountroot, | | 148 | ffs_mountroot, |
149 | ffs_snapshot, | | 149 | ffs_snapshot, |
150 | ffs_extattrctl, | | 150 | ffs_extattrctl, |
151 | ffs_suspendctl, | | 151 | ffs_suspendctl, |
152 | genfs_renamelock_enter, | | 152 | genfs_renamelock_enter, |
153 | genfs_renamelock_exit, | | 153 | genfs_renamelock_exit, |
154 | ffs_full_fsync, | | 154 | ffs_full_fsync, |
155 | ffs_vnodeopv_descs, | | 155 | ffs_vnodeopv_descs, |
156 | 0, | | 156 | 0, |
157 | { NULL, NULL }, | | 157 | { NULL, NULL }, |
158 | }; | | 158 | }; |
159 | | | 159 | |
160 | static const struct genfs_ops ffs_genfsops = { | | 160 | static const struct genfs_ops ffs_genfsops = { |
161 | .gop_size = ffs_gop_size, | | 161 | .gop_size = ffs_gop_size, |
162 | .gop_alloc = ufs_gop_alloc, | | 162 | .gop_alloc = ufs_gop_alloc, |
163 | .gop_write = ffs_gop_write, | | 163 | .gop_write = ffs_gop_write, |
164 | .gop_markupdate = ufs_gop_markupdate, | | 164 | .gop_markupdate = ufs_gop_markupdate, |
165 | }; | | 165 | }; |
166 | | | 166 | |
167 | static const struct ufs_ops ffs_ufsops = { | | 167 | static const struct ufs_ops ffs_ufsops = { |
168 | .uo_itimes = ffs_itimes, | | 168 | .uo_itimes = ffs_itimes, |
169 | .uo_update = ffs_update, | | 169 | .uo_update = ffs_update, |
170 | .uo_truncate = ffs_truncate, | | 170 | .uo_truncate = ffs_truncate, |
171 | .uo_valloc = ffs_valloc, | | 171 | .uo_valloc = ffs_valloc, |
172 | .uo_vfree = ffs_vfree, | | 172 | .uo_vfree = ffs_vfree, |
173 | .uo_balloc = ffs_balloc, | | 173 | .uo_balloc = ffs_balloc, |
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 | static int dolog; | | | |
303 | | | | |
304 | /* | | 302 | /* |
305 | * VFS Operations. | | 303 | * VFS Operations. |
306 | * | | 304 | * |
307 | * mount system call | | 305 | * mount system call |
308 | */ | | 306 | */ |
309 | int | | 307 | int |
310 | 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) |
311 | { | | 309 | { |
312 | struct lwp *l = curlwp; | | 310 | struct lwp *l = curlwp; |
313 | struct nameidata nd; | | 311 | struct nameidata nd; |
314 | struct vnode *vp, *devvp = NULL; | | 312 | struct vnode *vp, *devvp = NULL; |
315 | struct ufs_args *args = data; | | 313 | struct ufs_args *args = data; |
316 | struct ufsmount *ump = NULL; | | 314 | struct ufsmount *ump = NULL; |
317 | struct fs *fs; | | 315 | struct fs *fs; |
318 | int error = 0, flags, update; | | 316 | int error = 0, flags, update; |
319 | mode_t accessmode; | | 317 | mode_t accessmode; |
320 | | | 318 | |
321 | if (dolog) | | | |
322 | mp->mnt_flag |= MNT_LOG; | | | |
323 | | | | |
324 | if (*data_len < sizeof *args) | | 319 | if (*data_len < sizeof *args) |
325 | return EINVAL; | | 320 | return EINVAL; |
326 | | | 321 | |
327 | if (mp->mnt_flag & MNT_GETARGS) { | | 322 | if (mp->mnt_flag & MNT_GETARGS) { |
328 | ump = VFSTOUFS(mp); | | 323 | ump = VFSTOUFS(mp); |
329 | if (ump == NULL) | | 324 | if (ump == NULL) |
330 | return EIO; | | 325 | return EIO; |
331 | args->fspec = NULL; | | 326 | args->fspec = NULL; |
332 | *data_len = sizeof *args; | | 327 | *data_len = sizeof *args; |
333 | return 0; | | 328 | return 0; |
334 | } | | 329 | } |
335 | | | 330 | |
336 | #if !defined(SOFTDEP) | | 331 | #if !defined(SOFTDEP) |
337 | mp->mnt_flag &= ~MNT_SOFTDEP; | | 332 | mp->mnt_flag &= ~MNT_SOFTDEP; |
338 | #endif | | 333 | #endif |
339 | | | 334 | |
340 | update = mp->mnt_flag & MNT_UPDATE; | | 335 | update = mp->mnt_flag & MNT_UPDATE; |
341 | | | 336 | |
342 | /* Check arguments */ | | 337 | /* Check arguments */ |
343 | if (args->fspec != NULL) { | | 338 | if (args->fspec != NULL) { |
344 | /* | | 339 | /* |
345 | * Look up the name and verify that it's sane. | | 340 | * Look up the name and verify that it's sane. |
346 | */ | | 341 | */ |
347 | NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec); | | 342 | NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec); |
348 | if ((error = namei(&nd)) != 0) | | 343 | if ((error = namei(&nd)) != 0) |
349 | return (error); | | 344 | return (error); |
350 | devvp = nd.ni_vp; | | 345 | devvp = nd.ni_vp; |
351 | | | 346 | |
352 | if (!update) { | | 347 | if (!update) { |
353 | /* | | 348 | /* |
354 | * Be sure this is a valid block device | | 349 | * Be sure this is a valid block device |
355 | */ | | 350 | */ |
356 | if (devvp->v_type != VBLK) | | 351 | if (devvp->v_type != VBLK) |
357 | error = ENOTBLK; | | 352 | error = ENOTBLK; |
358 | else if (bdevsw_lookup(devvp->v_rdev) == NULL) | | 353 | else if (bdevsw_lookup(devvp->v_rdev) == NULL) |
359 | error = ENXIO; | | 354 | error = ENXIO; |
360 | } else { | | 355 | } else { |
361 | /* | | 356 | /* |
362 | * Be sure we're still naming the same device | | 357 | * Be sure we're still naming the same device |
363 | * used for our initial mount | | 358 | * used for our initial mount |
364 | */ | | 359 | */ |
365 | ump = VFSTOUFS(mp); | | 360 | ump = VFSTOUFS(mp); |
366 | if (devvp != ump->um_devvp) { | | 361 | if (devvp != ump->um_devvp) { |
367 | if (devvp->v_rdev != ump->um_devvp->v_rdev) | | 362 | if (devvp->v_rdev != ump->um_devvp->v_rdev) |
368 | error = EINVAL; | | 363 | error = EINVAL; |
369 | else { | | 364 | else { |
370 | vrele(devvp); | | 365 | vrele(devvp); |
371 | devvp = ump->um_devvp; | | 366 | devvp = ump->um_devvp; |
372 | vref(devvp); | | 367 | vref(devvp); |
373 | } | | 368 | } |
374 | } | | 369 | } |
375 | } | | 370 | } |
376 | } else { | | 371 | } else { |
377 | if (!update) { | | 372 | if (!update) { |
378 | /* New mounts must have a filename for the device */ | | 373 | /* New mounts must have a filename for the device */ |
379 | return (EINVAL); | | 374 | return (EINVAL); |
380 | } else { | | 375 | } else { |
381 | /* Use the extant mount */ | | 376 | /* Use the extant mount */ |
382 | ump = VFSTOUFS(mp); | | 377 | ump = VFSTOUFS(mp); |
383 | devvp = ump->um_devvp; | | 378 | devvp = ump->um_devvp; |
384 | vref(devvp); | | 379 | vref(devvp); |
385 | } | | 380 | } |
386 | } | | 381 | } |
387 | | | 382 | |
388 | /* | | 383 | /* |
389 | * Mark the device and any existing vnodes as involved in | | 384 | * Mark the device and any existing vnodes as involved in |
390 | * softdep processing. | | 385 | * softdep processing. |
391 | */ | | 386 | */ |
392 | if ((mp->mnt_flag & MNT_SOFTDEP) != 0) { | | 387 | if ((mp->mnt_flag & MNT_SOFTDEP) != 0) { |
393 | devvp->v_uflag |= VU_SOFTDEP; | | 388 | devvp->v_uflag |= VU_SOFTDEP; |
394 | mutex_enter(&mntvnode_lock); | | 389 | mutex_enter(&mntvnode_lock); |
395 | TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { | | 390 | TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { |
396 | if (vp->v_mount != mp || vismarker(vp)) | | 391 | if (vp->v_mount != mp || vismarker(vp)) |
397 | continue; | | 392 | continue; |
398 | vp->v_uflag |= VU_SOFTDEP; | | 393 | vp->v_uflag |= VU_SOFTDEP; |
399 | } | | 394 | } |
400 | mutex_exit(&mntvnode_lock); | | 395 | mutex_exit(&mntvnode_lock); |
401 | } | | 396 | } |
402 | | | 397 | |
403 | /* | | 398 | /* |
404 | * If mount by non-root, then verify that user has necessary | | 399 | * If mount by non-root, then verify that user has necessary |
405 | * permissions on the device. | | 400 | * permissions on the device. |
406 | */ | | 401 | */ |
407 | if (error == 0 && kauth_authorize_generic(l->l_cred, | | 402 | if (error == 0 && kauth_authorize_generic(l->l_cred, |
408 | KAUTH_GENERIC_ISSUSER, NULL) != 0) { | | 403 | KAUTH_GENERIC_ISSUSER, NULL) != 0) { |
409 | accessmode = VREAD; | | 404 | accessmode = VREAD; |
410 | if (update ? | | 405 | if (update ? |
411 | (mp->mnt_iflag & IMNT_WANTRDWR) != 0 : | | 406 | (mp->mnt_iflag & IMNT_WANTRDWR) != 0 : |
412 | (mp->mnt_flag & MNT_RDONLY) == 0) | | 407 | (mp->mnt_flag & MNT_RDONLY) == 0) |
413 | accessmode |= VWRITE; | | 408 | accessmode |= VWRITE; |
414 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 409 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
415 | error = VOP_ACCESS(devvp, accessmode, l->l_cred); | | 410 | error = VOP_ACCESS(devvp, accessmode, l->l_cred); |
416 | VOP_UNLOCK(devvp, 0); | | 411 | VOP_UNLOCK(devvp, 0); |
417 | } | | 412 | } |
418 | | | 413 | |
419 | if (error) { | | 414 | if (error) { |
420 | vrele(devvp); | | 415 | vrele(devvp); |
421 | return (error); | | 416 | return (error); |
422 | } | | 417 | } |
423 | | | 418 | |
424 | #ifdef WAPBL | | 419 | #ifdef WAPBL |
425 | /* | | 420 | /* |
426 | * WAPBL can only be enabled on a r/w mount | | 421 | * WAPBL can only be enabled on a r/w mount |
427 | * that does not use softdep. | | 422 | * that does not use softdep. |
428 | */ | | 423 | */ |
429 | if ((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) { | | 424 | if ((mp->mnt_flag & MNT_RDONLY) && !(mp->mnt_iflag & IMNT_WANTRDWR)) { |
430 | mp->mnt_flag &= ~MNT_LOG; | | 425 | mp->mnt_flag &= ~MNT_LOG; |
431 | } | | 426 | } |
432 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_LOG)) == | | 427 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_LOG)) == |
433 | (MNT_SOFTDEP | MNT_LOG)) { | | 428 | (MNT_SOFTDEP | MNT_LOG)) { |
434 | printf("%s fs is journalled, ignoring soft update mode\n", | | 429 | printf("%s fs is journalled, ignoring soft update mode\n", |
435 | VFSTOUFS(mp)->um_fs->fs_fsmnt); | | 430 | VFSTOUFS(mp)->um_fs->fs_fsmnt); |
436 | mp->mnt_flag &= ~MNT_SOFTDEP; | | 431 | mp->mnt_flag &= ~MNT_SOFTDEP; |
437 | } | | 432 | } |
438 | #else /* !WAPBL */ | | 433 | #else /* !WAPBL */ |
439 | mp->mnt_flag &= ~MNT_LOG; | | 434 | mp->mnt_flag &= ~MNT_LOG; |
440 | #endif /* !WAPBL */ | | 435 | #endif /* !WAPBL */ |
441 | | | 436 | |
442 | if (!update) { | | 437 | if (!update) { |
443 | int xflags; | | 438 | int xflags; |
444 | | | 439 | |
445 | if (mp->mnt_flag & MNT_RDONLY) | | 440 | if (mp->mnt_flag & MNT_RDONLY) |
446 | xflags = FREAD; | | 441 | xflags = FREAD; |
447 | else | | 442 | else |
448 | xflags = FREAD | FWRITE; | | 443 | xflags = FREAD | FWRITE; |
449 | error = VOP_OPEN(devvp, xflags, FSCRED); | | 444 | error = VOP_OPEN(devvp, xflags, FSCRED); |
450 | if (error) | | 445 | if (error) |
451 | goto fail; | | 446 | goto fail; |
452 | error = ffs_mountfs(devvp, mp, l); | | 447 | error = ffs_mountfs(devvp, mp, l); |
453 | if (error) { | | 448 | if (error) { |
454 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 449 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
455 | (void)VOP_CLOSE(devvp, xflags, NOCRED); | | 450 | (void)VOP_CLOSE(devvp, xflags, NOCRED); |
456 | VOP_UNLOCK(devvp, 0); | | 451 | VOP_UNLOCK(devvp, 0); |
457 | goto fail; | | 452 | goto fail; |
458 | } | | 453 | } |
459 | | | 454 | |
460 | ump = VFSTOUFS(mp); | | 455 | ump = VFSTOUFS(mp); |
461 | fs = ump->um_fs; | | 456 | fs = ump->um_fs; |
462 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_ASYNC)) == | | 457 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_ASYNC)) == |
463 | (MNT_SOFTDEP | MNT_ASYNC)) { | | 458 | (MNT_SOFTDEP | MNT_ASYNC)) { |
464 | printf("%s fs uses soft updates, " | | 459 | printf("%s fs uses soft updates, " |
465 | "ignoring async mode\n", | | 460 | "ignoring async mode\n", |
466 | fs->fs_fsmnt); | | 461 | fs->fs_fsmnt); |
467 | mp->mnt_flag &= ~MNT_ASYNC; | | 462 | mp->mnt_flag &= ~MNT_ASYNC; |
468 | } | | 463 | } |
469 | } else { | | 464 | } else { |
470 | /* | | 465 | /* |
471 | * Update the mount. | | 466 | * Update the mount. |
472 | */ | | 467 | */ |
473 | | | 468 | |
474 | /* | | 469 | /* |
475 | * The initial mount got a reference on this | | 470 | * The initial mount got a reference on this |
476 | * device, so drop the one obtained via | | 471 | * device, so drop the one obtained via |
477 | * namei(), above. | | 472 | * namei(), above. |
478 | */ | | 473 | */ |
479 | vrele(devvp); | | 474 | vrele(devvp); |
480 | | | 475 | |
481 | ump = VFSTOUFS(mp); | | 476 | ump = VFSTOUFS(mp); |
482 | fs = ump->um_fs; | | 477 | fs = ump->um_fs; |
483 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { | | 478 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { |
484 | /* | | 479 | /* |
485 | * Changing from r/w to r/o | | 480 | * Changing from r/w to r/o |
486 | */ | | 481 | */ |
487 | flags = WRITECLOSE; | | 482 | flags = WRITECLOSE; |
488 | if (mp->mnt_flag & MNT_FORCE) | | 483 | if (mp->mnt_flag & MNT_FORCE) |
489 | flags |= FORCECLOSE; | | 484 | flags |= FORCECLOSE; |
490 | if (mp->mnt_flag & MNT_SOFTDEP) | | 485 | if (mp->mnt_flag & MNT_SOFTDEP) |
491 | error = softdep_flushfiles(mp, flags, l); | | 486 | error = softdep_flushfiles(mp, flags, l); |
492 | else | | 487 | else |
493 | error = ffs_flushfiles(mp, flags, l); | | 488 | error = ffs_flushfiles(mp, flags, l); |
494 | if (fs->fs_pendingblocks != 0 || | | 489 | if (fs->fs_pendingblocks != 0 || |
495 | fs->fs_pendinginodes != 0) { | | 490 | fs->fs_pendinginodes != 0) { |
496 | printf("%s: update error: blocks %" PRId64 | | 491 | printf("%s: update error: blocks %" PRId64 |
497 | " files %d\n", | | 492 | " files %d\n", |
498 | fs->fs_fsmnt, fs->fs_pendingblocks, | | 493 | fs->fs_fsmnt, fs->fs_pendingblocks, |
499 | fs->fs_pendinginodes); | | 494 | fs->fs_pendinginodes); |
500 | fs->fs_pendingblocks = 0; | | 495 | fs->fs_pendingblocks = 0; |
501 | fs->fs_pendinginodes = 0; | | 496 | fs->fs_pendinginodes = 0; |
502 | } | | 497 | } |
503 | if (error == 0) | | 498 | if (error == 0) |
504 | error = UFS_WAPBL_BEGIN(mp); | | 499 | error = UFS_WAPBL_BEGIN(mp); |
505 | if (error == 0 && | | 500 | if (error == 0 && |
506 | ffs_cgupdate(ump, MNT_WAIT) == 0 && | | 501 | ffs_cgupdate(ump, MNT_WAIT) == 0 && |
507 | fs->fs_clean & FS_WASCLEAN) { | | 502 | fs->fs_clean & FS_WASCLEAN) { |
508 | if (mp->mnt_flag & MNT_SOFTDEP) | | 503 | if (mp->mnt_flag & MNT_SOFTDEP) |
509 | fs->fs_flags &= ~FS_DOSOFTDEP; | | 504 | fs->fs_flags &= ~FS_DOSOFTDEP; |
510 | fs->fs_clean = FS_ISCLEAN; | | 505 | fs->fs_clean = FS_ISCLEAN; |
511 | (void) ffs_sbupdate(ump, MNT_WAIT); | | 506 | (void) ffs_sbupdate(ump, MNT_WAIT); |
512 | } | | 507 | } |
513 | if (error == 0) | | 508 | if (error == 0) |
514 | UFS_WAPBL_END(mp); | | 509 | UFS_WAPBL_END(mp); |
515 | if (error) | | 510 | if (error) |
516 | return (error); | | 511 | return (error); |
517 | } | | 512 | } |
518 | | | 513 | |
519 | #ifdef WAPBL | | 514 | #ifdef WAPBL |
520 | if ((mp->mnt_flag & MNT_LOG) == 0) { | | 515 | if ((mp->mnt_flag & MNT_LOG) == 0) { |
521 | error = ffs_wapbl_stop(mp, mp->mnt_flag & MNT_FORCE); | | 516 | error = ffs_wapbl_stop(mp, mp->mnt_flag & MNT_FORCE); |
522 | if (error) | | 517 | if (error) |
523 | return error; | | 518 | return error; |
524 | } | | 519 | } |
525 | #endif /* WAPBL */ | | 520 | #endif /* WAPBL */ |
526 | | | 521 | |
527 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { | | 522 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { |
528 | /* | | 523 | /* |
529 | * Finish change from r/w to r/o | | 524 | * Finish change from r/w to r/o |
530 | */ | | 525 | */ |
531 | fs->fs_ronly = 1; | | 526 | fs->fs_ronly = 1; |
532 | fs->fs_fmod = 0; | | 527 | fs->fs_fmod = 0; |
533 | } | | 528 | } |
534 | | | 529 | |
535 | /* | | 530 | /* |
536 | * Flush soft dependencies if disabling it via an update | | 531 | * Flush soft dependencies if disabling it via an update |
537 | * mount. This may leave some items to be processed, | | 532 | * mount. This may leave some items to be processed, |
538 | * so don't do this yet XXX. | | 533 | * so don't do this yet XXX. |
539 | */ | | 534 | */ |
540 | if ((fs->fs_flags & FS_DOSOFTDEP) && | | 535 | if ((fs->fs_flags & FS_DOSOFTDEP) && |
541 | !(mp->mnt_flag & MNT_SOFTDEP) && fs->fs_ronly == 0) { | | 536 | !(mp->mnt_flag & MNT_SOFTDEP) && fs->fs_ronly == 0) { |
542 | #ifdef notyet | | 537 | #ifdef notyet |
543 | flags = WRITECLOSE; | | 538 | flags = WRITECLOSE; |
544 | if (mp->mnt_flag & MNT_FORCE) | | 539 | if (mp->mnt_flag & MNT_FORCE) |
545 | flags |= FORCECLOSE; | | 540 | flags |= FORCECLOSE; |
546 | error = softdep_flushfiles(mp, flags, l); | | 541 | error = softdep_flushfiles(mp, flags, l); |
547 | if (error == 0 && ffs_cgupdate(ump, MNT_WAIT) == 0) | | 542 | if (error == 0 && ffs_cgupdate(ump, MNT_WAIT) == 0) |
548 | fs->fs_flags &= ~FS_DOSOFTDEP; | | 543 | fs->fs_flags &= ~FS_DOSOFTDEP; |
549 | (void) ffs_sbupdate(ump, MNT_WAIT); | | 544 | (void) ffs_sbupdate(ump, MNT_WAIT); |
550 | #elif defined(SOFTDEP) | | 545 | #elif defined(SOFTDEP) |
551 | mp->mnt_flag |= MNT_SOFTDEP; | | 546 | mp->mnt_flag |= MNT_SOFTDEP; |
552 | #endif | | 547 | #endif |
553 | } | | 548 | } |
554 | | | 549 | |
555 | /* | | 550 | /* |
556 | * When upgrading to a softdep mount, we must first flush | | 551 | * When upgrading to a softdep mount, we must first flush |
557 | * all vnodes. (not done yet -- see above) | | 552 | * all vnodes. (not done yet -- see above) |
558 | */ | | 553 | */ |
559 | if (!(fs->fs_flags & FS_DOSOFTDEP) && | | 554 | if (!(fs->fs_flags & FS_DOSOFTDEP) && |
560 | (mp->mnt_flag & MNT_SOFTDEP) && fs->fs_ronly == 0) { | | 555 | (mp->mnt_flag & MNT_SOFTDEP) && fs->fs_ronly == 0) { |
561 | #ifdef notyet | | 556 | #ifdef notyet |
562 | flags = WRITECLOSE; | | 557 | flags = WRITECLOSE; |
563 | if (mp->mnt_flag & MNT_FORCE) | | 558 | if (mp->mnt_flag & MNT_FORCE) |
564 | flags |= FORCECLOSE; | | 559 | flags |= FORCECLOSE; |
565 | error = ffs_flushfiles(mp, flags, l); | | 560 | error = ffs_flushfiles(mp, flags, l); |
566 | #else | | 561 | #else |
567 | mp->mnt_flag &= ~MNT_SOFTDEP; | | 562 | mp->mnt_flag &= ~MNT_SOFTDEP; |
568 | #endif | | 563 | #endif |
569 | } | | 564 | } |
570 | | | 565 | |
571 | if (mp->mnt_flag & MNT_RELOAD) { | | 566 | if (mp->mnt_flag & MNT_RELOAD) { |
572 | error = ffs_reload(mp, l->l_cred, l); | | 567 | error = ffs_reload(mp, l->l_cred, l); |
573 | if (error) | | 568 | if (error) |
574 | return (error); | | 569 | return (error); |
575 | } | | 570 | } |
576 | | | 571 | |
577 | if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) { | | 572 | if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) { |
578 | /* | | 573 | /* |
579 | * Changing from read-only to read/write | | 574 | * Changing from read-only to read/write |
580 | */ | | 575 | */ |
581 | fs->fs_ronly = 0; | | 576 | fs->fs_ronly = 0; |
582 | fs->fs_clean <<= 1; | | 577 | fs->fs_clean <<= 1; |
583 | fs->fs_fmod = 1; | | 578 | fs->fs_fmod = 1; |
584 | if ((fs->fs_flags & FS_DOSOFTDEP)) { | | 579 | if ((fs->fs_flags & FS_DOSOFTDEP)) { |
585 | error = softdep_mount(devvp, mp, fs, | | 580 | error = softdep_mount(devvp, mp, fs, |
586 | l->l_cred); | | 581 | l->l_cred); |
587 | if (error) | | 582 | if (error) |
588 | return (error); | | 583 | return (error); |
589 | } | | 584 | } |
590 | #ifdef WAPBL | | 585 | #ifdef WAPBL |
591 | if (fs->fs_flags & FS_DOWAPBL) { | | 586 | if (fs->fs_flags & FS_DOWAPBL) { |
592 | printf("%s: replaying log to disk\n", | | 587 | printf("%s: replaying log to disk\n", |
593 | fs->fs_fsmnt); | | 588 | fs->fs_fsmnt); |
594 | KDASSERT(mp->mnt_wapbl_replay); | | 589 | KDASSERT(mp->mnt_wapbl_replay); |
595 | error = wapbl_replay_write(mp->mnt_wapbl_replay, | | 590 | error = wapbl_replay_write(mp->mnt_wapbl_replay, |
596 | devvp); | | 591 | devvp); |
597 | if (error) { | | 592 | if (error) { |
598 | return error; | | 593 | return error; |
599 | } | | 594 | } |
600 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 595 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
601 | fs->fs_clean = FS_WASCLEAN; | | 596 | fs->fs_clean = FS_WASCLEAN; |
602 | } | | 597 | } |
603 | #endif /* WAPBL */ | | 598 | #endif /* WAPBL */ |
604 | if (fs->fs_snapinum[0] != 0) | | 599 | if (fs->fs_snapinum[0] != 0) |
605 | ffs_snapshot_mount(mp); | | 600 | ffs_snapshot_mount(mp); |
606 | } | | 601 | } |
607 | | | 602 | |
608 | #ifdef WAPBL | | 603 | #ifdef WAPBL |
609 | error = ffs_wapbl_start(mp); | | 604 | error = ffs_wapbl_start(mp); |
610 | if (error) | | 605 | if (error) |
611 | return error; | | 606 | return error; |
612 | #endif /* WAPBL */ | | 607 | #endif /* WAPBL */ |
613 | | | 608 | |
614 | if (args->fspec == NULL) | | 609 | if (args->fspec == NULL) |
615 | return EINVAL; | | 610 | return EINVAL; |
616 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_ASYNC)) == | | 611 | if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_ASYNC)) == |
617 | (MNT_SOFTDEP | MNT_ASYNC)) { | | 612 | (MNT_SOFTDEP | MNT_ASYNC)) { |
618 | printf("%s fs uses soft updates, ignoring async mode\n", | | 613 | printf("%s fs uses soft updates, ignoring async mode\n", |
619 | fs->fs_fsmnt); | | 614 | fs->fs_fsmnt); |
620 | mp->mnt_flag &= ~MNT_ASYNC; | | 615 | mp->mnt_flag &= ~MNT_ASYNC; |
621 | } | | 616 | } |
622 | } | | 617 | } |
623 | | | 618 | |
624 | error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, | | 619 | error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, |
625 | UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); | | 620 | UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); |
626 | if (error == 0) | | 621 | if (error == 0) |
627 | (void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, | | 622 | (void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, |
628 | sizeof(fs->fs_fsmnt)); | | 623 | sizeof(fs->fs_fsmnt)); |
629 | if (mp->mnt_flag & MNT_SOFTDEP) | | 624 | if (mp->mnt_flag & MNT_SOFTDEP) |
630 | fs->fs_flags |= FS_DOSOFTDEP; | | 625 | fs->fs_flags |= FS_DOSOFTDEP; |
631 | else | | 626 | else |
632 | fs->fs_flags &= ~FS_DOSOFTDEP; | | 627 | fs->fs_flags &= ~FS_DOSOFTDEP; |
633 | if (fs->fs_fmod != 0) { /* XXX */ | | 628 | if (fs->fs_fmod != 0) { /* XXX */ |
634 | int err; | | 629 | int err; |
635 | | | 630 | |
636 | fs->fs_fmod = 0; | | 631 | fs->fs_fmod = 0; |
637 | if (fs->fs_clean & FS_WASCLEAN) | | 632 | if (fs->fs_clean & FS_WASCLEAN) |
638 | fs->fs_time = time_second; | | 633 | fs->fs_time = time_second; |
639 | else { | | 634 | else { |
640 | printf("%s: file system not clean (fs_clean=%#x); " | | 635 | printf("%s: file system not clean (fs_clean=%#x); " |
641 | "please fsck(8)\n", mp->mnt_stat.f_mntfromname, | | 636 | "please fsck(8)\n", mp->mnt_stat.f_mntfromname, |
642 | fs->fs_clean); | | 637 | fs->fs_clean); |
643 | printf("%s: lost blocks %" PRId64 " files %d\n", | | 638 | printf("%s: lost blocks %" PRId64 " files %d\n", |
644 | mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks, | | 639 | mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks, |
645 | fs->fs_pendinginodes); | | 640 | fs->fs_pendinginodes); |
646 | } | | 641 | } |
647 | err = UFS_WAPBL_BEGIN(mp); | | 642 | err = UFS_WAPBL_BEGIN(mp); |
648 | if (err == 0) { | | 643 | if (err == 0) { |
649 | (void) ffs_cgupdate(ump, MNT_WAIT); | | 644 | (void) ffs_cgupdate(ump, MNT_WAIT); |
650 | UFS_WAPBL_END(mp); | | 645 | UFS_WAPBL_END(mp); |
651 | } | | 646 | } |
652 | } | | 647 | } |
653 | return (error); | | 648 | return (error); |
654 | | | 649 | |
655 | fail: | | 650 | fail: |
656 | vrele(devvp); | | 651 | vrele(devvp); |
657 | return (error); | | 652 | return (error); |
658 | } | | 653 | } |
659 | | | 654 | |
660 | /* | | 655 | /* |
661 | * Reload all incore data for a filesystem (used after running fsck on | | 656 | * Reload all incore data for a filesystem (used after running fsck on |
662 | * the root filesystem and finding things to fix). The filesystem must | | 657 | * the root filesystem and finding things to fix). The filesystem must |
663 | * be mounted read-only. | | 658 | * be mounted read-only. |
664 | * | | 659 | * |
665 | * Things to do to update the mount: | | 660 | * Things to do to update the mount: |
666 | * 1) invalidate all cached meta-data. | | 661 | * 1) invalidate all cached meta-data. |
667 | * 2) re-read superblock from disk. | | 662 | * 2) re-read superblock from disk. |
668 | * 3) re-read summary information from disk. | | 663 | * 3) re-read summary information from disk. |
669 | * 4) invalidate all inactive vnodes. | | 664 | * 4) invalidate all inactive vnodes. |
670 | * 5) invalidate all cached file data. | | 665 | * 5) invalidate all cached file data. |
671 | * 6) re-read inode data for all active vnodes. | | 666 | * 6) re-read inode data for all active vnodes. |
672 | */ | | 667 | */ |
673 | int | | 668 | int |
674 | ffs_reload(struct mount *mp, kauth_cred_t cred, struct lwp *l) | | 669 | ffs_reload(struct mount *mp, kauth_cred_t cred, struct lwp *l) |
675 | { | | 670 | { |
676 | struct vnode *vp, *mvp, *devvp; | | 671 | struct vnode *vp, *mvp, *devvp; |
677 | struct inode *ip; | | 672 | struct inode *ip; |
678 | void *space; | | 673 | void *space; |
679 | struct buf *bp; | | 674 | struct buf *bp; |
680 | struct fs *fs, *newfs; | | 675 | struct fs *fs, *newfs; |
681 | struct partinfo dpart; | | 676 | struct partinfo dpart; |
682 | int i, blks, size, error; | | 677 | int i, blks, size, error; |
683 | int32_t *lp; | | 678 | int32_t *lp; |
684 | struct ufsmount *ump; | | 679 | struct ufsmount *ump; |
685 | daddr_t sblockloc; | | 680 | daddr_t sblockloc; |
686 | | | 681 | |
687 | if ((mp->mnt_flag & MNT_RDONLY) == 0) | | 682 | if ((mp->mnt_flag & MNT_RDONLY) == 0) |
688 | return (EINVAL); | | 683 | return (EINVAL); |
689 | | | 684 | |
690 | ump = VFSTOUFS(mp); | | 685 | ump = VFSTOUFS(mp); |
691 | /* | | 686 | /* |
692 | * Step 1: invalidate all cached meta-data. | | 687 | * Step 1: invalidate all cached meta-data. |
693 | */ | | 688 | */ |
694 | devvp = ump->um_devvp; | | 689 | devvp = ump->um_devvp; |
695 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 690 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
696 | error = vinvalbuf(devvp, 0, cred, l, 0, 0); | | 691 | error = vinvalbuf(devvp, 0, cred, l, 0, 0); |
697 | VOP_UNLOCK(devvp, 0); | | 692 | VOP_UNLOCK(devvp, 0); |
698 | if (error) | | 693 | if (error) |
699 | panic("ffs_reload: dirty1"); | | 694 | panic("ffs_reload: dirty1"); |
700 | /* | | 695 | /* |
701 | * Step 2: re-read superblock from disk. | | 696 | * Step 2: re-read superblock from disk. |
702 | */ | | 697 | */ |
703 | fs = ump->um_fs; | | 698 | fs = ump->um_fs; |
704 | if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED) != 0) | | 699 | if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED) != 0) |
705 | size = DEV_BSIZE; | | 700 | size = DEV_BSIZE; |
706 | else | | 701 | else |
707 | size = dpart.disklab->d_secsize; | | 702 | size = dpart.disklab->d_secsize; |
708 | /* XXX we don't handle possibility that superblock moved. */ | | 703 | /* XXX we don't handle possibility that superblock moved. */ |
709 | error = bread(devvp, fs->fs_sblockloc / size, fs->fs_sbsize, | | 704 | error = bread(devvp, fs->fs_sblockloc / size, fs->fs_sbsize, |
710 | NOCRED, 0, &bp); | | 705 | NOCRED, 0, &bp); |
711 | if (error) { | | 706 | if (error) { |
712 | brelse(bp, 0); | | 707 | brelse(bp, 0); |
713 | return (error); | | 708 | return (error); |
714 | } | | 709 | } |
715 | newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK); | | 710 | newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK); |
716 | memcpy(newfs, bp->b_data, fs->fs_sbsize); | | 711 | memcpy(newfs, bp->b_data, fs->fs_sbsize); |
717 | #ifdef FFS_EI | | 712 | #ifdef FFS_EI |
718 | if (ump->um_flags & UFS_NEEDSWAP) { | | 713 | if (ump->um_flags & UFS_NEEDSWAP) { |
719 | ffs_sb_swap((struct fs*)bp->b_data, newfs); | | 714 | ffs_sb_swap((struct fs*)bp->b_data, newfs); |
720 | fs->fs_flags |= FS_SWAPPED; | | 715 | fs->fs_flags |= FS_SWAPPED; |
721 | } else | | 716 | } else |
722 | #endif | | 717 | #endif |
723 | fs->fs_flags &= ~FS_SWAPPED; | | 718 | fs->fs_flags &= ~FS_SWAPPED; |
724 | if ((newfs->fs_magic != FS_UFS1_MAGIC && | | 719 | if ((newfs->fs_magic != FS_UFS1_MAGIC && |
725 | newfs->fs_magic != FS_UFS2_MAGIC)|| | | 720 | newfs->fs_magic != FS_UFS2_MAGIC)|| |
726 | newfs->fs_bsize > MAXBSIZE || | | 721 | newfs->fs_bsize > MAXBSIZE || |
727 | newfs->fs_bsize < sizeof(struct fs)) { | | 722 | newfs->fs_bsize < sizeof(struct fs)) { |
728 | brelse(bp, 0); | | 723 | brelse(bp, 0); |
729 | free(newfs, M_UFSMNT); | | 724 | free(newfs, M_UFSMNT); |
730 | return (EIO); /* XXX needs translation */ | | 725 | return (EIO); /* XXX needs translation */ |
731 | } | | 726 | } |
732 | /* Store off old fs_sblockloc for fs_oldfscompat_read. */ | | 727 | /* Store off old fs_sblockloc for fs_oldfscompat_read. */ |
733 | sblockloc = fs->fs_sblockloc; | | 728 | sblockloc = fs->fs_sblockloc; |
734 | /* | | 729 | /* |
735 | * Copy pointer fields back into superblock before copying in XXX | | 730 | * Copy pointer fields back into superblock before copying in XXX |
736 | * new superblock. These should really be in the ufsmount. XXX | | 731 | * new superblock. These should really be in the ufsmount. XXX |
737 | * Note that important parameters (eg fs_ncg) are unchanged. | | 732 | * Note that important parameters (eg fs_ncg) are unchanged. |
738 | */ | | 733 | */ |
739 | newfs->fs_csp = fs->fs_csp; | | 734 | newfs->fs_csp = fs->fs_csp; |
740 | newfs->fs_maxcluster = fs->fs_maxcluster; | | 735 | newfs->fs_maxcluster = fs->fs_maxcluster; |
741 | newfs->fs_contigdirs = fs->fs_contigdirs; | | 736 | newfs->fs_contigdirs = fs->fs_contigdirs; |
742 | newfs->fs_ronly = fs->fs_ronly; | | 737 | newfs->fs_ronly = fs->fs_ronly; |
743 | newfs->fs_active = fs->fs_active; | | 738 | newfs->fs_active = fs->fs_active; |
744 | memcpy(fs, newfs, (u_int)fs->fs_sbsize); | | 739 | memcpy(fs, newfs, (u_int)fs->fs_sbsize); |
745 | brelse(bp, 0); | | 740 | brelse(bp, 0); |
746 | free(newfs, M_UFSMNT); | | 741 | free(newfs, M_UFSMNT); |
747 | | | 742 | |
748 | /* Recheck for apple UFS filesystem */ | | 743 | /* Recheck for apple UFS filesystem */ |
749 | ump->um_flags &= ~UFS_ISAPPLEUFS; | | 744 | ump->um_flags &= ~UFS_ISAPPLEUFS; |
750 | /* First check to see if this is tagged as an Apple UFS filesystem | | 745 | /* First check to see if this is tagged as an Apple UFS filesystem |
751 | * in the disklabel | | 746 | * in the disklabel |
752 | */ | | 747 | */ |
753 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && | | 748 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && |
754 | (dpart.part->p_fstype == FS_APPLEUFS)) { | | 749 | (dpart.part->p_fstype == FS_APPLEUFS)) { |
755 | ump->um_flags |= UFS_ISAPPLEUFS; | | 750 | ump->um_flags |= UFS_ISAPPLEUFS; |
756 | } | | 751 | } |
757 | #ifdef APPLE_UFS | | 752 | #ifdef APPLE_UFS |
758 | else { | | 753 | else { |
759 | /* Manually look for an apple ufs label, and if a valid one | | 754 | /* Manually look for an apple ufs label, and if a valid one |
760 | * is found, then treat it like an Apple UFS filesystem anyway | | 755 | * is found, then treat it like an Apple UFS filesystem anyway |
761 | */ | | 756 | */ |
762 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size), | | 757 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size), |
763 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); | | 758 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); |
764 | if (error) { | | 759 | if (error) { |
765 | brelse(bp, 0); | | 760 | brelse(bp, 0); |
766 | return (error); | | 761 | return (error); |
767 | } | | 762 | } |
768 | error = ffs_appleufs_validate(fs->fs_fsmnt, | | 763 | error = ffs_appleufs_validate(fs->fs_fsmnt, |
769 | (struct appleufslabel *)bp->b_data, NULL); | | 764 | (struct appleufslabel *)bp->b_data, NULL); |
770 | if (error == 0) | | 765 | if (error == 0) |
771 | ump->um_flags |= UFS_ISAPPLEUFS; | | 766 | ump->um_flags |= UFS_ISAPPLEUFS; |
772 | brelse(bp, 0); | | 767 | brelse(bp, 0); |
773 | bp = NULL; | | 768 | bp = NULL; |
774 | } | | 769 | } |
775 | #else | | 770 | #else |
776 | if (ump->um_flags & UFS_ISAPPLEUFS) | | 771 | if (ump->um_flags & UFS_ISAPPLEUFS) |
777 | return (EIO); | | 772 | return (EIO); |
778 | #endif | | 773 | #endif |
779 | | | 774 | |
780 | if (UFS_MPISAPPLEUFS(ump)) { | | 775 | if (UFS_MPISAPPLEUFS(ump)) { |
781 | /* see comment about NeXT below */ | | 776 | /* see comment about NeXT below */ |
782 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; | | 777 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; |
783 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; | | 778 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; |
784 | mp->mnt_iflag |= IMNT_DTYPE; | | 779 | mp->mnt_iflag |= IMNT_DTYPE; |
785 | } else { | | 780 | } else { |
786 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; | | 781 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; |
787 | ump->um_dirblksiz = DIRBLKSIZ; | | 782 | ump->um_dirblksiz = DIRBLKSIZ; |
788 | if (ump->um_maxsymlinklen > 0) | | 783 | if (ump->um_maxsymlinklen > 0) |
789 | mp->mnt_iflag |= IMNT_DTYPE; | | 784 | mp->mnt_iflag |= IMNT_DTYPE; |
790 | else | | 785 | else |
791 | mp->mnt_iflag &= ~IMNT_DTYPE; | | 786 | mp->mnt_iflag &= ~IMNT_DTYPE; |
792 | } | | 787 | } |
793 | ffs_oldfscompat_read(fs, ump, sblockloc); | | 788 | ffs_oldfscompat_read(fs, ump, sblockloc); |
794 | mutex_enter(&ump->um_lock); | | 789 | mutex_enter(&ump->um_lock); |
795 | ump->um_maxfilesize = fs->fs_maxfilesize; | | 790 | ump->um_maxfilesize = fs->fs_maxfilesize; |
796 | | | 791 | |
797 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { | | 792 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { |
798 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", | | 793 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", |
799 | mp->mnt_stat.f_mntonname, fs->fs_flags, | | 794 | mp->mnt_stat.f_mntonname, fs->fs_flags, |
800 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); | | 795 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); |
801 | if ((mp->mnt_flag & MNT_FORCE) == 0) { | | 796 | if ((mp->mnt_flag & MNT_FORCE) == 0) { |
802 | mutex_exit(&ump->um_lock); | | 797 | mutex_exit(&ump->um_lock); |
803 | return (EINVAL); | | 798 | return (EINVAL); |
804 | } | | 799 | } |
805 | } | | 800 | } |
806 | | | 801 | |
807 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { | | 802 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { |
808 | fs->fs_pendingblocks = 0; | | 803 | fs->fs_pendingblocks = 0; |
809 | fs->fs_pendinginodes = 0; | | 804 | fs->fs_pendinginodes = 0; |
810 | } | | 805 | } |
811 | mutex_exit(&ump->um_lock); | | 806 | mutex_exit(&ump->um_lock); |
812 | | | 807 | |
813 | ffs_statvfs(mp, &mp->mnt_stat); | | 808 | ffs_statvfs(mp, &mp->mnt_stat); |
814 | /* | | 809 | /* |
815 | * Step 3: re-read summary information from disk. | | 810 | * Step 3: re-read summary information from disk. |
816 | */ | | 811 | */ |
817 | blks = howmany(fs->fs_cssize, fs->fs_fsize); | | 812 | blks = howmany(fs->fs_cssize, fs->fs_fsize); |
818 | space = fs->fs_csp; | | 813 | space = fs->fs_csp; |
819 | for (i = 0; i < blks; i += fs->fs_frag) { | | 814 | for (i = 0; i < blks; i += fs->fs_frag) { |
820 | size = fs->fs_bsize; | | 815 | size = fs->fs_bsize; |
821 | if (i + fs->fs_frag > blks) | | 816 | if (i + fs->fs_frag > blks) |
822 | size = (blks - i) * fs->fs_fsize; | | 817 | size = (blks - i) * fs->fs_fsize; |
823 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, | | 818 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, |
824 | NOCRED, 0, &bp); | | 819 | NOCRED, 0, &bp); |
825 | if (error) { | | 820 | if (error) { |
826 | brelse(bp, 0); | | 821 | brelse(bp, 0); |
827 | return (error); | | 822 | return (error); |
828 | } | | 823 | } |
829 | #ifdef FFS_EI | | 824 | #ifdef FFS_EI |
830 | if (UFS_FSNEEDSWAP(fs)) | | 825 | if (UFS_FSNEEDSWAP(fs)) |
831 | ffs_csum_swap((struct csum *)bp->b_data, | | 826 | ffs_csum_swap((struct csum *)bp->b_data, |
832 | (struct csum *)space, size); | | 827 | (struct csum *)space, size); |
833 | else | | 828 | else |
834 | #endif | | 829 | #endif |
835 | memcpy(space, bp->b_data, (size_t)size); | | 830 | memcpy(space, bp->b_data, (size_t)size); |
836 | space = (char *)space + size; | | 831 | space = (char *)space + size; |
837 | brelse(bp, 0); | | 832 | brelse(bp, 0); |
838 | } | | 833 | } |
839 | if ((fs->fs_flags & FS_DOSOFTDEP)) | | 834 | if ((fs->fs_flags & FS_DOSOFTDEP)) |
840 | softdep_mount(devvp, mp, fs, cred); | | 835 | softdep_mount(devvp, mp, fs, cred); |
841 | if (fs->fs_snapinum[0] != 0) | | 836 | if (fs->fs_snapinum[0] != 0) |
842 | ffs_snapshot_mount(mp); | | 837 | ffs_snapshot_mount(mp); |
843 | /* | | 838 | /* |
844 | * We no longer know anything about clusters per cylinder group. | | 839 | * We no longer know anything about clusters per cylinder group. |
845 | */ | | 840 | */ |
846 | if (fs->fs_contigsumsize > 0) { | | 841 | if (fs->fs_contigsumsize > 0) { |
847 | lp = fs->fs_maxcluster; | | 842 | lp = fs->fs_maxcluster; |
848 | for (i = 0; i < fs->fs_ncg; i++) | | 843 | for (i = 0; i < fs->fs_ncg; i++) |
849 | *lp++ = fs->fs_contigsumsize; | | 844 | *lp++ = fs->fs_contigsumsize; |
850 | } | | 845 | } |
851 | | | 846 | |
852 | /* Allocate a marker vnode. */ | | 847 | /* Allocate a marker vnode. */ |
853 | if ((mvp = vnalloc(mp)) == NULL) | | 848 | if ((mvp = vnalloc(mp)) == NULL) |
854 | return ENOMEM; | | 849 | return ENOMEM; |
855 | /* | | 850 | /* |
856 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() | | 851 | * NOTE: not using the TAILQ_FOREACH here since in this loop vgone() |
857 | * and vclean() can be called indirectly | | 852 | * and vclean() can be called indirectly |
858 | */ | | 853 | */ |
859 | mutex_enter(&mntvnode_lock); | | 854 | mutex_enter(&mntvnode_lock); |
860 | loop: | | 855 | loop: |
861 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { | | 856 | for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) { |
862 | vmark(mvp, vp); | | 857 | vmark(mvp, vp); |
863 | if (vp->v_mount != mp || vismarker(vp)) | | 858 | if (vp->v_mount != mp || vismarker(vp)) |
864 | continue; | | 859 | continue; |
865 | /* | | 860 | /* |
866 | * Step 4: invalidate all inactive vnodes. | | 861 | * Step 4: invalidate all inactive vnodes. |
867 | */ | | 862 | */ |
868 | if (vrecycle(vp, &mntvnode_lock, l)) { | | 863 | if (vrecycle(vp, &mntvnode_lock, l)) { |
869 | mutex_enter(&mntvnode_lock); | | 864 | mutex_enter(&mntvnode_lock); |
870 | (void)vunmark(mvp); | | 865 | (void)vunmark(mvp); |
871 | goto loop; | | 866 | goto loop; |
872 | } | | 867 | } |
873 | /* | | 868 | /* |
874 | * Step 5: invalidate all cached file data. | | 869 | * Step 5: invalidate all cached file data. |
875 | */ | | 870 | */ |
876 | mutex_enter(&vp->v_interlock); | | 871 | mutex_enter(&vp->v_interlock); |
877 | mutex_exit(&mntvnode_lock); | | 872 | mutex_exit(&mntvnode_lock); |
878 | if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) { | | 873 | if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) { |
879 | (void)vunmark(mvp); | | 874 | (void)vunmark(mvp); |
880 | goto loop; | | 875 | goto loop; |
881 | } | | 876 | } |
882 | if (vinvalbuf(vp, 0, cred, l, 0, 0)) | | 877 | if (vinvalbuf(vp, 0, cred, l, 0, 0)) |
883 | panic("ffs_reload: dirty2"); | | 878 | panic("ffs_reload: dirty2"); |
884 | /* | | 879 | /* |
885 | * Step 6: re-read inode data for all active vnodes. | | 880 | * Step 6: re-read inode data for all active vnodes. |
886 | */ | | 881 | */ |
887 | ip = VTOI(vp); | | 882 | ip = VTOI(vp); |
888 | error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), | | 883 | error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), |
889 | (int)fs->fs_bsize, NOCRED, 0, &bp); | | 884 | (int)fs->fs_bsize, NOCRED, 0, &bp); |
890 | if (error) { | | 885 | if (error) { |
891 | brelse(bp, 0); | | 886 | brelse(bp, 0); |
892 | vput(vp); | | 887 | vput(vp); |
893 | (void)vunmark(mvp); | | 888 | (void)vunmark(mvp); |
894 | break; | | 889 | break; |
895 | } | | 890 | } |
896 | ffs_load_inode(bp, ip, fs, ip->i_number); | | 891 | ffs_load_inode(bp, ip, fs, ip->i_number); |
897 | ip->i_ffs_effnlink = ip->i_nlink; | | 892 | ip->i_ffs_effnlink = ip->i_nlink; |
898 | brelse(bp, 0); | | 893 | brelse(bp, 0); |
899 | vput(vp); | | 894 | vput(vp); |
900 | mutex_enter(&mntvnode_lock); | | 895 | mutex_enter(&mntvnode_lock); |
901 | } | | 896 | } |
902 | mutex_exit(&mntvnode_lock); | | 897 | mutex_exit(&mntvnode_lock); |
903 | vnfree(mvp); | | 898 | vnfree(mvp); |
904 | return (error); | | 899 | return (error); |
905 | } | | 900 | } |
906 | | | 901 | |
907 | /* | | 902 | /* |
908 | * Possible superblock locations ordered from most to least likely. | | 903 | * Possible superblock locations ordered from most to least likely. |
909 | */ | | 904 | */ |
910 | static const int sblock_try[] = SBLOCKSEARCH; | | 905 | static const int sblock_try[] = SBLOCKSEARCH; |
911 | | | 906 | |
912 | /* | | 907 | /* |
913 | * Common code for mount and mountroot | | 908 | * Common code for mount and mountroot |
914 | */ | | 909 | */ |
915 | int | | 910 | int |
916 | ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) | | 911 | ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) |
917 | { | | 912 | { |
918 | struct ufsmount *ump; | | 913 | struct ufsmount *ump; |
919 | struct buf *bp; | | 914 | struct buf *bp; |
920 | struct fs *fs; | | 915 | struct fs *fs; |
921 | dev_t dev; | | 916 | dev_t dev; |
922 | struct partinfo dpart; | | 917 | struct partinfo dpart; |
923 | void *space; | | 918 | void *space; |
924 | daddr_t sblockloc, fsblockloc; | | 919 | daddr_t sblockloc, fsblockloc; |
925 | int blks, fstype; | | 920 | int blks, fstype; |
926 | int error, i, size, ronly, bset = 0; | | 921 | int error, i, size, ronly, bset = 0; |
927 | #ifdef FFS_EI | | 922 | #ifdef FFS_EI |
928 | int needswap = 0; /* keep gcc happy */ | | 923 | int needswap = 0; /* keep gcc happy */ |
929 | #endif | | 924 | #endif |
930 | int32_t *lp; | | 925 | int32_t *lp; |
931 | kauth_cred_t cred; | | 926 | kauth_cred_t cred; |
932 | u_int32_t sbsize = 8192; /* keep gcc happy*/ | | 927 | u_int32_t sbsize = 8192; /* keep gcc happy*/ |
933 | | | 928 | |
934 | dev = devvp->v_rdev; | | 929 | dev = devvp->v_rdev; |
935 | cred = l ? l->l_cred : NOCRED; | | 930 | cred = l ? l->l_cred : NOCRED; |
936 | | | 931 | |
937 | /* Flush out any old buffers remaining from a previous use. */ | | 932 | /* Flush out any old buffers remaining from a previous use. */ |
938 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); | | 933 | vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); |
939 | error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0); | | 934 | error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0); |
940 | VOP_UNLOCK(devvp, 0); | | 935 | VOP_UNLOCK(devvp, 0); |
941 | if (error) | | 936 | if (error) |
942 | return (error); | | 937 | return (error); |
943 | | | 938 | |
944 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | | 939 | ronly = (mp->mnt_flag & MNT_RDONLY) != 0; |
945 | if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) != 0) | | 940 | if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) != 0) |
946 | size = DEV_BSIZE; | | 941 | size = DEV_BSIZE; |
947 | else | | 942 | else |
948 | size = dpart.disklab->d_secsize; | | 943 | size = dpart.disklab->d_secsize; |
949 | | | 944 | |
950 | bp = NULL; | | 945 | bp = NULL; |
951 | ump = NULL; | | 946 | ump = NULL; |
952 | fs = NULL; | | 947 | fs = NULL; |
953 | sblockloc = 0; | | 948 | sblockloc = 0; |
954 | fstype = 0; | | 949 | fstype = 0; |
955 | | | 950 | |
956 | error = fstrans_mount(mp); | | 951 | error = fstrans_mount(mp); |
957 | if (error) | | 952 | if (error) |
958 | return error; | | 953 | return error; |
959 | | | 954 | |
960 | ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK); | | 955 | ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK); |
961 | memset(ump, 0, sizeof *ump); | | 956 | memset(ump, 0, sizeof *ump); |
962 | mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE); | | 957 | mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE); |
963 | error = ffs_snapshot_init(ump); | | 958 | error = ffs_snapshot_init(ump); |
964 | if (error) | | 959 | if (error) |
965 | goto out; | | 960 | goto out; |
966 | ump->um_ops = &ffs_ufsops; | | 961 | ump->um_ops = &ffs_ufsops; |
967 | | | 962 | |
968 | #ifdef WAPBL | | 963 | #ifdef WAPBL |
969 | sbagain: | | 964 | sbagain: |
970 | #endif | | 965 | #endif |
971 | /* | | 966 | /* |
972 | * Try reading the superblock in each of its possible locations. | | 967 | * Try reading the superblock in each of its possible locations. |
973 | */ | | 968 | */ |
974 | for (i = 0; ; i++) { | | 969 | for (i = 0; ; i++) { |
975 | if (bp != NULL) { | | 970 | if (bp != NULL) { |
976 | brelse(bp, BC_NOCACHE); | | 971 | brelse(bp, BC_NOCACHE); |
977 | bp = NULL; | | 972 | bp = NULL; |
978 | } | | 973 | } |
979 | if (sblock_try[i] == -1) { | | 974 | if (sblock_try[i] == -1) { |
980 | error = EINVAL; | | 975 | error = EINVAL; |
981 | fs = NULL; | | 976 | fs = NULL; |
982 | goto out; | | 977 | goto out; |
983 | } | | 978 | } |
984 | error = bread(devvp, sblock_try[i] / size, SBLOCKSIZE, cred, | | 979 | error = bread(devvp, sblock_try[i] / size, SBLOCKSIZE, cred, |
985 | 0, &bp); | | 980 | 0, &bp); |
986 | if (error) { | | 981 | if (error) { |
987 | fs = NULL; | | 982 | fs = NULL; |
988 | goto out; | | 983 | goto out; |
989 | } | | 984 | } |
990 | fs = (struct fs*)bp->b_data; | | 985 | fs = (struct fs*)bp->b_data; |
991 | fsblockloc = sblockloc = sblock_try[i]; | | 986 | fsblockloc = sblockloc = sblock_try[i]; |
992 | if (fs->fs_magic == FS_UFS1_MAGIC) { | | 987 | if (fs->fs_magic == FS_UFS1_MAGIC) { |
993 | sbsize = fs->fs_sbsize; | | 988 | sbsize = fs->fs_sbsize; |
994 | fstype = UFS1; | | 989 | fstype = UFS1; |
995 | #ifdef FFS_EI | | 990 | #ifdef FFS_EI |
996 | needswap = 0; | | 991 | needswap = 0; |
997 | } else if (fs->fs_magic == bswap32(FS_UFS1_MAGIC)) { | | 992 | } else if (fs->fs_magic == bswap32(FS_UFS1_MAGIC)) { |
998 | sbsize = bswap32(fs->fs_sbsize); | | 993 | sbsize = bswap32(fs->fs_sbsize); |
999 | fstype = UFS1; | | 994 | fstype = UFS1; |
1000 | needswap = 1; | | 995 | needswap = 1; |
1001 | #endif | | 996 | #endif |
1002 | } else if (fs->fs_magic == FS_UFS2_MAGIC) { | | 997 | } else if (fs->fs_magic == FS_UFS2_MAGIC) { |
1003 | sbsize = fs->fs_sbsize; | | 998 | sbsize = fs->fs_sbsize; |
1004 | fstype = UFS2; | | 999 | fstype = UFS2; |
1005 | #ifdef FFS_EI | | 1000 | #ifdef FFS_EI |
1006 | needswap = 0; | | 1001 | needswap = 0; |
1007 | } else if (fs->fs_magic == bswap32(FS_UFS2_MAGIC)) { | | 1002 | } else if (fs->fs_magic == bswap32(FS_UFS2_MAGIC)) { |
1008 | sbsize = bswap32(fs->fs_sbsize); | | 1003 | sbsize = bswap32(fs->fs_sbsize); |
1009 | fstype = UFS2; | | 1004 | fstype = UFS2; |
1010 | needswap = 1; | | 1005 | needswap = 1; |
1011 | #endif | | 1006 | #endif |
1012 | } else | | 1007 | } else |
1013 | continue; | | 1008 | continue; |
1014 | | | 1009 | |
1015 | | | 1010 | |
1016 | /* fs->fs_sblockloc isn't defined for old filesystems */ | | 1011 | /* fs->fs_sblockloc isn't defined for old filesystems */ |
1017 | if (fstype == UFS1 && !(fs->fs_old_flags & FS_FLAGS_UPDATED)) { | | 1012 | if (fstype == UFS1 && !(fs->fs_old_flags & FS_FLAGS_UPDATED)) { |
1018 | if (sblockloc == SBLOCK_UFS2) | | 1013 | if (sblockloc == SBLOCK_UFS2) |
1019 | /* | | 1014 | /* |
1020 | * This is likely to be the first alternate | | 1015 | * This is likely to be the first alternate |
1021 | * in a filesystem with 64k blocks. | | 1016 | * in a filesystem with 64k blocks. |
1022 | * Don't use it. | | 1017 | * Don't use it. |
1023 | */ | | 1018 | */ |
1024 | continue; | | 1019 | continue; |
1025 | fsblockloc = sblockloc; | | 1020 | fsblockloc = sblockloc; |
1026 | } else { | | 1021 | } else { |
1027 | fsblockloc = fs->fs_sblockloc; | | 1022 | fsblockloc = fs->fs_sblockloc; |
1028 | #ifdef FFS_EI | | 1023 | #ifdef FFS_EI |
1029 | if (needswap) | | 1024 | if (needswap) |
1030 | fsblockloc = bswap64(fsblockloc); | | 1025 | fsblockloc = bswap64(fsblockloc); |
1031 | #endif | | 1026 | #endif |
1032 | } | | 1027 | } |
1033 | | | 1028 | |
1034 | /* Check we haven't found an alternate superblock */ | | 1029 | /* Check we haven't found an alternate superblock */ |
1035 | if (fsblockloc != sblockloc) | | 1030 | if (fsblockloc != sblockloc) |
1036 | continue; | | 1031 | continue; |
1037 | | | 1032 | |
1038 | /* Validate size of superblock */ | | 1033 | /* Validate size of superblock */ |
1039 | if (sbsize > MAXBSIZE || sbsize < sizeof(struct fs)) | | 1034 | if (sbsize > MAXBSIZE || sbsize < sizeof(struct fs)) |
1040 | continue; | | 1035 | continue; |
1041 | | | 1036 | |
1042 | /* Ok seems to be a good superblock */ | | 1037 | /* Ok seems to be a good superblock */ |
1043 | break; | | 1038 | break; |
1044 | } | | 1039 | } |
1045 | | | 1040 | |
1046 | fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK); | | 1041 | fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK); |
1047 | memcpy(fs, bp->b_data, sbsize); | | 1042 | memcpy(fs, bp->b_data, sbsize); |
1048 | ump->um_fs = fs; | | 1043 | ump->um_fs = fs; |
1049 | | | 1044 | |
1050 | #ifdef FFS_EI | | 1045 | #ifdef FFS_EI |
1051 | if (needswap) { | | 1046 | if (needswap) { |
1052 | ffs_sb_swap((struct fs*)bp->b_data, fs); | | 1047 | ffs_sb_swap((struct fs*)bp->b_data, fs); |
1053 | fs->fs_flags |= FS_SWAPPED; | | 1048 | fs->fs_flags |= FS_SWAPPED; |
1054 | } else | | 1049 | } else |
1055 | #endif | | 1050 | #endif |
1056 | fs->fs_flags &= ~FS_SWAPPED; | | 1051 | fs->fs_flags &= ~FS_SWAPPED; |
1057 | | | 1052 | |
1058 | #ifdef WAPBL | | 1053 | #ifdef WAPBL |
1059 | if ((mp->mnt_wapbl_replay == 0) && (fs->fs_flags & FS_DOWAPBL)) { | | 1054 | if ((mp->mnt_wapbl_replay == 0) && (fs->fs_flags & FS_DOWAPBL)) { |
1060 | error = ffs_wapbl_replay_start(mp, fs, devvp); | | 1055 | error = ffs_wapbl_replay_start(mp, fs, devvp); |
1061 | if (error) | | 1056 | if (error) |
1062 | goto out; | | 1057 | goto out; |
1063 | | | 1058 | |
1064 | if (!ronly) { | | 1059 | if (!ronly) { |
1065 | /* XXX fsmnt may be stale. */ | | 1060 | /* XXX fsmnt may be stale. */ |
1066 | printf("%s: replaying log to disk\n", fs->fs_fsmnt); | | 1061 | printf("%s: replaying log to disk\n", fs->fs_fsmnt); |
1067 | error = wapbl_replay_write(mp->mnt_wapbl_replay, devvp); | | 1062 | error = wapbl_replay_write(mp->mnt_wapbl_replay, devvp); |
1068 | if (error) | | 1063 | if (error) |
1069 | goto out; | | 1064 | goto out; |
1070 | wapbl_replay_stop(mp->mnt_wapbl_replay); | | 1065 | wapbl_replay_stop(mp->mnt_wapbl_replay); |
1071 | fs->fs_clean = FS_WASCLEAN; | | 1066 | fs->fs_clean = FS_WASCLEAN; |
1072 | } else { | | 1067 | } else { |
1073 | /* XXX fsmnt may be stale */ | | 1068 | /* XXX fsmnt may be stale */ |
1074 | printf("%s: replaying log to memory\n", fs->fs_fsmnt); | | 1069 | printf("%s: replaying log to memory\n", fs->fs_fsmnt); |
1075 | } | | 1070 | } |
1076 | | | 1071 | |
1077 | /* Force a re-read of the superblock */ | | 1072 | /* Force a re-read of the superblock */ |
1078 | brelse(bp, BC_INVAL); | | 1073 | brelse(bp, BC_INVAL); |
1079 | bp = NULL; | | 1074 | bp = NULL; |
1080 | free(fs, M_UFSMNT); | | 1075 | free(fs, M_UFSMNT); |
1081 | fs = NULL; | | 1076 | fs = NULL; |
1082 | goto sbagain; | | 1077 | goto sbagain; |
1083 | } | | 1078 | } |
1084 | #else /* !WAPBL */ | | 1079 | #else /* !WAPBL */ |
1085 | if ((fs->fs_flags & FS_DOWAPBL) && (mp->mnt_flag & MNT_FORCE) == 0) { | | 1080 | if ((fs->fs_flags & FS_DOWAPBL) && (mp->mnt_flag & MNT_FORCE) == 0) { |
1086 | error = EPERM; | | 1081 | error = EPERM; |
1087 | goto out; | | 1082 | goto out; |
1088 | } | | 1083 | } |
1089 | #endif /* !WAPBL */ | | 1084 | #endif /* !WAPBL */ |
1090 | | | 1085 | |
1091 | ffs_oldfscompat_read(fs, ump, sblockloc); | | 1086 | ffs_oldfscompat_read(fs, ump, sblockloc); |
1092 | ump->um_maxfilesize = fs->fs_maxfilesize; | | 1087 | ump->um_maxfilesize = fs->fs_maxfilesize; |
1093 | | | 1088 | |
1094 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { | | 1089 | if (fs->fs_flags & ~(FS_KNOWN_FLAGS | FS_INTERNAL)) { |
1095 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", | | 1090 | uprintf("%s: unknown ufs flags: 0x%08"PRIx32"%s\n", |
1096 | mp->mnt_stat.f_mntonname, fs->fs_flags, | | 1091 | mp->mnt_stat.f_mntonname, fs->fs_flags, |
1097 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); | | 1092 | (mp->mnt_flag & MNT_FORCE) ? "" : ", not mounting"); |
1098 | if ((mp->mnt_flag & MNT_FORCE) == 0) { | | 1093 | if ((mp->mnt_flag & MNT_FORCE) == 0) { |
1099 | error = EINVAL; | | 1094 | error = EINVAL; |
1100 | goto out; | | 1095 | goto out; |
1101 | } | | 1096 | } |
1102 | } | | 1097 | } |
1103 | | | 1098 | |
1104 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { | | 1099 | if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { |
1105 | fs->fs_pendingblocks = 0; | | 1100 | fs->fs_pendingblocks = 0; |
1106 | fs->fs_pendinginodes = 0; | | 1101 | fs->fs_pendinginodes = 0; |
1107 | } | | 1102 | } |
1108 | | | 1103 | |
1109 | ump->um_fstype = fstype; | | 1104 | ump->um_fstype = fstype; |
1110 | if (fs->fs_sbsize < SBLOCKSIZE) | | 1105 | if (fs->fs_sbsize < SBLOCKSIZE) |
1111 | brelse(bp, BC_INVAL); | | 1106 | brelse(bp, BC_INVAL); |
1112 | else | | 1107 | else |
1113 | brelse(bp, 0); | | 1108 | brelse(bp, 0); |
1114 | bp = NULL; | | 1109 | bp = NULL; |
1115 | | | 1110 | |
1116 | /* First check to see if this is tagged as an Apple UFS filesystem | | 1111 | /* First check to see if this is tagged as an Apple UFS filesystem |
1117 | * in the disklabel | | 1112 | * in the disklabel |
1118 | */ | | 1113 | */ |
1119 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && | | 1114 | if ((VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) == 0) && |
1120 | (dpart.part->p_fstype == FS_APPLEUFS)) { | | 1115 | (dpart.part->p_fstype == FS_APPLEUFS)) { |
1121 | ump->um_flags |= UFS_ISAPPLEUFS; | | 1116 | ump->um_flags |= UFS_ISAPPLEUFS; |
1122 | } | | 1117 | } |
1123 | #ifdef APPLE_UFS | | 1118 | #ifdef APPLE_UFS |
1124 | else { | | 1119 | else { |
1125 | /* Manually look for an apple ufs label, and if a valid one | | 1120 | /* Manually look for an apple ufs label, and if a valid one |
1126 | * is found, then treat it like an Apple UFS filesystem anyway | | 1121 | * is found, then treat it like an Apple UFS filesystem anyway |
1127 | */ | | 1122 | */ |
1128 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size), | | 1123 | error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size), |
1129 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); | | 1124 | APPLEUFS_LABEL_SIZE, cred, 0, &bp); |
1130 | if (error) | | 1125 | if (error) |
1131 | goto out; | | 1126 | goto out; |
1132 | error = ffs_appleufs_validate(fs->fs_fsmnt, | | 1127 | error = ffs_appleufs_validate(fs->fs_fsmnt, |
1133 | (struct appleufslabel *)bp->b_data, NULL); | | 1128 | (struct appleufslabel *)bp->b_data, NULL); |
1134 | if (error == 0) { | | 1129 | if (error == 0) { |
1135 | ump->um_flags |= UFS_ISAPPLEUFS; | | 1130 | ump->um_flags |= UFS_ISAPPLEUFS; |
1136 | } | | 1131 | } |
1137 | brelse(bp, 0); | | 1132 | brelse(bp, 0); |
1138 | bp = NULL; | | 1133 | bp = NULL; |
1139 | } | | 1134 | } |
1140 | #else | | 1135 | #else |
1141 | if (ump->um_flags & UFS_ISAPPLEUFS) { | | 1136 | if (ump->um_flags & UFS_ISAPPLEUFS) { |
1142 | error = EINVAL; | | 1137 | error = EINVAL; |
1143 | goto out; | | 1138 | goto out; |
1144 | } | | 1139 | } |
1145 | #endif | | 1140 | #endif |
1146 | | | 1141 | |
1147 | #if 0 | | 1142 | #if 0 |
1148 | /* | | 1143 | /* |
1149 | * XXX This code changes the behaviour of mounting dirty filesystems, to | | 1144 | * XXX This code changes the behaviour of mounting dirty filesystems, to |
1150 | * XXX require "mount -f ..." to mount them. This doesn't match what | | 1145 | * XXX require "mount -f ..." to mount them. This doesn't match what |
1151 | * XXX mount(8) describes and is disabled for now. | | 1146 | * XXX mount(8) describes and is disabled for now. |
1152 | */ | | 1147 | */ |
1153 | /* | | 1148 | /* |
1154 | * If the file system is not clean, don't allow it to be mounted | | 1149 | * If the file system is not clean, don't allow it to be mounted |
1155 | * unless MNT_FORCE is specified. (Note: MNT_FORCE is always set | | 1150 | * unless MNT_FORCE is specified. (Note: MNT_FORCE is always set |
1156 | * for the root file system.) | | 1151 | * for the root file system.) |
1157 | */ | | 1152 | */ |
1158 | if (fs->fs_flags & FS_DOWAPBL) { | | 1153 | if (fs->fs_flags & FS_DOWAPBL) { |
1159 | /* | | 1154 | /* |
1160 | * wapbl normally expects to be FS_WASCLEAN when the FS_DOWAPBL | | 1155 | * wapbl normally expects to be FS_WASCLEAN when the FS_DOWAPBL |
1161 | * bit is set, although there's a window in unmount where it | | 1156 | * bit is set, although there's a window in unmount where it |
1162 | * could be FS_ISCLEAN | | 1157 | * could be FS_ISCLEAN |
1163 | */ | | 1158 | */ |
1164 | if ((mp->mnt_flag & MNT_FORCE) == 0 && | | 1159 | if ((mp->mnt_flag & MNT_FORCE) == 0 && |
1165 | (fs->fs_clean & (FS_WASCLEAN | FS_ISCLEAN)) == 0) { | | 1160 | (fs->fs_clean & (FS_WASCLEAN | FS_ISCLEAN)) == 0) { |
1166 | error = EPERM; | | 1161 | error = EPERM; |
1167 | goto out; | | 1162 | goto out; |
1168 | } | | 1163 | } |
1169 | } else | | 1164 | } else |
1170 | if ((fs->fs_clean & FS_ISCLEAN) == 0 && | | 1165 | if ((fs->fs_clean & FS_ISCLEAN) == 0 && |
1171 | (mp->mnt_flag & MNT_FORCE) == 0) { | | 1166 | (mp->mnt_flag & MNT_FORCE) == 0) { |
1172 | error = EPERM; | | 1167 | error = EPERM; |
1173 | goto out; | | 1168 | goto out; |
1174 | } | | 1169 | } |
1175 | #endif | | 1170 | #endif |
1176 | | | 1171 | |
1177 | /* | | 1172 | /* |
1178 | * verify that we can access the last block in the fs | | 1173 | * verify that we can access the last block in the fs |
1179 | * if we're mounting read/write. | | 1174 | * if we're mounting read/write. |
1180 | */ | | 1175 | */ |
1181 | | | 1176 | |
1182 | if (!ronly) { | | 1177 | if (!ronly) { |
1183 | error = bread(devvp, fsbtodb(fs, fs->fs_size - 1), fs->fs_fsize, | | 1178 | error = bread(devvp, fsbtodb(fs, fs->fs_size - 1), fs->fs_fsize, |
1184 | cred, 0, &bp); | | 1179 | cred, 0, &bp); |
1185 | if (bp->b_bcount != fs->fs_fsize) | | 1180 | if (bp->b_bcount != fs->fs_fsize) |
1186 | error = EINVAL; | | 1181 | error = EINVAL; |
1187 | if (error) { | | 1182 | if (error) { |
1188 | bset = BC_INVAL; | | 1183 | bset = BC_INVAL; |
1189 | goto out; | | 1184 | goto out; |
1190 | } | | 1185 | } |
1191 | brelse(bp, BC_INVAL); | | 1186 | brelse(bp, BC_INVAL); |
1192 | bp = NULL; | | 1187 | bp = NULL; |
1193 | } | | 1188 | } |
1194 | | | 1189 | |
1195 | fs->fs_ronly = ronly; | | 1190 | fs->fs_ronly = ronly; |
1196 | /* Don't bump fs_clean if we're replaying journal */ | | 1191 | /* Don't bump fs_clean if we're replaying journal */ |
1197 | if (!((fs->fs_flags & FS_DOWAPBL) && (fs->fs_clean & FS_WASCLEAN))) | | 1192 | if (!((fs->fs_flags & FS_DOWAPBL) && (fs->fs_clean & FS_WASCLEAN))) |
1198 | if (ronly == 0) { | | 1193 | if (ronly == 0) { |
1199 | fs->fs_clean <<= 1; | | 1194 | fs->fs_clean <<= 1; |
1200 | fs->fs_fmod = 1; | | 1195 | fs->fs_fmod = 1; |
1201 | } | | 1196 | } |
1202 | size = fs->fs_cssize; | | 1197 | size = fs->fs_cssize; |
1203 | blks = howmany(size, fs->fs_fsize); | | 1198 | blks = howmany(size, fs->fs_fsize); |
1204 | if (fs->fs_contigsumsize > 0) | | 1199 | if (fs->fs_contigsumsize > 0) |
1205 | size += fs->fs_ncg * sizeof(int32_t); | | 1200 | size += fs->fs_ncg * sizeof(int32_t); |
1206 | size += fs->fs_ncg * sizeof(*fs->fs_contigdirs); | | 1201 | size += fs->fs_ncg * sizeof(*fs->fs_contigdirs); |
1207 | space = malloc((u_long)size, M_UFSMNT, M_WAITOK); | | 1202 | space = malloc((u_long)size, M_UFSMNT, M_WAITOK); |
1208 | fs->fs_csp = space; | | 1203 | fs->fs_csp = space; |
1209 | for (i = 0; i < blks; i += fs->fs_frag) { | | 1204 | for (i = 0; i < blks; i += fs->fs_frag) { |
1210 | size = fs->fs_bsize; | | 1205 | size = fs->fs_bsize; |
1211 | if (i + fs->fs_frag > blks) | | 1206 | if (i + fs->fs_frag > blks) |
1212 | size = (blks - i) * fs->fs_fsize; | | 1207 | size = (blks - i) * fs->fs_fsize; |
1213 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, | | 1208 | error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, |
1214 | cred, 0, &bp); | | 1209 | cred, 0, &bp); |
1215 | if (error) { | | 1210 | if (error) { |
1216 | free(fs->fs_csp, M_UFSMNT); | | 1211 | free(fs->fs_csp, M_UFSMNT); |
1217 | goto out; | | 1212 | goto out; |
1218 | } | | 1213 | } |
1219 | #ifdef FFS_EI | | 1214 | #ifdef FFS_EI |
1220 | if (needswap) | | 1215 | if (needswap) |
1221 | ffs_csum_swap((struct csum *)bp->b_data, | | 1216 | ffs_csum_swap((struct csum *)bp->b_data, |
1222 | (struct csum *)space, size); | | 1217 | (struct csum *)space, size); |
1223 | else | | 1218 | else |
1224 | #endif | | 1219 | #endif |
1225 | memcpy(space, bp->b_data, (u_int)size); | | 1220 | memcpy(space, bp->b_data, (u_int)size); |
1226 | | | 1221 | |
1227 | space = (char *)space + size; | | 1222 | space = (char *)space + size; |
1228 | brelse(bp, 0); | | 1223 | brelse(bp, 0); |
1229 | bp = NULL; | | 1224 | bp = NULL; |
1230 | } | | 1225 | } |
1231 | if (fs->fs_contigsumsize > 0) { | | 1226 | if (fs->fs_contigsumsize > 0) { |
1232 | fs->fs_maxcluster = lp = space; | | 1227 | fs->fs_maxcluster = lp = space; |
1233 | for (i = 0; i < fs->fs_ncg; i++) | | 1228 | for (i = 0; i < fs->fs_ncg; i++) |
1234 | *lp++ = fs->fs_contigsumsize; | | 1229 | *lp++ = fs->fs_contigsumsize; |
1235 | space = lp; | | 1230 | space = lp; |
1236 | } | | 1231 | } |
1237 | size = fs->fs_ncg * sizeof(*fs->fs_contigdirs); | | 1232 | size = fs->fs_ncg * sizeof(*fs->fs_contigdirs); |
1238 | fs->fs_contigdirs = space; | | 1233 | fs->fs_contigdirs = space; |
1239 | space = (char *)space + size; | | 1234 | space = (char *)space + size; |
1240 | memset(fs->fs_contigdirs, 0, size); | | 1235 | memset(fs->fs_contigdirs, 0, size); |
1241 | /* Compatibility for old filesystems - XXX */ | | 1236 | /* Compatibility for old filesystems - XXX */ |
1242 | if (fs->fs_avgfilesize <= 0) | | 1237 | if (fs->fs_avgfilesize <= 0) |
1243 | fs->fs_avgfilesize = AVFILESIZ; | | 1238 | fs->fs_avgfilesize = AVFILESIZ; |
1244 | if (fs->fs_avgfpdir <= 0) | | 1239 | if (fs->fs_avgfpdir <= 0) |
1245 | fs->fs_avgfpdir = AFPDIR; | | 1240 | fs->fs_avgfpdir = AFPDIR; |
1246 | fs->fs_active = NULL; | | 1241 | fs->fs_active = NULL; |
1247 | mp->mnt_data = ump; | | 1242 | mp->mnt_data = ump; |
1248 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; | | 1243 | mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; |
1249 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FFS); | | 1244 | mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FFS); |
1250 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; | | 1245 | mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; |
1251 | mp->mnt_stat.f_namemax = FFS_MAXNAMLEN; | | 1246 | mp->mnt_stat.f_namemax = FFS_MAXNAMLEN; |
1252 | if (UFS_MPISAPPLEUFS(ump)) { | | 1247 | if (UFS_MPISAPPLEUFS(ump)) { |
1253 | /* NeXT used to keep short symlinks in the inode even | | 1248 | /* NeXT used to keep short symlinks in the inode even |
1254 | * when using FS_42INODEFMT. In that case fs->fs_maxsymlinklen | | 1249 | * when using FS_42INODEFMT. In that case fs->fs_maxsymlinklen |
1255 | * is probably -1, but we still need to be able to identify | | 1250 | * is probably -1, but we still need to be able to identify |
1256 | * short symlinks. | | 1251 | * short symlinks. |
1257 | */ | | 1252 | */ |
1258 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; | | 1253 | ump->um_maxsymlinklen = APPLEUFS_MAXSYMLINKLEN; |
1259 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; | | 1254 | ump->um_dirblksiz = APPLEUFS_DIRBLKSIZ; |
1260 | mp->mnt_iflag |= IMNT_DTYPE; | | 1255 | mp->mnt_iflag |= IMNT_DTYPE; |
1261 | } else { | | 1256 | } else { |
1262 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; | | 1257 | ump->um_maxsymlinklen = fs->fs_maxsymlinklen; |
1263 | ump->um_dirblksiz = DIRBLKSIZ; | | 1258 | ump->um_dirblksiz = DIRBLKSIZ; |
1264 | if (ump->um_maxsymlinklen > 0) | | 1259 | if (ump->um_maxsymlinklen > 0) |
1265 | mp->mnt_iflag |= IMNT_DTYPE; | | 1260 | mp->mnt_iflag |= IMNT_DTYPE; |
1266 | else | | 1261 | else |
1267 | mp->mnt_iflag &= ~IMNT_DTYPE; | | 1262 | mp->mnt_iflag &= ~IMNT_DTYPE; |
1268 | } | | 1263 | } |
1269 | mp->mnt_fs_bshift = fs->fs_bshift; | | 1264 | mp->mnt_fs_bshift = fs->fs_bshift; |
1270 | mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */ | | 1265 | mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */ |
1271 | mp->mnt_flag |= MNT_LOCAL; | | 1266 | mp->mnt_flag |= MNT_LOCAL; |
1272 | mp->mnt_iflag |= IMNT_MPSAFE; | | 1267 | mp->mnt_iflag |= IMNT_MPSAFE; |
1273 | #ifdef FFS_EI | | 1268 | #ifdef FFS_EI |
1274 | if (needswap) | | 1269 | if (needswap) |
1275 | ump->um_flags |= UFS_NEEDSWAP; | | 1270 | ump->um_flags |= UFS_NEEDSWAP; |
1276 | #endif | | 1271 | #endif |
1277 | ump->um_mountp = mp; | | 1272 | ump->um_mountp = mp; |
1278 | ump->um_dev = dev; | | 1273 | ump->um_dev = dev; |
1279 | ump->um_devvp = devvp; | | 1274 | ump->um_devvp = devvp; |
1280 | ump->um_nindir = fs->fs_nindir; | | 1275 | ump->um_nindir = fs->fs_nindir; |
1281 | ump->um_lognindir = ffs(fs->fs_nindir) - 1; | | 1276 | ump->um_lognindir = ffs(fs->fs_nindir) - 1; |
1282 | ump->um_bptrtodb = fs->fs_fsbtodb; | | 1277 | ump->um_bptrtodb = fs->fs_fsbtodb; |
1283 | ump->um_seqinc = fs->fs_frag; | | 1278 | ump->um_seqinc = fs->fs_frag; |
1284 | for (i = 0; i < MAXQUOTAS; i++) | | 1279 | for (i = 0; i < MAXQUOTAS; i++) |
1285 | ump->um_quotas[i] = NULLVP; | | 1280 | ump->um_quotas[i] = NULLVP; |
1286 | devvp->v_specmountpoint = mp; | | 1281 | devvp->v_specmountpoint = mp; |
1287 | if (ronly == 0 && (fs->fs_flags & FS_DOSOFTDEP)) { | | 1282 | if (ronly == 0 && (fs->fs_flags & FS_DOSOFTDEP)) { |
1288 | error = softdep_mount(devvp, mp, fs, cred); | | 1283 | error = softdep_mount(devvp, mp, fs, cred); |
1289 | if (error) { | | 1284 | if (error) { |
1290 | free(fs->fs_csp, M_UFSMNT); | | 1285 | free(fs->fs_csp, M_UFSMNT); |
1291 | goto out; | | 1286 | goto out; |
1292 | } | | 1287 | } |
1293 | } | | 1288 | } |
1294 | if (ronly == 0 && fs->fs_snapinum[0] != 0) | | 1289 | if (ronly == 0 && fs->fs_snapinum[0] != 0) |
1295 | ffs_snapshot_mount(mp); | | 1290 | ffs_snapshot_mount(mp); |
1296 | | | 1291 | |
1297 | #ifdef WAPBL | | 1292 | #ifdef WAPBL |
1298 | if (!ronly) { | | 1293 | if (!ronly) { |
1299 | KDASSERT(fs->fs_ronly == 0); | | 1294 | KDASSERT(fs->fs_ronly == 0); |
1300 | /* | | 1295 | /* |
1301 | * ffs_wapbl_start() needs mp->mnt_stat initialised if it | | 1296 | * ffs_wapbl_start() needs mp->mnt_stat initialised if it |
1302 | * needs to create a new log file in-filesystem. | | 1297 | * needs to create a new log file in-filesystem. |
1303 | */ | | 1298 | */ |
1304 | ffs_statvfs(mp, &mp->mnt_stat); | | 1299 | ffs_statvfs(mp, &mp->mnt_stat); |
1305 | | | 1300 | |
1306 | error = ffs_wapbl_start(mp); | | 1301 | error = ffs_wapbl_start(mp); |
1307 | if (error) { | | 1302 | if (error) { |
1308 | free(fs->fs_csp, M_UFSMNT); | | 1303 | free(fs->fs_csp, M_UFSMNT); |
1309 | goto out; | | 1304 | goto out; |
1310 | } | | 1305 | } |
1311 | } | | 1306 | } |
1312 | #endif /* WAPBL */ | | 1307 | #endif /* WAPBL */ |
1313 | #ifdef UFS_EXTATTR | | 1308 | #ifdef UFS_EXTATTR |
1314 | /* | | 1309 | /* |
1315 | * Initialize file-backed extended attributes on UFS1 file | | 1310 | * Initialize file-backed extended attributes on UFS1 file |
1316 | * systems. | | 1311 | * systems. |
1317 | */ | | 1312 | */ |
1318 | if (ump->um_fstype == UFS1) { | | 1313 | if (ump->um_fstype == UFS1) { |
1319 | ufs_extattr_uepm_init(&ump->um_extattr); | | 1314 | ufs_extattr_uepm_init(&ump->um_extattr); |
1320 | #ifdef UFS_EXTATTR_AUTOSTART | | 1315 | #ifdef UFS_EXTATTR_AUTOSTART |
1321 | /* | | 1316 | /* |
1322 | * XXX Just ignore errors. Not clear that we should | | 1317 | * XXX Just ignore errors. Not clear that we should |