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.30 1997/09/27 13:40:10 kato 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_lookup_desc, (vop_t *)vfs_cache_lookup },/* lookup */
77 { &vop_cachedlookup_desc, (vop_t *)ufs_lookup },/* cachedlookup */
78 { &vop_create_desc, (vop_t *)ufs_create }, /* create */
79 { &vop_whiteout_desc, (vop_t *)ufs_whiteout }, /* whiteout */
80 { &vop_mknod_desc, (vop_t *)ufs_mknod }, /* mknod */
81 { &vop_open_desc, (vop_t *)ufs_open }, /* open */
82 { &vop_close_desc, (vop_t *)ufs_close }, /* close */
83 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
84 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
85 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
86 { &vop_read_desc, (vop_t *)ffs_read }, /* read */
87 { &vop_write_desc, (vop_t *)ffs_write }, /* write */
88 { &vop_lease_desc, (vop_t *)ufs_lease_check }, /* lease */
89 { &vop_ioctl_desc, (vop_t *)ufs_ioctl }, /* ioctl */
90 { &vop_poll_desc, (vop_t *)ufs_poll }, /* poll */
91 { &vop_revoke_desc, (vop_t *)ufs_revoke }, /* revoke */
92 { &vop_mmap_desc, (vop_t *)ufs_mmap }, /* mmap */
93 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
94 { &vop_seek_desc, (vop_t *)ufs_seek }, /* seek */
95 { &vop_remove_desc, (vop_t *)ufs_remove }, /* remove */
96 { &vop_link_desc, (vop_t *)ufs_link }, /* link */
97 { &vop_rename_desc, (vop_t *)ufs_rename }, /* rename */
98 { &vop_mkdir_desc, (vop_t *)ufs_mkdir }, /* mkdir */
99 { &vop_rmdir_desc, (vop_t *)ufs_rmdir }, /* rmdir */
100 { &vop_symlink_desc, (vop_t *)ufs_symlink }, /* symlink */
101 { &vop_readdir_desc, (vop_t *)ufs_readdir }, /* readdir */
102 { &vop_readlink_desc, (vop_t *)ufs_readlink }, /* readlink */
103 { &vop_abortop_desc, (vop_t *)ufs_abortop }, /* abortop */
104 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
105 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
106 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
107 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
108 { &vop_bmap_desc, (vop_t *)ufs_bmap }, /* bmap */
109 { &vop_strategy_desc, (vop_t *)ufs_strategy }, /* strategy */
110 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
111 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
112 { &vop_pathconf_desc, (vop_t *)ufs_pathconf }, /* pathconf */
113 { &vop_advlock_desc, (vop_t *)ufs_advlock }, /* advlock */
114 { &vop_blkatoff_desc, (vop_t *)ffs_blkatoff }, /* blkatoff */
115 { &vop_valloc_desc, (vop_t *)ffs_valloc }, /* valloc */
116 { &vop_reallocblks_desc, (vop_t *)ffs_reallocblks }, /* reallocblks */
117 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
118 { &vop_truncate_desc, (vop_t *)ffs_truncate }, /* truncate */
119 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
120 { &vop_getpages_desc, (vop_t *)ffs_getpages}, /* getpages */
121/* XXX: vop_putpages */
122 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
123 { NULL, NULL }
124};
125static struct vnodeopv_desc ffs_vnodeop_opv_desc =
126 { &ffs_vnodeop_p, ffs_vnodeop_entries };
127
128vop_t **ffs_specop_p;
129static struct vnodeopv_entry_desc ffs_specop_entries[] = {
130 { &vop_default_desc, (vop_t *)vn_default_error },
131 { &vop_lookup_desc, (vop_t *)spec_lookup }, /* lookup */
132/* XXX: vop_cachedlookup */
133 { &vop_create_desc, (vop_t *)spec_create }, /* create */
134/* XXX: vop_whiteout */
135 { &vop_mknod_desc, (vop_t *)spec_mknod }, /* mknod */
136 { &vop_open_desc, (vop_t *)spec_open }, /* open */
137 { &vop_close_desc, (vop_t *)ufsspec_close }, /* close */
138 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
139 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
140 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
141 { &vop_read_desc, (vop_t *)ufsspec_read }, /* read */
142 { &vop_write_desc, (vop_t *)ufsspec_write }, /* write */
143 { &vop_lease_desc, (vop_t *)spec_lease_check }, /* lease */
144 { &vop_ioctl_desc, (vop_t *)spec_ioctl }, /* ioctl */
145 { &vop_poll_desc, (vop_t *)spec_poll }, /* poll */
146 { &vop_revoke_desc, (vop_t *)spec_revoke }, /* revoke */
147 { &vop_mmap_desc, (vop_t *)spec_mmap }, /* mmap */
148 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
149 { &vop_seek_desc, (vop_t *)spec_seek }, /* seek */
150 { &vop_remove_desc, (vop_t *)spec_remove }, /* remove */
151 { &vop_link_desc, (vop_t *)spec_link }, /* link */
152 { &vop_rename_desc, (vop_t *)spec_rename }, /* rename */
153 { &vop_mkdir_desc, (vop_t *)spec_mkdir }, /* mkdir */
154 { &vop_rmdir_desc, (vop_t *)spec_rmdir }, /* rmdir */
155 { &vop_symlink_desc, (vop_t *)spec_symlink }, /* symlink */
156 { &vop_readdir_desc, (vop_t *)spec_readdir }, /* readdir */
157 { &vop_readlink_desc, (vop_t *)spec_readlink }, /* readlink */
158 { &vop_abortop_desc, (vop_t *)spec_abortop }, /* abortop */
159 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
160 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
161 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
162 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
163 { &vop_bmap_desc, (vop_t *)spec_bmap }, /* bmap */
164 { &vop_strategy_desc, (vop_t *)spec_strategy }, /* strategy */
165 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
166 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
167 { &vop_pathconf_desc, (vop_t *)spec_pathconf }, /* pathconf */
168 { &vop_advlock_desc, (vop_t *)spec_advlock }, /* advlock */
169 { &vop_blkatoff_desc, (vop_t *)spec_blkatoff }, /* blkatoff */
170 { &vop_valloc_desc, (vop_t *)spec_valloc }, /* valloc */
171 { &vop_reallocblks_desc, (vop_t *)spec_reallocblks }, /* reallocblks */
172 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
173 { &vop_truncate_desc, (vop_t *)spec_truncate }, /* truncate */
174 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
175 { &vop_getpages_desc, (vop_t *)spec_getpages}, /* getpages */
176/* XXX: vop_putpages */
177 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
178 { NULL, NULL }
179};
180static struct vnodeopv_desc ffs_specop_opv_desc =
181 { &ffs_specop_p, ffs_specop_entries };
182
183vop_t **ffs_fifoop_p;
184static struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
185 { &vop_default_desc, (vop_t *)vn_default_error },
186 { &vop_lookup_desc, (vop_t *)fifo_lookup }, /* lookup */
187/* XXX: vop_cachedlookup */
188 { &vop_create_desc, (vop_t *)fifo_create }, /* create */
189/* XXX: vop_whiteout */
190 { &vop_mknod_desc, (vop_t *)fifo_mknod }, /* mknod */
191 { &vop_open_desc, (vop_t *)fifo_open }, /* open */
192 { &vop_close_desc, (vop_t *)ufsfifo_close }, /* close */
193 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
194 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
195 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
196 { &vop_read_desc, (vop_t *)ufsfifo_read }, /* read */
197 { &vop_write_desc, (vop_t *)ufsfifo_write }, /* write */
198 { &vop_lease_desc, (vop_t *)fifo_lease_check }, /* lease */
199 { &vop_ioctl_desc, (vop_t *)fifo_ioctl }, /* ioctl */
200 { &vop_poll_desc, (vop_t *)fifo_poll }, /* poll */
201 { &vop_revoke_desc, (vop_t *)fifo_revoke }, /* revoke */
202 { &vop_mmap_desc, (vop_t *)fifo_mmap }, /* mmap */
203 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
204 { &vop_seek_desc, (vop_t *)fifo_seek }, /* seek */
205 { &vop_remove_desc, (vop_t *)fifo_remove }, /* remove */
206 { &vop_link_desc, (vop_t *)fifo_link }, /* link */
207 { &vop_rename_desc, (vop_t *)fifo_rename }, /* rename */
208 { &vop_mkdir_desc, (vop_t *)fifo_mkdir }, /* mkdir */
209 { &vop_rmdir_desc, (vop_t *)fifo_rmdir }, /* rmdir */
210 { &vop_symlink_desc, (vop_t *)fifo_symlink }, /* symlink */
211 { &vop_readdir_desc, (vop_t *)fifo_readdir }, /* readdir */
212 { &vop_readlink_desc, (vop_t *)fifo_readlink }, /* readlink */
213 { &vop_abortop_desc, (vop_t *)fifo_abortop }, /* abortop */
214 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
215 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
216 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
217 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
218 { &vop_bmap_desc, (vop_t *)fifo_bmap }, /* bmap */
219 { &vop_strategy_desc, (vop_t *)fifo_strategy }, /* strategy */
220 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
221 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
222 { &vop_pathconf_desc, (vop_t *)fifo_pathconf }, /* pathconf */
223 { &vop_advlock_desc, (vop_t *)fifo_advlock }, /* advlock */
224 { &vop_blkatoff_desc, (vop_t *)fifo_blkatoff }, /* blkatoff */
225 { &vop_valloc_desc, (vop_t *)fifo_valloc }, /* valloc */
226 { &vop_reallocblks_desc, (vop_t *)fifo_reallocblks }, /* reallocblks */
227 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
228 { &vop_truncate_desc, (vop_t *)fifo_truncate }, /* truncate */
229 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
230/* XXX: vop_getpages */
231/* XXX: vop_putpages */
232 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
233 { NULL, NULL }
234};
235static struct vnodeopv_desc ffs_fifoop_opv_desc =
236 { &ffs_fifoop_p, ffs_fifoop_entries };
237
238VNODEOP_SET(ffs_vnodeop_opv_desc);
239VNODEOP_SET(ffs_specop_opv_desc);
240VNODEOP_SET(ffs_fifoop_opv_desc);
241
242SYSCTL_NODE(_vfs, MOUNT_UFS, ffs, CTLFLAG_RW, 0, "FFS filesystem");
243
244#include <ufs/ufs/ufs_readwrite.c>
245
246/*
247 * Synch an open file.
248 */
249/* ARGSUSED */
250static int
251ffs_fsync(ap)
252 struct vop_fsync_args /* {
253 struct vnode *a_vp;
254 struct ucred *a_cred;
255 int a_waitfor;
256 struct proc *a_p;
257 } */ *ap;
258{
259 register struct vnode *vp = ap->a_vp;
260 register struct buf *bp;
261 struct timeval tv;
262 struct buf *nbp;
263 int pass;
264 int s;
265
266 pass = 0;
267 /*
268 * Flush all dirty buffers associated with a vnode.
269 */
270loop:
271 s = splbio();
272 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
273 nbp = bp->b_vnbufs.le_next;
274 if ((bp->b_flags & B_BUSY) || (pass == 0 && (bp->b_blkno < 0)))
275 continue;
276 if ((bp->b_flags & B_DELWRI) == 0)
277 panic("ffs_fsync: not dirty");
278
279 if (bp->b_vp != vp || ap->a_waitfor != MNT_NOWAIT) {
280
281 bremfree(bp);
282 bp->b_flags |= B_BUSY;
283 splx(s);
284 /*
285 * Wait for I/O associated with indirect blocks to complete,
286 * since there is no way to quickly wait for them below.
287 */
288 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
289 (void) bawrite(bp);
290 else
291 (void) bwrite(bp);
292 } else {
293 vfs_bio_awrite(bp);
294 splx(s);
295 }
296 goto loop;
297 }
298 splx(s);
299
300 if (pass == 0) {
301 pass = 1;
302 goto loop;
303 }
304
305 if (ap->a_waitfor == MNT_WAIT) {
306 s = splbio();
307 while (vp->v_numoutput) {
308 vp->v_flag |= VBWAIT;
309 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "ffsfsn", 0);
310 }
311 splx(s);
312#ifdef DIAGNOSTIC
313 if (vp->v_dirtyblkhd.lh_first) {
314 vprint("ffs_fsync: dirty", vp);
315 goto loop;
316 }
317#endif
318 }
319
320 gettime(&tv);
321 return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
322}
323
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.30 1997/09/27 13:40:10 kato 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_lookup_desc, (vop_t *)vfs_cache_lookup },/* lookup */
77 { &vop_cachedlookup_desc, (vop_t *)ufs_lookup },/* cachedlookup */
78 { &vop_create_desc, (vop_t *)ufs_create }, /* create */
79 { &vop_whiteout_desc, (vop_t *)ufs_whiteout }, /* whiteout */
80 { &vop_mknod_desc, (vop_t *)ufs_mknod }, /* mknod */
81 { &vop_open_desc, (vop_t *)ufs_open }, /* open */
82 { &vop_close_desc, (vop_t *)ufs_close }, /* close */
83 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
84 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
85 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
86 { &vop_read_desc, (vop_t *)ffs_read }, /* read */
87 { &vop_write_desc, (vop_t *)ffs_write }, /* write */
88 { &vop_lease_desc, (vop_t *)ufs_lease_check }, /* lease */
89 { &vop_ioctl_desc, (vop_t *)ufs_ioctl }, /* ioctl */
90 { &vop_poll_desc, (vop_t *)ufs_poll }, /* poll */
91 { &vop_revoke_desc, (vop_t *)ufs_revoke }, /* revoke */
92 { &vop_mmap_desc, (vop_t *)ufs_mmap }, /* mmap */
93 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
94 { &vop_seek_desc, (vop_t *)ufs_seek }, /* seek */
95 { &vop_remove_desc, (vop_t *)ufs_remove }, /* remove */
96 { &vop_link_desc, (vop_t *)ufs_link }, /* link */
97 { &vop_rename_desc, (vop_t *)ufs_rename }, /* rename */
98 { &vop_mkdir_desc, (vop_t *)ufs_mkdir }, /* mkdir */
99 { &vop_rmdir_desc, (vop_t *)ufs_rmdir }, /* rmdir */
100 { &vop_symlink_desc, (vop_t *)ufs_symlink }, /* symlink */
101 { &vop_readdir_desc, (vop_t *)ufs_readdir }, /* readdir */
102 { &vop_readlink_desc, (vop_t *)ufs_readlink }, /* readlink */
103 { &vop_abortop_desc, (vop_t *)ufs_abortop }, /* abortop */
104 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
105 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
106 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
107 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
108 { &vop_bmap_desc, (vop_t *)ufs_bmap }, /* bmap */
109 { &vop_strategy_desc, (vop_t *)ufs_strategy }, /* strategy */
110 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
111 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
112 { &vop_pathconf_desc, (vop_t *)ufs_pathconf }, /* pathconf */
113 { &vop_advlock_desc, (vop_t *)ufs_advlock }, /* advlock */
114 { &vop_blkatoff_desc, (vop_t *)ffs_blkatoff }, /* blkatoff */
115 { &vop_valloc_desc, (vop_t *)ffs_valloc }, /* valloc */
116 { &vop_reallocblks_desc, (vop_t *)ffs_reallocblks }, /* reallocblks */
117 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
118 { &vop_truncate_desc, (vop_t *)ffs_truncate }, /* truncate */
119 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
120 { &vop_getpages_desc, (vop_t *)ffs_getpages}, /* getpages */
121/* XXX: vop_putpages */
122 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
123 { NULL, NULL }
124};
125static struct vnodeopv_desc ffs_vnodeop_opv_desc =
126 { &ffs_vnodeop_p, ffs_vnodeop_entries };
127
128vop_t **ffs_specop_p;
129static struct vnodeopv_entry_desc ffs_specop_entries[] = {
130 { &vop_default_desc, (vop_t *)vn_default_error },
131 { &vop_lookup_desc, (vop_t *)spec_lookup }, /* lookup */
132/* XXX: vop_cachedlookup */
133 { &vop_create_desc, (vop_t *)spec_create }, /* create */
134/* XXX: vop_whiteout */
135 { &vop_mknod_desc, (vop_t *)spec_mknod }, /* mknod */
136 { &vop_open_desc, (vop_t *)spec_open }, /* open */
137 { &vop_close_desc, (vop_t *)ufsspec_close }, /* close */
138 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
139 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
140 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
141 { &vop_read_desc, (vop_t *)ufsspec_read }, /* read */
142 { &vop_write_desc, (vop_t *)ufsspec_write }, /* write */
143 { &vop_lease_desc, (vop_t *)spec_lease_check }, /* lease */
144 { &vop_ioctl_desc, (vop_t *)spec_ioctl }, /* ioctl */
145 { &vop_poll_desc, (vop_t *)spec_poll }, /* poll */
146 { &vop_revoke_desc, (vop_t *)spec_revoke }, /* revoke */
147 { &vop_mmap_desc, (vop_t *)spec_mmap }, /* mmap */
148 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
149 { &vop_seek_desc, (vop_t *)spec_seek }, /* seek */
150 { &vop_remove_desc, (vop_t *)spec_remove }, /* remove */
151 { &vop_link_desc, (vop_t *)spec_link }, /* link */
152 { &vop_rename_desc, (vop_t *)spec_rename }, /* rename */
153 { &vop_mkdir_desc, (vop_t *)spec_mkdir }, /* mkdir */
154 { &vop_rmdir_desc, (vop_t *)spec_rmdir }, /* rmdir */
155 { &vop_symlink_desc, (vop_t *)spec_symlink }, /* symlink */
156 { &vop_readdir_desc, (vop_t *)spec_readdir }, /* readdir */
157 { &vop_readlink_desc, (vop_t *)spec_readlink }, /* readlink */
158 { &vop_abortop_desc, (vop_t *)spec_abortop }, /* abortop */
159 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
160 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
161 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
162 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
163 { &vop_bmap_desc, (vop_t *)spec_bmap }, /* bmap */
164 { &vop_strategy_desc, (vop_t *)spec_strategy }, /* strategy */
165 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
166 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
167 { &vop_pathconf_desc, (vop_t *)spec_pathconf }, /* pathconf */
168 { &vop_advlock_desc, (vop_t *)spec_advlock }, /* advlock */
169 { &vop_blkatoff_desc, (vop_t *)spec_blkatoff }, /* blkatoff */
170 { &vop_valloc_desc, (vop_t *)spec_valloc }, /* valloc */
171 { &vop_reallocblks_desc, (vop_t *)spec_reallocblks }, /* reallocblks */
172 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
173 { &vop_truncate_desc, (vop_t *)spec_truncate }, /* truncate */
174 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
175 { &vop_getpages_desc, (vop_t *)spec_getpages}, /* getpages */
176/* XXX: vop_putpages */
177 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
178 { NULL, NULL }
179};
180static struct vnodeopv_desc ffs_specop_opv_desc =
181 { &ffs_specop_p, ffs_specop_entries };
182
183vop_t **ffs_fifoop_p;
184static struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
185 { &vop_default_desc, (vop_t *)vn_default_error },
186 { &vop_lookup_desc, (vop_t *)fifo_lookup }, /* lookup */
187/* XXX: vop_cachedlookup */
188 { &vop_create_desc, (vop_t *)fifo_create }, /* create */
189/* XXX: vop_whiteout */
190 { &vop_mknod_desc, (vop_t *)fifo_mknod }, /* mknod */
191 { &vop_open_desc, (vop_t *)fifo_open }, /* open */
192 { &vop_close_desc, (vop_t *)ufsfifo_close }, /* close */
193 { &vop_access_desc, (vop_t *)ufs_access }, /* access */
194 { &vop_getattr_desc, (vop_t *)ufs_getattr }, /* getattr */
195 { &vop_setattr_desc, (vop_t *)ufs_setattr }, /* setattr */
196 { &vop_read_desc, (vop_t *)ufsfifo_read }, /* read */
197 { &vop_write_desc, (vop_t *)ufsfifo_write }, /* write */
198 { &vop_lease_desc, (vop_t *)fifo_lease_check }, /* lease */
199 { &vop_ioctl_desc, (vop_t *)fifo_ioctl }, /* ioctl */
200 { &vop_poll_desc, (vop_t *)fifo_poll }, /* poll */
201 { &vop_revoke_desc, (vop_t *)fifo_revoke }, /* revoke */
202 { &vop_mmap_desc, (vop_t *)fifo_mmap }, /* mmap */
203 { &vop_fsync_desc, (vop_t *)ffs_fsync }, /* fsync */
204 { &vop_seek_desc, (vop_t *)fifo_seek }, /* seek */
205 { &vop_remove_desc, (vop_t *)fifo_remove }, /* remove */
206 { &vop_link_desc, (vop_t *)fifo_link }, /* link */
207 { &vop_rename_desc, (vop_t *)fifo_rename }, /* rename */
208 { &vop_mkdir_desc, (vop_t *)fifo_mkdir }, /* mkdir */
209 { &vop_rmdir_desc, (vop_t *)fifo_rmdir }, /* rmdir */
210 { &vop_symlink_desc, (vop_t *)fifo_symlink }, /* symlink */
211 { &vop_readdir_desc, (vop_t *)fifo_readdir }, /* readdir */
212 { &vop_readlink_desc, (vop_t *)fifo_readlink }, /* readlink */
213 { &vop_abortop_desc, (vop_t *)fifo_abortop }, /* abortop */
214 { &vop_inactive_desc, (vop_t *)ufs_inactive }, /* inactive */
215 { &vop_reclaim_desc, (vop_t *)ufs_reclaim }, /* reclaim */
216 { &vop_lock_desc, (vop_t *)ufs_lock }, /* lock */
217 { &vop_unlock_desc, (vop_t *)ufs_unlock }, /* unlock */
218 { &vop_bmap_desc, (vop_t *)fifo_bmap }, /* bmap */
219 { &vop_strategy_desc, (vop_t *)fifo_strategy }, /* strategy */
220 { &vop_print_desc, (vop_t *)ufs_print }, /* print */
221 { &vop_islocked_desc, (vop_t *)ufs_islocked }, /* islocked */
222 { &vop_pathconf_desc, (vop_t *)fifo_pathconf }, /* pathconf */
223 { &vop_advlock_desc, (vop_t *)fifo_advlock }, /* advlock */
224 { &vop_blkatoff_desc, (vop_t *)fifo_blkatoff }, /* blkatoff */
225 { &vop_valloc_desc, (vop_t *)fifo_valloc }, /* valloc */
226 { &vop_reallocblks_desc, (vop_t *)fifo_reallocblks }, /* reallocblks */
227 { &vop_vfree_desc, (vop_t *)ffs_vfree }, /* vfree */
228 { &vop_truncate_desc, (vop_t *)fifo_truncate }, /* truncate */
229 { &vop_update_desc, (vop_t *)ffs_update }, /* update */
230/* XXX: vop_getpages */
231/* XXX: vop_putpages */
232 { &vop_bwrite_desc, (vop_t *)vn_bwrite }, /* bwrite */
233 { NULL, NULL }
234};
235static struct vnodeopv_desc ffs_fifoop_opv_desc =
236 { &ffs_fifoop_p, ffs_fifoop_entries };
237
238VNODEOP_SET(ffs_vnodeop_opv_desc);
239VNODEOP_SET(ffs_specop_opv_desc);
240VNODEOP_SET(ffs_fifoop_opv_desc);
241
242SYSCTL_NODE(_vfs, MOUNT_UFS, ffs, CTLFLAG_RW, 0, "FFS filesystem");
243
244#include <ufs/ufs/ufs_readwrite.c>
245
246/*
247 * Synch an open file.
248 */
249/* ARGSUSED */
250static int
251ffs_fsync(ap)
252 struct vop_fsync_args /* {
253 struct vnode *a_vp;
254 struct ucred *a_cred;
255 int a_waitfor;
256 struct proc *a_p;
257 } */ *ap;
258{
259 register struct vnode *vp = ap->a_vp;
260 register struct buf *bp;
261 struct timeval tv;
262 struct buf *nbp;
263 int pass;
264 int s;
265
266 pass = 0;
267 /*
268 * Flush all dirty buffers associated with a vnode.
269 */
270loop:
271 s = splbio();
272 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
273 nbp = bp->b_vnbufs.le_next;
274 if ((bp->b_flags & B_BUSY) || (pass == 0 && (bp->b_blkno < 0)))
275 continue;
276 if ((bp->b_flags & B_DELWRI) == 0)
277 panic("ffs_fsync: not dirty");
278
279 if (bp->b_vp != vp || ap->a_waitfor != MNT_NOWAIT) {
280
281 bremfree(bp);
282 bp->b_flags |= B_BUSY;
283 splx(s);
284 /*
285 * Wait for I/O associated with indirect blocks to complete,
286 * since there is no way to quickly wait for them below.
287 */
288 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
289 (void) bawrite(bp);
290 else
291 (void) bwrite(bp);
292 } else {
293 vfs_bio_awrite(bp);
294 splx(s);
295 }
296 goto loop;
297 }
298 splx(s);
299
300 if (pass == 0) {
301 pass = 1;
302 goto loop;
303 }
304
305 if (ap->a_waitfor == MNT_WAIT) {
306 s = splbio();
307 while (vp->v_numoutput) {
308 vp->v_flag |= VBWAIT;
309 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "ffsfsn", 0);
310 }
311 splx(s);
312#ifdef DIAGNOSTIC
313 if (vp->v_dirtyblkhd.lh_first) {
314 vprint("ffs_fsync: dirty", vp);
315 goto loop;
316 }
317#endif
318 }
319
320 gettime(&tv);
321 return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
322}
323