1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
34 * $Id: ffs_vnops.c,v 1.31 1997/10/10 18:17:00 phk Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/resourcevar.h>
40#include <sys/signalvar.h>
41#include <sys/kernel.h>
42#include <sys/stat.h>
43#include <sys/buf.h>
44#include <sys/proc.h>
45#include <sys/mount.h>
46#include <sys/sysctl.h>
47#include <sys/vnode.h>
48#include <sys/malloc.h>
49
50#include <vm/vm.h>
51#include <vm/vm_prot.h>
52#include <vm/vm_page.h>
53#include <vm/vm_object.h>
54#include <vm/vm_extern.h>
55
56#include <miscfs/specfs/specdev.h>
57#include <miscfs/fifofs/fifo.h>
58
59#include <ufs/ufs/quota.h>
60#include <ufs/ufs/inode.h>
61#include <ufs/ufs/ufsmount.h>
62#include <ufs/ufs/ufs_extern.h>
63
64#include <ufs/ffs/fs.h>
65#include <ufs/ffs/ffs_extern.h>
66
67static int ffs_fsync __P((struct vop_fsync_args *));
68static int ffs_getpages __P((struct vop_getpages_args *));
69static int ffs_read __P((struct vop_read_args *));
70static int ffs_write __P((struct vop_write_args *));
71
72/* Global vfs data structures for ufs. */
73vop_t **ffs_vnodeop_p;
74static struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
75 { &vop_default_desc, (vop_t *) vn_default_error },
76 { &vop_abortop_desc, (vop_t *) ufs_abortop },
77 { &vop_access_desc, (vop_t *) ufs_access },
78 { &vop_advlock_desc, (vop_t *) ufs_advlock },
79 { &vop_blkatoff_desc, (vop_t *) ffs_blkatoff },
80 { &vop_bmap_desc, (vop_t *) ufs_bmap },
81 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
82 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
83 { &vop_close_desc, (vop_t *) ufs_close },
84 { &vop_create_desc, (vop_t *) ufs_create },
85 { &vop_fsync_desc, (vop_t *) ffs_fsync },
86 { &vop_getattr_desc, (vop_t *) ufs_getattr },
87 { &vop_getpages_desc, (vop_t *) ffs_getpages },
88 { &vop_inactive_desc, (vop_t *) ufs_inactive },
89 { &vop_ioctl_desc, (vop_t *) ufs_ioctl },
90 { &vop_islocked_desc, (vop_t *) ufs_islocked },
91 { &vop_lease_desc, (vop_t *) ufs_lease_check },
92 { &vop_link_desc, (vop_t *) ufs_link },
93 { &vop_lock_desc, (vop_t *) ufs_lock },
94 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
95 { &vop_mkdir_desc, (vop_t *) ufs_mkdir },
96 { &vop_mknod_desc, (vop_t *) ufs_mknod },
97 { &vop_mmap_desc, (vop_t *) ufs_mmap },
98 { &vop_open_desc, (vop_t *) ufs_open },
99 { &vop_pathconf_desc, (vop_t *) ufs_pathconf },
100 { &vop_poll_desc, (vop_t *) ufs_poll },
101 { &vop_print_desc, (vop_t *) ufs_print },
102 { &vop_read_desc, (vop_t *) ffs_read },
103 { &vop_readdir_desc, (vop_t *) ufs_readdir },
104 { &vop_readlink_desc, (vop_t *) ufs_readlink },
105 { &vop_reallocblks_desc, (vop_t *) ffs_reallocblks },
106 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
107 { &vop_remove_desc, (vop_t *) ufs_remove },
108 { &vop_rename_desc, (vop_t *) ufs_rename },
109 { &vop_revoke_desc, (vop_t *) ufs_revoke },
110 { &vop_rmdir_desc, (vop_t *) ufs_rmdir },
111 { &vop_seek_desc, (vop_t *) ufs_seek },
112 { &vop_setattr_desc, (vop_t *) ufs_setattr },
113 { &vop_strategy_desc, (vop_t *) ufs_strategy },
114 { &vop_symlink_desc, (vop_t *) ufs_symlink },
115 { &vop_truncate_desc, (vop_t *) ffs_truncate },
116 { &vop_unlock_desc, (vop_t *) ufs_unlock },
117 { &vop_update_desc, (vop_t *) ffs_update },
118 { &vop_valloc_desc, (vop_t *) ffs_valloc },
119 { &vop_vfree_desc, (vop_t *) ffs_vfree },
120 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
121 { &vop_write_desc, (vop_t *) ffs_write },
122 { NULL, NULL }
123};
124static struct vnodeopv_desc ffs_vnodeop_opv_desc =
125 { &ffs_vnodeop_p, ffs_vnodeop_entries };
126
127vop_t **ffs_specop_p;
128static struct vnodeopv_entry_desc ffs_specop_entries[] = {
129 { &vop_default_desc, (vop_t *) vn_default_error },
130 { &vop_abortop_desc, (vop_t *) spec_abortop },
131 { &vop_access_desc, (vop_t *) ufs_access },
132 { &vop_advlock_desc, (vop_t *) spec_advlock },
133 { &vop_blkatoff_desc, (vop_t *) spec_blkatoff },
134 { &vop_bmap_desc, (vop_t *) spec_bmap },
135 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
136 { &vop_close_desc, (vop_t *) ufsspec_close },
137 { &vop_create_desc, (vop_t *) spec_create },
138 { &vop_fsync_desc, (vop_t *) ffs_fsync },
139 { &vop_getattr_desc, (vop_t *) ufs_getattr },
140 { &vop_getpages_desc, (vop_t *) spec_getpages },
141 { &vop_inactive_desc, (vop_t *) ufs_inactive },
142 { &vop_ioctl_desc, (vop_t *) spec_ioctl },
143 { &vop_islocked_desc, (vop_t *) ufs_islocked },
144 { &vop_lease_desc, (vop_t *) spec_lease_check },
145 { &vop_link_desc, (vop_t *) spec_link },
146 { &vop_lock_desc, (vop_t *) ufs_lock },
147 { &vop_lookup_desc, (vop_t *) spec_lookup },
148 { &vop_mkdir_desc, (vop_t *) spec_mkdir },
149 { &vop_mknod_desc, (vop_t *) spec_mknod },
150 { &vop_mmap_desc, (vop_t *) spec_mmap },
151 { &vop_open_desc, (vop_t *) spec_open },
152 { &vop_pathconf_desc, (vop_t *) spec_pathconf },
153 { &vop_poll_desc, (vop_t *) spec_poll },
154 { &vop_print_desc, (vop_t *) ufs_print },
155 { &vop_read_desc, (vop_t *) ufsspec_read },
156 { &vop_readdir_desc, (vop_t *) spec_readdir },
157 { &vop_readlink_desc, (vop_t *) spec_readlink },
158 { &vop_reallocblks_desc, (vop_t *) spec_reallocblks },
159 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
160 { &vop_remove_desc, (vop_t *) spec_remove },
161 { &vop_rename_desc, (vop_t *) spec_rename },
162 { &vop_revoke_desc, (vop_t *) spec_revoke },
163 { &vop_rmdir_desc, (vop_t *) spec_rmdir },
164 { &vop_seek_desc, (vop_t *) spec_seek },
165 { &vop_setattr_desc, (vop_t *) ufs_setattr },
166 { &vop_strategy_desc, (vop_t *) spec_strategy },
167 { &vop_symlink_desc, (vop_t *) spec_symlink },
168 { &vop_truncate_desc, (vop_t *) spec_truncate },
169 { &vop_unlock_desc, (vop_t *) ufs_unlock },
170 { &vop_update_desc, (vop_t *) ffs_update },
171 { &vop_valloc_desc, (vop_t *) spec_valloc },
172 { &vop_vfree_desc, (vop_t *) ffs_vfree },
173 { &vop_write_desc, (vop_t *) ufsspec_write },
174 { NULL, NULL }
175};
176static struct vnodeopv_desc ffs_specop_opv_desc =
177 { &ffs_specop_p, ffs_specop_entries };
178
179vop_t **ffs_fifoop_p;
180static struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
181 { &vop_default_desc, (vop_t *) vn_default_error },
182 { &vop_abortop_desc, (vop_t *) fifo_abortop },
183 { &vop_access_desc, (vop_t *) ufs_access },
184 { &vop_advlock_desc, (vop_t *) fifo_advlock },
185 { &vop_blkatoff_desc, (vop_t *) fifo_blkatoff },
186 { &vop_bmap_desc, (vop_t *) fifo_bmap },
187 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
188 { &vop_close_desc, (vop_t *) ufsfifo_close },
189 { &vop_create_desc, (vop_t *) fifo_create },
190 { &vop_fsync_desc, (vop_t *) ffs_fsync },
191 { &vop_getattr_desc, (vop_t *) ufs_getattr },
192 { &vop_inactive_desc, (vop_t *) ufs_inactive },
193 { &vop_ioctl_desc, (vop_t *) fifo_ioctl },
194 { &vop_islocked_desc, (vop_t *) ufs_islocked },
195 { &vop_lease_desc, (vop_t *) fifo_lease_check },
196 { &vop_link_desc, (vop_t *) fifo_link },
197 { &vop_lock_desc, (vop_t *) ufs_lock },
198 { &vop_lookup_desc, (vop_t *) fifo_lookup },
199 { &vop_mkdir_desc, (vop_t *) fifo_mkdir },
200 { &vop_mknod_desc, (vop_t *) fifo_mknod },
201 { &vop_mmap_desc, (vop_t *) fifo_mmap },
202 { &vop_open_desc, (vop_t *) fifo_open },
203 { &vop_pathconf_desc, (vop_t *) fifo_pathconf },
204 { &vop_poll_desc, (vop_t *) fifo_poll },
205 { &vop_print_desc, (vop_t *) ufs_print },
206 { &vop_read_desc, (vop_t *) ufsfifo_read },
207 { &vop_readdir_desc, (vop_t *) fifo_readdir },
208 { &vop_readlink_desc, (vop_t *) fifo_readlink },
209 { &vop_reallocblks_desc, (vop_t *) fifo_reallocblks },
210 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
211 { &vop_remove_desc, (vop_t *) fifo_remove },
212 { &vop_rename_desc, (vop_t *) fifo_rename },
213 { &vop_revoke_desc, (vop_t *) fifo_revoke },
214 { &vop_rmdir_desc, (vop_t *) fifo_rmdir },
215 { &vop_seek_desc, (vop_t *) fifo_seek },
216 { &vop_setattr_desc, (vop_t *) ufs_setattr },
217 { &vop_strategy_desc, (vop_t *) fifo_strategy },
218 { &vop_symlink_desc, (vop_t *) fifo_symlink },
219 { &vop_truncate_desc, (vop_t *) fifo_truncate },
220 { &vop_unlock_desc, (vop_t *) ufs_unlock },
221 { &vop_update_desc, (vop_t *) ffs_update },
222 { &vop_valloc_desc, (vop_t *) fifo_valloc },
223 { &vop_vfree_desc, (vop_t *) ffs_vfree },
224 { &vop_write_desc, (vop_t *) ufsfifo_write },
225 { NULL, NULL }
226};
227static struct vnodeopv_desc ffs_fifoop_opv_desc =
228 { &ffs_fifoop_p, ffs_fifoop_entries };
229
230VNODEOP_SET(ffs_vnodeop_opv_desc);
231VNODEOP_SET(ffs_specop_opv_desc);
232VNODEOP_SET(ffs_fifoop_opv_desc);
233
234SYSCTL_NODE(_vfs, MOUNT_UFS, ffs, CTLFLAG_RW, 0, "FFS filesystem");
235
236#include <ufs/ufs/ufs_readwrite.c>
237
238/*
239 * Synch an open file.
240 */
241/* ARGSUSED */
242static int
243ffs_fsync(ap)
244 struct vop_fsync_args /* {
245 struct vnode *a_vp;
246 struct ucred *a_cred;
247 int a_waitfor;
248 struct proc *a_p;
249 } */ *ap;
250{
251 register struct vnode *vp = ap->a_vp;
252 register struct buf *bp;
253 struct timeval tv;
254 struct buf *nbp;
255 int pass;
256 int s;
257
258 pass = 0;
259 /*
260 * Flush all dirty buffers associated with a vnode.
261 */
262loop:
263 s = splbio();
264 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
265 nbp = bp->b_vnbufs.le_next;
266 if ((bp->b_flags & B_BUSY) || (pass == 0 && (bp->b_blkno < 0)))
267 continue;
268 if ((bp->b_flags & B_DELWRI) == 0)
269 panic("ffs_fsync: not dirty");
270
271 if (bp->b_vp != vp || ap->a_waitfor != MNT_NOWAIT) {
272
273 bremfree(bp);
274 bp->b_flags |= B_BUSY;
275 splx(s);
276 /*
277 * Wait for I/O associated with indirect blocks to complete,
278 * since there is no way to quickly wait for them below.
279 */
280 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
281 (void) bawrite(bp);
282 else
283 (void) bwrite(bp);
284 } else {
285 vfs_bio_awrite(bp);
286 splx(s);
287 }
288 goto loop;
289 }
290 splx(s);
291
292 if (pass == 0) {
293 pass = 1;
294 goto loop;
295 }
296
297 if (ap->a_waitfor == MNT_WAIT) {
298 s = splbio();
299 while (vp->v_numoutput) {
300 vp->v_flag |= VBWAIT;
301 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "ffsfsn", 0);
302 }
303 splx(s);
304#ifdef DIAGNOSTIC
305 if (vp->v_dirtyblkhd.lh_first) {
306 vprint("ffs_fsync: dirty", vp);
307 goto loop;
308 }
309#endif
310 }
311
312 gettime(&tv);
313 return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
314}
315
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
34 * $Id: ffs_vnops.c,v 1.31 1997/10/10 18:17:00 phk Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/resourcevar.h>
40#include <sys/signalvar.h>
41#include <sys/kernel.h>
42#include <sys/stat.h>
43#include <sys/buf.h>
44#include <sys/proc.h>
45#include <sys/mount.h>
46#include <sys/sysctl.h>
47#include <sys/vnode.h>
48#include <sys/malloc.h>
49
50#include <vm/vm.h>
51#include <vm/vm_prot.h>
52#include <vm/vm_page.h>
53#include <vm/vm_object.h>
54#include <vm/vm_extern.h>
55
56#include <miscfs/specfs/specdev.h>
57#include <miscfs/fifofs/fifo.h>
58
59#include <ufs/ufs/quota.h>
60#include <ufs/ufs/inode.h>
61#include <ufs/ufs/ufsmount.h>
62#include <ufs/ufs/ufs_extern.h>
63
64#include <ufs/ffs/fs.h>
65#include <ufs/ffs/ffs_extern.h>
66
67static int ffs_fsync __P((struct vop_fsync_args *));
68static int ffs_getpages __P((struct vop_getpages_args *));
69static int ffs_read __P((struct vop_read_args *));
70static int ffs_write __P((struct vop_write_args *));
71
72/* Global vfs data structures for ufs. */
73vop_t **ffs_vnodeop_p;
74static struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
75 { &vop_default_desc, (vop_t *) vn_default_error },
76 { &vop_abortop_desc, (vop_t *) ufs_abortop },
77 { &vop_access_desc, (vop_t *) ufs_access },
78 { &vop_advlock_desc, (vop_t *) ufs_advlock },
79 { &vop_blkatoff_desc, (vop_t *) ffs_blkatoff },
80 { &vop_bmap_desc, (vop_t *) ufs_bmap },
81 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
82 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
83 { &vop_close_desc, (vop_t *) ufs_close },
84 { &vop_create_desc, (vop_t *) ufs_create },
85 { &vop_fsync_desc, (vop_t *) ffs_fsync },
86 { &vop_getattr_desc, (vop_t *) ufs_getattr },
87 { &vop_getpages_desc, (vop_t *) ffs_getpages },
88 { &vop_inactive_desc, (vop_t *) ufs_inactive },
89 { &vop_ioctl_desc, (vop_t *) ufs_ioctl },
90 { &vop_islocked_desc, (vop_t *) ufs_islocked },
91 { &vop_lease_desc, (vop_t *) ufs_lease_check },
92 { &vop_link_desc, (vop_t *) ufs_link },
93 { &vop_lock_desc, (vop_t *) ufs_lock },
94 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
95 { &vop_mkdir_desc, (vop_t *) ufs_mkdir },
96 { &vop_mknod_desc, (vop_t *) ufs_mknod },
97 { &vop_mmap_desc, (vop_t *) ufs_mmap },
98 { &vop_open_desc, (vop_t *) ufs_open },
99 { &vop_pathconf_desc, (vop_t *) ufs_pathconf },
100 { &vop_poll_desc, (vop_t *) ufs_poll },
101 { &vop_print_desc, (vop_t *) ufs_print },
102 { &vop_read_desc, (vop_t *) ffs_read },
103 { &vop_readdir_desc, (vop_t *) ufs_readdir },
104 { &vop_readlink_desc, (vop_t *) ufs_readlink },
105 { &vop_reallocblks_desc, (vop_t *) ffs_reallocblks },
106 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
107 { &vop_remove_desc, (vop_t *) ufs_remove },
108 { &vop_rename_desc, (vop_t *) ufs_rename },
109 { &vop_revoke_desc, (vop_t *) ufs_revoke },
110 { &vop_rmdir_desc, (vop_t *) ufs_rmdir },
111 { &vop_seek_desc, (vop_t *) ufs_seek },
112 { &vop_setattr_desc, (vop_t *) ufs_setattr },
113 { &vop_strategy_desc, (vop_t *) ufs_strategy },
114 { &vop_symlink_desc, (vop_t *) ufs_symlink },
115 { &vop_truncate_desc, (vop_t *) ffs_truncate },
116 { &vop_unlock_desc, (vop_t *) ufs_unlock },
117 { &vop_update_desc, (vop_t *) ffs_update },
118 { &vop_valloc_desc, (vop_t *) ffs_valloc },
119 { &vop_vfree_desc, (vop_t *) ffs_vfree },
120 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
121 { &vop_write_desc, (vop_t *) ffs_write },
122 { NULL, NULL }
123};
124static struct vnodeopv_desc ffs_vnodeop_opv_desc =
125 { &ffs_vnodeop_p, ffs_vnodeop_entries };
126
127vop_t **ffs_specop_p;
128static struct vnodeopv_entry_desc ffs_specop_entries[] = {
129 { &vop_default_desc, (vop_t *) vn_default_error },
130 { &vop_abortop_desc, (vop_t *) spec_abortop },
131 { &vop_access_desc, (vop_t *) ufs_access },
132 { &vop_advlock_desc, (vop_t *) spec_advlock },
133 { &vop_blkatoff_desc, (vop_t *) spec_blkatoff },
134 { &vop_bmap_desc, (vop_t *) spec_bmap },
135 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
136 { &vop_close_desc, (vop_t *) ufsspec_close },
137 { &vop_create_desc, (vop_t *) spec_create },
138 { &vop_fsync_desc, (vop_t *) ffs_fsync },
139 { &vop_getattr_desc, (vop_t *) ufs_getattr },
140 { &vop_getpages_desc, (vop_t *) spec_getpages },
141 { &vop_inactive_desc, (vop_t *) ufs_inactive },
142 { &vop_ioctl_desc, (vop_t *) spec_ioctl },
143 { &vop_islocked_desc, (vop_t *) ufs_islocked },
144 { &vop_lease_desc, (vop_t *) spec_lease_check },
145 { &vop_link_desc, (vop_t *) spec_link },
146 { &vop_lock_desc, (vop_t *) ufs_lock },
147 { &vop_lookup_desc, (vop_t *) spec_lookup },
148 { &vop_mkdir_desc, (vop_t *) spec_mkdir },
149 { &vop_mknod_desc, (vop_t *) spec_mknod },
150 { &vop_mmap_desc, (vop_t *) spec_mmap },
151 { &vop_open_desc, (vop_t *) spec_open },
152 { &vop_pathconf_desc, (vop_t *) spec_pathconf },
153 { &vop_poll_desc, (vop_t *) spec_poll },
154 { &vop_print_desc, (vop_t *) ufs_print },
155 { &vop_read_desc, (vop_t *) ufsspec_read },
156 { &vop_readdir_desc, (vop_t *) spec_readdir },
157 { &vop_readlink_desc, (vop_t *) spec_readlink },
158 { &vop_reallocblks_desc, (vop_t *) spec_reallocblks },
159 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
160 { &vop_remove_desc, (vop_t *) spec_remove },
161 { &vop_rename_desc, (vop_t *) spec_rename },
162 { &vop_revoke_desc, (vop_t *) spec_revoke },
163 { &vop_rmdir_desc, (vop_t *) spec_rmdir },
164 { &vop_seek_desc, (vop_t *) spec_seek },
165 { &vop_setattr_desc, (vop_t *) ufs_setattr },
166 { &vop_strategy_desc, (vop_t *) spec_strategy },
167 { &vop_symlink_desc, (vop_t *) spec_symlink },
168 { &vop_truncate_desc, (vop_t *) spec_truncate },
169 { &vop_unlock_desc, (vop_t *) ufs_unlock },
170 { &vop_update_desc, (vop_t *) ffs_update },
171 { &vop_valloc_desc, (vop_t *) spec_valloc },
172 { &vop_vfree_desc, (vop_t *) ffs_vfree },
173 { &vop_write_desc, (vop_t *) ufsspec_write },
174 { NULL, NULL }
175};
176static struct vnodeopv_desc ffs_specop_opv_desc =
177 { &ffs_specop_p, ffs_specop_entries };
178
179vop_t **ffs_fifoop_p;
180static struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
181 { &vop_default_desc, (vop_t *) vn_default_error },
182 { &vop_abortop_desc, (vop_t *) fifo_abortop },
183 { &vop_access_desc, (vop_t *) ufs_access },
184 { &vop_advlock_desc, (vop_t *) fifo_advlock },
185 { &vop_blkatoff_desc, (vop_t *) fifo_blkatoff },
186 { &vop_bmap_desc, (vop_t *) fifo_bmap },
187 { &vop_bwrite_desc, (vop_t *) vn_bwrite },
188 { &vop_close_desc, (vop_t *) ufsfifo_close },
189 { &vop_create_desc, (vop_t *) fifo_create },
190 { &vop_fsync_desc, (vop_t *) ffs_fsync },
191 { &vop_getattr_desc, (vop_t *) ufs_getattr },
192 { &vop_inactive_desc, (vop_t *) ufs_inactive },
193 { &vop_ioctl_desc, (vop_t *) fifo_ioctl },
194 { &vop_islocked_desc, (vop_t *) ufs_islocked },
195 { &vop_lease_desc, (vop_t *) fifo_lease_check },
196 { &vop_link_desc, (vop_t *) fifo_link },
197 { &vop_lock_desc, (vop_t *) ufs_lock },
198 { &vop_lookup_desc, (vop_t *) fifo_lookup },
199 { &vop_mkdir_desc, (vop_t *) fifo_mkdir },
200 { &vop_mknod_desc, (vop_t *) fifo_mknod },
201 { &vop_mmap_desc, (vop_t *) fifo_mmap },
202 { &vop_open_desc, (vop_t *) fifo_open },
203 { &vop_pathconf_desc, (vop_t *) fifo_pathconf },
204 { &vop_poll_desc, (vop_t *) fifo_poll },
205 { &vop_print_desc, (vop_t *) ufs_print },
206 { &vop_read_desc, (vop_t *) ufsfifo_read },
207 { &vop_readdir_desc, (vop_t *) fifo_readdir },
208 { &vop_readlink_desc, (vop_t *) fifo_readlink },
209 { &vop_reallocblks_desc, (vop_t *) fifo_reallocblks },
210 { &vop_reclaim_desc, (vop_t *) ufs_reclaim },
211 { &vop_remove_desc, (vop_t *) fifo_remove },
212 { &vop_rename_desc, (vop_t *) fifo_rename },
213 { &vop_revoke_desc, (vop_t *) fifo_revoke },
214 { &vop_rmdir_desc, (vop_t *) fifo_rmdir },
215 { &vop_seek_desc, (vop_t *) fifo_seek },
216 { &vop_setattr_desc, (vop_t *) ufs_setattr },
217 { &vop_strategy_desc, (vop_t *) fifo_strategy },
218 { &vop_symlink_desc, (vop_t *) fifo_symlink },
219 { &vop_truncate_desc, (vop_t *) fifo_truncate },
220 { &vop_unlock_desc, (vop_t *) ufs_unlock },
221 { &vop_update_desc, (vop_t *) ffs_update },
222 { &vop_valloc_desc, (vop_t *) fifo_valloc },
223 { &vop_vfree_desc, (vop_t *) ffs_vfree },
224 { &vop_write_desc, (vop_t *) ufsfifo_write },
225 { NULL, NULL }
226};
227static struct vnodeopv_desc ffs_fifoop_opv_desc =
228 { &ffs_fifoop_p, ffs_fifoop_entries };
229
230VNODEOP_SET(ffs_vnodeop_opv_desc);
231VNODEOP_SET(ffs_specop_opv_desc);
232VNODEOP_SET(ffs_fifoop_opv_desc);
233
234SYSCTL_NODE(_vfs, MOUNT_UFS, ffs, CTLFLAG_RW, 0, "FFS filesystem");
235
236#include <ufs/ufs/ufs_readwrite.c>
237
238/*
239 * Synch an open file.
240 */
241/* ARGSUSED */
242static int
243ffs_fsync(ap)
244 struct vop_fsync_args /* {
245 struct vnode *a_vp;
246 struct ucred *a_cred;
247 int a_waitfor;
248 struct proc *a_p;
249 } */ *ap;
250{
251 register struct vnode *vp = ap->a_vp;
252 register struct buf *bp;
253 struct timeval tv;
254 struct buf *nbp;
255 int pass;
256 int s;
257
258 pass = 0;
259 /*
260 * Flush all dirty buffers associated with a vnode.
261 */
262loop:
263 s = splbio();
264 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
265 nbp = bp->b_vnbufs.le_next;
266 if ((bp->b_flags & B_BUSY) || (pass == 0 && (bp->b_blkno < 0)))
267 continue;
268 if ((bp->b_flags & B_DELWRI) == 0)
269 panic("ffs_fsync: not dirty");
270
271 if (bp->b_vp != vp || ap->a_waitfor != MNT_NOWAIT) {
272
273 bremfree(bp);
274 bp->b_flags |= B_BUSY;
275 splx(s);
276 /*
277 * Wait for I/O associated with indirect blocks to complete,
278 * since there is no way to quickly wait for them below.
279 */
280 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
281 (void) bawrite(bp);
282 else
283 (void) bwrite(bp);
284 } else {
285 vfs_bio_awrite(bp);
286 splx(s);
287 }
288 goto loop;
289 }
290 splx(s);
291
292 if (pass == 0) {
293 pass = 1;
294 goto loop;
295 }
296
297 if (ap->a_waitfor == MNT_WAIT) {
298 s = splbio();
299 while (vp->v_numoutput) {
300 vp->v_flag |= VBWAIT;
301 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "ffsfsn", 0);
302 }
303 splx(s);
304#ifdef DIAGNOSTIC
305 if (vp->v_dirtyblkhd.lh_first) {
306 vprint("ffs_fsync: dirty", vp);
307 goto loop;
308 }
309#endif
310 }
311
312 gettime(&tv);
313 return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
314}
315