]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
23 | /* | |
24 | * Copyright (c) 1982, 1986, 1989, 1993 | |
25 | * The Regents of the University of California. All rights reserved. | |
26 | * | |
27 | * Redistribution and use in source and binary forms, with or without | |
28 | * modification, are permitted provided that the following conditions | |
29 | * are met: | |
30 | * 1. Redistributions of source code must retain the above copyright | |
31 | * notice, this list of conditions and the following disclaimer. | |
32 | * 2. Redistributions in binary form must reproduce the above copyright | |
33 | * notice, this list of conditions and the following disclaimer in the | |
34 | * documentation and/or other materials provided with the distribution. | |
35 | * 3. All advertising materials mentioning features or use of this software | |
36 | * must display the following acknowledgement: | |
37 | * This product includes software developed by the University of | |
38 | * California, Berkeley and its contributors. | |
39 | * 4. Neither the name of the University nor the names of its contributors | |
40 | * may be used to endorse or promote products derived from this software | |
41 | * without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
44 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
46 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
49 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
50 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
51 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
52 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
53 | * SUCH DAMAGE. | |
54 | * | |
55 | * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95 | |
56 | */ | |
57 | ||
58 | #include <rev_endian_fs.h> | |
59 | #include <sys/param.h> | |
60 | #include <sys/systm.h> | |
61 | #include <sys/resourcevar.h> | |
62 | #include <sys/kernel.h> | |
63 | #include <sys/file.h> | |
64 | #include <sys/stat.h> | |
65 | #include <sys/buf.h> | |
66 | #include <sys/proc.h> | |
67 | #include <sys/conf.h> | |
68 | #include <sys/mount.h> | |
69 | #include <sys/vnode.h> | |
70 | #include <sys/malloc.h> | |
71 | #include <sys/ubc.h> | |
72 | ||
73 | #include <sys/vm.h> | |
74 | #include <vfs/vfs_support.h> | |
75 | ||
76 | #include <miscfs/specfs/specdev.h> | |
77 | #include <miscfs/fifofs/fifo.h> | |
78 | ||
79 | #include <ufs/ufs/lockf.h> | |
80 | #include <ufs/ufs/quota.h> | |
81 | #include <ufs/ufs/inode.h> | |
82 | #include <ufs/ufs/dir.h> | |
83 | #include <ufs/ufs/ufsmount.h> | |
84 | #include <ufs/ufs/ufs_extern.h> | |
85 | ||
86 | #include <ufs/ffs/fs.h> | |
87 | #include <ufs/ffs/ffs_extern.h> | |
88 | #if REV_ENDIAN_FS | |
89 | #include <ufs/ufs/ufs_byte_order.h> | |
90 | #include <architecture/byte_order.h> | |
91 | #endif /* REV_ENDIAN_FS */ | |
92 | ||
93 | #define VOPFUNC int (*)(void *) | |
94 | ||
95 | /* Global vfs data structures for ufs. */ | |
96 | int (**ffs_vnodeop_p)(void *); | |
97 | struct vnodeopv_entry_desc ffs_vnodeop_entries[] = { | |
98 | { &vop_default_desc, (VOPFUNC)vn_default_error }, | |
99 | { &vop_lookup_desc, (VOPFUNC)ufs_lookup }, /* lookup */ | |
100 | { &vop_create_desc, (VOPFUNC)ufs_create }, /* create */ | |
101 | { &vop_whiteout_desc, (VOPFUNC)ufs_whiteout }, /* whiteout */ | |
102 | { &vop_mknod_desc, (VOPFUNC)ufs_mknod }, /* mknod */ | |
103 | { &vop_open_desc, (VOPFUNC)ufs_open }, /* open */ | |
104 | { &vop_close_desc, (VOPFUNC)ufs_close }, /* close */ | |
105 | { &vop_access_desc, (VOPFUNC)ufs_access }, /* access */ | |
106 | { &vop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */ | |
107 | { &vop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */ | |
108 | { &vop_read_desc, (VOPFUNC)ffs_read }, /* read */ | |
109 | { &vop_write_desc, (VOPFUNC)ffs_write }, /* write */ | |
110 | { &vop_lease_desc, (VOPFUNC)ufs_lease_check }, /* lease */ | |
111 | { &vop_ioctl_desc, (VOPFUNC)ufs_ioctl }, /* ioctl */ | |
112 | { &vop_select_desc, (VOPFUNC)ufs_select }, /* select */ | |
113 | { &vop_revoke_desc, (VOPFUNC)ufs_revoke }, /* revoke */ | |
114 | { &vop_mmap_desc, (VOPFUNC)ufs_mmap }, /* mmap */ | |
115 | { &vop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */ | |
116 | { &vop_seek_desc, (VOPFUNC)ufs_seek }, /* seek */ | |
117 | { &vop_remove_desc, (VOPFUNC)ufs_remove }, /* remove */ | |
118 | { &vop_link_desc, (VOPFUNC)ufs_link }, /* link */ | |
119 | { &vop_rename_desc, (VOPFUNC)ufs_rename }, /* rename */ | |
120 | { &vop_mkdir_desc, (VOPFUNC)ufs_mkdir }, /* mkdir */ | |
121 | { &vop_rmdir_desc, (VOPFUNC)ufs_rmdir }, /* rmdir */ | |
122 | { &vop_symlink_desc, (VOPFUNC)ufs_symlink }, /* symlink */ | |
123 | { &vop_readdir_desc, (VOPFUNC)ufs_readdir }, /* readdir */ | |
124 | { &vop_readlink_desc, (VOPFUNC)ufs_readlink }, /* readlink */ | |
125 | { &vop_abortop_desc, (VOPFUNC)ufs_abortop }, /* abortop */ | |
126 | { &vop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */ | |
127 | { &vop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */ | |
128 | { &vop_lock_desc, (VOPFUNC)ufs_lock }, /* lock */ | |
129 | { &vop_unlock_desc, (VOPFUNC)ufs_unlock }, /* unlock */ | |
130 | { &vop_bmap_desc, (VOPFUNC)ufs_bmap }, /* bmap */ | |
131 | { &vop_strategy_desc, (VOPFUNC)ufs_strategy }, /* strategy */ | |
132 | { &vop_print_desc, (VOPFUNC)ufs_print }, /* print */ | |
133 | { &vop_islocked_desc, (VOPFUNC)ufs_islocked }, /* islocked */ | |
134 | { &vop_pathconf_desc, (VOPFUNC)ufs_pathconf }, /* pathconf */ | |
135 | { &vop_advlock_desc, (VOPFUNC)ufs_advlock }, /* advlock */ | |
136 | { &vop_blkatoff_desc, (VOPFUNC)ffs_blkatoff }, /* blkatoff */ | |
137 | { &vop_valloc_desc, (VOPFUNC)ffs_valloc }, /* valloc */ | |
138 | { &vop_reallocblks_desc, (VOPFUNC)ffs_reallocblks }, /* reallocblks */ | |
139 | { &vop_vfree_desc, (VOPFUNC)ffs_vfree }, /* vfree */ | |
140 | { &vop_truncate_desc, (VOPFUNC)ffs_truncate }, /* truncate */ | |
141 | { &vop_update_desc, (VOPFUNC)ffs_update }, /* update */ | |
142 | { &vop_bwrite_desc, (VOPFUNC)vn_bwrite }, | |
143 | { &vop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */ | |
144 | { &vop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */ | |
145 | { &vop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */ | |
146 | { &vop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */ | |
147 | { &vop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */ | |
148 | { &vop_cmap_desc, (VOPFUNC)ufs_cmap }, /* cmap */ | |
149 | { (struct vnodeop_desc*)NULL, (int(*)())NULL } | |
150 | }; | |
151 | struct vnodeopv_desc ffs_vnodeop_opv_desc = | |
152 | { &ffs_vnodeop_p, ffs_vnodeop_entries }; | |
153 | ||
154 | int (**ffs_specop_p)(void *); | |
155 | struct vnodeopv_entry_desc ffs_specop_entries[] = { | |
156 | { &vop_default_desc, (VOPFUNC)vn_default_error }, | |
157 | { &vop_lookup_desc, (VOPFUNC)spec_lookup }, /* lookup */ | |
158 | { &vop_create_desc, (VOPFUNC)spec_create }, /* create */ | |
159 | { &vop_mknod_desc, (VOPFUNC)spec_mknod }, /* mknod */ | |
160 | { &vop_open_desc, (VOPFUNC)spec_open }, /* open */ | |
161 | { &vop_close_desc, (VOPFUNC)ufsspec_close }, /* close */ | |
162 | { &vop_access_desc, (VOPFUNC)ufs_access }, /* access */ | |
163 | { &vop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */ | |
164 | { &vop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */ | |
165 | { &vop_read_desc, (VOPFUNC)ufsspec_read }, /* read */ | |
166 | { &vop_write_desc, (VOPFUNC)ufsspec_write }, /* write */ | |
167 | { &vop_lease_desc, (VOPFUNC)spec_lease_check }, /* lease */ | |
168 | { &vop_ioctl_desc, (VOPFUNC)spec_ioctl }, /* ioctl */ | |
169 | { &vop_select_desc, (VOPFUNC)spec_select }, /* select */ | |
170 | { &vop_revoke_desc, (VOPFUNC)spec_revoke }, /* revoke */ | |
171 | { &vop_mmap_desc, (VOPFUNC)spec_mmap }, /* mmap */ | |
172 | { &vop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */ | |
173 | { &vop_seek_desc, (VOPFUNC)spec_seek }, /* seek */ | |
174 | { &vop_remove_desc, (VOPFUNC)spec_remove }, /* remove */ | |
175 | { &vop_link_desc, (VOPFUNC)spec_link }, /* link */ | |
176 | { &vop_rename_desc, (VOPFUNC)spec_rename }, /* rename */ | |
177 | { &vop_mkdir_desc, (VOPFUNC)spec_mkdir }, /* mkdir */ | |
178 | { &vop_rmdir_desc, (VOPFUNC)spec_rmdir }, /* rmdir */ | |
179 | { &vop_symlink_desc, (VOPFUNC)spec_symlink }, /* symlink */ | |
180 | { &vop_readdir_desc, (VOPFUNC)spec_readdir }, /* readdir */ | |
181 | { &vop_readlink_desc, (VOPFUNC)spec_readlink }, /* readlink */ | |
182 | { &vop_abortop_desc, (VOPFUNC)spec_abortop }, /* abortop */ | |
183 | { &vop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */ | |
184 | { &vop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */ | |
185 | { &vop_lock_desc, (VOPFUNC)ufs_lock }, /* lock */ | |
186 | { &vop_unlock_desc, (VOPFUNC)ufs_unlock }, /* unlock */ | |
187 | { &vop_bmap_desc, (VOPFUNC)spec_bmap }, /* bmap */ | |
188 | { &vop_strategy_desc, (VOPFUNC)spec_strategy }, /* strategy */ | |
189 | { &vop_print_desc, (VOPFUNC)ufs_print }, /* print */ | |
190 | { &vop_islocked_desc, (VOPFUNC)ufs_islocked }, /* islocked */ | |
191 | { &vop_pathconf_desc, (VOPFUNC)spec_pathconf }, /* pathconf */ | |
192 | { &vop_advlock_desc, (VOPFUNC)spec_advlock }, /* advlock */ | |
193 | { &vop_blkatoff_desc, (VOPFUNC)spec_blkatoff }, /* blkatoff */ | |
194 | { &vop_valloc_desc, (VOPFUNC)spec_valloc }, /* valloc */ | |
195 | { &vop_reallocblks_desc, (VOPFUNC)spec_reallocblks }, /* reallocblks */ | |
196 | { &vop_vfree_desc, (VOPFUNC)ffs_vfree }, /* vfree */ | |
197 | { &vop_truncate_desc, (VOPFUNC)spec_truncate }, /* truncate */ | |
198 | { &vop_update_desc, (VOPFUNC)ffs_update }, /* update */ | |
199 | { &vop_bwrite_desc, (VOPFUNC)vn_bwrite }, | |
200 | { &vop_devblocksize_desc, (VOPFUNC)spec_devblocksize }, /* devblocksize */ | |
201 | { &vop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */ | |
202 | { &vop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */ | |
203 | { &vop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */ | |
204 | { &vop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */ | |
205 | { &vop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */ | |
206 | { &vop_cmap_desc, (VOPFUNC)spec_cmap }, /* cmap */ | |
207 | { (struct vnodeop_desc*)NULL, (int(*)())NULL } | |
208 | }; | |
209 | struct vnodeopv_desc ffs_specop_opv_desc = | |
210 | { &ffs_specop_p, ffs_specop_entries }; | |
211 | ||
212 | #if FIFO | |
213 | int (**ffs_fifoop_p)(void *); | |
214 | struct vnodeopv_entry_desc ffs_fifoop_entries[] = { | |
215 | { &vop_default_desc, (VOPFUNC)vn_default_error }, | |
216 | { &vop_lookup_desc, (VOPFUNC)fifo_lookup }, /* lookup */ | |
217 | { &vop_create_desc, (VOPFUNC)fifo_create }, /* create */ | |
218 | { &vop_mknod_desc, (VOPFUNC)fifo_mknod }, /* mknod */ | |
219 | { &vop_open_desc, (VOPFUNC)fifo_open }, /* open */ | |
220 | { &vop_close_desc, (VOPFUNC)ufsfifo_close }, /* close */ | |
221 | { &vop_access_desc, (VOPFUNC)ufs_access }, /* access */ | |
222 | { &vop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */ | |
223 | { &vop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */ | |
224 | { &vop_read_desc, (VOPFUNC)ufsfifo_read }, /* read */ | |
225 | { &vop_write_desc, (VOPFUNC)ufsfifo_write }, /* write */ | |
226 | { &vop_lease_desc, (VOPFUNC)fifo_lease_check }, /* lease */ | |
227 | { &vop_ioctl_desc, (VOPFUNC)fifo_ioctl }, /* ioctl */ | |
228 | { &vop_select_desc, (VOPFUNC)fifo_select }, /* select */ | |
229 | { &vop_revoke_desc, (VOPFUNC)fifo_revoke }, /* revoke */ | |
230 | { &vop_mmap_desc, (VOPFUNC)fifo_mmap }, /* mmap */ | |
231 | { &vop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */ | |
232 | { &vop_seek_desc, (VOPFUNC)fifo_seek }, /* seek */ | |
233 | { &vop_remove_desc, (VOPFUNC)fifo_remove }, /* remove */ | |
234 | { &vop_link_desc, (VOPFUNC)fifo_link }, /* link */ | |
235 | { &vop_rename_desc, (VOPFUNC)fifo_rename }, /* rename */ | |
236 | { &vop_mkdir_desc, (VOPFUNC)fifo_mkdir }, /* mkdir */ | |
237 | { &vop_rmdir_desc, (VOPFUNC)fifo_rmdir }, /* rmdir */ | |
238 | { &vop_symlink_desc, (VOPFUNC)fifo_symlink }, /* symlink */ | |
239 | { &vop_readdir_desc, (VOPFUNC)fifo_readdir }, /* readdir */ | |
240 | { &vop_readlink_desc, (VOPFUNC)fifo_readlink }, /* readlink */ | |
241 | { &vop_abortop_desc, (VOPFUNC)fifo_abortop }, /* abortop */ | |
242 | { &vop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */ | |
243 | { &vop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */ | |
244 | { &vop_lock_desc, (VOPFUNC)ufs_lock }, /* lock */ | |
245 | { &vop_unlock_desc, (VOPFUNC)ufs_unlock }, /* unlock */ | |
246 | { &vop_bmap_desc, (VOPFUNC)fifo_bmap }, /* bmap */ | |
247 | { &vop_strategy_desc, (VOPFUNC)fifo_strategy }, /* strategy */ | |
248 | { &vop_print_desc, (VOPFUNC)ufs_print }, /* print */ | |
249 | { &vop_islocked_desc, (VOPFUNC)ufs_islocked }, /* islocked */ | |
250 | { &vop_pathconf_desc, (VOPFUNC)fifo_pathconf }, /* pathconf */ | |
251 | { &vop_advlock_desc, (VOPFUNC)fifo_advlock }, /* advlock */ | |
252 | { &vop_blkatoff_desc, (VOPFUNC)fifo_blkatoff }, /* blkatoff */ | |
253 | { &vop_valloc_desc, (VOPFUNC)fifo_valloc }, /* valloc */ | |
254 | { &vop_reallocblks_desc, (VOPFUNC)fifo_reallocblks }, /* reallocblks */ | |
255 | { &vop_vfree_desc, (VOPFUNC)ffs_vfree }, /* vfree */ | |
256 | { &vop_truncate_desc, (VOPFUNC)fifo_truncate }, /* truncate */ | |
257 | { &vop_update_desc, (VOPFUNC)ffs_update }, /* update */ | |
258 | { &vop_bwrite_desc, (VOPFUNC)vn_bwrite }, | |
259 | { &vop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */ | |
260 | { &vop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */ | |
261 | { &vop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */ | |
262 | { &vop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */ | |
263 | { &vop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */ | |
264 | { &vop_cmap_desc, (VOPFUNC)ufs_cmap }, /* cmap */ | |
265 | { (struct vnodeop_desc*)NULL, (int(*)())NULL } | |
266 | }; | |
267 | struct vnodeopv_desc ffs_fifoop_opv_desc = | |
268 | { &ffs_fifoop_p, ffs_fifoop_entries }; | |
269 | #endif /* FIFO */ | |
270 | ||
271 | /* | |
272 | * Enabling cluster read/write operations. | |
273 | */ | |
274 | int doclusterread = 0; | |
275 | int doclusterwrite = 0; | |
276 | ||
277 | #include <ufs/ufs/ufs_readwrite.c> | |
278 | ||
279 | /* | |
280 | * Synch an open file. | |
281 | */ | |
282 | /* ARGSUSED */ | |
283 | int | |
284 | ffs_fsync(ap) | |
285 | struct vop_fsync_args /* { | |
286 | struct vnode *a_vp; | |
287 | struct ucred *a_cred; | |
288 | int a_waitfor; | |
289 | struct proc *a_p; | |
290 | } */ *ap; | |
291 | { | |
292 | register struct vnode *vp = ap->a_vp; | |
293 | register struct buf *bp; | |
294 | struct timeval tv; | |
295 | struct buf *nbp; | |
296 | int s; | |
297 | struct inode *ip = VTOI(vp); | |
298 | ||
299 | /* | |
300 | * Write out any clusters. | |
301 | */ | |
302 | cluster_push(vp); | |
303 | ||
1c79356b A |
304 | /* |
305 | * Flush all dirty buffers associated with a vnode. | |
306 | */ | |
307 | loop: | |
308 | s = splbio(); | |
309 | for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) { | |
310 | nbp = bp->b_vnbufs.le_next; | |
311 | if ((bp->b_flags & B_BUSY)) | |
312 | continue; | |
313 | if ((bp->b_flags & B_DELWRI) == 0) | |
314 | panic("ffs_fsync: not dirty"); | |
315 | bremfree(bp); | |
316 | bp->b_flags |= B_BUSY; | |
317 | splx(s); | |
318 | /* | |
319 | * Wait for I/O associated with indirect blocks to complete, | |
320 | * since there is no way to quickly wait for them below. | |
321 | */ | |
322 | if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT) | |
323 | (void) bawrite(bp); | |
324 | else | |
325 | (void) bwrite(bp); | |
326 | goto loop; | |
327 | } | |
328 | if (vp->v_flag & VHASDIRTY) | |
329 | ubc_pushdirty(vp); | |
330 | ||
331 | if (ap->a_waitfor == MNT_WAIT) { | |
332 | while (vp->v_numoutput) { | |
333 | vp->v_flag |= VBWAIT; | |
334 | tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "ffs_fsync", 0); | |
335 | } | |
336 | ||
337 | /* I have seen this happen for swapfile. So it is safer to | |
338 | * check for dirty buffers again. --Umesh | |
339 | */ | |
340 | if (vp->v_dirtyblkhd.lh_first || (vp->v_flag & VHASDIRTY)) { | |
341 | vprint("ffs_fsync: dirty", vp); | |
342 | splx(s); | |
343 | goto loop; | |
344 | } | |
345 | } | |
346 | splx(s); | |
347 | tv = time; | |
348 | return (VOP_UPDATE(ap->a_vp, &tv, &tv, ap->a_waitfor == MNT_WAIT)); | |
349 | } | |
350 | ||
351 | /* | |
352 | * Reclaim an inode so that it can be used for other purposes. | |
353 | */ | |
354 | int | |
355 | ffs_reclaim(ap) | |
356 | struct vop_reclaim_args /* { | |
357 | struct vnode *a_vp; | |
358 | struct proc *a_p; | |
359 | } */ *ap; | |
360 | { | |
361 | register struct vnode *vp = ap->a_vp; | |
362 | int error; | |
363 | ||
364 | if (error = ufs_reclaim(vp, ap->a_p)) | |
365 | return (error); | |
366 | FREE_ZONE(vp->v_data, sizeof (struct inode), | |
367 | VFSTOUFS(vp->v_mount)->um_devvp->v_tag == VT_MFS ? | |
368 | M_MFSNODE : M_FFSNODE); | |
369 | vp->v_data = NULL; | |
370 | return (0); | |
371 | } | |
372 | ||
373 | /* Blktooff converts a logical block number to a file offset */ | |
374 | int | |
375 | ffs_blktooff(ap) | |
376 | struct vop_blktooff_args /* { | |
377 | struct vnode *a_vp; | |
378 | daddr_t a_lblkno; | |
379 | off_t *a_offset; | |
380 | } */ *ap; | |
381 | { | |
382 | register struct inode *ip; | |
383 | register FS *fs; | |
384 | ufs_daddr_t bn; | |
385 | ||
386 | ||
387 | if (ap->a_vp == NULL) | |
388 | return (EINVAL); | |
389 | ||
390 | ip = VTOI(ap->a_vp); | |
391 | fs = ip->I_FS; | |
392 | bn = ap->a_lblkno; | |
393 | ||
394 | if ((long)bn < 0) { | |
395 | panic("-ve blkno in ffs_blktooff"); | |
396 | bn = -(long)bn; | |
397 | } | |
398 | ||
399 | *ap->a_offset = (off_t)lblktosize(fs, bn); | |
400 | return (0); | |
401 | } | |
402 | ||
403 | /* Blktooff converts a logical block number to a file offset */ | |
404 | int | |
405 | ffs_offtoblk(ap) | |
406 | struct vop_offtoblk_args /* { | |
407 | struct vnode *a_vp; | |
408 | off_t a_offset; | |
409 | daddr_t *a_lblkno; | |
410 | } */ *ap; | |
411 | { | |
412 | register struct inode *ip; | |
413 | register FS *fs; | |
414 | ||
415 | if (ap->a_vp == NULL) | |
416 | return (EINVAL); | |
417 | ||
418 | ip = VTOI(ap->a_vp); | |
419 | fs = ip->I_FS; | |
420 | ||
421 | *ap->a_lblkno = (daddr_t)lblkno(fs, ap->a_offset); | |
422 | return (0); | |
423 | } |