]> git.saurik.com Git - apple/xnu.git/blame - bsd/ufs/ffs/ffs_vnops.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / ufs / ffs / ffs_vnops.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
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>
1c79356b
A
65#include <sys/proc.h>
66#include <sys/conf.h>
91447636
A
67#include <sys/mount_internal.h>
68#include <sys/vnode_internal.h>
1c79356b
A
69#include <sys/malloc.h>
70#include <sys/ubc.h>
9bccf70c 71#include <sys/quota.h>
1c79356b
A
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
1c79356b
A
79#include <ufs/ufs/quota.h>
80#include <ufs/ufs/inode.h>
81#include <ufs/ufs/dir.h>
82#include <ufs/ufs/ufsmount.h>
83#include <ufs/ufs/ufs_extern.h>
84
85#include <ufs/ffs/fs.h>
86#include <ufs/ffs/ffs_extern.h>
87#if REV_ENDIAN_FS
88#include <ufs/ufs/ufs_byte_order.h>
1c79356b
A
89#endif /* REV_ENDIAN_FS */
90
91#define VOPFUNC int (*)(void *)
92
93/* Global vfs data structures for ufs. */
94int (**ffs_vnodeop_p)(void *);
95struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
91447636
A
96 { &vnop_default_desc, (VOPFUNC)vn_default_error },
97 { &vnop_lookup_desc, (VOPFUNC)ufs_lookup }, /* lookup */
98 { &vnop_create_desc, (VOPFUNC)ufs_create }, /* create */
99 { &vnop_whiteout_desc, (VOPFUNC)ufs_whiteout }, /* whiteout */
100 { &vnop_mknod_desc, (VOPFUNC)ufs_mknod }, /* mknod */
101 { &vnop_open_desc, (VOPFUNC)ufs_open }, /* open */
102 { &vnop_close_desc, (VOPFUNC)ufs_close }, /* close */
103 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
104 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
105 { &vnop_read_desc, (VOPFUNC)ffs_read }, /* read */
106 { &vnop_write_desc, (VOPFUNC)ffs_write }, /* write */
107 { &vnop_ioctl_desc, (VOPFUNC)ufs_ioctl }, /* ioctl */
108 { &vnop_select_desc, (VOPFUNC)ufs_select }, /* select */
109 { &vnop_revoke_desc, (VOPFUNC)ufs_revoke }, /* revoke */
110 { &vnop_mmap_desc, (VOPFUNC)ufs_mmap }, /* mmap */
111 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
112 { &vnop_remove_desc, (VOPFUNC)ufs_remove }, /* remove */
113 { &vnop_link_desc, (VOPFUNC)ufs_link }, /* link */
114 { &vnop_rename_desc, (VOPFUNC)ufs_rename }, /* rename */
115 { &vnop_mkdir_desc, (VOPFUNC)ufs_mkdir }, /* mkdir */
116 { &vnop_rmdir_desc, (VOPFUNC)ufs_rmdir }, /* rmdir */
117 { &vnop_symlink_desc, (VOPFUNC)ufs_symlink }, /* symlink */
118 { &vnop_readdir_desc, (VOPFUNC)ufs_readdir }, /* readdir */
119 { &vnop_readlink_desc, (VOPFUNC)ufs_readlink }, /* readlink */
120 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
121 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
122 { &vnop_strategy_desc, (VOPFUNC)ufs_strategy }, /* strategy */
123 { &vnop_pathconf_desc, (VOPFUNC)ufs_pathconf }, /* pathconf */
124 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
125 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
126 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
127 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
128 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
129 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
130 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
131 { &vnop_blockmap_desc, (VOPFUNC)ufs_blockmap }, /* blockmap */
132 { &vnop_kqfilt_add_desc, (VOPFUNC)ufs_kqfilt_add }, /* kqfilt_add */
1c79356b
A
133 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
134};
135struct vnodeopv_desc ffs_vnodeop_opv_desc =
136 { &ffs_vnodeop_p, ffs_vnodeop_entries };
137
138int (**ffs_specop_p)(void *);
139struct vnodeopv_entry_desc ffs_specop_entries[] = {
91447636
A
140 { &vnop_default_desc, (VOPFUNC)vn_default_error },
141 { &vnop_lookup_desc, (VOPFUNC)spec_lookup }, /* lookup */
142 { &vnop_create_desc, (VOPFUNC)spec_create }, /* create */
143 { &vnop_mknod_desc, (VOPFUNC)spec_mknod }, /* mknod */
144 { &vnop_open_desc, (VOPFUNC)spec_open }, /* open */
145 { &vnop_close_desc, (VOPFUNC)ufsspec_close }, /* close */
146 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
147 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
148 { &vnop_read_desc, (VOPFUNC)ufsspec_read }, /* read */
149 { &vnop_write_desc, (VOPFUNC)ufsspec_write }, /* write */
150 { &vnop_ioctl_desc, (VOPFUNC)spec_ioctl }, /* ioctl */
151 { &vnop_select_desc, (VOPFUNC)spec_select }, /* select */
152 { &vnop_revoke_desc, (VOPFUNC)spec_revoke }, /* revoke */
153 { &vnop_mmap_desc, (VOPFUNC)spec_mmap }, /* mmap */
154 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
155 { &vnop_remove_desc, (VOPFUNC)spec_remove }, /* remove */
156 { &vnop_link_desc, (VOPFUNC)spec_link }, /* link */
157 { &vnop_rename_desc, (VOPFUNC)spec_rename }, /* rename */
158 { &vnop_mkdir_desc, (VOPFUNC)spec_mkdir }, /* mkdir */
159 { &vnop_rmdir_desc, (VOPFUNC)spec_rmdir }, /* rmdir */
160 { &vnop_symlink_desc, (VOPFUNC)spec_symlink }, /* symlink */
161 { &vnop_readdir_desc, (VOPFUNC)spec_readdir }, /* readdir */
162 { &vnop_readlink_desc, (VOPFUNC)spec_readlink }, /* readlink */
163 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
164 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
165 { &vnop_strategy_desc, (VOPFUNC)spec_strategy }, /* strategy */
166 { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf }, /* pathconf */
167 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
168 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
91447636
A
169 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
170 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
171 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
172 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
173 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
174 { &vnop_blockmap_desc, (VOPFUNC)spec_blockmap }, /* blockmap */
1c79356b
A
175 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
176};
177struct vnodeopv_desc ffs_specop_opv_desc =
178 { &ffs_specop_p, ffs_specop_entries };
179
180#if FIFO
181int (**ffs_fifoop_p)(void *);
182struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
91447636
A
183 { &vnop_default_desc, (VOPFUNC)vn_default_error },
184 { &vnop_lookup_desc, (VOPFUNC)fifo_lookup }, /* lookup */
185 { &vnop_create_desc, (VOPFUNC)fifo_create }, /* create */
186 { &vnop_mknod_desc, (VOPFUNC)fifo_mknod }, /* mknod */
187 { &vnop_open_desc, (VOPFUNC)fifo_open }, /* open */
188 { &vnop_close_desc, (VOPFUNC)ufsfifo_close }, /* close */
189 { &vnop_getattr_desc, (VOPFUNC)ufs_getattr }, /* getattr */
190 { &vnop_setattr_desc, (VOPFUNC)ufs_setattr }, /* setattr */
191 { &vnop_read_desc, (VOPFUNC)ufsfifo_read }, /* read */
192 { &vnop_write_desc, (VOPFUNC)ufsfifo_write }, /* write */
193 { &vnop_ioctl_desc, (VOPFUNC)fifo_ioctl }, /* ioctl */
194 { &vnop_select_desc, (VOPFUNC)fifo_select }, /* select */
195 { &vnop_revoke_desc, (VOPFUNC)fifo_revoke }, /* revoke */
196 { &vnop_mmap_desc, (VOPFUNC)fifo_mmap }, /* mmap */
197 { &vnop_fsync_desc, (VOPFUNC)ffs_fsync }, /* fsync */
198 { &vnop_remove_desc, (VOPFUNC)fifo_remove }, /* remove */
199 { &vnop_link_desc, (VOPFUNC)fifo_link }, /* link */
200 { &vnop_rename_desc, (VOPFUNC)fifo_rename }, /* rename */
201 { &vnop_mkdir_desc, (VOPFUNC)fifo_mkdir }, /* mkdir */
202 { &vnop_rmdir_desc, (VOPFUNC)fifo_rmdir }, /* rmdir */
203 { &vnop_symlink_desc, (VOPFUNC)fifo_symlink }, /* symlink */
204 { &vnop_readdir_desc, (VOPFUNC)fifo_readdir }, /* readdir */
205 { &vnop_readlink_desc, (VOPFUNC)fifo_readlink }, /* readlink */
206 { &vnop_inactive_desc, (VOPFUNC)ufs_inactive }, /* inactive */
207 { &vnop_reclaim_desc, (VOPFUNC)ffs_reclaim }, /* reclaim */
208 { &vnop_strategy_desc, (VOPFUNC)fifo_strategy }, /* strategy */
209 { &vnop_pathconf_desc, (VOPFUNC)fifo_pathconf }, /* pathconf */
210 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
211 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
212 { &vnop_pagein_desc, (VOPFUNC)ffs_pagein }, /* Pagein */
213 { &vnop_pageout_desc, (VOPFUNC)ffs_pageout }, /* Pageout */
214 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copy File */
215 { &vnop_blktooff_desc, (VOPFUNC)ffs_blktooff }, /* blktooff */
216 { &vnop_offtoblk_desc, (VOPFUNC)ffs_offtoblk }, /* offtoblk */
217 { &vnop_blockmap_desc, (VOPFUNC)ufs_blockmap }, /* blockmap */
218 { &vnop_kqfilt_add_desc, (VOPFUNC)ufsfifo_kqfilt_add }, /* kqfilt_add */
1c79356b
A
219 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
220};
221struct vnodeopv_desc ffs_fifoop_opv_desc =
222 { &ffs_fifoop_p, ffs_fifoop_entries };
223#endif /* FIFO */
224
225/*
226 * Enabling cluster read/write operations.
227 */
228int doclusterread = 0;
229int doclusterwrite = 0;
230
231#include <ufs/ufs/ufs_readwrite.c>
232
233/*
234 * Synch an open file.
235 */
236/* ARGSUSED */
237int
238ffs_fsync(ap)
91447636 239 struct vnop_fsync_args /* {
1c79356b 240 struct vnode *a_vp;
1c79356b 241 int a_waitfor;
91447636 242 vfs_context_t a_context;
1c79356b
A
243 } */ *ap;
244{
91447636
A
245 return(ffs_fsync_internal(ap->a_vp, ap->a_waitfor));
246}
247
248
249int
250ffs_fsync_internal(vnode_t vp, int waitfor)
251{
1c79356b 252 struct timeval tv;
91447636 253 int wait = (waitfor == MNT_WAIT);
1c79356b
A
254
255 /*
256 * Write out any clusters.
257 */
91447636 258 cluster_push(vp, 0);
1c79356b 259
1c79356b
A
260 /*
261 * Flush all dirty buffers associated with a vnode.
262 */
91447636
A
263 buf_flushdirtyblks(vp, wait, 0, (char *)"ffs_fsync");
264 microtime(&tv);
265
266 return (ffs_update(vp, &tv, &tv, wait));
1c79356b
A
267}
268
269/*
270 * Reclaim an inode so that it can be used for other purposes.
271 */
272int
273ffs_reclaim(ap)
91447636 274 struct vnop_reclaim_args /* {
1c79356b 275 struct vnode *a_vp;
91447636 276 vfs_context_t a_context;
1c79356b
A
277 } */ *ap;
278{
279 register struct vnode *vp = ap->a_vp;
280 int error;
281
91447636 282 if ( (error = ufs_reclaim(vp, vfs_context_proc(ap->a_context))) )
1c79356b 283 return (error);
91447636
A
284
285 FREE_ZONE(vnode_fsnode(vp), sizeof (struct inode), M_FFSNODE);
286
287 vnode_clearfsnode(vp);
288
1c79356b
A
289 return (0);
290}
291
292/* Blktooff converts a logical block number to a file offset */
293int
294ffs_blktooff(ap)
91447636 295 struct vnop_blktooff_args /* {
1c79356b 296 struct vnode *a_vp;
91447636 297 daddr64_t a_lblkno;
1c79356b
A
298 off_t *a_offset;
299 } */ *ap;
300{
301 register struct inode *ip;
302 register FS *fs;
1c79356b
A
303
304 if (ap->a_vp == NULL)
305 return (EINVAL);
306
91447636 307 fs = VTOI(ap->a_vp)->I_FS;
1c79356b 308
91447636 309 *ap->a_offset = (off_t)lblktosize(fs, ap->a_lblkno);
1c79356b 310
1c79356b
A
311 return (0);
312}
313
314/* Blktooff converts a logical block number to a file offset */
315int
316ffs_offtoblk(ap)
91447636 317 struct vnop_offtoblk_args /* {
1c79356b
A
318 struct vnode *a_vp;
319 off_t a_offset;
91447636 320 daddr64_t *a_lblkno;
1c79356b
A
321 } */ *ap;
322{
91447636 323 register FS *fs;
1c79356b
A
324
325 if (ap->a_vp == NULL)
326 return (EINVAL);
327
91447636
A
328 fs = VTOI(ap->a_vp)->I_FS;
329
330 *ap->a_lblkno = (daddr64_t)lblkno(fs, ap->a_offset);
1c79356b 331
1c79356b
A
332 return (0);
333}