Deleted Added
full compact
ext2_vnops.c (30474) ext2_vnops.c (30492)
1/*
2 * modified for EXT2FS support in Lites 1.1
3 *
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
6 */
7/*
8 * Copyright (c) 1982, 1986, 1989, 1993
9 * The Regents of the University of California. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)ext2_vnops.c 8.7 (Berkeley) 2/3/94
40 */
41
42#if !defined(__FreeBSD__)
43#include "fifo.h"
44#include "diagnostic.h"
45#endif
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/resourcevar.h>
50#include <sys/kernel.h>
51#include <sys/stat.h>
52#include <sys/buf.h>
53#include <sys/proc.h>
54#include <sys/mount.h>
55#include <sys/sysctl.h>
56#include <sys/time.h>
57#include <sys/vnode.h>
58
59#include <vm/vm.h>
60#include <vm/vm_extern.h>
61
62#include <miscfs/specfs/specdev.h>
63#include <miscfs/fifofs/fifo.h>
64
65#if !defined(__FreeBSD__)
66#include <ufs/ufs/lockf.h>
67#else
68#include <sys/signalvar.h>
69#endif
70#include <ufs/ufs/quota.h>
71#include <ufs/ufs/inode.h>
72#include <ufs/ufs/ufsmount.h>
73#include <ufs/ufs/ufs_extern.h>
74#include <ufs/ffs/ffs_extern.h>
75
76#include <gnu/ext2fs/ext2_fs_sb.h>
77#include <gnu/ext2fs/fs.h>
78#include <gnu/ext2fs/ext2_extern.h>
79
80static int ext2_fsync __P((struct vop_fsync_args *));
81static int ext2_read __P((struct vop_read_args *));
82static int ext2_write __P((struct vop_write_args *));
83
84/* Global vfs data structures for ufs. */
85vop_t **ext2_vnodeop_p;
86static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
87 { &vop_default_desc, (vop_t *) ufs_vnoperate },
88 { &vop_cachedlookup_desc, (vop_t *) ext2_lookup },
89 { &vop_fsync_desc, (vop_t *) ext2_fsync },
90 { &vop_inactive_desc, (vop_t *) ext2_inactive },
91 { &vop_read_desc, (vop_t *) ext2_read },
92 { &vop_readdir_desc, (vop_t *) ext2_readdir },
93 { &vop_reallocblks_desc, (vop_t *) ext2_reallocblks },
1/*
2 * modified for EXT2FS support in Lites 1.1
3 *
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
6 */
7/*
8 * Copyright (c) 1982, 1986, 1989, 1993
9 * The Regents of the University of California. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)ext2_vnops.c 8.7 (Berkeley) 2/3/94
40 */
41
42#if !defined(__FreeBSD__)
43#include "fifo.h"
44#include "diagnostic.h"
45#endif
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/resourcevar.h>
50#include <sys/kernel.h>
51#include <sys/stat.h>
52#include <sys/buf.h>
53#include <sys/proc.h>
54#include <sys/mount.h>
55#include <sys/sysctl.h>
56#include <sys/time.h>
57#include <sys/vnode.h>
58
59#include <vm/vm.h>
60#include <vm/vm_extern.h>
61
62#include <miscfs/specfs/specdev.h>
63#include <miscfs/fifofs/fifo.h>
64
65#if !defined(__FreeBSD__)
66#include <ufs/ufs/lockf.h>
67#else
68#include <sys/signalvar.h>
69#endif
70#include <ufs/ufs/quota.h>
71#include <ufs/ufs/inode.h>
72#include <ufs/ufs/ufsmount.h>
73#include <ufs/ufs/ufs_extern.h>
74#include <ufs/ffs/ffs_extern.h>
75
76#include <gnu/ext2fs/ext2_fs_sb.h>
77#include <gnu/ext2fs/fs.h>
78#include <gnu/ext2fs/ext2_extern.h>
79
80static int ext2_fsync __P((struct vop_fsync_args *));
81static int ext2_read __P((struct vop_read_args *));
82static int ext2_write __P((struct vop_write_args *));
83
84/* Global vfs data structures for ufs. */
85vop_t **ext2_vnodeop_p;
86static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
87 { &vop_default_desc, (vop_t *) ufs_vnoperate },
88 { &vop_cachedlookup_desc, (vop_t *) ext2_lookup },
89 { &vop_fsync_desc, (vop_t *) ext2_fsync },
90 { &vop_inactive_desc, (vop_t *) ext2_inactive },
91 { &vop_read_desc, (vop_t *) ext2_read },
92 { &vop_readdir_desc, (vop_t *) ext2_readdir },
93 { &vop_reallocblks_desc, (vop_t *) ext2_reallocblks },
94 { &vop_update_desc, (vop_t *) ext2_update },
95 { &vop_write_desc, (vop_t *) ext2_write },
96 { NULL, NULL }
97};
98static struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
99 { &ext2_vnodeop_p, ext2_vnodeop_entries };
100
101vop_t **ext2_specop_p;
102static struct vnodeopv_entry_desc ext2_specop_entries[] = {
103 { &vop_default_desc, (vop_t *) ufs_vnoperatespec },
104 { &vop_fsync_desc, (vop_t *) ext2_fsync },
105 { &vop_inactive_desc, (vop_t *) ext2_inactive },
94 { &vop_write_desc, (vop_t *) ext2_write },
95 { NULL, NULL }
96};
97static struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
98 { &ext2_vnodeop_p, ext2_vnodeop_entries };
99
100vop_t **ext2_specop_p;
101static struct vnodeopv_entry_desc ext2_specop_entries[] = {
102 { &vop_default_desc, (vop_t *) ufs_vnoperatespec },
103 { &vop_fsync_desc, (vop_t *) ext2_fsync },
104 { &vop_inactive_desc, (vop_t *) ext2_inactive },
106 { &vop_update_desc, (vop_t *) ext2_update },
107 { NULL, NULL }
108};
109static struct vnodeopv_desc ext2fs_specop_opv_desc =
110 { &ext2_specop_p, ext2_specop_entries };
111
112vop_t **ext2_fifoop_p;
113static struct vnodeopv_entry_desc ext2_fifoop_entries[] = {
114 { &vop_default_desc, (vop_t *) ufs_vnoperatefifo },
115 { &vop_fsync_desc, (vop_t *) ext2_fsync },
116 { &vop_inactive_desc, (vop_t *) ext2_inactive },
105 { NULL, NULL }
106};
107static struct vnodeopv_desc ext2fs_specop_opv_desc =
108 { &ext2_specop_p, ext2_specop_entries };
109
110vop_t **ext2_fifoop_p;
111static struct vnodeopv_entry_desc ext2_fifoop_entries[] = {
112 { &vop_default_desc, (vop_t *) ufs_vnoperatefifo },
113 { &vop_fsync_desc, (vop_t *) ext2_fsync },
114 { &vop_inactive_desc, (vop_t *) ext2_inactive },
117 { &vop_update_desc, (vop_t *) ext2_update },
118 { NULL, NULL }
119};
120static struct vnodeopv_desc ext2fs_fifoop_opv_desc =
121 { &ext2_fifoop_p, ext2_fifoop_entries };
122
123#if defined(__FreeBSD__)
124 VNODEOP_SET(ext2fs_vnodeop_opv_desc);
125 VNODEOP_SET(ext2fs_specop_opv_desc);
126 VNODEOP_SET(ext2fs_fifoop_opv_desc);
127#endif
128
129#include <gnu/ext2fs/ext2_readwrite.c>
130
131/*
132 * Synch an open file.
133 */
134/* ARGSUSED */
135static int
136ext2_fsync(ap)
137 struct vop_fsync_args /* {
138 struct vnode *a_vp;
139 struct ucred *a_cred;
140 int a_waitfor;
141 struct proc *a_p;
142 } */ *ap;
143{
144 register struct vnode *vp = ap->a_vp;
145 register struct buf *bp;
146 struct timeval tv;
147 struct buf *nbp;
148 int s;
149
150 /*
151 * Clean memory object.
152 * XXX add this to all file systems.
153 * XXX why is all this fs specific?
154 */
155#if !defined(__FreeBSD__)
156 vn_pager_sync(vp, ap->a_waitfor);
157#endif
158
159 /*
160 * Flush all dirty buffers associated with a vnode.
161 */
162 ext2_discard_prealloc(VTOI(vp));
163
164loop:
165 s = splbio();
166 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
167 nbp = bp->b_vnbufs.le_next;
168 if ((bp->b_flags & B_BUSY))
169 continue;
170 if ((bp->b_flags & B_DELWRI) == 0)
171 panic("ext2_fsync: not dirty");
172 bremfree(bp);
173 bp->b_flags |= B_BUSY;
174 splx(s);
175 /*
176 * Wait for I/O associated with indirect blocks to complete,
177 * since there is no way to quickly wait for them below.
178 */
179 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
180 (void) bawrite(bp);
181 else
182 (void) bwrite(bp);
183 goto loop;
184 }
185 if (ap->a_waitfor == MNT_WAIT) {
186 while (vp->v_numoutput) {
187 vp->v_flag |= VBWAIT;
188#if !defined(__FreeBSD__)
189 sleep((caddr_t)&vp->v_numoutput, PRIBIO + 1);
190#else
191 tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "extfsn", 0);
192#endif
193 }
194#if DIAGNOSTIC
195 if (vp->v_dirtyblkhd.lh_first) {
196 vprint("ext2_fsync: dirty", vp);
197 goto loop;
198 }
199#endif
200 }
201 splx(s);
202 gettime(&tv);
115 { NULL, NULL }
116};
117static struct vnodeopv_desc ext2fs_fifoop_opv_desc =
118 { &ext2_fifoop_p, ext2_fifoop_entries };
119
120#if defined(__FreeBSD__)
121 VNODEOP_SET(ext2fs_vnodeop_opv_desc);
122 VNODEOP_SET(ext2fs_specop_opv_desc);
123 VNODEOP_SET(ext2fs_fifoop_opv_desc);
124#endif
125
126#include <gnu/ext2fs/ext2_readwrite.c>
127
128/*
129 * Synch an open file.
130 */
131/* ARGSUSED */
132static int
133ext2_fsync(ap)
134 struct vop_fsync_args /* {
135 struct vnode *a_vp;
136 struct ucred *a_cred;
137 int a_waitfor;
138 struct proc *a_p;
139 } */ *ap;
140{
141 register struct vnode *vp = ap->a_vp;
142 register struct buf *bp;
143 struct timeval tv;
144 struct buf *nbp;
145 int s;
146
147 /*
148 * Clean memory object.
149 * XXX add this to all file systems.
150 * XXX why is all this fs specific?
151 */
152#if !defined(__FreeBSD__)
153 vn_pager_sync(vp, ap->a_waitfor);
154#endif
155
156 /*
157 * Flush all dirty buffers associated with a vnode.
158 */
159 ext2_discard_prealloc(VTOI(vp));
160
161loop:
162 s = splbio();
163 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
164 nbp = bp->b_vnbufs.le_next;
165 if ((bp->b_flags & B_BUSY))
166 continue;
167 if ((bp->b_flags & B_DELWRI) == 0)
168 panic("ext2_fsync: not dirty");
169 bremfree(bp);
170 bp->b_flags |= B_BUSY;
171 splx(s);
172 /*
173 * Wait for I/O associated with indirect blocks to complete,
174 * since there is no way to quickly wait for them below.
175 */
176 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
177 (void) bawrite(bp);
178 else
179 (void) bwrite(bp);
180 goto loop;
181 }
182 if (ap->a_waitfor == MNT_WAIT) {
183 while (vp->v_numoutput) {
184 vp->v_flag |= VBWAIT;
185#if !defined(__FreeBSD__)
186 sleep((caddr_t)&vp->v_numoutput, PRIBIO + 1);
187#else
188 tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "extfsn", 0);
189#endif
190 }
191#if DIAGNOSTIC
192 if (vp->v_dirtyblkhd.lh_first) {
193 vprint("ext2_fsync: dirty", vp);
194 goto loop;
195 }
196#endif
197 }
198 splx(s);
199 gettime(&tv);
203 return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
200 return (UFS_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT));
204}
201}