]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/ufs/ffs/ffs_vnops.c
xnu-1228.15.4.tar.gz
[apple/xnu.git] / bsd / ufs / ffs / ffs_vnops.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*
30 * Copyright (c) 1982, 1986, 1989, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
62 */
63
64#include <rev_endian_fs.h>
65#include <sys/param.h>
66#include <sys/systm.h>
67#include <sys/resourcevar.h>
68#include <sys/kernel.h>
69#include <sys/file.h>
70#include <sys/stat.h>
71#include <sys/proc.h>
72#include <sys/conf.h>
73#include <sys/mount_internal.h>
74#include <sys/vnode_internal.h>
75#include <sys/malloc.h>
76#include <sys/ubc.h>
77#include <sys/quota.h>
78
79#include <sys/vm.h>
80#include <vfs/vfs_support.h>
81
82#include <miscfs/specfs/specdev.h>
83#include <miscfs/fifofs/fifo.h>
84
85#include <ufs/ufs/quota.h>
86#include <ufs/ufs/inode.h>
87#include <ufs/ufs/dir.h>
88#include <ufs/ufs/ufsmount.h>
89#include <ufs/ufs/ufs_extern.h>
90
91#include <ufs/ffs/fs.h>
92#include <ufs/ffs/ffs_extern.h>
93#if REV_ENDIAN_FS
94#include <ufs/ufs/ufs_byte_order.h>
95#endif /* REV_ENDIAN_FS */
96
97#define VOPFUNC int (*)(void *)
98
99/* Global vfs data structures for ufs. */
100int (**ffs_vnodeop_p)(void *);
101struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
102 { &vnop_default_desc, (VOPFUNC)vn_default_error },
103 { &vnop_lookup_desc, (VOPFUNC)ufs_lookup }, /* lookup */
104 { &vnop_create_desc, (VOPFUNC)ufs_create }, /* create */
105 { &vnop_whiteout_desc, (VOPFUNC)ufs_whiteout }, /* whiteout */
106 { &vnop_mknod_desc, (VOPFUNC)ufs_mknod }, /* mknod */
107 { &vnop_open_desc, (VOPFUNC)ufs_open }, /* open */
108 { &vnop_close_desc, (VOPFUNC)ufs_close }, /* close */
109 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
110 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
111 { &vnop_read_desc, (VOPFUNC)ffs_read }, /* read */
112 { &vnop_write_desc, (VOPFUNC)ffs_write }, /* write */
113 { &vnop_ioctl_desc, (VOPFUNC)ufs_ioctl }, /* ioctl */
114 { &vnop_select_desc, (VOPFUNC)ufs_select }, /* select */
115 { &vnop_revoke_desc, (VOPFUNC)ufs_revoke }, /* revoke */
116 { &vnop_mmap_desc, (VOPFUNC)ufs_mmap }, /* mmap */
117 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
118 { &vnop_remove_desc, (VOPFUNC)ufs_remove }, /* remove */
119 { &vnop_link_desc, (VOPFUNC)ufs_link }, /* link */
120 { &vnop_rename_desc, (VOPFUNC)ufs_rename }, /* rename */
121 { &vnop_mkdir_desc, (VOPFUNC)ufs_mkdir }, /* mkdir */
122 { &vnop_rmdir_desc, (VOPFUNC)ufs_rmdir }, /* rmdir */
123 { &vnop_symlink_desc, (VOPFUNC)ufs_symlink }, /* symlink */
124 { &vnop_readdir_desc, (VOPFUNC)ufs_readdir }, /* readdir */
125 { &vnop_readlink_desc, (VOPFUNC)ufs_readlink }, /* readlink */
126 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
127 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
128 { &vnop_strategy_desc, (VOPFUNC)ufs_strategy }, /* strategy */
129 { &vnop_pathconf_desc, (VOPFUNC)ufs_pathconf }, /* pathconf */
130 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
131 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
132 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
133 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
134 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
135 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
136 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
137 { &vnop_blockmap_desc, (VOPFUNC)ufs_blockmap }, /* blockmap */
138 { &vnop_kqfilt_add_desc, (VOPFUNC)ufs_kqfilt_add }, /* kqfilt_add */
139 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
140};
141struct vnodeopv_desc ffs_vnodeop_opv_desc =
142 { &ffs_vnodeop_p, ffs_vnodeop_entries };
143
144int (**ffs_specop_p)(void *);
145struct vnodeopv_entry_desc ffs_specop_entries[] = {
146 { &vnop_default_desc, (VOPFUNC)vn_default_error },
147 { &vnop_lookup_desc, (VOPFUNC)spec_lookup }, /* lookup */
148 { &vnop_create_desc, (VOPFUNC)spec_create }, /* create */
149 { &vnop_mknod_desc, (VOPFUNC)spec_mknod }, /* mknod */
150 { &vnop_open_desc, (VOPFUNC)spec_open }, /* open */
151 { &vnop_close_desc, (VOPFUNC)ufsspec_close }, /* close */
152 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
153 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
154 { &vnop_read_desc, (VOPFUNC)ufsspec_read }, /* read */
155 { &vnop_write_desc, (VOPFUNC)ufsspec_write }, /* write */
156 { &vnop_ioctl_desc, (VOPFUNC)spec_ioctl }, /* ioctl */
157 { &vnop_select_desc, (VOPFUNC)spec_select }, /* select */
158 { &vnop_revoke_desc, (VOPFUNC)spec_revoke }, /* revoke */
159 { &vnop_mmap_desc, (VOPFUNC)spec_mmap }, /* mmap */
160 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
161 { &vnop_remove_desc, (VOPFUNC)spec_remove }, /* remove */
162 { &vnop_link_desc, (VOPFUNC)spec_link }, /* link */
163 { &vnop_rename_desc, (VOPFUNC)spec_rename }, /* rename */
164 { &vnop_mkdir_desc, (VOPFUNC)spec_mkdir }, /* mkdir */
165 { &vnop_rmdir_desc, (VOPFUNC)spec_rmdir }, /* rmdir */
166 { &vnop_symlink_desc, (VOPFUNC)spec_symlink }, /* symlink */
167 { &vnop_readdir_desc, (VOPFUNC)spec_readdir }, /* readdir */
168 { &vnop_readlink_desc, (VOPFUNC)spec_readlink }, /* readlink */
169 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
170 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
171 { &vnop_strategy_desc, (VOPFUNC)spec_strategy }, /* strategy */
172 { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf }, /* pathconf */
173 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
174 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
175 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
176 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
177 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
178 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
179 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
180 { &vnop_blockmap_desc, (VOPFUNC)spec_blockmap }, /* blockmap */
181 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
182};
183struct vnodeopv_desc ffs_specop_opv_desc =
184 { &ffs_specop_p, ffs_specop_entries };
185
186#if FIFO
187int (**ffs_fifoop_p)(void *);
188struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
189 { &vnop_default_desc, (VOPFUNC)vn_default_error },
190 { &vnop_lookup_desc, (VOPFUNC)fifo_lookup }, /* lookup */
191 { &vnop_create_desc, (VOPFUNC)fifo_create }, /* create */
192 { &vnop_mknod_desc, (VOPFUNC)fifo_mknod }, /* mknod */
193 { &vnop_open_desc, (VOPFUNC)fifo_open }, /* open */
194 { &vnop_close_desc, (VOPFUNC)ufsfifo_close }, /* close */
195 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
196 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
197 { &vnop_read_desc, (VOPFUNC)ufsfifo_read }, /* read */
198 { &vnop_write_desc, (VOPFUNC)ufsfifo_write }, /* write */
199 { &vnop_ioctl_desc, (VOPFUNC)fifo_ioctl }, /* ioctl */
200 { &vnop_select_desc, (VOPFUNC)fifo_select }, /* select */
201 { &vnop_revoke_desc, (VOPFUNC)fifo_revoke }, /* revoke */
202 { &vnop_mmap_desc, (VOPFUNC)fifo_mmap }, /* mmap */
203 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
204 { &vnop_remove_desc, (VOPFUNC)fifo_remove }, /* remove */
205 { &vnop_link_desc, (VOPFUNC)fifo_link }, /* link */
206 { &vnop_rename_desc, (VOPFUNC)fifo_rename }, /* rename */
207 { &vnop_mkdir_desc, (VOPFUNC)fifo_mkdir }, /* mkdir */
208 { &vnop_rmdir_desc, (VOPFUNC)fifo_rmdir }, /* rmdir */
209 { &vnop_symlink_desc, (VOPFUNC)fifo_symlink }, /* symlink */
210 { &vnop_readdir_desc, (VOPFUNC)fifo_readdir }, /* readdir */
211 { &vnop_readlink_desc, (VOPFUNC)fifo_readlink }, /* readlink */
212 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
213 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
214 { &vnop_strategy_desc, (VOPFUNC)fifo_strategy }, /* strategy */
215 { &vnop_pathconf_desc, (VOPFUNC)fifo_pathconf }, /* pathconf */
216 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
217 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
218 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
219 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
220 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
221 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
222 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
223 { &vnop_blockmap_desc, (VOPFUNC)ufs_blockmap }, /* blockmap */
224 { &vnop_kqfilt_add_desc, (VOPFUNC)ufsfifo_kqfilt_add }, /* kqfilt_add */
225 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
226};
227struct vnodeopv_desc ffs_fifoop_opv_desc =
228 { &ffs_fifoop_p, ffs_fifoop_entries };
229#endif /* FIFO */
230
231/*
232 * Enabling cluster read/write operations.
233 */
234int doclusterread = 0;
235int doclusterwrite = 0;
236
237#include <ufs/ufs/ufs_readwrite.c>
238
239/*
240 * Synch an open file.
241 */
242/* ARGSUSED */
243int
244ffs_fsync(ap)
245 struct vnop_fsync_args /* {
246 struct vnode *a_vp;
247 int a_waitfor;
248 vfs_context_t a_context;
249 } */ *ap;
250{
251 return(ffs_fsync_internal(ap->a_vp, ap->a_waitfor));
252}
253
254
255int
256ffs_fsync_internal(vnode_t vp, int waitfor)
257{
258 struct timeval tv;
259 int wait = (waitfor == MNT_WAIT);
260
261 /*
262 * Write out any clusters.
263 */
264 cluster_push(vp, 0);
265
266 /*
267 * Flush all dirty buffers associated with a vnode.
268 */
269 buf_flushdirtyblks(vp, wait, 0, "ffs_fsync");
270 microtime(&tv);
271
272 return (ffs_update(vp, &tv, &tv, wait));
273}
274
275/*
276 * Reclaim an inode so that it can be used for other purposes.
277 */
278int
279ffs_reclaim(ap)
280 struct vnop_reclaim_args /* {
281 struct vnode *a_vp;
282 vfs_context_t a_context;
283 } */ *ap;
284{
285 register struct vnode *vp = ap->a_vp;
286 int error;
287
288 if ( (error = ufs_reclaim(vp, vfs_context_proc(ap->a_context))) )
289 return (error);
290
291 FREE_ZONE(vnode_fsnode(vp), sizeof (struct inode), M_FFSNODE);
292
293 vnode_clearfsnode(vp);
294
295 return (0);
296}
297
298/* Blktooff converts a logical block number to a file offset */
299int
300ffs_blktooff(ap)
301 struct vnop_blktooff_args /* {
302 struct vnode *a_vp;
303 daddr64_t a_lblkno;
304 off_t *a_offset;
305 } */ *ap;
306{
307 register struct inode *ip;
308 register FS *fs;
309
310 if (ap->a_vp == NULL)
311 return (EINVAL);
312
313 fs = VTOI(ap->a_vp)->I_FS;
314
315 *ap->a_offset = (off_t)lblktosize(fs, ap->a_lblkno);
316
317 return (0);
318}
319
320/* Blktooff converts a logical block number to a file offset */
321int
322ffs_offtoblk(ap)
323 struct vnop_offtoblk_args /* {
324 struct vnode *a_vp;
325 off_t a_offset;
326 daddr64_t *a_lblkno;
327 } */ *ap;
328{
329 register FS *fs;
330
331 if (ap->a_vp == NULL)
332 return (EINVAL);
333
334 fs = VTOI(ap->a_vp)->I_FS;
335
336 *ap->a_lblkno = (daddr64_t)lblkno(fs, ap->a_offset);
337
338 return (0);
339}